]> git.mxchange.org Git - friendica.git/commitdiff
PoCo endpoint added
authorMichael <heluecht@pirati.ca>
Thu, 3 Oct 2019 15:30:07 +0000 (15:30 +0000)
committerMichael <heluecht@pirati.ca>
Thu, 3 Oct 2019 15:30:07 +0000 (15:30 +0000)
src/Model/GServer.php

index a1f194ed9a4e6de6fc767e8003de9935bd3134ff..11dd9b5257e9a695fbba936eb8e2ae692cbfc996 100644 (file)
@@ -27,14 +27,13 @@ class GServer
         * Detect server data (type, protocol, version number, ...)
         * The detected data is then updated or inserted in the gserver table.
         *
-        * @param string  $url   Server url
+        * @param string $url Server url
         *
         * @return boolean 'true' if server could be detected
         */
        public static function detect($url)
        {
                /// @Todo:
-               // - poco endpoint
                // - Pleroma version number
 
                $serverdata = [];
@@ -97,6 +96,8 @@ class GServer
                        $serverdata = $nodeinfo;
                }
 
+               $serverdata = self::checkPoCo($url, $serverdata);
+
                // We can't detect the network type. Possibly it is some system that we don't know yet
                if (empty($serverdata['network'])) {
                        $serverdata['network'] = Protocol::PHANTOM;
@@ -105,14 +106,19 @@ class GServer
                $serverdata['url'] = $url;
                $serverdata['nurl'] = Strings::normaliseLink($url);
 
-               // When we don't have the registered users, we simply count what we know
-               if (empty($serverdata['registered-users'])) {
-                       $gcontacts = DBA::count('gcontact', ['server_url' => [$url, $serverdata['nurl']]]);
-                       $apcontacts = DBA::count('apcontact', ['baseurl' => [$url, $serverdata['nurl']]]);
-                       $contacts = DBA::count('contact', ['uid' => 0, 'baseurl' => [$url, $serverdata['nurl']]]);
-                       $serverdata['registered-users'] = max($gcontacts, $apcontacts, $contacts);
+               // We take the highest number that we do find
+               $registeredUsers = $serverdata['registered-users'] ?? 0;
+
+               // On an active server there has to be at least a single user
+               if (($serverdata['network'] != Protocol::PHANTOM) && ($registeredUsers == 0)) {
+                       $registeredUsers = 1;
                }
 
+               $gcontacts = DBA::count('gcontact', ['server_url' => [$url, $serverdata['nurl']]]);
+               $apcontacts = DBA::count('apcontact', ['baseurl' => [$url, $serverdata['nurl']]]);
+               $contacts = DBA::count('contact', ['uid' => 0, 'baseurl' => [$url, $serverdata['nurl']]]);
+               $serverdata['registered-users'] = max($gcontacts, $apcontacts, $contacts, $registeredUsers);
+
                $serverdata['last_contact'] = DateTimeFormat::utcNow();
 
                if (!DBA::exists('gserver', ['nurl' => Strings::normaliseLink($url)])) {
@@ -437,6 +443,29 @@ class GServer
                return $serverdata;
        }
 
+       private static function checkPoCo($url, $serverdata)
+       {
+               $curlResult = Network::curl($url. '/poco');
+               if (!$curlResult->isSuccess()) {
+                       return $serverdata;
+               }
+
+               $data = json_decode($curlResult->getBody(), true);
+               if (empty($data)) {
+                       return $serverdata;
+               }
+
+               if (!empty($data['totalResults'])) {
+                       $registeredUsers = $serverdata['registered-users'] ?? 0;
+                       $serverdata['registered-users'] = max($data['totalResults'], $registeredUsers);
+                       $serverdata['poco'] = $url . '/poco';
+               } else {
+                       $serverdata['poco'] = '';
+               }
+
+               return $serverdata;
+       }
+
        private static function detectNextcloud($url, $serverdata)
        {
                $curlResult = Network::curl($url . '/status.php');