5 * Description: Generates some statistics for http://pods.jasonrobinson.me/
7 * Author: Michael Vogel <https://pirati.ca/profile/heluecht>
10 function statistics_json_install() {
14 function statistics_json_uninstall() {
17 function statistics_json_module() {}
19 function statistics_json_init() {
23 "name" => $a->config["sitename"],
24 "version" => FRIENDICA_VERSION,
25 "registrations_open" => ($a->config['register_policy'] != 0),
28 $users = q("SELECT `user`.`login_date`, `lastitem`.`lastitem_date`
29 FROM (SELECT MAX(`item`.`changed`) as `lastitem_date`, `item`.`uid`
31 WHERE `item`.`type` = 'wall'
32 GROUP BY `item`.`uid`) AS `lastitem`
33 RIGHT OUTER JOIN `user` ON `user`.`uid` = `lastitem`.`uid`, `contact`
35 `user`.`uid` = `contact`.`uid`
36 AND `user`.`verified` AND `contact`.`self`
37 AND NOT `user`.`blocked` AND NOT `user`.`hidewall`
38 AND NOT `user`.`account_removed`
39 AND NOT `user`.`account_expired`");
41 if (!is_array($users)) {
42 $statistics["total_users"] = -1;
43 $statistics["active_users_halfyear"] = -1;
44 $statistics["active_users_monthly"] = -1;
46 $statistics["total_users"] = count($users);
47 $statistics["active_users_halfyear"] = 0;
48 $statistics["active_users_monthly"] = 0;
50 $halfyear = time() - (180 * 24 * 60 * 60);
51 $month = time() - (30 * 24 * 60 * 60);
53 foreach ($users AS $user) {
54 if ((strtotime($user['login_date']) > $halfyear) OR
55 (strtotime($user['lastitem_date']) > $halfyear))
56 ++$statistics["active_users_halfyear"];
58 if ((strtotime($user['login_date']) > $month) OR
59 (strtotime($user['lastitem_date']) > $month))
60 ++$statistics["active_users_monthly"];
65 $posts = q("SELECT COUNT(*) AS local_posts FROM `item` WHERE `wall`");
66 if (!is_array($posts))
67 $statistics["local_posts"] = -1;
69 $statistics["local_posts"] = $posts[0]["local_posts"];
71 header("Content-Type: application/json");
72 echo json_encode($statistics);
74 logger("statistics_init: printed ".print_r($statistics, true));