Do not count views of administrators or creators

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

<?php
// $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');
}
?>

 
 

Drupal is a registered trademark of Dries Buytaert.