]> git.mxchange.org Git - friendica.git/commitdiff
Fix for Mastodon falsely adding previews to mentions
authorMichael <heluecht@pirati.ca>
Thu, 22 Jul 2021 04:50:01 +0000 (04:50 +0000)
committerMichael <heluecht@pirati.ca>
Thu, 22 Jul 2021 04:50:01 +0000 (04:50 +0000)
src/Content/Text/BBCode.php
src/Protocol/ActivityPub/Transmitter.php

index 177d6480812bbbd120cac41f7b1c5ec08c2a1e05..44a6189d9d5533bc0a916e75ab7fba5eb57d9d2d 100644 (file)
@@ -1748,32 +1748,35 @@ class BBCode
                                        }
                                }
 
-                               if (!$for_plaintext) {
-                                       if (in_array($simple_html, [self::OSTATUS, self::API, self::ACTIVITYPUB])) {
-                                               $text = preg_replace_callback("/\[url\](.*?)\[\/url\]/ism", 'self::convertUrlForActivityPubCallback', $text);
-                                               $text = preg_replace_callback("/\[url\=(.*?)\](.*?)\[\/url\]/ism", 'self::convertUrlForActivityPubCallback', $text);
-                                       }
-                               } else {
-                                       $text = preg_replace("(\[url\](.*?)\[\/url\])ism", " $1 ", $text);
-                                       $text = preg_replace_callback("&\[url=([^\[\]]*)\]\[img\](.*)\[\/img\]\[\/url\]&Usi", 'self::removePictureLinksCallback', $text);
-                               }
-
-                               // Remove all hashtag addresses
-                               if ($simple_html && !in_array($simple_html, [self::DIASPORA, self::OSTATUS, self::ACTIVITYPUB])) {
-                                       $text = preg_replace("/([#@!])\[url\=(.*?)\](.*?)\[\/url\]/ism", '$1$3', $text);
-                               } elseif ($simple_html == self::DIASPORA) {
+                               // Handle mentions and hashtag links
+                               if ($simple_html == self::DIASPORA) {
                                        // The ! is converted to @ since Diaspora only understands the @
                                        $text = preg_replace("/([@!])\[url\=(.*?)\](.*?)\[\/url\]/ism",
                                                '@<a href="$2">$3</a>',
                                                $text);
                                } elseif (in_array($simple_html, [self::OSTATUS, self::ACTIVITYPUB])) {
                                        $text = preg_replace("/([@!])\[url\=(.*?)\](.*?)\[\/url\]/ism",
-                                               '$1<span class="vcard"><a href="$2" class="url u-url mention" title="$3"><span class="fn nickname mention">$3</span></a></span>',
+                                               '<span class="h-card"><a href="$2" class="u-url mention">$1<span>$3</span></a></span>',
+                                               $text);
+                                       $text = preg_replace("/([#])\[url\=(.*?)\](.*?)\[\/url\]/ism",
+                                               '<a href="$2" class="mention hashtag" rel="tag">$1<span>$3</span></a>',
                                                $text);
-                               } elseif (!$simple_html) {
+                               } elseif (in_array($simple_html, [self::INTERNAL, self::EXTERNAL, self::API])) {
                                        $text = preg_replace("/([@!])\[url\=(.*?)\](.*?)\[\/url\]/ism",
                                                '<bdi>$1<a href="$2" class="userinfo mention" title="$3">$3</a></bdi>',
                                                $text);
+                               } else {
+                                       $text = preg_replace("/([#@!])\[url\=(.*?)\](.*?)\[\/url\]/ism", '$1$3', $text);
+                               }
+                               
+                               if (!$for_plaintext) {
+                                       if (in_array($simple_html, [self::OSTATUS, self::API, self::ACTIVITYPUB])) {
+                                               $text = preg_replace_callback("/\[url\](.*?)\[\/url\]/ism", 'self::convertUrlForActivityPubCallback', $text);
+                                               $text = preg_replace_callback("/\[url\=(.*?)\](.*?)\[\/url\]/ism", 'self::convertUrlForActivityPubCallback', $text);
+                                       }
+                               } else {
+                                       $text = preg_replace("(\[url\](.*?)\[\/url\])ism", " $1 ", $text);
+                                       $text = preg_replace_callback("&\[url=([^\[\]]*)\]\[img\](.*)\[\/img\]\[\/url\]&Usi", 'self::removePictureLinksCallback', $text);
                                }
 
                                // Bookmarks in red - will be converted to bookmarks in friendica
index a65ebc8cda8ab1ff202860c9b6414b3630336972..53c060e87d4ceed9ba23e21e770cb0d12cd7dd4d 100644 (file)
@@ -1356,12 +1356,12 @@ class Transmitter
                        return '';
                }
 
-               $data = Contact::getByURL($match[1], false, ['url', 'alias', 'nick']);
+               $data = Contact::getByURL($match[1], false, ['url', 'nick']);
                if (empty($data['nick'])) {
                        return $match[0];
                }
 
-               return '[url=' . $data['url'] . ']@' . $data['nick'] . '[/url]';
+               return '@[url=' . $data['url'] . ']' . $data['nick'] . '[/url]';
        }
 
        /**