| Commit | Line | Data |
|---|---|---|
| 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 | ||
| 89804871 J |
16 | // Auto-rebuild the theme registry during theme development. |
| 17 | if (theme_get_setting('zen_rebuild_registry')) { | |
| 18 | drupal_rebuild_theme_registry(); | |
| 19 | } | |
| 7c5fa196 | 20 | |
| 719059ea | 21 | |
| 4f5c1d0c J |
22 | /** |
| 23 | * Implements HOOK_theme(). | |
| 52521ba9 | 24 | */ |
| 4f5c1d0c | 25 | function zen_theme(&$existing, $type, $theme, $path) { |
| c5199614 J |
26 | if (!db_is_active()) { |
| 27 | return array(); | |
| 28 | } | |
| 007fb748 | 29 | include_once './' . drupal_get_path('theme', 'zen') . '/zen-internals/template.theme-registry.inc'; |
| 4f5c1d0c J |
30 | return _zen_theme($existing, $type, $theme, $path); |
| 31 | } | |
| 52521ba9 | 32 | |
| 7c5fa196 J |
33 | /** |
| 34 | * Return a themed breadcrumb trail. | |
| 7081db43 | 35 | * |
| 7c5fa196 J |
36 | * @param $breadcrumb |
| 37 | * An array containing the breadcrumb links. | |
| 38 | * @return | |
| 39 | * A string containing the breadcrumb output. | |
| 7081db43 | 40 | */ |
| bdf1d868 | 41 | function zen_breadcrumb($breadcrumb) { |
| d60c8c02 | 42 | // Determine if we are to display the breadcrumb. |
| 59794464 | 43 | $show_breadcrumb = theme_get_setting('zen_breadcrumb'); |
| 52521ba9 | 44 | if ($show_breadcrumb == 'yes' || $show_breadcrumb == 'admin' && arg(0) == 'admin') { |
| 59794464 | 45 | |
| d60c8c02 | 46 | // Optionally get rid of the homepage link. |
| 59794464 | 47 | $show_breadcrumb_home = theme_get_setting('zen_breadcrumb_home'); |
| 52521ba9 | 48 | if (!$show_breadcrumb_home) { |
| 52521ba9 J |
49 | array_shift($breadcrumb); |
| 50 | } | |
| 59794464 | 51 | |
| d60c8c02 | 52 | // Return the breadcrumb with separators. |
| 52521ba9 | 53 | if (!empty($breadcrumb)) { |
| 59794464 | 54 | $breadcrumb_separator = theme_get_setting('zen_breadcrumb_separator'); |
| d60c8c02 J |
55 | $trailing_separator = $title = ''; |
| 56 | if (theme_get_setting('zen_breadcrumb_title')) { | |
| 57 | $trailing_separator = $breadcrumb_separator; | |
| 101297cb | 58 | $title = drupal_get_title(); |
| d60c8c02 J |
59 | } |
| 60 | elseif (theme_get_setting('zen_breadcrumb_trailing')) { | |
| 61 | $trailing_separator = $breadcrumb_separator; | |
| 62 | } | |
| 63 | return '<div class="breadcrumb">' . implode($breadcrumb_separator, $breadcrumb) . "$trailing_separator$title</div>"; | |
| 52521ba9 | 64 | } |
| 7c5fa196 | 65 | } |
| d60c8c02 | 66 | // Otherwise, return an empty string. |
| 52521ba9 | 67 | return ''; |
| 7c5fa196 J |
68 | } |
| 69 | ||
| 4f5c1d0c J |
70 | /** |
| 71 | * Implements theme_menu_item_link() | |
| 72 | */ | |
| 73 | function zen_menu_item_link($link) { | |
| 74 | if (empty($link['localized_options'])) { | |
| 75 | $link['localized_options'] = array(); | |
| 76 | } | |
| 77 | ||
| 78 | // If an item is a LOCAL TASK, render it as a tab | |
| 79 | if ($link['type'] & MENU_IS_LOCAL_TASK) { | |
| 80 | $link['title'] = '<span class="tab">' . check_plain($link['title']) . '</span>'; | |
| 81 | $link['localized_options']['html'] = TRUE; | |
| 82 | } | |
| 83 | ||
| 84 | return l($link['title'], $link['href'], $link['localized_options']); | |
| 85 | } | |
| 86 | ||
| 87 | /** | |
| 88 | * Duplicate of theme_menu_local_tasks() but adds clear-block to tabs. | |
| 89 | */ | |
| 90 | function zen_menu_local_tasks() { | |
| 91 | $output = ''; | |
| 92 | ||
| 93 | if ($primary = menu_primary_local_tasks()) { | |
| 94 | $output .= '<ul class="tabs primary clear-block">' . $primary . '</ul>'; | |
| 95 | } | |
| 96 | if ($secondary = menu_secondary_local_tasks()) { | |
| 97 | $output .= '<ul class="tabs secondary clear-block">' . $secondary . '</ul>'; | |
| 98 | } | |
| 99 | ||
| 100 | return $output; | |
| 101 | } | |
| 960bac1c | 102 | |
| 7c5fa196 | 103 | |
| 960bac1c | 104 | /** |
| 0b1037f4 | 105 | * Override or insert variables into the page templates. |
| 87695e28 J |
106 | * |
| 107 | * @param $vars | |
| 0b1037f4 | 108 | * An array of variables to pass to the theme template. |
| e6f4a124 | 109 | * @param $hook |
| 0b1037f4 | 110 | * The name of the template being rendered ("page" in this case.) |
| 87695e28 | 111 | */ |
| fcf0b3cc | 112 | function zen_preprocess_page(&$vars, $hook) { |
| 78d8d215 J |
113 | // If the user is silly and enables Zen as the theme, add some styles. |
| 114 | if ($GLOBALS['theme'] == 'zen') { | |
| 007fb748 | 115 | include_once './' . drupal_get_path('theme', 'zen') . '/zen-internals/template.zen.inc'; |
| 78d8d215 J |
116 | _zen_preprocess_page($vars, $hook); |
| 117 | } | |
| 719059ea | 118 | // Add conditional stylesheets. |
| 78d8d215 | 119 | elseif (!module_exists('conditional_styles')) { |
| 719059ea J |
120 | $vars['styles'] .= $vars['conditional_styles'] = variable_get('conditional_styles_' . $GLOBALS['theme'], ''); |
| 121 | } | |
| 122 | ||
| e0a8f494 J |
123 | // Classes for body element. Allows advanced theming based on context |
| 124 | // (home page, node of certain type, etc.) | |
| ad0416cf | 125 | $classes = explode(' ', $vars['body_classes']); |
| 6930eb03 J |
126 | // Remove the mostly useless page-ARG0 class. |
| 127 | if ($index = array_search(preg_replace('![^abcdefghijklmnopqrstuvwxyz0-9-_]+!s', '', 'page-'. drupal_strtolower(arg(0))), $classes)) { | |
| 128 | unset($classes[$index]); | |
| 129 | } | |
| e0a8f494 | 130 | if (!$vars['is_front']) { |
| 363d1497 | 131 | // Add unique class for each page. |
| 9faf4798 | 132 | $path = drupal_get_path_alias($_GET['q']); |
| 363d1497 J |
133 | $classes[] = zen_id_safe('page-' . $path); |
| 134 | // Add unique class for each website section. | |
| 8357c010 | 135 | list($section, ) = explode('/', $path, 2); |
| 28511ba8 J |
136 | if (arg(0) == 'node') { |
| 137 | if (arg(1) == 'add') { | |
| 363d1497 | 138 | $section = 'node-add'; |
| 28511ba8 J |
139 | } |
| 140 | elseif (is_numeric(arg(1)) && (arg(2) == 'edit' || arg(2) == 'delete')) { | |
| 363d1497 | 141 | $section = 'node-' . arg(2); |
| 28511ba8 J |
142 | } |
| 143 | } | |
| 363d1497 | 144 | $classes[] = zen_id_safe('section-' . $section); |
| 960bac1c | 145 | } |
| 2041a7c1 | 146 | if (theme_get_setting('zen_wireframes')) { |
| 363d1497 | 147 | $classes[] = 'with-wireframes'; // Optionally add the wireframes style. |
| 2041a7c1 | 148 | } |
| fdf6d8c0 J |
149 | // Add new sidebar classes in addition to Drupal core's sidebar-* classes. |
| 150 | // This provides some backwards compatibility with Zen 6.x-1.x themes. | |
| 2f37f103 J |
151 | if ($vars['layout'] != 'both') { |
| 152 | $new_layout = ($vars['layout'] == 'left') ? 'first' : 'second'; | |
| fdf6d8c0 J |
153 | if (array_search('sidebar-' . $vars['layout'], $classes)) { |
| 154 | $classes[] = 'sidebar-' . $new_layout; | |
| 2f37f103 | 155 | } |
| fdf6d8c0 | 156 | // Replace core's $layout variable with our naming of sidebars. |
| 2f37f103 | 157 | $vars['layout'] = $new_layout; |
| 536678ab | 158 | } |
| 007cbfc2 | 159 | $vars['body_classes_array'] = $classes; |
| 363d1497 | 160 | $vars['body_classes'] = implode(' ', $classes); // Concatenate with spaces. |
| e0a8f494 | 161 | } |
| 7c5fa196 | 162 | |
| e0a8f494 | 163 | /** |
| 0b1037f4 | 164 | * Override or insert variables into the node templates. |
| e0a8f494 J |
165 | * |
| 166 | * @param $vars | |
| 0b1037f4 | 167 | * An array of variables to pass to the theme template. |
| e6f4a124 | 168 | * @param $hook |
| 0b1037f4 | 169 | * The name of the template being rendered ("node" in this case.) |
| e0a8f494 | 170 | */ |
| fcf0b3cc | 171 | function zen_preprocess_node(&$vars, $hook) { |
| e0a8f494 | 172 | // Special classes for nodes |
| 23086957 | 173 | $classes = array('node'); |
| e0a8f494 | 174 | if ($vars['sticky']) { |
| 23086957 | 175 | $classes[] = 'sticky'; |
| e0a8f494 | 176 | } |
| b457ba98 | 177 | if (!$vars['status']) { |
| 23086957 | 178 | $classes[] = 'node-unpublished'; |
| 28511ba8 J |
179 | $vars['unpublished'] = TRUE; |
| 180 | } | |
| 181 | else { | |
| 182 | $vars['unpublished'] = FALSE; | |
| e0a8f494 | 183 | } |
| b457ba98 J |
184 | if ($vars['uid'] && $vars['uid'] == $GLOBALS['user']->uid) { |
| 185 | $classes[] = 'node-mine'; // Node is authored by current user. | |
| 7c5fa196 | 186 | } |
| e0a8f494 | 187 | if ($vars['teaser']) { |
| b457ba98 | 188 | $classes[] = 'node-teaser'; // Node is displayed as teaser. |
| e0a8f494 J |
189 | } |
| 190 | // Class for node type: "node-type-page", "node-type-story", "node-type-my-custom-type", etc. | |
| 4d7d1dc8 | 191 | $classes[] = zen_id_safe('node-type-' . $vars['type']); |
| 1f314b47 | 192 | $vars['classes_array'] = $classes; |
| 23086957 | 193 | $vars['classes'] = implode(' ', $classes); // Concatenate with spaces |
| e0a8f494 | 194 | } |
| 7c5fa196 | 195 | |
| e0a8f494 | 196 | /** |
| 0b1037f4 | 197 | * Override or insert variables into the comment templates. |
| e0a8f494 J |
198 | * |
| 199 | * @param $vars | |
| 0b1037f4 | 200 | * An array of variables to pass to the theme template. |
| e6f4a124 | 201 | * @param $hook |
| 0b1037f4 | 202 | * The name of the template being rendered ("comment" in this case.) |
| e0a8f494 | 203 | */ |
| fcf0b3cc | 204 | function zen_preprocess_comment(&$vars, $hook) { |
| 007fb748 | 205 | include_once './' . drupal_get_path('theme', 'zen') . '/zen-internals/template.comment.inc'; |
| 29ba6758 | 206 | _zen_preprocess_comment($vars, $hook); |
| 960bac1c | 207 | } |
| 4dd0f1bf JR |
208 | |
| 209 | /** | |
| 0b1037f4 | 210 | * Override or insert variables into the block templates. |
| 28511ba8 J |
211 | * |
| 212 | * @param $vars | |
| 0b1037f4 | 213 | * An array of variables to pass to the theme template. |
| e6f4a124 | 214 | * @param $hook |
| 0b1037f4 | 215 | * The name of the template being rendered ("block" in this case.) |
| 28511ba8 | 216 | */ |
| fcf0b3cc | 217 | function zen_preprocess_block(&$vars, $hook) { |
| 28511ba8 J |
218 | $block = $vars['block']; |
| 219 | ||
| 76772d59 | 220 | // Special classes for blocks. |
| 0bcb1dd5 J |
221 | $classes = array('block'); |
| 222 | $classes[] = 'block-' . $block->module; | |
| 223 | $classes[] = 'region-' . $vars['block_zebra']; | |
| 224 | $classes[] = $vars['zebra']; | |
| 225 | $classes[] = 'region-count-' . $vars['block_id']; | |
| 226 | $classes[] = 'count-' . $vars['id']; | |
| 28511ba8 | 227 | |
| a0e81398 | 228 | $vars['edit_links_array'] = array(); |
| 56ba2845 | 229 | $vars['edit_links'] = ''; |
| 28511ba8 | 230 | if (theme_get_setting('zen_block_editing') && user_access('administer blocks')) { |
| 007fb748 | 231 | include_once './' . drupal_get_path('theme', 'zen') . '/zen-internals/template.block-editing.inc'; |
| a0e81398 | 232 | zen_preprocess_block_editing($vars, $hook); |
| 9c9b5bbc | 233 | $classes[] = 'with-block-editing'; |
| 28511ba8 | 234 | } |
| 9c9b5bbc J |
235 | |
| 236 | // Render block classes. | |
| 1f314b47 | 237 | $vars['classes_array'] = $classes; |
| 9c9b5bbc | 238 | $vars['classes'] = implode(' ', $classes); |
| 28511ba8 J |
239 | } |
| 240 | ||
| 241 | /** | |
| 7c5fa196 J |
242 | * Converts a string to a suitable html ID attribute. |
| 243 | * | |
| 2bf29305 J |
244 | * http://www.w3.org/TR/html4/struct/global.html#h-7.5.2 specifies what makes a |
| 245 | * valid ID attribute in HTML. This function: | |
| 246 | * | |
| 4f5c1d0c | 247 | * - Ensure an ID starts with an alpha character by optionally adding an 'id'. |
| 4d7d1dc8 | 248 | * - Replaces any character except alphanumeric characters with dashes. |
| 7c5fa196 | 249 | * - Converts entire string to lowercase. |
| 7c5fa196 | 250 | * |
| 28511ba8 | 251 | * @param $string |
| 7c5fa196 J |
252 | * The string |
| 253 | * @return | |
| 254 | * The converted string | |
| 255 | */ | |
| 4dd0f1bf | 256 | function zen_id_safe($string) { |
| 2bf29305 | 257 | // Replace with dashes anything that isn't A-Z, numbers, dashes, or underscores. |
| 4d7d1dc8 J |
258 | $string = strtolower(preg_replace('/[^a-zA-Z0-9-]+/', '-', $string)); |
| 259 | // If the first character is not a-z, add 'id' in front. | |
| 2bf29305 J |
260 | if (!ctype_lower($string{0})) { // Don't use ctype_alpha since its locale aware. |
| 261 | $string = 'id' . $string; | |
| 4dd0f1bf | 262 | } |
| 2bf29305 | 263 | return $string; |
| 7c5fa196 | 264 | } |