]> git.mxchange.org Git - friendica.git/blobdiff - src/Network/Probe.php
Centralized gsid generation
[friendica.git] / src / Network / Probe.php
index 6c64f790ec71adad62e832a4036e774cb0cc1d5a..5872ae587b53fe84efd4248699a98a2d9cf5c064 100644 (file)
@@ -30,6 +30,7 @@ use Friendica\Core\System;
 use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Model\Contact;
+use Friendica\Model\GServer;
 use Friendica\Model\Profile;
 use Friendica\Protocol\ActivityNamespace;
 use Friendica\Protocol\ActivityPub;
@@ -86,14 +87,16 @@ class Probe
                                "community", "keywords", "location", "about", "hide",
                                "batch", "notify", "poll", "request", "confirm", "poco",
                                "following", "followers", "inbox", "outbox", "sharedinbox",
-                               "priority", "network", "pubkey", "baseurl"];
+                               "priority", "network", "pubkey", "baseurl", "gsid"];
 
                $newdata = [];
                foreach ($fields as $field) {
                        if (isset($data[$field])) {
                                $newdata[$field] = $data[$field];
-                       } else {
+                       } elseif ($field != "gsid") {
                                $newdata[$field] = "";
+                       } else {
+                               $newdata[$field] = null;
                        }
                }
 
@@ -160,8 +163,12 @@ class Probe
                $ssl_connection_error = ($curlResult->getErrorNumber() == CURLE_COULDNT_CONNECT) || ($curlResult->getReturnCode() == 0);
                if ($curlResult->isSuccess()) {
                        $xml = $curlResult->getBody();
-                       $xrd = XML::parseString($xml, false);
-                       $host_url = 'https://'.$host;
+                       $xrd = XML::parseString($xml, true);
+                       if (!empty($url)) {
+                               $host_url = 'https://' . $host;
+                       } else {
+                               $host_url = $host;
+                       }
                } elseif ($curlResult->isTimeout()) {
                        Logger::info('Probing timeout', ['url' => $ssl_url], Logger::DEBUG);
                        self::$istimeout = true;
@@ -181,7 +188,7 @@ class Probe
                        }
 
                        $xml = $curlResult->getBody();
-                       $xrd = XML::parseString($xml, false);
+                       $xrd = XML::parseString($xml, true);
                        $host_url = 'http://'.$host;
                }
                if (!is_object($xrd)) {
@@ -366,7 +373,7 @@ class Probe
                        $data[] = ["@attributes" => $link];
                }
 
-               if (is_array($webfinger["aliases"])) {
+               if (!empty($webfinger["aliases"]) && is_array($webfinger["aliases"])) {
                        foreach ($webfinger["aliases"] as $alias) {
                                $data[] = ["@attributes" =>
                                                        ["rel" => "alias",
@@ -457,6 +464,10 @@ class Probe
                        $data['baseurl'] = self::$baseurl;
                }
 
+               if (!empty($data['baseurl']) && empty($data['gsid'])) {
+                       $data['gsid'] = GServer::getID($data['baseurl']);
+               }
+
                if (empty($data['network'])) {
                        $data['network'] = Protocol::PHANTOM;
                }
@@ -932,7 +943,7 @@ class Probe
                }
 
                // If it is not JSON, maybe it is XML
-               $xrd = XML::parseString($data, false);
+               $xrd = XML::parseString($data, true);
                if (!is_object($xrd)) {
                        Logger::log("No webfinger data retrievable for ".$url, Logger::DEBUG);
                        return false;