Fix tabs by implementing zen_preprocess_menu_local_task().
[project/zen.git] / template.php
1 <?php
2 // $Id$
3
4 /**
5 * @file
6 * Contains theme override functions and preprocess functions for the Zen theme.
7 *
8 * IMPORTANT WARNING: DO NOT MODIFY THIS FILE.
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
14 */
15
16 // Auto-rebuild the theme registry during theme development.
17 if (theme_get_setting('zen_rebuild_registry')) {
18 system_rebuild_theme_data();
19 }
20
21
22 /**
23 * Implements HOOK_theme().
24 */
25 function zen_theme(&$existing, $type, $theme, $path) {
26 include_once './' . drupal_get_path('theme', 'zen') . '/zen-internals/template.theme-registry.inc';
27 return _zen_theme($existing, $type, $theme, $path);
28 }
29
30 /**
31 * Return a themed breadcrumb trail.
32 *
33 * @param $breadcrumb
34 * An array containing the breadcrumb links.
35 * @return
36 * A string containing the breadcrumb output.
37 */
38 function zen_breadcrumb($variables) {
39 $breadcrumb = $variables['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') {
43
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);
48 }
49
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 if ($title = drupal_get_title()) {
56 $trailing_separator = $breadcrumb_separator;
57 }
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>";
63 }
64 }
65 // Otherwise, return an empty string.
66 return '';
67 }
68
69 /**
70 * Duplicate of theme_menu_local_tasks() but adds clearfix to tabs.
71 */
72 function zen_menu_local_tasks() {
73 $output = array();
74
75 if ($primary = menu_primary_local_tasks()) {
76 $primary['#prefix'] = '<ul class="tabs primary clearfix">';
77 $primary['#suffix'] = '</ul>';
78 $output[] = $primary;
79 }
80 if ($secondary = menu_secondary_local_tasks()) {
81 $secondary['#prefix'] = '<ul class="tabs secondary clearfix">';
82 $secondary['#suffix'] = '</ul>';
83 $output[] = $secondary;
84 }
85
86 return $output;
87 }
88
89 /**
90 * Override or insert variables into theme_menu_local_task().
91 */
92 function zen_preprocess_menu_local_task(&$variables) {
93 $link =& $variables['element']['#link'];
94
95 // If the link does not contain HTML already, check_plain() it now.
96 // After we set 'html'=TRUE the link will not be sanitized by l().
97 if (empty($link['localized_options']['html'])) {
98 $link['title'] = check_plain($link['title']);
99 }
100 $link['localized_options']['html'] = TRUE;
101 $link['title'] = '<span class="tab">' . $link['title'] . '</span>';
102 }
103
104 /**
105 * Override or insert variables into the html template.
106 *
107 * @param $vars
108 * An array of variables to pass to the theme template.
109 * @param $hook
110 * The name of the template being rendered ("html" in this case.)
111 */
112 function zen_preprocess_html(&$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_html($vars, $hook);
117 }
118
119 // Classes for body element. Allows advanced theming based on context
120 // (home page, node of certain type, etc.)
121 if (!$vars['is_front']) {
122 // Add unique class for each page.
123 $path = drupal_get_path_alias($_GET['q']);
124 // Add unique class for each website section.
125 list($section, ) = explode('/', $path, 2);
126 if (arg(0) == 'node') {
127 if (arg(1) == 'add') {
128 $section = 'node-add';
129 }
130 elseif (is_numeric(arg(1)) && (arg(2) == 'edit' || arg(2) == 'delete')) {
131 $section = 'node-' . arg(2);
132 }
133 }
134 $vars['classes_array'][] = drupal_html_class('section-' . $section);
135 }
136 if (theme_get_setting('zen_wireframes')) {
137 $vars['classes_array'][] = 'with-wireframes'; // Optionally add the wireframes style.
138 }
139 }
140
141 /**
142 * Override or insert variables into the html template.
143 *
144 * @param $vars
145 * An array of variables to pass to the theme template.
146 * @param $hook
147 * The name of the template being rendered ("html" in this case.)
148 */
149 function zen_process_html(&$vars, $hook) {
150 // Add conditional stylesheets.
151 if ($GLOBALS['theme'] == 'zen') {
152 _zen_process_html($vars, $hook);
153 }
154 elseif (!module_exists('conditional_styles')) {
155 $vars['styles'] .= $vars['conditional_styles'] = variable_get('conditional_styles_' . $GLOBALS['theme'], '');
156 }
157 }
158
159 /**
160 * Override or insert variables into the maintenance page template.
161 *
162 * @param $vars
163 * An array of variables to pass to the theme template.
164 * @param $hook
165 * The name of the template being rendered ("maintenance_page" in this case.)
166 */
167 function zen_preprocess_maintenance_page(&$vars, $hook) {
168 // If Zen is the maintenance theme, add some styles.
169 if ($GLOBALS['theme'] == 'zen') {
170 include_once './' . drupal_get_path('theme', 'zen') . '/zen-internals/template.zen.inc';
171 _zen_preprocess_html($vars, $hook);
172 }
173 // Add conditional stylesheets.
174 elseif (!module_exists('conditional_styles')) {
175 $vars['styles'] .= $vars['conditional_styles'] = variable_get('conditional_styles_' . $GLOBALS['theme'], '');
176 }
177
178 // Classes for body element. Allows advanced theming based on context
179 // (home page, node of certain type, etc.)
180 $vars['body_classes_array'] = explode(' ', $vars['body_classes']);
181 }
182
183 /**
184 * Override or insert variables into the node templates.
185 *
186 * @param $vars
187 * An array of variables to pass to the theme template.
188 * @param $hook
189 * The name of the template being rendered ("node" in this case.)
190 */
191 function zen_preprocess_node(&$vars, $hook) {
192 // $node_title is idiotic.
193 $vars['title'] = $vars['node_title'];
194
195 // Special classes for nodes.
196 // Class for node type: "node-type-page", "node-type-story", "node-type-my-custom-type", etc.
197 $vars['classes_array'][] = drupal_html_class('node-type-' . $vars['type']);
198 if ($vars['promote']) {
199 $vars['classes_array'][] = 'node-promoted';
200 }
201 if ($vars['sticky']) {
202 $vars['classes_array'][] = 'node-sticky';
203 }
204 if (!$vars['status']) {
205 $vars['classes_array'][] = 'node-unpublished';
206 $vars['unpublished'] = TRUE;
207 }
208 else {
209 $vars['unpublished'] = FALSE;
210 }
211 if ($vars['uid'] && $vars['uid'] == $GLOBALS['user']->uid) {
212 $vars['classes_array'][] = 'node-by-viewer'; // Node is authored by current user.
213 }
214 if ($vars['teaser']) {
215 $vars['classes_array'][] = 'node-teaser'; // Node is displayed as teaser.
216 }
217 if (isset($vars['preview'])) {
218 $vars['classes_array'][] = 'node-preview';
219 }
220 }
221
222 /**
223 * Override or insert variables into the comment templates.
224 *
225 * @param $vars
226 * An array of variables to pass to the theme template.
227 * @param $hook
228 * The name of the template being rendered ("comment" in this case.)
229 */
230 function zen_preprocess_comment(&$vars, $hook) {
231 include_once './' . drupal_get_path('theme', 'zen') . '/zen-internals/template.comment.inc';
232 _zen_preprocess_comment($vars, $hook);
233 }
234
235 /**
236 * Preprocess variables for region.tpl.php
237 *
238 * Prepare the values passed to the theme_region function to be passed into a
239 * pluggable template engine. Uses the region name to generate a template file
240 * suggestions. If none are found, the default region.tpl.php is used.
241 *
242 * @see region.tpl.php
243 */
244 function zen_preprocess_region(&$vars, $hook) {
245 // Sidebar regions get a common template suggestion a couple extra classes.
246 if (strpos($vars['region'], 'sidebar_') === 0) {
247 $vars['template_files'][] = 'region-sidebar';
248 $vars['classes_array'][] = 'column';
249 $vars['classes_array'][] = 'sidebar';
250 }
251 }
252
253 /**
254 * Override or insert variables into the block templates.
255 *
256 * @param $vars
257 * An array of variables to pass to the theme template.
258 * @param $hook
259 * The name of the template being rendered ("block" in this case.)
260 */
261 function zen_preprocess_block(&$vars, $hook) {
262 $block = $vars['block'];
263
264 // Drupal 7 should use a $title variable instead of $block->subject.
265 $vars['title'] = $block->subject;
266
267 // Special classes for blocks.
268 $vars['classes_array'][] = 'block-' . $block->module;
269 $vars['classes_array'][] = 'region-' . $vars['block_zebra'];
270 $vars['classes_array'][] = $vars['zebra'];
271 $vars['classes_array'][] = 'region-count-' . $vars['block_id'];
272 $vars['classes_array'][] = 'count-' . $vars['id'];
273 }