private static $baseurl;
/**
- * @var boolean Whether a timeout has occured
+ * @var boolean Whether a timeout has occurred
*/
private static $isTimeout;
$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])) {
*/
private static function ownHost(string $host): bool
{
- $own_host = DI::baseUrl()->getHostname();
+ $own_host = DI::baseUrl()->getHost();
$parts = parse_url($host);
* @param string $uri Address that should be probed
* @param string $network Test for this specific network
* @param integer $uid User ID for the probe (only used for mails)
- * @param boolean $cache Use cached values?
*
* @return array uri data
* @throws HTTPException\InternalServerErrorException
$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.
+ // We overwrite the detected nick with our try if the previous routines hadn't detected it.
// Additionally, it is overwritten when the nickname doesn't make sense (contains spaces).
if ((empty($result['nick']) || (strstr($result['nick'], ' '))) && ($nick != '')) {
$result['nick'] = $nick;
*/
public static function webfinger(string $url, string $type): array
{
- $xrd_timeout = DI::config()->get('system', 'xrd_timeout', 20);
+ try {
+ $curlResult = DI::httpClient()->get(
+ $url,
+ $type,
+ [HttpClientOptions::TIMEOUT => DI::config()->get('system', 'xrd_timeout', 20)]
+ );
+ } catch (\Throwable $e) {
+ Logger::notice($e->getMessage(), ['url' => $url, 'type' => $type, 'class' => get_class($e)]);
+ return [];
+ }
- $curlResult = DI::httpClient()->get($url, $type, [HttpClientOptions::TIMEOUT => $xrd_timeout]);
if ($curlResult->isTimeout()) {
self::$isTimeout = true;
return [];
$data = self::pollHcard($profile_link, $data, true);
}
- $prof_data = [];
if (empty($data['addr']) || empty($data['nick'])) {
$probe_data = self::uri($profile_link);
$data['nick'] = ($data['nick'] ?? '') ?: $probe_data['nick'];
}
- $prof_data['addr'] = $data['addr'];
- $prof_data['nick'] = $data['nick'];
- $prof_data['dfrn-request'] = $data['request'] ?? null;
- $prof_data['dfrn-confirm'] = $data['confirm'] ?? null;
- $prof_data['dfrn-notify'] = $data['notify'] ?? null;
- $prof_data['dfrn-poll'] = $data['poll'] ?? null;
- $prof_data['photo'] = $data['photo'] ?? null;
- $prof_data['fn'] = $data['name'] ?? null;
- $prof_data['key'] = $data['pubkey'] ?? null;
+ $prof_data = [
+ 'addr' => $data['addr'],
+ 'nick' => $data['nick'],
+ 'dfrn-request' => $data['request'] ?? null,
+ 'dfrn-confirm' => $data['confirm'] ?? null,
+ 'dfrn-notify' => $data['notify'] ?? null,
+ 'dfrn-poll' => $data['poll'] ?? null,
+ 'photo' => $data['photo'] ?? null,
+ 'fn' => $data['name'] ?? null,
+ 'key' => $data['pubkey'] ?? null,
+ ];
Logger::debug('Result', ['link' => $profile_link, 'data' => $prof_data]);
if (!empty($feed_data['header']['author-about'])) {
$data['about'] = $feed_data['header']['author-about'];
}
- // OStatus has serious issues when the the url doesn't fit (ssl vs. non ssl)
+ // OStatus has serious issues when the url doesn't fit (ssl vs. non ssl)
// So we take the value that we just fetched, although the other one worked as well
if (!empty($feed_data['header']['author-link'])) {
$data['url'] = $feed_data['header']['author-link'];
*
* @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())) {
}
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);
}
}
}
*
* @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 [];
]
];
} catch (Exception $e) {
- // Default values for non existing targets
+ // Default values for nonexistent targets
$data = [
'name' => $url, 'nick' => $url, 'url' => $url, 'network' => Protocol::PHANTOM,
'photo' => DI::baseUrl() . Contact::DEFAULT_AVATAR_PHOTO