Extended History aims to help module developers (or PHP-savvy web developers) by keeping an extended history of visits to nodes for each user.
While Drupal already provides some basic funcionality in the history table, there are a couple of drawbacks:
- History records are purged after 30 days;
- That 30-day limit is non-manageable, unless you disable cron runs altogether;
- It doesn't count how many times each user saw that node.
Original code from node.module:
define('NODE_NEW_LIMIT', time() - 30 * 24 * 60 * 60);
function node_cron() {
db_query('DELETE FROM {history} WHERE timestamp < %d', NODE_NEW_LIMIT);
}
Extended History adds a new table called extendedhistory to store (uid, nid, timestamp, count) tuples.
For anonymous users, it keeps these details in session until they log in or register, at which time this is saved into the DB under their new UIDs.
If you want records to be deleted after some time, this can be set in Site Building » Extended History.
As 'API', it provides the following function:
/**
* Returns an array of the form:
* array(
* 'timestamp' => [int],
* 'count' => [int],
* );
* If no record was found, it returns an empty array.
*/
function extendedhistory_last_viewed($nid)