function statistics_top_pages

Same name and namespace in other branches
  1. 7.x drupal-7.x/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 drupal-6.x/modules/statistics/statistics.module
Implementation of hook_menu().

Archivo

drupal-6.x/modules/statistics/statistics.admin.inc, line 43
Admin page callbacks for the statistics module.

Código

function statistics_top_pages() {
  // MAX(title) avoids having empty node titles which otherwise causes duplicates in the top pages list
  $sql = "SELECT COUNT(path) AS hits, path, MAX(title) AS title, AVG(timer) AS average_time, SUM(timer) AS total_time FROM {accesslog} GROUP BY path";
  $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);

  $rows = array();
  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)));
  }

  if (empty($rows)) {
    $rows[] = array(array(
      'data' => t('No statistics available.'),
      'colspan' => 4,
    ));
  }

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