| Commit | Line | Data |
|---|---|---|
| 15fe5a55 J |
1 | <?php |
| 2 | // $Id$ | |
| 3 | ||
| 4 | /** | |
| 5 | * @file | |
| 6 | * | |
| 2502b3b4 J |
7 | * OVERRIDING THEME FUNCTIONS |
| 8 | * | |
| 9 | * The Drupal theme system uses special theme functions to generate HTML output | |
| 10 | * automatically. Often we wish to customize this HTML output. To do this, we | |
| 11 | * have to override the theme function. You have to first find the theme | |
| 12 | * function that generates the output, and then "catch" it and modify it here. | |
| 13 | * The easiest way to do it is to copy the original function in its entirety and | |
| 14 | * paste it here, changing the prefix from theme_ to phptemplate_ or zen_. For | |
| 15 | * example: | |
| 16 | * | |
| 17 | * original: theme_breadcrumb() | |
| 18 | * theme override: zen_breadcrumb() | |
| 19 | * | |
| 20 | * DIFFERENCES BETWEEN ZEN SUB-THEMES AND NORMAL DRUPAL SUB-THEMES | |
| 21 | * | |
| 15fe5a55 J |
22 | * The Zen theme allows its sub-themes to have their own template.php files. The |
| 23 | * only restriction with these files is that they cannot redefine any of the | |
| 24 | * functions that are already defined in Zen's main template files: | |
| 2502b3b4 J |
25 | * template.php, template-menus.php, and template-subtheme.php. |
| 26 | * Any theme override function used in those files is documented below. | |
| 15fe5a55 | 27 | * |
| 2502b3b4 J |
28 | * Also remember that the "main" theme is still Zen, so your theme theme |
| 29 | * override functions should be named as such: | |
| 15fe5a55 J |
30 | * theme_block() becomes zen_block() |
| 31 | * theme_feed_icon() becomes zen_feed_icon() as well | |
| 32 | * | |
| 2502b3b4 J |
33 | * Normally, for a theme to define its own regions, you would use the |
| 34 | * THEME_regions() fuction. But for a Zen sub-theme to define its own regions, | |
| 35 | * use the function name | |
| 15fe5a55 J |
36 | * SUBTHEME_regions() |
| 37 | * where SUBTHEME is the name of your sub-theme. For example, the zen_classic | |
| 38 | * theme would define a zen_classic_regions() function. | |
| 39 | * | |
| 2502b3b4 J |
40 | * For a sub-theme to add its own variables, instead of _phptemplate_variables, |
| 41 | * use these functions: | |
| 6c18217d J |
42 | * SUBTHEME_preprocess_page(&$vars) |
| 43 | * SUBTHEME_preprocess_node(&$vars) | |
| 44 | * SUBTHEME_preprocess_comment(&$vars) | |
| 2502b3b4 | 45 | * SUBTHEME_preprocess_block(&$vars) |
| 15fe5a55 J |
46 | */ |
| 47 | ||
| 48 | ||
| 49 | /* | |
| 50 | * Initialize theme settings | |
| 51 | */ | |
| 52 | include_once 'theme-settings-init.php'; | |
| 53 | ||
| 54 | ||
| 55 | /* | |
| 56 | * Sub-themes with their own page.tpl.php files are seen by PHPTemplate as their | |
| 57 | * own theme (seperate from Zen). So we need to re-connect those sub-themes | |
| 58 | * with the main Zen theme. | |
| 59 | */ | |
| 60 | include_once './'. drupal_get_path('theme', 'zen') .'/template.php'; | |
| 61 | ||
| 62 | ||
| 63 | /* | |
| 64 | * Add the stylesheets you will need for this sub-theme. | |
| 65 | * | |
| 66 | * To add stylesheets that are in the main Zen folder, use path_to_theme(). | |
| 67 | * To add stylesheets thar are in your sub-theme's folder, use path_to_subtheme(). | |
| 68 | */ | |
| 69 | ||
| 70 | // Add any stylesheets you would like from the main Zen theme. | |
| 71 | drupal_add_css(path_to_theme() .'/html-elements.css', 'theme', 'all'); | |
| 72 | drupal_add_css(path_to_theme() .'/tabs.css', 'theme', 'all'); | |
| 73 | ||
| 74 | // Then add styles for this sub-theme. | |
| 75 | drupal_add_css(path_to_subtheme() .'/layout.css', 'theme', 'all'); | |
| 76 | drupal_add_css(path_to_subtheme() .'/SUBTHEME.css', 'theme', 'all'); | |
| 77 | ||
| 78 | // Avoid IE5 bug that always loads @import print stylesheets | |
| 79 | zen_add_print_css(path_to_subtheme() .'/print.css'); | |
| 80 | ||
| 81 | ||
| 82 | /** | |
| 83 | * Declare the available regions implemented by this theme. | |
| 84 | * | |
| 85 | * @return | |
| 86 | * An array of regions. | |
| 87 | */ | |
| 88 | /* -- Delete this line if you want to use this function | |
| 89 | function SUBTHEME_regions() { | |
| 90 | return array( | |
| 91 | 'left' => t('left sidebar'), | |
| 92 | 'right' => t('right sidebar'), | |
| 93 | 'navbar' => t('navigation bar'), | |
| 94 | 'content_top' => t('content top'), | |
| 95 | 'content_bottom' => t('content bottom'), | |
| 96 | 'header' => t('header'), | |
| 97 | 'footer' => t('footer'), | |
| 98 | 'closure_region' => t('closure'), | |
| 99 | ); | |
| 100 | } | |
| 101 | // */ | |
| 102 | ||
| 103 | ||
| 104 | /** | |
| 2f573a33 J |
105 | * Return a themed breadcrumb trail. |
| 106 | * | |
| 107 | * @param $breadcrumb | |
| 108 | * An array containing the breadcrumb links. | |
| 109 | * @return | |
| 110 | * A string containing the breadcrumb output. | |
| 111 | */ | |
| 112 | /* -- Delete this line if you want to use this function | |
| 113 | function zen_breadcrumb($breadcrumb) { | |
| 114 | return '<div class="breadcrumb">'. implode(' › ', $breadcrumb) .' ›</div>'; | |
| 115 | } | |
| 116 | // */ | |
| 117 | ||
| 118 | ||
| 119 | /** | |
| 15fe5a55 J |
120 | * Override or insert PHPTemplate variables into the page templates. |
| 121 | * | |
| 122 | * @param $vars | |
| 123 | * A sequential array of variables to pass to the theme template. | |
| 124 | */ | |
| 125 | /* -- Delete this line if you want to use this function | |
| 6c18217d | 126 | function SUBTHEME_preprocess_page(&$vars) { |
| 15fe5a55 J |
127 | $vars['sample_variable'] = t('Lorem ipsum.'); |
| 128 | } | |
| 129 | // */ | |
| 130 | ||
| 131 | /** | |
| 132 | * Override or insert PHPTemplate variables into the node templates. | |
| 133 | * | |
| 134 | * @param $vars | |
| 135 | * A sequential array of variables to pass to the theme template. | |
| 136 | */ | |
| 137 | /* -- Delete this line if you want to use this function | |
| 6c18217d | 138 | function SUBTHEME_preprocess_node(&$vars) { |
| 15fe5a55 J |
139 | $vars['sample_variable'] = t('Lorem ipsum.'); |
| 140 | } | |
| 141 | // */ | |
| 142 | ||
| 143 | /** | |
| 144 | * Override or insert PHPTemplate variables into the comment templates. | |
| 145 | * | |
| 146 | * @param $vars | |
| 147 | * A sequential array of variables to pass to the theme template. | |
| 148 | */ | |
| 149 | /* -- Delete this line if you want to use this function | |
| 6c18217d | 150 | function SUBTHEME_preprocess_comment(&$vars) { |
| 15fe5a55 J |
151 | $vars['sample_variable'] = t('Lorem ipsum.'); |
| 152 | } | |
| 153 | // */ | |
| 154 | ||
| 39bce758 J |
155 | /** |
| 156 | * Override or insert PHPTemplate variables into the block templates. | |
| 157 | * | |
| 158 | * @param $vars | |
| 159 | * A sequential array of variables to pass to the theme template. | |
| 160 | */ | |
| 161 | /* -- Delete this line if you want to use this function | |
| 162 | function SUBTHEME_preprocess_block(&$vars) { | |
| 163 | $vars['sample_variable'] = t('Lorem ipsum.'); | |
| 164 | } | |
| 165 | // */ | |
| 166 | ||
| 15fe5a55 J |
167 | |
| 168 | /** | |
| 169 | * Override the Drupal search form using the search-theme-form.tpl.php file. | |
| 170 | */ | |
| 171 | /* -- Delete this line if you want to use this function | |
| 94dd41dc | 172 | function phptemplate_search_theme_form($form) { |
| 797dcb9a | 173 | return _phptemplate_callback('search_theme_form', array('form' => $form), array('search-theme-form')); |
| 15fe5a55 J |
174 | } |
| 175 | // */ | |
| 2f573a33 J |
176 | |
| 177 | /** | |
| 178 | * Generate the HTML representing a given menu item ID. | |
| 179 | * | |
| 180 | * An implementation of theme_menu_item_link() | |
| 181 | * | |
| 182 | * @param $item | |
| 183 | * array The menu item to render. | |
| 184 | * @param $link_item | |
| 185 | * array The menu item which should be used to find the correct path. | |
| 186 | * @return | |
| 187 | * string The rendered menu item. | |
| 188 | */ | |
| 189 | /* -- Delete this line if you want to use this function | |
| 190 | function zen_menu_item_link($item, $link_item) { | |
| 191 | // If an item is a LOCAL TASK, render it as a tab | |
| 192 | $tab = ($item['type'] & MENU_IS_LOCAL_TASK) ? TRUE : FALSE; | |
| 193 | return l( | |
| 194 | $tab ? '<span class="tab">'. check_plain($item['title']) .'</span>' : $item['title'], | |
| 195 | $link_item['path'], | |
| 196 | !empty($item['description']) ? array('title' => $item['description']) : array(), | |
| 197 | !empty($item['query']) ? $item['query'] : NULL, | |
| 198 | !empty($link_item['fragment']) ? $link_item['fragment'] : NULL, | |
| 199 | FALSE, | |
| 200 | $tab | |
| 201 | ); | |
| 202 | } | |
| 203 | // */ | |
| 204 | ||
| 205 | /** | |
| 206 | * Duplicate of theme_menu_local_tasks() but adds clear-block to tabs. | |
| 207 | */ | |
| 208 | /* -- Delete this line if you want to use this function | |
| 209 | function zen_menu_local_tasks() { | |
| 210 | $output = ''; | |
| 211 | ||
| 212 | if ($primary = menu_primary_local_tasks()) { | |
| 213 | $output .= '<ul class="tabs primary clear-block">'. $primary .'</ul>'; | |
| 214 | } | |
| 215 | if ($secondary = menu_secondary_local_tasks()) { | |
| 216 | $output .= '<ul class="tabs secondary clear-block">'. $secondary .'</ul>'; | |
| 217 | } | |
| 218 | ||
| 219 | return $output; | |
| 220 | } | |
| 221 | // */ | |
| ba05d520 J |
222 | |
| 223 | /** | |
| 224 | * Overriding theme_comment_wrapper to add CSS id around all comments | |
| 225 | * and add "Comments" title above | |
| 226 | */ | |
| 227 | /* -- Delete this line if you want to use this function | |
| 228 | function SUBTHEME_comment_wrapper($content) { | |
| 229 | return '<div id="comments"><h2 id="comments-title" class="title">'. t('Comments') .'</h2>'. $content .'</div>'; | |
| 230 | } | |
| 231 | // */ | |
| 232 | ||
| 233 | /** | |
| 234 | * Duplicate of theme_username() with rel=nofollow added for commentators. | |
| 235 | */ | |
| 236 | /* -- Delete this line if you want to use this function | |
| 237 | function SUBTHEME_username($object) { | |
| 238 | ||
| 239 | if ($object->uid && $object->name) { | |
| 240 | // Shorten the name when it is too long or it will break many tables. | |
| 241 | if (drupal_strlen($object->name) > 20) { | |
| 242 | $name = drupal_substr($object->name, 0, 15) .'...'; | |
| 243 | } | |
| 244 | else { | |
| 245 | $name = $object->name; | |
| 246 | } | |
| 247 | ||
| 248 | if (user_access('access user profiles')) { | |
| 249 | $output = l($name, 'user/'. $object->uid, array('title' => t('View user profile.'))); | |
| 250 | } | |
| 251 | else { | |
| 252 | $output = check_plain($name); | |
| 253 | } | |
| 254 | } | |
| 255 | else if ($object->name) { | |
| 256 | // Sometimes modules display content composed by people who are | |
| 257 | // not registered members of the site (e.g. mailing list or news | |
| 258 | // aggregator modules). This clause enables modules to display | |
| 259 | // the true author of the content. | |
| 260 | if ($object->homepage) { | |
| 261 | $output = l($object->name, $object->homepage, array('rel' => 'nofollow')); | |
| 262 | } | |
| 263 | else { | |
| 264 | $output = check_plain($object->name); | |
| 265 | } | |
| 266 | ||
| 267 | $output .= ' ('. t('not verified') .')'; | |
| 268 | } | |
| 269 | else { | |
| 270 | $output = variable_get('anonymous', t('Anonymous')); | |
| 271 | } | |
| 272 | ||
| 273 | return $output; | |
| 274 | } | |
| 275 | // */ |