No need to create your own module for this.
The query executed by the statistics module:
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()); }
The only thing we need to do is replace arg(1) with the node identifier that we want to add so that the count can be executed in the user module like this.
function custom_module_menu() { $items['custom/ajax/%node'] = array( 'title' => 'Update count', 'page callback' => 'custom_module_update_counter', 'page arguments' => array(2), 'access callback' => array('custom_module_access_control'), ); function custom_module_update_counter($node) { db_query('UPDATE {node_counter} SET daycount = daycount + 1, totalcount = totalcount + 1, timestamp = %d WHERE nid = %d', time(), $node->nid);
All that remains is to implement a custom access control function, you can check if the request is ajax or make any control you like, the function should simply return TRUE or FALSE. You also need to make an ajax event with the node id in your setup, but that should not be too heavy either.
You need to click custom/ajax/2 URL to update node with id 2, etc.
googletorp
source share