You are here

function statistics_top_referrers in Drupal 6

Same name and namespace in other branches
  1. 4 modules/statistics.module \statistics_top_referrers()
  2. 5 modules/statistics/statistics.module \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/statistics.module
Implementation of hook_menu().

File

modules/statistics/statistics.admin.inc, line 108
Admin page callbacks for the statistics module.

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']);
  $rows = array();
  while ($referrer = db_fetch_object($result)) {
    $rows[] = array(
      $referrer->hits,
      _statistics_link($referrer->url),
      t('@time ago', array(
        '@time' => format_interval(time() - $referrer->last),
      )),
    );
  }
  if (empty($rows)) {
    $rows[] = array(
      array(
        'data' => t('No statistics available.'),
        'colspan' => 3,
      ),
    );
  }
  $output = theme('table', $header, $rows);
  $output .= theme('pager', NULL, 30, 0);
  return $output;
}