Definition

comment_num_new($nid, $timestamp = 0)
drupal/modules/comment/comment.module, line 1226

Description

Get number of new comments for current user and 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 result or FALSE on error.

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(c.cid) FROM {node} n INNER JOIN {comment} c ON n.nid = c.nid WHERE n.nid = :nid AND timestamp > :timestamp AND c.status = :status', array(
      ':nid' => $nid,
      ':timestamp' => $timestamp,
      ':status' => COMMENT_PUBLISHED ))
      ->fetchField();
  }
  else {
    return FALSE;
  }

}