statistics_top_visitors

  1. drupal
    1. 4.7
    2. 5 statistics.module
    3. 6 statistics.admin.inc
    4. 7 statistics.admin.inc
Versions
4.7 – 7 statistics_top_visitors()

Menu callback; presents the "top visitors" page.

Code

modules/statistics.module, line 285

<?php
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(uid)) 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/access/rules/delete/$account->aid", array(), $qs) : l(t('ban'), "admin/access/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;
}
?>