]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/Contact/Follow.php
Merge pull request #13310 from MrPetovan/bug/13217-mirroring-blocked
[friendica.git] / src / Module / Contact / Follow.php
index f3d4a386f8ba9eb8502b3a51a18ba7231847857b..0199aca78f46f455c85f6cc8506e74177428b018 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2022, the Friendica project
+ * @copyright Copyright (C) 2010-2023, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -40,6 +40,7 @@ use Friendica\Network\HTTPException\ForbiddenException;
 use Friendica\Network\Probe;
 use Friendica\Util\Profiler;
 use Friendica\Util\Strings;
+use GuzzleHttp\Psr7\Uri;
 use Psr\Log\LoggerInterface;
 
 class Follow extends BaseModule
@@ -88,7 +89,9 @@ class Follow extends BaseModule
                }
 
                $uid = $this->session->getLocalUserId();
-               $url = Probe::cleanURI(trim($request['url'] ?? ''));
+
+               // uri is used by the /authorize_interaction Mastodon route
+               $url = Probe::cleanURI(trim($request['uri'] ?? $request['url'] ?? ''));
 
                // Issue 6874: Allow remote following from Peertube
                if (strpos($url, 'acct:') === 0) {
@@ -103,11 +106,10 @@ class Follow extends BaseModule
 
                // Don't try to add a pending contact
                $userContact = Contact::selectFirst(['pending'], [
-                       "`uid` = ? AND ((`rel` != ?) OR (`network` = ?)) AND (`nurl` = ? OR `alias` = ? OR `alias` = ?) AND `network` != ?",
+                       "`uid` = ? AND ((`rel` != ?) OR (`network` = ?)) AND (`nurl` = ? OR `alias` = ? OR `alias` = ?)",
                        $uid, Contact::FOLLOWER, Protocol::DFRN,
                        Strings::normaliseLink($url),
-                       Strings::normaliseLink($url), $url,
-                       Protocol::STATUSNET]);
+                       Strings::normaliseLink($url), $url]);
 
                if (!empty($userContact['pending'])) {
                        $this->sysMessages->addNotice($this->t('You already added this contact.'));
@@ -151,7 +153,7 @@ class Follow extends BaseModule
                }
 
                $requestUrl = $this->baseUrl . '/contact/follow';
-               $tpl     = Renderer::getMarkupTemplate('auto_request.tpl');
+               $tpl        = Renderer::getMarkupTemplate('auto_request.tpl');
 
                $owner = User::getOwnerDataById($uid);
                if (empty($owner)) {
@@ -170,7 +172,7 @@ class Follow extends BaseModule
                        '$submit'         => $submit,
                        '$cancel'         => $this->t('Cancel'),
 
-                       '$request'  => $requestUrl,
+                       '$action'   => $requestUrl,
                        '$name'     => $contact['name'],
                        '$url'      => $contact['url'],
                        '$zrl'      => Profile::zrl($contact['url']),
@@ -187,7 +189,7 @@ class Follow extends BaseModule
                        $this->page['aside'] = VCard::getHTML($contact);
 
                        $output .= Renderer::replaceMacros(Renderer::getMarkupTemplate('section_title.tpl'),
-                               ['$title' => $this->t('Status Messages and Posts')]
+                               ['$title' => $this->t('Posts and Replies')]
                        );
 
                        // Show last public posts
@@ -222,17 +224,26 @@ class Follow extends BaseModule
 
        protected function followRemoteItem(string $url)
        {
-               $itemId = Item::fetchByLink($url, $this->session->getLocalUserId());
-               if (!$itemId) {
-                       // If the user-specific search failed, we search and probe a public post
-                       $itemId = Item::fetchByLink($url);
-               }
+               try {
+                       $uri = new Uri($url);
+                       if (!$uri->getScheme()) {
+                               return;
+                       }
+
+                       $itemId = Item::fetchByLink($url, $this->session->getLocalUserId());
+                       if (!$itemId) {
+                               // If the user-specific search failed, we search and probe a public post
+                               $itemId = Item::fetchByLink($url);
+                       }
 
-               if (!empty($itemId)) {
-                       $item = Post::selectFirst(['guid'], ['id' => $itemId]);
-                       if (!empty($item['guid'])) {
-                               $this->baseUrl->redirect('display/' . $item['guid']);
+                       if (!empty($itemId)) {
+                               $item = Post::selectFirst(['guid'], ['id' => $itemId]);
+                               if (!empty($item['guid'])) {
+                                       $this->baseUrl->redirect('display/' . $item['guid']);
+                               }
                        }
+               } catch (\InvalidArgumentException $e) {
+                       return;
                }
        }
 }