You are here

function advanced_forum_reply_num_new in Advanced Forum 6.2

Same name and namespace in other branches
  1. 7.2 advanced_forum.module \advanced_forum_reply_num_new()

Get the number of new posts on a topic. This is simply a wrapper to either call the comment module version or the nodecomment module version.

4 calls to advanced_forum_reply_num_new()
advanced_forum_first_new_post_link in ./advanced_forum.module
Returns a link directly to the first new post in a topic.
advanced_forum_handler_field_node_topic_icon::render in includes/views/advanced_forum_handler_field_node_topic_icon.inc
advanced_forum_preprocess_advanced_forum_topic_header in includes/theme.inc
Preprocesses template variables for the topic header template.
advanced_forum_preprocess_forum_submitted in includes/theme.inc
Preprocesses template variables for the submitted by/in template.

File

./advanced_forum.module, line 938
Enables the look and feel of other popular forum software.

Code

function advanced_forum_reply_num_new($nid, $timestamp = 0) {

  // Make a static cache because this function is called twice from the topic
  // header. Once to display the number and once to make the link to first new.
  static $number_new_for_node = array();
  if (empty($number_new_for_node[$nid])) {
    global $user;
    $node = node_load($nid);

    // We must also check the forum post itself to see if we have viewed it
    $viewed = 0;

    // If not told otherwise, it has been viewed before
    if ($user->uid) {
      $viewed = node_last_viewed($nid);

      // Set it to 1 if it has not been viewed before, but only if it has been
      // modified after NODE_NEW_LIMIT; that is, it wouldn't have been purged
      // from {history}.
      if ($viewed == 0) {
        if (node_last_changed($nid) > NODE_NEW_LIMIT) {
          $viewed = 1;
        }
      }
      else {

        // seems counterintuitive, but set to zero as node_last_viewed gave us a timestamp
        //  indicating that the node has been viewed before
        $viewed = 0;
      }
    }
    $comment_type = module_invoke('nodecomment', 'get_comment_type', $node->type);
    if (isset($comment_type)) {
      $number_new_for_node[$nid] = nodecomment_num_new($nid, $timestamp) + $viewed;
    }
    else {
      $number_new_for_node[$nid] = comment_num_new($nid, $timestamp) + $viewed;
    }
  }
  return $number_new_for_node[$nid];
}