]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/GServer.php
Merge pull request #9405 from nupplaphil/task/psr7_remove_binary
[friendica.git] / src / Model / GServer.php
index 9a8166158b67bcd04b024dcfe813cb61a006632d..009816d8186c7f82f1b71a4b007de7f99fa39f5c 100644 (file)
@@ -32,7 +32,6 @@ use Friendica\DI;
 use Friendica\Module\Register;
 use Friendica\Network\CurlResult;
 use Friendica\Protocol\Diaspora;
-use Friendica\Protocol\PortableContact;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Network;
 use Friendica\Util\Strings;
@@ -111,7 +110,10 @@ class GServer
        public static function reachable(string $profile, string $server = '', string $network = '', bool $force = false)
        {
                if ($server == '') {
-                       $server = GContact::getBasepath($profile);
+                       $contact = Contact::getByURL($profile, null, ['baseurl']);
+                       if (!empty($contact['baseurl'])) {
+                               $server = $contact['baseurl'];
+                       }
                }
 
                if ($server == '') {
@@ -309,7 +311,7 @@ class GServer
 
                // When a nodeinfo is present, we don't need to dig further
                $xrd_timeout = DI::config()->get('system', 'xrd_timeout');
-               $curlResult = DI::httpRequest()->get($url . '/.well-known/nodeinfo', false, ['timeout' => $xrd_timeout]);
+               $curlResult = DI::httpRequest()->get($url . '/.well-known/nodeinfo', ['timeout' => $xrd_timeout]);
                if ($curlResult->isTimeout()) {
                        self::setFailure($url);
                        return false;
@@ -342,7 +344,7 @@ class GServer
                                        $basedata = ['detection-method' => self::DETECT_MANUAL];
                                }
 
-                               $curlResult = DI::httpRequest()->get($baseurl, false, ['timeout' => $xrd_timeout]);
+                               $curlResult = DI::httpRequest()->get($baseurl, ['timeout' => $xrd_timeout]);
                                if ($curlResult->isSuccess()) {
                                        $basedata = self::analyseRootHeader($curlResult, $basedata);
                                        $basedata = self::analyseRootBody($curlResult, $basedata, $baseurl);
@@ -359,7 +361,7 @@ class GServer
                                        // When the base path doesn't seem to contain a social network we try the complete path.
                                        // Most detectable system have to be installed in the root directory.
                                        // We checked the base to avoid false positives.
-                                       $curlResult = DI::httpRequest()->get($url, false, ['timeout' => $xrd_timeout]);
+                                       $curlResult = DI::httpRequest()->get($url, ['timeout' => $xrd_timeout]);
                                        if ($curlResult->isSuccess()) {
                                                $urldata = self::analyseRootHeader($curlResult, $serverdata);
                                                $urldata = self::analyseRootBody($curlResult, $urldata, $url);
@@ -471,10 +473,9 @@ class GServer
                }
 
                if (!empty($serverdata['network']) && !empty($id) && ($serverdata['network'] != Protocol::PHANTOM)) {
-                       $gcontacts = DBA::count('gcontact', ['gsid' => $id]);
                        $apcontacts = DBA::count('apcontact', ['gsid' => $id]);
                        $contacts = DBA::count('contact', ['uid' => 0, 'gsid' => $id]);
-                       $max_users = max($gcontacts, $apcontacts, $contacts, $registeredUsers);
+                       $max_users = max($apcontacts, $contacts, $registeredUsers);
                        if ($max_users > $registeredUsers) {
                                Logger::info('Update registered users', ['id' => $id, 'url' => $serverdata['nurl'], 'registered-users' => $max_users]);
                                DBA::update('gserver', ['registered-users' => $max_users], ['id' => $id]);
@@ -912,7 +913,7 @@ class GServer
        private static function validHostMeta(string $url)
        {
                $xrd_timeout = DI::config()->get('system', 'xrd_timeout');
-               $curlResult = DI::httpRequest()->get($url . '/.well-known/host-meta', false, ['timeout' => $xrd_timeout]);
+               $curlResult = DI::httpRequest()->get($url . '/.well-known/host-meta', ['timeout' => $xrd_timeout]);
                if (!$curlResult->isSuccess()) {
                        return false;
                }
@@ -959,12 +960,6 @@ class GServer
        {
                $contacts = [];
 
-               $gcontacts = DBA::select('gcontact', ['url', 'nurl'], ['server_url' => [$url, $serverdata['nurl']]]);
-               while ($gcontact = DBA::fetch($gcontacts)) {
-                       $contacts[$gcontact['nurl']] = $gcontact['url'];
-               }
-               DBA::close($gcontacts);
-
                $apcontacts = DBA::select('apcontact', ['url'], ['baseurl' => [$url, $serverdata['nurl']]]);
                while ($apcontact = DBA::fetch($apcontacts)) {
                        $contacts[Strings::normaliseLink($apcontact['url'])] = $apcontact['url'];
@@ -1556,20 +1551,6 @@ class GServer
                return !strpos($body, '>');
        }
 
-       /**
-        * Update the user directory of a given gserver record
-        *
-        * @param array $gserver gserver record
-        */
-       public static function updateDirectory(array $gserver)
-       {
-               /// @todo Add Mastodon API directory
-
-               if (!empty($gserver['poco'])) {
-                       PortableContact::discoverSingleServer($gserver['id']);
-               }
-       }
-
        /**
         * Update GServer entries
         */
@@ -1588,7 +1569,7 @@ class GServer
 
                $last_update = date('c', time() - (60 * 60 * 24 * $requery_days));
 
-               $gservers = DBA::p("SELECT `id`, `url`, `nurl`, `network`, `poco`
+               $gservers = DBA::p("SELECT `id`, `url`, `nurl`, `network`, `poco`, `directory-type`
                        FROM `gserver`
                        WHERE NOT `failed`
                        AND `directory-type` != ?
@@ -1607,11 +1588,12 @@ class GServer
                        Logger::info('Update peer list', ['server' => $gserver['url'], 'id' => $gserver['id']]);
                        Worker::add(PRIORITY_LOW, 'UpdateServerPeers', $gserver['url']);
 
-                       if ($gserver['directory-type'] == self::DT_POCO) {
-                               Logger::info('Update directory', ['server' => $gserver['url'], 'id' => $gserver['id']]);
-                               Worker::add(PRIORITY_LOW, 'UpdateServerDirectory', $gserver);
-                       }
+                       Logger::info('Update directory', ['server' => $gserver['url'], 'id' => $gserver['id']]);
+                       Worker::add(PRIORITY_LOW, 'UpdateServerDirectory', $gserver);
 
+                       $fields = ['last_poco_query' => DateTimeFormat::utcNow()];
+                       DBA::update('gserver', $fields, ['nurl' => $gserver['nurl']]);
+       
                        if (--$no_of_queries == 0) {
                                break;
                        }
@@ -1657,7 +1639,7 @@ class GServer
                if (!empty($accesstoken)) {
                        $api = 'https://instances.social/api/1.0/instances/list?count=0';
                        $header = ['Authorization: Bearer '.$accesstoken];
-                       $curlResult = DI::httpRequest()->get($api, false, ['headers' => $header]);
+                       $curlResult = DI::httpRequest()->get($api, ['headers' => $header]);
 
                        if ($curlResult->isSuccess()) {
                                $servers = json_decode($curlResult->getBody(), true);