From e7b70296beed93c59f69fe1fc3181d2949c4765f Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Thu, 19 May 2005 19:05:27 +0000 Subject: [PATCH] - Renamed "top users" page to "top visitors" and added some page generation times per user. This make it trivial to spot evil crawlers. --- modules/statistics.module | 23 ++++++++++++----------- modules/statistics/statistics.module | 23 ++++++++++++----------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/modules/statistics.module b/modules/statistics.module index 20bc687fbdf..62db34e55e4 100644 --- a/modules/statistics.module +++ b/modules/statistics.module @@ -114,8 +114,8 @@ function statistics_menu($may_cache) { $items[] = array('path' => 'admin/logs/pages', 'title' => t('top pages'), 'callback' => 'statistics_top_pages', 'access' => $access, 'weight' => 1); - $items[] = array('path' => 'admin/logs/users', 'title' => t('top users'), - 'callback' => 'statistics_top_users', 'access' => $access, + $items[] = array('path' => 'admin/logs/visitors', 'title' => t('top visitors'), + 'callback' => 'statistics_top_visitors', 'access' => $access, 'weight' => 2); $items[] = array('path' => 'admin/logs/referrers', 'title' => t('referrers'), 'callback' => 'statistics_top_referrers', 'access' => $access); @@ -254,8 +254,8 @@ function statistics_top_pages() { $header = array( array('data' => t('Hits'), 'field' => 'hits', 'sort' => 'desc'), array('data' => t('Page'), 'field' => 'path'), - array('data' => t('Average generation time'), 'field' => 'average_time'), - array('data' => t('Total generation time'), 'field' => 'total_time') + array('data' => t('Average page generation time'), 'field' => 'average_time'), + array('data' => t('Total page generation time'), 'field' => 'total_time') ); $sql .= tablesort_sql($header); $result = pager_query($sql, 30, 0, $sql_cnt); @@ -273,28 +273,29 @@ function statistics_top_pages() { } /** - * Menu callback; presents the "top users" page. + * Menu callback; presents the "top visitors" page. */ -function statistics_top_users() { +function statistics_top_visitors() { $header = array( array('data' => t('Hits'), 'field' => 'hits', 'sort' => 'desc'), - array('data' => t('User'), 'field' => 'u.name'), + array('data' => t('Visitor'), 'field' => 'u.name'), + array('data' => t('Total page generation time'), 'field' => 'total'), ); - $sql = "SELECT COUNT(a.uid) AS hits, a.uid, u.name FROM {accesslog} a LEFT JOIN {users} u ON a.uid = u.uid GROUP BY a.uid, u.name". tablesort_sql($header); + $sql = "SELECT COUNT(a.uid) AS hits, a.uid, u.name, a.hostname, SUM(a.timer) AS total FROM {accesslog} a LEFT JOIN {users} u ON a.uid = u.uid GROUP BY a.hostname". tablesort_sql($header); $sql_cnt = "SELECT COUNT(DISTINCT(uid)) FROM {accesslog}"; $result = pager_query($sql, 30, 0, $sql_cnt); while ($account = db_fetch_object($result)) { - $rows[] = array($account->hits, format_name($account)); + $rows[] = array($account->hits, ($account->uid ? format_name($account) : $account->hostname), format_interval(round($account->total / 1000))); } if ($pager = theme('pager', NULL, 30, 0, tablesort_pager())) { - $rows[] = array(array('data' => $pager, 'colspan' => '2')); + $rows[] = array(array('data' => $pager, 'colspan' => '3')); } - drupal_set_title(t('Top users in the past %interval', array('%interval' => format_interval(variable_get('statistics_flush_accesslog_timer', 259200))))); + drupal_set_title(t('Top visitors in the past %interval', array('%interval' => format_interval(variable_get('statistics_flush_accesslog_timer', 259200))))); return theme('table', $header, $rows); } diff --git a/modules/statistics/statistics.module b/modules/statistics/statistics.module index 20bc687fbdf..62db34e55e4 100644 --- a/modules/statistics/statistics.module +++ b/modules/statistics/statistics.module @@ -114,8 +114,8 @@ function statistics_menu($may_cache) { $items[] = array('path' => 'admin/logs/pages', 'title' => t('top pages'), 'callback' => 'statistics_top_pages', 'access' => $access, 'weight' => 1); - $items[] = array('path' => 'admin/logs/users', 'title' => t('top users'), - 'callback' => 'statistics_top_users', 'access' => $access, + $items[] = array('path' => 'admin/logs/visitors', 'title' => t('top visitors'), + 'callback' => 'statistics_top_visitors', 'access' => $access, 'weight' => 2); $items[] = array('path' => 'admin/logs/referrers', 'title' => t('referrers'), 'callback' => 'statistics_top_referrers', 'access' => $access); @@ -254,8 +254,8 @@ function statistics_top_pages() { $header = array( array('data' => t('Hits'), 'field' => 'hits', 'sort' => 'desc'), array('data' => t('Page'), 'field' => 'path'), - array('data' => t('Average generation time'), 'field' => 'average_time'), - array('data' => t('Total generation time'), 'field' => 'total_time') + array('data' => t('Average page generation time'), 'field' => 'average_time'), + array('data' => t('Total page generation time'), 'field' => 'total_time') ); $sql .= tablesort_sql($header); $result = pager_query($sql, 30, 0, $sql_cnt); @@ -273,28 +273,29 @@ function statistics_top_pages() { } /** - * Menu callback; presents the "top users" page. + * Menu callback; presents the "top visitors" page. */ -function statistics_top_users() { +function statistics_top_visitors() { $header = array( array('data' => t('Hits'), 'field' => 'hits', 'sort' => 'desc'), - array('data' => t('User'), 'field' => 'u.name'), + array('data' => t('Visitor'), 'field' => 'u.name'), + array('data' => t('Total page generation time'), 'field' => 'total'), ); - $sql = "SELECT COUNT(a.uid) AS hits, a.uid, u.name FROM {accesslog} a LEFT JOIN {users} u ON a.uid = u.uid GROUP BY a.uid, u.name". tablesort_sql($header); + $sql = "SELECT COUNT(a.uid) AS hits, a.uid, u.name, a.hostname, SUM(a.timer) AS total FROM {accesslog} a LEFT JOIN {users} u ON a.uid = u.uid GROUP BY a.hostname". tablesort_sql($header); $sql_cnt = "SELECT COUNT(DISTINCT(uid)) FROM {accesslog}"; $result = pager_query($sql, 30, 0, $sql_cnt); while ($account = db_fetch_object($result)) { - $rows[] = array($account->hits, format_name($account)); + $rows[] = array($account->hits, ($account->uid ? format_name($account) : $account->hostname), format_interval(round($account->total / 1000))); } if ($pager = theme('pager', NULL, 30, 0, tablesort_pager())) { - $rows[] = array(array('data' => $pager, 'colspan' => '2')); + $rows[] = array(array('data' => $pager, 'colspan' => '3')); } - drupal_set_title(t('Top users in the past %interval', array('%interval' => format_interval(variable_get('statistics_flush_accesslog_timer', 259200))))); + drupal_set_title(t('Top visitors in the past %interval', array('%interval' => format_interval(variable_get('statistics_flush_accesslog_timer', 259200))))); return theme('table', $header, $rows); }