]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/GServer.php
Merge pull request #10619 from nupplaphil/task/guzzlehttp
[friendica.git] / src / Model / GServer.php
index 30a1acc02a3df74ff97d290b31dd6eeb4ef63a41..eb99b1bbc8fa06677adb74d6aa1b8fb4881f9ac9 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
  *
@@ -32,7 +32,7 @@ use Friendica\Database\Database;
 use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Module\Register;
-use Friendica\Network\CurlResult;
+use Friendica\Network\IHTTPResult;
 use Friendica\Protocol\Relay;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Network;
@@ -171,7 +171,7 @@ class GServer
                if (($now - $contact_time) < (60 * 60 * 24)) {
                        return DateTimeFormat::utc('now +1 day');
                }
-               
+
                // If the last contact was less than a week before then try again in a week
                if (($now - $contact_time) < (60 * 60 * 24 * 7)) {
                        return DateTimeFormat::utc('now +1 week');
@@ -671,18 +671,19 @@ class GServer
        /**
         * Detect server type by using the nodeinfo data
         *
-        * @param string     $url        address of the server
-        * @param CurlResult $curlResult
+        * @param string      $url        address of the server
+        * @param IHTTPResult $httpResult
+        *
         * @return array Server data
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       private static function fetchNodeinfo(string $url, CurlResult $curlResult)
+       private static function fetchNodeinfo(string $url, IHTTPResult $httpResult)
        {
-               if (!$curlResult->isSuccess()) {
+               if (!$httpResult->isSuccess()) {
                        return [];
                }
 
-               $nodeinfo = json_decode($curlResult->getBody(), true);
+               $nodeinfo = json_decode($httpResult->getBody(), true);
 
                if (!is_array($nodeinfo) || empty($nodeinfo['links'])) {
                        return [];
@@ -802,6 +803,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 +852,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 +1479,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);
@@ -1741,8 +1749,8 @@ class GServer
         *
         * @param int $gsid     Server id
         * @param int $protocol Protocol id
-        * @return void 
-        * @throws Exception 
+        * @return void
+        * @throws Exception
         */
        public static function setProtocol(int $gsid, int $protocol)
        {
@@ -1801,8 +1809,8 @@ class GServer
         * Fetch the protocol of the given server
         *
         * @param int $gsid Server id
-        * @return int 
-        * @throws Exception 
+        * @return int
+        * @throws Exception
         */
        public static function getProtocol(int $gsid)
        {