statistics_top_referrers
- Versions
- 4.6 – 7
statistics_top_referrers()
Menu callback; presents the "referrer" page.
Code
modules/statistics/statistics.admin.inc, line 155
<?php
function statistics_top_referrers() {
drupal_set_title(t('Top referrers in the past %interval', array('%interval' => format_interval(variable_get('statistics_flush_accesslog_timer', 259200)))), PASS_THROUGH);
$header = array(
array('data' => t('Hits'), 'field' => 'hits', 'sort' => 'desc'),
array('data' => t('Url'), 'field' => 'url'),
array('data' => t('Last visit'), 'field' => 'last'),
);
$query = db_select('accesslog', 'a')->extend('PagerDefault')->extend('TableSort');
$query->addExpression('COUNT(url)', 'hits');
$query->addExpression('MAX(timestamp)', 'last');
$query
->fields('a', array('url'))
->where('LOWER(url) NOT LIKE :host', array(':host' => '%' . $_SERVER['HTTP_HOST'] . '%'))
->condition('url', '', '<>')
->groupBy('url')
->limit(30)
->orderByHeader($header);
$count_query = db_select('accesslog', array('target' => 'slave'));
$count_query->addExpression('COUNT(DISTINCT url)');
$count_query
->where('LOWER(url) NOT LIKE :host', array(':host' => '%' . $_SERVER['HTTP_HOST'] . '%'))
->condition('url', '', '<>');
$query->setCountQuery($count_query);
$result = $query->execute();
$rows = array();
foreach ($result as $referrer) {
$rows[] = array($referrer->hits, _statistics_link($referrer->url), t('@time ago', array('@time' => format_interval(REQUEST_TIME - $referrer->last))));
}
if (empty($rows)) {
$rows[] = array(array('data' => t('No statistics available.'), 'colspan' => 3));
}
$build['statistics_top_referrers_table'] = array(
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
);
$build['statistics_top_referrers_pager'] = array('#theme' => 'pager');
return $build;
}
?>Login or register to post comments 