- Patch #599640 by sun: move hard-coded comment query options to caller.

merge-requests/26/head
Dries Buytaert 2009-10-09 02:26:15 +00:00
parent 0e3cb8a5e1
commit 02d4ddb7bd
1 changed files with 13 additions and 31 deletions

View File

@ -414,8 +414,8 @@ function comment_get_recent($number = 10) {
* "page=X" if the page number is greater than zero; empty string otherwise. * "page=X" if the page number is greater than zero; empty string otherwise.
*/ */
function comment_new_page_count($num_comments, $new_replies, $node) { function comment_new_page_count($num_comments, $new_replies, $node) {
$comments_per_page = _comment_get_display_setting('comments_per_page', $node); $mode = variable_get('comment_default_mode_' . $node->type, COMMENT_MODE_THREADED);
$mode = _comment_get_display_setting('mode', $node); $comments_per_page = variable_get('comment_default_per_page_' . $node->type, 50);
$pagenum = NULL; $pagenum = NULL;
$flat = $mode == COMMENT_MODE_FLAT ? TRUE : FALSE; $flat = $mode == COMMENT_MODE_FLAT ? TRUE : FALSE;
if ($num_comments <= $comments_per_page) { if ($num_comments <= $comments_per_page) {
@ -586,7 +586,9 @@ function comment_node_page_additions($node) {
// Unpublished comments are not included in $node->comment_count, so show // Unpublished comments are not included in $node->comment_count, so show
// comments unconditionally if the user is an administrator. // comments unconditionally if the user is an administrator.
if ($node->comment_count || user_access('administer comments')) { if ($node->comment_count || user_access('administer comments')) {
if ($cids = comment_get_thread($node)) { $mode = variable_get('comment_default_mode_' . $node->type, COMMENT_MODE_THREADED);
$comments_per_page = variable_get('comment_default_per_page_' . $node->type, 50);
if ($cids = comment_get_thread($node, $mode, $comments_per_page)) {
$comments = comment_load_multiple($cids); $comments = comment_load_multiple($cids);
comment_prepare_thread($comments); comment_prepare_thread($comments);
$build = comment_build_multiple($comments, $node); $build = comment_build_multiple($comments, $node);
@ -615,10 +617,14 @@ function comment_node_page_additions($node) {
} }
/** /**
* Retrieve comment(s) for a thread. * Retrieve comments for a thread.
* *
* @param $node * @param $node
* The node whose comment(s) needs rendering. * The node whose comment(s) needs rendering.
* @param $mode
* The comment display mode; COMMENT_MODE_FLAT or COMMENT_MODE_THREADED.
* @param $comments_per_page
* The amount of comments to display per page.
* *
* To display threaded comments in the correct order we keep a 'thread' field * To display threaded comments in the correct order we keep a 'thread' field
* and order by that value. This field keeps this data in * and order by that value. This field keeps this data in
@ -674,10 +680,7 @@ function comment_node_page_additions($node) {
* spoil the reverse ordering, "ORDER BY thread ASC" -- here, we do not need * spoil the reverse ordering, "ORDER BY thread ASC" -- here, we do not need
* to consider the trailing "/" so we use a substring only. * to consider the trailing "/" so we use a substring only.
*/ */
function comment_get_thread($node) { function comment_get_thread($node, $mode, $comments_per_page) {
$mode = _comment_get_display_setting('mode', $node);
$comments_per_page = _comment_get_display_setting('comments_per_page', $node);
$query = db_select('comment', 'c')->extend('PagerDefault'); $query = db_select('comment', 'c')->extend('PagerDefault');
$query->addField('c', 'cid'); $query->addField('c', 'cid');
$query $query
@ -783,7 +786,7 @@ function comment_build($comment, $node, $build_mode = 'full') {
); );
$prefix = ''; $prefix = '';
$is_threaded = isset($comment->divs) && _comment_get_display_setting('mode', $node) == COMMENT_MODE_THREADED; $is_threaded = isset($comment->divs) && variable_get('comment_default_mode_' . $node->type, COMMENT_MODE_THREADED) == COMMENT_MODE_THREADED;
// Add 'new' anchor if needed. // Add 'new' anchor if needed.
if (!empty($comment->first_new)) { if (!empty($comment->first_new)) {
@ -2183,7 +2186,7 @@ function theme_comment_post_forbidden($variables) {
function template_preprocess_comment_wrapper(&$variables) { function template_preprocess_comment_wrapper(&$variables) {
// Provide contextual information. // Provide contextual information.
$variables['node'] = $variables['content']['#node']; $variables['node'] = $variables['content']['#node'];
$variables['display_mode'] = _comment_get_display_setting('mode', $variables['node']); $variables['display_mode'] = variable_get('comment_default_mode_' . $variables['node']->type, COMMENT_MODE_THREADED);
$variables['template_files'][] = 'comment-wrapper-' . $variables['node']->type; $variables['template_files'][] = 'comment-wrapper-' . $variables['node']->type;
} }
@ -2208,27 +2211,6 @@ function _comment_per_page() {
return drupal_map_assoc(array(10, 30, 50, 70, 90, 150, 200, 250, 300)); return drupal_map_assoc(array(10, 30, 50, 70, 90, 150, 200, 250, 300));
} }
/**
* Return a current comment display setting
*
* @param $setting
* can be one of these: 'mode', 'sort', 'comments_per_page'
* @param $node
* The comment node in question.
*/
function _comment_get_display_setting($setting, $node) {
switch ($setting) {
case 'mode':
$value = variable_get('comment_default_mode_' . $node->type, COMMENT_MODE_THREADED);
break;
case 'comments_per_page':
$value = variable_get('comment_default_per_page_' . $node->type, 50);
}
return $value;
}
/** /**
* Updates the comment statistics for a given node. This should be called any * Updates the comment statistics for a given node. This should be called any
* time a comment is added, deleted, or updated. * time a comment is added, deleted, or updated.