]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Item.php
Merge pull request #6132 from annando/notice
[friendica.git] / src / Model / Item.php
index d6a6d02085e54a18b07ba207e09e0a7b78872dae..30c29e1518b18cea736de93613f6a9c9657abd3a 100644 (file)
@@ -33,6 +33,7 @@ use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Map;
 use Friendica\Util\XML;
 use Friendica\Util\Security;
+use Friendica\Util\Strings;
 use Text_LanguageDetect;
 
 require_once 'boot.php';
@@ -1149,7 +1150,7 @@ class Item extends BaseObject
        private static function guid($item, $notify)
        {
                if (!empty($item['guid'])) {
-                       return notags(trim($item['guid']));
+                       return Strings::escapeTags(trim($item['guid']));
                }
 
                if ($notify) {
@@ -1264,7 +1265,7 @@ class Item extends BaseObject
                }
 
                $item['guid'] = self::guid($item, $notify);
-               $item['uri'] = notags(trim(defaults($item, 'uri', self::newURI($item['uid'], $item['guid']))));
+               $item['uri'] = Strings::escapeTags(trim(defaults($item, 'uri', self::newURI($item['uid'], $item['guid']))));
 
                // Store URI data
                $item['uri-id'] = ItemURI::insert(['uri' => $item['uri'], 'guid' => $item['guid']]);
@@ -1534,7 +1535,7 @@ class Item extends BaseObject
                                Logger::log("Checking if parent ".$parent_id." has to be tagged as mention for user ".$item['uid'], Logger::DEBUG);
                                $user = DBA::selectFirst('user', ['nickname'], ['uid' => $item['uid']]);
                                if (DBA::isResult($user)) {
-                                       $self = normalise_link(System::baseUrl() . '/profile/' . $user['nickname']);
+                                       $self = Strings::normaliseLink(System::baseUrl() . '/profile/' . $user['nickname']);
                                        $self_id = Contact::getIdForURL($self, 0, true);
                                        Logger::log("'myself' is ".$self_id." for parent ".$parent_id." checking against ".$item['author-id']." and ".$item['owner-id'], Logger::DEBUG);
                                        if (($item['author-id'] == $self_id) || ($item['owner-id'] == $self_id)) {
@@ -2402,7 +2403,7 @@ class Item extends BaseObject
        public static function setHashtags(&$item)
        {
 
-               $tags = get_tags($item["body"]);
+               $tags = BBCode::getTags($item["body"]);
 
                // No hashtags?
                if (!count($tags)) {
@@ -2544,18 +2545,18 @@ class Item extends BaseObject
                        return;
                }
 
-               $link = normalise_link(System::baseUrl() . '/profile/' . $user['nickname']);
+               $link = Strings::normaliseLink(System::baseUrl() . '/profile/' . $user['nickname']);
 
                /*
                 * Diaspora uses their own hardwired link URL in @-tags
                 * instead of the one we supply with webfinger
                 */
-               $dlink = normalise_link(System::baseUrl() . '/u/' . $user['nickname']);
+               $dlink = Strings::normaliseLink(System::baseUrl() . '/u/' . $user['nickname']);
 
                $cnt = preg_match_all('/[\@\!]\[url\=(.*?)\](.*?)\[\/url\]/ism', $item['body'], $matches, PREG_SET_ORDER);
                if ($cnt) {
                        foreach ($matches as $mtch) {
-                               if (link_compare($link, $mtch[1]) || link_compare($dlink, $mtch[1])) {
+                               if (Strings::compareLink($link, $mtch[1]) || Strings::compareLink($dlink, $mtch[1])) {
                                        $mention = true;
                                        Logger::log('mention found: ' . $mtch[2]);
                                }
@@ -3297,7 +3298,7 @@ class Item extends BaseObject
                        || $rendered_hash != hash("md5", $item["body"])
                        || Config::get("system", "ignore_cache")
                ) {
-                       $a = get_app();
+                       $a = self::getApp();
                        redir_private_images($a, $item);
 
                        $item["rendered-html"] = prepare_text($item["body"]);
@@ -3348,7 +3349,7 @@ class Item extends BaseObject
         */
        public static function prepareBody(array &$item, $attach = false, $is_preview = false)
        {
-               $a = get_app();
+               $a = self::getApp();
                Addon::callHooks('prepare_body_init', $item);
 
                // In order to provide theme developers more possibilities, event items
@@ -3446,7 +3447,7 @@ class Item extends BaseObject
                                $filesubtype = 'unkn';
                        }
 
-                       $title = escape_tags(trim(!empty($mtch[4]) ? $mtch[4] : $mtch[1]));
+                       $title = Strings::escapeHtml(trim(!empty($mtch[4]) ? $mtch[4] : $mtch[1]));
                        $title .= ' ' . $mtch[2] . ' ' . L10n::t('bytes');
 
                        $icon = '<div class="attachtype icon s22 type-' . $filetype . ' subtype-' . $filesubtype . '"></div>';
@@ -3479,7 +3480,7 @@ class Item extends BaseObject
 
                while ((strpos($s, $spoilersearch) !== false)) {
                        $pos = strpos($s, $spoilersearch);
-                       $rnd = random_string(8);
+                       $rnd = Strings::getRandomHex(8);
                        $spoilerreplace = '<br /> <span id="spoiler-wrap-' . $rnd . '" class="spoiler-wrap fakelink" onclick="openClose(\'spoiler-' . $rnd . '\');">' . L10n::t('Click to open/close') . '</span>'.
                                                '<blockquote class="spoiler" id="spoiler-' . $rnd . '" style="display: none;">';
                        $s = substr($s, 0, $pos) . $spoilerreplace . substr($s, $pos + strlen($spoilersearch));
@@ -3490,14 +3491,14 @@ class Item extends BaseObject
 
                while ((strpos($s, $authorsearch) !== false)) {
                        $pos = strpos($s, $authorsearch);
-                       $rnd = random_string(8);
+                       $rnd = Strings::getRandomHex(8);
                        $authorreplace = '<br /> <span id="author-wrap-' . $rnd . '" class="author-wrap fakelink" onclick="openClose(\'author-' . $rnd . '\');">' . L10n::t('Click to open/close') . '</span>'.
                                                '<blockquote class="author" id="author-' . $rnd . '" style="display: block;">';
                        $s = substr($s, 0, $pos) . $authorreplace . substr($s, $pos + strlen($authorsearch));
                }
 
                // Replace friendica image url size with theme preference.
-               if (x($a->theme_info, 'item_image_size')) {
+               if (!empty($a->theme_info['item_image_size'])) {
                        $ps = $a->theme_info['item_image_size'];
                        $s = preg_replace('|(<img[^>]+src="[^"]+/photo/[0-9a-f]+)-[0-9]|', "$1-" . $ps, $s);
                }
@@ -3509,4 +3510,39 @@ class Item extends BaseObject
 
                return $hook_data['html'];
        }
+
+       /**
+        * get private link for item
+        * @param array $item
+        * @return boolean|array False if item has not plink, otherwise array('href'=>plink url, 'title'=>translated title)
+        */
+       public static function getPlink($item)
+       {
+               $a = self::getApp();
+
+               if ($a->user['nickname'] != "") {
+                       $ret = [
+                               'href' => "display/" . $item['guid'],
+                               'orig' => "display/" . $item['guid'],
+                               'title' => L10n::t('View on separate page'),
+                               'orig_title' => L10n::t('view on separate page'),
+                       ];
+
+                       if (!empty($item['plink'])) {
+                               $ret["href"] = $a->removeBaseURL($item['plink']);
+                               $ret["title"] = L10n::t('link to source');
+                       }
+
+               } elseif (!empty($item['plink']) && ($item['private'] != 1)) {
+                       $ret = [
+                               'href' => $item['plink'],
+                               'orig' => $item['plink'],
+                               'title' => L10n::t('link to source'),
+                       ];
+               } else {
+                       $ret = [];
+               }
+
+               return $ret;
+       }
 }