]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/GServer.php
File and category aren't using "term" anymore
[friendica.git] / src / Model / GServer.php
index a85ab2408d230d325c96140613c92cc5ddfbd275..bc189af9d6bb7567ff531884ed214a2aaaca44c9 100644 (file)
@@ -1,17 +1,32 @@
 <?php
-
 /**
- * @file src/Model/GServer.php
- * This file includes the GServer class to handle with servers
+ * @copyright Copyright (C) 2020, Friendica
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
  */
+
 namespace Friendica\Model;
 
 use DOMDocument;
 use DOMXPath;
-use Friendica\Core\Config;
 use Friendica\Core\Protocol;
 use Friendica\Core\Worker;
 use Friendica\Database\DBA;
+use Friendica\DI;
 use Friendica\Module\Register;
 use Friendica\Network\CurlResult;
 use Friendica\Util\Network;
@@ -192,7 +207,7 @@ class GServer
                }
 
                // When a nodeinfo is present, we don't need to dig further
-               $xrd_timeout = Config::get('system', 'xrd_timeout');
+               $xrd_timeout = DI::config()->get('system', 'xrd_timeout');
                $curlResult = Network::curl($url . '/.well-known/nodeinfo', false, ['timeout' => $xrd_timeout]);
                if ($curlResult->isTimeout()) {
                        DBA::update('gserver', ['last_failure' => DateTimeFormat::utcNow()], ['nurl' => Strings::normaliseLink($url)]);
@@ -726,13 +741,13 @@ class GServer
         */
        private static function validHostMeta(string $url)
        {
-               $xrd_timeout = Config::get('system', 'xrd_timeout');
+               $xrd_timeout = DI::config()->get('system', 'xrd_timeout');
                $curlResult = Network::curl($url . '/.well-known/host-meta', false, ['timeout' => $xrd_timeout]);
                if (!$curlResult->isSuccess()) {
                        return false;
                }
 
-               $xrd = XML::parseString($curlResult->getBody(), false);
+               $xrd = XML::parseString($curlResult->getBody());
                if (!is_object($xrd)) {
                        return false;
                }
@@ -781,13 +796,13 @@ class GServer
                DBA::close($gcontacts);
 
                $apcontacts = DBA::select('apcontact', ['url'], ['baseurl' => [$url, $serverdata['nurl']]]);
-               while ($gcontact = DBA::fetch($gcontacts)) {
+               while ($apcontact = DBA::fetch($apcontacts)) {
                        $contacts[Strings::normaliseLink($apcontact['url'])] = $apcontact['url'];
                }
                DBA::close($apcontacts);
 
                $pcontacts = DBA::select('contact', ['url', 'nurl'], ['uid' => 0, 'baseurl' => [$url, $serverdata['nurl']]]);
-               while ($gcontact = DBA::fetch($gcontacts)) {
+               while ($pcontact = DBA::fetch($pcontacts)) {
                        $contacts[$pcontact['nurl']] = $pcontact['url'];
                }
                DBA::close($pcontacts);
@@ -931,6 +946,11 @@ class GServer
                        $serverdata['site_name'] = $data['title'];
                }
 
+               if (!empty($data['title']) && empty($serverdata['platform']) && empty($serverdata['network'])) {
+                       $serverdata['platform'] = 'mastodon';
+                       $serverdata['network'] = Protocol::ACTIVITYPUB;
+               }
+
                if (!empty($data['description'])) {
                        $serverdata['info'] = trim($data['description']);
                }
@@ -944,9 +964,14 @@ class GServer
                        $serverdata['version'] = $matches[2];
                }
 
-               if (!empty($serverdata['version']) && strstr($serverdata['version'], 'Pleroma')) {
+               if (!empty($serverdata['version']) && strstr(strtolower($serverdata['version']), 'pleroma')) {
+                       $serverdata['platform'] = 'pleroma';
+                       $serverdata['version'] = trim(str_ireplace('pleroma', '', $serverdata['version']));
+               }
+
+               if (!empty($serverdata['platform']) && strstr($serverdata['platform'], 'pleroma')) {
+                       $serverdata['version'] = trim(str_ireplace('pleroma', '', $serverdata['platform']));
                        $serverdata['platform'] = 'pleroma';
-                       $serverdata['version'] = trim(str_replace('Pleroma', '', $serverdata['version']));
                }
 
                return $serverdata;
@@ -1203,10 +1228,8 @@ class GServer
                                        $serverdata['network'] = Protocol::ACTIVITYPUB;
                                }
                        }
-
-                       if ($attr['name'] == 'generator') {
+                       if (($attr['name'] == 'generator') && (empty($serverdata['platform']) || (substr(strtolower($attr['content']), 0, 9) == 'wordpress'))) {
                                $serverdata['platform'] = strtolower($attr['content']);
-
                                $version_part = explode(' ', $attr['content']);
 
                                if (count($version_part) == 2) {
@@ -1340,7 +1363,7 @@ class GServer
 
                $no_of_queries = 5;
 
-               $requery_days = intval(Config::get('system', 'poco_requery_days'));
+               $requery_days = intval(DI::config()->get('system', 'poco_requery_days'));
 
                if ($requery_days == 0) {
                        $requery_days = 7;
@@ -1380,7 +1403,7 @@ class GServer
         */
        private static function discoverFederation()
        {
-               $last = Config::get('poco', 'last_federation_discovery');
+               $last = DI::config()->get('poco', 'last_federation_discovery');
 
                if ($last) {
                        $next = $last + (24 * 60 * 60);
@@ -1404,7 +1427,7 @@ class GServer
                }
 
                // Disvover Mastodon servers
-               $accesstoken = Config::get('system', 'instances_social_key');
+               $accesstoken = DI::config()->get('system', 'instances_social_key');
 
                if (!empty($accesstoken)) {
                        $api = 'https://instances.social/api/1.0/instances/list?count=0';
@@ -1421,6 +1444,6 @@ class GServer
                        }
                }
 
-               Config::set('poco', 'last_federation_discovery', time());
+               DI::config()->set('poco', 'last_federation_discovery', time());
        }
 }