--- /home/guus/drupal-5.1/modules/comment/comment.module Mon Jan 29 22:51:53 2007 +++ /var/www/htdocs/testguusbosmannl/modules/comment/comment.module Fri Mar 2 20:59:19 2007 @@ -51,6 +51,16 @@ define('COMMENT_ORDER_NEWEST_FIRST', 1); define('COMMENT_ORDER_OLDEST_FIRST', 2); /** + * Recent comments block doesn't display user name. + */ +define('COMMENT_BLOCK_NO_USERNAME', 1); + +/** + * Recent comment block includes user names. + */ +define('COMMENT_BLOCK_WITH_USERNAME', 2); + +/** * Comment controls should be shown above the comment list. */ define('COMMENT_CONTROLS_ABOVE', 0); @@ -242,7 +252,7 @@ function comment_block($op = 'list', $de * * @param $number (optional) The maximum number of comments to find. * @return $comments An array of comment objects each containing a nid, - * subject, cid, and timstamp, or an empty array if there are no recent + * subject, cid, comment author and timestamp, or an empty array if there are no recent * comments visible to the current user. */ function comment_get_recent($number = 10) { @@ -260,7 +270,12 @@ function comment_get_recent($number = 10 if (!empty($nids)) { // From among the comments on the nodes selected in the first query, // find the $number most recent comments. - $result = db_query_range('SELECT c.nid, c.subject, c.cid, c.timestamp FROM {comments} c INNER JOIN {node} n ON n.nid = c.nid WHERE c.nid IN ('. implode(',', $nids) .') AND n.status = 1 AND c.status = %d ORDER BY c.timestamp DESC', COMMENT_PUBLISHED, 0, $number); + if (variable_get('comment_block_display', COMMENT_BLOCK_NO_USERNAME) == COMMENT_BLOCK_NO_USERNAME) { + // faster query when not looking for comments authors + $result = db_query_range('SELECT c.nid, c.subject, c.cid, c.timestamp FROM {comments} c INNER JOIN {node} n ON n.nid = c.nid WHERE c.nid IN ('. implode(',', $nids) .') AND n.status = 1 AND c.status = %d ORDER BY c.timestamp DESC', COMMENT_PUBLISHED, 0, $number); + } else { + $result = db_query_range('SELECT c.nid, c.subject, c.cid, u.name, c.timestamp FROM {comments} c LEFT JOIN users u ON c.uid = u.uid INNER JOIN {node} n ON n.nid = c.nid WHERE c.nid IN ('. implode(',', $nids) .') AND n.status = 1 AND c.status = %d AND (c.uid = u.uid) ORDER BY c.timestamp DESC', COMMENT_PUBLISHED, 0, $number); + } while ($comment = db_fetch_object($result)) { $comments[] = $comment; } @@ -277,8 +292,16 @@ function comment_get_recent($number = 10 */ function theme_comment_block() { $items = array(); - foreach (comment_get_recent() as $comment) { - $items[] = l($comment->subject, 'node/'. $comment->nid, NULL, NULL, 'comment-'. $comment->cid) .'
'. t('@time ago', array('@time' => format_interval(time() - $comment->timestamp))); + if (variable_get('comment_block_display', COMMENT_BLOCK_NO_USERNAME) == COMMENT_BLOCK_NO_USERNAME) { + foreach (comment_get_recent() as $comment) { + $items[] = l($comment->subject, 'node/'. $comment->nid, NULL, NULL, 'comment-'. $comment->cid) .'
'. t('@time ago', array('@time' => format_interval(time() - $comment->timestamp))); + } + } else { + // format links with comment author + foreach (comment_get_recent() as $comment) { + if ($comment->name == '') { $comment->name = t('Anonymous'); } + $items[] = l($comment->name, 'node/'. $comment->nid, NULL, NULL, 'comment-'. $comment->cid) . ": " . $comment->subject . ' ('. t('@time ago', array('@time' => format_interval(time() - $comment->timestamp, 1))) . ")"; + } } if ($items) { return theme('item_list', $items); @@ -497,6 +520,14 @@ function comment_admin_settings() { '#options' => _comment_get_orders(), '#description' => t('The default sorting for new users and anonymous users while viewing comments. These users may change their view using the comment control panel. For registered users, this change is remembered as a persistent user preference.'), ); + + $form['viewing_options']['comment_block_display'] = array( + '#type' => 'radios', + '#title' => t('Block display'), + '#default_value' => variable_get('comment_block_display', COMMENT_BLOCK_NO_USERNAME), + '#options' => _comment_get_block_displays(), + '#description' => t('Whether or not to display the name of the user that wrote the comment in the block with recent comments.'), + ); $form['viewing_options']['comment_default_per_page'] = array( '#type' => 'select', @@ -1877,6 +1908,17 @@ function _comment_get_orders() { return array( COMMENT_ORDER_NEWEST_FIRST => t('Date - newest first'), COMMENT_ORDER_OLDEST_FIRST => t('Date - oldest first') + ); +} + +/** + * Return an array of ways to display recent comments in the + * recent comments block. + */ +function _comment_get_block_displays() { + return array( + COMMENT_BLOCK_NO_USERNAME => t('Don\'t display comment author'), + COMMENT_BLOCK_WITH_USERNAME => t('Display comment author') ); }