function comment_num_new

7.x comment.module comment_num_new($nid, $timestamp = 0)
6.x comment.module comment_num_new($nid, $timestamp = 0)

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)

3 calls to comment_num_new()
comment_link in drupal-6.x/modules/comment/comment.module
Implementation of hook_link().
forum_get_topics in drupal-6.x/modules/forum/forum.module
tracker_page in drupal-6.x/modules/tracker/tracker.pages.inc
Menu callback. Prints a listing of active nodes on the site.

File

drupal-6.x/modules/comment/comment.module, line 1153
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 the
    // specified 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.
    $result = db_result(db_query('SELECT COUNT(c.cid) FROM {node} n INNER JOIN {comments} c ON n.nid = c.nid WHERE n.nid = %d AND timestamp > %d AND c.status = %d', $nid, $timestamp, COMMENT_PUBLISHED));

    return $result;
  }
  else {
    return 0;
  }

}