| 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_". | |
| 236 | if (($render_sidebars || (strpos($region, 'sidebar_') !== 0)) && ($list = block_list($region))) { | |
| 237 | foreach ($list as $key => $block) { | |
| 238 | // $key == module_delta | |
| 239 | $output .= theme('block', $block); | |
| 240 | } | |
| 94f89279 | 241 | } |
| 94f89279 | 242 | |
| 9dfc7d9f J |
243 | // Add any content assigned to this region through drupal_set_content() calls. |
| 244 | $output .= drupal_get_content($region); | |
| 94f89279 | 245 | |
| 9dfc7d9f J |
246 | $elements['#children'] = $output; |
| 247 | $elements['#region'] = $region; | |
| 94f89279 | 248 | |
| 54b77701 J |
249 | // Set the theme hook suggestions. |
| 250 | $hook = array('region_' . $region); | |
| 251 | if (strpos($region, 'sidebar_') === 0) { | |
| 252 | $hook[] = 'region_sidebar'; | |
| 253 | } | |
| 254 | $hook[] = 'region'; | |
| 255 | return $output ? theme($hook, $elements) : ''; | |
| 9dfc7d9f J |
256 | } |
| 257 | } | |
| 258 | ||
| 259 | /** | |
| 260 | * Examine the $show_blocks variable before template_preprocess_page() is called. | |
| 261 | * | |
| 262 | * @param $vars | |
| 263 | * An array of variables to pass to the page template. | |
| 264 | * | |
| 265 | * @see zen_blocks() | |
| 266 | */ | |
| 267 | function zen_show_blocks_discovery(&$vars) { | |
| 268 | if ($vars['show_blocks'] == FALSE) { | |
| 269 | // Allow zen_blocks() to statically cache the $show_blocks variable. A TRUE | |
| 270 | // value is assumed, so we only need to override when $show_blocks is FALSE. | |
| 271 | theme('blocks', NULL, FALSE); | |
| 272 | } | |
| 94f89279 | 273 | } |
| 7c5fa196 | 274 | |
| 960bac1c | 275 | /** |
| d212bfc9 J |
276 | * Override or insert variables into templates before other preprocess functions have run. |
| 277 | * | |
| 278 | * @param $vars | |
| 279 | * An array of variables to pass to the theme template. | |
| 280 | * @param $hook | |
| 281 | * The name of the template being rendered. | |
| 282 | */ | |
| 283 | function zen_preprocess(&$vars, $hook) { | |
| 284 | // In D6, the page.tpl uses a different variable name to hold the classes. | |
| 285 | $key = ($hook == 'page' || $hook == 'maintenance_page') ? 'body_classes' : 'classes'; | |
| 286 | ||
| 287 | // Create a D7-standard classes_array variable. | |
| 288 | if (array_key_exists($key, $vars)) { | |
| 17e89a6f J |
289 | // Views (and possibly other modules) have templates with a $classes |
| 290 | // variable that isn't a string, so we leave those variables alone. | |
| 291 | if (is_string($vars[$key])) { | |
| cc8f2faf | 292 | $vars['classes_array'] = explode(' ', $hook . ' ' . $vars[$key]); |
| 17e89a6f J |
293 | unset($vars[$key]); |
| 294 | } | |
| d212bfc9 J |
295 | } |
| 296 | else { | |
| 297 | $vars['classes_array'] = array($hook); | |
| 298 | } | |
| 3dd81302 J |
299 | // Add support for Skinr |
| 300 | if (!empty($vars['skinr']) && array_key_exists('classes_array', $vars)) { | |
| 301 | $vars['classes_array'][] = $vars['skinr']; | |
| 302 | } | |
| d212bfc9 J |
303 | } |
| 304 | ||
| 305 | /** | |
| 0b1037f4 | 306 | * Override or insert variables into the page templates. |
| 87695e28 J |
307 | * |
| 308 | * @param $vars | |
| 0b1037f4 | 309 | * An array of variables to pass to the theme template. |
| e6f4a124 | 310 | * @param $hook |
| 0b1037f4 | 311 | * The name of the template being rendered ("page" in this case.) |
| 87695e28 | 312 | */ |
| fcf0b3cc | 313 | function zen_preprocess_page(&$vars, $hook) { |
| 78d8d215 J |
314 | // If the user is silly and enables Zen as the theme, add some styles. |
| 315 | if ($GLOBALS['theme'] == 'zen') { | |
| 3183d194 | 316 | include_once './' . _zen_path() . '/zen-internals/template.zen.inc'; |
| 78d8d215 J |
317 | _zen_preprocess_page($vars, $hook); |
| 318 | } | |
| 719059ea | 319 | // Add conditional stylesheets. |
| 78d8d215 | 320 | elseif (!module_exists('conditional_styles')) { |
| 719059ea J |
321 | $vars['styles'] .= $vars['conditional_styles'] = variable_get('conditional_styles_' . $GLOBALS['theme'], ''); |
| 322 | } | |
| 323 | ||
| e0a8f494 J |
324 | // Classes for body element. Allows advanced theming based on context |
| 325 | // (home page, node of certain type, etc.) | |
| 6930eb03 | 326 | // Remove the mostly useless page-ARG0 class. |
| d212bfc9 J |
327 | if ($index = array_search(preg_replace('![^abcdefghijklmnopqrstuvwxyz0-9-_]+!s', '', 'page-'. drupal_strtolower(arg(0))), $vars['classes_array'])) { |
| 328 | unset($vars['classes_array'][$index]); | |
| 6930eb03 | 329 | } |
| e0a8f494 | 330 | if (!$vars['is_front']) { |
| 363d1497 | 331 | // Add unique class for each page. |
| 9faf4798 | 332 | $path = drupal_get_path_alias($_GET['q']); |
| a20a7825 | 333 | $vars['classes_array'][] = drupal_html_class('page-' . $path); |
| 363d1497 | 334 | // Add unique class for each website section. |
| 8357c010 | 335 | list($section, ) = explode('/', $path, 2); |
| 28511ba8 J |
336 | if (arg(0) == 'node') { |
| 337 | if (arg(1) == 'add') { | |
| 363d1497 | 338 | $section = 'node-add'; |
| 28511ba8 J |
339 | } |
| 340 | elseif (is_numeric(arg(1)) && (arg(2) == 'edit' || arg(2) == 'delete')) { | |
| 363d1497 | 341 | $section = 'node-' . arg(2); |
| 28511ba8 J |
342 | } |
| 343 | } | |
| a20a7825 | 344 | $vars['classes_array'][] = drupal_html_class('section-' . $section); |
| 960bac1c | 345 | } |
| 2041a7c1 | 346 | if (theme_get_setting('zen_wireframes')) { |
| d212bfc9 | 347 | $vars['classes_array'][] = 'with-wireframes'; // Optionally add the wireframes style. |
| 2041a7c1 | 348 | } |
| 9dfc7d9f J |
349 | // We need to re-do the $layout and body classes because |
| 350 | // template_preprocess_page() assumes sidebars are named 'left' and 'right'. | |
| 351 | $vars['layout'] = 'none'; | |
| 352 | if (!empty($vars['sidebar_first'])) { | |
| 353 | $vars['layout'] = 'first'; | |
| 354 | } | |
| 355 | if (!empty($vars['sidebar_second'])) { | |
| 356 | $vars['layout'] = ($vars['layout'] == 'first') ? 'both' : 'second'; | |
| 357 | } | |
| 358 | // If the layout is 'none', then template_preprocess_page() will already have | |
| 359 | // set a 'no-sidebars' class since it won't find a 'left' or 'right' sidebar. | |
| 360 | if ($vars['layout'] != 'none') { | |
| 361 | // Remove the incorrect 'no-sidebars' class. | |
| 362 | if ($index = array_search('no-sidebars', $vars['classes_array'])) { | |
| 363 | unset($vars['classes_array'][$index]); | |
| 364 | } | |
| 365 | // Set the proper layout body classes. | |
| 366 | if ($vars['layout'] == 'both') { | |
| 367 | $vars['classes_array'][] = 'two-sidebars'; | |
| 368 | } | |
| 369 | else { | |
| 370 | $vars['classes_array'][] = 'one-sidebar'; | |
| 371 | $vars['classes_array'][] = 'sidebar-' . $vars['layout']; | |
| 2f37f103 | 372 | } |
| 536678ab | 373 | } |
| fbb0e7b8 J |
374 | // Store the menu item since it has some useful information. |
| 375 | $vars['menu_item'] = menu_get_item(); | |
| 376 | switch ($vars['menu_item']['page_callback']) { | |
| 377 | case 'views_page': | |
| 378 | // Is this a Views page? | |
| 379 | $vars['classes_array'][] = 'page-views'; | |
| 380 | break; | |
| 381 | case 'page_manager_page_execute': | |
| 382 | // Is this a Panels page? | |
| 383 | $vars['classes_array'][] = 'page-panels'; | |
| 384 | break; | |
| 385 | } | |
| e0a8f494 | 386 | } |
| 7c5fa196 | 387 | |
| e0a8f494 | 388 | /** |
| 3183d194 J |
389 | * Override or insert variables into the maintenance page template. |
| 390 | * | |
| 391 | * @param $vars | |
| 392 | * An array of variables to pass to the theme template. | |
| 393 | * @param $hook | |
| 31c1fbc2 | 394 | * The name of the template being rendered ("maintenance_page" in this case.) |
| 3183d194 J |
395 | */ |
| 396 | function zen_preprocess_maintenance_page(&$vars, $hook) { | |
| 397 | // If Zen is the maintenance theme, add some styles. | |
| 398 | if ($GLOBALS['theme'] == 'zen') { | |
| 399 | include_once './' . _zen_path() . '/zen-internals/template.zen.inc'; | |
| 400 | _zen_preprocess_page($vars, $hook); | |
| 401 | } | |
| 402 | // Add conditional stylesheets. | |
| 403 | elseif (!module_exists('conditional_styles')) { | |
| 404 | $vars['styles'] .= $vars['conditional_styles'] = variable_get('conditional_styles_' . $GLOBALS['theme'], ''); | |
| 405 | } | |
| 3183d194 J |
406 | } |
| 407 | ||
| 408 | /** | |
| 0b1037f4 | 409 | * Override or insert variables into the node templates. |
| e0a8f494 J |
410 | * |
| 411 | * @param $vars | |
| 0b1037f4 | 412 | * An array of variables to pass to the theme template. |
| e6f4a124 | 413 | * @param $hook |
| 0b1037f4 | 414 | * The name of the template being rendered ("node" in this case.) |
| e0a8f494 | 415 | */ |
| fcf0b3cc | 416 | function zen_preprocess_node(&$vars, $hook) { |
| 78362cd3 J |
417 | // Create the build_mode variable. |
| 418 | switch ($vars['node']->build_mode) { | |
| 419 | case NODE_BUILD_NORMAL: | |
| 420 | $vars['build_mode'] = $vars['teaser'] ? 'teaser' : 'full'; | |
| 421 | break; | |
| 422 | case NODE_BUILD_PREVIEW: | |
| 423 | $vars['build_mode'] = 'preview'; | |
| 424 | break; | |
| 425 | case NODE_BUILD_SEARCH_INDEX: | |
| 426 | $vars['build_mode'] = 'search_index'; | |
| 427 | break; | |
| 428 | case NODE_BUILD_SEARCH_RESULT: | |
| 429 | $vars['build_mode'] = 'search_result'; | |
| 430 | break; | |
| 431 | case NODE_BUILD_RSS: | |
| 432 | $vars['build_mode'] = 'rss'; | |
| 433 | break; | |
| 434 | case NODE_BUILD_PRINT: | |
| 435 | $vars['build_mode'] = 'print'; | |
| 436 | break; | |
| 437 | } | |
| 438 | ||
| c91ed8a5 J |
439 | // Create the user_picture variable. |
| 440 | $vars['user_picture'] = $vars['picture']; | |
| 441 | ||
| 911d5130 J |
442 | // Create the Drupal 7 $display_submitted variable. |
| 443 | $vars['display_submitted'] = theme_get_setting('toggle_node_info_' . $vars['node']->type); | |
| 444 | ||
| 78362cd3 | 445 | // Special classes for nodes. |
| c91ed8a5 | 446 | // Class for node type: "node-type-page", "node-type-story", "node-type-my-custom-type", etc. |
| a20a7825 | 447 | $vars['classes_array'][] = drupal_html_class('node-type-' . $vars['type']); |
| d893f301 J |
448 | if ($vars['promote']) { |
| 449 | $vars['classes_array'][] = 'node-promoted'; | |
| c91ed8a5 | 450 | } |
| e0a8f494 | 451 | if ($vars['sticky']) { |
| d212bfc9 | 452 | $vars['classes_array'][] = 'node-sticky'; |
| e0a8f494 | 453 | } |
| b457ba98 | 454 | if (!$vars['status']) { |
| d212bfc9 | 455 | $vars['classes_array'][] = 'node-unpublished'; |
| 28511ba8 J |
456 | $vars['unpublished'] = TRUE; |
| 457 | } | |
| 458 | else { | |
| 459 | $vars['unpublished'] = FALSE; | |
| e0a8f494 | 460 | } |
| b457ba98 | 461 | if ($vars['uid'] && $vars['uid'] == $GLOBALS['user']->uid) { |
| e5af59a4 | 462 | $vars['classes_array'][] = 'node-by-viewer'; // Node is authored by current user. |
| 7c5fa196 | 463 | } |
| e0a8f494 | 464 | if ($vars['teaser']) { |
| d212bfc9 | 465 | $vars['classes_array'][] = 'node-teaser'; // Node is displayed as teaser. |
| e0a8f494 | 466 | } |
| d893f301 J |
467 | if (isset($vars['preview'])) { |
| 468 | $vars['classes_array'][] = 'node-preview'; | |
| c91ed8a5 | 469 | } |
| e0a8f494 | 470 | } |
| 7c5fa196 | 471 | |
| e0a8f494 | 472 | /** |
| 0b1037f4 | 473 | * Override or insert variables into the comment templates. |
| e0a8f494 J |
474 | * |
| 475 | * @param $vars | |
| 0b1037f4 | 476 | * An array of variables to pass to the theme template. |
| e6f4a124 | 477 | * @param $hook |
| 0b1037f4 | 478 | * The name of the template being rendered ("comment" in this case.) |
| e0a8f494 | 479 | */ |
| fcf0b3cc | 480 | function zen_preprocess_comment(&$vars, $hook) { |
| 3183d194 | 481 | include_once './' . _zen_path() . '/zen-internals/template.comment.inc'; |
| 29ba6758 | 482 | _zen_preprocess_comment($vars, $hook); |
| 960bac1c | 483 | } |
| 4dd0f1bf JR |
484 | |
| 485 | /** | |
| 94f89279 J |
486 | * Preprocess variables for region.tpl.php |
| 487 | * | |
| 488 | * Prepare the values passed to the theme_region function to be passed into a | |
| ba48165b | 489 | * pluggable template engine. |
| 94f89279 J |
490 | * |
| 491 | * @see region.tpl.php | |
| 492 | */ | |
| 493 | function zen_preprocess_region(&$vars, $hook) { | |
| 494 | // Create the $content variable that templates expect. | |
| 495 | $vars['content'] = $vars['elements']['#children']; | |
| 496 | $vars['region'] = $vars['elements']['#region']; | |
| 497 | ||
| e2e805cb | 498 | // Setup the default classes. |
| ba48165b | 499 | $vars['classes_array'] = array('region', 'region-' . str_replace('_', '-', $vars['region'])); |
| e2e805cb | 500 | |
| ba48165b | 501 | // Sidebar regions get a couple extra classes. |
| 995d309c | 502 | if (strpos($vars['region'], 'sidebar_') === 0) { |
| e2e805cb J |
503 | $vars['classes_array'][] = 'column'; |
| 504 | $vars['classes_array'][] = 'sidebar'; | |
| 995d309c | 505 | } |
| 94f89279 J |
506 | } |
| 507 | ||
| 508 | /** | |
| 0b1037f4 | 509 | * Override or insert variables into the block templates. |
| 28511ba8 J |
510 | * |
| 511 | * @param $vars | |
| 0b1037f4 | 512 | * An array of variables to pass to the theme template. |
| e6f4a124 | 513 | * @param $hook |
| 0b1037f4 | 514 | * The name of the template being rendered ("block" in this case.) |
| 28511ba8 | 515 | */ |
| fcf0b3cc | 516 | function zen_preprocess_block(&$vars, $hook) { |
| 28511ba8 J |
517 | $block = $vars['block']; |
| 518 | ||
| c531ccf0 J |
519 | // Drupal 7 uses a $content variable instead of $block->content. |
| 520 | $vars['content'] = $block->content; | |
| 521 | // Drupal 7 should use a $title variable instead of $block->subject. | |
| 522 | $vars['title'] = $block->subject; | |
| 523 | ||
| 76772d59 | 524 | // Special classes for blocks. |
| d212bfc9 J |
525 | $vars['classes_array'][] = 'block-' . $block->module; |
| 526 | $vars['classes_array'][] = 'region-' . $vars['block_zebra']; | |
| 527 | $vars['classes_array'][] = $vars['zebra']; | |
| 528 | $vars['classes_array'][] = 'region-count-' . $vars['block_id']; | |
| 529 | $vars['classes_array'][] = 'count-' . $vars['id']; | |
| 28511ba8 | 530 | |
| 1c8b6021 J |
531 | // Create the block ID. |
| 532 | $vars['block_html_id'] = 'block-' . $block->module . '-' . $block->delta; | |
| 533 | ||
| a0e81398 | 534 | $vars['edit_links_array'] = array(); |
| 28511ba8 | 535 | if (theme_get_setting('zen_block_editing') && user_access('administer blocks')) { |
| 3183d194 | 536 | include_once './' . _zen_path() . '/zen-internals/template.block-editing.inc'; |
| a0e81398 | 537 | zen_preprocess_block_editing($vars, $hook); |
| d212bfc9 | 538 | $vars['classes_array'][] = 'with-block-editing'; |
| 28511ba8 | 539 | } |
| 0db41f1b J |
540 | } |
| 541 | ||
| 542 | /** | |
| 3dd81302 J |
543 | * Override or insert variables into the views-view templates. |
| 544 | * | |
| 545 | * @param $vars | |
| 546 | * An array of variables to pass to the theme template. | |
| 547 | * @param $hook | |
| 548 | * The name of the template being rendered ("views-view" in this case.) | |
| 549 | */ | |
| 550 | function zen_preprocess_views_view(&$vars, $hook) { | |
| 551 | // Add the default Views classes. | |
| 552 | $vars['classes_array'][0] = 'view'; // Replace "views-view". | |
| 553 | $vars['classes_array'][] = 'view-' . $vars['css_name']; | |
| 554 | $vars['classes_array'][] = 'view-id-' . $vars['name']; | |
| 555 | $vars['classes_array'][] = 'view-display-id-' . $vars['display_id']; | |
| 556 | $vars['classes_array'][] = 'view-dom-id-' . $vars['dom_id']; | |
| 557 | } | |
| 558 | ||
| 559 | /** | |
| 0db41f1b J |
560 | * Override or insert variables into templates after preprocess functions have run. |
| 561 | * | |
| 562 | * @param $vars | |
| 563 | * An array of variables to pass to the theme template. | |
| 564 | * @param $hook | |
| 565 | * The name of the template being rendered. | |
| 566 | */ | |
| 567 | function zen_process(&$vars, $hook) { | |
| 337ff0a2 J |
568 | // Don't clobber Views 3 classes. |
| 569 | if (array_key_exists('classes_array', $vars) && !array_key_exists('classes', $vars)) { | |
| 17e89a6f J |
570 | $vars['classes'] = implode(' ', $vars['classes_array']); |
| 571 | } | |
| 28511ba8 J |
572 | } |
| 573 | ||
| 574 | /** | |
| 6f634acb J |
575 | * Override or insert variables into the block templates after preprocess functions have run. |
| 576 | * | |
| 577 | * @param $vars | |
| 578 | * An array of variables to pass to the theme template. | |
| 579 | * @param $hook | |
| 580 | * The name of the template being rendered ("block" in this case.) | |
| 581 | */ | |
| 582 | function zen_process_block(&$vars, $hook) { | |
| 583 | $vars['edit_links'] = !empty($vars['edit_links_array']) ? '<div class="edit">' . implode(' ', $vars['edit_links_array']) . '</div>' : ''; | |
| 584 | } | |
| 585 | ||
| a20a7825 J |
586 | if (!function_exists('drupal_html_class')) { |
| 587 | /** | |
| 588 | * Prepare a string for use as a valid class name. | |
| 589 | * | |
| 590 | * Do not pass one string containing multiple classes as they will be | |
| 591 | * incorrectly concatenated with dashes, i.e. "one two" will become "one-two". | |
| 592 | * | |
| 593 | * @param $class | |
| 594 | * The class name to clean. | |
| 595 | * @return | |
| 596 | * The cleaned class name. | |
| 597 | */ | |
| 598 | function drupal_html_class($class) { | |
| 599 | // By default, we filter using Drupal's coding standards. | |
| 600 | $class = strtr(drupal_strtolower($class), array(' ' => '-', '_' => '-', '/' => '-', '[' => '-', ']' => '')); | |
| 601 | ||
| 602 | // http://www.w3.org/TR/CSS21/syndata.html#characters shows the syntax for valid | |
| 603 | // CSS identifiers (including element names, classes, and IDs in selectors.) | |
| 604 | // | |
| 605 | // Valid characters in a CSS identifier are: | |
| 606 | // - the hyphen (U+002D) | |
| 607 | // - a-z (U+0030 - U+0039) | |
| 608 | // - A-Z (U+0041 - U+005A) | |
| 609 | // - the underscore (U+005F) | |
| 610 | // - 0-9 (U+0061 - U+007A) | |
| 611 | // - ISO 10646 characters U+00A1 and higher | |
| 612 | // We strip out any character not in the above list. | |
| 613 | $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); | |
| 614 | ||
| 615 | return $class; | |
| 616 | } | |
| 617 | } /* End of drupal_html_class conditional definition. */ | |
| 618 | ||
| 619 | if (!function_exists('drupal_html_id')) { | |
| 620 | /** | |
| 621 | * Prepare a string for use as a valid HTML ID and guarantee uniqueness. | |
| 622 | * | |
| 623 | * @param $id | |
| 624 | * The ID to clean. | |
| 625 | * @return | |
| 626 | * The cleaned ID. | |
| 627 | */ | |
| 628 | function drupal_html_id($id) { | |
| 629 | $id = strtr(drupal_strtolower($id), array(' ' => '-', '_' => '-', '[' => '-', ']' => '')); | |
| 630 | ||
| 631 | // As defined in http://www.w3.org/TR/html4/types.html#type-name, HTML IDs can | |
| 632 | // only contain letters, digits ([0-9]), hyphens ("-"), underscores ("_"), | |
| 633 | // colons (":"), and periods ("."). We strip out any character not in that | |
| 634 | // list. Note that the CSS spec doesn't allow colons or periods in identifiers | |
| 635 | // (http://www.w3.org/TR/CSS21/syndata.html#characters), so we strip those two | |
| 636 | // characters as well. | |
| 637 | $id = preg_replace('/[^A-Za-z0-9\-_]/', '', $id); | |
| 638 | ||
| 639 | return $id; | |
| 640 | } | |
| 641 | } /* End of drupal_html_id conditional definition. */ | |
| 3183d194 J |
642 | |
| 643 | /** | |
| 644 | * Returns the path to the Zen theme. | |
| 645 | * | |
| 646 | * drupal_get_filename() is broken; see #341140. When that is fixed in Drupal 6, | |
| 647 | * replace _zen_path() with drupal_get_path('theme', 'zen'). | |
| 648 | */ | |
| 649 | function _zen_path() { | |
| 650 | static $path = FALSE; | |
| 651 | if (!$path) { | |
| 652 | $matches = drupal_system_listing('zen\.info$', 'themes', 'name', 0); | |
| 653 | if (!empty($matches['zen']->filename)) { | |
| 654 | $path = dirname($matches['zen']->filename); | |
| 655 | } | |
| 656 | } | |
| 657 | return $path; | |
| 658 | } |