From 657935c263486b801b4eb13e6e96a24fff4b3500 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Thu, 21 Feb 2008 19:38:07 +0000 Subject: - Patch #81931 by webchick et al: made the recent comments block configurable. Somme minor changes by me. --- modules/comment/comment.module | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) (limited to 'modules') diff --git a/modules/comment/comment.module b/modules/comment/comment.module index 2eb985559..a6166a89d 100644 --- a/modules/comment/comment.module +++ b/modules/comment/comment.module @@ -284,15 +284,32 @@ function comment_perm() { * * Generates a block with the most recent comments. */ -function comment_block($op = 'list', $delta = 0) { - if ($op == 'list') { - $blocks[0]['info'] = t('Recent comments'); - return $blocks; - } - else if ($op == 'view' && user_access('access comments')) { - $block['subject'] = t('Recent comments'); - $block['content'] = theme('comment_block'); - return $block; +function comment_block($op = 'list', $delta = 0, $edit = array()) { + switch ($op) { + case 'list': + $blocks[0]['info'] = t('Recent comments'); + return $blocks; + + case 'configure': + $form['comment_block_count'] = array( + '#type' => 'select', + '#title' => t('Number of recent comments'), + '#default_value' => variable_get('comment_block_count', 10), + '#options' => drupal_map_assoc(array(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 25, 30)), + '#description' => t('Number of comments to display in block with recent comments.'), + ); + return $form; + + case 'save': + variable_set('comment_block_count', (int)$edit['comment_block_count']); + break; + + case 'view': + if (user_access('access comments')) { + $block['subject'] = t('Recent comments'); + $block['content'] = theme('comment_block'); + return $block; + } } } @@ -396,7 +413,8 @@ function comment_new_page_count($num_comments, $new_replies, $node) { */ function theme_comment_block() { $items = array(); - foreach (comment_get_recent() as $comment) { + $number = variable_get('comment_block_count', 10); + foreach (comment_get_recent($number) as $comment) { $items[] = l($comment->subject, 'node/'. $comment->nid, array('fragment' => 'comment-'. $comment->cid)) .'
'. t('@time ago', array('@time' => format_interval(time() - $comment->timestamp))); } if ($items) { -- cgit v1.2.3