Changed $node_classes to $classes.
[project/zen.git] / zen / 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
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 */
21 if ($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
31 /**
32 * Implements HOOK_theme().
33 */
34 function zen_theme(&$existing, $type, $theme, $path) {
35 include_once './' . drupal_get_path('theme', 'zen') . '/template.theme-registry.inc';
36 return _zen_theme($existing, $type, $theme, $path);
37 }
38
39 /**
40 * Return a themed breadcrumb trail.
41 *
42 * @param $breadcrumb
43 * An array containing the breadcrumb links.
44 * @return
45 * A string containing the breadcrumb output.
46 */
47 function zen_breadcrumb($breadcrumb) {
48 // Determine if we are to display the breadcrumb
49 $show_breadcrumb = theme_get_setting('zen_breadcrumb');
50 if ($show_breadcrumb == 'yes' || $show_breadcrumb == 'admin' && arg(0) == 'admin') {
51
52 // Optionally get rid of the homepage link
53 $show_breadcrumb_home = theme_get_setting('zen_breadcrumb_home');
54 if (!$show_breadcrumb_home) {
55 array_shift($breadcrumb);
56 }
57
58 // Return the breadcrumb with separators
59 if (!empty($breadcrumb)) {
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 : '';
62 return '<div class="breadcrumb">' . implode($breadcrumb_separator, $breadcrumb) . "$trailing_separator</div>";
63 }
64 }
65 // Otherwise, return an empty string
66 return '';
67 }
68
69 /**
70 * Implements theme_menu_item_link()
71 */
72 function 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 */
89 function 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 }
101
102
103 /**
104 * Override or insert variables into the page templates.
105 *
106 * @param $vars
107 * An array of variables to pass to the theme template.
108 * @param $hook
109 * The name of the template being rendered ("page" in this case.)
110 */
111 function zen_preprocess_page(&$vars, $hook) {
112 // Add an optional title to the end of the breadcrumb.
113 if (theme_get_setting('zen_breadcrumb_title') && $vars['breadcrumb']) {
114 $vars['breadcrumb'] = substr($vars['breadcrumb'], 0, -6) . $vars['title'] . '</div>';
115 }
116
117 // Don't display empty help from node_help().
118 if ($vars['help'] == "<div class=\"help\"><p></p>\n</div>") {
119 $vars['help'] = '';
120 }
121
122 // Add conditional stylesheets.
123 if (!module_exists('conditional_styles')) {
124 $vars['styles'] .= $vars['conditional_styles'] = variable_get('conditional_styles_' . $GLOBALS['theme'], '');
125 }
126
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
132 $path = drupal_get_path_alias($_GET['q']);
133 list($section, ) = explode('/', $path, 2);
134 $body_classes[] = zen_id_safe('page-' . $path);
135 $body_classes[] = zen_id_safe('section-' . $section);
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 }
147 $body_classes[] = 'section-node-' . arg(2); // Add 'section-node-edit' or 'section-node-delete'
148 }
149 }
150 }
151 if (theme_get_setting('zen_wireframes')) {
152 $body_classes[] = 'with-wireframes'; // Optionally add the wireframes style.
153 }
154 $vars['body_classes'] = implode(' ', $body_classes); // Concatenate with spaces
155 }
156
157 /**
158 * Override or insert variables into the node templates.
159 *
160 * @param $vars
161 * An array of variables to pass to the theme template.
162 * @param $hook
163 * The name of the template being rendered ("node" in this case.)
164 */
165 function zen_preprocess_node(&$vars, $hook) {
166 // Special classes for nodes
167 $classes = array('node');
168 if ($vars['sticky']) {
169 $classes[] = 'sticky';
170 }
171 if (!$vars['node']->status) {
172 $classes[] = 'node-unpublished';
173 $vars['unpublished'] = TRUE;
174 }
175 else {
176 $vars['unpublished'] = FALSE;
177 }
178 if ($vars['node']->uid && $vars['node']->uid == $GLOBALS['user']->uid) {
179 // Node is authored by current user
180 $classes[] = 'node-mine';
181 }
182 if ($vars['teaser']) {
183 // Node is displayed as teaser
184 $classes[] = 'node-teaser';
185 }
186 // Class for node type: "node-type-page", "node-type-story", "node-type-my-custom-type", etc.
187 $classes[] = 'node-type-' . $vars['node']->type;
188 $vars['classes'] = implode(' ', $classes); // Concatenate with spaces
189 }
190
191 /**
192 * Override or insert variables into the comment templates.
193 *
194 * @param $vars
195 * An array of variables to pass to the theme template.
196 * @param $hook
197 * The name of the template being rendered ("comment" in this case.)
198 */
199 function zen_preprocess_comment(&$vars, $hook) {
200 include_once './' . drupal_get_path('theme', 'zen') . '/template.comment.inc';
201 _zen_preprocess_comment($vars, $hook);
202 }
203
204 /**
205 * Override or insert variables into the block templates.
206 *
207 * @param $vars
208 * An array of variables to pass to the theme template.
209 * @param $hook
210 * The name of the template being rendered ("block" in this case.)
211 */
212 function zen_preprocess_block(&$vars, $hook) {
213 $block = $vars['block'];
214
215 // Special classes for blocks.
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'];
222
223 $vars['edit_links_array'] = array();
224 $vars['edit_links'] = '';
225 if (theme_get_setting('zen_block_editing') && user_access('administer blocks')) {
226 include_once './' . drupal_get_path('theme', 'zen') . '/template.block-editing.inc';
227 zen_preprocess_block_editing($vars, $hook);
228 $classes[] = 'with-block-editing';
229 }
230
231 // Render block classes.
232 $vars['classes'] = implode(' ', $classes);
233 }
234
235 /**
236 * Converts a string to a suitable html ID attribute.
237 *
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 *
241 * - Ensure an ID starts with an alpha character by optionally adding an 'id'.
242 * - Replaces any character except A-Z, numbers, and underscores with dashes.
243 * - Converts entire string to lowercase.
244 *
245 * @param $string
246 * The string
247 * @return
248 * The converted string
249 */
250 function zen_id_safe($string) {
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;
256 }
257 return $string;
258 }