Index: modules/comment.module =================================================================== RCS file: /cvs/drupal/drupal/modules/comment.module,v retrieving revision 1.455 diff -p -u -r1.455 comment.module --- modules/comment.module 27 Apr 2006 22:03:20 -0000 1.455 +++ modules/comment.module 1 May 2006 17:41:16 -0000 @@ -174,7 +174,7 @@ function theme_comment_block() { $result = db_query_range(db_rewrite_sql('SELECT c.nid, c.subject, c.cid, c.timestamp FROM {comments} c INNER JOIN {node} n ON n.nid = c.nid WHERE n.status = 1 AND c.status = %d ORDER BY c.timestamp DESC', 'c'), COMMENT_PUBLISHED, 0, 10); $items = array(); while ($comment = db_fetch_object($result)) { - $items[] = l($comment->subject, 'node/'. $comment->nid, NULL, NULL, 'comment-'. $comment->cid) .'
'. t('%time ago', array('%time' => format_interval(time() - $comment->timestamp))); + $items[] = l($comment->subject, 'node/'. $comment->nid, NULL, _comment_page_query($comment->nid, $comment->cid), 'comment-'. $comment->cid) .'
'. t('%time ago', array('%time' => format_interval(time() - $comment->timestamp))); } return theme('item_list', $items); } @@ -198,7 +198,8 @@ function comment_link($type, $node = 0, $links[] = l(format_plural($all, '1 comment', '%count comments'), "node/$node->nid", array('title' => t('Jump to the first comment of this posting.')), NULL, 'comment'); if ($new) { - $links[] = l(format_plural($new, '1 new comment', '%count new comments'), "node/$node->nid", array('title' => t('Jump to the first new comment of this posting.')), NULL, 'new'); + $query = _comment_page_query($node->nid, _comment_first_new($node->nid)); + $links[] = l(format_plural($new, '1 new comment', '%count new comments'), "node/$node->nid", array('title' => t('Jump to the first new comment of this posting.')), $query, 'new'); } } else { @@ -1439,7 +1440,7 @@ function _comment_form_submit($form_valu function comment_form_submit($form_id, $form_values) { $form_values = _comment_form_submit($form_values); if ($cid = comment_save($form_values)) { - return array('node/'. $form_values['nid'], NULL, "comment-$cid"); + return array('node/'. $form_values['nid'], _comment_page_query($form_values['nid'], $cid), "comment-$cid"); } } @@ -1701,6 +1702,93 @@ function _comment_get_display_setting($s } /** + * Return the page a comment is on + */ +function _comment_page($nid, $cid) { + // get the current display settings + $mode = _comment_get_display_setting('mode'); + $order = _comment_get_display_setting('sort'); + $comments_per_page = _comment_get_display_setting('comments_per_page'); + + // Build the database queries + // This follows the same sheme as in comment_render(). + // See comments there for an explanation. + $query_count = 'SELECT COUNT(*) FROM {comments} WHERE nid = %d'; + $query = 'SELECT cid FROM {comments} WHERE nid = %d'; + + $query_args = array($nid); + if (!user_access('administer comments')) { + $query .= ' AND status = %d'; + $query_count .= ' AND status = %d'; + $query_args[] = COMMENT_PUBLISHED; + } + + if ($order == COMMENT_ORDER_NEWEST_FIRST) { + if ($mode == COMMENT_MODE_FLAT_COLLAPSED || $mode == COMMENT_MODE_FLAT_EXPANDED) { + $query .= ' ORDER BY timestamp DESC'; + } + else { + $query .= ' ORDER BY thread DESC'; + } + } + else if ($order == COMMENT_ORDER_OLDEST_FIRST) { + if ($mode == COMMENT_MODE_FLAT_COLLAPSED || $mode == COMMENT_MODE_FLAT_EXPANDED) { + $query .= ' ORDER BY timestamp'; + } + else { + $query .= ' ORDER BY SUBSTRING(thread, 1, (LENGTH(thread) - 1))'; + } + } + + $comments_num = db_result(db_query($query_count, $query_args)); + if ($comments_num <= $comments_per_page) { + // one page of comments only + return 0; + } + else { + $count = 0; + $result = db_query($query, $query_args); + while ($comment = db_fetch_array($result)) { + if ($comment['cid'] == $cid) { + return floor($count / $comments_per_page); + } + $count++; + } + } +} + +/** + * Return a query string used in links to comments to point to the page the + * comment is on + */ +function _comment_page_query($nid, $cid) { + $page = _comment_page($nid, $cid); + return $page ? "page=$page" : NULL; +} + +/** + * Return the specified node's first new comment for the current user + */ +function _comment_first_new($nid) { + global $user; + + if ($user->uid) { + // Retrieve the timestamp at which the current user last viewed the + // specified node. + $timestamp = node_last_viewed($nid); + $timestamp = ($timestamp > NODE_NEW_LIMIT ? $timestamp : NODE_NEW_LIMIT); + + // Use the timestamp to retrieve the first new comment + $result = db_result(db_query('SELECT MIN(cid) FROM {comments} WHERE nid = %d AND timestamp > %d AND status = %d', $nid, $timestamp, COMMENT_PUBLISHED)); + return $result; + } + else { + return NULL; + } + +} + +/** * Updates the comment statistics for a given node. This should be called any * time a comment is added, deleted, or updated. * Index: modules/forum.module =================================================================== RCS file: /cvs/drupal/drupal/modules/forum.module,v retrieving revision 1.328 diff -p -u -r1.328 forum.module --- modules/forum.module 13 Apr 2006 08:25:27 -0000 1.328 +++ modules/forum.module 1 May 2006 13:59:12 -0000 @@ -993,7 +993,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_page_query($topic->nid, _comment_first_new($topic->nid)), 'new') : ''), 'class' => 'replies'), array('data' => _forum_format($topic), 'class' => 'created'), array('data' => _forum_format($topic->last_reply), 'class' => 'last-reply') ); Index: modules/tracker.module =================================================================== RCS file: /cvs/drupal/drupal/modules/tracker.module,v retrieving revision 1.129 diff -p -u -r1.129 tracker.module --- modules/tracker.module 17 Apr 2006 20:48:26 -0000 1.129 +++ modules/tracker.module 1 May 2006 14:41:35 -0000 @@ -105,7 +105,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_page_query($node->nid, _comment_first_new($node->nid)), 'new'); } }