You are here

function statistics_top_pages in Drupal 4

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

Menu callback; presents the "top pages" page.

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

File

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

Code

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