Index: statistics.module =================================================================== RCS file: /cvs/drupal/drupal/modules/statistics.module,v retrieving revision 1.203 diff -u -r1.203 statistics.module --- statistics.module 16 Aug 2005 19:48:04 -0000 1.203 +++ statistics.module 21 Aug 2005 17:21:15 -0000 @@ -32,8 +32,9 @@
This module creates a block that can display the day's top viewed content, the all time top viewed content, and the last content viewed. Each of these links can be enabled or disabled individually, and the number of posts displayed for each can be configured with a drop down menu. If you disable all sections of this block, it will not appear.
@@ -59,22 +60,54 @@ */ function statistics_exit() { global $user, $recent_activity; + + $do_filtering = FALSE; + + // Who are we ignoring? + $filter_admin = variable_get('statistics_filter_noadmin', FALSE); + if ($filter_admin && ($user->uid == 1)) { + $do_filtering = TRUE; + } else { + $filtered_roles = variable_get('statistics_filter_roles', FALSE); + if (is_array($filtered_roles)) { + $filtered_roles = array_flip($filtered_roles); + foreach ($user->roles as $key => $value) { + if (isset($filtered_roles[$key])) { + $do_filtering = TRUE; + break; + } + } + } + } - if (variable_get('statistics_count_content_views', 0)) { - // We are counting content views. - if ((arg(0) == 'node') && arg(1)) { - // 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()); + // Ignore crawlers if requested + if ((!$do_filtering) && module_exist('browscap')) { + $filter_crawlers = variable_get('statistics_filter_crawlers', FALSE); + if ($filter_crawlers) { + $browser = browscap_get_browser(); + if ($browser->crawler) { + $do_filtering = TRUE; } } } - 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, timer, timestamp) values('%s', '%s', '%s', '%s', %d, %d, %d)", drupal_get_title(), $_GET['q'], referer_uri(), $_SERVER['REMOTE_ADDR'], $user->uid, timer_read('page'), time()); + + if (!$do_filtering) { + if (variable_get('statistics_count_content_views', 0)) { + // We are counting content views. + if ((arg(0) == 'node') && arg(1)) { + // 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, timer, timestamp) values('%s', '%s', '%s', '%s', %d, %d, %d)", drupal_get_title(), $_GET['q'], referer_uri(), $_SERVER['REMOTE_ADDR'], $user->uid, timer_read('page'), time()); + } } } @@ -347,6 +380,28 @@ $group .= form_radios(t('Display counter values'), 'statistics_display_counter', variable_get('statistics_display_counter', 0), array('1' => t('Enabled'), '0' => t('Disabled')), t('Display how many times given content has been viewed.')); $output .= form_group(t('Content viewing counter settings'), $group); + // Filter out uninteresting accesses + + // Restrict administration of this module + $group = form_checkbox(t('Ignore administrator'), 'statistics_filter_noadmin', + TRUE, variable_get('statistics_filter_noadmin', FALSE), + t("Ignore the special administrator account's accesses to this site.")); + + $roles = user_roles(); + $group .= form_checkboxes(t('Roles to ignore'), 'statistics_filter_roles', + variable_get('statistics_filter_roles', FALSE), $roles, + t("Ignore accesses by users in any of the checked roles.")); + + if (module_exist('browscap')) { + $group .= form_checkbox(t('Ignore crawlers'), 'statistics_filter_crawlers', + TRUE, variable_get('statistics_filter_crawlers', FALSE), + t("Ignore search engine crawlers' accesses to this site.")); + } else { + $group .= 'Enable the browscap module to permit filtering of crawlers.
'; + } + + $output .= form_group(t('Filtering'), $group); + return $output; }