X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FGServer.php;h=f68851af6826b945cdc25f392a7381a5636c7db8;hb=feb74b4d9aeecbcac2b81cd6f0e0c8cfde1464f3;hp=a128060f4c1694388b8c5f2b83c83856155c8a31;hpb=7676aa790867d9d37f0996483140f505408fd665;p=friendica.git diff --git a/src/Model/GServer.php b/src/Model/GServer.php index a128060f4c..f68851af68 100644 --- a/src/Model/GServer.php +++ b/src/Model/GServer.php @@ -177,9 +177,13 @@ class GServer public static function reachable(string $profile, string $server = '', string $network = '', bool $force = false): bool { if ($server == '') { - $contact = Contact::getByURL($profile, null, ['baseurl']); + $contact = Contact::getByURL($profile, null, ['baseurl', 'network']); if (!empty($contact['baseurl'])) { $server = $contact['baseurl']; + } elseif ($contact['network'] == Protocol::DIASPORA) { + $parts = parse_url($profile); + unset($parts['path']); + $server = (string)Uri::fromParts($parts); } } @@ -314,25 +318,20 @@ class GServer /** * Remove unwanted content from the given URL * - * @param string $url + * @param string $dirtyUrl * * @return string cleaned URL + * @throws Exception */ - public static function cleanURL(string $url): string + public static function cleanURL(string $dirtyUrl): string { - $url = trim($url, '/'); - $url = str_replace('/index.php', '', $url); - - $urlparts = parse_url($url); - if (empty($urlparts)) { + try { + $url = str_replace('/index.php', '', trim($dirtyUrl, '/')); + return (string)(new Uri($url))->withUserInfo('')->withQuery('')->withFragment(''); + } catch (\Throwable $e) { + Logger::warning('Invalid URL', ['dirtyUrl' => $dirtyUrl, 'url' => $url]); return ''; } - - unset($urlparts['user']); - unset($urlparts['pass']); - unset($urlparts['query']); - unset($urlparts['fragment']); - return (string)Uri::fromParts($urlparts); } /**