]> git.mxchange.org Git - friendica.git/blobdiff - src/Network/Probe.php
Merge pull request #8765 from annando/fix-pubkey
[friendica.git] / src / Network / Probe.php
index 241988dd53efb5dbbc68fcc14912ce9883974043..dcb0bf192f68b84a0574e3f9e5a79129fe18ab80 100644 (file)
@@ -536,50 +536,6 @@ class Probe
                return false;
        }
 
-       /**
-        * Checks if a profile url should be OStatus but only provides partial information
-        *
-        * @param array  $webfinger Webfinger data
-        * @param string $lrdd      Path template for webfinger request
-        * @param string $type      type
-        *
-        * @return array fixed webfinger data
-        * @throws HTTPException\InternalServerErrorException
-        */
-       private static function fixOStatus($webfinger, $lrdd, $type)
-       {
-               if (empty($webfinger['links']) || empty($webfinger['subject'])) {
-                       return $webfinger;
-               }
-
-               $is_ostatus = false;
-               $has_key = false;
-
-               foreach ($webfinger['links'] as $link) {
-                       if ($link['rel'] == ActivityNamespace::OSTATUSSUB) {
-                               $is_ostatus = true;
-                       }
-                       if ($link['rel'] == 'magic-public-key') {
-                               $has_key = true;
-                       }
-               }
-
-               if (!$is_ostatus || $has_key) {
-                       return $webfinger;
-               }
-
-               $url = Network::switchScheme($webfinger['subject']);
-               $path = str_replace('{uri}', urlencode($url), $lrdd);
-               $webfinger2 = self::webfinger($path, $type);
-
-               // Is the new webfinger detectable as OStatus?
-               if (self::ostatus($webfinger2, true)) {
-                       $webfinger = $webfinger2;
-               }
-
-               return $webfinger;
-       }
-
        /**
         * Fetch the "subscribe" and add it to the result
         *
@@ -706,30 +662,29 @@ class Probe
                                continue;
                        }
 
-                       // At first try it with the given uri
-                       $path = str_replace('{uri}', urlencode($uri), $template);
-                       $webfinger = self::webfinger($path, $type);
-
-                       // Fix possible problems with GNU Social probing to wrong scheme
-                       $webfinger = self::fixOStatus($webfinger, $template, $type);
-
-                       // We cannot be sure that the detected address was correct, so we don't use the values
-                       if ($webfinger && ($uri != $addr)) {
-                               $nick = "";
-                               $addr = "";
+                       // Try the URI first
+                       if ($uri != $addr) {
+                               $path = str_replace('{uri}', urlencode($uri), $template);
+                               $webfinger = self::webfinger($path, $type);
                        }
 
-                       // Try webfinger with the address (user@domain.tld)
+                       // Then try the address
                        if (!$webfinger) {
-                               $path = str_replace('{uri}', urlencode($addr), $template);
+                               $path = str_replace('{uri}', urlencode("acct:" . $addr), $template);
                                $webfinger = self::webfinger($path, $type);
                        }
 
-                       // Mastodon needs to have it with "acct:"
+                       // Finally try without the "acct"
                        if (!$webfinger) {
-                               $path = str_replace('{uri}', urlencode("acct:".$addr), $template);
+                               $path = str_replace('{uri}', urlencode($addr), $template);
                                $webfinger = self::webfinger($path, $type);
                        }
+
+                       // We cannot be sure that the detected address was correct, so we don't use the values
+                       if ($webfinger && ($uri != $addr)) {
+                               $nick = "";
+                               $addr = "";
+                       }
                }
 
                if (!$webfinger) {
@@ -781,13 +736,6 @@ class Probe
 
                Logger::log($uri." is ".$result["network"], Logger::DEBUG);
 
-               if (empty($result["baseurl"]) && ($result["network"] != Protocol::PHANTOM)) {
-                       $pos = strpos($result["url"], $host);
-                       if ($pos) {
-                               $result["baseurl"] = substr($result["url"], 0, $pos).$host;
-                       }
-               }
-
                return $result;
        }
 
@@ -1511,7 +1459,7 @@ class Probe
                                        && (($link["type"] ?? "") == "text/html")
                                        && ($link["href"] != "")
                                ) {
-                                       $data["url"] = $link["href"];
+                                       $data["url"] = $data["alias"] = $link["href"];
                                } elseif (($link["rel"] == "salmon") && !empty($link["href"])) {
                                        $data["notify"] = $link["href"];
                                } elseif (($link["rel"] == ActivityNamespace::FEED) && !empty($link["href"])) {
@@ -1594,8 +1542,7 @@ class Probe
                        $data["url"] = $feed_data["header"]["author-link"];
                }
 
-               if (($data['poll'] == $data['url']) && ($data["alias"] != '')) {
-                       $data['url'] = $data["alias"];
+               if ($data["url"] == $data["alias"]) {
                        $data["alias"] = '';
                }
 
@@ -1730,8 +1677,6 @@ class Probe
         */
        private static function twitter($uri)
        {
-               self::$baseurl = '';
-
                if (preg_match('=(.*)@twitter.com=i', $uri, $matches)) {
                        $nick = $matches[1];
                } elseif (preg_match('=https?://twitter.com/(.*)=i', $uri, $matches)) {