]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/GServer.php
Don't perform a delivery to failing servers
[friendica.git] / src / Model / GServer.php
index a128060f4c1694388b8c5f2b83c83856155c8a31..f68851af6826b945cdc25f392a7381a5636c7db8 100644 (file)
@@ -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);
        }
 
        /**