diff options
author | Dries Buytaert <dries@buytaert.net> | 2003-01-26 13:22:02 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2003-01-26 13:22:02 +0000 |
commit | 4028362fda6f9423d95e53267fbd7ba99e96c106 (patch) | |
tree | 678e613f4731b112d314cbc6d61cb03f0d094634 /modules/statistics/statistics.module | |
parent | ad9b03033a2bfcbb4cb0b7d64698d6b12a57e13f (diff) | |
download | brdo-4028362fda6f9423d95e53267fbd7ba99e96c106.tar.gz brdo-4028362fda6f9423d95e53267fbd7ba99e96c106.tar.bz2 |
- Applied Moshe's _exit patch (slightly modified).
- Fixed bug in system.module.
Diffstat (limited to 'modules/statistics/statistics.module')
-rw-r--r-- | modules/statistics/statistics.module | 59 |
1 files changed, 31 insertions, 28 deletions
diff --git a/modules/statistics/statistics.module b/modules/statistics/statistics.module index 3121a7dbf..4fd0c6267 100644 --- a/modules/statistics/statistics.module +++ b/modules/statistics/statistics.module @@ -1,35 +1,8 @@ <?php // $Id$ -// Initialization hook, runs each time statistic module is loaded function statistics_init() { - global $user, $recent_activity; - - if (variable_get("statistics_enable_node_counter", 0)) { - // node view counters are enabled - if ((arg(0) == "node") && (arg(1) == "view") && arg(2)) { - // a node has been viewed, so updated the node's counters - db_query("UPDATE statistics SET daycount = daycount + 1, totalcount = totalcount + 1, timestamp = '%s' WHERE nid = '%s'", 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 statistics (nid, daycount, totalcount) VALUES('%s', daycount + 1, totalcount + 1)", arg(2)); - } - } - } - - if ((variable_get("statistics_enable_access_log", 0)) && (throttle_status() < 5)) { - // statistical logs are enabled - $referrer = getenv("HTTP_REFERER"); - $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('%s', '%s', '%s', '%s', '%s')", arg(2), $referrer, $hostname, $user->uid, time()); - } - else { - db_query("INSERT INTO accesslog (url, hostname, uid, timestamp) values('%s', '%s', '%s', '%s')", $referrer, $hostname, $user->uid, time()); - } - } + global $recent_activity; /* ** The following logic determines what the current throttle level should @@ -61,6 +34,36 @@ function statistics_init() { } } +// Footer 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)) { + // a node has been viewed, so updated the node's counters + db_query("UPDATE statistics SET daycount = daycount + 1, totalcount = totalcount + 1, timestamp = '%s' WHERE nid = '%s'", 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 statistics (nid, daycount, totalcount) VALUES('%s', daycount + 1, totalcount + 1)", arg(2)); + } + } + } + + if ((variable_get("statistics_enable_access_log", 0)) && (throttle_status() < 5)) { + // statistical logs are enabled + $referrer = getenv("HTTP_REFERER"); + $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('%s', '%s', '%s', '%s', '%s')", arg(2), $referrer, $hostname, $user->uid, time()); + } + else { + db_query("INSERT INTO accesslog (url, hostname, uid, timestamp) values('%s', '%s', '%s', '%s')", $referrer, $hostname, $user->uid, time()); + } + } +} /* System hook, sets description of module in admin page */ function statistics_system($field) { |