From da08a6813bc6c1cc493497fc931e4d9d509216e0 Mon Sep 17 00:00:00 2001 From: mose Date: Tue, 20 Aug 2019 17:56:39 +0800 Subject: [PATCH] add stats php script for q2a --- tools/idees/stats.php | 65 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 tools/idees/stats.php diff --git a/tools/idees/stats.php b/tools/idees/stats.php new file mode 100644 index 0000000..11db765 --- /dev/null +++ b/tools/idees/stats.php @@ -0,0 +1,65 @@ +connect_errno) { + echo mysqli_connect_error(); + exit; +} + +$db->set_charset("utf8"); + +function getone($query) { + global $db; + $result = $db->query($query); + return $result->fetch_row()[0]; +} +function getlist($query) { + global $db; + $result = $db->query($query); + $back = array(); + while ($row = $result->fetch_row()) { + $back[$row[0]] = $row[1]; + } + return $back; +} + +$interval = "date_sub(current_date(), interval 30 day)"; + +$data = array( + 'crapauds' => array( + 'total' => 0, + 'recent' => 0 + ), + 'idees' => array( + 'total' => 0, + 'recent' => 0, + 'liste' => array() + ), + 'commentaires' => array( + 'total' => 0, + 'recent' => 0 + ) +); + +$data['crapauds']['total'] = getone("select count(*) from qa_users"); +$data['crapauds']['recent'] = getone("select count(*) from qa_users where loggedin > $interval"); + +$data['idees']['total'] = getone("select count(*) from qa_posts where type = 'Q'"); +$data['idees']['recent'] = getone("select count(*) from qa_posts where type = 'Q' and created > $interval"); +$data['idees']['liste'] = getlist("select postid, title from qa_posts where type='Q' order by created desc limit 10"); + +$data['commentaires']['total'] = getone("select count(*) from qa_posts where type = 'A' or type = 'C'"); +$data['commentaires']['recent'] = getone("select count(*) from qa_posts where (type = 'A' or type = 'C') and created > $interval"); + +header('Content-Type: application/json'); +$json = json_encode( (object) $data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); + +if ($json === false) { + $json = json_encode(array("jsonError", json_last_error_msg())); +} + +echo $json;