comment_new_page_count
- Versions
- 6 – 7
comment_new_page_count($num_comments, $new_replies, $node)
Calculate page number for first new comment.
Parameters
$num_comments Number of comments.
$new_replies Number of new replies.
$node The first new comment node.
Return value
"page=X" if the page number is greater than zero; empty string otherwise.
Code
modules/comment/comment.module, line 414
<?php
function comment_new_page_count($num_comments, $new_replies, $node) {
$mode = variable_get('comment_default_mode_' . $node->type, COMMENT_MODE_THREADED);
$comments_per_page = variable_get('comment_default_per_page_' . $node->type, 50);
$pagenum = NULL;
$flat = $mode == COMMENT_MODE_FLAT ? TRUE : FALSE;
if ($num_comments <= $comments_per_page) {
// Only one page of comments.
$pageno = 0;
}
elseif ($flat) {
// Flat comments.
$count = $num_comments - $new_replies;
$pageno = $count / $comments_per_page;
}
else {
// Threaded comments.
// Find the first thread with a new comment.
$result = db_query_range('SELECT thread FROM (SELECT thread
FROM {comment}
WHERE nid = :nid
AND status = 0
ORDER BY changed DESC) AS thread
ORDER BY SUBSTRING(thread, 1, (LENGTH(thread) - 1))', 0, $new_replies, array(':nid' => $node->nid))->fetchField();
$thread = substr($result, 0, -1);
$count = db_query('SELECT COUNT(*) FROM {comment} WHERE nid = :nid AND status = 0 AND SUBSTRING(thread, 1, (LENGTH(thread) - 1)) < :thread', array(
':nid' => $node->nid,
':thread' => $thread,
))->fetchField();
$pageno = $count / $comments_per_page;
}
if ($pageno >= 1) {
$pagenum = array('page' => intval($pageno));
}
return $pagenum;
}
?>Login or register to post comments 