]> git.mxchange.org Git - friendica.git/commitdiff
Ensure url property of Probe::uri result is used authoritatively
authorHypolite Petovan <hypolite@mrpetovan.com>
Thu, 25 Jun 2020 00:57:47 +0000 (20:57 -0400)
committerHypolite Petovan <hypolite@mrpetovan.com>
Fri, 26 Jun 2020 16:52:39 +0000 (12:52 -0400)
- Some profile URLs aren't canonical and need to be updated during probe

mod/dfrn_request.php
mod/follow.php
mod/ostatus_subscribe.php
src/Model/Contact.php
src/Model/GContact.php
src/Model/Mail.php
src/Module/Acctlink.php
src/Protocol/OStatus.php

index 0be8403c2bfbec4031a5ae57adde17be2b5c49e9..06c81a084e1600f7e1b563fa5432810a1ef00f75 100644 (file)
@@ -297,8 +297,8 @@ function dfrn_request_post(App $a)
                $data = Probe::uri($url);
                $network = $data["network"];
 
-               // Canonicalise email-style profile locator
-               $url = Probe::webfingerDfrn($url, $hcard);
+               // Canonicalize email-style profile locator
+               $url = Probe::webfingerDfrn($data['url'], $hcard);
 
                if (substr($url, 0, 5) === 'stat:') {
                        // Every time we detect the remote subscription we define this as OStatus.
index 8910f54c0c086ebb1cdeaf3f579ac9b514e8f3ec..e4aecb8a2d3f66d5ac29cc851aa6b0e3d2731899 100644 (file)
@@ -129,7 +129,7 @@ function follow_content(App $a)
 
        if ($protocol == Protocol::PHANTOM) {
                // Possibly it is a remote item and not an account
-               follow_remote_item($url);
+               follow_remote_item($ret['url']);
 
                notice(DI::l10n()->t("The network type couldn't be detected. Contact can't be added."));
                $submit = '';
index e5c4fa7b0161016ded2e621e58b1c0d63fa8fd47..64774eead9fc5a4ede2f612baa200457667018be 100644 (file)
@@ -48,7 +48,6 @@ function ostatus_subscribe_content(App $a)
                }
 
                $contact = Probe::uri($_REQUEST['url']);
-
                if (!$contact) {
                        DI::pConfig()->delete($uid, 'ostatus', 'legacy_contact');
                        return $o . DI::l10n()->t('Couldn\'t fetch information for contact.');
@@ -91,7 +90,7 @@ function ostatus_subscribe_content(App $a)
 
        $probed = Probe::uri($url);
        if ($probed['network'] == Protocol::OSTATUS) {
-               $result = Contact::createFromProbe($a->user, $url, true, Protocol::OSTATUS);
+               $result = Contact::createFromProbe($a->user, $probed['url'], true, Protocol::OSTATUS);
                if ($result['success']) {
                        $o .= ' - ' . DI::l10n()->t('success');
                } else {
index e3fc2d334d8e1d38b79e858e76daf0780626248b..e83a11f8210913d9ebb4b5a404b7e97c3eae91cd 100644 (file)
@@ -1572,7 +1572,7 @@ class Contact
                        $data['gsid'] = GServer::getID($data['baseurl']);
                }
 
-               if (!$contact_id && !empty($data['alias']) && ($data['alias'] != $url) && !$in_loop) {
+               if (!$contact_id && !empty($data['alias']) && ($data['alias'] != $data['url']) && !$in_loop) {
                        $contact_id = self::getIdForURL($data["alias"], $uid, true, $default, true);
                }
 
@@ -2353,11 +2353,11 @@ class Contact
                $condition = ['uid' => $user['uid'], 'poll' => [$ret['poll'], Strings::normaliseLink($ret['poll'])], 'network' => $ret['network'], 'pending' => false];
                $contact = DBA::selectFirst('contact', ['id', 'rel'], $condition);
                if (!DBA::isResult($contact)) {
-                       $condition = ['uid' => $user['uid'], 'nurl' => Strings::normaliseLink($url), 'network' => $ret['network'], 'pending' => false];
+                       $condition = ['uid' => $user['uid'], 'nurl' => Strings::normaliseLink($ret['url']), 'network' => $ret['network'], 'pending' => false];
                        $contact = DBA::selectFirst('contact', ['id', 'rel'], $condition);
                }
 
-               $protocol = self::getProtocol($url, $ret['network']);
+               $protocol = self::getProtocol($ret['url'], $ret['network']);
 
                if (($protocol === Protocol::DFRN) && !DBA::isResult($contact)) {
                        if ($interactive) {
@@ -2394,7 +2394,7 @@ class Contact
                        if (empty($ret['url'])) {
                                $result['message'] .= DI::l10n()->t('No browser URL could be matched to this address.') . EOL;
                        }
-                       if (strpos($url, '@') !== false) {
+                       if (strpos($ret['url'], '@') !== false) {
                                $result['message'] .= DI::l10n()->t('Unable to match @-style Identity Address with a known protocol or email contact.') . EOL;
                                $result['message'] .= DI::l10n()->t('Use mailto: in front of address to force email check.') . EOL;
                        }
@@ -2418,7 +2418,7 @@ class Contact
 
                $pending = false;
                if ($protocol == Protocol::ACTIVITYPUB) {
-                       $apcontact = APContact::getByURL($url, false);
+                       $apcontact = APContact::getByURL($ret['url'], false);
                        if (isset($apcontact['manually-approve'])) {
                                $pending = (bool)$apcontact['manually-approve'];
                        }
index fb4df9a63ae834d0bbab4dde8c0409859702a36f..02834ba31fcd778148f0d43f992de89dcc472c94 100644 (file)
@@ -230,8 +230,6 @@ class GContact
                                throw new Exception('Probing for URL ' . $gcontact['url'] . ' failed');
                        }
 
-                       $orig_profile = $gcontact['url'];
-
                        $gcontact['server_url'] = $data['baseurl'];
 
                        $gcontact = array_merge($gcontact, $data);
index 848b419bef88affa4a7a4504e2b9c1f8b94f1c47..098c200292c109cf23b9c5720948d9335816b6a2 100644 (file)
@@ -268,7 +268,6 @@ class Mail
                $uri = Item::newURI(local_user(), $guid);
 
                $me = Probe::uri($replyto);
-
                if (!$me['name']) {
                        return -2;
                }
@@ -277,8 +276,8 @@ class Mail
 
                $recip_handle = $recipient['nickname'] . '@' . substr(DI::baseUrl(), strpos(DI::baseUrl(), '://') + 3);
 
-               $sender_nick = basename($replyto);
-               $sender_host = substr($replyto, strpos($replyto, '://') + 3);
+               $sender_nick = basename($me['url']);
+               $sender_host = substr($me['url'], strpos($me['url'], '://') + 3);
                $sender_host = substr($sender_host, 0, strpos($sender_host, '/'));
                $sender_handle = $sender_nick . '@' . $sender_host;
 
@@ -313,7 +312,7 @@ class Mail
                                'reply' => 0,
                                'replied' => 0,
                                'uri' => $uri,
-                               'parent-uri' => $replyto,
+                               'parent-uri' => $me['url'],
                                'created' => DateTimeFormat::utcNow(),
                                'unknown' => 1
                        ]
index bcd5e19f84bfcf56642b70acdc1d8219a8759cd3..f80ea4c73c9d32e353fa9a67ac57023a096c874a 100644 (file)
@@ -36,7 +36,6 @@ class Acctlink extends BaseModule
 
                if ($addr) {
                        $url = Probe::uri($addr)['url'] ?? '';
-
                        if ($url) {
                                System::externalRedirect($url);
                                exit();
index 2720d6050ff5324d4c66ad327382826207b6cbac..0b9a45fc3b4082c8e0e1034791466ca8555e61c4 100644 (file)
@@ -1829,11 +1829,12 @@ class OStatus
                $item["private"] = Item::PRIVATE;
 
                $contact = Probe::uri($item['follow']);
+               $item['follow'] = $contact['url'];
 
-               if ($contact['alias'] == '') {
-                       $contact['alias'] = $contact["url"];
-               } else {
+               if ($contact['alias']) {
                        $item['follow'] = $contact['alias'];
+               } else {
+                       $contact['alias'] = $contact['url'];
                }
 
                $condition = ['uid' => $owner['uid'], 'nurl' => Strings::normaliseLink($contact["url"])];