]> git.mxchange.org Git - friendica.git/commitdiff
Fix mentions for the summary
authorMichael <heluecht@pirati.ca>
Sat, 10 Apr 2021 21:13:37 +0000 (21:13 +0000)
committerMichael <heluecht@pirati.ca>
Sat, 10 Apr 2021 21:13:37 +0000 (21:13 +0000)
src/Protocol/ActivityPub/Transmitter.php

index 65a3c9167abb9ce07d0ad5f421c0ccd1ca7dfc10..3a6cf56bdffe4727366bfadfd589764fcf1b69a5 100644 (file)
@@ -1333,6 +1333,27 @@ class Transmitter
                return '[url=' . $data['url'] . ']@' . $data['nick'] . '[/url]';
        }
 
+       /**
+        * Callback function to replace a Friendica style mention in a mention for a summary
+        *
+        * @param array $match Matching values for the callback
+        * @return string Replaced mention
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+        */
+       private static function mentionAddrCallback($match)
+       {
+               if (empty($match[1])) {
+                       return '';
+               }
+
+               $data = Contact::getByURL($match[1], false, ['addr', 'nick']);
+               if (empty($data['addr'])) {
+                       return $match[0];
+               }
+
+               return '@' . $data['addr'];
+       }
+
        /**
         * Remove image elements since they are added as attachment
         *
@@ -1495,7 +1516,9 @@ class Transmitter
                if ($type == 'Note') {
                        $body = $item['raw-body'] ?? self::removePictures($body);
                } elseif (($type == 'Article') && empty($data['summary'])) {
-                       $data['summary'] = BBCode::toPlaintext(Plaintext::shorten(self::removePictures($body), 1000));
+                       $regexp = "/[@!]\[url\=([^\[\]]*)\].*?\[\/url\]/ism";
+                       $summary = preg_replace_callback($regexp, ['\Friendica\Protocol\ActivityPub\Transmitter', 'mentionAddrCallback'], $body);
+                       $data['summary'] = BBCode::toPlaintext(Plaintext::shorten(self::removePictures($summary), 1000));
                }
 
                if (empty($item['uid']) || !Feature::isEnabled($item['uid'], 'explicit_mentions')) {