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;
}
// 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']);
$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])) {
* @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);
$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;
}
*
* @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())) {
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'];
+ }
}
}
}
*
* @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
return [];
}
- $profile_data = self::pumpioProfileData($data['url']);
+ $profile_data = self::pumpioProfileData($data['url'], $baseurl);
if (!$profile_data) {
return [];
*/
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);