function comment_num_new

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.

4 calls to comment_num_new()
comment_node_view in drupal/core/modules/comment/comment.module
Implements hook_node_view().
comment_tokens in drupal/core/modules/comment/comment.tokens.inc
Implements hook_tokens().
forum_get_topics in drupal/core/modules/forum/forum.module
Gets all the topics in a forum.
tracker_page in drupal/core/modules/tracker/tracker.pages.inc
Page callback: Generates a page of tracked nodes for the site.
1 string reference to 'comment_num_new'
comment_update_8002 in drupal/core/modules/comment/comment.install
Make *id fields unsigned.

File

drupal/core/modules/comment/comment.module, line 1477
Enables users to comment on published content.

Code

function comment_num_new($nid, $timestamp = 0) {
  global $user;
  if ($user->uid && module_exists('history')) {

    // Retrieve the timestamp at which the current user last viewed this node.
    if (!$timestamp) {
      $timestamp = history_read($nid);
    }
    $timestamp = $timestamp > HISTORY_READ_LIMIT ? $timestamp : HISTORY_READ_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;
  }
}