1 node.module | node_last_viewed($nid) |
Retrieves the timestamp for the current user's last view of a specified node.
Parameters
$nid: A node ID.
Return value
If a node has been previously viewed by the user, the timestamp in seconds: of when the last view occurred; otherwise, zero.
File
- core/
modules/ node/ node.module, line 331 - The core module that allows content to be submitted to the site.
Code
function node_last_viewed($nid) {
global $user;
$history = &backdrop_static(__FUNCTION__, array());
if (!isset($history[$nid])) {
$history[$nid] = db_query("SELECT timestamp FROM {history} WHERE uid = :uid AND nid = :nid", array(':uid' => $user->uid, ':nid' => $nid))->fetchObject();
}
return (isset($history[$nid]->timestamp) ? $history[$nid]->timestamp : 0);
}