We now fetch the number of registered users

This commit is contained in:
Michael 2017-12-18 23:58:18 +00:00
parent 7a6706b0f7
commit dab83c8b40
5 changed files with 40 additions and 37 deletions

View file

@ -43,7 +43,7 @@ define('FRIENDICA_PLATFORM', 'Friendica');
define('FRIENDICA_CODENAME', 'Asparagus'); define('FRIENDICA_CODENAME', 'Asparagus');
define('FRIENDICA_VERSION', '3.6-dev'); define('FRIENDICA_VERSION', '3.6-dev');
define('DFRN_PROTOCOL_VERSION', '2.23'); define('DFRN_PROTOCOL_VERSION', '2.23');
define('DB_UPDATE_VERSION', 1237); define('DB_UPDATE_VERSION', 1238);
define('NEW_UPDATE_ROUTINE_VERSION', 1170); define('NEW_UPDATE_ROUTINE_VERSION', 1170);
/** /**

View file

@ -1,6 +1,6 @@
-- ------------------------------------------ -- ------------------------------------------
-- Friendica 3.6-dev (Asparagus) -- 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 '', `site_name` varchar(255) NOT NULL DEFAULT '',
`info` text, `info` text,
`register_policy` tinyint(1) NOT NULL DEFAULT 0, `register_policy` tinyint(1) NOT NULL DEFAULT 0,
`registered-users` int(10) NOT NULL DEFAULT 0,
`poco` varchar(255) NOT NULL DEFAULT '', `poco` varchar(255) NOT NULL DEFAULT '',
`noscrape` varchar(255) NOT NULL DEFAULT '', `noscrape` varchar(255) NOT NULL DEFAULT '',
`network` varchar(32) NOT NULL DEFAULT '', `network` varchar(32) NOT NULL DEFAULT '',

View file

@ -1010,6 +1010,7 @@ class DBStructure {
"site_name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "site_name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"info" => array("type" => "text"), "info" => array("type" => "text"),
"register_policy" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"), "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" => ""), "poco" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"noscrape" => 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" => ""), "network" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),

View file

@ -722,6 +722,10 @@ class PortableContact
} }
} }
if (!empty($nodeinfo->usage->users->total)) {
$server['registered-users'] = $nodeinfo->usage->users->total;
}
$diaspora = false; $diaspora = false;
$friendica = false; $friendica = false;
$gnusocial = false; $gnusocial = false;
@ -853,6 +857,7 @@ class PortableContact
$site_name = $servers[0]["site_name"]; $site_name = $servers[0]["site_name"];
$info = $servers[0]["info"]; $info = $servers[0]["info"];
$register_policy = $servers[0]["register_policy"]; $register_policy = $servers[0]["register_policy"];
$registered_users = $servers[0]["registered-users"];
if (!$force && !self::updateNeeded($servers[0]["created"], "", $last_failure, $last_contact)) { if (!$force && !self::updateNeeded($servers[0]["created"], "", $last_failure, $last_contact)) {
logger("Use cached data for server ".$server_url, LOGGER_DEBUG); logger("Use cached data for server ".$server_url, LOGGER_DEBUG);
@ -866,6 +871,7 @@ class PortableContact
$site_name = ""; $site_name = "";
$info = ""; $info = "";
$register_policy = -1; $register_policy = -1;
$registered_users = 0;
$last_contact = NULL_DATE; $last_contact = NULL_DATE;
$last_failure = NULL_DATE; $last_failure = NULL_DATE;
@ -928,12 +934,18 @@ class PortableContact
$register_policy = -1; $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 // Look for poco
if (!$failure) { if (!$failure) {
$serverret = z_fetch_url($server_url."/poco"); $serverret = z_fetch_url($server_url."/poco");
if ($serverret["success"]) { if ($serverret["success"]) {
$data = json_decode($serverret["body"]); $data = json_decode($serverret["body"]);
if (isset($data->totalResults)) { if (isset($data->totalResults)) {
$registered_users = $data->totalResults;
$poco = $server_url."/poco"; $poco = $server_url."/poco";
$server = self::detectPocoData($data); $server = self::detectPocoData($data);
if ($server) { if ($server) {
@ -1020,6 +1032,9 @@ class PortableContact
$info = $data->description; $info = $data->description;
$network = NETWORK_OSTATUS; $network = NETWORK_OSTATUS;
} }
if (!empty($data->stats->user_count)) {
$registered_users = $data->stats->user_count;
}
} }
if (strstr($orig_version.$version, 'Pleroma')) { if (strstr($orig_version.$version, 'Pleroma')) {
$platform = 'Pleroma'; $platform = 'Pleroma';
@ -1040,6 +1055,9 @@ class PortableContact
if (!empty($data->site_name)) { if (!empty($data->site_name)) {
$site_name = $data->site_name; $site_name = $data->site_name;
} }
if (!empty($data->channels_total)) {
$registered_users = $data->channels_total;
}
switch ($data->register_policy) { switch ($data->register_policy) {
case "REGISTER_OPEN": case "REGISTER_OPEN":
$register_policy = REGISTER_OPEN; $register_policy = REGISTER_OPEN;
@ -1160,6 +1178,10 @@ class PortableContact
if (isset($server['site_name'])) { if (isset($server['site_name'])) {
$site_name = $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); $platform = strip_tags($platform);
if ($servers) { if ($servers) {
q( $fields = ['url' => $server_url, 'version' => $version,
"UPDATE `gserver` SET `url` = '%s', `version` = '%s', `site_name` = '%s', `info` = '%s', `register_policy` = %d, `poco` = '%s', `noscrape` = '%s', 'site_name' => $site_name, 'info' => $info, 'register_policy' => $register_policy,
`network` = '%s', `platform` = '%s', `last_contact` = '%s', `last_failure` = '%s' WHERE `nurl` = '%s'", 'poco' => $poco, 'noscrape' => $noscrape, 'network' => $network,
dbesc($server_url), 'platform' => $platform, 'registered-users' => $registered_users,
dbesc($version), 'last_contact' => $last_contact, 'last_failure' => last_failure];
dbesc($site_name), dba::update('gserver', $fields, ['nurl' => normalise_link($server_url)]);
dbesc($info),
intval($register_policy),
dbesc($poco),
dbesc($noscrape),
dbesc($network),
dbesc($platform),
dbesc($last_contact),
dbesc($last_failure),
dbesc(normalise_link($server_url))
);
} elseif (!$failure) { } elseif (!$failure) {
q( $fields = ['url' => $server_url, 'nurl' => normalise_link($server_url), 'version' => $version,
"INSERT INTO `gserver` (`url`, `nurl`, `version`, `site_name`, `info`, `register_policy`, `poco`, `noscrape`, `network`, `platform`, `created`, `last_contact`, `last_failure`) 'site_name' => $site_name, 'info' => $info, 'register_policy' => $register_policy,
VALUES ('%s', '%s', '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s')", 'poco' => $poco, 'noscrape' => $noscrape, 'network' => $network,
dbesc($server_url), 'platform' => $platform, 'registered-users' => $registered_users,
dbesc(normalise_link($server_url)), 'created' => datetime_convert(),
dbesc($version), 'last_contact' => $last_contact, 'last_failure' => last_failure];
dbesc($site_name), dba::insert('gserver', $fields);
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())
);
} }
logger("End discovery for server " . $server_url, LOGGER_DEBUG); logger("End discovery for server " . $server_url, LOGGER_DEBUG);

View file

@ -1,6 +1,6 @@
<?php <?php
define('UPDATE_VERSION' , 1237); define('UPDATE_VERSION' , 1238);
use Friendica\Core\Config; use Friendica\Core\Config;
use Friendica\Core\PConfig; use Friendica\Core\PConfig;