--- comment.module.old 2009-01-11 18:20:10.000000000 -0500
+++ comment.module 2009-01-11 19:09:44.000000000 -0500
@@ -135,6 +135,9 @@
'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),
),
@@ -922,6 +925,9 @@
function comment_links($comment, $return = 1) {
global $user;
$links = array();
+ if ($comment->cid==-1) {
+ return $links;
+ }
// If viewing just this comment, link back to the node.
if ($return) {
@@ -976,6 +982,66 @@
}
/**
+ * 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
@@ -1104,46 +1170,18 @@
$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');
foreach ($result as $comment) {
$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);
- }
- elseif ($mode == COMMENT_MODE_FLAT_EXPANDED) {
- $comments .= theme('comment_flat_expanded', $comment, $node);
- }
- elseif ($mode == COMMENT_MODE_THREADED_COLLAPSED) {
- $comments .= theme('comment_thread_collapsed', $comment, $node);
- }
- elseif ($mode == COMMENT_MODE_THREADED_EXPANDED) {
- $comments .= theme('comment_thread_expanded', $comment, $node);
- }
+ $comments[] = $comment;
$num_rows = TRUE;
}
- while ($divs-- > 0) {
- $comments .= '';
- }
- $output .= $comments;
+ comment_invoke_comment_prerender($node, $mode, &$comments);
+ $output .= theme('comment_list', $comments, $node);
$output .= theme('pager', NULL, $comments_per_page, 0);
}
@@ -1157,7 +1195,20 @@
return $output;
}
-
+function comment_invoke_comment_prerender($node, $mode, &$comments) {
+ $return = array();
+ foreach (module_implements('comment_prerender') as $name) {
+ $function = $name .'_comment_prerender';
+ $result = $function($node, $mode, $comments);
+ if (isset($result) && is_array($result)) {
+ $return = array_merge($return, $result);
+ }
+ else if (isset($result)) {
+ $return[] = $result;
+ }
+ }
+ return $return;
+}
/**
* Comment operations. Offer different update operations depending on
* which comment administration page is being viewed.