#6162 by various people: actually point new anchors to the page the first new comment is displayed (in a multipage comment view)
parent
1b658ae850
commit
e310d9e4a4
|
@ -316,6 +316,49 @@ function comment_get_recent($number = 10) {
|
||||||
return $comments;
|
return $comments;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
$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', $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;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a formatted list of recent comments to be displayed in the comment
|
* Returns a formatted list of recent comments to be displayed in the comment
|
||||||
* block.
|
* block.
|
||||||
|
@ -360,6 +403,7 @@ function comment_link($type, $node = NULL, $teaser = FALSE) {
|
||||||
$links['comment_new_comments'] = array(
|
$links['comment_new_comments'] = array(
|
||||||
'title' => format_plural($new, '1 new comment', '@count new comments'),
|
'title' => format_plural($new, '1 new comment', '@count new comments'),
|
||||||
'href' => "node/$node->nid",
|
'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.')),
|
'attributes' => array('title' => t('Jump to the first new comment of this posting.')),
|
||||||
'fragment' => 'new'
|
'fragment' => 'new'
|
||||||
);
|
);
|
||||||
|
|
|
@ -786,7 +786,7 @@ function template_preprocess_forum_topic_list(&$variables) {
|
||||||
$variables['topics'][$id]->new_url = '';
|
$variables['topics'][$id]->new_url = '';
|
||||||
if ($topic->new_replies) {
|
if ($topic->new_replies) {
|
||||||
$variables['topics'][$id]->new_text = t('!count new', array('!count' => $variables['forums'][$id]->new_topics));
|
$variables['topics'][$id]->new_text = t('!count new', array('!count' => $variables['forums'][$id]->new_topics));
|
||||||
$variables['topics'][$id]->new_url = url("node/$topic->nid", array('fragment' => 'new'));
|
$variables['topics'][$id]->new_url = url("node/$topic->nid", array('query' => comment_new_page_count($topic->num_comments, $topic->new_replies, $topic->nid), 'fragment' => 'new'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$variables['topics'][$id]->moved = FALSE;
|
$variables['topics'][$id]->moved = FALSE;
|
||||||
|
|
|
@ -57,7 +57,7 @@ function tracker_page($uid = 0) {
|
||||||
|
|
||||||
if ($new = comment_num_new($node->nid)) {
|
if ($new = comment_num_new($node->nid)) {
|
||||||
$comments .= '<br />';
|
$comments .= '<br />';
|
||||||
$comments .= l(format_plural($new, '1 new', '@count new'), "node/$node->nid", array('fragment' => 'new'));
|
$comments .= l(format_plural($new, '1 new', '@count new'), "node/$node->nid", array('query' => comment_new_page_count($node->comment_count, $new, $node->nid), 'fragment' => 'new'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue