2014-01-27 18:26:17 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Name: Statistics
|
|
|
|
* Description: Generates some statistics for http://pods.jasonrobinson.me/
|
|
|
|
* Version: 0.1
|
|
|
|
* Author: Michael Vogel <https://pirati.ca/profile/heluecht>
|
|
|
|
*/
|
|
|
|
|
|
|
|
function statistics_json_install() {
|
2014-02-02 04:05:23 -05:00
|
|
|
register_hook('cron', 'addon/statistics_json/statistics_json.php', 'statistics_json_cron');
|
2014-01-27 18:26:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function statistics_json_uninstall() {
|
2014-02-02 04:05:23 -05:00
|
|
|
unregister_hook('cron', 'addon/statistics_json/statistics_json.php', 'statistics_json_cron');
|
2014-01-27 18:26:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function statistics_json_module() {}
|
|
|
|
|
2014-10-07 14:15:56 -04:00
|
|
|
function statistics_json_plugin_enabled($plugin) {
|
|
|
|
$r = q("SELECT * FROM `addon` WHERE `installed` = 1 AND `name` = '%s'", $plugin);
|
|
|
|
return((bool)(count($r) > 0));
|
|
|
|
}
|
|
|
|
|
2014-01-27 18:26:17 -05:00
|
|
|
function statistics_json_init() {
|
|
|
|
global $a;
|
|
|
|
|
|
|
|
$statistics = array(
|
|
|
|
"name" => $a->config["sitename"],
|
2014-02-02 15:27:16 -05:00
|
|
|
"network" => FRIENDICA_PLATFORM,
|
2014-01-27 18:26:17 -05:00
|
|
|
"version" => FRIENDICA_VERSION,
|
|
|
|
"registrations_open" => ($a->config['register_policy'] != 0),
|
2014-02-02 04:05:23 -05:00
|
|
|
"total_users" => get_config('statistics_json','total_users'),
|
|
|
|
"active_users_halfyear" => get_config('statistics_json','active_users_halfyear'),
|
|
|
|
"active_users_monthly" => get_config('statistics_json','active_users_monthly'),
|
|
|
|
"local_posts" => get_config('statistics_json','local_posts')
|
2014-01-27 18:26:17 -05:00
|
|
|
);
|
|
|
|
|
2014-10-13 14:06:28 -04:00
|
|
|
$statistics["services"] = array();
|
|
|
|
$statistics["services"]["appnet"] = statistics_json_plugin_enabled("appnet");
|
|
|
|
$statistics["services"]["blogger"] = statistics_json_plugin_enabled("blogger");
|
|
|
|
$statistics["services"]["buffer"] = statistics_json_plugin_enabled("buffer");
|
|
|
|
$statistics["services"]["dreamwidth"] = statistics_json_plugin_enabled("dwpost");
|
|
|
|
$statistics["services"]["facebook"] = statistics_json_plugin_enabled("fbpost");
|
|
|
|
$statistics["services"]["gnusocial"] = statistics_json_plugin_enabled("statusnet");
|
|
|
|
$statistics["services"]["googleplus"] = statistics_json_plugin_enabled("gpluspost");
|
|
|
|
$statistics["services"]["libertree"] = statistics_json_plugin_enabled("libertree");
|
|
|
|
$statistics["services"]["livejournal"] = statistics_json_plugin_enabled("ljpost");
|
|
|
|
$statistics["services"]["pumpio"] = statistics_json_plugin_enabled("pumpio");
|
|
|
|
$statistics["services"]["twitter"] = statistics_json_plugin_enabled("twitter");
|
|
|
|
$statistics["services"]["tumblr"] = statistics_json_plugin_enabled("tumblr");
|
|
|
|
$statistics["services"]["wordpress"] = statistics_json_plugin_enabled("wppost");
|
|
|
|
|
|
|
|
$statistics["appnet"] = $statistics["services"]["appnet"];
|
|
|
|
$statistics["blogger"] = $statistics["services"]["blogger"];
|
|
|
|
$statistics["buffer"] = $statistics["services"]["buffer"];
|
|
|
|
$statistics["dreamwidth"] = $statistics["services"]["dreamwidth"];
|
|
|
|
$statistics["facebook"] = $statistics["services"]["facebook"];
|
|
|
|
$statistics["gnusocial"] = $statistics["services"]["gnusocial"];
|
|
|
|
$statistics["googleplus"] = $statistics["services"]["googleplus"];
|
|
|
|
$statistics["libertree"] = $statistics["services"]["libertree"];
|
|
|
|
$statistics["livejournal"] = $statistics["services"]["livejournal"];
|
|
|
|
$statistics["pumpio"] = $statistics["services"]["pumpio"];
|
|
|
|
$statistics["twitter"] = $statistics["services"]["twitter"];
|
|
|
|
$statistics["tumblr"] = $statistics["services"]["tumblr"];
|
|
|
|
$statistics["wordpress"] = $statistics["services"]["wordpress"];
|
2014-10-07 14:15:56 -04:00
|
|
|
|
2014-02-02 04:05:23 -05:00
|
|
|
header("Content-Type: application/json");
|
|
|
|
echo json_encode($statistics);
|
|
|
|
logger("statistics_init: printed ".print_r($statistics, true));
|
|
|
|
killme();
|
|
|
|
}
|
|
|
|
|
|
|
|
function statistics_json_cron($a,$b) {
|
|
|
|
$last = get_config('statistics_json','last_calucation');
|
|
|
|
|
|
|
|
if($last) {
|
2014-03-01 19:45:59 -05:00
|
|
|
// Calculate every 24 hours
|
|
|
|
$next = $last + (24 * 60 * 60);
|
2014-02-02 04:05:23 -05:00
|
|
|
if($next > time()) {
|
|
|
|
logger('statistics_json_cron: calculation intervall not reached');
|
2014-02-05 18:25:55 -05:00
|
|
|
return;
|
2014-02-02 04:05:23 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
logger('statistics_json_cron: cron_start');
|
|
|
|
|
|
|
|
|
2014-01-27 18:42:48 -05:00
|
|
|
$users = q("SELECT profile.*, `user`.`login_date`, `lastitem`.`lastitem_date`
|
2014-01-27 18:26:17 -05:00
|
|
|
FROM (SELECT MAX(`item`.`changed`) as `lastitem_date`, `item`.`uid`
|
|
|
|
FROM `item`
|
|
|
|
WHERE `item`.`type` = 'wall'
|
|
|
|
GROUP BY `item`.`uid`) AS `lastitem`
|
2014-01-27 18:42:48 -05:00
|
|
|
RIGHT OUTER JOIN `user` ON `user`.`uid` = `lastitem`.`uid`, `contact`, `profile`
|
2014-01-27 18:26:17 -05:00
|
|
|
WHERE
|
2014-01-27 18:42:48 -05:00
|
|
|
`user`.`uid` = `contact`.`uid` AND `profile`.`uid` = `user`.`uid`
|
|
|
|
AND `profile`.`is-default` AND (`profile`.`publish` OR `profile`.`net-publish`)
|
2014-01-27 18:26:17 -05:00
|
|
|
AND `user`.`verified` AND `contact`.`self`
|
2014-01-27 18:42:48 -05:00
|
|
|
AND NOT `user`.`blocked`
|
2014-01-27 18:26:17 -05:00
|
|
|
AND NOT `user`.`account_removed`
|
|
|
|
AND NOT `user`.`account_expired`");
|
|
|
|
|
2014-02-02 04:05:23 -05:00
|
|
|
if (is_array($users)) {
|
|
|
|
$total_users = count($users);
|
|
|
|
$active_users_halfyear = 0;
|
|
|
|
$active_users_monthly = 0;
|
2014-01-27 18:26:17 -05:00
|
|
|
|
|
|
|
$halfyear = time() - (180 * 24 * 60 * 60);
|
|
|
|
$month = time() - (30 * 24 * 60 * 60);
|
|
|
|
|
|
|
|
foreach ($users AS $user) {
|
|
|
|
if ((strtotime($user['login_date']) > $halfyear) OR
|
|
|
|
(strtotime($user['lastitem_date']) > $halfyear))
|
2014-02-02 04:05:23 -05:00
|
|
|
++$active_users_halfyear;
|
2014-01-27 18:26:17 -05:00
|
|
|
|
|
|
|
if ((strtotime($user['login_date']) > $month) OR
|
|
|
|
(strtotime($user['lastitem_date']) > $month))
|
2014-02-02 04:05:23 -05:00
|
|
|
++$active_users_monthly;
|
2014-01-27 18:26:17 -05:00
|
|
|
|
|
|
|
}
|
2014-02-02 04:05:23 -05:00
|
|
|
set_config('statistics_json','total_users', $total_users);
|
|
|
|
logger('statistics_json_cron: total_users: '.$total_users, LOGGER_DEBUG);
|
|
|
|
|
|
|
|
set_config('statistics_json','active_users_halfyear', $active_users_halfyear);
|
|
|
|
set_config('statistics_json','active_users_monthly', $active_users_monthly);
|
2014-01-27 18:26:17 -05:00
|
|
|
}
|
|
|
|
|
2014-02-03 16:39:02 -05:00
|
|
|
$posts = q("SELECT COUNT(*) AS local_posts FROM `item` WHERE `wall` AND left(body, 6) != '[share'");
|
2014-02-02 04:05:23 -05:00
|
|
|
|
2014-01-27 18:26:17 -05:00
|
|
|
if (!is_array($posts))
|
2014-02-02 04:05:23 -05:00
|
|
|
$local_posts = -1;
|
2014-01-27 18:26:17 -05:00
|
|
|
else
|
2014-02-02 04:05:23 -05:00
|
|
|
$local_posts = $posts[0]["local_posts"];
|
2014-01-27 18:26:17 -05:00
|
|
|
|
2014-02-02 04:05:23 -05:00
|
|
|
set_config('statistics_json','local_posts', $local_posts);
|
|
|
|
|
|
|
|
logger('statistics_json_cron: local_posts: '.$local_posts, LOGGER_DEBUG);
|
|
|
|
|
2014-02-05 18:23:08 -05:00
|
|
|
// Now trying to register
|
|
|
|
$url = "http://pods.jasonrobinson.me/register/".$a->get_hostname();
|
|
|
|
logger('statistics_json_cron: registering url: '.$url, LOGGER_DEBUG);
|
|
|
|
$ret = fetch_url($url);
|
|
|
|
logger('statistics_json_cron: registering answer: '.$ret, LOGGER_DEBUG);
|
|
|
|
|
2014-02-02 04:05:23 -05:00
|
|
|
logger('statistics_json_cron: cron_end');
|
|
|
|
set_config('statistics_json','last_calucation', time());
|
2014-01-27 18:26:17 -05:00
|
|
|
}
|