summaryrefslogtreecommitdiff
path: root/modules/comment
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2009-05-28 16:44:07 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2009-05-28 16:44:07 +0000
commit2df43894e2f24cb6a39e6cf11a3b39f3c4b70193 (patch)
tree7290e373de00adc8796333b848e9cd3ca5d4612b /modules/comment
parentcb756bcf08bb5e1288539c06aa16905cda06af9c (diff)
downloadbrdo-2df43894e2f24cb6a39e6cf11a3b39f3c4b70193.tar.gz
brdo-2df43894e2f24cb6a39e6cf11a3b39f3c4b70193.tar.bz2
#306358 by dvessel, JohnAlbin, and flobruit: Add a single $classes string (and corresponding $classes_array) for all dynamic classes in template files.
Diffstat (limited to 'modules/comment')
-rw-r--r--modules/comment/comment-folded.tpl.php20
-rw-r--r--modules/comment/comment-wrapper.tpl.php13
-rw-r--r--modules/comment/comment.module42
-rw-r--r--modules/comment/comment.tpl.php21
4 files changed, 87 insertions, 9 deletions
diff --git a/modules/comment/comment-folded.tpl.php b/modules/comment/comment-folded.tpl.php
index 3f52f0bbb..a582720f0 100644
--- a/modules/comment/comment-folded.tpl.php
+++ b/modules/comment/comment-folded.tpl.php
@@ -11,11 +11,29 @@
* - $author: Comment author. Can be link or plain text.
* - $date: Date and time of posting.
* - $comment: Full comment object.
+ * - $classes: String of classes that can be used to style contextually through
+ * CSS. It can be manipulated through the variable $classes_array from
+ * preprocess functions. The default values can be one or more of the following:
+ * - comment-folded: The current template type, i.e., "theming hook".
+ * - comment-by-anonymous: Comment by an unregistered user.
+ * - comment-by-node-author: Comment by the author of the parent node.
+ * The following applies only to viewers who are registered users:
+ * - comment-unpublished: An unpublished comment visible only to administrators.
+ * - comment-by-viewer: Comment by the user currently viewing the page.
+ * - comment-new: New comment since last the visit.
+ *
+ * These two variables are provided for context:
+ * - $comment: Full comment object.
+ * - $node: Node object the comments are attached to.
+ *
+ * Other variables:
+ * - $classes_array: Array of html class attribute values. It is flattened
+ * into a string within the variable $classes.
*
* @see template_preprocess_comment_folded()
* @see theme_comment_folded()
*/
?>
-<div class="comment-folded">
+<div class="<?php print $classes; ?>">
<span class="subject"><?php print $title . ' ' . $new; ?></span><span class="credit"><?php print t('by') . ' ' . $author; ?></span>
</div>
diff --git a/modules/comment/comment-wrapper.tpl.php b/modules/comment/comment-wrapper.tpl.php
index 1b19be335..99d4708d2 100644
--- a/modules/comment/comment-wrapper.tpl.php
+++ b/modules/comment/comment-wrapper.tpl.php
@@ -8,6 +8,10 @@
* Available variables:
* - $content: All comments for a given page. Also contains comment form
* if enabled.
+ * - $classes: String of classes that can be used to style contextually through
+ * CSS. It can be manipulated through the variable $classes_array from
+ * preprocess functions. The default value has the following:
+ * - comment-wrapper: The current template type, i.e., "theming hook".
*
* The following variables are provided for contextual information.
* - $node: Node object the comments are attached to.
@@ -18,14 +22,15 @@
* - COMMENT_MODE_FLAT_EXPANDED
* - COMMENT_MODE_THREADED_COLLAPSED
* - COMMENT_MODE_THREADED_EXPANDED
- * - $display_order
- * - COMMENT_ORDER_NEWEST_FIRST
- * - COMMENT_ORDER_OLDEST_FIRST
+ *
+ * Other variables:
+ * - $classes_array: Array of html class attribute values. It is flattened
+ * into a string within the variable $classes.
*
* @see template_preprocess_comment_wrapper()
* @see theme_comment_wrapper()
*/
?>
-<div id="comments">
+<div id="comments" class="<?php print $classes; ?>">
<?php print $content; ?>
</div>
diff --git a/modules/comment/comment.module b/modules/comment/comment.module
index ae67b5d94..80f008450 100644
--- a/modules/comment/comment.module
+++ b/modules/comment/comment.module
@@ -128,7 +128,7 @@ function comment_theme() {
),
'comment_folded' => array(
'template' => 'comment-folded',
- 'arguments' => array('comment' => NULL),
+ 'arguments' => array('comment' => NULL, 'node' => NULL),
),
'comment_flat_collapsed' => array(
'arguments' => array('comment' => NULL, 'node' => NULL),
@@ -1833,7 +1833,7 @@ function theme_comment_view($comment, $node, $links = array(), $visible = TRUE)
$output .= theme('comment', $comment, $node, $links);
}
else {
- $output .= theme('comment_folded', $comment);
+ $output .= theme('comment_folded', $comment, $node);
}
return $output;
@@ -1865,6 +1865,25 @@ function template_preprocess_comment(&$variables) {
else {
$variables['status'] = ($comment->status == COMMENT_NOT_PUBLISHED) ? 'comment-unpublished' : 'comment-published';
}
+ // Gather comment classes.
+ if ($comment->uid === 0) {
+ $variables['classes_array'][] = 'comment-by-anonymous';
+ }
+ else {
+ // Published class is not needed. It is either 'comment-preview' or 'comment-unpublished'.
+ if ($variables['status'] != 'comment-published') {
+ $variables['classes_array'][] = $variables['status'];
+ }
+ if ($comment->uid === $variables['node']->uid) {
+ $variables['classes_array'][] = 'comment-by-node-author';
+ }
+ if ($comment->uid === $variables['user']->uid) {
+ $variables['classes_array'][] = 'comment-by-viewer';
+ }
+ if ($comment->new) {
+ $variables['classes_array'][] = 'comment-new';
+ }
+ }
}
/**
@@ -1879,6 +1898,25 @@ function template_preprocess_comment_folded(&$variables) {
$variables['date'] = format_date($comment->timestamp);
$variables['new'] = $comment->new ? t('new') : '';
$variables['title'] = l($comment->subject, comment_node_url() . '/' . $comment->cid, array('fragment' => "comment-$comment->cid"));
+ // Gather comment classes.
+ if ($comment->uid === 0) {
+ $variables['classes_array'][] = 'comment-by-anonymous';
+ }
+ else {
+ if ($comment->status == COMMENT_NOT_PUBLISHED) {
+ $variables['classes_array'][] = 'comment-unpublished';
+ }
+ if ($comment->uid === $variables['node']->uid) {
+ $variables['classes_array'][] = 'comment-by-node-author';
+ }
+ if ($comment->uid === $variables['user']->uid) {
+ $variables['classes_array'][] = 'comment-by-viewer';
+ }
+ if ($comment->new) {
+ $variables['classes_array'][] = 'comment-new';
+ }
+ }
+
}
/**
diff --git a/modules/comment/comment.tpl.php b/modules/comment/comment.tpl.php
index 7d8be3b03..07360a044 100644
--- a/modules/comment/comment.tpl.php
+++ b/modules/comment/comment.tpl.php
@@ -17,16 +17,33 @@
* comment-unpublished, comment-published or comment-preview.
* - $submitted: By line with date and time.
* - $title: Linked title.
+ * - $classes: String of classes that can be used to style contextually through
+ * CSS. It can be manipulated through the variable $classes_array from
+ * preprocess functions. The default values can be one or more of the following:
+ * - comment: The current template type, i.e., "theming hook".
+ * - comment-by-anonymous: Comment by an unregistered user.
+ * - comment-by-node-author: Comment by the author of the parent node.
+ * - comment-preview: When previewing a new or edited comment.
+ * The following applies only to viewers who are registered users:
+ * - comment-unpublished: An unpublished comment visible only to administrators.
+ * - comment-by-viewer: Comment by the user currently viewing the page.
+ * - comment-new: New comment since last the visit.
*
- * These two variables are provided for context.
+ * These two variables are provided for context:
* - $comment: Full comment object.
* - $node: Node object the comments are attached to.
*
+ * Other variables:
+ * - $classes_array: Array of html class attribute values. It is flattened
+ * into a string within the variable $classes.
+ *
+ * @see template_preprocess()
* @see template_preprocess_comment()
+ * @see template_process()
* @see theme_comment()
*/
?>
-<div class="comment<?php print ($comment->new) ? ' comment-new' : ''; print ' ' . $status ?> clearfix">
+<div class="<?php print $classes; ?> clearfix">
<?php print $picture ?>
<?php if ($comment->new): ?>