]> git.mxchange.org Git - friendica.git/blobdiff - src/Network/Probe.php
Merge pull request #7997 from annando/zot-aliases
[friendica.git] / src / Network / Probe.php
index fe7a25a05f434dc16e156be0167b4e0055606423..02a755eec6826b1e43ef6b2a10209df918d0b967 100644 (file)
@@ -645,16 +645,16 @@ class Probe
                        $result = self::diaspora($webfinger);
                }
                if ((!$result && ($network == "")) || ($network == Protocol::OSTATUS)) {
-                       $result = self::ostatus($webfinger, false);
+                       $result = self::ostatus($webfinger);
+               }
+               if (in_array($network, ['', Protocol::ZOT])) {
+                       $result = self::zot($webfinger, $result);
                }
-//             if (in_array($network, ['', Protocol::ZOT])) {
-//                     $result = self::zot($webfinger, $result);
-//             }
                if ((!$result && ($network == "")) || ($network == Protocol::PUMPIO)) {
                        $result = self::pumpio($webfinger, $addr);
                }
                if ((!$result && ($network == "")) || ($network == Protocol::FEED)) {
-                       $result = self::feed($uri, true);
+                       $result = self::feed($uri);
                } else {
                        // We overwrite the detected nick with our try if the previois routines hadn't detected it.
                        // Additionally it is overwritten when the nickname doesn't make sense (contains spaces).
@@ -719,13 +719,23 @@ class Probe
                if (empty($zot_url) && !empty($data['addr']) && !empty(self::$baseurl)) {
                        $condition = ['nurl' => Strings::normaliseLink(self::$baseurl), 'platform' => ['hubzilla']];
                        if (!DBA::exists('gserver', $condition)) {
-                               exit;
+                               return $data;
                        }
                        $zot_url = self::$baseurl . '/.well-known/zot-info?address=' . $data['addr'];
                }
 
-               if (!empty($zot_url)) {
-                       $data = self::pollZot($zot_url, $data);
+               if (empty($zot_url)) {
+                       return $data;
+               }
+
+               $data = self::pollZot($zot_url, $data);
+
+               if (!empty($data['url']) && !empty($webfinger['aliases']) && is_array($webfinger['aliases'])) {
+                       foreach ($webfinger['aliases'] as $alias) {
+                               if (!strstr($alias, '@') && Strings::normaliseLink($alias) != Strings::normaliseLink($data['url'])) {
+                                       $data['alias'] = $alias;
+                               }
+                       }
                }
 
                return $data;
@@ -746,7 +756,7 @@ class Probe
                if (!is_array($json)) {
                        return $data;
                }
-//print_r($json);
+
                if (empty($data['network'])) {
                        if (!empty($json['protocols']) && in_array('zot', $json['protocols'])) {
                                $data['network'] = Protocol::ZOT;
@@ -1294,7 +1304,6 @@ class Probe
        private static function diaspora($webfinger)
        {
                $hcard_url = "";
-
                $data = [];
 
                // The array is reversed to take into account the order of preference for same-rel links
@@ -1325,7 +1334,7 @@ class Probe
                }
 
                if (empty($data["url"]) || empty($hcard_url)) {
-                       return $data;
+                       return false;
                }
 
                if (!empty($webfinger["aliases"]) && is_array($webfinger["aliases"])) {
@@ -1345,6 +1354,10 @@ class Probe
                // Fetch further information from the hcard
                $data = self::pollHcard($hcard_url, $data);
 
+               if (!$data) {
+                       return false;
+               }
+
                if (!empty($data["url"])
                        && !empty($data["guid"])
                        && !empty($data["baseurl"])
@@ -1361,6 +1374,8 @@ class Probe
                        // We have to overwrite the detected value for "notify" since Hubzilla doesn't send it
                        $data["notify"] = $data["baseurl"] . "/receive/users/" . $data["guid"];
                        $data["batch"]  = $data["baseurl"] . "/receive/public";
+               } else {
+                       return false;
                }
 
                return $data;
@@ -1419,11 +1434,7 @@ class Probe
                                                $curlResult = Network::curl($pubkey);
                                                if ($curlResult->isTimeout()) {
                                                        self::$istimeout = true;
-                                                       if ($short) {
-                                                               return false;
-                                                       } else {
-                                                               return $data;
-                                                       }
+                                                       return false;
                                                }
                                                $pubkey = $curlResult->getBody();
                                        }
@@ -1444,10 +1455,8 @@ class Probe
                        && isset($data["url"])
                ) {
                        $data["network"] = Protocol::OSTATUS;
-               } elseif ($short) {
-                       return false;
                } else {
-                       return $data;
+                       return false;
                }
 
                if ($short) {
@@ -1458,7 +1467,7 @@ class Probe
                $curlResult = Network::curl($data["poll"]);
                if ($curlResult->isTimeout()) {
                        self::$istimeout = true;
-                       return $data;
+                       return false;
                }
                $feed = $curlResult->getBody();
                $dummy1 = null;
@@ -1466,7 +1475,7 @@ class Probe
                $dummy2 = null;
                $feed_data = Feed::import($feed, $dummy1, $dummy2, $dummy3, true);
                if (!$feed_data) {
-                       return $data;
+                       return false;
                }
 
                if (!empty($feed_data["header"]["author-name"])) {