4 * Contains theme override functions and preprocess functions for the Zen theme.
6 * IMPORTANT WARNING: DO NOT MODIFY THIS FILE.
8 * The base Zen theme is designed to be easily extended by its sub-themes. You
9 * shouldn't modify this or any of the CSS or PHP files in the root zen/ folder.
10 * See the online documentation for more information:
11 * http://drupal.org/node/193318
14 // Auto-rebuild the theme registry during theme development.
15 if (theme_get_setting('zen_rebuild_registry')) {
16 drupal_rebuild_theme_registry();
20 * Add stylesheets only needed when Zen is the active theme. Don't do something
21 * this dumb in your sub-theme; see how wireframes.css is handled instead.
23 if ($GLOBALS['theme'] == 'zen') { // If we're in the main theme
24 if (theme_get_setting('zen_layout') == 'border-politics-fixed') {
25 drupal_add_css(_zen_path() .
'/layout-fixed.css', 'theme', 'all');
28 drupal_add_css(_zen_path() .
'/layout-liquid.css', 'theme', 'all');
33 * Implements HOOK_theme().
35 function zen_theme(&$existing, $type, $theme, $path) {
36 include_once
'./' .
_zen_path() .
'/template.theme-registry.inc';
37 return _zen_theme($existing, $type, $theme, $path);
41 * Return a themed breadcrumb trail.
44 * An array containing the breadcrumb links.
46 * A string containing the breadcrumb output.
48 function zen_breadcrumb($breadcrumb) {
49 // Determine if we are to display the breadcrumb.
50 $show_breadcrumb = theme_get_setting('zen_breadcrumb');
51 if ($show_breadcrumb == 'yes' || $show_breadcrumb == 'admin' && arg(0) == 'admin') {
53 // Optionally get rid of the homepage link.
54 $show_breadcrumb_home = theme_get_setting('zen_breadcrumb_home');
55 if (!$show_breadcrumb_home) {
56 array_shift($breadcrumb);
59 // Return the breadcrumb with separators.
60 if (!empty($breadcrumb)) {
61 $breadcrumb_separator = theme_get_setting('zen_breadcrumb_separator');
62 $trailing_separator = $title = '';
63 if (theme_get_setting('zen_breadcrumb_title')) {
64 if ($title = drupal_get_title()) {
65 $trailing_separator = $breadcrumb_separator;
68 elseif (theme_get_setting('zen_breadcrumb_trailing')) {
69 $trailing_separator = $breadcrumb_separator;
71 return '<div class="breadcrumb">' .
implode($breadcrumb_separator, $breadcrumb) .
"$trailing_separator$title</div>";
74 // Otherwise, return an empty string.
79 * Implements theme_menu_item_link()
81 function zen_menu_item_link($link) {
82 if (empty($link['localized_options'])) {
83 $link['localized_options'] = array();
86 // If an item is a LOCAL TASK, render it as a tab
87 if ($link['type'] & MENU_IS_LOCAL_TASK
) {
88 $link['title'] = '<span class="tab">' .
check_plain($link['title']) .
'</span>';
89 $link['localized_options']['html'] = TRUE
;
92 return l($link['title'], $link['href'], $link['localized_options']);
96 * Duplicate of theme_menu_local_tasks() but adds clear-block to tabs.
98 function zen_menu_local_tasks() {
101 // CTools requires a different set of local task functions.
102 if (module_exists('ctools')) {
103 $primary = ctools_menu_primary_local_tasks();
104 $secondary = ctools_menu_secondary_local_tasks();
107 $primary = menu_primary_local_tasks();
108 $secondary = menu_secondary_local_tasks();
112 $output .
= '<ul class="tabs primary clear-block">' .
$primary .
'</ul>';
115 $output .
= '<ul class="tabs secondary clear-block">' .
$secondary .
'</ul>';
123 * Override or insert variables into the page templates.
126 * An array of variables to pass to the theme template.
128 * The name of the template being rendered ("page" in this case.)
130 function zen_preprocess_page(&$vars, $hook) {
131 // Add conditional stylesheets.
132 if (!module_exists('conditional_styles')) {
133 $vars['conditional_styles'] = variable_get('conditional_styles_' .
$GLOBALS['theme'], '');
134 $vars['styles'] .
= $vars['conditional_styles'];
137 // Classes for body element. Allows advanced theming based on context
138 // (home page, node of certain type, etc.)
139 $classes = explode(' ', $vars['body_classes']);
140 // Remove the mostly useless page-ARG0 class.
141 if ($index = array_search(preg_replace('![^abcdefghijklmnopqrstuvwxyz0-9-_]+!s', '', 'page-'.
drupal_strtolower(arg(0))), $classes)) {
142 unset($classes[$index]);
144 if (!$vars['is_front']) {
145 // Add unique class for each page.
146 $path = drupal_get_path_alias($_GET['q']);
147 $classes[] = zen_id_safe('page-' .
$path);
148 // Add unique class for each website section.
149 list($section, ) = explode('/', $path, 2);
150 if (arg(0) == 'node') {
151 if (arg(1) == 'add') {
152 $section = 'node-add';
154 elseif (is_numeric(arg(1)) && (arg(2) == 'edit' || arg(2) == 'delete')) {
155 $section = 'node-' .
arg(2);
158 $classes[] = zen_id_safe('section-' .
$section);
160 if (theme_get_setting('zen_wireframes')) {
161 $classes[] = 'with-wireframes'; // Optionally add the wireframes style.
163 $vars['body_classes_array'] = $classes;
164 $vars['body_classes'] = implode(' ', $classes); // Concatenate with spaces.
168 * Override or insert variables into the maintenance page template.
171 * An array of variables to pass to the theme template.
173 * The name of the template being rendered ("maintenance_page" in this case.)
175 function zen_preprocess_maintenance_page(&$vars, $hook) {
176 // Add conditional stylesheets.
177 if (!module_exists('conditional_styles')) {
178 $vars['conditional_styles'] = variable_get('conditional_styles_' .
$GLOBALS['theme'], '');
179 $vars['styles'] .
= $vars['conditional_styles'];
182 // Classes for body element. Allows advanced theming based on context
183 // (home page, node of certain type, etc.)
184 $vars['body_classes_array'] = explode(' ', $vars['body_classes']);
188 * Override or insert variables into the node templates.
191 * An array of variables to pass to the theme template.
193 * The name of the template being rendered ("node" in this case.)
195 function zen_preprocess_node(&$vars, $hook) {
196 // Special classes for nodes
197 $classes = array('node');
198 if ($vars['sticky']) {
199 $classes[] = 'sticky';
201 if (!$vars['status']) {
202 $classes[] = 'node-unpublished';
203 $vars['unpublished'] = TRUE
;
206 $vars['unpublished'] = FALSE
;
208 if ($vars['uid'] && $vars['uid'] == $GLOBALS['user']->uid
) {
209 $classes[] = 'node-mine'; // Node is authored by current user.
211 if ($vars['teaser']) {
212 $classes[] = 'node-teaser'; // Node is displayed as teaser.
214 // Class for node type: "node-type-page", "node-type-story", "node-type-my-custom-type", etc.
215 $classes[] = zen_id_safe('node-type-' .
$vars['type']);
216 $vars['classes'] = implode(' ', $classes); // Concatenate with spaces
220 * Override or insert variables into the comment templates.
223 * An array of variables to pass to the theme template.
225 * The name of the template being rendered ("comment" in this case.)
227 function zen_preprocess_comment(&$vars, $hook) {
228 include_once
'./' .
_zen_path() .
'/template.comment.inc';
229 _zen_preprocess_comment($vars, $hook);
233 * Override or insert variables into the block templates.
236 * An array of variables to pass to the theme template.
238 * The name of the template being rendered ("block" in this case.)
240 function zen_preprocess_block(&$vars, $hook) {
241 $block = $vars['block'];
243 // Special classes for blocks.
244 $classes = array('block');
245 $classes[] = 'block-' .
$block->module
;
246 $classes[] = 'region-' .
$vars['block_zebra'];
247 $classes[] = $vars['zebra'];
248 $classes[] = 'region-count-' .
$vars['block_id'];
249 $classes[] = 'count-' .
$vars['id'];
251 $vars['edit_links_array'] = array();
252 $vars['edit_links'] = '';
253 if (theme_get_setting('zen_block_editing') && user_access('administer blocks')) {
254 include_once
'./' .
_zen_path() .
'/template.block-editing.inc';
255 zen_preprocess_block_editing($vars, $hook);
256 $classes[] = 'with-block-editing';
259 // Render block 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 return strtolower(preg_replace('/[^a-zA-Z0-9-]+/', '-', $string));
284 * Returns the path to the Zen theme.
286 * drupal_get_filename() is broken; see #341140. When that is fixed in Drupal 6,
287 * replace _zen_path() with drupal_get_path('theme', 'zen').
289 function _zen_path() {
290 static
$path = FALSE
;
292 $matches = drupal_system_listing('zen\.info$', 'themes', 'name', 0);
293 if (!empty($matches['zen']->filename
)) {
294 $path = dirname($matches['zen']->filename
);