]> git.mxchange.org Git - friendica.git/commitdiff
We now fetch the number of registered users
authorMichael <heluecht@pirati.ca>
Mon, 18 Dec 2017 23:58:18 +0000 (23:58 +0000)
committerMichael <heluecht@pirati.ca>
Mon, 18 Dec 2017 23:58:18 +0000 (23:58 +0000)
boot.php
database.sql
src/Database/DBStructure.php
src/Protocol/PortableContact.php
update.php

index 00058727f50142907da991b1698caae48e209286..8d70e9fca9838f66925cf487eed18b78831d738e 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -43,7 +43,7 @@ define('FRIENDICA_PLATFORM',     'Friendica');
 define('FRIENDICA_CODENAME',     'Asparagus');
 define('FRIENDICA_VERSION',      '3.6-dev');
 define('DFRN_PROTOCOL_VERSION',  '2.23');
-define('DB_UPDATE_VERSION',      1237);
+define('DB_UPDATE_VERSION',      1238);
 define('NEW_UPDATE_ROUTINE_VERSION', 1170);
 
 /**
index f8ed2e5c155e1bc2a6973f83c5155a0973cad746..a8c12f272b41805c1cae49008618ac1538fc4f1a 100644 (file)
@@ -1,6 +1,6 @@
 -- ------------------------------------------
 -- Friendica 3.6-dev (Asparagus)
--- DB_UPDATE_VERSION 1237
+-- DB_UPDATE_VERSION 1238
 -- ------------------------------------------
 
 
@@ -392,6 +392,7 @@ CREATE TABLE IF NOT EXISTS `gserver` (
        `site_name` varchar(255) NOT NULL DEFAULT '',
        `info` text,
        `register_policy` tinyint(1) NOT NULL DEFAULT 0,
+       `registered-users` int(10) NOT NULL DEFAULT 0,
        `poco` varchar(255) NOT NULL DEFAULT '',
        `noscrape` varchar(255) NOT NULL DEFAULT '',
        `network` varchar(32) NOT NULL DEFAULT '',
index c5bd3e99bc59c64d6d37c8a13e94abf7e45ce7bf..aac0eeed766dd1f7e4e4b0091bdef4173127bcaa 100644 (file)
@@ -1010,6 +1010,7 @@ class DBStructure {
                                                "site_name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
                                                "info" => array("type" => "text"),
                                                "register_policy" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
+                                               "registered-users" => array("type" => "int(10)", "not null" => "1", "default" => "0"),
                                                "poco" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
                                                "noscrape" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
                                                "network" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
index 04b16a72db6b341adcbdfedba96726e6af120212..384256fe98836fa080a90ba78c2f459c39300751 100644 (file)
@@ -722,6 +722,10 @@ class PortableContact
                        }
                }
 
+               if (!empty($nodeinfo->usage->users->total)) {
+                       $server['registered-users'] = $nodeinfo->usage->users->total;
+               }
+
                $diaspora = false;
                $friendica = false;
                $gnusocial = false;
@@ -853,6 +857,7 @@ class PortableContact
                        $site_name = $servers[0]["site_name"];
                        $info = $servers[0]["info"];
                        $register_policy = $servers[0]["register_policy"];
+                       $registered_users = $servers[0]["registered-users"];
 
                        if (!$force && !self::updateNeeded($servers[0]["created"], "", $last_failure, $last_contact)) {
                                logger("Use cached data for server ".$server_url, LOGGER_DEBUG);
@@ -866,6 +871,7 @@ class PortableContact
                        $site_name = "";
                        $info = "";
                        $register_policy = -1;
+                       $registered_users = 0;
 
                        $last_contact = NULL_DATE;
                        $last_failure = NULL_DATE;
@@ -928,12 +934,18 @@ class PortableContact
                        $register_policy = -1;
                }
 
+               if (!$failure) {
+                       // This will be too low, but better than no value at all.
+                       $registered_users = dba::count('gcontact', ['server_url' => normalise_link($server_url)]);
+               }
+
                // Look for poco
                if (!$failure) {
                        $serverret = z_fetch_url($server_url."/poco");
                        if ($serverret["success"]) {
                                $data = json_decode($serverret["body"]);
                                if (isset($data->totalResults)) {
+                                       $registered_users = $data->totalResults;
                                        $poco = $server_url."/poco";
                                        $server = self::detectPocoData($data);
                                        if ($server) {
@@ -1020,6 +1032,9 @@ class PortableContact
                                        $info = $data->description;
                                        $network = NETWORK_OSTATUS;
                                }
+                               if (!empty($data->stats->user_count)) {
+                                       $registered_users = $data->stats->user_count;
+                               }
                        }
                        if (strstr($orig_version.$version, 'Pleroma')) {
                                $platform = 'Pleroma';
@@ -1040,6 +1055,9 @@ class PortableContact
                                if (!empty($data->site_name)) {
                                        $site_name = $data->site_name;
                                }
+                               if (!empty($data->channels_total)) {
+                                       $registered_users = $data->channels_total;
+                               }
                                switch ($data->register_policy) {
                                        case "REGISTER_OPEN":
                                                $register_policy = REGISTER_OPEN;
@@ -1160,6 +1178,10 @@ class PortableContact
                                if (isset($server['site_name'])) {
                                        $site_name = $server['site_name'];
                                }
+
+                               if (isset($server['registered-users'])) {
+                                       $registered_users = $server['registered-users'];
+                               }
                        }
                }
 
@@ -1227,41 +1249,20 @@ class PortableContact
                $platform = strip_tags($platform);
 
                if ($servers) {
-                       q(
-                               "UPDATE `gserver` SET `url` = '%s', `version` = '%s', `site_name` = '%s', `info` = '%s', `register_policy` = %d, `poco` = '%s', `noscrape` = '%s',
-                               `network` = '%s', `platform` = '%s', `last_contact` = '%s', `last_failure` = '%s' WHERE `nurl` = '%s'",
-                               dbesc($server_url),
-                               dbesc($version),
-                               dbesc($site_name),
-                               dbesc($info),
-                               intval($register_policy),
-                               dbesc($poco),
-                               dbesc($noscrape),
-                               dbesc($network),
-                               dbesc($platform),
-                               dbesc($last_contact),
-                               dbesc($last_failure),
-                               dbesc(normalise_link($server_url))
-                       );
+                       $fields = ['url' => $server_url, 'version' => $version,
+                                       'site_name' => $site_name, 'info' => $info, 'register_policy' => $register_policy,
+                                       'poco' => $poco, 'noscrape' => $noscrape, 'network' => $network,
+                                       'platform' => $platform, 'registered-users' => $registered_users,
+                                       'last_contact' => $last_contact, 'last_failure' => last_failure];
+                       dba::update('gserver', $fields, ['nurl' => normalise_link($server_url)]);
                } elseif (!$failure) {
-                       q(
-                               "INSERT INTO `gserver` (`url`, `nurl`, `version`, `site_name`, `info`, `register_policy`, `poco`, `noscrape`, `network`, `platform`, `created`, `last_contact`, `last_failure`)
-                                               VALUES ('%s', '%s', '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s')",
-                               dbesc($server_url),
-                               dbesc(normalise_link($server_url)),
-                               dbesc($version),
-                               dbesc($site_name),
-                               dbesc($info),
-                               intval($register_policy),
-                               dbesc($poco),
-                               dbesc($noscrape),
-                               dbesc($network),
-                               dbesc($platform),
-                               dbesc(datetime_convert()),
-                               dbesc($last_contact),
-                               dbesc($last_failure),
-                               dbesc(datetime_convert())
-                       );
+                       $fields = ['url' => $server_url, 'nurl' => normalise_link($server_url), 'version' => $version,
+                                       'site_name' => $site_name, 'info' => $info, 'register_policy' => $register_policy,
+                                       'poco' => $poco, 'noscrape' => $noscrape, 'network' => $network,
+                                       'platform' => $platform, 'registered-users' => $registered_users,
+                                       'created' => datetime_convert(),
+                                       'last_contact' => $last_contact, 'last_failure' => last_failure];
+                       dba::insert('gserver', $fields);
                }
                logger("End discovery for server " . $server_url, LOGGER_DEBUG);
 
index 9701e9e398fff286991ab0d1838525b0230972df..a968451e367f92f05d652e128de0046787b3e953 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 
-define('UPDATE_VERSION' , 1237);
+define('UPDATE_VERSION' , 1238);
 
 use Friendica\Core\Config;
 use Friendica\Core\PConfig;