You are here

function comment_new_page_count in Advanced Forum 5

3 calls to comment_new_page_count()
advanced_forum_first_new_post_link in ./advanced_forum.module
Returns a link directly to the first new post in a topic.
advanced_forum_preprocess_forum_submitted in ./advanced_forum.module
Preprocesses template variables for the submitted by/in template.
template_preprocess_forum_topic_list in ./d6_compat.inc
Preprocess variables to format the topic listing.

File

./d6_compat.inc, line 303
Code needed to backport functionality from D6.

Code

function comment_new_page_count($num_comments, $new_replies, $node) {
  $comments_per_page = _comment_get_display_setting('comments_per_page', $node);
  $mode = _comment_get_display_setting('mode', $node);
  $order = _comment_get_display_setting('sort', $node);
  $pagenum = NULL;
  $flat = in_array($mode, array(
    COMMENT_MODE_FLAT_COLLAPSED,
    COMMENT_MODE_FLAT_EXPANDED,
  ));
  if ($num_comments <= $comments_per_page || $flat && $order == COMMENT_ORDER_NEWEST_FIRST) {

    // Only one page of comments or flat forum and newest first.
    // First new comment will always be on first page.
    $pageno = 0;
  }
  else {
    if ($flat) {

      // Flat comments and oldest first.
      $count = $num_comments - $new_replies;
    }
    else {

      // Threaded comments. See the documentation for comment_render().
      if ($order == COMMENT_ORDER_NEWEST_FIRST) {

        // Newest first: find the last thread with new comment
        $result = db_query('(SELECT thread FROM {comments} WHERE nid = %d  AND status = 0 ORDER BY timestamp DESC LIMIT %d) ORDER BY thread DESC LIMIT 1', $node->nid, $new_replies);
        $thread = db_result($result);
        $result_count = db_query("SELECT COUNT(*) FROM {comments} WHERE nid = %d AND status = 0 AND thread > '" . $thread . "'", $node->nid);
      }
      else {

        // Oldest first: find the first thread with new comment
        $result = db_query('(SELECT thread FROM {comments} WHERE nid = %d  AND status = 0 ORDER BY timestamp DESC LIMIT %d) ORDER BY SUBSTRING(thread, 1, (LENGTH(thread) - 1)) LIMIT 1', $node->nid, $new_replies);
        $thread = substr(db_result($result), 0, -1);
        $result_count = db_query("SELECT COUNT(*) FROM {comments} WHERE nid = %d AND status = 0 AND SUBSTRING(thread, 1, (LENGTH(thread) - 1)) < '" . $thread . "'", $node->nid);
      }
      $count = db_result($result_count);
    }
    $pageno = $count / $comments_per_page;
  }
  if ($pageno >= 1) {
    $pagenum = "page=" . intval($pageno);
  }
  return $pagenum;
}