]> 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 d4545e72583a018368138b55819f75b2b9281b2e..dcb0bf192f68b84a0574e3f9e5a79129fe18ab80 100644 (file)
@@ -441,7 +441,7 @@ class Probe
                        }
                }
 
-               if (!empty(self::$baseurl)) {
+               if (empty($data['baseurl']) && !empty(self::$baseurl)) {
                        $data['baseurl'] = self::$baseurl;
                }
 
@@ -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
         *
@@ -594,7 +550,7 @@ class Probe
                }
 
                foreach ($webfinger['links'] as $link) {
-                       if ($link['rel'] === ActivityNamespace::OSTATUSSUB) {
+                       if (!empty($link['template']) && ($link['rel'] === ActivityNamespace::OSTATUSSUB)) {
                                $result['subscribe'] = $link['template'];
                        }
                }
@@ -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"] = '';
                }
 
@@ -1745,39 +1692,6 @@ class Probe
                $data['network'] = Protocol::TWITTER;
                $data['baseurl'] = 'https://twitter.com';
 
-               $curlResult = Network::curl($data['url'], false);
-               if (!$curlResult->isSuccess()) {
-                       return [];
-               }
-
-               $body = $curlResult->getBody();
-               $doc = new DOMDocument();
-               @$doc->loadHTML($body);
-               $xpath = new DOMXPath($doc);
-
-               $list = $xpath->query('//img[@class]');
-               foreach ($list as $node) {
-                       $img_attr = [];
-                       if ($node->attributes->length) {
-                               foreach ($node->attributes as $attribute) {
-                                       $img_attr[$attribute->name] = $attribute->value;
-                               }
-                       }
-
-                       if (empty($img_attr['class'])) {
-                               continue;
-                       }
-
-                       if (strpos($img_attr['class'], 'ProfileAvatar-image') !== false) {
-                               if (!empty($img_attr['src'])) {
-                                       $data['photo'] = $img_attr['src'];
-                               }
-                               if (!empty($img_attr['alt'])) {
-                                       $data['name'] = $img_attr['alt'];
-                               }
-                       }
-               }
-
                return $data;
        }