X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Ftext.php;h=2ca0e0e517052a6c838ed7da42008b4c5a31b281;hb=a6eae9adec28454b1829fe15dc79e1cb8278d5ac;hp=2ec017caffa9bb613348d153f8cae2c47cc92a01;hpb=ab82c6df0341346658a7f28adc53ca2506d23c5a;p=friendica.git diff --git a/include/text.php b/include/text.php index 2ec017caff..2ca0e0e517 100644 --- a/include/text.php +++ b/include/text.php @@ -14,6 +14,7 @@ use Friendica\Core\L10n; use Friendica\Core\PConfig; use Friendica\Core\System; use Friendica\Database\DBM; +use Friendica\Model\Contact; use Friendica\Model\Event; use Friendica\Model\Item; use Friendica\Model\Profile; @@ -151,7 +152,7 @@ function autoname($len) { 'nd','ng','nk','nt','rn','rp','rt']; $noend = ['bl', 'br', 'cl','cr','dr','fl','fr','gl','gr', - 'kh', 'kl','kr','mn','pl','pr','rh','tr','qu','wh']; + 'kh', 'kl','kr','mn','pl','pr','rh','tr','qu','wh','q']; $start = mt_rand(0,2); if ($start == 0) { @@ -177,14 +178,13 @@ function autoname($len) { $word = substr($word,0,$len); foreach ($noend as $noe) { - if ((strlen($word) > 2) && (substr($word, -2) == $noe)) { - $word = substr($word, 0, -1); + $noelen = strlen($noe); + if ((strlen($word) > $noelen) && (substr($word, -$noelen) == $noe)) { + $word = autoname($len); break; } } - if (substr($word, -1) == 'q') { - $word = substr($word, 0, -1); - } + return $word; } @@ -452,7 +452,7 @@ function perms2str($p) { if (is_array($p)) { $tmp = $p; } else { - $tmp = explode(',',$p); + $tmp = explode(',', $p); } if (is_array($tmp)) { @@ -462,33 +462,6 @@ function perms2str($p) { return $ret; } - -/** - * generate a guaranteed unique (for this domain) item ID for ATOM - * safe from birthday paradox - * - * @param string $hostname - * @param int $uid - * @return string - */ -function item_new_uri($hostname, $uid, $guid = "") { - - do { - if ($guid == "") { - $hash = get_guid(32); - } else { - $hash = $guid; - $guid = ""; - } - - $uri = "urn:X-dfrn:" . $hostname . ':' . $uid . ':' . $hash; - - $dups = dba::exists('item', ['uri' => $uri]); - } while ($dups == true); - - return $uri; -} - /** * @deprecated * wrapper to load a view template, checking for alternate @@ -501,7 +474,7 @@ function item_new_uri($hostname, $uid, $guid = "") { */ function load_view_file($s) { global $lang, $a; - if (! isset($lang)) { + if (!isset($lang)) { $lang = 'en'; } $b = basename($s); @@ -513,7 +486,7 @@ function load_view_file($s) { return $content; } - $theme = current_theme(); + $theme = $a->getCurrentTheme(); if (file_exists("$d/theme/$theme/$b")) { $stamp1 = microtime(true); @@ -546,7 +519,7 @@ function get_intltext_template($s) { $engine = "/smarty3"; } - if (! isset($lang)) { + if (!isset($lang)) { $lang = 'en'; } @@ -637,7 +610,7 @@ function logger($msg, $level = 0) { // turn off logger in install mode if ( - $a->module == 'install' + $a->mode == App::MODE_INSTALL || !dba::$connected ) { return; @@ -648,8 +621,8 @@ function logger($msg, $level = 0) { $loglevel = intval(Config::get('system','loglevel')); if ( - ! $debugging - || ! $logfile + !$debugging + || !$logfile || $level > $loglevel ) { return; @@ -670,13 +643,20 @@ function logger($msg, $level = 0) { } $callers = debug_backtrace(); + + if (count($callers) > 1) { + $function = $callers[1]['function']; + } else { + $function = ''; + } + $logline = sprintf("%s@%s\t[%s]:%s:%s:%s\t%s\n", DateTimeFormat::utcNow(DateTimeFormat::ATOM), $process_id, $LOGGER_LEVELS[$level], basename($callers[0]['file']), $callers[0]['line'], - $callers[1]['function'], + $function, $msg ); @@ -709,14 +689,14 @@ function dlogger($msg, $level = 0) { // turn off logger in install mode if ( - $a->module == 'install' + $a->mode == App::MODE_INSTALL || !dba::$connected ) { return; } $logfile = Config::get('system', 'dlogfile'); - if (! $logfile) { + if (!$logfile) { return; } @@ -961,13 +941,9 @@ function micropro($contact, $redirect = false, $class = '', $textmode = false) { $redir = false; if ($redirect) { - $redirect_url = 'redir/' . $contact['id']; - if (local_user() && ($contact['uid'] == local_user()) && ($contact['network'] === NETWORK_DFRN)) { - $redir = true; - $url = $redirect_url; + $url = Contact::magicLink($contact['url']); + if (strpos($url, 'redir/') === 0) { $sparkle = ' sparkle'; - } else { - $url = Profile::zrl($url); } } @@ -1015,7 +991,7 @@ function search($s, $id = 'search-box', $url = 'search', $save = false, $aside = '$action_url' => $url, '$search_label' => L10n::t('Search'), '$save_label' => $save_label, - '$savedsearch' => Feature::isEnabled(local_user(),'savedsearch'), + '$savedsearch' => local_user() && Feature::isEnabled(local_user(),'savedsearch'), '$search_hint' => L10n::t('@name, !forum, #tags, content'), '$mode' => $mode ]; @@ -1187,7 +1163,7 @@ function put_item_in_cache(&$item, $update = false) $rendered_html = defaults($item, 'rendered-html', ''); if ($rendered_hash == '' - || $item["rendered-html"] == "" + || $rendered_html == "" || $rendered_hash != hash("md5", $item["body"]) || Config::get("system", "ignore_cache") ) { @@ -1197,6 +1173,12 @@ function put_item_in_cache(&$item, $update = false) $item["rendered-html"] = prepare_text($item["body"]); $item["rendered-hash"] = hash("md5", $item["body"]); + $hook_data = ['item' => $item, 'rendered-html' => $item['rendered-html'], 'rendered-hash' => $item['rendered-hash']]; + Addon::callHooks('put_item_in_cache', $hook_data); + $item['rendered-html'] = $hook_data['rendered-html']; + $item['rendered-hash'] = $hook_data['rendered-hash']; + unset($hook_data); + // Force an update if the generated values differ from the existing ones if ($rendered_hash != $item["rendered-hash"]) { $update = true; @@ -1207,9 +1189,9 @@ function put_item_in_cache(&$item, $update = false) $update = true; } - if ($update && ($item["id"] > 0)) { - dba::update('item', ['rendered-html' => $item["rendered-html"], 'rendered-hash' => $item["rendered-hash"]], - ['id' => $item["id"]], false); + if ($update && !empty($item["id"])) { + Item::update(['rendered-html' => $item["rendered-html"], 'rendered-hash' => $item["rendered-hash"]], + ['id' => $item["id"]]); } } @@ -1249,7 +1231,7 @@ function prepare_body(array &$item, $attach = false, $is_preview = false) // Compile eventual content filter reasons $filter_reasons = []; - if (!$is_preview && !($item['self'] && local_user() == $item['uid'])) { + if (!$is_preview && public_contact() != $item['author-id']) { if (!empty($item['content-warning']) && (!local_user() || !PConfig::get(local_user(), 'system', 'disable_cw', false))) { $filter_reasons[] = L10n::t('Content warning: %s', $item['content-warning']); } @@ -1284,9 +1266,7 @@ function prepare_body(array &$item, $attach = false, $is_preview = false) $s = $hook_data['html']; unset($hook_data); - $s = apply_content_filter($s, $filter_reasons); - - if (! $attach) { + if (!$attach) { // Replace the blockquotes with quotes that are used in mails. $mailquote = '
'; $s = str_replace(['
', '
', '
'], [$mailquote, $mailquote, $mailquote], $s); @@ -1300,11 +1280,7 @@ function prepare_body(array &$item, $attach = false, $is_preview = false) foreach ($matches as $mtch) { $mime = $mtch[3]; - if ((local_user() == $item['uid']) && ($item['contact-id'] != $a->contact['id']) && ($item['network'] == NETWORK_DFRN)) { - $the_url = 'redir/' . $item['contact-id'] . '?f=1&url=' . $mtch[1]; - } else { - $the_url = $mtch[1]; - } + $the_url = Contact::magicLinkById($item['author-id'], $mtch[1]); if (strpos($mime, 'video') !== false) { if (!$vhead) { @@ -1317,7 +1293,8 @@ function prepare_body(array &$item, $attach = false, $is_preview = false) ]); } - $id = end(explode('/', $the_url)); + $url_parts = explode('/', $the_url); + $id = end($url_parts); $as .= replace_macros(get_markup_template('video_top.tpl'), [ '$video' => [ 'id' => $id, @@ -1393,6 +1370,8 @@ function prepare_body(array &$item, $attach = false, $is_preview = false) $s = preg_replace('|(]+src="[^"]+/photo/[0-9a-f]+)-[0-9]|', "$1-" . $ps, $s); } + $s = apply_content_filter($s, $filter_reasons); + $hook_data = ['item' => $item, 'html' => $s]; Addon::callHooks('prepare_body_final', $hook_data); @@ -1411,18 +1390,13 @@ function prepare_body(array &$item, $attach = false, $is_preview = false) function apply_content_filter($html, array $reasons) { if (count($reasons)) { - $rnd = random_string(8); - $content_filter_html = '
    '; - foreach ($reasons as $reason) { - $content_filter_html .= '
  • ' . htmlspecialchars($reason) . '
  • ' . PHP_EOL; - } - $content_filter_html .= '
-

' . - L10n::t('Click to open/close') . - '

- '; + $tpl = get_markup_template('wall/content_filter.tpl'); + $html = replace_macros($tpl, [ + '$reasons' => $reasons, + '$rnd' => random_string(8), + '$openclose' => L10n::t('Click to open/close'), + '$html' => $html + ]); } return $html; @@ -1589,11 +1563,11 @@ function return_bytes($size_str) { function generate_user_guid() { $found = true; do { - $guid = get_guid(32); + $guid = System::createGUID(32); $x = q("SELECT `uid` FROM `user` WHERE `guid` = '%s' LIMIT 1", dbesc($guid) ); - if (! DBM::is_result($x)) { + if (!DBM::is_result($x)) { $found = false; } } while ($found == true); @@ -1635,7 +1609,7 @@ function base64url_decode($s) { * // Uncomment if you find you need it. * * $l = strlen($s); - * if (! strpos($s,'=')) { + * if (!strpos($s,'=')) { * $m = $l % 4; * if ($m == 2) * $s .= '=='; @@ -1665,10 +1639,11 @@ function bb_translate_video($s) { $r = preg_match_all("/\[video\](.*?)\[\/video\]/ism",$s,$matches,PREG_SET_ORDER); if ($r) { foreach ($matches as $mtch) { - if ((stristr($mtch[1],'youtube')) || (stristr($mtch[1],'youtu.be'))) - $s = str_replace($mtch[0],'[youtube]' . $mtch[1] . '[/youtube]',$s); - elseif (stristr($mtch[1],'vimeo')) - $s = str_replace($mtch[0],'[vimeo]' . $mtch[1] . '[/vimeo]',$s); + if ((stristr($mtch[1], 'youtube')) || (stristr($mtch[1], 'youtu.be'))) { + $s = str_replace($mtch[0], '[youtube]' . $mtch[1] . '[/youtube]', $s); + } elseif (stristr($mtch[1], 'vimeo')) { + $s = str_replace($mtch[0], '[vimeo]' . $mtch[1] . '[/vimeo]', $s); + } } } return $s; @@ -1749,11 +1724,11 @@ function reltoabs($text, $base) { * @return string */ function item_post_type($item) { - if (intval($item['event-id'])) { + if (!empty($item['event-id'])) { return L10n::t('event'); - } elseif (strlen($item['resource-id'])) { + } elseif (!empty($item['resource-id'])) { return L10n::t('photo'); - } elseif (strlen($item['verb']) && $item['verb'] !== ACTIVITY_POST) { + } elseif (!empty($item['verb']) && $item['verb'] !== ACTIVITY_POST) { return L10n::t('activity'); } elseif ($item['id'] != $item['parent']) { return L10n::t('comment'); @@ -1786,7 +1761,7 @@ function file_tag_file_query($table,$s,$type = 'file') { } // ex. given music,video return