From 369e27942307ea23ba725b9fedb4b49acb65f5e0 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Tue, 28 Jan 2014 00:26:17 +0100 Subject: [PATCH 1/3] statistics: A module to take part to the statistics at http://pods.jasonrobinson.me/ --- statistics_json/statistics_json.php | 76 +++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 statistics_json/statistics_json.php diff --git a/statistics_json/statistics_json.php b/statistics_json/statistics_json.php new file mode 100644 index 00000000..d6c7b965 --- /dev/null +++ b/statistics_json/statistics_json.php @@ -0,0 +1,76 @@ + + */ + +function statistics_json_install() { +} + + +function statistics_json_uninstall() { +} + +function statistics_json_module() {} + +function statistics_json_init() { + global $a; + + $statistics = array( + "name" => $a->config["sitename"], + "version" => FRIENDICA_VERSION, + "registrations_open" => ($a->config['register_policy'] != 0), + ); + + $users = q("SELECT `user`.`login_date`, `lastitem`.`lastitem_date` + FROM (SELECT MAX(`item`.`changed`) as `lastitem_date`, `item`.`uid` + FROM `item` + WHERE `item`.`type` = 'wall' + GROUP BY `item`.`uid`) AS `lastitem` + RIGHT OUTER JOIN `user` ON `user`.`uid` = `lastitem`.`uid`, `contact` + WHERE + `user`.`uid` = `contact`.`uid` + AND `user`.`verified` AND `contact`.`self` + AND NOT `user`.`blocked` AND NOT `user`.`hidewall` + AND NOT `user`.`account_removed` + AND NOT `user`.`account_expired`"); + + if (!is_array($users)) { + $statistics["total_users"] = -1; + $statistics["active_users_halfyear"] = -1; + $statistics["active_users_monthly"] = -1; + } else { + $statistics["total_users"] = count($users); + $statistics["active_users_halfyear"] = 0; + $statistics["active_users_monthly"] = 0; + + $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)) + ++$statistics["active_users_halfyear"]; + + if ((strtotime($user['login_date']) > $month) OR + (strtotime($user['lastitem_date']) > $month)) + ++$statistics["active_users_monthly"]; + + } + } + + $posts = q("SELECT COUNT(*) AS local_posts FROM `item` WHERE `wall`"); + if (!is_array($posts)) + $statistics["local_posts"] = -1; + else + $statistics["local_posts"] = $posts[0]["local_posts"]; + + header("Content-Type: application/json"); + echo json_encode($statistics); + + logger("statistics_init: printed ".print_r($statistics, true)); + killme(); +} From fb7897aa383b9bb42f65c15752cdd9cd45ab3bea Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Tue, 28 Jan 2014 00:42:48 +0100 Subject: [PATCH 2/3] statistics: Using the profile settings for publishing the profile --- statistics_json/statistics_json.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/statistics_json/statistics_json.php b/statistics_json/statistics_json.php index d6c7b965..0ecbd3ba 100644 --- a/statistics_json/statistics_json.php +++ b/statistics_json/statistics_json.php @@ -25,16 +25,17 @@ function statistics_json_init() { "registrations_open" => ($a->config['register_policy'] != 0), ); - $users = q("SELECT `user`.`login_date`, `lastitem`.`lastitem_date` + $users = q("SELECT profile.*, `user`.`login_date`, `lastitem`.`lastitem_date` FROM (SELECT MAX(`item`.`changed`) as `lastitem_date`, `item`.`uid` FROM `item` WHERE `item`.`type` = 'wall' GROUP BY `item`.`uid`) AS `lastitem` - RIGHT OUTER JOIN `user` ON `user`.`uid` = `lastitem`.`uid`, `contact` + RIGHT OUTER JOIN `user` ON `user`.`uid` = `lastitem`.`uid`, `contact`, `profile` WHERE - `user`.`uid` = `contact`.`uid` + `user`.`uid` = `contact`.`uid` AND `profile`.`uid` = `user`.`uid` + AND `profile`.`is-default` AND (`profile`.`publish` OR `profile`.`net-publish`) AND `user`.`verified` AND `contact`.`self` - AND NOT `user`.`blocked` AND NOT `user`.`hidewall` + AND NOT `user`.`blocked` AND NOT `user`.`account_removed` AND NOT `user`.`account_expired`"); @@ -70,7 +71,7 @@ function statistics_json_init() { header("Content-Type: application/json"); echo json_encode($statistics); - +print_r($users); logger("statistics_init: printed ".print_r($statistics, true)); killme(); } From f66a8d0be8fc7a948d56b1c7ee05bf8753365c79 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Tue, 28 Jan 2014 00:43:48 +0100 Subject: [PATCH 3/3] statistics: removed debug statements --- statistics_json/statistics_json.php | 1 - 1 file changed, 1 deletion(-) diff --git a/statistics_json/statistics_json.php b/statistics_json/statistics_json.php index 0ecbd3ba..fe48bac2 100644 --- a/statistics_json/statistics_json.php +++ b/statistics_json/statistics_json.php @@ -71,7 +71,6 @@ function statistics_json_init() { header("Content-Type: application/json"); echo json_encode($statistics); -print_r($users); logger("statistics_init: printed ".print_r($statistics, true)); killme(); }