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 // When #341140 is fixed, replace _zen_path() with drupal_get_path().
27 include_once
'./' .
_zen_path() .
'/zen-internals/template.theme-registry.inc';
28 return _zen_theme($existing, $type, $theme, $path);
32 * Return a themed breadcrumb trail.
35 * An array containing the breadcrumb links.
37 * A string containing the breadcrumb output.
39 function zen_breadcrumb($breadcrumb) {
40 // Determine if we are to display the breadcrumb.
41 $show_breadcrumb = theme_get_setting('zen_breadcrumb');
42 if ($show_breadcrumb == 'yes' || $show_breadcrumb == 'admin' && arg(0) == 'admin') {
44 // Optionally get rid of the homepage link.
45 $show_breadcrumb_home = theme_get_setting('zen_breadcrumb_home');
46 if (!$show_breadcrumb_home) {
47 array_shift($breadcrumb);
50 // Return the breadcrumb with separators.
51 if (!empty($breadcrumb)) {
52 $breadcrumb_separator = theme_get_setting('zen_breadcrumb_separator');
53 $trailing_separator = $title = '';
54 if (theme_get_setting('zen_breadcrumb_title')) {
55 $trailing_separator = $breadcrumb_separator;
56 $title = drupal_get_title();
58 elseif (theme_get_setting('zen_breadcrumb_trailing')) {
59 $trailing_separator = $breadcrumb_separator;
61 return '<div class="breadcrumb">' .
implode($breadcrumb_separator, $breadcrumb) .
"$trailing_separator$title</div>";
64 // Otherwise, return an empty string.
69 * Implements theme_menu_item_link()
71 function zen_menu_item_link($link) {
72 if (empty($link['localized_options'])) {
73 $link['localized_options'] = array();
76 // If an item is a LOCAL TASK, render it as a tab
77 if ($link['type'] & MENU_IS_LOCAL_TASK
) {
78 $link['title'] = '<span class="tab">' .
check_plain($link['title']) .
'</span>';
79 $link['localized_options']['html'] = TRUE
;
82 return l($link['title'], $link['href'], $link['localized_options']);
86 * Duplicate of theme_menu_local_tasks() but adds clear-block to tabs.
88 function zen_menu_local_tasks() {
91 if ($primary = menu_primary_local_tasks()) {
92 $output .
= '<ul class="tabs primary clear-block">' .
$primary .
'</ul>';
94 if ($secondary = menu_secondary_local_tasks()) {
95 $output .
= '<ul class="tabs secondary clear-block">' .
$secondary .
'</ul>';
103 * Override or insert variables into the page templates.
106 * An array of variables to pass to the theme template.
108 * The name of the template being rendered ("page" in this case.)
110 function zen_preprocess_page(&$vars, $hook) {
111 // If the user is silly and enables Zen as the theme, add some styles.
112 if ($GLOBALS['theme'] == 'zen') {
113 include_once
'./' .
_zen_path() .
'/zen-internals/template.zen.inc';
114 _zen_preprocess_page($vars, $hook);
116 // Add conditional stylesheets.
117 elseif (!module_exists('conditional_styles')) {
118 $vars['styles'] .
= $vars['conditional_styles'] = variable_get('conditional_styles_' .
$GLOBALS['theme'], '');
121 // Classes for body element. Allows advanced theming based on context
122 // (home page, node of certain type, etc.)
123 $classes = explode(' ', $vars['body_classes']);
124 // Remove the mostly useless page-ARG0 class.
125 if ($index = array_search(preg_replace('![^abcdefghijklmnopqrstuvwxyz0-9-_]+!s', '', 'page-'.
drupal_strtolower(arg(0))), $classes)) {
126 unset($classes[$index]);
128 if (!$vars['is_front']) {
129 // Add unique class for each page.
130 $path = drupal_get_path_alias($_GET['q']);
131 $classes[] = zen_id_safe('page-' .
$path);
132 // Add unique class for each website section.
133 list($section, ) = explode('/', $path, 2);
134 if (arg(0) == 'node') {
135 if (arg(1) == 'add') {
136 $section = 'node-add';
138 elseif (is_numeric(arg(1)) && (arg(2) == 'edit' || arg(2) == 'delete')) {
139 $section = 'node-' .
arg(2);
142 $classes[] = zen_id_safe('section-' .
$section);
144 if (theme_get_setting('zen_wireframes')) {
145 $classes[] = 'with-wireframes'; // Optionally add the wireframes style.
147 // Add new sidebar classes in addition to Drupal core's sidebar-* classes.
148 // This provides some backwards compatibility with Zen 6.x-1.x themes.
149 if ($vars['layout'] != 'both') {
150 $new_layout = ($vars['layout'] == 'left') ?
'first' : 'second';
151 if (array_search('sidebar-' .
$vars['layout'], $classes)) {
152 $classes[] = 'sidebar-' .
$new_layout;
154 // Replace core's $layout variable with our naming of sidebars.
155 $vars['layout'] = $new_layout;
157 $vars['body_classes_array'] = $classes;
158 $vars['body_classes'] = implode(' ', $classes); // Concatenate with spaces.
162 * Override or insert variables into the maintenance page template.
165 * An array of variables to pass to the theme template.
167 * The name of the template being rendered ("maintenance_page" in this case.)
169 function zen_preprocess_maintenance_page(&$vars, $hook) {
170 // If Zen is the maintenance theme, add some styles.
171 if ($GLOBALS['theme'] == 'zen') {
172 include_once
'./' .
_zen_path() .
'/zen-internals/template.zen.inc';
173 _zen_preprocess_page($vars, $hook);
175 // Add conditional stylesheets.
176 elseif (!module_exists('conditional_styles')) {
177 $vars['styles'] .
= $vars['conditional_styles'] = variable_get('conditional_styles_' .
$GLOBALS['theme'], '');
180 // Classes for body element. Allows advanced theming based on context
181 // (home page, node of certain type, etc.)
182 $vars['body_classes_array'] = explode(' ', $vars['body_classes']);
186 * Override or insert variables into the node templates.
189 * An array of variables to pass to the theme template.
191 * The name of the template being rendered ("node" in this case.)
193 function zen_preprocess_node(&$vars, $hook) {
194 // Create the build_mode variable.
195 switch ($vars['node']->build_mode
) {
196 case NODE_BUILD_NORMAL
:
197 $vars['build_mode'] = $vars['teaser'] ?
'teaser' : 'full';
199 case NODE_BUILD_PREVIEW
:
200 $vars['build_mode'] = 'preview';
202 case NODE_BUILD_SEARCH_INDEX
:
203 $vars['build_mode'] = 'search_index';
205 case NODE_BUILD_SEARCH_RESULT
:
206 $vars['build_mode'] = 'search_result';
209 $vars['build_mode'] = 'rss';
211 case NODE_BUILD_PRINT
:
212 $vars['build_mode'] = 'print';
216 // Create the user_picture variable.
217 $vars['user_picture'] = $vars['picture'];
219 // Special classes for nodes.
220 $classes = array('node');
221 // Class for node type: "node-type-page", "node-type-story", "node-type-my-custom-type", etc.
222 $classes[] = zen_id_safe('node-type-' .
$vars['type']);
223 if ($vars['promote']) {
224 $vars['classes_array'][] = 'node-promoted';
226 if ($vars['sticky']) {
227 $classes[] = 'node-sticky';
229 if (!$vars['status']) {
230 $classes[] = 'node-unpublished';
231 $vars['unpublished'] = TRUE
;
234 $vars['unpublished'] = FALSE
;
236 if ($vars['uid'] && $vars['uid'] == $GLOBALS['user']->uid
) {
237 $classes[] = 'node-mine'; // Node is authored by current user.
239 if ($vars['teaser']) {
240 $classes[] = 'node-teaser'; // Node is displayed as teaser.
242 if (isset($vars['preview'])) {
243 $vars['classes_array'][] = 'node-preview';
245 $vars['classes_array'] = $classes;
246 $vars['classes'] = implode(' ', $classes); // Concatenate with spaces
250 * Override or insert variables into the comment templates.
253 * An array of variables to pass to the theme template.
255 * The name of the template being rendered ("comment" in this case.)
257 function zen_preprocess_comment(&$vars, $hook) {
258 include_once
'./' .
_zen_path() .
'/zen-internals/template.comment.inc';
259 _zen_preprocess_comment($vars, $hook);
263 * Override or insert variables into the block templates.
266 * An array of variables to pass to the theme template.
268 * The name of the template being rendered ("block" in this case.)
270 function zen_preprocess_block(&$vars, $hook) {
271 $block = $vars['block'];
273 // Special classes for blocks.
274 $classes = array('block');
275 $classes[] = 'block-' .
$block->module
;
276 $classes[] = 'region-' .
$vars['block_zebra'];
277 $classes[] = $vars['zebra'];
278 $classes[] = 'region-count-' .
$vars['block_id'];
279 $classes[] = 'count-' .
$vars['id'];
281 $vars['edit_links_array'] = array();
282 $vars['edit_links'] = '';
283 if (theme_get_setting('zen_block_editing') && user_access('administer blocks')) {
284 include_once
'./' .
_zen_path() .
'/zen-internals/template.block-editing.inc';
285 zen_preprocess_block_editing($vars, $hook);
286 $classes[] = 'with-block-editing';
289 // Render block classes.
290 $vars['classes_array'] = $classes;
291 $vars['classes'] = implode(' ', $classes);
295 * Converts a string to a suitable html ID attribute.
297 * http://www.w3.org/TR/html4/struct/global.html#h-7.5.2 specifies what makes a
298 * valid ID attribute in HTML. This function:
300 * - Ensure an ID starts with an alpha character by optionally adding an 'id'.
301 * - Replaces any character except alphanumeric characters with dashes.
302 * - Converts entire string to lowercase.
307 * The converted string
309 function zen_id_safe($string) {
310 // Replace with dashes anything that isn't A-Z, numbers, dashes, or underscores.
311 $string = strtolower(preg_replace('/[^a-zA-Z0-9-]+/', '-', $string));
312 // If the first character is not a-z, add 'id' in front.
313 if (!ctype_lower($string{0})) { // Don't use ctype_alpha since its locale aware.
314 $string = 'id' .
$string;
320 * Returns the path to the Zen theme.
322 * drupal_get_filename() is broken; see #341140. When that is fixed in Drupal 6,
323 * replace _zen_path() with drupal_get_path('theme', 'zen').
325 function _zen_path() {
326 static
$path = FALSE
;
328 $matches = drupal_system_listing('zen\.info$', 'themes', 'name', 0);
329 if (!empty($matches['zen']->filename
)) {
330 $path = dirname($matches['zen']->filename
);