6 * Contains theme override functions and preprocess functions for the Zen theme.
8 * IMPORTANT WARNING: DO NOT MODIFY THIS FILE.
10 * The base Zen theme is designed to be easily extended by its sub-themes. You
11 * shouldn't modify this or any of the CSS or PHP files in the root zen/ folder.
12 * See the online documentation for more information:
13 * http://drupal.org/node/193318
16 // Auto-rebuild the theme registry during theme development.
17 if (theme_get_setting('zen_rebuild_registry')) {
18 drupal_rebuild_theme_registry();
23 * Implements HOOK_theme().
25 function zen_theme(&$existing, $type, $theme, $path) {
26 if (!db_is_active()) {
29 include_once
'./' .
drupal_get_path('theme', 'zen') .
'/zen-internals/template.theme-registry.inc';
30 return _zen_theme($existing, $type, $theme, $path);
34 * Return a themed breadcrumb trail.
37 * An array containing the breadcrumb links.
39 * A string containing the breadcrumb output.
41 function zen_breadcrumb($breadcrumb) {
42 // Determine if we are to display the breadcrumb.
43 $show_breadcrumb = theme_get_setting('zen_breadcrumb');
44 if ($show_breadcrumb == 'yes' || $show_breadcrumb == 'admin' && arg(0) == 'admin') {
46 // Optionally get rid of the homepage link.
47 $show_breadcrumb_home = theme_get_setting('zen_breadcrumb_home');
48 if (!$show_breadcrumb_home) {
49 array_shift($breadcrumb);
52 // Return the breadcrumb with separators.
53 if (!empty($breadcrumb)) {
54 $breadcrumb_separator = theme_get_setting('zen_breadcrumb_separator');
55 $trailing_separator = $title = '';
56 if (theme_get_setting('zen_breadcrumb_title')) {
57 $trailing_separator = $breadcrumb_separator;
58 $title = drupal_get_title();
60 elseif (theme_get_setting('zen_breadcrumb_trailing')) {
61 $trailing_separator = $breadcrumb_separator;
63 return '<div class="breadcrumb">' .
implode($breadcrumb_separator, $breadcrumb) .
"$trailing_separator$title</div>";
66 // Otherwise, return an empty string.
71 * Implements theme_menu_item_link()
73 function zen_menu_item_link($link) {
74 if (empty($link['localized_options'])) {
75 $link['localized_options'] = array();
78 // If an item is a LOCAL TASK, render it as a tab
79 if ($link['type'] & MENU_IS_LOCAL_TASK
) {
80 $link['title'] = '<span class="tab">' .
check_plain($link['title']) .
'</span>';
81 $link['localized_options']['html'] = TRUE
;
84 return l($link['title'], $link['href'], $link['localized_options']);
88 * Duplicate of theme_menu_local_tasks() but adds clear-block to tabs.
90 function zen_menu_local_tasks() {
93 if ($primary = menu_primary_local_tasks()) {
94 $output .
= '<ul class="tabs primary clear-block">' .
$primary .
'</ul>';
96 if ($secondary = menu_secondary_local_tasks()) {
97 $output .
= '<ul class="tabs secondary clear-block">' .
$secondary .
'</ul>';
105 * Override or insert variables into the page templates.
108 * An array of variables to pass to the theme template.
110 * The name of the template being rendered ("page" in this case.)
112 function zen_preprocess_page(&$vars, $hook) {
113 // If the user is silly and enables Zen as the theme, add some styles.
114 if ($GLOBALS['theme'] == 'zen') {
115 include_once
'./' .
drupal_get_path('theme', 'zen') .
'/zen-internals/template.zen.inc';
116 _zen_preprocess_page($vars, $hook);
118 // Add conditional stylesheets.
119 elseif (!module_exists('conditional_styles')) {
120 $vars['styles'] .
= $vars['conditional_styles'] = variable_get('conditional_styles_' .
$GLOBALS['theme'], '');
123 // Classes for body element. Allows advanced theming based on context
124 // (home page, node of certain type, etc.)
125 $classes = explode(' ', $vars['body_classes']);
126 // Remove the mostly useless page-ARG0 class.
127 if ($index = array_search(preg_replace('![^abcdefghijklmnopqrstuvwxyz0-9-_]+!s', '', 'page-'.
drupal_strtolower(arg(0))), $classes)) {
128 unset($classes[$index]);
130 if (!$vars['is_front']) {
131 // Add unique class for each page.
132 $path = drupal_get_path_alias($_GET['q']);
133 $classes[] = zen_id_safe('page-' .
$path);
134 // Add unique class for each website section.
135 list($section, ) = explode('/', $path, 2);
136 if (arg(0) == 'node') {
137 if (arg(1) == 'add') {
138 $section = 'node-add';
140 elseif (is_numeric(arg(1)) && (arg(2) == 'edit' || arg(2) == 'delete')) {
141 $section = 'node-' .
arg(2);
144 $classes[] = zen_id_safe('section-' .
$section);
146 if (theme_get_setting('zen_wireframes')) {
147 $classes[] = 'with-wireframes'; // Optionally add the wireframes style.
149 // Add new sidebar classes in addition to Drupal core's sidebar-* classes.
150 // This provides some backwards compatibility with Zen 6.x-1.x themes.
151 if ($vars['layout'] != 'both') {
152 $new_layout = ($vars['layout'] == 'left') ?
'first' : 'second';
153 if (array_search('sidebar-' .
$vars['layout'], $classes)) {
154 $classes[] = 'sidebar-' .
$new_layout;
156 // Replace core's $layout variable with our naming of sidebars.
157 $vars['layout'] = $new_layout;
159 $vars['body_classes_array'] = $classes;
160 $vars['body_classes'] = implode(' ', $classes); // Concatenate with spaces.
164 * Override or insert variables into the node templates.
167 * An array of variables to pass to the theme template.
169 * The name of the template being rendered ("node" in this case.)
171 function zen_preprocess_node(&$vars, $hook) {
172 // Create the build_mode variable.
173 switch ($vars['node']->build_mode
) {
174 case NODE_BUILD_NORMAL
:
175 $vars['build_mode'] = $vars['teaser'] ?
'teaser' : 'full';
177 case NODE_BUILD_PREVIEW
:
178 $vars['build_mode'] = 'preview';
180 case NODE_BUILD_SEARCH_INDEX
:
181 $vars['build_mode'] = 'search_index';
183 case NODE_BUILD_SEARCH_RESULT
:
184 $vars['build_mode'] = 'search_result';
187 $vars['build_mode'] = 'rss';
189 case NODE_BUILD_PRINT
:
190 $vars['build_mode'] = 'print';
194 // Special classes for nodes.
195 $classes = array('node');
196 if ($vars['sticky']) {
197 $classes[] = 'sticky';
199 if (!$vars['status']) {
200 $classes[] = 'node-unpublished';
201 $vars['unpublished'] = TRUE
;
204 $vars['unpublished'] = FALSE
;
206 if ($vars['uid'] && $vars['uid'] == $GLOBALS['user']->uid
) {
207 $classes[] = 'node-mine'; // Node is authored by current user.
209 if ($vars['teaser']) {
210 $classes[] = 'node-teaser'; // Node is displayed as teaser.
212 // Class for node type: "node-type-page", "node-type-story", "node-type-my-custom-type", etc.
213 $classes[] = zen_id_safe('node-type-' .
$vars['type']);
214 $vars['classes_array'] = $classes;
215 $vars['classes'] = implode(' ', $classes); // Concatenate with spaces
219 * Override or insert variables into the comment templates.
222 * An array of variables to pass to the theme template.
224 * The name of the template being rendered ("comment" in this case.)
226 function zen_preprocess_comment(&$vars, $hook) {
227 include_once
'./' .
drupal_get_path('theme', 'zen') .
'/zen-internals/template.comment.inc';
228 _zen_preprocess_comment($vars, $hook);
232 * Override or insert variables into the block templates.
235 * An array of variables to pass to the theme template.
237 * The name of the template being rendered ("block" in this case.)
239 function zen_preprocess_block(&$vars, $hook) {
240 $block = $vars['block'];
242 // Special classes for blocks.
243 $classes = array('block');
244 $classes[] = 'block-' .
$block->module
;
245 $classes[] = 'region-' .
$vars['block_zebra'];
246 $classes[] = $vars['zebra'];
247 $classes[] = 'region-count-' .
$vars['block_id'];
248 $classes[] = 'count-' .
$vars['id'];
250 $vars['edit_links_array'] = array();
251 $vars['edit_links'] = '';
252 if (theme_get_setting('zen_block_editing') && user_access('administer blocks')) {
253 include_once
'./' .
drupal_get_path('theme', 'zen') .
'/zen-internals/template.block-editing.inc';
254 zen_preprocess_block_editing($vars, $hook);
255 $classes[] = 'with-block-editing';
258 // Render block classes.
259 $vars['classes_array'] = $classes;
260 $vars['classes'] = implode(' ', $classes);
264 * Converts a string to a suitable html ID attribute.
266 * http://www.w3.org/TR/html4/struct/global.html#h-7.5.2 specifies what makes a
267 * valid ID attribute in HTML. This function:
269 * - Ensure an ID starts with an alpha character by optionally adding an 'id'.
270 * - Replaces any character except alphanumeric characters with dashes.
271 * - Converts entire string to lowercase.
276 * The converted string
278 function zen_id_safe($string) {
279 // Replace with dashes anything that isn't A-Z, numbers, dashes, or underscores.
280 $string = strtolower(preg_replace('/[^a-zA-Z0-9-]+/', '-', $string));
281 // If the first character is not a-z, add 'id' in front.
282 if (!ctype_lower($string{0})) { // Don't use ctype_alpha since its locale aware.
283 $string = 'id' .
$string;