X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FAPContact.php;h=69f9be5135095d3df00c0eb35dcc58073dc94c50;hb=624e4c192c7f837ac0587a50da6e1409081eb519;hp=7bdde60c65ca31be4446c4009378bb1a9446d3f5;hpb=d2408c1f1b73127d90a7563604d81323784f09c7;p=friendica.git diff --git a/src/Model/APContact.php b/src/Model/APContact.php index 7bdde60c65..69f9be5135 100644 --- a/src/Model/APContact.php +++ b/src/Model/APContact.php @@ -1,6 +1,6 @@ $addr]; $template = 'https://' . $addr_parts[1] . '/.well-known/webfinger?resource=acct:' . urlencode($addr); - $webfinger = Probe::webfinger(str_replace('{uri}', urlencode($addr), $template), 'application/jrd+json'); + $webfinger = Probe::webfinger(str_replace('{uri}', urlencode($addr), $template), HttpClientAccept::JRD_JSON); if (empty($webfinger['links'])) { $template = 'http://' . $addr_parts[1] . '/.well-known/webfinger?resource=acct:' . urlencode($addr); - $webfinger = Probe::webfinger(str_replace('{uri}', urlencode($addr), $template), 'application/jrd+json'); + $webfinger = Probe::webfinger(str_replace('{uri}', urlencode($addr), $template), HttpClientAccept::JRD_JSON); if (empty($webfinger['links'])) { return []; } @@ -118,7 +119,8 @@ class APContact */ public static function getByURL($url, $update = null) { - if (empty($url)) { + if (empty($url) || Network::isUrlBlocked($url)) { + Logger::info('Domain is blocked', ['url' => $url]); return []; } @@ -166,7 +168,7 @@ class APContact // Detect multiple fast repeating request to the same address // See https://github.com/friendica/friendica/issues/9303 - $cachekey = 'apcontact:getByURL:' . $url; + $cachekey = 'apcontact:' . ItemURI::getIdByURI($url); $result = DI::cache()->get($cachekey); if (!is_null($result)) { Logger::notice('Multiple requests for the address', ['url' => $url, 'update' => $update, 'callstack' => System::callstack(20), 'result' => $result]); @@ -178,8 +180,12 @@ class APContact } if (Network::isLocalLink($url) && ($local_uid = User::getIdForURL($url))) { - $data = Transmitter::getProfile($local_uid); - $local_owner = User::getOwnerDataById($local_uid); + try { + $data = Transmitter::getProfile($local_uid); + $local_owner = User::getOwnerDataById($local_uid); + } catch(HTTPException\NotFoundException $e) { + $data = null; + } } if (empty($data)) { @@ -225,6 +231,9 @@ class APContact self::unarchiveInbox($apcontact['sharedinbox'], true); } + $apcontact['featured'] = JsonLD::fetchElement($compacted, 'toot:featured', '@id'); + $apcontact['featured-tags'] = JsonLD::fetchElement($compacted, 'toot:featuredTags', '@id'); + $apcontact['nick'] = JsonLD::fetchElement($compacted, 'as:preferredUsername', '@value') ?? ''; $apcontact['name'] = JsonLD::fetchElement($compacted, 'as:name', '@value'); @@ -232,7 +241,21 @@ class APContact $apcontact['name'] = $apcontact['nick']; } - $apcontact['about'] = HTML::toBBCode(JsonLD::fetchElement($compacted, 'as:summary', '@value')); + $aboutHtml = JsonLD::fetchElement($compacted, 'as:summary', '@value'); + $apcontact['about'] = (!empty($aboutHtml) ? HTML::toBBCode($aboutHtml) : ''); + + $ims = JsonLD::fetchElementArray($compacted, 'vcard:hasInstantMessage'); + + if (!empty($ims)) { + foreach ($ims as $link) { + if (substr($link, 0, 5) == 'xmpp:') { + $apcontact['xmpp'] = substr($link, 5); + } + if (substr($link, 0, 7) == 'matrix:') { + $apcontact['matrix'] = substr($link, 7); + } + } + } $apcontact['photo'] = JsonLD::fetchElement($compacted, 'as:icon', '@id'); if (is_array($apcontact['photo']) || !empty($compacted['as:icon']['as:url']['@id'])) { @@ -330,6 +353,11 @@ class APContact $outbox = ActivityPub::fetchContent($apcontact['outbox']); } if (!empty($outbox['totalItems'])) { + // Mastodon seriously allows for this condition? + // Jul 20 2021 - See https://chaos.social/@m11 for a negative posts count + if ($outbox['totalItems'] < 0) { + $outbox['totalItems'] = 0; + } $apcontact['statuses_count'] = $outbox['totalItems']; } } @@ -339,7 +367,7 @@ class APContact // To-Do // Unhandled - // tag, attachment, image, nomadicLocations, signature, featured, movedTo, liked + // tag, attachment, image, nomadicLocations, signature, movedTo, liked // Unhandled from Misskey // sharedInbox, isCat @@ -405,6 +433,30 @@ class APContact $apcontact['uri-id'] = ItemURI::insert(['uri' => $apcontact['url'], 'guid' => $apcontact['uuid']]); } + foreach (APContact\Endpoint::ENDPOINT_NAMES as $type => $name) { + $value = JsonLD::fetchElement($compacted, $name, '@id'); + if (empty($value)) { + continue; + } + APContact\Endpoint::update($apcontact['uri-id'], $type, $value); + } + + if (!empty($compacted['as:endpoints'])) { + foreach ($compacted['as:endpoints'] as $name => $endpoint) { + if (empty($endpoint['@id']) || !is_string($endpoint['@id'])) { + continue; + } + + if (in_array($name, APContact\Endpoint::ENDPOINT_NAMES)) { + $key = array_search($name, APContact\Endpoint::ENDPOINT_NAMES); + APContact\Endpoint::update($apcontact['uri-id'], $key, $endpoint['@id']); + Logger::debug('Store endpoint', ['key' => $key, 'name' => $name, 'endpoint' => $endpoint['@id']]); + } elseif (!in_array($name, ['as:sharedInbox', 'as:uploadMedia', 'as:oauthTokenEndpoint', 'as:oauthAuthorizationEndpoint', 'litepub:oauthRegistrationEndpoint'])) { + Logger::debug('Unknown endpoint', ['name' => $name, 'endpoint' => $endpoint['@id']]); + } + } + } + $apcontact['updated'] = DateTimeFormat::utcNow(); // We delete the old entry when the URL is changed