Issue 8675: reduce requests of foreign pages

This commit is contained in:
Michael 2020-06-01 21:52:31 +00:00
parent 4a363b50b4
commit e379698227
7 changed files with 51 additions and 47 deletions

View file

@ -22,6 +22,7 @@
namespace Friendica\Network;
use Friendica\Core\Logger;
use Friendica\Core\System;
use Friendica\Network\HTTPException\InternalServerErrorException;
use Friendica\Util\Network;
@ -166,7 +167,7 @@ class CurlResult
}
if (!$this->isSuccess) {
Logger::log('error: ' . $this->url . ': ' . $this->returnCode . ' - ' . $this->error, Logger::INFO);
Logger::error('error', ['url' => $this->url, 'code' => $this->returnCode, 'error' => $this->error, 'callstack' => System::callstack(20)]);
Logger::log('debug: ' . print_r($this->info, true), Logger::DATA);
}

View file

@ -85,7 +85,7 @@ class Probe
{
$fields = ["name", "nick", "guid", "url", "addr", "alias", "photo", "account-type",
"community", "keywords", "location", "about", "hide",
"batch", "notify", "poll", "request", "confirm", "poco",
"batch", "notify", "poll", "request", "confirm", "subscribe", "poco",
"following", "followers", "inbox", "outbox", "sharedinbox",
"priority", "network", "pubkey", "baseurl", "gsid"];
@ -270,37 +270,15 @@ class Probe
return $profile_link;
}
/**
* Get the link for the remote follow page for a given profile link
*
* @param sting $profile
* @return string Remote follow page link
*/
public static function getRemoteFollowLink(string $profile)
{
$follow_link = '';
$links = self::lrdd($profile);
if (!empty($links) && is_array($links)) {
foreach ($links as $link) {
if ($link['@attributes']['rel'] === ActivityNamespace::OSTATUSSUB) {
$follow_link = $link['@attributes']['template'];
}
}
}
return $follow_link;
}
/**
* Check an URI for LRDD data
*
* @param string $uri Address that should be probed
* @param string $uri Address that should be probed
*
* @return array uri data
* @throws HTTPException\InternalServerErrorException
*/
public static function lrdd($uri)
public static function lrdd(string $uri)
{
$lrdd = self::hostMeta($uri);
$webfinger = null;
@ -423,7 +401,9 @@ class Probe
$ap_profile = ActivityPub::probeProfile($uri);
if (empty($data) || (!empty($ap_profile) && empty($network) && (($data['network'] ?? '') != Protocol::DFRN))) {
$subscribe = $data['subscribe'];
$data = $ap_profile;
$data['subscribe'] = $subscribe;
} elseif (!empty($ap_profile)) {
$ap_profile['batch'] = '';
$data = array_merge($ap_profile, $data);
@ -597,6 +577,28 @@ class Probe
return $webfinger;
}
/**
* Fetch the "subscribe" and add it to the result
*
* @param array $result
* @param array $webfinger
* @return array result
*/
private static function getSubscribeLink(array $result, array $webfinger)
{
if (empty($webfinger['links'])) {
return $result;
}
foreach ($webfinger['links'] as $link) {
if ($link['rel'] === ActivityNamespace::OSTATUSSUB) {
$result['subscribe'] = $link['template'];
}
}
return $result;
}
/**
* Fetch information (protocol endpoints and user information) about a given uri
*
@ -720,7 +722,7 @@ class Probe
$result = false;
Logger::log("Probing ".$uri, Logger::DEBUG);
Logger::info("Probing", ['uri' => $uri]);
if (in_array($network, ["", Protocol::DFRN])) {
$result = self::dfrn($webfinger);
@ -751,6 +753,8 @@ class Probe
}
}
$result = self::getSubscribeLink($result, $webfinger);
if (empty($result["network"])) {
$result["network"] = Protocol::PHANTOM;
}