00001 <?php
00002
00003
00012 function statistics_recent_hits() {
00013 $header = array(
00014 array('data' => t('Timestamp'), 'field' => 'a.timestamp', 'sort' => 'desc'),
00015 array('data' => t('Page'), 'field' => 'a.path'),
00016 array('data' => t('User'), 'field' => 'u.name'),
00017 array('data' => t('Operations'))
00018 );
00019
00020 $sql = 'SELECT a.aid, a.path, a.title, a.uid, u.name, a.timestamp FROM {accesslog} a LEFT JOIN {users} u ON u.uid = a.uid' . tablesort_sql($header);
00021
00022 $result = pager_query($sql, 30);
00023 $rows = array();
00024 while ($log = db_fetch_object($result)) {
00025 $rows[] = array(
00026 array('data' => format_date($log->timestamp, 'small'), 'class' => 'nowrap'),
00027 _statistics_format_item($log->title, $log->path),
00028 theme('username', $log),
00029 l(t('details'), "admin/reports/access/$log->aid"));
00030 }
00031
00032 if (empty($rows)) {
00033 $rows[] = array(array('data' => t('No statistics available.'), 'colspan' => 4));
00034 }
00035
00036 $output = theme('table', $header, $rows);
00037 $output .= theme('pager', NULL, 30, 0);
00038 return $output;
00039 }
00040
00044 function statistics_top_pages() {
00045
00046 $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";
00047 $sql_cnt = "SELECT COUNT(DISTINCT(path)) FROM {accesslog}";
00048
00049 $header = array(
00050 array('data' => t('Hits'), 'field' => 'hits', 'sort' => 'desc'),
00051 array('data' => t('Page'), 'field' => 'path'),
00052 array('data' => t('Average page generation time'), 'field' => 'average_time'),
00053 array('data' => t('Total page generation time'), 'field' => 'total_time')
00054 );
00055 $sql .= tablesort_sql($header);
00056 $result = pager_query($sql, 30, 0, $sql_cnt);
00057
00058 $rows = array();
00059 while ($page = db_fetch_object($result)) {
00060 $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)));
00061 }
00062
00063 if (empty($rows)) {
00064 $rows[] = array(array('data' => t('No statistics available.'), 'colspan' => 4));
00065 }
00066
00067 drupal_set_title(t('Top pages in the past %interval', array('%interval' => format_interval(variable_get('statistics_flush_accesslog_timer', 259200)))));
00068 $output = theme('table', $header, $rows);
00069 $output .= theme('pager', NULL, 30, 0);
00070 return $output;
00071 }
00072
00076 function statistics_top_visitors() {
00077
00078 $header = array(
00079 array('data' => t('Hits'), 'field' => 'hits', 'sort' => 'desc'),
00080 array('data' => t('Visitor'), 'field' => 'u.name'),
00081 array('data' => t('Total page generation time'), 'field' => 'total'),
00082 array('data' => user_access('block IP addresses') ? t('Operations') : '', 'colspan' => 2),
00083 );
00084
00085 $sql = "SELECT COUNT(a.uid) AS hits, a.uid, u.name, a.hostname, SUM(a.timer) AS total, bl.iid FROM {accesslog} a LEFT JOIN {blocked_ips} bl ON a.hostname = bl.ip LEFT JOIN {users} u ON a.uid = u.uid GROUP BY a.hostname, a.uid, u.name, bl.iid" . tablesort_sql($header);
00086 $sql_cnt = "SELECT COUNT(DISTINCT(CONCAT(uid, hostname))) FROM {accesslog}";
00087 $result = pager_query($sql, 30, 0, $sql_cnt);
00088
00089 $rows = array();
00090 while ($account = db_fetch_object($result)) {
00091 $qs = drupal_get_destination();
00092 $ban_link = $account->iid ? l(t('unblock IP address'), "admin/settings/ip-blocking/delete/$account->iid", array('query' => $qs)) : l(t('block IP address'), "admin/settings/ip-blocking/$account->hostname", array('query' => $qs));
00093 $rows[] = array($account->hits, ($account->uid ? theme('username', $account) : $account->hostname), format_interval(round($account->total / 1000)), (user_access('block IP addresses') && !$account->uid) ? $ban_link : '');
00094 }
00095
00096 if (empty($rows)) {
00097 $rows[] = array(array('data' => t('No statistics available.'), 'colspan' => 4));
00098 }
00099
00100 drupal_set_title(t('Top visitors in the past %interval', array('%interval' => format_interval(variable_get('statistics_flush_accesslog_timer', 259200)))));
00101 $output = theme('table', $header, $rows);
00102 $output .= theme('pager', NULL, 30, 0);
00103 return $output;
00104 }
00105
00109 function statistics_top_referrers() {
00110 $query = "SELECT url, COUNT(url) AS hits, MAX(timestamp) AS last FROM {accesslog} WHERE url NOT LIKE '%%%s%%' AND url <> '' GROUP BY url";
00111 $query_cnt = "SELECT COUNT(DISTINCT(url)) FROM {accesslog} WHERE url <> '' AND url NOT LIKE '%%%s%%'";
00112 drupal_set_title(t('Top referrers in the past %interval', array('%interval' => format_interval(variable_get('statistics_flush_accesslog_timer', 259200)))));
00113
00114 $header = array(
00115 array('data' => t('Hits'), 'field' => 'hits', 'sort' => 'desc'),
00116 array('data' => t('Url'), 'field' => 'url'),
00117 array('data' => t('Last visit'), 'field' => 'last'),
00118 );
00119
00120 $query .= tablesort_sql($header);
00121 $result = pager_query($query, 30, 0, $query_cnt, $_SERVER['HTTP_HOST']);
00122
00123 $rows = array();
00124 while ($referrer = db_fetch_object($result)) {
00125 $rows[] = array($referrer->hits, _statistics_link($referrer->url), t('@time ago', array('@time' => format_interval(time() - $referrer->last))));
00126 }
00127
00128 if (empty($rows)) {
00129 $rows[] = array(array('data' => t('No statistics available.'), 'colspan' => 3));
00130 }
00131
00132 $output = theme('table', $header, $rows);
00133 $output .= theme('pager', NULL, 30, 0);
00134 return $output;
00135 }
00136
00140 function statistics_access_log($aid) {
00141 $result = db_query('SELECT a.*, u.name FROM {accesslog} a LEFT JOIN {users} u ON a.uid = u.uid WHERE aid = %d', $aid);
00142 if ($access = db_fetch_object($result)) {
00143 $rows[] = array(
00144 array('data' => t('URL'), 'header' => TRUE),
00145 l(url($access->path, array('absolute' => TRUE)), $access->path)
00146 );
00147
00148
00149 $rows[] = array(
00150 array('data' => t('Title'), 'header' => TRUE),
00151 $access->title
00152 );
00153 $rows[] = array(
00154 array('data' => t('Referrer'), 'header' => TRUE),
00155 ($access->url ? l($access->url, $access->url) : '')
00156 );
00157 $rows[] = array(
00158 array('data' => t('Date'), 'header' => TRUE),
00159 format_date($access->timestamp, 'large')
00160 );
00161 $rows[] = array(
00162 array('data' => t('User'), 'header' => TRUE),
00163 theme('username', $access)
00164 );
00165 $rows[] = array(
00166 array('data' => t('Hostname'), 'header' => TRUE),
00167 check_plain($access->hostname)
00168 );
00169
00170 return theme('table', array(), $rows);
00171 }
00172 else {
00173 drupal_not_found();
00174 }
00175 }
00176
00183 function statistics_access_logging_settings() {
00184
00185 $options = array('1' => t('Enabled'), '0' => t('Disabled'));
00186 $form['access'] = array(
00187 '#type' => 'fieldset',
00188 '#title' => t('Access log settings'));
00189 $form['access']['statistics_enable_access_log'] = array(
00190 '#type' => 'radios',
00191 '#title' => t('Enable access log'),
00192 '#default_value' => variable_get('statistics_enable_access_log', 0),
00193 '#options' => $options,
00194 '#description' => t('Log each page access. Required for referrer statistics.'));
00195 $period = drupal_map_assoc(array(3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200, 4838400, 9676800), 'format_interval');
00196 $form['access']['statistics_flush_accesslog_timer'] = array(
00197 '#type' => 'select',
00198 '#title' => t('Discard access logs older than'),
00199 '#default_value' => variable_get('statistics_flush_accesslog_timer', 259200),
00200 '#options' => $period,
00201 '#description' => t('Older access log entries (including referrer statistics) will be automatically discarded. (Requires a correctly configured <a href="@cron">cron maintenance task</a>.)', array('@cron' => url('admin/reports/status'))));
00202
00203
00204 $form['content'] = array(
00205 '#type' => 'fieldset',
00206 '#title' => t('Content viewing counter settings'));
00207 $form['content']['statistics_count_content_views'] = array(
00208 '#type' => 'radios',
00209 '#title' => t('Count content views'),
00210 '#default_value' => variable_get('statistics_count_content_views', 0),
00211 '#options' => $options,
00212 '#description' => t('Increment a counter each time content is viewed.'));
00213
00214 return system_settings_form($form);
00215 }