Initial code using Drupal 6.38

This commit is contained in:
Manuel Cillero 2017-07-24 15:21:05 +02:00
commit 4824608a33
467 changed files with 90887 additions and 0 deletions

View file

@ -0,0 +1,214 @@
<?php
/**
* @file
* Admin page callbacks for the statistics module.
*/
/**
* Menu callback; presents the "recent hits" page.
*/
function statistics_recent_hits() {
$header = array(
array('data' => t('Timestamp'), 'field' => 'a.timestamp', 'sort' => 'desc'),
array('data' => t('Page'), 'field' => 'a.path'),
array('data' => t('User'), 'field' => 'u.name'),
array('data' => t('Operations'))
);
$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);
$result = pager_query($sql, 30);
$rows = array();
while ($log = db_fetch_object($result)) {
$rows[] = array(
array('data' => format_date($log->timestamp, 'small'), 'class' => 'nowrap'),
_statistics_format_item($log->title, $log->path),
theme('username', $log),
l(t('details'), "admin/reports/access/$log->aid"));
}
if (empty($rows)) {
$rows[] = array(array('data' => t('No statistics available.'), 'colspan' => 4));
}
$output = theme('table', $header, $rows);
$output .= theme('pager', NULL, 30, 0);
return $output;
}
/**
* Menu callback; presents the "top pages" page.
*/
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;
}
/**
* Menu callback; presents the "top visitors" page.
*/
function statistics_top_visitors() {
$header = array(
array('data' => t('Hits'), 'field' => 'hits', 'sort' => 'desc'),
array('data' => t('Visitor'), 'field' => 'u.name'),
array('data' => t('Total page generation time'), 'field' => 'total'),
array('data' => t('Operations'))
);
$sql = "SELECT COUNT(a.uid) AS hits, a.uid, u.name, a.hostname, SUM(a.timer) AS total, ac.aid FROM {accesslog} a LEFT JOIN {access} ac ON ac.type = 'host' AND LOWER(a.hostname) LIKE (ac.mask) LEFT JOIN {users} u ON a.uid = u.uid GROUP BY a.hostname, a.uid, u.name, ac.aid". tablesort_sql($header);
$sql_cnt = "SELECT COUNT(*) FROM (SELECT DISTINCT uid, hostname FROM {accesslog}) AS unique_visits";
$result = pager_query($sql, 30, 0, $sql_cnt);
$rows = array();
while ($account = db_fetch_object($result)) {
$qs = drupal_get_destination();
$ban_link = $account->aid ? l(t('unban'), "admin/user/rules/delete/$account->aid", array('query' => $qs)) : l(t('ban'), "admin/user/rules/add/$account->hostname/host", array('query' => $qs));
$rows[] = array($account->hits, ($account->uid ? theme('username', $account) : $account->hostname), format_interval(round($account->total / 1000)), $ban_link);
}
if (empty($rows)) {
$rows[] = array(array('data' => t('No statistics available.'), 'colspan' => 4));
}
drupal_set_title(t('Top visitors 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;
}
/**
* Menu callback; presents the "referrer" page.
*/
function statistics_top_referrers() {
$query = "SELECT url, COUNT(url) AS hits, MAX(timestamp) AS last FROM {accesslog} WHERE url NOT LIKE '%%%s%%' AND url <> '' GROUP BY url";
$query_cnt = "SELECT COUNT(DISTINCT(url)) FROM {accesslog} WHERE url <> '' AND url NOT LIKE '%%%s%%'";
drupal_set_title(t('Top referrers in the past %interval', array('%interval' => format_interval(variable_get('statistics_flush_accesslog_timer', 259200)))));
$header = array(
array('data' => t('Hits'), 'field' => 'hits', 'sort' => 'desc'),
array('data' => t('Url'), 'field' => 'url'),
array('data' => t('Last visit'), 'field' => 'last'),
);
$query .= tablesort_sql($header);
$result = pager_query($query, 30, 0, $query_cnt, $_SERVER['HTTP_HOST']);
$rows = array();
while ($referrer = db_fetch_object($result)) {
$rows[] = array($referrer->hits, _statistics_link($referrer->url), t('@time ago', array('@time' => format_interval(time() - $referrer->last))));
}
if (empty($rows)) {
$rows[] = array(array('data' => t('No statistics available.'), 'colspan' => 3));
}
$output = theme('table', $header, $rows);
$output .= theme('pager', NULL, 30, 0);
return $output;
}
/**
* Menu callback; Displays recent page accesses.
*/
function statistics_access_log($aid) {
$result = db_query('SELECT a.*, u.name FROM {accesslog} a LEFT JOIN {users} u ON a.uid = u.uid WHERE aid = %d', $aid);
if ($access = db_fetch_object($result)) {
$rows[] = array(
array('data' => t('URL'), 'header' => TRUE),
l(url($access->path, array('absolute' => TRUE)), $access->path)
);
// It is safe to avoid filtering $access->title through check_plain because
// it comes from drupal_get_title().
$rows[] = array(
array('data' => t('Title'), 'header' => TRUE),
$access->title
);
$rows[] = array(
array('data' => t('Referrer'), 'header' => TRUE),
($access->url ? l($access->url, $access->url) : '')
);
$rows[] = array(
array('data' => t('Date'), 'header' => TRUE),
format_date($access->timestamp, 'large')
);
$rows[] = array(
array('data' => t('User'), 'header' => TRUE),
theme('username', $access)
);
$rows[] = array(
array('data' => t('Hostname'), 'header' => TRUE),
check_plain($access->hostname)
);
return theme('table', array(), $rows);
}
else {
drupal_not_found();
}
}
/**
* Form builder; Configure access logging.
*
* @ingroup forms
* @see system_settings_form()
*/
function statistics_access_logging_settings() {
// Access log settings:
$options = array('1' => t('Enabled'), '0' => t('Disabled'));
$form['access'] = array(
'#type' => 'fieldset',
'#title' => t('Access log settings'));
$form['access']['statistics_enable_access_log'] = array(
'#type' => 'radios',
'#title' => t('Enable access log'),
'#default_value' => variable_get('statistics_enable_access_log', 0),
'#options' => $options,
'#description' => t('Log each page access. Required for referrer statistics.'));
$period = array('0' => t('Never')) + drupal_map_assoc(array(3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200, 4838400, 9676800), 'format_interval');
$form['access']['statistics_flush_accesslog_timer'] = array(
'#type' => 'select',
'#title' => t('Discard access logs older than'),
'#default_value' => variable_get('statistics_flush_accesslog_timer', 259200),
'#options' => $period,
'#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'))));
// count content views settings
$form['content'] = array(
'#type' => 'fieldset',
'#title' => t('Content viewing counter settings'));
$form['content']['statistics_count_content_views'] = array(
'#type' => 'radios',
'#title' => t('Count content views'),
'#default_value' => variable_get('statistics_count_content_views', 0),
'#options' => $options,
'#description' => t('Increment a counter each time content is viewed.'));
return system_settings_form($form);
}

