--- /home/Ber/V_cvs/drupal431/drupal/modules/statistics.module 2003-11-11 09:14:02.000000000 +0100 +++ statistics.module 2004-02-05 14:12:50.578125000 +0100 @@ -37,30 +37,29 @@ // Exit hook, runs at the end of every page request function statistics_exit() { global $user; - if (variable_get("statistics_enable_node_counter", 0)) { // node view counters are enabled - if ((arg(0) == "node") && (arg(1) == "view") && arg(2)) { + if ((arg(0) == "node") && (arg(1) == "view") && arg(2) && statistics_filter_flag($user->hostname)) { // a node has been viewed, so updated the node's counters - db_query("UPDATE {node_counter} SET daycount = daycount + 1, totalcount = totalcount + 1, timestamp = %d WHERE nid = %d", time(), arg(2)); + db_queryd("UPDATE {node_counter} SET daycount = daycount + 1, totalcount = totalcount + 1, timestamp = %d WHERE nid = %d", time(), arg(2)); // if we affected 0 rows, this is the first time viewing the node if (!db_affected_rows()) { // must create a new row to store counter's for new node - db_query("INSERT INTO {node_counter} (nid, daycount, totalcount, timestamp) VALUES(%d, 1, 1, %d)", arg(2), time()); + db_queryd("INSERT INTO {node_counter} (nid, daycount, totalcount, timestamp) VALUES(%d, 1, 1, %d)", arg(2), time()); } } } - if ((variable_get("statistics_enable_access_log", 0)) && (throttle_status() < 5)) { + if ((variable_get("statistics_enable_access_log", 0)) && (throttle_status() < 5) && statistics_filter_flag($user->hostname)) { // statistical logs are enabled $referrer = referer_uri(); $hostname = getenv("REMOTE_ADDR"); // log this page access if ((arg(0) == "node") && (arg(1) == "view") && arg(2)) { - db_query("INSERT INTO {accesslog} (nid, url, hostname, uid, timestamp) values(%d, '%s', '%s', %d, %d)", arg(2), $referrer, $hostname, $user->uid, time()); + db_queryd("INSERT INTO {accesslog} (nid, url, hostname, uid, timestamp) values(%d, '%s', '%s', %d, %d)", arg(2), $referrer, $hostname, $user->uid, time()); } else { - db_query("INSERT INTO {accesslog} (url, hostname, uid, timestamp) values('%s', '%s', %d, %d)", $referrer, $hostname, $user->uid, time()); + db_queryd("INSERT INTO {accesslog} (url, hostname, uid, timestamp) values('%s', '%s', %d, %d)", $referrer, $hostname, $user->uid, time()); } } } @@ -557,13 +556,19 @@ /* Adds configure option to the main configure site admin page */ function statistics_settings() { /* access log options */ + $output = form_select(t("Enable access log"), "statistics_enable_access_log", variable_get("statistics_enable_access_log", 0), array("1" => t("Enabled"), "0" => t("Disabled")), t("Log each page access. Required for referrer statistics.")); $period = array(3600 => format_interval(3600), 10800 => format_interval(10800), 21600 => format_interval(21600), 32400 => format_interval(32400), 43200 => format_interval(43200), 86400 => format_interval(86400), 172800 => format_interval(172800), 259200 => format_interval(259200), 604800 => format_interval(604800), 1209600 => format_interval(1209600), 2419200 => format_interval(2419200), 4838400 => format_interval(4838400), 9676800 => format_interval(9676800)); $output .= form_select(t("Discard access logs older than"), "statistics_flush_accesslog_timer", variable_get("statistics_flush_accesslog_timer", 259200), $period, t("Older access log entries (including referrer statistics) will be automatically discarded. Requires crontab.")); $output .= form_select(t("Enable node view counters"), "statistics_enable_node_counter", variable_get("statistics_enable_node_counter", 0), array("1" => t("Enabled"), "0" => t("Disabled")), t("Increment node view counter each time a node is viewed.")); $output .= form_select(t("Display node view counters"), "statistics_display_counter", variable_get("statistics_display_counter", ""), array("1" => t("Enabled"), "0" => t("Disabled")), t("Display how many times each node has been viewed. User must have the 'access statistics' permissions.")); - + $output .= form_checkbox(t("Use access log filter"),"statistics_enable_filter", 1, variable_get("statistics_enable_filter", 0), t("Enable filtering of certain hosts from the access logs")); + + if(variable_get("statistics_enable_filter", 0)) { + $output .= form_textarea(t("Filter hosts"), "statistics_filter_hosts", variable_get("statistics_filter_hosts", ""), 70, 10, t("These filters will not be displayed in the statistic pages. Use linefeeds (enter) to seperate each entry.")); + } + return $output; } @@ -607,6 +612,21 @@ variable_set("statistics_display_counter", $edit["statistics_display_counter"]); } +/* Prepares the list of to-be-filtered hosts */ +function statistics_get_filterlist() { + return explode("\n",variable_get("statistics_filter_hosts", "")); +} + +/* Prepares the list of to-be-filtered hosts */ +function statistics_filter_flag($hostname) { + if(variable_get("statistics_enable_filter", 0)) { + return !in_array($hostname,statistics_get_filterlist()); + } + else { + return TRUE; + } +} + /* cron hook, performs automatic functions */ function statistics_cron() {