function statistics_top_visitors in Drupal 5
Same name and namespace in other branches
- 4 modules/statistics.module \statistics_top_visitors()
- 6 modules/statistics/statistics.admin.inc \statistics_top_visitors()
- 7 modules/statistics/statistics.admin.inc \statistics_top_visitors()
Menu callback; presents the "top visitors" page.
1 string reference to 'statistics_top_visitors'
- statistics_menu in modules/
statistics/ statistics.module - Implementation of hook_menu().
File
- modules/
statistics/ statistics.module, line 310 - Logs access statistics for your site.
Code
function statistics_top_visitors() {
$header = array(
array(
'data' => t('Hits'),
'field' => 'hits',
'sort' => 'desc',
),
array(
'data' => t('Visitor'),
'field' => 'u.name',
),
array(
'data' => t('Total page generation time'),
'field' => 'total',
),
array(
'data' => t('Operations'),
),
);
$sql = "SELECT COUNT(a.uid) AS hits, a.uid, u.name, a.hostname, SUM(a.timer) AS total, ac.aid FROM {accesslog} a LEFT JOIN {access} ac ON ac.type = 'host' AND LOWER(a.hostname) LIKE (ac.mask) LEFT JOIN {users} u ON a.uid = u.uid GROUP BY a.hostname, a.uid, u.name, ac.aid" . tablesort_sql($header);
$sql_cnt = "SELECT COUNT(DISTINCT(CONCAT(uid, hostname))) FROM {accesslog}";
$result = pager_query($sql, 30, 0, $sql_cnt);
while ($account = db_fetch_object($result)) {
$qs = drupal_get_destination();
$ban_link = $account->aid ? l(t('unban'), "admin/user/rules/delete/{$account->aid}", array(), $qs) : l(t('ban'), "admin/user/rules/add/{$account->hostname}/host", array(), $qs);
$rows[] = array(
$account->hits,
$account->uid ? theme('username', $account) : $account->hostname,
format_interval(round($account->total / 1000)),
$ban_link,
);
}
drupal_set_title(t('Top visitors in the past %interval', array(
'%interval' => format_interval(variable_get('statistics_flush_accesslog_timer', 259200)),
)));
$output = theme('table', $header, $rows);
$output .= theme('pager', NULL, 30, 0);
return $output;
}