View file

@ -0,0 +1,11 @@
name = Statistics
description = Logs access statistics for your site.
package = Core - optional
version = VERSION
core = 6.x
; Information added by Drupal.org packaging script on 2016-02-24
version = "6.38"
project = "drupal"
datestamp = "1456343372"

View file

@ -0,0 +1,137 @@
<?php
/**
* Implementation of hook_install().
*/
function statistics_install() {
// Create tables.
drupal_install_schema('statistics');
}
/**
* Changes session ID field to VARCHAR(64) to add support for SHA-1 hashes.
*/
function statistics_update_1000() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {accesslog} CHANGE COLUMN sid sid varchar(64) NOT NULL default ''");
break;
case 'pgsql':
db_change_column($ret, 'accesslog', 'sid', 'sid', 'varchar(64)', array('not null' => TRUE, 'default' => "''"));
break;
}
return $ret;
}
/**
* Implementation of hook_uninstall().
*/
function statistics_uninstall() {
// Remove tables.
drupal_uninstall_schema('statistics');
variable_del('statistics_count_content_views');
variable_del('statistics_enable_access_log');
variable_del('statistics_flush_accesslog_timer');
variable_del('statistics_day_timestamp');
variable_del('statistics_block_top_day_num');
variable_del('statistics_block_top_all_num');
variable_del('statistics_block_top_last_num');
}
/**
* Implementation of hook_schema().
*/
function statistics_schema() {
$schema['accesslog'] = array(
'description' => 'Stores site access information for statistics.',
'fields' => array(
'aid' => array(
'type' => 'serial',
'not null' => TRUE,
'description' => 'Primary Key: Unique accesslog ID.',
),
'sid' => array(
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'default' => '',
'description' => 'Browser session ID of user that visited page.',
),
'title' => array(
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'description' => 'Title of page visited.',
),
'path' => array(
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'description' => 'Internal path to page visited (relative to Drupal root.)',
),
'url' => array(
'type' => 'text',
'not null' => FALSE,
'description' => 'Referrer URI.',
),
'hostname' => array(
'type' => 'varchar',
'length' => 128,
'not null' => FALSE,
'description' => 'Hostname of user that visited the page.',
),
'uid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE,
'default' => 0,
'description' => 'User {users}.uid that visited the page.',
),
'timer' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'Time in milliseconds that the page took to load.',
),
'timestamp' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'Timestamp of when the page was visited.',
),
),
'indexes' => array(
'accesslog_timestamp' => array('timestamp'),
'uid' => array('uid'),
),
'primary key' => array('aid'),
);
return $schema;
}
/**
* @addtogroup updates-6.x-extra
* @{
*/
/**
* Allow longer referrers.
*/
function statistics_update_6000() {
$ret = array();
db_change_field($ret, 'accesslog', 'url', 'url', array('type' => 'text', 'not null' => FALSE));
return $ret;
}
/**
* @} End of "addtogroup updates-6.x-extra".
* The next series of updates should start at 7000.
*/

