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() */ ?> -
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() */ ?> -subject; ?>
" . ($teaser ? l($node->title, "node/$node->nid") : check_plain($node->title)) . "
\n"; Index: themes/garland/block.tpl.php =================================================================== RCS file: /cvs/drupal/drupal/themes/garland/block.tpl.php,v retrieving revision 1.4 diff -u -p -r1.4 block.tpl.php --- themes/garland/block.tpl.php 14 Apr 2008 17:48:46 -0000 1.4 +++ themes/garland/block.tpl.php 17 Sep 2008 17:04:29 -0000 @@ -1,7 +1,7 @@ -subject ?>
Index: themes/garland/comment.tpl.php =================================================================== RCS file: /cvs/drupal/drupal/themes/garland/comment.tpl.php,v retrieving revision 1.11 diff -u -p -r1.11 comment.tpl.php --- themes/garland/comment.tpl.php 14 Apr 2008 17:48:46 -0000 1.11 +++ themes/garland/comment.tpl.php 17 Sep 2008 17:04:29 -0000 @@ -1,7 +1,7 @@ -subject ?>
Index: themes/pushbutton/page.tpl.php =================================================================== RCS file: /cvs/drupal/drupal/themes/pushbutton/page.tpl.php,v retrieving revision 1.26 diff -u -p -r1.26 page.tpl.php --- themes/pushbutton/page.tpl.php 25 Jun 2008 09:12:25 -0000 1.26 +++ themes/pushbutton/page.tpl.php 17 Sep 2008 17:04:29 -0000 @@ -10,7 +10,7 @@ - +