Changed $node_classes to $classes.
[project/zen.git] / zen / 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
7c5fa196 16
719059ea
J
17/*
18 * Add stylesheets only needed when Zen is the active theme. Don't do something
19 * this dumb in your sub-theme; see how wireframes.css is handled instead.
20 */
21if ($GLOBALS['theme'] == 'zen') { // If we're in the main theme
22 if (theme_get_setting('zen_layout') == 'border-politics-fixed') {
23 drupal_add_css(drupal_get_path('theme', 'zen') . '/layout-fixed.css', 'theme', 'all');
24 }
25 else {
26 drupal_add_css(drupal_get_path('theme', 'zen') . '/layout-liquid.css', 'theme', 'all');
27 }
28}
29
30
4f5c1d0c
J
31/**
32 * Implements HOOK_theme().
52521ba9 33 */
4f5c1d0c 34function zen_theme(&$existing, $type, $theme, $path) {
09d52536 35 include_once './' . drupal_get_path('theme', 'zen') . '/template.theme-registry.inc';
4f5c1d0c
J
36 return _zen_theme($existing, $type, $theme, $path);
37}
52521ba9 38
7c5fa196
J
39/**
40 * Return a themed breadcrumb trail.
7081db43 41 *
7c5fa196
J
42 * @param $breadcrumb
43 * An array containing the breadcrumb links.
44 * @return
45 * A string containing the breadcrumb output.
7081db43 46 */
bdf1d868 47function zen_breadcrumb($breadcrumb) {
52521ba9 48 // Determine if we are to display the breadcrumb
59794464 49 $show_breadcrumb = theme_get_setting('zen_breadcrumb');
52521ba9 50 if ($show_breadcrumb == 'yes' || $show_breadcrumb == 'admin' && arg(0) == 'admin') {
59794464
J
51
52 // Optionally get rid of the homepage link
53 $show_breadcrumb_home = theme_get_setting('zen_breadcrumb_home');
52521ba9 54 if (!$show_breadcrumb_home) {
52521ba9
J
55 array_shift($breadcrumb);
56 }
59794464
J
57
58 // Return the breadcrumb with separators
52521ba9 59 if (!empty($breadcrumb)) {
59794464
J
60 $breadcrumb_separator = theme_get_setting('zen_breadcrumb_separator');
61 $trailing_separator = (theme_get_setting('zen_breadcrumb_trailing') || theme_get_setting('zen_breadcrumb_title')) ? $breadcrumb_separator : '';
adc5ab38 62 return '<div class="breadcrumb">' . implode($breadcrumb_separator, $breadcrumb) . "$trailing_separator</div>";
52521ba9 63 }
7c5fa196 64 }
52521ba9
J
65 // Otherwise, return an empty string
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/**
87 * Duplicate of theme_menu_local_tasks() but adds clear-block to tabs.
88 */
89function zen_menu_local_tasks() {
90 $output = '';
91
92 if ($primary = menu_primary_local_tasks()) {
93 $output .= '<ul class="tabs primary clear-block">' . $primary . '</ul>';
94 }
95 if ($secondary = menu_secondary_local_tasks()) {
96 $output .= '<ul class="tabs secondary clear-block">' . $secondary . '</ul>';
97 }
98
99 return $output;
100}
960bac1c 101
7c5fa196 102
960bac1c 103/**
0b1037f4 104 * Override or insert variables into the page templates.
87695e28
J
105 *
106 * @param $vars
0b1037f4 107 * An array of variables to pass to the theme template.
e6f4a124 108 * @param $hook
0b1037f4 109 * The name of the template being rendered ("page" in this case.)
87695e28 110 */
fcf0b3cc 111function zen_preprocess_page(&$vars, $hook) {
47a99cfa
J
112 // Add an optional title to the end of the breadcrumb.
113 if (theme_get_setting('zen_breadcrumb_title') && $vars['breadcrumb']) {
adc5ab38 114 $vars['breadcrumb'] = substr($vars['breadcrumb'], 0, -6) . $vars['title'] . '</div>';
47a99cfa
J
115 }
116
28511ba8
J
117 // Don't display empty help from node_help().
118 if ($vars['help'] == "<div class=\"help\"><p></p>\n</div>") {
119 $vars['help'] = '';
120 }
e0a8f494 121
719059ea
J
122 // Add conditional stylesheets.
123 if (!module_exists('conditional_styles')) {
124 $vars['styles'] .= $vars['conditional_styles'] = variable_get('conditional_styles_' . $GLOBALS['theme'], '');
125 }
126
e0a8f494
J
127 // Classes for body element. Allows advanced theming based on context
128 // (home page, node of certain type, etc.)
129 $body_classes = array($vars['body_classes']);
130 if (!$vars['is_front']) {
131 // Add unique classes for each page and website section
9faf4798 132 $path = drupal_get_path_alias($_GET['q']);
8357c010 133 list($section, ) = explode('/', $path, 2);
adc5ab38
J
134 $body_classes[] = zen_id_safe('page-' . $path);
135 $body_classes[] = zen_id_safe('section-' . $section);
28511ba8
J
136 if (arg(0) == 'node') {
137 if (arg(1) == 'add') {
138 if ($section == 'node') {
139 array_pop($body_classes); // Remove 'section-node'
140 }
141 $body_classes[] = 'section-node-add'; // Add 'section-node-add'
142 }
143 elseif (is_numeric(arg(1)) && (arg(2) == 'edit' || arg(2) == 'delete')) {
144 if ($section == 'node') {
145 array_pop($body_classes); // Remove 'section-node'
146 }
adc5ab38 147 $body_classes[] = 'section-node-' . arg(2); // Add 'section-node-edit' or 'section-node-delete'
28511ba8
J
148 }
149 }
960bac1c 150 }
2041a7c1
J
151 if (theme_get_setting('zen_wireframes')) {
152 $body_classes[] = 'with-wireframes'; // Optionally add the wireframes style.
153 }
28511ba8 154 $vars['body_classes'] = implode(' ', $body_classes); // Concatenate with spaces
e0a8f494 155}
7c5fa196 156
e0a8f494 157/**
0b1037f4 158 * Override or insert variables into the node templates.
e0a8f494
J
159 *
160 * @param $vars
0b1037f4 161 * An array of variables to pass to the theme template.
e6f4a124 162 * @param $hook
0b1037f4 163 * The name of the template being rendered ("node" in this case.)
e0a8f494 164 */
fcf0b3cc 165function zen_preprocess_node(&$vars, $hook) {
e0a8f494 166 // Special classes for nodes
23086957 167 $classes = array('node');
e0a8f494 168 if ($vars['sticky']) {
23086957 169 $classes[] = 'sticky';
e0a8f494
J
170 }
171 if (!$vars['node']->status) {
23086957 172 $classes[] = 'node-unpublished';
28511ba8
J
173 $vars['unpublished'] = TRUE;
174 }
175 else {
176 $vars['unpublished'] = FALSE;
e0a8f494 177 }
23086957 178 if ($vars['node']->uid && $vars['node']->uid == $GLOBALS['user']->uid) {
e0a8f494 179 // Node is authored by current user
23086957 180 $classes[] = 'node-mine';
7c5fa196 181 }
e0a8f494
J
182 if ($vars['teaser']) {
183 // Node is displayed as teaser
23086957 184 $classes[] = 'node-teaser';
e0a8f494
J
185 }
186 // Class for node type: "node-type-page", "node-type-story", "node-type-my-custom-type", etc.
23086957
J
187 $classes[] = 'node-type-' . $vars['node']->type;
188 $vars['classes'] = implode(' ', $classes); // Concatenate with spaces
e0a8f494 189}
7c5fa196 190
e0a8f494 191/**
0b1037f4 192 * Override or insert variables into the comment templates.
e0a8f494
J
193 *
194 * @param $vars
0b1037f4 195 * An array of variables to pass to the theme template.
e6f4a124 196 * @param $hook
0b1037f4 197 * The name of the template being rendered ("comment" in this case.)
e0a8f494 198 */
fcf0b3cc 199function zen_preprocess_comment(&$vars, $hook) {
29ba6758
J
200 include_once './' . drupal_get_path('theme', 'zen') . '/template.comment.inc';
201 _zen_preprocess_comment($vars, $hook);
960bac1c 202}
4dd0f1bf
JR
203
204/**
0b1037f4 205 * Override or insert variables into the block templates.
28511ba8
J
206 *
207 * @param $vars
0b1037f4 208 * An array of variables to pass to the theme template.
e6f4a124 209 * @param $hook
0b1037f4 210 * The name of the template being rendered ("block" in this case.)
28511ba8 211 */
fcf0b3cc 212function zen_preprocess_block(&$vars, $hook) {
28511ba8
J
213 $block = $vars['block'];
214
76772d59 215 // Special classes for blocks.
0bcb1dd5
J
216 $classes = array('block');
217 $classes[] = 'block-' . $block->module;
218 $classes[] = 'region-' . $vars['block_zebra'];
219 $classes[] = $vars['zebra'];
220 $classes[] = 'region-count-' . $vars['block_id'];
221 $classes[] = 'count-' . $vars['id'];
28511ba8 222
a0e81398 223 $vars['edit_links_array'] = array();
56ba2845 224 $vars['edit_links'] = '';
28511ba8 225 if (theme_get_setting('zen_block_editing') && user_access('administer blocks')) {
a0e81398
J
226 include_once './' . drupal_get_path('theme', 'zen') . '/template.block-editing.inc';
227 zen_preprocess_block_editing($vars, $hook);
9c9b5bbc 228 $classes[] = 'with-block-editing';
28511ba8 229 }
9c9b5bbc
J
230
231 // Render block classes.
232 $vars['classes'] = implode(' ', $classes);
28511ba8
J
233}
234
235/**
7c5fa196
J
236 * Converts a string to a suitable html ID attribute.
237 *
2bf29305
J
238 * http://www.w3.org/TR/html4/struct/global.html#h-7.5.2 specifies what makes a
239 * valid ID attribute in HTML. This function:
240 *
4f5c1d0c 241 * - Ensure an ID starts with an alpha character by optionally adding an 'id'.
28511ba8 242 * - Replaces any character except A-Z, numbers, and underscores with dashes.
7c5fa196 243 * - Converts entire string to lowercase.
7c5fa196 244 *
28511ba8 245 * @param $string
7c5fa196
J
246 * The string
247 * @return
248 * The converted string
249 */
4dd0f1bf 250function zen_id_safe($string) {
2bf29305
J
251 // Replace with dashes anything that isn't A-Z, numbers, dashes, or underscores.
252 $string = strtolower(preg_replace('/[^a-zA-Z0-9_-]+/', '-', $string));
253 // If the first character is not a-z, add 'n' in front.
254 if (!ctype_lower($string{0})) { // Don't use ctype_alpha since its locale aware.
255 $string = 'id' . $string;
4dd0f1bf 256 }
2bf29305 257 return $string;
7c5fa196 258}