View file

@ -0,0 +1,322 @@
<?php
/**
* @file
* Logs access statistics for your site.
*/
/**
* Implementation of hook_help().
*/
function statistics_help($path, $arg) {
switch ($path) {
case 'admin/help#statistics':
$output = '<p>'. t('The statistics module keeps track of numerous site usage statistics, including the number of times, and from where, each of your posts is viewed. These statistics are useful in determining how users are interacting with each other and with your site, and are required for the display of some Drupal blocks.') .'</p>';
$output .= '<p>'. t('The statistics module provides:') .'</p>';
$output .= '<ul><li>'. t('a counter for each post on your site that increments each time the post is viewed. (Enable <em>Count content views</em> on the <a href="@accesslog">access log settings page</a>, and determine if the post access counters should be visible to any user roles on the <a href="@permissions">permissions page</a>.)', array('@accesslog' => url('admin/reports/settings'), '@permissions' => url('admin/user/permissions'))) .'</li>';
$output .= '<li>'. t('a <a href="@recent-hits">recent hits</a> log that displays information about the latest activity on your site, including the URL and title of the page accessed, the user name (if available) and IP address of the accessing party.', array('@recent-hits' => url('admin/reports/hits'))) .'</li>';
$output .= '<li>'. t('a <a href="@top-referrers">top referrers</a> log that displays the referring parties for your site visits (where your visitors came from).', array('@top-referrers' => url('admin/reports/referrers'))) .'</li>';
$output .= '<li>'. t('a <a href="@top-pages">top pages</a> log that displays site content in descending order by number of views.', array('@top-pages' => url('admin/reports/pages'))) .'</li>';
$output .= '<li>'. t('a <a href="@top-visitors">top visitors</a> log that displays the most active users on your site.', array('@top-visitors' => url('admin/reports/visitors'))) .'</li>';
$output .= '<li>'. t('a <em>Popular content</em> block that displays the day\'s most viewed content, the all-time most viewed content, and the last content viewed. (Enable the <em>Popular content</em> block on the <a href="@blocks">blocks administration page</a>.)', array('@blocks' => url('admin/build/block'))) .'</li></ul>';
$output .= '<p>'. t('Configuring the statistics module') .'</p>';
$output .= '<ul><li>'. t('When the <em>Enable access log</em> setting on the <a href="@accesslog">access log settings page</a> is enabled, data about every page accessed (including the remote host\'s IP address, referrer, node accessed, and user name) is stored in the access log. The access log must be enabled for the <a href="@recent-hits">recent hits</a>, <a href="@top-referrers">top referrers</a>, <a href="@top-pages">top pages</a>, and <a href="@top-visitors">top visitors</a> log pages to function. Enabling the access log adds one additional database call per page displayed by Drupal.', array('@accesslog' => url('admin/reports/settings'), '@recent-hits' => url('admin/reports/hits'), '@top-referrers' => url('admin/reports/referrers'), '@top-pages' => url('admin/reports/pages'), '@top-visitors' => url('admin/reports/visitors'))) .'</li>';
$output .= '<li>'. t('The <em>Discard access logs older than</em> setting on the <a href="@accesslog">access log settings page</a> specifies the length of time entries are retained in the access log before they are deleted. Automatic access log entry deletion requires a correctly configured <a href="@cron">cron maintenance task</a>.', array('@accesslog' => url('admin/reports/settings'), '@cron' => url('admin/reports/status'))) .'</li>';
$output .= '<li>'. t('The <em>Count content views</em> setting on the <a href="@accesslog">access log settings page</a> enables a counter for each post on your site that increments each time the post is viewed. This option must be enabled to provide post-specific access counts. Enabling this option adds one additional database call per each post displayed by Drupal.', array('@accesslog' => url('admin/reports/settings'))) .'</li></ul>';
$output .= '<p>'. t('For more information, see the online handbook entry for <a href="@statistics">Statistics module</a>.', array('@statistics' => 'http://drupal.org/handbook/modules/statistics/')) .'</p>';
return $output;
case 'admin/reports/settings':
return '<p>'. t('Settings for the statistical information that Drupal will keep about the site. See <a href="@statistics">site statistics</a> for the actual information.', array('@statistics' => url('admin/reports/hits'))) .'</p>';
case 'admin/reports/hits':
return '<p>'. t("This page displays the site's most recent hits.") .'</p>';
case 'admin/reports/referrers':
return '<p>'. t('This page displays all external referrers, or external references to your website.') .'</p>';
case 'admin/reports/visitors':
return '<p>'. t("When you ban a visitor, you prevent the visitor's IP address from accessing your site. Unlike blocking a user, banning a visitor works even for anonymous users. This is most commonly used to block resource-intensive bots or web crawlers.") .'</p>';
}
}
/**
* Implementation of hook_exit().
*
* This is where statistics are gathered on page accesses.
*/
function statistics_exit() {
global $user, $recent_activity;
drupal_bootstrap(DRUPAL_BOOTSTRAP_PATH);
if (variable_get('statistics_count_content_views', 0)) {
// We are counting content views.
if ((arg(0) == 'node') && is_numeric(arg(1)) && arg(2) == '') {
// A node has been viewed, so update the node's counters.
db_query('UPDATE {node_counter} SET daycount = daycount + 1, totalcount = totalcount + 1, timestamp = %d WHERE nid = %d', time(), arg(1));
// If we affected 0 rows, this is the first time viewing the node.
if (!db_affected_rows()) {
// We must create a new row to store counters for the new node.
db_query('INSERT INTO {node_counter} (nid, daycount, totalcount, timestamp) VALUES (%d, 1, 1, %d)', arg(1), time());
}
}
}
if ((variable_get('statistics_enable_access_log', 0)) && (module_invoke('throttle', 'status') == 0)) {
// Log this page access.
db_query("INSERT INTO {accesslog} (title, path, url, hostname, uid, sid, timer, timestamp) values('%s', '%s', '%s', '%s', %d, '%s', %d, %d)", strip_tags(drupal_get_title()), $_GET['q'], referer_uri(), ip_address(), $user->uid, session_id(), timer_read('page'), time());
}
}
/**
* Implementation of hook_perm().
*/
function statistics_perm() {
return array('access statistics', 'view post access counter');
}
/**
* Implementation of hook_link().
*/
function statistics_link($type, $node = NULL, $teaser = FALSE) {
global $id;
$links = array();
if ($type == 'node' && user_access('view post access counter')) {
$statistics = statistics_get($node->nid);
if ($statistics) {
$links['statistics_counter']['title'] = format_plural($statistics['totalcount'], '1 read', '@count reads');
}
}
return $links;
}
/**
* Implementation of hook_menu().
*/
function statistics_menu() {
$items['admin/reports/hits'] = array(
'title' => 'Recent hits',
'description' => 'View pages that have recently been visited.',
'page callback' => 'statistics_recent_hits',
'access arguments' => array('access statistics'),
'file' => 'statistics.admin.inc',
);
$items['admin/reports/pages'] = array(
'title' => 'Top pages',
'description' => 'View pages that have been hit frequently.',
'page callback' => 'statistics_top_pages',
'access arguments' => array('access statistics'),
'weight' => 1,
'file' => 'statistics.admin.inc',
);
$items['admin/reports/visitors'] = array(
'title' => 'Top visitors',
'description' => 'View visitors that hit many pages.',
'page callback' => 'statistics_top_visitors',
'access arguments' => array('access statistics'),
'weight' => 2,
'file' => 'statistics.admin.inc',
);
$items['admin/reports/referrers'] = array(
'title' => 'Top referrers',
'description' => 'View top referrers.',
'page callback' => 'statistics_top_referrers',
'access arguments' => array('access statistics'),
'file' => 'statistics.admin.inc',
);
$items['admin/reports/access/%'] = array(
'title' => 'Details',
'description' => 'View access log.',
'page callback' => 'statistics_access_log',
'page arguments' => array(3),
'access arguments' => array('access statistics'),
'type' => MENU_CALLBACK,
'file' => 'statistics.admin.inc',
);
$items['admin/reports/settings'] = array(
'title' => 'Access log settings',
'description' => 'Control details about what and how your site logs.',
'page callback' => 'drupal_get_form',
'page arguments' => array('statistics_access_logging_settings'),
'access arguments' => array('administer site configuration'),
'type' => MENU_NORMAL_ITEM,
'weight' => 3,
'file' => 'statistics.admin.inc',
);
$items['user/%user/track/navigation'] = array(
'title' => 'Track page visits',
'page callback' => 'statistics_user_tracker',
'access callback' => 'user_access',
'access arguments' => array('access statistics'),
'type' => MENU_LOCAL_TASK,
'weight' => 2,
'file' => 'statistics.pages.inc',
);
$items['node/%node/track'] = array(
'title' => 'Track',
'page callback' => 'statistics_node_tracker',
'access callback' => 'user_access',
'access arguments' => array('access statistics'),
'type' => MENU_LOCAL_TASK,
'weight' => 2,
'file' => 'statistics.pages.inc',
);
return $items;
}
/**
* Implementation of hook_user().
*/
function statistics_user($op, &$edit, &$user) {
if ($op == 'delete') {
db_query('UPDATE {accesslog} SET uid = 0 WHERE uid = %d', $user->uid);
}
}
/**
* Implementation of hook_cron().
*/
function statistics_cron() {
$statistics_timestamp = variable_get('statistics_day_timestamp', '');
if ((time() - $statistics_timestamp) >= 86400) {
// Reset day counts.
db_query('UPDATE {node_counter} SET daycount = 0');
variable_set('statistics_day_timestamp', time());
}
// Clean up expired access logs.
if (variable_get('statistics_flush_accesslog_timer', 259200) > 0) {
db_query('DELETE FROM {accesslog} WHERE timestamp < %d', time() - variable_get('statistics_flush_accesslog_timer', 259200));
}
}
/**
* Returns all time or today top or last viewed node(s).
*
* @param $dbfield
* one of
* - 'totalcount': top viewed content of all time.
* - 'daycount': top viewed content for today.
* - 'timestamp': last viewed node.
*
* @param $dbrows
* number of rows to be returned.
*
* @return
* A query result containing n.nid, n.title, u.uid, u.name of the selected node(s)
* or FALSE if the query could not be executed correctly.
*/
function statistics_title_list($dbfield, $dbrows) {
if (in_array($dbfield, array('totalcount', 'daycount', 'timestamp'))) {
return db_query_range(db_rewrite_sql("SELECT n.nid, n.title, u.uid, u.name FROM {node} n INNER JOIN {node_counter} s ON n.nid = s.nid INNER JOIN {users} u ON n.uid = u.uid WHERE s.". $dbfield ." != 0 AND n.status = 1 ORDER BY s.". $dbfield ." DESC"), 0, $dbrows);
}
return FALSE;
}
/**
* Retrieves a node's "view statistics".
*
* @param $nid
* node ID
*
* @return
* An array with three entries: [0]=totalcount, [1]=daycount, [2]=timestamp
* - totalcount: count of the total number of times that node has been viewed.
* - daycount: count of the total number of times that node has been viewed "today".
* For the daycount to be reset, cron must be enabled.
* - timestamp: timestamp of when that node was last viewed.
*/
function statistics_get($nid) {
if ($nid > 0) {
// Retrieve an array with both totalcount and daycount.
$statistics = db_fetch_array(db_query('SELECT totalcount, daycount, timestamp FROM {node_counter} WHERE nid = %d', $nid));
}
return $statistics;
}
/**
* Implementation of hook_block().
*/
function statistics_block($op = 'list', $delta = 0, $edit = array()) {
switch ($op) {
case 'list':
if (variable_get('statistics_count_content_views', 0)) {
$blocks[0]['info'] = t('Popular content');
// Too dynamic to cache.
$blocks[0]['cache'] = BLOCK_NO_CACHE;
return $blocks;
}
break;
case 'configure':
// Popular content block settings
$numbers = array('0' => t('Disabled')) + drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30, 40));
$form['statistics_block_top_day_num'] = array('#type' => 'select', '#title' => t("Number of day's top views to display"), '#default_value' => variable_get('statistics_block_top_day_num', 0), '#options' => $numbers, '#description' => t('How many content items to display in "day" list.'));
$form['statistics_block_top_all_num'] = array('#type' => 'select', '#title' => t('Number of all time views to display'), '#default_value' => variable_get('statistics_block_top_all_num', 0), '#options' => $numbers, '#description' => t('How many content items to display in "all time" list.'));
$form['statistics_block_top_last_num'] = array('#type' => 'select', '#title' => t('Number of most recent views to display'), '#default_value' => variable_get('statistics_block_top_last_num', 0), '#options' => $numbers, '#description' => t('How many content items to display in "recently viewed" list.'));
return $form;
case 'save':
variable_set('statistics_block_top_day_num', $edit['statistics_block_top_day_num']);
variable_set('statistics_block_top_all_num', $edit['statistics_block_top_all_num']);
variable_set('statistics_block_top_last_num', $edit['statistics_block_top_last_num']);
break;
case 'view':
if (user_access('access content')) {
$content = array();
$daytop = variable_get('statistics_block_top_day_num', 0);
if ($daytop && ($result = statistics_title_list('daycount', $daytop)) && ($node_title_list = node_title_list($result, t("Today's:")))) {
$content[] = $node_title_list;
}
$alltimetop = variable_get('statistics_block_top_all_num', 0);
if ($alltimetop && ($result = statistics_title_list('totalcount', $alltimetop)) && ($node_title_list = node_title_list($result, t('All time:')))) {
$content[] = $node_title_list;
}
$lasttop = variable_get('statistics_block_top_last_num', 0);
if ($lasttop && ($result = statistics_title_list('timestamp', $lasttop)) && ($node_title_list = node_title_list($result, t('Last viewed:')))) {
$content[] = $node_title_list;
}
if (count($content)) {
$block['content'] = implode('<br />', $content);
$block['subject'] = t('Popular content');
return $block;
}
}
}
}
/**
* It is possible to adjust the width of columns generated by the
* statistics module.
*/
function _statistics_link($path, $width = 35) {
$title = drupal_get_path_alias($path);
$title = truncate_utf8($title, $width, FALSE, TRUE);
return l($title, $path);
}
function _statistics_format_item($title, $path) {
$path = ($path ? $path : '/');
$output = ($title ? "$title<br />" : '');
$output .= _statistics_link($path);
return $output;
}
/**
* Implementation of hook_nodeapi().
*/
function statistics_nodeapi(&$node, $op, $arg = 0) {
switch ($op) {
case 'delete':
// clean up statistics table when node is deleted
db_query('DELETE FROM {node_counter} WHERE nid = %d', $node->nid);
}
}

