]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/GServer.php
Standards
[friendica.git] / src / Model / GServer.php
index 86893529177b1e078fb113889684e4c9d270059b..7e1d178ddfe1bf6986f36cc9464b00b95f165148 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2020, Friendica
+ * @copyright Copyright (C) 2010-2021, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -802,6 +802,7 @@ class GServer
        /**
         * Parses Nodeinfo 2
         *
+        * @see https://git.feneas.org/jaywink/nodeinfo2
         * @param string $nodeinfo_url address of the nodeinfo path
         * @return array Server data
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
@@ -850,7 +851,9 @@ class GServer
                if (!empty($nodeinfo['protocols'])) {
                        $protocols = [];
                        foreach ($nodeinfo['protocols'] as $protocol) {
-                               $protocols[$protocol] = true;
+                               if (is_string($protocol)) {
+                                       $protocols[$protocol] = true;
+                               }
                        }
 
                        if (!empty($protocols['dfrn'])) {
@@ -1475,6 +1478,10 @@ class GServer
         */
        private static function analyseRootBody($curlResult, array $serverdata, string $url)
        {
+               if (empty($curlResult->getBody())) {
+                       return $serverdata;
+               }
+
                $doc = new DOMDocument();
                @$doc->loadHTML($curlResult->getBody());
                $xpath = new DOMXPath($doc);
@@ -1744,7 +1751,7 @@ class GServer
         * @return void 
         * @throws Exception 
         */
-       static function setProtocol(int $gsid, int $protocol)
+       public static function setProtocol(int $gsid, int $protocol)
        {
                if (empty($gsid)) {
                        return;
@@ -1793,7 +1800,28 @@ class GServer
                        }
                }
 
-               Logger::info('Protocol for server', ['protocol' => $protocol, 'old' => $old, 'id' => $gsid, 'url' => $gserver['url']]);
+               Logger::info('Protocol for server', ['protocol' => $protocol, 'old' => $old, 'id' => $gsid, 'url' => $gserver['url'], 'callstack' => System::callstack(20)]);
                DBA::update('gserver', ['protocol' => $protocol], ['id' => $gsid]);
        }
+
+       /**
+        * Fetch the protocol of the given server
+        *
+        * @param int $gsid Server id
+        * @return int 
+        * @throws Exception 
+        */
+       public static function getProtocol(int $gsid)
+       {
+               if (empty($gsid)) {
+                       return null;
+               }
+
+               $gserver = DBA::selectFirst('gserver', ['protocol'], ['id' => $gsid]);
+               if (DBA::isResult($gserver)) {
+                       return $gserver['protocol'];
+               }
+
+               return null;
+       }
 }