| Versions | |
|---|---|
| 4.7 – 7 | statistics_top_pages() |
Menu callback; presents the "top pages" page.
modules/
<?php
function statistics_top_pages() {
$sql = "SELECT COUNT(path) AS hits, path, title, AVG(timer) AS average_time, SUM(timer) AS total_time FROM {accesslog} GROUP BY path, title";
$sql_cnt = "SELECT COUNT(DISTINCT(path)) FROM {accesslog}";
$header = array(
array(
'data' => t('Hits'),
'field' => 'hits',
'sort' => 'desc',
),
array(
'data' => t('Page'),
'field' => 'path',
),
array(
'data' => t('Average page generation time'),
'field' => 'average_time',
),
array(
'data' => t('Total page generation time'),
'field' => 'total_time',
),
);
$sql .= tablesort_sql($header);
$result = pager_query($sql, 30, 0, $sql_cnt);
while ($page = db_fetch_object($result)) {
$rows[] = array($page->hits, _statistics_format_item($page->title, $page->path), t('%time ms', array('%time' => round($page->average_time))), format_interval(round($page->total_time / 1000)));
}
drupal_set_title(t('Top pages 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;
}
?>