View file

@ -0,0 +1,70 @@
<?php
/**
* @file
* User page callbacks for the statistics module.
*/
function statistics_node_tracker() {
if ($node = node_load(arg(1))) {
$header = array(
array('data' => t('Time'), 'field' => 'a.timestamp', 'sort' => 'desc'),
array('data' => t('Referrer'), 'field' => 'a.url'),
array('data' => t('User'), 'field' => 'u.name'),
array('data' => t('Operations')));
$result = pager_query("SELECT a.aid, a.timestamp, a.url, a.uid, u.name FROM {accesslog} a LEFT JOIN {users} u ON a.uid = u.uid WHERE a.path = 'node/%d' OR a.path LIKE 'node/%d/%%'". tablesort_sql($header), 30, 0, NULL, $node->nid, $node->nid);
$rows = array();
while ($log = db_fetch_object($result)) {
$rows[] = array(
array('data' => format_date($log->timestamp, 'small'), 'class' => 'nowrap'),
_statistics_link($log->url),
theme('username', $log),
l(t('details'), "admin/reports/access/$log->aid"));
}
if (empty($rows)) {
$rows[] = array(array('data' => t('No statistics available.'), 'colspan' => 4));
}
drupal_set_title(check_plain($node->title));
$output = theme('table', $header, $rows);
$output .= theme('pager', NULL, 30, 0);
return $output;
}
else {
drupal_not_found();
}
}
function statistics_user_tracker() {
if ($account = user_load(array('uid' => arg(1)))) {
$header = array(
array('data' => t('Timestamp'), 'field' => 'timestamp', 'sort' => 'desc'),
array('data' => t('Page'), 'field' => 'path'),
array('data' => t('Operations')));
$result = pager_query('SELECT aid, timestamp, path, title FROM {accesslog} WHERE uid = %d'. tablesort_sql($header), 30, 0, NULL, $account->uid);
$rows = array();
while ($log = db_fetch_object($result)) {
$rows[] = array(
array('data' => format_date($log->timestamp, 'small'), 'class' => 'nowrap'),
_statistics_format_item($log->title, $log->path),
l(t('details'), "admin/reports/access/$log->aid"));
}
if (empty($rows)) {
$rows[] = array(array('data' => t('No statistics available.'), 'colspan' => 3));
}
drupal_set_title(check_plain($account->name));
$output = theme('table', $header, $rows);
$output .= theme('pager', NULL, 30, 0);
return $output;
}
else {
drupal_not_found();
}
}