Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
This mini module prevents the statistics module to increase the view counter if an administrator or the author of the node has viewed a node.
Download: http://e-faux.com/node/45
// $Id$
/**
* Implementation of hook_exit().
*
* Decrement counter of current viewed node if user is admin or author of node.
*/
function noadmincount_exit() {
global $user;
// Check if we are counting views.
if (variable_get('statistics_count_content_views', 0)) {
// Check if current page displays a node in viewing mode.
if ((arg(0) == 'node') && is_numeric(arg(1)) && arg(2) == '') {
// Check if the user is admin or author.
if (user_access('administer nodes') || $user->uid == node_load(arg(1))->uid) {
// Decrement total view count and day view count of current node.
db_query('UPDATE {node_counter} SET daycount = daycount - 1, totalcount = totalcount - 1, timestamp = %d WHERE nid = %d', time(), arg(1));
}
}
}
}
/**
* Implementation of hook_cron().
*
* Delete entries with zero views. Such entries may exist because noadmincount_exit()
* does not delete zero viewed lines.
*/
function noadmincount_cron() {
db_query('DELETE FROM {node_counter} WHERE totalcount = 0');
}
Alternatives
Modules which provide similar functionality:
http://drupal.org/project/statistics_filter
http://drupal.org/project/statistics_advanced
See also http://drupal.org/node/305764, which suggests merging the two modules. Any help is much appreciated!