| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
*
|
| 7 |
*/
|
| 8 |
|
| 9 |
/**
|
| 10 |
* Implementation of hook_enable().
|
| 11 |
*
|
| 12 |
* Our accurate_read_count_exit function needs to run after the statistics_exit
|
| 13 |
* so we need to set this modules weight to delay execution.
|
| 14 |
*/
|
| 15 |
function accurate_read_count_enable() {
|
| 16 |
$weight = (int) db_result(db_query("SELECT weight FROM {system} WHERE name = 'statistics'"));
|
| 17 |
$result = db_query("UPDATE {system} SET weight = %d WHERE name = 'accurate_read_count'", $weight + 1);
|
| 18 |
}
|
| 19 |
|
| 20 |
/**
|
| 21 |
* Implementation of hook_boot().
|
| 22 |
*
|
| 23 |
* Check to see if this page has been visited before.
|
| 24 |
*/
|
| 25 |
function accurate_read_count_boot() {
|
| 26 |
drupal_bootstrap(DRUPAL_BOOTSTRAP_PATH);
|
| 27 |
global $_accurate_read_count_visited;
|
| 28 |
$_accurate_read_count_visited = FALSE;
|
| 29 |
|
| 30 |
if ((arg(0) == 'node') && is_numeric(arg(1)) && arg(2) == '' && variable_get('statistics_count_content_views', 0)) {
|
| 31 |
|
| 32 |
global $user;
|
| 33 |
if ($user->uid) {
|
| 34 |
$_accurate_read_count_visited = (bool) db_result(db_query("SELECT COUNT(uid) FROM {history} WHERE uid = %d AND nid = %d", $user->uid, arg(1)));
|
| 35 |
}
|
| 36 |
|
| 37 |
if (!$_accurate_read_count_visited && variable_get('statistics_enable_access_log', 0)) {
|
| 38 |
$_accurate_read_count_visited = db_result(db_query("SELECT * FROM {accesslog} WHERE path = '%s' AND sid = '%s' AND timestamp < %d", $_GET['q'], session_id(), time()));
|
| 39 |
}
|
| 40 |
}
|
| 41 |
}
|
| 42 |
|
| 43 |
/**
|
| 44 |
* Implementation of hook_exit().
|
| 45 |
*
|
| 46 |
* If the page has been visited before, remove the view count increment
|
| 47 |
* statistics module puts in the node_counter table.
|
| 48 |
*/
|
| 49 |
function accurate_read_count_exit() {
|
| 50 |
global $_accurate_read_count_visited;
|
| 51 |
if ($_accurate_read_count_visited) {
|
| 52 |
db_query('UPDATE {node_counter} SET daycount = daycount - 1, totalcount = totalcount - 1 WHERE nid = %d', arg(1));
|
| 53 |
}
|
| 54 |
}
|