statistics_top_referrers

  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_referrers()

Menu callback; presents the "referrer" page.

Code

modules/statistics.module, line 313

<?php
function statistics_top_referrers() {
  $query = "SELECT url, COUNT(url) AS hits, MAX(timestamp) AS last FROM {accesslog} WHERE url NOT LIKE '%%%s%%' AND url <> '' GROUP BY url";
  $query_cnt = "SELECT COUNT(DISTINCT(url)) FROM {accesslog} WHERE url <> '' AND url NOT LIKE '%%%s%%'";
  drupal_set_title(t('Top referrers in the past %interval', array('%interval' => format_interval(variable_get('statistics_flush_accesslog_timer', 259200)))));

  $header = array(
    array(
      'data' => t('Hits'),
      'field' => 'hits',
      'sort' => 'desc',
    ),
    array(
      'data' => t('Url'),
      'field' => 'url',
    ),
    array(
      'data' => t('Last visit'),
      'field' => 'last',
    ),
  );

  $query .= tablesort_sql($header);
  $result = pager_query($query, 30, 0, $query_cnt, $_SERVER['HTTP_HOST']);

  while ($referrer = db_fetch_object($result)) {
    $rows[] = array($referrer->hits, _statistics_link($referrer->url), t('%time ago', array('%time' => format_interval(time() - $referrer->last))));
  }

  $output = theme('table', $header, $rows);
  $output .= theme('pager', NULL, 30, 0);
  return $output;
}
?>