You are here

function statistics_top_referrers in Drupal 4

Same name and namespace in other branches
  1. 5 modules/statistics/statistics.module \statistics_top_referrers()
  2. 6 modules/statistics/statistics.admin.inc \statistics_top_referrers()
  3. 7 modules/statistics/statistics.admin.inc \statistics_top_referrers()

Menu callback; presents the "referrer" page.

1 string reference to 'statistics_top_referrers'
statistics_menu in modules/statistics.module
Implementation of hook_menu().

File

modules/statistics.module, line 312
Logs access statistics for your site.

Code

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;
}