From: Michael Vogel Date: Fri, 27 Jan 2023 07:27:20 +0000 (+0100) Subject: Merge pull request #12736 from MrPetovan/bug/12733-webfinger-apcontact X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=1d7d6fe35c3a8c32762b7dbd454acbdc6bf7c247;hp=-c;p=friendica.git Merge pull request #12736 from MrPetovan/bug/12733-webfinger-apcontact Replace custom WebFinger implementation by Probe::getWebfingerArray in APContact::fetchWebfingerData --- 1d7d6fe35c3a8c32762b7dbd454acbdc6bf7c247 diff --combined src/Model/APContact.php index 072dea9d3e,c72028ef31..1fedfc0c79 --- a/src/Model/APContact.php +++ b/src/Model/APContact.php @@@ -71,21 -71,14 +71,14 @@@ class APContac return $data; } - $data = ['addr' => $addr]; - $template = 'https://' . $addr_parts[1] . '/.well-known/webfinger?resource=acct:' . urlencode($addr); - $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), HttpClientAccept::JRD_JSON); - if (empty($webfinger['links'])) { - return []; - } - $data['baseurl'] = 'http://' . $addr_parts[1]; - } else { - $data['baseurl'] = 'https://' . $addr_parts[1]; + $webfinger = Probe::getWebfingerArray($addr); + if (empty($webfinger['webfinger']['links'])) { + return []; } - foreach ($webfinger['links'] as $link) { + $data['baseurl'] = $webfinger['baseurl']; + + foreach ($webfinger['webfinger']['links'] as $link) { if (empty($link['rel'])) { continue; } @@@ -376,11 -369,6 +369,11 @@@ // Unhandled from Kroeg // kroeg:blocks, updated + if (!empty($apcontact['photo']) && !Network::isValidHttpUrl($apcontact['photo'])) { + Logger::info('Invalid URL for photo', ['url' => $apcontact['url'], 'photo' => $apcontact['photo']]); + $apcontact['photo'] = null; + } + // When the photo is too large, try to shorten it by removing parts if (strlen($apcontact['photo'] ?? '') > 255) { $parts = parse_url($apcontact['photo']); diff --combined src/Network/Probe.php index e1bedf5e53,12ac8a04f9..92e049ce39 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@@ -120,11 -120,6 +120,11 @@@ class Prob $numeric_fields = ['gsid', 'hide', 'account-type', 'manually-approve']; + if (!empty($data['photo']) && !Network::isValidHttpUrl($data['photo'])) { + Logger::info('Invalid URL for photo', ['url' => $data['url'], 'photo' => $data['photo']]); + unset($data['photo']); + } + $newdata = []; foreach ($fields as $field) { if (isset($data[$field])) { @@@ -524,7 -519,7 +524,7 @@@ * @return array Webfinger data * @throws HTTPException\InternalServerErrorException */ - private static function getWebfingerArray(string $uri): array + public static function getWebfingerArray(string $uri): array { $parts = parse_url($uri); @@@ -760,13 -755,13 +760,13 @@@ $result = self::zot($webfinger, $result, $baseurl); } if ((!$result && ($network == '')) || ($network == Protocol::PUMPIO)) { - $result = self::pumpio($webfinger, $addr); + $result = self::pumpio($webfinger, $addr, $baseurl); } 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. - // Additionally it is overwritten when the nickname doesn't make sense (contains spaces). + // Additionally, it is overwritten when the nickname doesn't make sense (contains spaces). if ((empty($result['nick']) || (strstr($result['nick'], ' '))) && ($nick != '')) { $result['nick'] = $nick; } @@@ -1640,7 -1635,7 +1640,7 @@@ * * @return array Profile data */ - private static function pumpioProfileData(string $profile_link): array + private static function pumpioProfileData(string $profile_link, string $baseurl): array { $curlResult = DI::httpClient()->get($profile_link, HttpClientAccept::HTML); if (!$curlResult->isSuccess() || empty($curlResult->getBody())) { @@@ -1686,9 -1681,6 +1686,9 @@@ foreach ($avatar->attributes as $attribute) { if ($attribute->name == 'src') { $data['photo'] = trim($attribute->value); + if (!empty($data['photo']) && !parse_url($data['photo'], PHP_URL_SCHEME) && !parse_url($data['photo'], PHP_URL_HOST)) { + $data['photo'] = $baseurl . $data['photo']; + } } } } @@@ -1704,7 -1696,7 +1704,7 @@@ * * @return array pump.io data */ - private static function pumpio(array $webfinger, string $addr): array + private static function pumpio(array $webfinger, string $addr, string $baseurl): array { $data = []; // The array is reversed to take into account the order of preference for same-rel links @@@ -1736,7 -1728,7 +1736,7 @@@ return []; } - $profile_data = self::pumpioProfileData($data['url']); + $profile_data = self::pumpioProfileData($data['url'], $baseurl); if (!$profile_data) { return []; @@@ -1861,11 -1853,18 +1861,18 @@@ */ private static function feed(string $url, bool $probe = true): array { - $curlResult = DI::httpClient()->get($url, HttpClientAccept::FEED_XML); + try { + $curlResult = DI::httpClient()->get($url, HttpClientAccept::FEED_XML); + } catch(\Throwable $e) { + DI::logger()->info('Error requesting feed URL', ['url' => $url, 'exception' => $e]); + return []; + } + if ($curlResult->isTimeout()) { self::$isTimeout = true; return []; } + $feed = $curlResult->getBody(); $feed_data = Feed::import($feed);