t('summary'), 'path' => 'admin/logs/summary', 'callback' => 'xstatistics_summary', 'access' => user_access('access statistics')); $items[] = array('title' => t('usage'), 'path' => 'admin/logs/usage', 'callback' => 'xstatistics_usage', 'access' => user_access('access statistics')); } return $items; } function xstatistics_help($section = "admin/help#xstatistics") { $output = ""; switch ($section) { case 'admin/modules#description': $output = t("Extends statistics for your site."); break; case 'admin/help#xstatistics': case 'admin/statistics/summary': $output = t("This page shows usage statistics of your site"); break; } return $output; } function xstatistics_block($op = 'list', $delta = 0) { $block = array(); $title = array(t('Site Summary'), t('Site Usage')); switch ($op) { case 'list': $block[0]['info'] = $title[0]; $block[1]['info'] = $title[1]; break; case 'view': switch ($delta) { case 0: $block['subject'] = t($title[$delta]); $block['content'] = xstatistics_summary('block'); break; case 1: $block['subject'] = t($title[$delta]); $block['content'] = xstatistics_usage('block'); break; } break; } return $block; } function xstatistics_summary($mode = 'page') { $output = xstatistics_do_summary(); return xstatistics_output($mode, $output); } function xstatistics_usage($mode = 'page') { $output = xstatistics_do_usage(); return xstatistics_output($mode, $output); } function xstatistics_output($mode = 'page', $output) { switch($mode) { case 'page': print theme($mode, $output); break; case 'block': return $output; break; } } function xstatistics_do_summary() { //prepare amount of node_views //todo rewrite to use count() and sum() $res = db_query("SELECT totalcount, daycount FROM {node_counter}"); while($count = db_fetch_object($res)) { $count_nodes_view_tot = $count_nodes_view_tot + $count->totalcount; $count_nodes_view_day = $count_nodes_view_day + $count->daycount; } $count_referrer_ext_day = db_fetch_array(db_query("SELECT COUNT(DISTINCT(url)) AS referrers FROM {accesslog} WHERE url <> '' AND url NOT LIKE '%%%s%%' AND timestamp >= %d", $_SERVER['HTTP_HOST'], (time()-86400))); $count_referrer_int_day = db_fetch_array(db_query("SELECT COUNT(DISTINCT(url)) AS referrers FROM {accesslog} WHERE url <> '' AND url LIKE '%%%s%%' AND timestamp >= %d", $_SERVER['HTTP_HOST'], (time()-86400))); $count_hits_day = db_fetch_array(db_query("SELECT COUNT(aid) AS hits FROM {accesslog} WHERE timestamp >= %d", (time()-86400))); $count_pageviews_day = db_fetch_array(db_query("SELECT COUNT(path) AS hits FROM {accesslog} WHERE timestamp >= %d", (time()-86400))); $header = array("description", "value"); $rows = array(array(t("External referrers today"),$count_referrer_ext_day['referrers']), array(t("Internal referrers today"),$count_referrer_int_day['referrers']), array(t("Viewed nodes today"),$count_nodes_view_day), array(t("Viewed nodes all time"),$count_nodes_view_tot), array(t("Viewed pages today"), $count_pageviews_day['hits']), array(t("Hits today"), $count_hits_day['hits']) ); return theme('table', $header, $rows); } function xstatistics_do_usage() { //prepare amount of nodes $count_nodes_tot = db_fetch_array(db_query("SELECT COUNT(nid) FROM {node}")); $count_nodes_pub = db_fetch_array(db_query("SELECT COUNT(nid) FROM {node} WHERE status=1")); $count_nodes_que = db_fetch_array(db_query("SELECT COUNT(nid) FROM {node} WHERE moderate=1")); //prepare amount of users $count_users_tot = db_fetch_array(db_query("SELECT COUNT(uid) FROM {users}")); //prepare amount of comments $count_comments_tot = db_fetch_array(db_query("SELECT COUNT(cid) FROM {comments} WHERE status=0")); $header = array("description", "value"); $rows = array(array(t("Nodes"),$count_nodes_tot['COUNT(nid)']), array(t("Published nodes"),$count_nodes_pub['COUNT(nid)']), array(t("Nodes in the queue"),$count_nodes_que['COUNT(nid)']), array(t("Comments"),$count_comments_tot['COUNT(cid)']), array(t("Users"),$count_users_tot['COUNT(uid)']), ); return theme('table', $header, $rows); }