--- comment.module.original Thu Feb 14 12:41:08 2008
+++ comment.module Thu Feb 14 12:28:52 2008
@@ -165,6 +165,9 @@ function comment_theme() {
'template' => 'comment-folded',
'arguments' => array('comment' => NULL),
),
+ 'comment_list' => array(
+ 'arguments' => array('comments' => NULL, 'mode' => NULL),
+ ),
'comment_flat_collapsed' => array(
'arguments' => array('comment' => NULL, 'node' => NULL),
),
@@ -854,6 +857,66 @@ function comment_links($comment, $return
}
/**
+ * Theme comment list threaded list.
+ *
+ * @param $comments
+ * An array containing comments.
+ * @param $node
+ * The node which comment(s) needs rendering.
+ * @ingroup themeable
+ */
+function theme_comment_list($comments, $node) {
+
+ $mode = _comment_get_display_setting('mode', $node);
+ $divs = 0;
+ $num_rows = FALSE;
+ $depth0 = FALSE;
+ $output = '';
+ drupal_add_css(drupal_get_path('module', 'comment') .'/comment.css');
+
+ foreach($comments as $comment) {
+ // add divs for threaded mode
+ if ($mode == COMMENT_MODE_THREADED_COLLAPSED || $mode == COMMENT_MODE_THREADED_EXPANDED) {
+
+ if ($comment->depth > $divs) {
+ $divs++;
+ $output .= '
';
+ }
+ }
+
+ // add enclosing div for first level
+ if ($comment->depth == 0) {
+ if($depth0) $output .= '';
+ $output .= '';
+ $depth0 = TRUE;
+ }
+ }
+ if ($mode == COMMENT_MODE_FLAT_COLLAPSED) {
+ $output .= theme('comment_flat_collapsed', $comment, $node);
+ }
+ else if ($mode == COMMENT_MODE_FLAT_EXPANDED) {
+ $output .= theme('comment_flat_expanded', $comment, $node);
+ }
+ else if ($mode == COMMENT_MODE_THREADED_COLLAPSED) {
+ $output .= theme('comment_thread_collapsed', $comment, $node);
+ }
+ else if ($mode == COMMENT_MODE_THREADED_EXPANDED) {
+ $output .= theme('comment_thread_expanded', $comment, $node);
+ }
+ }
+ while ($divs-- > 0) {
+ $output .= '
';
+ }
+ if($depth0) $output .= '';
+ return $output;
+}
+
+/**
* Renders comment(s).
*
* @param $node
@@ -988,53 +1051,23 @@ function comment_render($node, $cid = 0)
// Start a form, for use with comment control.
$result = pager_query($query, $comments_per_page, 0, $query_count, $query_args);
- $divs = 0;
$num_rows = FALSE;
- $comments = '';
+ $comments = array();
drupal_add_css(drupal_get_path('module', 'comment') .'/comment.css');
while ($comment = db_fetch_object($result)) {
$comment = drupal_unpack($comment);
$comment->name = $comment->uid ? $comment->registered_name : $comment->name;
$comment->depth = count(explode('.', $comment->thread)) - 1;
-
- if ($mode == COMMENT_MODE_THREADED_COLLAPSED || $mode == COMMENT_MODE_THREADED_EXPANDED) {
- if ($comment->depth > $divs) {
- $divs++;
- $comments .= '';
- }
- else {
- while ($comment->depth < $divs) {
- $divs--;
- $comments .= '
';
- }
- }
- }
-
- if ($mode == COMMENT_MODE_FLAT_COLLAPSED) {
- $comments .= theme('comment_flat_collapsed', $comment, $node);
- }
- else if ($mode == COMMENT_MODE_FLAT_EXPANDED) {
- $comments .= theme('comment_flat_expanded', $comment, $node);
- }
- else if ($mode == COMMENT_MODE_THREADED_COLLAPSED) {
- $comments .= theme('comment_thread_collapsed', $comment, $node);
- }
- else if ($mode == COMMENT_MODE_THREADED_EXPANDED) {
- $comments .= theme('comment_thread_expanded', $comment, $node);
- }
-
+ $comments[] = $comment;
$num_rows = TRUE;
}
- while ($divs-- > 0) {
- $comments .= '';
- }
$comment_controls = variable_get('comment_controls_'. $node->type, COMMENT_CONTROLS_HIDDEN);
if ($num_rows && ($comment_controls == COMMENT_CONTROLS_ABOVE || $comment_controls == COMMENT_CONTROLS_ABOVE_BELOW)) {
$output .= drupal_get_form('comment_controls', $mode, $order, $comments_per_page);
}
- $output .= $comments;
+ $output .= theme('comment_list', $comments, $node);
$output .= theme('pager', NULL, $comments_per_page, 0);
if ($num_rows && ($comment_controls == COMMENT_CONTROLS_BELOW || $comment_controls == COMMENT_CONTROLS_ABOVE_BELOW)) {