1 comment.module | comment_num_new($nid, $timestamp = 0) |
Gets the number of new comments for the current user and the specified node.
Parameters
$nid: Node ID to count comments for.
$timestamp: Time to count from (defaults to time of last user access to node).
Return value
The number of new comments or FALSE if the user is not logged in.:
File
- core/
modules/ comment/ comment.module, line 1621 - Enables users to comment on published content.
Code
function comment_num_new($nid, $timestamp = 0) {
global $user;
if ($user->uid) {
// Retrieve the timestamp at which the current user last viewed this node.
if (!$timestamp) {
$timestamp = node_last_viewed($nid);
}
$timestamp = ($timestamp > NODE_NEW_LIMIT ? $timestamp : NODE_NEW_LIMIT);
// Use the timestamp to retrieve the number of new comments.
return db_query('SELECT COUNT(cid) FROM {comment} WHERE nid = :nid AND created > :timestamp AND status = :status', array(
':nid' => $nid,
':timestamp' => $timestamp,
':status' => COMMENT_PUBLISHED,
))->fetchField();
}
else {
return FALSE;
}
}