]> git.mxchange.org Git - friendica.git/blobdiff - include/text.php
Move suppress_tags config to template
[friendica.git] / include / text.php
index 0aeaa7203be2a384f0a06d525dfc79bad5490b60..67ce7e65e83df258ae041296b951478453066ca6 100644 (file)
@@ -14,6 +14,7 @@ use Friendica\Core\L10n;
 use Friendica\Core\PConfig;
 use Friendica\Core\System;
 use Friendica\Database\DBM;
+use Friendica\Model\Event;
 use Friendica\Model\Item;
 use Friendica\Model\Profile;
 use Friendica\Render\FriendicaSmarty;
@@ -21,7 +22,6 @@ use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Map;
 
 require_once "mod/proxy.php";
-require_once "include/event.php";
 require_once "include/conversation.php";
 
 /**
@@ -1062,7 +1062,7 @@ function linkify($s) {
  * Load poke verbs
  *
  * @return array index is present tense verb
                               value is array containing past tense verb, translation of present, translation of past
*                              value is array containing past tense verb, translation of present, translation of past
  * @hook poke_verbs pokes array
  */
 function get_poke_verbs() {
@@ -1169,8 +1169,25 @@ function redir_private_images($a, &$item)
        }
 }
 
+/**
+ * Sets the "rendered-html" field of the provided item
+ *
+ * Body is preserved to avoid side-effects as we modify it just-in-time for spoilers and private image links
+ *
+ * @param array $item
+ * @param bool  $update
+ *
+ * @todo Remove reference, simply return "rendered-html" and "rendered-hash"
+ */
 function put_item_in_cache(&$item, $update = false)
 {
+       $body = $item["body"];
+
+       // Add the content warning
+       if (!empty($item['content-warning'])) {
+               $item["body"] = $item['content-warning'] . '[spoiler]' . $item["body"] . '[/spoiler]';
+       }
+
        $rendered_hash = defaults($item, 'rendered-hash', '');
 
        if ($rendered_hash == ''
@@ -1178,27 +1195,19 @@ function put_item_in_cache(&$item, $update = false)
                || $rendered_hash != hash("md5", $item["body"])
                || Config::get("system", "ignore_cache")
        ) {
-               // The function "redir_private_images" changes the body.
-               // I'm not sure if we should store it permanently, so we save the old value.
-               $body = $item["body"];
-
-               // Add the content warning
-               if (!empty($item['content-warning'])) {
-                       $item["body"] = $item['content-warning'] . '[spoiler]' . $item["body"] . '[/spoiler]';
-               }
-
                $a = get_app();
                redir_private_images($a, $item);
 
                $item["rendered-html"] = prepare_text($item["body"]);
                $item["rendered-hash"] = hash("md5", $item["body"]);
-               $item["body"] = $body;
 
                if ($update && ($item["id"] > 0)) {
                        dba::update('item', ['rendered-html' => $item["rendered-html"], 'rendered-hash' => $item["rendered-hash"]],
                                        ['id' => $item["id"]], false);
                }
        }
+
+       $item["body"] = $body;
 }
 
 /**
@@ -1226,37 +1235,37 @@ function prepare_body(&$item, $attach = false, $preview = false) {
        // In order to provide theme developers more possibilities, event items
        // are treated differently.
        if ($item['object-type'] === ACTIVITY_OBJ_EVENT && isset($item['event-id'])) {
-               $ev = format_event_item($item);
+               $ev = Event::getItemHTML($item);
                return $ev;
        }
 
-       if (!Config::get('system','suppress_tags')) {
-               $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));
+       $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"]);
-                       }
+       while ($tag = dba::fetch($taglist)) {
+               if ($tag["url"] == "") {
+                       $tag["url"] = $searchpath . strtolower($tag["term"]);
+               }
 
-                       $orig_tag = $tag["url"];
+               $orig_tag = $tag["url"];
 
-                       $tag["url"] = best_link_url($item, $sp, $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[] = "#<a href=\"".$tag["url"]."\" target=\"_blank\">".$tag["term"]."</a>";
-                               $prefix = "#";
-                       } elseif ($tag["type"] == TERM_MENTION) {
-                               $mentions[] = "@<a href=\"".$tag["url"]."\" target=\"_blank\">".$tag["term"]."</a>";
-                               $prefix = "@";
+               if ($tag["type"] == TERM_HASHTAG) {
+                       if ($orig_tag != $tag["url"]) {
+                               $item['body'] = str_replace($orig_tag, $tag["url"], $item['body']);
                        }
-                       $tags[] = $prefix."<a href=\"".$tag["url"]."\" target=\"_blank\">".$tag["term"]."</a>";
+
+                       $hashtags[] = "#<a href=\"" . $tag["url"] . "\" target=\"_blank\">" . $tag["term"] . "</a>";
+                       $prefix = "#";
+               } elseif ($tag["type"] == TERM_MENTION) {
+                       $mentions[] = "@<a href=\"" . $tag["url"] . "\" target=\"_blank\">" . $tag["term"] . "</a>";
+                       $prefix = "@";
                }
-               dba::close($taglist);
+
+               $tags[] = $prefix . "<a href=\"" . $tag["url"] . "\" target=\"_blank\">" . $tag["term"] . "</a>";
        }
+       dba::close($taglist);
 
        $item['tags'] = $tags;
        $item['hashtags'] = $hashtags;