]> git.mxchange.org Git - friendica.git/blobdiff - src/Content/Text/BBCode.php
Avoid proxyfying images that are removed or replaced later
[friendica.git] / src / Content / Text / BBCode.php
index 32cd818cac690c29364802f70bc7df59dc9008d7..b1244d0ac3cd44255a15379bdf8b486bc388ad7b 100644 (file)
@@ -50,7 +50,7 @@ use Friendica\Util\XML;
 class BBCode
 {
        // Update this value to the current date whenever changes are made to BBCode::convert
-       const VERSION = '2021-05-01';
+       const VERSION = '2021-05-21';
 
        const INTERNAL = 0;
        const EXTERNAL = 1;
@@ -433,6 +433,10 @@ class BBCode
         */
        public static function toPlaintext($text, $keep_urls = true)
        {
+               // Remove pictures in advance to avoid unneeded proxy calls
+               $text = preg_replace("/\[img\=(.*?)\](.*?)\[\/img\]/ism", ' $2 ', $text);
+               $text = preg_replace("/\[img.*?\[\/img\]/ism", ' ', $text);
+
                $naked_text = HTML::toPlaintext(self::convert($text, false, 0, true), 0, !$keep_urls);
 
                return $naked_text;
@@ -953,6 +957,10 @@ class BBCode
         */
        public static function fetchShareAttributes($text)
        {
+               // See Issue https://github.com/friendica/friendica/issues/10454
+               // Hashtags in usernames are expanded to links. This here is a quick fix. 
+               $text = preg_replace('/([@!#])\[url\=.*?\](.*?)\[\/url\]/ism', '$1$2', $text);
+
                $attributes = [];
                if (!preg_match("/(.*?)\[share(.*?)\](.*)\[\/share\]/ism", $text, $matches)) {
                        return $attributes;
@@ -997,7 +1005,7 @@ class BBCode
                                        $attributes[$field] = html_entity_decode($matches[2] ?? '', ENT_QUOTES, 'UTF-8');
                                }
 
-                               $author_contact = Contact::getByURL($attributes['profile'], false, ['url', 'addr', 'name', 'micro']);
+                               $author_contact = Contact::getByURL($attributes['profile'], false, ['id', 'url', 'addr', 'name', 'micro']);
                                $author_contact['url'] = ($author_contact['url'] ?? $attributes['profile']);
                                $author_contact['addr'] = ($author_contact['addr'] ?? '') ?: Protocol::getAddrFromProfileUrl($attributes['profile']);
 
@@ -1005,8 +1013,10 @@ class BBCode
                                $attributes['avatar']   = ($author_contact['micro'] ?? '') ?: $attributes['avatar'];
                                $attributes['profile']  = ($author_contact['url']   ?? '') ?: $attributes['profile'];
 
-                               if ($attributes['avatar']) {
-                                       $attributes['avatar'] = ProxyUtils::proxifyUrl($attributes['avatar'], false, ProxyUtils::SIZE_THUMB);
+                               if (!empty($author_contact['id'])) {
+                                       $attributes['avatar'] = Contact::getAvatarUrlForId($author_contact['id'], ProxyUtils::SIZE_THUMB);
+                               } elseif ($attributes['avatar']) {
+                                       $attributes['avatar'] = ProxyUtils::proxifyUrl($attributes['avatar'], ProxyUtils::SIZE_THUMB);
                                }
 
                                $content = preg_replace(Strings::autoLinkRegEx(), '<a href="$1">$1</a>', $match[3]);
@@ -1039,7 +1049,9 @@ class BBCode
 
                switch ($simplehtml) {
                        case self::API:
-                               $text = ($is_quote_share? '<br>' : '') . '<p>' . html_entity_decode('&#x2672; ', ENT_QUOTES, 'UTF-8') . ' ' . $author_contact['addr'] . ': </p>' . "\n" . $content;
+                               $text = ($is_quote_share? '<br>' : '') .
+                               '<p><b><a href="' . $attributes['link'] . '">' . html_entity_decode('&#x2672; ', ENT_QUOTES, 'UTF-8') . ' ' . $author_contact['addr'] . "</a>:</b> </p>\n" .
+                               '<blockquote class="shared_content">' . $content . '</blockquote>';
                                break;
                        case self::DIASPORA:
                                if (stripos(Strings::normaliseLink($attributes['link']), 'http://twitter.com/') === 0) {
@@ -1721,7 +1733,7 @@ class BBCode
                                                $text);
                                } elseif (!$simple_html) {
                                        $text = preg_replace("/([@!])\[url\=(.*?)\](.*?)\[\/url\]/ism",
-                                               '$1<a href="$2" class="userinfo mention" title="$3"><bdi>$3</bdi></a>',
+                                               '<bdi>$1<a href="$2" class="userinfo mention" title="$3">$3</a></bdi>',
                                                $text);
                                }
 
@@ -2194,9 +2206,7 @@ class BBCode
                                        }
                                }
 
-                               $success = Item::replaceTag($body, $inform, $profile_uid, $tag, $network);
-
-                               if ($success['replaced']) {
+                               if (($success = Item::replaceTag($body, $inform, $profile_uid, $tag, $network)) && $success['replaced']) {
                                        $tagged[] = $tag;
                                }
                        }