]> git.mxchange.org Git - friendica.git/commitdiff
Use alias for profile link in reshare
authorMichael <heluecht@pirati.ca>
Fri, 18 Apr 2025 04:22:56 +0000 (04:22 +0000)
committerMichael <heluecht@pirati.ca>
Sun, 18 May 2025 10:53:14 +0000 (10:53 +0000)
src/Content/Text/BBCode.php
src/Protocol/ATProtocol/Processor.php

index d111437dffc71f16f75cf3a71ab7640c4c2688e4..55a46b88aa8811382429d0edc778aa91f7c5504b 100644 (file)
@@ -913,13 +913,18 @@ class BBCode
                        default:
                                $text = ($is_quote_share ? "\n" : '');
 
-                               $contact = Contact::getByURL($attributes['profile'], false, ['network']);
+                               $contact = Contact::getByURL($attributes['profile'], false, ['network', 'url', 'alias']);
                                $network = $contact['network'] ?? Protocol::PHANTOM;
+                               if (!empty($contact)) {
+                                       $profile = Contact::getProfileLink($contact);
+                               } else {
+                                       $profile = $attributes['profile'];
+                               }
 
                                $gsid = ContactSelector::getServerIdForProfile($attributes['profile']);
                                $tpl  = Renderer::getMarkupTemplate('shared_content.tpl');
                                $text .= self::SHARED_ANCHOR . Renderer::replaceMacros($tpl, [
-                                       '$profile'      => $attributes['profile'],
+                                       '$profile'      => $profile,
                                        '$avatar'       => $attributes['avatar'],
                                        '$author'       => $attributes['author'],
                                        '$link'         => $attributes['link'],
@@ -1984,12 +1989,25 @@ class BBCode
                                '<a href="$2" class="mention hashtag" rel="tag">$1<span>$3</span></a>',
                                $text
                        );
-               } elseif (in_array($simple_html, [self::INTERNAL, self::EXTERNAL, self::TWITTER_API])) {
+               } elseif (in_array($simple_html, [self::EXTERNAL, self::TWITTER_API])) {
                        $text = preg_replace(
                                "/([@!])\[url\=(.*?)\](.*?)\[\/url\]/ism",
                                '<bdi>$1<a href="$2" class="userinfo mention" title="$3">$3</a></bdi>',
                                $text
                        );
+               } elseif ($simple_html == self::INTERNAL) {
+                       if (preg_match_all("/([@!])\[url\=(.*?)\](.*?)\[\/url\]/ism", $text, $matches, PREG_SET_ORDER)) {
+                               foreach ($matches as $match) {
+                                       $contact = Contact::getByURL($match[2], false, ['network', 'url', 'alias']);
+                                       if (!empty($contact)) {
+                                               $url = Contact::getProfileLink($contact);
+                                       } else {
+                                               $url = $match[2];
+                                       }
+                                       $text = str_replace($match[0], '<bdi>' . $match[1] . '<a href="' . $url . '" class="userinfo mention" title="' . $match[3] . '">' . $match[3] . '</a></bdi>', $text);
+                               }
+
+                       }
                } elseif ($simple_html == self::MASTODON_API) {
                        $text = preg_replace(
                                "/([@!])\[url\=(.*?)\](.*?)\[\/url\]/ism",
index 2c0e2528c5a5cd648d137c93922a66236d126b1e..1ac2a9f00cce820e8c13c79bc31ff7401b323a8a 100755 (executable)
@@ -506,13 +506,10 @@ class Processor
                                                break;
 
                                        case 'app.bsky.richtext.facet#mention':
-                                               $contact = Contact::getByURL($feature->did, null, ['id']);
-                                               if (!empty($contact['id'])) {
-                                                       $url = $this->baseURL . '/contact/' . $contact['id'];
-                                                       if (substr($linktext, 0, 1) == '@') {
-                                                               $prefix .= '@';
-                                                               $linktext = substr($linktext, 1);
-                                                       }
+                                               $url = $feature->did;
+                                               if (substr($linktext, 0, 1) == '@') {
+                                                       $prefix .= '@';
+                                                       $linktext = substr($linktext, 1);
                                                }
                                                break;