]> git.mxchange.org Git - friendica.git/commitdiff
Issue 2657: Mentions will now be recognized by clients
authorMichael <heluecht@pirati.ca>
Sun, 6 Nov 2022 05:43:34 +0000 (05:43 +0000)
committerMichael <heluecht@pirati.ca>
Sun, 6 Nov 2022 05:43:34 +0000 (05:43 +0000)
src/Content/Text/BBCode.php
src/Module/Api/Mastodon/Accounts/Search.php
src/Module/Api/Mastodon/Search.php

index 2ed4e57b3cecb9d55a05bf33582783eb35531435..a9c137b6a0de46f704a29e2715fb805629328368 100644 (file)
@@ -1971,13 +1971,20 @@ class BBCode
                                        $text = preg_replace("/([#])\[url\=(.*?)\](.*?)\[\/url\]/ism",
                                                '<a href="$2" class="mention hashtag" rel="tag">$1<span>$3</span></a>',
                                                $text);
-                               } elseif (in_array($simple_html, [self::INTERNAL, self::EXTERNAL, self::API])) {
+                               } elseif (in_array($simple_html, [self::INTERNAL, self::EXTERNAL])) {
                                        $text = preg_replace("/([@!])\[url\=(.*?)\](.*?)\[\/url\]/ism",
                                                '<bdi>$1<a href="$2" class="userinfo mention" title="$3">$3</a></bdi>',
                                                $text);
                                        $text = preg_replace("/([#])\[url\=(.*?)\](.*?)\[\/url\]/ism",
                                                '<a class="mention hashtag status-link" href="$2" rel="tag">$1<span>$3</span></a>',
                                                $text);
+                               } elseif ($simple_html == self::API) {
+                                       $text = preg_replace("/([@!])\[url\=(.*?)\](.*?)\[\/url\]/ism",
+                                               '<a class="u-url mention status-link" href="$2" rel="nofollow noopener noreferrer" target="_blank" title="$3">$1<span>$3</span></a>',
+                                               $text);
+                                       $text = preg_replace("/([#])\[url\=(.*?)\](.*?)\[\/url\]/ism",
+                                               '<a class="mention hashtag status-link" href="$2" rel="tag">$1<span>$3</span></a>',
+                                               $text);
                                } else {
                                        $text = preg_replace("/([#@!])\[url\=(.*?)\](.*?)\[\/url\]/ism", '$1$3', $text);
                                }
index 71f6f82dab74fe2002ab03148307a7cb9938a769..5e8e647ea509b658cb6dd7a89f4fb8df4f52d3b1 100644 (file)
@@ -52,27 +52,15 @@ class Search extends BaseApi
 
                $accounts = [];
 
-               if ($request['resolve']) {
-                       if ((strrpos($request['q'], '@') > 0) || Network::isValidHttpUrl($request['q'])) {
-                               $results = CoreSearch::getContactsFromProbe($request['q']);
-                       }
-
-                       if (!empty($results)) {
-                               $counter = 0;
-                               foreach ($results->getResults() as $result) {
-                                       if (++$counter > $request['limit']) {
-                                               continue;
-                                       }
-                                       if ($result instanceof ContactResult) {
-                                               $id = Contact::getIdForURL($result->getUrl(), 0, false);
+               if ((strrpos($request['q'], '@') > 0) || Network::isValidHttpUrl($request['q'])) {
+                       $id = Contact::getIdForURL($request['q'], 0, $request['resolve'] ? null : false);
 
-                                               $accounts[] = DI::mstdnAccount()->createFromContactId($id, $uid);
-                                       }
-                               }
+                       if (!empty($id)) {
+                               $accounts[] = DI::mstdnAccount()->createFromContactId($id, $uid);
                        }
                }
 
-               if (count($accounts) < $request['limit']) {
+               if (empty($accounts)) {
                        $contacts = Contact::searchByName($request['q'], '', $request['following'] ? $uid : 0, $request['limit']);
                        foreach ($contacts as $contact) {
                                $accounts[] = DI::mstdnAccount()->createFromContactId($contact['id'], $uid);
index b21ff50f29d8a7f6a5094a915b9a7c41f2911fc8..3a4999242ec3124e082702bc61345a8846560b2b 100644 (file)
@@ -84,28 +84,16 @@ class Search extends BaseApi
        {
                $accounts = [];
 
-               if ($resolve) {
-                       if ((strrpos($q, '@') > 0) || Network::isValidHttpUrl($q)) {
-                               $results = CoreSearch::getContactsFromProbe($q);
-                       }
+               if ((strrpos($q, '@') > 0) || Network::isValidHttpUrl($q)) {
+                       $id = Contact::getIdForURL($q, 0, $resolve ? null : false);
 
-                       if (!empty($results)) {
-                               $counter = 0;
-                               foreach ($results->getResults() as $result) {
-                                       if (++$counter > $limit) {
-                                               continue;
-                                       }
-                                       if ($result instanceof ContactResult) {
-                                               $id = Contact::getIdForURL($result->getUrl(), 0, false);
-
-                                               $accounts[] = DI::mstdnAccount()->createFromContactId($id, $uid);
-                                       }
-                               }
+                       if (!empty($id)) {
+                               $accounts[] = DI::mstdnAccount()->createFromContactId($id, $uid);
                        }
                }
 
-               if (count($accounts) < $limit) {
-                       $contacts = Contact::searchByName($q, '', $following ? $uid : 0, $limit - count($accounts), $offset);
+               if (empty($accounts)) {
+                       $contacts = Contact::searchByName($q, '', $following ? $uid : 0, $limit, $offset);
                        foreach ($contacts as $contact) {
                                $accounts[] = DI::mstdnAccount()->createFromContactId($contact['id'], $uid);
                        }