<?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\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();
}
/**
}
$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)) {