Merge pull request #8813 from annando/issue-8807

Issue 8807: Improved feed detecting
This commit is contained in:
Hypolite Petovan 2020-06-25 17:04:50 -04:00 committed by GitHub
commit 7822238fe0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -341,28 +341,27 @@ class Probe
$uid = local_user(); $uid = local_user();
} }
if (empty($network) || ($network == Protocol::ACTIVITYPUB)) {
$ap_profile = ActivityPub::probeProfile($uri, !$cache);
} else {
$ap_profile = [];
}
self::$istimeout = false; self::$istimeout = false;
if ($network != Protocol::ACTIVITYPUB) { if ($network != Protocol::ACTIVITYPUB) {
$data = self::detect($uri, $network, $uid); $data = self::detect($uri, $network, $uid, $ap_profile);
if (!is_array($data)) { if (!is_array($data)) {
$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))) { if (empty($data) || (!empty($ap_profile) && empty($network) && (($data['network'] ?? '') != Protocol::DFRN))) {
$data = $ap_profile; $data = $ap_profile;
} elseif (!empty($ap_profile)) { } elseif (!empty($ap_profile)) {
$ap_profile['batch'] = ''; $ap_profile['batch'] = '';
$data = array_merge($ap_profile, $data); $data = array_merge($ap_profile, $data);
} }
} else {
$data = $ap_profile;
} }
if (!isset($data['url'])) { 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. * 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 $uri Address that should be probed
* @param string $network Test for this specific network * @param string $network Test for this specific network
* @param integer $uid User ID for the probe (only used for mails) * @param integer $uid User ID for the probe (only used for mails)
* @param array $ap_profile Previously probed AP profile
* *
* @return array uri data * @return array uri data
* @throws HTTPException\InternalServerErrorException * @throws HTTPException\InternalServerErrorException
*/ */
private static function detect($uri, $network, $uid) private static function detect(string $uri, string $network, int $uid, array $ap_profile)
{ {
$hookData = [ $hookData = [
'uri' => $uri, 'uri' => $uri,
@ -749,7 +749,7 @@ class Probe
if ((!$result && ($network == "")) || ($network == Protocol::PUMPIO)) { if ((!$result && ($network == "")) || ($network == Protocol::PUMPIO)) {
$result = self::pumpio($webfinger, $addr); $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); $result = self::feed($uri);
} else { } else {
// We overwrite the detected nick with our try if the previois routines hadn't detected it. // We overwrite the detected nick with our try if the previois routines hadn't detected it.
@ -1874,12 +1874,6 @@ class Probe
$data["url"] = $url; $data["url"] = $url;
$data["poll"] = $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; $data["network"] = Protocol::FEED;
return $data; return $data;