Index: modules/comments/comment.module
===================================================================
--- modules/comments/comment.module 2007-01-29 22:51:52.000000000 +0100
+++ modules/comments/comment.module 2007-04-09 14:13:35.000000000 +0200
@@ -313,6 +313,7 @@ function comment_link($type, $node = NUL
$links['comment_new_comments'] = array(
'title' => format_plural($new, '1 new comment', '@count new comments'),
'href' => "node/$node->nid",
+ 'query' => comment_new_page_count($all, $new, $node->nid),
'attributes' => array('title' => t('Jump to the first new comment of this posting.')),
'fragment' => 'new'
);
@@ -2008,3 +2009,46 @@ function vancode2int($c = '00') {
return base_convert(substr($c, 1), 36, 10);
}
+/**
+ * New function to calculate page number for first new comment.
+ */
+
+function comment_new_page_count($num_comments, $new_replies, $nid) {
+ $comments_per_page = _comment_get_display_setting('comments_per_page');
+ $mode = _comment_get_display_setting('mode');
+ $order = _comment_get_display_setting('sort');
+ $pagenum = NULL;
+ if ($num_comments <= $comments_per_page || ($mode<3 && $order == 1)) {
+ //Only one page of comments or flat forum and newest first.
+ //First new comment will always be on first page
+ $pageno = 0;
+ }
+ else {
+ if ($mode < 3){
+ //Flat comments and oldest first
+ $count = $num_comments - $new_replies;
+ }
+ else {
+ //Threaded comments. See the documentation for comment_render().
+ if ($order == 1) {
+ //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', $nid, $new_replies);
+ $thread = db_result($result);
+ $result_count = db_query("SELECT COUNT(*) FROM {comments} WHERE nid = %d AND status = 0 AND thread > '" . $thread . "'", $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', $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 . "'", $nid);
+ }
+ $count = db_result($result_count);
+ }
+ $pageno = $count / $comments_per_page;
+ }
+ if ($pageno >= 1) {
+ $pagenum = "page=" . intval($pageno);
+ }
+ return $pagenum;
+}
+
Index: modules/forum/forum.module
===================================================================
--- modules/forum/forum.module 2007-01-25 22:49:20.000000000 +0100
+++ modules/forum/forum.module 2007-04-09 14:17:49.000000000 +0200
@@ -1007,7 +1007,7 @@ function theme_forum_topic_list($tid, $t
$rows[] = array(
array('data' => theme('forum_icon', $topic->new, $topic->num_comments, $topic->comment_mode, $topic->sticky), 'class' => 'icon'),
array('data' => l($topic->title, "node/$topic->nid"), 'class' => 'topic'),
- array('data' => $topic->num_comments . ($topic->new_replies ? '
'. l(format_plural($topic->new_replies, '1 new', '@count new'), "node/$topic->nid", NULL, NULL, 'new') : ''), 'class' => 'replies'),
+ array('data' => $topic->num_comments . ($topic->new_replies ? '
'. l(format_plural($topic->new_replies, '1 new', '@count new'), "node/$topic->nid", NULL, comment_new_page_count($topic->num_comments, $topic->new_replies, $topic->nid), 'new') : ''), 'class' => 'replies'),
array('data' => _forum_format($topic), 'class' => 'created'),
array('data' => _forum_format(isset($topic->last_reply) ? $topic->last_reply : NULL), 'class' => 'last-reply')
);
Index: modules/tracker/tracker.module
===================================================================
--- modules/tracker/tracker.module 2007-01-10 16:17:50.000000000 +0100
+++ modules/tracker/tracker.module 2007-04-09 14:20:40.000000000 +0200
@@ -101,7 +101,7 @@ function tracker_page($uid = 0) {
if ($new = comment_num_new($node->nid)) {
$comments .= '
';
- $comments .= l(format_plural($new, '1 new', '@count new'), "node/$node->nid", NULL, NULL, 'new');
+ $comments .= l(format_plural($new, '1 new', '@count new'), "node/$node->nid", NULL, comment_new_page_count($node->comment_count, $new, $node->nid), 'new');
}
}