X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Ftext.php;h=4c9a8864d595d6dca9d10c9f221d5a9e4627542b;hb=6dda5366ded349288b65eb7bc7c88b909a04626d;hp=6e11c3a38a64e48395bda7324e20aeaa7984868f;hpb=d603bf062da148e8262906c67129dc78067bffa6;p=friendica.git diff --git a/include/text.php b/include/text.php index 6e11c3a38a..4c9a8864d5 100644 --- a/include/text.php +++ b/include/text.php @@ -513,7 +513,7 @@ function load_view_file($s) { return $content; } - $theme = current_theme(); + $theme = $a->getCurrentTheme(); if (file_exists("$d/theme/$theme/$b")) { $stamp1 = microtime(true); @@ -637,7 +637,7 @@ function logger($msg, $level = 0) { // turn off logger in install mode if ( - $a->module == 'install' + $a->mode == App::MODE_INSTALL || !dba::$connected ) { return; @@ -709,7 +709,7 @@ function dlogger($msg, $level = 0) { // turn off logger in install mode if ( - $a->module == 'install' + $a->mode == App::MODE_INSTALL || !dba::$connected ) { return; @@ -1184,6 +1184,7 @@ function put_item_in_cache(&$item, $update = false) $body = $item["body"]; $rendered_hash = defaults($item, 'rendered-hash', ''); + $rendered_html = defaults($item, 'rendered-html', ''); if ($rendered_hash == '' || $item["rendered-html"] == "" @@ -1196,6 +1197,16 @@ function put_item_in_cache(&$item, $update = false) $item["rendered-html"] = prepare_text($item["body"]); $item["rendered-hash"] = hash("md5", $item["body"]); + // Force an update if the generated values differ from the existing ones + if ($rendered_hash != $item["rendered-hash"]) { + $update = true; + } + + // Only compare the HTML when we forcefully ignore the cache + if (Config::get("system", "ignore_cache") && ($rendered_html != $item["rendered-html"])) { + $update = true; + } + if ($update && ($item["id"] > 0)) { dba::update('item', ['rendered-html' => $item["rendered-html"], 'rendered-hash' => $item["rendered-hash"]], ['id' => $item["id"]], false); @@ -1214,7 +1225,7 @@ function put_item_in_cache(&$item, $update = false) * @param boolean $is_preview * @return string item body html * @hook prepare_body_init item array before any work - * @hook content_filter ('item'=>item array, 'filter_reasons'=>string array) before first bbcode to html + * @hook prepare_body_content_filter ('item'=>item array, 'filter_reasons'=>string array) before first bbcode to html * @hook prepare_body ('item'=>item array, 'html'=>body string, 'is_preview'=>boolean, 'filter_reasons'=>string array) after first bbcode to html * @hook prepare_body_final ('item'=>item array, 'html'=>body string) after attach icons and blockquote special case handling (spoiler, author) */ @@ -1223,12 +1234,6 @@ function prepare_body(array &$item, $attach = false, $is_preview = false) $a = get_app(); Addon::callHooks('prepare_body_init', $item); - $searchpath = System::baseUrl() . "/search?tag="; - - $tags = []; - $hashtags = []; - $mentions = []; - // In order to provide theme developers more possibilities, event items // are treated differently. if ($item['object-type'] === ACTIVITY_OBJ_EVENT && isset($item['event-id'])) { @@ -1236,51 +1241,27 @@ function prepare_body(array &$item, $attach = false, $is_preview = false) return $ev; } - $taglist = dba::p("SELECT `type`, `term`, `url` FROM `term` WHERE `otype` = ? AND `oid` = ? AND `type` IN (?, ?) ORDER BY `tid`", - intval(TERM_OBJ_POST), intval($item['id']), intval(TERM_HASHTAG), intval(TERM_MENTION)); - - while ($tag = dba::fetch($taglist)) { - if ($tag["url"] == "") { - $tag["url"] = $searchpath . strtolower($tag["term"]); - } - - $orig_tag = $tag["url"]; - - $tag["url"] = best_link_url($item, $sp, $tag["url"]); - - if ($tag["type"] == TERM_HASHTAG) { - if ($orig_tag != $tag["url"]) { - $item['body'] = str_replace($orig_tag, $tag["url"], $item['body']); - } - - $hashtags[] = "#" . $tag["term"] . ""; - $prefix = "#"; - } elseif ($tag["type"] == TERM_MENTION) { - $mentions[] = "@" . $tag["term"] . ""; - $prefix = "@"; - } - - $tags[] = $prefix . "" . $tag["term"] . ""; - } - dba::close($taglist); + $tags = \Friendica\Model\Term::populateTagsFromItem($item); - $item['tags'] = $tags; - $item['hashtags'] = $hashtags; - $item['mentions'] = $mentions; + $item['tags'] = $tags['tags']; + $item['hashtags'] = $tags['hashtags']; + $item['mentions'] = $tags['mentions']; // Compile eventual content filter reasons $filter_reasons = []; - if (!empty($item['content-warning']) && !PConfig::get(local_user(), 'social', 'disable_cw')) { - $filter_reasons[] = L10n::t('Content warning: %s', $item['content-warning']); - } + 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']); + } - $hook_data = [ - 'item' => $item, - 'filter_reasons' => $filter_reasons - ]; - Addon::callHooks('content_filter', $hook_data); - $filter_reasons = $hook_data['filter_reasons']; - unset($hook_data); + $hook_data = [ + 'item' => $item, + 'filter_reasons' => $filter_reasons + ]; + Addon::callHooks('prepare_body_content_filter', $hook_data); + $filter_reasons = $hook_data['filter_reasons']; + unset($hook_data); + } // Update the cached values if there is no "zrl=..." on the links. $update = (!local_user() && !remote_user() && ($item["uid"] == 0)); @@ -1430,18 +1411,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 = ' -

' . - 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;