#624818 by Aren Cambre: Tahoma shouldn't be first font pick
[project/zen.git] / template.php
CommitLineData
0c91c6b4 1<?php
8c1acf80 2// $Id$
0c91c6b4
JR
3
4/**
8c1acf80 5 * @file
0b1037f4 6 * Contains theme override functions and preprocess functions for the Zen theme.
7c5fa196 7 *
0b1037f4 8 * IMPORTANT WARNING: DO NOT MODIFY THIS FILE.
28511ba8
J
9 *
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
960bac1c
TS
14 */
15
89804871
J
16// Auto-rebuild the theme registry during theme development.
17if (theme_get_setting('zen_rebuild_registry')) {
18 drupal_rebuild_theme_registry();
19}
7c5fa196 20
719059ea 21
4f5c1d0c
J
22/**
23 * Implements HOOK_theme().
52521ba9 24 */
4f5c1d0c 25function zen_theme(&$existing, $type, $theme, $path) {
3183d194
J
26 // When #341140 is fixed, replace _zen_path() with drupal_get_path().
27 include_once './' . _zen_path() . '/zen-internals/template.theme-registry.inc';
4f5c1d0c
J
28 return _zen_theme($existing, $type, $theme, $path);
29}
52521ba9 30
7c5fa196
J
31/**
32 * Return a themed breadcrumb trail.
7081db43 33 *
7c5fa196
J
34 * @param $breadcrumb
35 * An array containing the breadcrumb links.
36 * @return
37 * A string containing the breadcrumb output.
7081db43 38 */
bdf1d868 39function zen_breadcrumb($breadcrumb) {
d60c8c02 40 // Determine if we are to display the breadcrumb.
59794464 41 $show_breadcrumb = theme_get_setting('zen_breadcrumb');
52521ba9 42 if ($show_breadcrumb == 'yes' || $show_breadcrumb == 'admin' && arg(0) == 'admin') {
59794464 43
d60c8c02 44 // Optionally get rid of the homepage link.
59794464 45 $show_breadcrumb_home = theme_get_setting('zen_breadcrumb_home');
52521ba9 46 if (!$show_breadcrumb_home) {
52521ba9
J
47 array_shift($breadcrumb);
48 }
59794464 49
d60c8c02 50 // Return the breadcrumb with separators.
52521ba9 51 if (!empty($breadcrumb)) {
59794464 52 $breadcrumb_separator = theme_get_setting('zen_breadcrumb_separator');
d60c8c02
J
53 $trailing_separator = $title = '';
54 if (theme_get_setting('zen_breadcrumb_title')) {
b6656287
J
55 if ($title = drupal_get_title()) {
56 $trailing_separator = $breadcrumb_separator;
57 }
d60c8c02
J
58 }
59 elseif (theme_get_setting('zen_breadcrumb_trailing')) {
60 $trailing_separator = $breadcrumb_separator;
61 }
62 return '<div class="breadcrumb">' . implode($breadcrumb_separator, $breadcrumb) . "$trailing_separator$title</div>";
52521ba9 63 }
7c5fa196 64 }
d60c8c02 65 // Otherwise, return an empty string.
52521ba9 66 return '';
7c5fa196
J
67}
68
4f5c1d0c
J
69/**
70 * Implements theme_menu_item_link()
71 */
72function zen_menu_item_link($link) {
73 if (empty($link['localized_options'])) {
74 $link['localized_options'] = array();
75 }
76
77 // If an item is a LOCAL TASK, render it as a tab
78 if ($link['type'] & MENU_IS_LOCAL_TASK) {
79 $link['title'] = '<span class="tab">' . check_plain($link['title']) . '</span>';
80 $link['localized_options']['html'] = TRUE;
81 }
82
83 return l($link['title'], $link['href'], $link['localized_options']);
84}
85
86/**
da899813 87 * Duplicate of theme_menu_local_tasks() but adds clearfix to tabs.
4f5c1d0c
J
88 */
89function zen_menu_local_tasks() {
90 $output = '';
91
92 if ($primary = menu_primary_local_tasks()) {
da899813 93 $output .= '<ul class="tabs primary clearfix">' . $primary . '</ul>';
4f5c1d0c
J
94 }
95 if ($secondary = menu_secondary_local_tasks()) {
da899813 96 $output .= '<ul class="tabs secondary clearfix">' . $secondary . '</ul>';
4f5c1d0c
J
97 }
98
99 return $output;
100}
960bac1c 101
94f89279
J
102/**
103 * Return a set of blocks available for the current user.
104 *
105 * @param $region
106 * Which set of blocks to retrieve.
9dfc7d9f
J
107 * @param $show_blocks
108 * A boolean to determine whether to render sidebar regions or not. Should be
109 * the same value as passed to theme_page.
94f89279
J
110 * @return
111 * A string containing the themed blocks for this region.
9dfc7d9f
J
112 *
113 * @see zen_show_blocks_discovery()
94f89279 114 */
9dfc7d9f
J
115function zen_blocks($region, $show_blocks = NULL) {
116 // Since Drupal 6 doesn't pass $show_blocks to theme_blocks, we manually call
117 // theme('blocks', NULL, $show_blocks) so that this function can remember the
118 // value on later calls.
119 static $render_sidebars = TRUE;
120 if (!is_null($show_blocks)) {
121 $render_sidebars = $show_blocks;
122 }
94f89279 123
9dfc7d9f
J
124 // If zen_blocks was called with a NULL region, its likely we were just
125 // setting the $render_sidebars static variable.
126 if ($region) {
127 $output = '';
128
129 // If $renders_sidebars is FALSE, don't render any region whose name begins
130 // with "sidebar_".
131 if (($render_sidebars || (strpos($region, 'sidebar_') !== 0)) && ($list = block_list($region))) {
132 foreach ($list as $key => $block) {
133 // $key == module_delta
134 $output .= theme('block', $block);
135 }
94f89279 136 }
94f89279 137
9dfc7d9f
J
138 // Add any content assigned to this region through drupal_set_content() calls.
139 $output .= drupal_get_content($region);
94f89279 140
9dfc7d9f
J
141 $elements['#children'] = $output;
142 $elements['#region'] = $region;
94f89279 143
9dfc7d9f
J
144 return $output ? theme('region', $elements) : '';
145 }
146}
147
148/**
149 * Examine the $show_blocks variable before template_preprocess_page() is called.
150 *
151 * @param $vars
152 * An array of variables to pass to the page template.
153 *
154 * @see zen_blocks()
155 */
156function zen_show_blocks_discovery(&$vars) {
157 if ($vars['show_blocks'] == FALSE) {
158 // Allow zen_blocks() to statically cache the $show_blocks variable. A TRUE
159 // value is assumed, so we only need to override when $show_blocks is FALSE.
160 theme('blocks', NULL, FALSE);
161 }
94f89279 162}
7c5fa196 163
960bac1c 164/**
d212bfc9
J
165 * Override or insert variables into templates before other preprocess functions have run.
166 *
167 * @param $vars
168 * An array of variables to pass to the theme template.
169 * @param $hook
170 * The name of the template being rendered.
171 */
172function zen_preprocess(&$vars, $hook) {
173 // In D6, the page.tpl uses a different variable name to hold the classes.
174 $key = ($hook == 'page' || $hook == 'maintenance_page') ? 'body_classes' : 'classes';
175
176 // Create a D7-standard classes_array variable.
177 if (array_key_exists($key, $vars)) {
17e89a6f
J
178 // Views (and possibly other modules) have templates with a $classes
179 // variable that isn't a string, so we leave those variables alone.
180 if (is_string($vars[$key])) {
181 $vars['classes_array'] = explode(' ', $vars[$key]);
182 unset($vars[$key]);
183 }
d212bfc9
J
184 }
185 else {
186 $vars['classes_array'] = array($hook);
187 }
188}
189
190/**
0b1037f4 191 * Override or insert variables into the page templates.
87695e28
J
192 *
193 * @param $vars
0b1037f4 194 * An array of variables to pass to the theme template.
e6f4a124 195 * @param $hook
0b1037f4 196 * The name of the template being rendered ("page" in this case.)
87695e28 197 */
fcf0b3cc 198function zen_preprocess_page(&$vars, $hook) {
78d8d215
J
199 // If the user is silly and enables Zen as the theme, add some styles.
200 if ($GLOBALS['theme'] == 'zen') {
3183d194 201 include_once './' . _zen_path() . '/zen-internals/template.zen.inc';
78d8d215
J
202 _zen_preprocess_page($vars, $hook);
203 }
719059ea 204 // Add conditional stylesheets.
78d8d215 205 elseif (!module_exists('conditional_styles')) {
719059ea
J
206 $vars['styles'] .= $vars['conditional_styles'] = variable_get('conditional_styles_' . $GLOBALS['theme'], '');
207 }
208
e0a8f494
J
209 // Classes for body element. Allows advanced theming based on context
210 // (home page, node of certain type, etc.)
6930eb03 211 // Remove the mostly useless page-ARG0 class.
d212bfc9
J
212 if ($index = array_search(preg_replace('![^abcdefghijklmnopqrstuvwxyz0-9-_]+!s', '', 'page-'. drupal_strtolower(arg(0))), $vars['classes_array'])) {
213 unset($vars['classes_array'][$index]);
6930eb03 214 }
e0a8f494 215 if (!$vars['is_front']) {
363d1497 216 // Add unique class for each page.
9faf4798 217 $path = drupal_get_path_alias($_GET['q']);
a20a7825 218 $vars['classes_array'][] = drupal_html_class('page-' . $path);
363d1497 219 // Add unique class for each website section.
8357c010 220 list($section, ) = explode('/', $path, 2);
28511ba8
J
221 if (arg(0) == 'node') {
222 if (arg(1) == 'add') {
363d1497 223 $section = 'node-add';
28511ba8
J
224 }
225 elseif (is_numeric(arg(1)) && (arg(2) == 'edit' || arg(2) == 'delete')) {
363d1497 226 $section = 'node-' . arg(2);
28511ba8
J
227 }
228 }
a20a7825 229 $vars['classes_array'][] = drupal_html_class('section-' . $section);
960bac1c 230 }
2041a7c1 231 if (theme_get_setting('zen_wireframes')) {
d212bfc9 232 $vars['classes_array'][] = 'with-wireframes'; // Optionally add the wireframes style.
2041a7c1 233 }
9dfc7d9f
J
234 // We need to re-do the $layout and body classes because
235 // template_preprocess_page() assumes sidebars are named 'left' and 'right'.
236 $vars['layout'] = 'none';
237 if (!empty($vars['sidebar_first'])) {
238 $vars['layout'] = 'first';
239 }
240 if (!empty($vars['sidebar_second'])) {
241 $vars['layout'] = ($vars['layout'] == 'first') ? 'both' : 'second';
242 }
243 // If the layout is 'none', then template_preprocess_page() will already have
244 // set a 'no-sidebars' class since it won't find a 'left' or 'right' sidebar.
245 if ($vars['layout'] != 'none') {
246 // Remove the incorrect 'no-sidebars' class.
247 if ($index = array_search('no-sidebars', $vars['classes_array'])) {
248 unset($vars['classes_array'][$index]);
249 }
250 // Set the proper layout body classes.
251 if ($vars['layout'] == 'both') {
252 $vars['classes_array'][] = 'two-sidebars';
253 }
254 else {
255 $vars['classes_array'][] = 'one-sidebar';
256 $vars['classes_array'][] = 'sidebar-' . $vars['layout'];
2f37f103 257 }
536678ab 258 }
e0a8f494 259}
7c5fa196 260
e0a8f494 261/**
3183d194
J
262 * Override or insert variables into the maintenance page template.
263 *
264 * @param $vars
265 * An array of variables to pass to the theme template.
266 * @param $hook
31c1fbc2 267 * The name of the template being rendered ("maintenance_page" in this case.)
3183d194
J
268 */
269function zen_preprocess_maintenance_page(&$vars, $hook) {
270 // If Zen is the maintenance theme, add some styles.
271 if ($GLOBALS['theme'] == 'zen') {
272 include_once './' . _zen_path() . '/zen-internals/template.zen.inc';
273 _zen_preprocess_page($vars, $hook);
274 }
275 // Add conditional stylesheets.
276 elseif (!module_exists('conditional_styles')) {
277 $vars['styles'] .= $vars['conditional_styles'] = variable_get('conditional_styles_' . $GLOBALS['theme'], '');
278 }
279
280 // Classes for body element. Allows advanced theming based on context
281 // (home page, node of certain type, etc.)
282 $vars['body_classes_array'] = explode(' ', $vars['body_classes']);
283}
284
285/**
0b1037f4 286 * Override or insert variables into the node templates.
e0a8f494
J
287 *
288 * @param $vars
0b1037f4 289 * An array of variables to pass to the theme template.
e6f4a124 290 * @param $hook
0b1037f4 291 * The name of the template being rendered ("node" in this case.)
e0a8f494 292 */
fcf0b3cc 293function zen_preprocess_node(&$vars, $hook) {
78362cd3
J
294 // Create the build_mode variable.
295 switch ($vars['node']->build_mode) {
296 case NODE_BUILD_NORMAL:
297 $vars['build_mode'] = $vars['teaser'] ? 'teaser' : 'full';
298 break;
299 case NODE_BUILD_PREVIEW:
300 $vars['build_mode'] = 'preview';
301 break;
302 case NODE_BUILD_SEARCH_INDEX:
303 $vars['build_mode'] = 'search_index';
304 break;
305 case NODE_BUILD_SEARCH_RESULT:
306 $vars['build_mode'] = 'search_result';
307 break;
308 case NODE_BUILD_RSS:
309 $vars['build_mode'] = 'rss';
310 break;
311 case NODE_BUILD_PRINT:
312 $vars['build_mode'] = 'print';
313 break;
314 }
315
c91ed8a5
J
316 // Create the user_picture variable.
317 $vars['user_picture'] = $vars['picture'];
318
911d5130
J
319 // Create the Drupal 7 $display_submitted variable.
320 $vars['display_submitted'] = theme_get_setting('toggle_node_info_' . $vars['node']->type);
321
78362cd3 322 // Special classes for nodes.
c91ed8a5 323 // Class for node type: "node-type-page", "node-type-story", "node-type-my-custom-type", etc.
a20a7825 324 $vars['classes_array'][] = drupal_html_class('node-type-' . $vars['type']);
d893f301
J
325 if ($vars['promote']) {
326 $vars['classes_array'][] = 'node-promoted';
c91ed8a5 327 }
e0a8f494 328 if ($vars['sticky']) {
d212bfc9 329 $vars['classes_array'][] = 'node-sticky';
e0a8f494 330 }
b457ba98 331 if (!$vars['status']) {
d212bfc9 332 $vars['classes_array'][] = 'node-unpublished';
28511ba8
J
333 $vars['unpublished'] = TRUE;
334 }
335 else {
336 $vars['unpublished'] = FALSE;
e0a8f494 337 }
b457ba98 338 if ($vars['uid'] && $vars['uid'] == $GLOBALS['user']->uid) {
e5af59a4 339 $vars['classes_array'][] = 'node-by-viewer'; // Node is authored by current user.
7c5fa196 340 }
e0a8f494 341 if ($vars['teaser']) {
d212bfc9 342 $vars['classes_array'][] = 'node-teaser'; // Node is displayed as teaser.
e0a8f494 343 }
d893f301
J
344 if (isset($vars['preview'])) {
345 $vars['classes_array'][] = 'node-preview';
c91ed8a5 346 }
e0a8f494 347}
7c5fa196 348
e0a8f494 349/**
0b1037f4 350 * Override or insert variables into the comment templates.
e0a8f494
J
351 *
352 * @param $vars
0b1037f4 353 * An array of variables to pass to the theme template.
e6f4a124 354 * @param $hook
0b1037f4 355 * The name of the template being rendered ("comment" in this case.)
e0a8f494 356 */
fcf0b3cc 357function zen_preprocess_comment(&$vars, $hook) {
3183d194 358 include_once './' . _zen_path() . '/zen-internals/template.comment.inc';
29ba6758 359 _zen_preprocess_comment($vars, $hook);
960bac1c 360}
4dd0f1bf
JR
361
362/**
94f89279
J
363 * Preprocess variables for region.tpl.php
364 *
365 * Prepare the values passed to the theme_region function to be passed into a
366 * pluggable template engine. Uses the region name to generate a template file
367 * suggestions. If none are found, the default region.tpl.php is used.
368 *
369 * @see region.tpl.php
370 */
371function zen_preprocess_region(&$vars, $hook) {
372 // Create the $content variable that templates expect.
373 $vars['content'] = $vars['elements']['#children'];
374 $vars['region'] = $vars['elements']['#region'];
375
e2e805cb
J
376 // Setup the default classes.
377 $region = 'region-' . str_replace('_', '-', $vars['region']);
378 $vars['classes_array'] = array('region', $region);
379
380 // Sidebar regions get a common template suggestion a couple extra classes.
995d309c
J
381 if (strpos($vars['region'], 'sidebar_') === 0) {
382 $vars['template_files'][] = 'region-sidebar';
e2e805cb
J
383 $vars['classes_array'][] = 'column';
384 $vars['classes_array'][] = 'sidebar';
995d309c
J
385 }
386
e2e805cb 387 // Setup the default template suggestion.
995d309c 388 $vars['template_files'][] = $region;
94f89279
J
389}
390
391/**
0b1037f4 392 * Override or insert variables into the block templates.
28511ba8
J
393 *
394 * @param $vars
0b1037f4 395 * An array of variables to pass to the theme template.
e6f4a124 396 * @param $hook
0b1037f4 397 * The name of the template being rendered ("block" in this case.)
28511ba8 398 */
fcf0b3cc 399function zen_preprocess_block(&$vars, $hook) {
28511ba8
J
400 $block = $vars['block'];
401
c531ccf0
J
402 // Drupal 7 uses a $content variable instead of $block->content.
403 $vars['content'] = $block->content;
404 // Drupal 7 should use a $title variable instead of $block->subject.
405 $vars['title'] = $block->subject;
406
76772d59 407 // Special classes for blocks.
d212bfc9
J
408 $vars['classes_array'][] = 'block-' . $block->module;
409 $vars['classes_array'][] = 'region-' . $vars['block_zebra'];
410 $vars['classes_array'][] = $vars['zebra'];
411 $vars['classes_array'][] = 'region-count-' . $vars['block_id'];
412 $vars['classes_array'][] = 'count-' . $vars['id'];
28511ba8 413
a0e81398 414 $vars['edit_links_array'] = array();
28511ba8 415 if (theme_get_setting('zen_block_editing') && user_access('administer blocks')) {
3183d194 416 include_once './' . _zen_path() . '/zen-internals/template.block-editing.inc';
a0e81398 417 zen_preprocess_block_editing($vars, $hook);
d212bfc9 418 $vars['classes_array'][] = 'with-block-editing';
28511ba8 419 }
0db41f1b
J
420}
421
422/**
423 * Override or insert variables into templates after preprocess functions have run.
424 *
425 * @param $vars
426 * An array of variables to pass to the theme template.
427 * @param $hook
428 * The name of the template being rendered.
429 */
430function zen_process(&$vars, $hook) {
17e89a6f
J
431 if (array_key_exists('classes_array', $vars)) {
432 $vars['classes'] = implode(' ', $vars['classes_array']);
433 }
28511ba8
J
434}
435
436/**
6f634acb
J
437 * Override or insert variables into the block templates after preprocess functions have run.
438 *
439 * @param $vars
440 * An array of variables to pass to the theme template.
441 * @param $hook
442 * The name of the template being rendered ("block" in this case.)
443 */
444function zen_process_block(&$vars, $hook) {
445 $vars['edit_links'] = !empty($vars['edit_links_array']) ? '<div class="edit">' . implode(' ', $vars['edit_links_array']) . '</div>' : '';
446}
447
a20a7825
J
448if (!function_exists('drupal_html_class')) {
449 /**
450 * Prepare a string for use as a valid class name.
451 *
452 * Do not pass one string containing multiple classes as they will be
453 * incorrectly concatenated with dashes, i.e. "one two" will become "one-two".
454 *
455 * @param $class
456 * The class name to clean.
457 * @return
458 * The cleaned class name.
459 */
460 function drupal_html_class($class) {
461 // By default, we filter using Drupal's coding standards.
462 $class = strtr(drupal_strtolower($class), array(' ' => '-', '_' => '-', '/' => '-', '[' => '-', ']' => ''));
463
464 // http://www.w3.org/TR/CSS21/syndata.html#characters shows the syntax for valid
465 // CSS identifiers (including element names, classes, and IDs in selectors.)
466 //
467 // Valid characters in a CSS identifier are:
468 // - the hyphen (U+002D)
469 // - a-z (U+0030 - U+0039)
470 // - A-Z (U+0041 - U+005A)
471 // - the underscore (U+005F)
472 // - 0-9 (U+0061 - U+007A)
473 // - ISO 10646 characters U+00A1 and higher
474 // We strip out any character not in the above list.
475 $class = preg_replace('/[^\x{002D}\x{0030}-\x{0039}\x{0041}-\x{005A}\x{005F}\x{0061}-\x{007A}\x{00A1}-\x{FFFF}]/u', '', $class);
476
477 return $class;
478 }
479} /* End of drupal_html_class conditional definition. */
480
481if (!function_exists('drupal_html_id')) {
482 /**
483 * Prepare a string for use as a valid HTML ID and guarantee uniqueness.
484 *
485 * @param $id
486 * The ID to clean.
487 * @return
488 * The cleaned ID.
489 */
490 function drupal_html_id($id) {
491 $id = strtr(drupal_strtolower($id), array(' ' => '-', '_' => '-', '[' => '-', ']' => ''));
492
493 // As defined in http://www.w3.org/TR/html4/types.html#type-name, HTML IDs can
494 // only contain letters, digits ([0-9]), hyphens ("-"), underscores ("_"),
495 // colons (":"), and periods ("."). We strip out any character not in that
496 // list. Note that the CSS spec doesn't allow colons or periods in identifiers
497 // (http://www.w3.org/TR/CSS21/syndata.html#characters), so we strip those two
498 // characters as well.
499 $id = preg_replace('/[^A-Za-z0-9\-_]/', '', $id);
500
501 return $id;
502 }
503} /* End of drupal_html_id conditional definition. */
3183d194
J
504
505/**
506 * Returns the path to the Zen theme.
507 *
508 * drupal_get_filename() is broken; see #341140. When that is fixed in Drupal 6,
509 * replace _zen_path() with drupal_get_path('theme', 'zen').
510 */
511function _zen_path() {
512 static $path = FALSE;
513 if (!$path) {
514 $matches = drupal_system_listing('zen\.info$', 'themes', 'name', 0);
515 if (!empty($matches['zen']->filename)) {
516 $path = dirname($matches['zen']->filename);
517 }
518 }
519 return $path;
520}