| Commit | Line | Data |
|---|---|---|
| 0c91c6b4 | 1 | <?php |
| 0c91c6b4 | 2 | /** |
| 8c1acf80 | 3 | * @file |
| 0b1037f4 | 4 | * Contains theme override functions and preprocess functions for the Zen theme. |
| 7c5fa196 | 5 | * |
| 0b1037f4 | 6 | * IMPORTANT WARNING: DO NOT MODIFY THIS FILE. |
| 28511ba8 J |
7 | * |
| 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 | |
| 960bac1c TS |
12 | */ |
| 13 | ||
| 89804871 J |
14 | // Auto-rebuild the theme registry during theme development. |
| 15 | if (theme_get_setting('zen_rebuild_registry')) { | |
| 16 | drupal_rebuild_theme_registry(); | |
| 17 | } | |
| 7c5fa196 | 18 | |
| 719059ea | 19 | |
| 4f5c1d0c J |
20 | /** |
| 21 | * Implements HOOK_theme(). | |
| 52521ba9 | 22 | */ |
| 4f5c1d0c | 23 | function zen_theme(&$existing, $type, $theme, $path) { |
| 3183d194 J |
24 | // When #341140 is fixed, replace _zen_path() with drupal_get_path(). |
| 25 | include_once './' . _zen_path() . '/zen-internals/template.theme-registry.inc'; | |
| 4f5c1d0c J |
26 | return _zen_theme($existing, $type, $theme, $path); |
| 27 | } | |
| 52521ba9 | 28 | |
| 7c5fa196 J |
29 | /** |
| 30 | * Return a themed breadcrumb trail. | |
| 7081db43 | 31 | * |
| 7c5fa196 J |
32 | * @param $breadcrumb |
| 33 | * An array containing the breadcrumb links. | |
| 34 | * @return | |
| 35 | * A string containing the breadcrumb output. | |
| 7081db43 | 36 | */ |
| bdf1d868 | 37 | function zen_breadcrumb($breadcrumb) { |
| d60c8c02 | 38 | // Determine if we are to display the breadcrumb. |
| 59794464 | 39 | $show_breadcrumb = theme_get_setting('zen_breadcrumb'); |
| 52521ba9 | 40 | if ($show_breadcrumb == 'yes' || $show_breadcrumb == 'admin' && arg(0) == 'admin') { |
| 59794464 | 41 | |
| d60c8c02 | 42 | // Optionally get rid of the homepage link. |
| 59794464 | 43 | $show_breadcrumb_home = theme_get_setting('zen_breadcrumb_home'); |
| 52521ba9 | 44 | if (!$show_breadcrumb_home) { |
| 52521ba9 J |
45 | array_shift($breadcrumb); |
| 46 | } | |
| 59794464 | 47 | |
| d60c8c02 | 48 | // Return the breadcrumb with separators. |
| 52521ba9 | 49 | if (!empty($breadcrumb)) { |
| 59794464 | 50 | $breadcrumb_separator = theme_get_setting('zen_breadcrumb_separator'); |
| d60c8c02 J |
51 | $trailing_separator = $title = ''; |
| 52 | if (theme_get_setting('zen_breadcrumb_title')) { | |
| b6656287 J |
53 | if ($title = drupal_get_title()) { |
| 54 | $trailing_separator = $breadcrumb_separator; | |
| 55 | } | |
| d60c8c02 J |
56 | } |
| 57 | elseif (theme_get_setting('zen_breadcrumb_trailing')) { | |
| 58 | $trailing_separator = $breadcrumb_separator; | |
| 59 | } | |
| 60 | return '<div class="breadcrumb">' . implode($breadcrumb_separator, $breadcrumb) . "$trailing_separator$title</div>"; | |
| 52521ba9 | 61 | } |
| 7c5fa196 | 62 | } |
| d60c8c02 | 63 | // Otherwise, return an empty string. |
| 52521ba9 | 64 | return ''; |
| 7c5fa196 J |
65 | } |
| 66 | ||
| 4f5c1d0c | 67 | /** |
| 673abbb2 J |
68 | * Return a themed set of links. |
| 69 | * | |
| 70 | * @param $links | |
| 71 | * A keyed array of links to be themed. | |
| 72 | * @param $attributes | |
| 73 | * A keyed array of attributes | |
| 74 | * @param $heading | |
| 75 | * An optional keyed array or a string for a heading to precede the links. | |
| 76 | * When using an array the following keys can be used: | |
| 77 | * - text: the heading text | |
| 78 | * - level: the heading level (e.g. 'h2', 'h3') | |
| 79 | * - class: (optional) a string of the CSS classes for the heading | |
| 80 | * When using a string it will be used as the text of the heading and the | |
| 81 | * level will default to 'h2'. | |
| 82 | * Headings should be used on navigation menus and any list of links that | |
| 83 | * consistently appears on multiple pages. To make the heading invisible | |
| 84 | * use the 'element-invisible' CSS class. Do not use 'display:none', which | |
| 85 | * removes it from screen-readers and assistive technology. Headings allow | |
| 86 | * screen-reader and keyboard only users to navigate to or skip the links. | |
| 87 | * See http://juicystudio.com/article/screen-readers-display-none.php | |
| 88 | * and http://www.w3.org/TR/WCAG-TECHS/H42.html for more information. | |
| 89 | * @return | |
| 90 | * A string containing an unordered list of links. | |
| 91 | */ | |
| 92 | function zen_links($links, $attributes = array('class' => 'links'), $heading = '') { | |
| 93 | global $language; | |
| 94 | $output = ''; | |
| 95 | ||
| 96 | if (count($links) > 0) { | |
| 97 | // Treat the heading first if it is present to prepend it to the | |
| 98 | // list of links. | |
| 99 | if (!empty($heading)) { | |
| 100 | if (is_string($heading)) { | |
| 101 | // Prepare the array that will be used when the passed heading | |
| 102 | // is a string. | |
| 103 | $heading = array( | |
| 104 | 'text' => $heading, | |
| 105 | // Set the default level of the heading. | |
| 106 | 'level' => 'h2', | |
| 107 | ); | |
| 108 | } | |
| 109 | $output .= '<' . $heading['level']; | |
| 110 | if (!empty($heading['class'])) { | |
| 111 | $output .= drupal_attributes(array('class' => $heading['class'])); | |
| 112 | } | |
| 113 | $output .= '>' . check_plain($heading['text']) . '</' . $heading['level'] . '>'; | |
| 114 | } | |
| 115 | ||
| 116 | $output .= '<ul'. drupal_attributes($attributes) .'>'; | |
| 117 | ||
| 118 | $num_links = count($links); | |
| 119 | $i = 1; | |
| 120 | ||
| 121 | foreach ($links as $key => $link) { | |
| 122 | $class = $key; | |
| 123 | ||
| 124 | // Add first, last and active classes to the list of links to help out themers. | |
| 125 | if ($i == 1) { | |
| 126 | $class .= ' first'; | |
| 127 | } | |
| 128 | if ($i == $num_links) { | |
| 129 | $class .= ' last'; | |
| 130 | } | |
| 131 | if (isset($link['href']) && ($link['href'] == $_GET['q'] || ($link['href'] == '<front>' && drupal_is_front_page())) | |
| 132 | && (empty($link['language']) || $link['language']->language == $language->language)) { | |
| 133 | $class .= ' active'; | |
| 134 | } | |
| 135 | $output .= '<li'. drupal_attributes(array('class' => $class)) .'>'; | |
| 136 | ||
| 137 | if (isset($link['href'])) { | |
| 138 | // Pass in $link as $options, they share the same keys. | |
| 139 | $output .= l($link['title'], $link['href'], $link); | |
| 140 | } | |
| 141 | else if (!empty($link['title'])) { | |
| 142 | // Some links are actually not links, but we wrap these in <span> for adding title and class attributes | |
| 143 | if (empty($link['html'])) { | |
| 144 | $link['title'] = check_plain($link['title']); | |
| 145 | } | |
| 146 | $span_attributes = ''; | |
| 147 | if (isset($link['attributes'])) { | |
| 148 | $span_attributes = drupal_attributes($link['attributes']); | |
| 149 | } | |
| 150 | $output .= '<span'. $span_attributes .'>'. $link['title'] .'</span>'; | |
| 151 | } | |
| 152 | ||
| 153 | $i++; | |
| 154 | $output .= "</li>\n"; | |
| 155 | } | |
| 156 | ||
| 157 | $output .= '</ul>'; | |
| 158 | } | |
| 159 | ||
| 160 | return $output; | |
| 161 | } | |
| 162 | ||
| 163 | /** | |
| 4f5c1d0c J |
164 | * Implements theme_menu_item_link() |
| 165 | */ | |
| 166 | function zen_menu_item_link($link) { | |
| 167 | if (empty($link['localized_options'])) { | |
| 168 | $link['localized_options'] = array(); | |
| 169 | } | |
| 170 | ||
| 171 | // If an item is a LOCAL TASK, render it as a tab | |
| 172 | if ($link['type'] & MENU_IS_LOCAL_TASK) { | |
| 173 | $link['title'] = '<span class="tab">' . check_plain($link['title']) . '</span>'; | |
| 174 | $link['localized_options']['html'] = TRUE; | |
| 175 | } | |
| 176 | ||
| 177 | return l($link['title'], $link['href'], $link['localized_options']); | |
| 178 | } | |
| 179 | ||
| 180 | /** | |
| da899813 | 181 | * Duplicate of theme_menu_local_tasks() but adds clearfix to tabs. |
| 4f5c1d0c J |
182 | */ |
| 183 | function zen_menu_local_tasks() { | |
| 184 | $output = ''; | |
| 185 | ||
| 8206f826 J |
186 | // CTools requires a different set of local task functions. |
| 187 | if (module_exists('ctools')) { | |
| d313689a | 188 | ctools_include('menu'); |
| 8206f826 J |
189 | $primary = ctools_menu_primary_local_tasks(); |
| 190 | $secondary = ctools_menu_secondary_local_tasks(); | |
| 191 | } | |
| 192 | else { | |
| 193 | $primary = menu_primary_local_tasks(); | |
| 194 | $secondary = menu_secondary_local_tasks(); | |
| 195 | } | |
| 196 | ||
| 197 | if ($primary) { | |
| da899813 | 198 | $output .= '<ul class="tabs primary clearfix">' . $primary . '</ul>'; |
| 4f5c1d0c | 199 | } |
| 8206f826 | 200 | if ($secondary) { |
| da899813 | 201 | $output .= '<ul class="tabs secondary clearfix">' . $secondary . '</ul>'; |
| 4f5c1d0c J |
202 | } |
| 203 | ||
| 204 | return $output; | |
| 205 | } | |
| 960bac1c | 206 | |
| 94f89279 J |
207 | /** |
| 208 | * Return a set of blocks available for the current user. | |
| 209 | * | |
| 210 | * @param $region | |
| 211 | * Which set of blocks to retrieve. | |
| 9dfc7d9f J |
212 | * @param $show_blocks |
| 213 | * A boolean to determine whether to render sidebar regions or not. Should be | |
| 214 | * the same value as passed to theme_page. | |
| 94f89279 J |
215 | * @return |
| 216 | * A string containing the themed blocks for this region. | |
| 9dfc7d9f J |
217 | * |
| 218 | * @see zen_show_blocks_discovery() | |
| 94f89279 | 219 | */ |
| 9dfc7d9f J |
220 | function zen_blocks($region, $show_blocks = NULL) { |
| 221 | // Since Drupal 6 doesn't pass $show_blocks to theme_blocks, we manually call | |
| 222 | // theme('blocks', NULL, $show_blocks) so that this function can remember the | |
| 223 | // value on later calls. | |
| 224 | static $render_sidebars = TRUE; | |
| 225 | if (!is_null($show_blocks)) { | |
| 226 | $render_sidebars = $show_blocks; | |
| 227 | } | |
| 94f89279 | 228 | |
| 9dfc7d9f J |
229 | // If zen_blocks was called with a NULL region, its likely we were just |
| 230 | // setting the $render_sidebars static variable. | |
| 231 | if ($region) { | |
| 232 | $output = ''; | |
| 233 | ||
| 234 | // If $renders_sidebars is FALSE, don't render any region whose name begins | |
| 235 | // with "sidebar_". | |
| 349f7405 J |
236 | if ($render_sidebars || (strpos($region, 'sidebar_') !== 0)) { |
| 237 | // Allow context module to set blocks. | |
| 238 | if (function_exists('context_blocks')) { | |
| 239 | $output = context_blocks($region); | |
| 240 | } | |
| 241 | else { | |
| 242 | foreach (block_list($region) as $key => $block) { | |
| 243 | // $key == module_delta | |
| 244 | $output .= theme('block', $block); | |
| 245 | } | |
| 9dfc7d9f | 246 | } |
| 94f89279 | 247 | } |
| 94f89279 | 248 | |
| 9dfc7d9f J |
249 | // Add any content assigned to this region through drupal_set_content() calls. |
| 250 | $output .= drupal_get_content($region); | |
| 94f89279 | 251 | |
| 9dfc7d9f J |
252 | $elements['#children'] = $output; |
| 253 | $elements['#region'] = $region; | |
| 94f89279 | 254 | |
| 54b77701 J |
255 | // Set the theme hook suggestions. |
| 256 | $hook = array('region_' . $region); | |
| 257 | if (strpos($region, 'sidebar_') === 0) { | |
| 258 | $hook[] = 'region_sidebar'; | |
| 259 | } | |
| 260 | $hook[] = 'region'; | |
| 261 | return $output ? theme($hook, $elements) : ''; | |
| 9dfc7d9f J |
262 | } |
| 263 | } | |
| 264 | ||
| 265 | /** | |
| 266 | * Examine the $show_blocks variable before template_preprocess_page() is called. | |
| 267 | * | |
| 268 | * @param $vars | |
| 269 | * An array of variables to pass to the page template. | |
| 270 | * | |
| 271 | * @see zen_blocks() | |
| 272 | */ | |
| 273 | function zen_show_blocks_discovery(&$vars) { | |
| 274 | if ($vars['show_blocks'] == FALSE) { | |
| 275 | // Allow zen_blocks() to statically cache the $show_blocks variable. A TRUE | |
| 276 | // value is assumed, so we only need to override when $show_blocks is FALSE. | |
| 277 | theme('blocks', NULL, FALSE); | |
| 278 | } | |
| 94f89279 | 279 | } |
| 7c5fa196 | 280 | |
| 960bac1c | 281 | /** |
| d212bfc9 J |
282 | * Override or insert variables into templates before other preprocess functions have run. |
| 283 | * | |
| 284 | * @param $vars | |
| 285 | * An array of variables to pass to the theme template. | |
| 286 | * @param $hook | |
| 287 | * The name of the template being rendered. | |
| 288 | */ | |
| 289 | function zen_preprocess(&$vars, $hook) { | |
| 290 | // In D6, the page.tpl uses a different variable name to hold the classes. | |
| 291 | $key = ($hook == 'page' || $hook == 'maintenance_page') ? 'body_classes' : 'classes'; | |
| 292 | ||
| 293 | // Create a D7-standard classes_array variable. | |
| 294 | if (array_key_exists($key, $vars)) { | |
| 17e89a6f J |
295 | // Views (and possibly other modules) have templates with a $classes |
| 296 | // variable that isn't a string, so we leave those variables alone. | |
| 297 | if (is_string($vars[$key])) { | |
| cc8f2faf | 298 | $vars['classes_array'] = explode(' ', $hook . ' ' . $vars[$key]); |
| 17e89a6f J |
299 | unset($vars[$key]); |
| 300 | } | |
| d212bfc9 J |
301 | } |
| 302 | else { | |
| 303 | $vars['classes_array'] = array($hook); | |
| 304 | } | |
| 3dd81302 J |
305 | // Add support for Skinr |
| 306 | if (!empty($vars['skinr']) && array_key_exists('classes_array', $vars)) { | |
| 307 | $vars['classes_array'][] = $vars['skinr']; | |
| 308 | } | |
| d212bfc9 J |
309 | } |
| 310 | ||
| 311 | /** | |
| 0b1037f4 | 312 | * Override or insert variables into the page templates. |
| 87695e28 J |
313 | * |
| 314 | * @param $vars | |
| 0b1037f4 | 315 | * An array of variables to pass to the theme template. |
| e6f4a124 | 316 | * @param $hook |
| 0b1037f4 | 317 | * The name of the template being rendered ("page" in this case.) |
| 87695e28 | 318 | */ |
| fcf0b3cc | 319 | function zen_preprocess_page(&$vars, $hook) { |
| 78d8d215 J |
320 | // If the user is silly and enables Zen as the theme, add some styles. |
| 321 | if ($GLOBALS['theme'] == 'zen') { | |
| 3183d194 | 322 | include_once './' . _zen_path() . '/zen-internals/template.zen.inc'; |
| 78d8d215 J |
323 | _zen_preprocess_page($vars, $hook); |
| 324 | } | |
| 719059ea | 325 | // Add conditional stylesheets. |
| 78d8d215 | 326 | elseif (!module_exists('conditional_styles')) { |
| 719059ea J |
327 | $vars['styles'] .= $vars['conditional_styles'] = variable_get('conditional_styles_' . $GLOBALS['theme'], ''); |
| 328 | } | |
| 329 | ||
| e0a8f494 J |
330 | // Classes for body element. Allows advanced theming based on context |
| 331 | // (home page, node of certain type, etc.) | |
| 6930eb03 | 332 | // Remove the mostly useless page-ARG0 class. |
| d212bfc9 J |
333 | if ($index = array_search(preg_replace('![^abcdefghijklmnopqrstuvwxyz0-9-_]+!s', '', 'page-'. drupal_strtolower(arg(0))), $vars['classes_array'])) { |
| 334 | unset($vars['classes_array'][$index]); | |
| 6930eb03 | 335 | } |
| e0a8f494 | 336 | if (!$vars['is_front']) { |
| 363d1497 | 337 | // Add unique class for each page. |
| 9faf4798 | 338 | $path = drupal_get_path_alias($_GET['q']); |
| a20a7825 | 339 | $vars['classes_array'][] = drupal_html_class('page-' . $path); |
| 363d1497 | 340 | // Add unique class for each website section. |
| 8357c010 | 341 | list($section, ) = explode('/', $path, 2); |
| 28511ba8 J |
342 | if (arg(0) == 'node') { |
| 343 | if (arg(1) == 'add') { | |
| 363d1497 | 344 | $section = 'node-add'; |
| 28511ba8 J |
345 | } |
| 346 | elseif (is_numeric(arg(1)) && (arg(2) == 'edit' || arg(2) == 'delete')) { | |
| 363d1497 | 347 | $section = 'node-' . arg(2); |
| 28511ba8 J |
348 | } |
| 349 | } | |
| a20a7825 | 350 | $vars['classes_array'][] = drupal_html_class('section-' . $section); |
| 960bac1c | 351 | } |
| 2041a7c1 | 352 | if (theme_get_setting('zen_wireframes')) { |
| d212bfc9 | 353 | $vars['classes_array'][] = 'with-wireframes'; // Optionally add the wireframes style. |
| 2041a7c1 | 354 | } |
| 9dfc7d9f J |
355 | // We need to re-do the $layout and body classes because |
| 356 | // template_preprocess_page() assumes sidebars are named 'left' and 'right'. | |
| 357 | $vars['layout'] = 'none'; | |
| 358 | if (!empty($vars['sidebar_first'])) { | |
| 359 | $vars['layout'] = 'first'; | |
| 360 | } | |
| 361 | if (!empty($vars['sidebar_second'])) { | |
| 362 | $vars['layout'] = ($vars['layout'] == 'first') ? 'both' : 'second'; | |
| 363 | } | |
| 364 | // If the layout is 'none', then template_preprocess_page() will already have | |
| 365 | // set a 'no-sidebars' class since it won't find a 'left' or 'right' sidebar. | |
| 366 | if ($vars['layout'] != 'none') { | |
| 367 | // Remove the incorrect 'no-sidebars' class. | |
| 368 | if ($index = array_search('no-sidebars', $vars['classes_array'])) { | |
| 369 | unset($vars['classes_array'][$index]); | |
| 370 | } | |
| 371 | // Set the proper layout body classes. | |
| 372 | if ($vars['layout'] == 'both') { | |
| 373 | $vars['classes_array'][] = 'two-sidebars'; | |
| 374 | } | |
| 375 | else { | |
| 376 | $vars['classes_array'][] = 'one-sidebar'; | |
| 377 | $vars['classes_array'][] = 'sidebar-' . $vars['layout']; | |
| 2f37f103 | 378 | } |
| 536678ab | 379 | } |
| fbb0e7b8 J |
380 | // Store the menu item since it has some useful information. |
| 381 | $vars['menu_item'] = menu_get_item(); | |
| 382 | switch ($vars['menu_item']['page_callback']) { | |
| 383 | case 'views_page': | |
| 384 | // Is this a Views page? | |
| 385 | $vars['classes_array'][] = 'page-views'; | |
| 386 | break; | |
| 387 | case 'page_manager_page_execute': | |
| 28feeaf6 J |
388 | case 'page_manager_node_view': |
| 389 | case 'page_manager_contact_site': | |
| fbb0e7b8 J |
390 | // Is this a Panels page? |
| 391 | $vars['classes_array'][] = 'page-panels'; | |
| 392 | break; | |
| 393 | } | |
| e0a8f494 | 394 | } |
| 7c5fa196 | 395 | |
| e0a8f494 | 396 | /** |
| 3183d194 J |
397 | * Override or insert variables into the maintenance page template. |
| 398 | * | |
| 399 | * @param $vars | |
| 400 | * An array of variables to pass to the theme template. | |
| 401 | * @param $hook | |
| 31c1fbc2 | 402 | * The name of the template being rendered ("maintenance_page" in this case.) |
| 3183d194 J |
403 | */ |
| 404 | function zen_preprocess_maintenance_page(&$vars, $hook) { | |
| 405 | // If Zen is the maintenance theme, add some styles. | |
| 406 | if ($GLOBALS['theme'] == 'zen') { | |
| 407 | include_once './' . _zen_path() . '/zen-internals/template.zen.inc'; | |
| 408 | _zen_preprocess_page($vars, $hook); | |
| 409 | } | |
| 410 | // Add conditional stylesheets. | |
| 411 | elseif (!module_exists('conditional_styles')) { | |
| 412 | $vars['styles'] .= $vars['conditional_styles'] = variable_get('conditional_styles_' . $GLOBALS['theme'], ''); | |
| 413 | } | |
| 3183d194 J |
414 | } |
| 415 | ||
| 416 | /** | |
| 0b1037f4 | 417 | * Override or insert variables into the node templates. |
| e0a8f494 J |
418 | * |
| 419 | * @param $vars | |
| 0b1037f4 | 420 | * An array of variables to pass to the theme template. |
| e6f4a124 | 421 | * @param $hook |
| 0b1037f4 | 422 | * The name of the template being rendered ("node" in this case.) |
| e0a8f494 | 423 | */ |
| fcf0b3cc | 424 | function zen_preprocess_node(&$vars, $hook) { |
| 78362cd3 J |
425 | // Create the build_mode variable. |
| 426 | switch ($vars['node']->build_mode) { | |
| 427 | case NODE_BUILD_NORMAL: | |
| d90f68f9 J |
428 | if ($vars['node']->build_mode === NODE_BUILD_NORMAL) { |
| 429 | $vars['build_mode'] = $vars['teaser'] ? 'teaser' : 'full'; | |
| 430 | } | |
| 6a2a1aec J |
431 | else { |
| 432 | $vars['build_mode'] = $vars['node']->build_mode; | |
| 433 | } | |
| 78362cd3 J |
434 | break; |
| 435 | case NODE_BUILD_PREVIEW: | |
| 436 | $vars['build_mode'] = 'preview'; | |
| 437 | break; | |
| 438 | case NODE_BUILD_SEARCH_INDEX: | |
| 439 | $vars['build_mode'] = 'search_index'; | |
| 440 | break; | |
| 441 | case NODE_BUILD_SEARCH_RESULT: | |
| 442 | $vars['build_mode'] = 'search_result'; | |
| 443 | break; | |
| 444 | case NODE_BUILD_RSS: | |
| 445 | $vars['build_mode'] = 'rss'; | |
| 446 | break; | |
| 447 | case NODE_BUILD_PRINT: | |
| 448 | $vars['build_mode'] = 'print'; | |
| 449 | break; | |
| d90f68f9 J |
450 | default: |
| 451 | $vars['build_mode'] = $vars['node']->build_mode; | |
| 78362cd3 J |
452 | } |
| 453 | ||
| c91ed8a5 J |
454 | // Create the user_picture variable. |
| 455 | $vars['user_picture'] = $vars['picture']; | |
| 456 | ||
| 911d5130 J |
457 | // Create the Drupal 7 $display_submitted variable. |
| 458 | $vars['display_submitted'] = theme_get_setting('toggle_node_info_' . $vars['node']->type); | |
| 459 | ||
| 78362cd3 | 460 | // Special classes for nodes. |
| c91ed8a5 | 461 | // Class for node type: "node-type-page", "node-type-story", "node-type-my-custom-type", etc. |
| a20a7825 | 462 | $vars['classes_array'][] = drupal_html_class('node-type-' . $vars['type']); |
| d893f301 J |
463 | if ($vars['promote']) { |
| 464 | $vars['classes_array'][] = 'node-promoted'; | |
| c91ed8a5 | 465 | } |
| e0a8f494 | 466 | if ($vars['sticky']) { |
| d212bfc9 | 467 | $vars['classes_array'][] = 'node-sticky'; |
| e0a8f494 | 468 | } |
| b457ba98 | 469 | if (!$vars['status']) { |
| d212bfc9 | 470 | $vars['classes_array'][] = 'node-unpublished'; |
| 28511ba8 J |
471 | $vars['unpublished'] = TRUE; |
| 472 | } | |
| 473 | else { | |
| 474 | $vars['unpublished'] = FALSE; | |
| e0a8f494 | 475 | } |
| b457ba98 | 476 | if ($vars['uid'] && $vars['uid'] == $GLOBALS['user']->uid) { |
| e5af59a4 | 477 | $vars['classes_array'][] = 'node-by-viewer'; // Node is authored by current user. |
| 7c5fa196 | 478 | } |
| e0a8f494 | 479 | if ($vars['teaser']) { |
| d212bfc9 | 480 | $vars['classes_array'][] = 'node-teaser'; // Node is displayed as teaser. |
| e0a8f494 | 481 | } |
| d893f301 J |
482 | if (isset($vars['preview'])) { |
| 483 | $vars['classes_array'][] = 'node-preview'; | |
| c91ed8a5 | 484 | } |
| d90f68f9 | 485 | $vars['classes_array'][] = 'build-mode-' . $vars['build_mode'] ; |
| e0a8f494 | 486 | } |
| 7c5fa196 | 487 | |
| e0a8f494 | 488 | /** |
| 0b1037f4 | 489 | * Override or insert variables into the comment templates. |
| e0a8f494 J |
490 | * |
| 491 | * @param $vars | |
| 0b1037f4 | 492 | * An array of variables to pass to the theme template. |
| e6f4a124 | 493 | * @param $hook |
| 0b1037f4 | 494 | * The name of the template being rendered ("comment" in this case.) |
| e0a8f494 | 495 | */ |
| fcf0b3cc | 496 | function zen_preprocess_comment(&$vars, $hook) { |
| 3183d194 | 497 | include_once './' . _zen_path() . '/zen-internals/template.comment.inc'; |
| 29ba6758 | 498 | _zen_preprocess_comment($vars, $hook); |
| 960bac1c | 499 | } |
| 4dd0f1bf JR |
500 | |
| 501 | /** | |
| 94f89279 J |
502 | * Preprocess variables for region.tpl.php |
| 503 | * | |
| 504 | * Prepare the values passed to the theme_region function to be passed into a | |
| ba48165b | 505 | * pluggable template engine. |
| 94f89279 J |
506 | * |
| 507 | * @see region.tpl.php | |
| 508 | */ | |
| 509 | function zen_preprocess_region(&$vars, $hook) { | |
| 510 | // Create the $content variable that templates expect. | |
| 511 | $vars['content'] = $vars['elements']['#children']; | |
| 512 | $vars['region'] = $vars['elements']['#region']; | |
| 513 | ||
| e2e805cb | 514 | // Setup the default classes. |
| ba48165b | 515 | $vars['classes_array'] = array('region', 'region-' . str_replace('_', '-', $vars['region'])); |
| e2e805cb | 516 | |
| ba48165b | 517 | // Sidebar regions get a couple extra classes. |
| 995d309c | 518 | if (strpos($vars['region'], 'sidebar_') === 0) { |
| e2e805cb J |
519 | $vars['classes_array'][] = 'column'; |
| 520 | $vars['classes_array'][] = 'sidebar'; | |
| 995d309c | 521 | } |
| 94f89279 J |
522 | } |
| 523 | ||
| 524 | /** | |
| 0b1037f4 | 525 | * Override or insert variables into the block templates. |
| 28511ba8 J |
526 | * |
| 527 | * @param $vars | |
| 0b1037f4 | 528 | * An array of variables to pass to the theme template. |
| e6f4a124 | 529 | * @param $hook |
| 0b1037f4 | 530 | * The name of the template being rendered ("block" in this case.) |
| 28511ba8 | 531 | */ |
| fcf0b3cc | 532 | function zen_preprocess_block(&$vars, $hook) { |
| 28511ba8 J |
533 | $block = $vars['block']; |
| 534 | ||
| c531ccf0 J |
535 | // Drupal 7 uses a $content variable instead of $block->content. |
| 536 | $vars['content'] = $block->content; | |
| 537 | // Drupal 7 should use a $title variable instead of $block->subject. | |
| 538 | $vars['title'] = $block->subject; | |
| 539 | ||
| 76772d59 | 540 | // Special classes for blocks. |
| d212bfc9 | 541 | $vars['classes_array'][] = 'block-' . $block->module; |
| feb73a51 J |
542 | // Classes describing the position of the block within the region. |
| 543 | if ($vars['block_id'] == 1) { | |
| 544 | $vars['classes_array'][] = 'first'; | |
| 545 | } | |
| 546 | if (!function_exists('context_blocks') && count(block_list($vars['block']->region)) == $vars['block_id']) { | |
| 547 | $vars['classes_array'][] = 'last'; | |
| 548 | } | |
| d212bfc9 J |
549 | $vars['classes_array'][] = 'region-' . $vars['block_zebra']; |
| 550 | $vars['classes_array'][] = $vars['zebra']; | |
| 551 | $vars['classes_array'][] = 'region-count-' . $vars['block_id']; | |
| 552 | $vars['classes_array'][] = 'count-' . $vars['id']; | |
| 28511ba8 | 553 | |
| 1c8b6021 J |
554 | // Create the block ID. |
| 555 | $vars['block_html_id'] = 'block-' . $block->module . '-' . $block->delta; | |
| 556 | ||
| a0e81398 | 557 | $vars['edit_links_array'] = array(); |
| 28511ba8 | 558 | if (theme_get_setting('zen_block_editing') && user_access('administer blocks')) { |
| 3183d194 | 559 | include_once './' . _zen_path() . '/zen-internals/template.block-editing.inc'; |
| a0e81398 | 560 | zen_preprocess_block_editing($vars, $hook); |
| d212bfc9 | 561 | $vars['classes_array'][] = 'with-block-editing'; |
| 28511ba8 | 562 | } |
| 0db41f1b J |
563 | } |
| 564 | ||
| 565 | /** | |
| 566 | * Override or insert variables into templates after preprocess functions have run. | |
| 567 | * | |
| 568 | * @param $vars | |
| 569 | * An array of variables to pass to the theme template. | |
| 570 | * @param $hook | |
| 571 | * The name of the template being rendered. | |
| 572 | */ | |
| 573 | function zen_process(&$vars, $hook) { | |
| 337ff0a2 J |
574 | // Don't clobber Views 3 classes. |
| 575 | if (array_key_exists('classes_array', $vars) && !array_key_exists('classes', $vars)) { | |
| 17e89a6f J |
576 | $vars['classes'] = implode(' ', $vars['classes_array']); |
| 577 | } | |
| 28511ba8 J |
578 | } |
| 579 | ||
| 580 | /** | |
| 6f634acb J |
581 | * Override or insert variables into the block templates after preprocess functions have run. |
| 582 | * | |
| 583 | * @param $vars | |
| 584 | * An array of variables to pass to the theme template. | |
| 585 | * @param $hook | |
| 586 | * The name of the template being rendered ("block" in this case.) | |
| 587 | */ | |
| 588 | function zen_process_block(&$vars, $hook) { | |
| 589 | $vars['edit_links'] = !empty($vars['edit_links_array']) ? '<div class="edit">' . implode(' ', $vars['edit_links_array']) . '</div>' : ''; | |
| 590 | } | |
| 591 | ||
| a20a7825 J |
592 | if (!function_exists('drupal_html_class')) { |
| 593 | /** | |
| 594 | * Prepare a string for use as a valid class name. | |
| 595 | * | |
| 596 | * Do not pass one string containing multiple classes as they will be | |
| 597 | * incorrectly concatenated with dashes, i.e. "one two" will become "one-two". | |
| 598 | * | |
| 599 | * @param $class | |
| 600 | * The class name to clean. | |
| 601 | * @return | |
| 602 | * The cleaned class name. | |
| 603 | */ | |
| 604 | function drupal_html_class($class) { | |
| 605 | // By default, we filter using Drupal's coding standards. | |
| 606 | $class = strtr(drupal_strtolower($class), array(' ' => '-', '_' => '-', '/' => '-', '[' => '-', ']' => '')); | |
| 607 | ||
| 608 | // http://www.w3.org/TR/CSS21/syndata.html#characters shows the syntax for valid | |
| 609 | // CSS identifiers (including element names, classes, and IDs in selectors.) | |
| 610 | // | |
| 611 | // Valid characters in a CSS identifier are: | |
| 612 | // - the hyphen (U+002D) | |
| 613 | // - a-z (U+0030 - U+0039) | |
| 614 | // - A-Z (U+0041 - U+005A) | |
| 615 | // - the underscore (U+005F) | |
| 616 | // - 0-9 (U+0061 - U+007A) | |
| 617 | // - ISO 10646 characters U+00A1 and higher | |
| 618 | // We strip out any character not in the above list. | |
| 619 | $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); | |
| 620 | ||
| 621 | return $class; | |
| 622 | } | |
| 623 | } /* End of drupal_html_class conditional definition. */ | |
| 624 | ||
| 625 | if (!function_exists('drupal_html_id')) { | |
| 626 | /** | |
| 627 | * Prepare a string for use as a valid HTML ID and guarantee uniqueness. | |
| 628 | * | |
| 629 | * @param $id | |
| 630 | * The ID to clean. | |
| 631 | * @return | |
| 632 | * The cleaned ID. | |
| 633 | */ | |
| 634 | function drupal_html_id($id) { | |
| 635 | $id = strtr(drupal_strtolower($id), array(' ' => '-', '_' => '-', '[' => '-', ']' => '')); | |
| 636 | ||
| 637 | // As defined in http://www.w3.org/TR/html4/types.html#type-name, HTML IDs can | |
| 638 | // only contain letters, digits ([0-9]), hyphens ("-"), underscores ("_"), | |
| 639 | // colons (":"), and periods ("."). We strip out any character not in that | |
| 640 | // list. Note that the CSS spec doesn't allow colons or periods in identifiers | |
| 641 | // (http://www.w3.org/TR/CSS21/syndata.html#characters), so we strip those two | |
| 642 | // characters as well. | |
| 643 | $id = preg_replace('/[^A-Za-z0-9\-_]/', '', $id); | |
| 644 | ||
| 645 | return $id; | |
| 646 | } | |
| 647 | } /* End of drupal_html_id conditional definition. */ | |
| 3183d194 J |
648 | |
| 649 | /** | |
| 650 | * Returns the path to the Zen theme. | |
| 651 | * | |
| 652 | * drupal_get_filename() is broken; see #341140. When that is fixed in Drupal 6, | |
| 653 | * replace _zen_path() with drupal_get_path('theme', 'zen'). | |
| 654 | */ | |
| 655 | function _zen_path() { | |
| 656 | static $path = FALSE; | |
| 657 | if (!$path) { | |
| 658 | $matches = drupal_system_listing('zen\.info$', 'themes', 'name', 0); | |
| 659 | if (!empty($matches['zen']->filename)) { | |
| 660 | $path = dirname($matches['zen']->filename); | |
| 661 | } | |
| 662 | } | |
| 663 | return $path; | |
| 664 | } |