<?php
/**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2022, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
use Friendica\Model\GServer;
use Friendica\Model\Profile;
use Friendica\Model\User;
+use Friendica\Network\HTTPClient\Client\HttpClient;
use Friendica\Network\HTTPClient\Client\HttpClientOptions;
use Friendica\Protocol\ActivityNamespace;
use Friendica\Protocol\ActivityPub;
use Friendica\Util\Network;
use Friendica\Util\Strings;
use Friendica\Util\XML;
+use GuzzleHttp\Psr7\Uri;
/**
* This class contain functions for probing URL
/**
* Remove stuff from an URI that doesn't belong there
*
- * @param string $URI
+ * @param string $rawUri
* @return string Cleaned URI
*/
- public static function cleanURI(string $URI)
+ public static function cleanURI(string $rawUri): string
{
// At first remove leading and trailing junk
- $URI = trim($URI, "@#?:/ \t\n\r\0\x0B");
+ $rawUri = trim($rawUri, "@#?:/ \t\n\r\0\x0B");
- $parts = parse_url($URI);
-
- if (empty($parts['scheme'])) {
- return $URI;
+ $uri = new Uri($rawUri);
+ if (!$uri->getScheme()) {
+ return $uri->__toString();
}
// Remove the URL fragment, since these shouldn't be part of any profile URL
- unset($parts['fragment']);
-
- $URI = Network::unparseURL($parts);
+ $uri = $uri->withFragment('');
- return $URI;
+ return $uri->__toString();
}
/**
$path_parts = explode('/', trim($parts['path'] ?? '', '/'));
if (!empty($path_parts)) {
$nick = ltrim(end($path_parts), '@');
- // When the last part of the URI is numeric then it is most likely an ID and not a nick name
- if (!is_numeric($nick)) {
- $addr = $nick . '@' . $host;
- } else {
- $nick = '';
- }
+ $addr = $nick . '@' . $host;
}
- $webfinger = self::getWebfinger($parts['scheme'] . '://' . $host . self::WEBFINGER, 'application/jrd+json', $uri, $addr);
+ $webfinger = self::getWebfinger($parts['scheme'] . '://' . $host . self::WEBFINGER, HttpClient::ACCEPT_JRD_JSON, $uri, $addr);
if (empty($webfinger)) {
$lrdd = self::hostMeta($host);
}
$addr = $nick . '@' . $host;
}
- $webfinger = self::getWebfinger($parts['scheme'] . '://' . $host . self::WEBFINGER, 'application/jrd+json', $uri, $addr);
+ $webfinger = self::getWebfinger($parts['scheme'] . '://' . $host . self::WEBFINGER, HttpClient::ACCEPT_JRD_JSON, $uri, $addr);
if (empty($webfinger)) {
$lrdd = self::hostMeta($host);
}
$nick = substr($uri, 0, strpos($uri, '@'));
$addr = $uri;
- $webfinger = self::getWebfinger('https://' . $host . self::WEBFINGER, 'application/jrd+json', $uri, $addr);
+ $webfinger = self::getWebfinger('https://' . $host . self::WEBFINGER, HttpClient::ACCEPT_JRD_JSON, $uri, $addr);
if (self::$istimeout) {
return [];
}
if (empty($webfinger)) {
- $webfinger = self::getWebfinger('http://' . $host . self::WEBFINGER, 'application/jrd+json', $uri, $addr);
+ $webfinger = self::getWebfinger('http://' . $host . self::WEBFINGER, HttpClient::ACCEPT_JRD_JSON, $uri, $addr);
if (self::$istimeout) {
return [];
}
}
$parts = parse_url($uri);
-
- if (empty($parts['scheme']) || !empty($parts['host']) && strstr($uri, '@')) {
- // If the URI starts with "mailto:" then jump directly to the mail detection
- if (strpos($uri, 'mailto:') !== false) {
- $uri = str_replace('mailto:', '', $uri);
- return self::mail($uri, $uid);
- }
-
- if ($network == Protocol::MAIL) {
- return self::mail($uri, $uid);
- }
- } else {
+ if (empty($parts['scheme']) && empty($parts['host']) && !strstr($parts['path'], '@')) {
Logger::info('URI was not detectable', ['uri' => $uri]);
return [];
}
+ // If the URI starts with "mailto:" then jump directly to the mail detection
+ if (strpos($uri, 'mailto:') !== false) {
+ $uri = str_replace('mailto:', '', $uri);
+ return self::mail($uri, $uid);
+ }
+
+ if ($network == Protocol::MAIL) {
+ return self::mail($uri, $uid);
+ }
+
Logger::info('Probing start', ['uri' => $uri]);
if (!empty($ap_profile['addr']) && ($ap_profile['addr'] != $uri)) {
/**
* Fetch the last date that the contact had posted something (publically)
*
- * @param string $data probing result
+ * @param array $data probing result
* @return string last activity
*/
public static function getLastUpdate(array $data)