Index: includes/theme.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/theme.inc,v retrieving revision 1.435 diff -u -p -r1.435 theme.inc --- includes/theme.inc 15 Sep 2008 20:48:07 -0000 1.435 +++ includes/theme.inc 17 Sep 2008 17:04:28 -0000 @@ -650,6 +650,11 @@ function theme() { } } + // Clean up and flatten the HTML class attribute. + if (isset($variables['classes'])) { + $variables['classes'] = implode(' ', str_replace('_', '-', $variables['classes'])); + } + // Get suggestions for alternate templates out of the variables // that were set. This lets us dynamically choose a template // from a list. The order is FILO, so this array is ordered from @@ -1743,6 +1748,9 @@ function template_preprocess(&$variables // Tell all templates where they are located. $variables['directory'] = path_to_theme(); + // Initialize html class attribute for the current hook. + $variables['classes'] = array($hook); + // Set default variables that depend on the database. $variables['is_admin'] = FALSE; $variables['is_front'] = FALSE; @@ -1858,32 +1866,29 @@ function template_preprocess_page(&$vari // Compile a list of classes that are going to be applied to the body element. // This allows advanced theming based on context (home page, node of certain type, etc.). - $body_classes = array(); // Add a class that tells us whether we're on the front page or not. - $body_classes[] = $variables['is_front'] ? 'front' : 'not-front'; + $variables['classes'][] = $variables['is_front'] ? 'front' : 'not-front'; // Add a class that tells us whether the page is viewed by an authenticated user or not. - $body_classes[] = $variables['logged_in'] ? 'logged-in' : 'not-logged-in'; + $variables['classes'][] = $variables['logged_in'] ? 'logged-in' : 'not-logged-in'; // Add arg(0) to make it possible to theme the page depending on the current page // type (e.g. node, admin, user, etc.). To avoid illegal characters in the class, // we're removing everything disallowed. We are not using 'a-z' as that might leave // in certain international characters (e.g. German umlauts). - $body_classes[] = preg_replace('![^abcdefghijklmnopqrstuvwxyz0-9-_]+!s', '', 'page-' . form_clean_id(drupal_strtolower(arg(0)))); + $variables['classes'][] = preg_replace('![^abcdefghijklmnopqrstuvwxyz0-9-_]+!s', '', 'page-' . form_clean_id(drupal_strtolower(arg(0)))); // If on an individual node page, add the node type. if (isset($variables['node']) && $variables['node']->type) { - $body_classes[] = 'node-type-' . form_clean_id($variables['node']->type); + $variables['classes'][] = 'node-type-' . form_clean_id($variables['node']->type); } // Add information about the number of sidebars. if ($variables['layout'] == 'both') { - $body_classes[] = 'two-sidebars'; + $variables['classes'][] = 'two-sidebars'; } elseif ($variables['layout'] == 'none') { - $body_classes[] = 'no-sidebars'; + $variables['classes'][] = 'no-sidebars'; } else { - $body_classes[] = 'one-sidebar sidebar-' . $variables['layout']; + $variables['classes'][] = 'one-sidebar sidebar-' . $variables['layout']; } - // Implode with spaces. - $variables['body_classes'] = implode(' ', $body_classes); // Build a list of suggested template files in order of specificity. One // suggestion is made for every element of the current path, though @@ -1955,6 +1960,24 @@ function template_preprocess_node(&$vari // Flatten the node object's member fields. $variables = array_merge((array)$node, $variables); + + // Gather node classes. + $variables['classes'][] = 'node-' . $node->type; + if ($variables['promote']) { + $variables['classes'][] = 'node-promoted'; + } + if ($variables['sticky']) { + $variables['classes'][] = 'node-sticky'; + } + if (!$variables['status']) { + $variables['classes'][] = 'node-unpublished'; + } + if ($variables['teaser']) { + $variables['classes'][] = 'node-teaser'; + } + if (isset($variables['preview'])) { + $variables['classes'][] = 'node-preview'; + } // Display info only on certain node types. if (theme_get_setting('toggle_node_info_' . $node->type)) { @@ -1997,6 +2020,8 @@ function template_preprocess_block(&$var $variables['block_zebra'] = ($block_counter[$variables['block']->region] % 2) ? 'odd' : 'even'; $variables['block_id'] = $block_counter[$variables['block']->region]++; + $variables['classes'][] = 'block-' . $variables['block']->module; + $variables['template_files'][] = 'block-' . $variables['block']->region; $variables['template_files'][] = 'block-' . $variables['block']->module; $variables['template_files'][] = 'block-' . $variables['block']->module . '-' . $variables['block']->delta; Index: includes/theme.maintenance.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/theme.maintenance.inc,v retrieving revision 1.16 diff -u -p -r1.16 theme.maintenance.inc --- includes/theme.maintenance.inc 21 Aug 2008 19:36:36 -0000 1.16 +++ includes/theme.maintenance.inc 17 Sep 2008 17:04:29 -0000 @@ -265,21 +265,19 @@ function template_preprocess_maintenance $variables['closure'] = ''; // Compile a list of classes that are going to be applied to the body element. - $body_classes = array(); - $body_classes[] = 'in-maintenance'; + $variables['classes'][] = 'in-maintenance'; if (isset($variables['db_is_active']) && !$variables['db_is_active']) { - $body_classes[] = 'db-offline'; + $variables['classes'][] = 'db-offline'; } if ($variables['layout'] == 'both') { - $body_classes[] = 'two-sidebars'; + $variables['classes'][] = 'two-sidebars'; } elseif ($variables['layout'] == 'none') { - $body_classes[] = 'no-sidebars'; + $variables['classes'][] = 'no-sidebars'; } else { - $body_classes[] = 'one-sidebar sidebar-' . $variables['layout']; + $variables['classes'][] = 'one-sidebar sidebar-' . $variables['layout']; } - $variables['body_classes'] = implode(' ', $body_classes); // Dead databases will show error messages so supplying this template will // allow themers to override the page and the content completely. Index: modules/comment/comment-folded.tpl.php =================================================================== RCS file: /cvs/drupal/drupal/modules/comment/comment-folded.tpl.php,v retrieving revision 1.4 diff -u -p -r1.4 comment-folded.tpl.php --- modules/comment/comment-folded.tpl.php 14 May 2008 13:12:40 -0000 1.4 +++ modules/comment/comment-folded.tpl.php 17 Sep 2008 17:04:29 -0000 @@ -11,11 +11,20 @@ * - $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 has one or more of the following values: + * - comment-folded: The current 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. * * @see template_preprocess_comment_folded() * @see theme_comment_folded() */ ?> -
+
Index: modules/comment/comment-wrapper.tpl.php =================================================================== RCS file: /cvs/drupal/drupal/modules/comment/comment-wrapper.tpl.php,v retrieving revision 1.4 diff -u -p -r1.4 comment-wrapper.tpl.php --- modules/comment/comment-wrapper.tpl.php 14 May 2008 13:12:40 -0000 1.4 +++ modules/comment/comment-wrapper.tpl.php 17 Sep 2008 17:04:29 -0000 @@ -8,6 +8,9 @@ * 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 has the following value: + * - comment-wrapper: The current theming hook. * * The following variables are provided for contextual information. * - $node: Node object the comments are attached to. @@ -18,14 +21,11 @@ * - COMMENT_MODE_FLAT_EXPANDED * - COMMENT_MODE_THREADED_COLLAPSED * - COMMENT_MODE_THREADED_EXPANDED - * - $display_order - * - COMMENT_ORDER_NEWEST_FIRST - * - COMMENT_ORDER_OLDEST_FIRST * * @see template_preprocess_comment_wrapper() * @see theme_comment_wrapper() */ ?> -
+
Index: modules/comment/comment.module =================================================================== RCS file: /cvs/drupal/drupal/modules/comment/comment.module,v retrieving revision 1.649 diff -u -p -r1.649 comment.module --- modules/comment/comment.module 17 Sep 2008 07:11:56 -0000 1.649 +++ modules/comment/comment.module 17 Sep 2008 17:04:29 -0000 @@ -133,7 +133,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), @@ -1581,7 +1581,7 @@ function theme_comment_view($comment, $n $output .= theme('comment', $comment, $node, $links); } else { - $output .= theme('comment_folded', $comment); + $output .= theme('comment_folded', $comment, $node); } return $output; @@ -1613,6 +1613,25 @@ function template_preprocess_comment(&$v else { $variables['status'] = ($comment->status == COMMENT_NOT_PUBLISHED) ? 'comment-unpublished' : 'comment-published'; } + // Gather comment classes. + if ($comment->uid === 0) { + $variables['classes'][] = 'comment-by-anonymous'; + } + else { + // Published class is not needed. It is either 'comment-preview' or 'comment-unpublished'. + if ($variables['status'] != 'comment-published') { + $variables['classes'][] = $variables['status']; + } + if ($comment->uid === $variables['node']->uid) { + $variables['classes'][] = 'comment-by-node-author'; + } + if ($comment->uid === $variables['user']->uid) { + $variables['classes'][] = 'comment-by-viewer'; + } + if ($comment->new) { + $variables['classes'][] = 'comment-new'; + } + } } /** @@ -1627,6 +1646,25 @@ function template_preprocess_comment_fol $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'][] = 'comment-by-anonymous'; + } + else { + if ($comment->status == COMMENT_NOT_PUBLISHED) { + $variables['classes'][] = 'comment-unpublished'; + } + if ($comment->uid === $variables['node']->uid) { + $variables['classes'][] = 'comment-by-node-author'; + } + if ($comment->uid === $variables['user']->uid) { + $variables['classes'][] = 'comment-by-viewer'; + } + if ($comment->new) { + $variables['classes'][] = 'comment-new'; + } + } + } /** Index: modules/comment/comment.tpl.php =================================================================== RCS file: /cvs/drupal/drupal/modules/comment/comment.tpl.php,v retrieving revision 1.7 diff -u -p -r1.7 comment.tpl.php --- modules/comment/comment.tpl.php 14 May 2008 13:12:41 -0000 1.7 +++ modules/comment/comment.tpl.php 17 Sep 2008 17:04:29 -0000 @@ -17,6 +17,16 @@ * 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 has one or more of the following values: + * - comment: The current 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. * - $comment: Full comment object. @@ -26,7 +36,7 @@ * @see theme_comment() */ ?> -
+
new): ?> Index: modules/node/node.tpl.php =================================================================== RCS file: /cvs/drupal/drupal/modules/node/node.tpl.php,v retrieving revision 1.4 diff -u -p -r1.4 node.tpl.php --- modules/node/node.tpl.php 25 Jan 2008 21:21:44 -0000 1.4 +++ modules/node/node.tpl.php 17 Sep 2008 17:04:29 -0000 @@ -20,6 +20,18 @@ * - $terms: the themed list of taxonomy term links output from theme_links(). * - $submitted: themed submission information output from * theme_node_submitted(). + * - $classes: String of classes that can be used to style contextually through + * CSS. It has one or more of the following values: + * - node: The current theming hook. + * - node-[type]: The current node type. For example, if the node is a + * "Blog entry" it would result in "node-blog". Note that the machine + * name will often be in a short form of the human readable label. + * - node-teaser: Nodes in teaser form. + * - node-preview: Nodes in preview mode. + * The following are controlled through the node publishing options. + * - node-promoted: Nodes promoted to the front page. + * - node-sticky: Nodes ordered above other non-sticky nodes in teaser listings. + * - node-unpublished: Unpublished nodes visible only to administrators. * * Other variables: * - $node: Full node object. Contains data that may not be safe. @@ -48,7 +60,7 @@ * @see template_preprocess_node() */ ?> -
+
Index: modules/system/block.tpl.php =================================================================== RCS file: /cvs/drupal/drupal/modules/system/block.tpl.php,v retrieving revision 1.6 diff -u -p -r1.6 block.tpl.php --- modules/system/block.tpl.php 14 Apr 2008 17:48:41 -0000 1.6 +++ modules/system/block.tpl.php 17 Sep 2008 17:04:29 -0000 @@ -12,6 +12,12 @@ * - $block->module: Module that generated the block. * - $block->delta: An ID for the block, unique within each module. * - $block->region: The block region embedding the current block. + * - $classes: String of classes that can be used to style contextually through + * CSS. It has one or more of the following values: + * - block: The current theming hook. + * - block-[module]: The module generating the block. For example, the user module + * is responsible for handling the default user navigation block. In that case + * the class would be "block-user". * * Helper variables: * - $block_zebra: Outputs 'odd' and 'even' dependent on each block region. @@ -26,7 +32,7 @@ * @see template_preprocess_block() */ ?> -
+
subject): ?>

subject ?>

Index: modules/system/box.tpl.php =================================================================== RCS file: /cvs/drupal/drupal/modules/system/box.tpl.php,v retrieving revision 1.3 diff -u -p -r1.3 box.tpl.php --- modules/system/box.tpl.php 16 Dec 2007 21:01:45 -0000 1.3 +++ modules/system/box.tpl.php 17 Sep 2008 17:04:29 -0000 @@ -9,11 +9,14 @@ * Available variables: * - $title: Box title. * - $content: Box content. + * - $classes: String of classes that can be used to style contextually through + * CSS. It has the following value: + * - box: The current theming hook. * * @see template_preprocess() */ ?> -
+

Index: modules/system/maintenance-page.tpl.php =================================================================== RCS file: /cvs/drupal/drupal/modules/system/maintenance-page.tpl.php,v retrieving revision 1.3 diff -u -p -r1.3 maintenance-page.tpl.php --- modules/system/maintenance-page.tpl.php 1 Jul 2008 20:36:40 -0000 1.3 +++ modules/system/maintenance-page.tpl.php 17 Sep 2008 17:04:29 -0000 @@ -25,7 +25,7 @@ - +