X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FNetwork%2FProbe.php;h=88c256fe08d9975046423a67887672424b95bee9;hb=f8018f8dfe0183ce7c8f7e8460e0d9fbd5b9395b;hp=d35490d0d366f7e4ab2b91c10b957e56649345b6;hpb=4faf08c0643d3e6bbe2a0a77be2ff8c1dbea4d5c;p=friendica.git diff --git a/src/Network/Probe.php b/src/Network/Probe.php index d35490d0d3..88c256fe08 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -120,6 +120,15 @@ class Probe $numeric_fields = ['gsid', 'hide', 'account-type', 'manually-approve']; + if (!empty($data['photo'])) { + $data['photo'] = Network::addBasePath($data['photo'], $data['url']); + + if (!Network::isValidHttpUrl($data['photo'])) { + Logger::warning('Invalid URL for photo', ['url' => $data['url'], 'photo' => $data['photo']]); + unset($data['photo']); + } + } + $newdata = []; foreach ($fields as $field) { if (isset($data[$field])) { @@ -169,7 +178,7 @@ class Probe */ private static function ownHost(string $host): bool { - $own_host = DI::baseUrl()->getHostname(); + $own_host = DI::baseUrl()->getHost(); $parts = parse_url($host); @@ -519,7 +528,7 @@ class Probe * @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); @@ -755,13 +764,13 @@ class Probe $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; } @@ -1635,7 +1644,7 @@ class Probe * * @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())) { @@ -1679,8 +1688,8 @@ class Probe } if ($avatar) { foreach ($avatar->attributes as $attribute) { - if ($attribute->name == 'src') { - $data['photo'] = trim($attribute->value); + if (($attribute->name == 'src') && !empty($attribute->value)) { + $data['photo'] = Network::addBasePath($attribute->value, $baseurl); } } } @@ -1696,7 +1705,7 @@ class Probe * * @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 @@ -1728,7 +1737,7 @@ class Probe return []; } - $profile_data = self::pumpioProfileData($data['url']); + $profile_data = self::pumpioProfileData($data['url'], $baseurl); if (!$profile_data) { return []; @@ -1853,11 +1862,18 @@ class Probe */ 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);