From 4d986526f93197ddc622b585374cc59d35949d07 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 25 Jun 2020 20:29:21 +0000 Subject: [PATCH 1/2] Issue 8807: Improved feed detecting --- src/Network/Probe.php | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/src/Network/Probe.php b/src/Network/Probe.php index b1f4f233a6..60f085fb09 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -341,28 +341,27 @@ class Probe $uid = local_user(); } + if (empty($network) || ($network == Protocol::ACTIVITYPUB)) { + $ap_profile = ActivityPub::probeProfile($uri, !$cache); + } else { + $ap_profile = []; + } + self::$istimeout = false; if ($network != Protocol::ACTIVITYPUB) { - $data = self::detect($uri, $network, $uid); + $data = self::detect($uri, $network, $uid, $ap_profile); if (!is_array($data)) { $data = []; } - } else { - $data = []; - } - - // When the previous detection process had got a time out - // we could falsely detect a Friendica profile as AP profile. - if (!self::$istimeout && (empty($network) || $network == Protocol::ACTIVITYPUB)) { - $ap_profile = ActivityPub::probeProfile($uri, !$cache); - if (empty($data) || (!empty($ap_profile) && empty($network) && (($data['network'] ?? '') != Protocol::DFRN))) { $data = $ap_profile; } elseif (!empty($ap_profile)) { $ap_profile['batch'] = ''; $data = array_merge($ap_profile, $data); } + } else { + $data = $ap_profile; } if (!isset($data['url'])) { @@ -663,14 +662,15 @@ class Probe * * This function is only called by the "uri" function that adds caching and rearranging of data. * - * @param string $uri Address that should be probed - * @param string $network Test for this specific network - * @param integer $uid User ID for the probe (only used for mails) + * @param string $uri Address that should be probed + * @param string $network Test for this specific network + * @param integer $uid User ID for the probe (only used for mails) + * @param array $ap_profile Previously probed AP profile * * @return array uri data * @throws HTTPException\InternalServerErrorException */ - private static function detect($uri, $network, $uid) + private static function detect(string $uri, string $network, int $uid, array $ap_profile) { $hookData = [ 'uri' => $uri, @@ -749,7 +749,8 @@ class Probe if ((!$result && ($network == "")) || ($network == Protocol::PUMPIO)) { $result = self::pumpio($webfinger, $addr); } - if ((!$result && ($network == "")) || ($network == Protocol::FEED)) { + + if (empty($result['network']) && empty($ap_profile['network']) || ($network == Protocol::FEED)) { $result = self::feed($uri); } else { // We overwrite the detected nick with our try if the previois routines hadn't detected it. @@ -1874,12 +1875,6 @@ class Probe $data["url"] = $url; $data["poll"] = $url; - if (!empty($feed_data["header"]["author-link"])) { - $data["baseurl"] = $feed_data["header"]["author-link"]; - } else { - $data["baseurl"] = $data["url"]; - } - $data["network"] = Protocol::FEED; return $data; From d8f9bb1e0a47e331a75b6f2f37ae8e1a14b4e9b2 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 25 Jun 2020 20:41:34 +0000 Subject: [PATCH 2/2] Unify code structure --- src/Network/Probe.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Network/Probe.php b/src/Network/Probe.php index 60f085fb09..879ccf7fef 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -749,7 +749,6 @@ class Probe if ((!$result && ($network == "")) || ($network == Protocol::PUMPIO)) { $result = self::pumpio($webfinger, $addr); } - if (empty($result['network']) && empty($ap_profile['network']) || ($network == Protocol::FEED)) { $result = self::feed($uri); } else {