| 1 |
<?php
|
| 2 |
// Tabs and menu functions
|
| 3 |
include_once 'template-menus.php';
|
| 4 |
|
| 5 |
|
| 6 |
/**
|
| 7 |
* Return a themed breadcrumb trail.
|
| 8 |
*
|
| 9 |
* @param $breadcrumb
|
| 10 |
* An array containing the breadcrumb links.
|
| 11 |
* @return
|
| 12 |
* A string containing the breadcrumb output.
|
| 13 |
*/
|
| 14 |
function ad_redoable_breadcrumb($breadcrumb) {
|
| 15 |
$show_breadcrumb = theme_get_setting('ad_redoable_breadcrumb');
|
| 16 |
$show_breadcrumb_home = theme_get_setting('ad_redoable_breadcrumb_home');
|
| 17 |
$breadcrumb_separator = theme_get_setting('ad_redoable_breadcrumb_separator');
|
| 18 |
$trailing_separator = (theme_get_setting('ad_redoable_breadcrumb_trailing') || theme_get_setting('ad_redoable_breadcrumb_title')) ? $breadcrumb_separator : '';
|
| 19 |
|
| 20 |
// Determine if we are to display the breadcrumb
|
| 21 |
if ($show_breadcrumb == 'yes' || $show_breadcrumb == 'admin' && arg(0) == 'admin') {
|
| 22 |
if (!$show_breadcrumb_home) {
|
| 23 |
// Optionally get rid of the homepage link
|
| 24 |
array_shift($breadcrumb);
|
| 25 |
}
|
| 26 |
if (!empty($breadcrumb)) {
|
| 27 |
// Return the breadcrumb with separators
|
| 28 |
return '<div class="breadcrumb">' . implode($breadcrumb_separator, $breadcrumb) . "$trailing_separator</div>";
|
| 29 |
}
|
| 30 |
}
|
| 31 |
// Otherwise, return an empty string
|
| 32 |
return '';
|
| 33 |
}
|
| 34 |
|
| 35 |
|
| 36 |
/*
|
| 37 |
* CREATE OR MODIFY VARIABLES FOR YOUR THEME
|
| 38 |
*
|
| 39 |
* The most powerful functions available to themers are the
|
| 40 |
* THEME_preprocess_HOOK() functions. They allow you to pass newly created
|
| 41 |
* variables to different template (tpl.php) files in your theme. Or even unset
|
| 42 |
* ones you don't want to use.
|
| 43 |
*
|
| 44 |
* It works by switching on the hook, or name of the theme function, such as:
|
| 45 |
* - page
|
| 46 |
* - node
|
| 47 |
* - comment
|
| 48 |
* - block
|
| 49 |
*
|
| 50 |
* By switching on this hook you can send different variables to page.tpl.php
|
| 51 |
* file, node.tpl.php (and any other derivative node template file, like
|
| 52 |
* node-forum.tpl.php), comment.tpl.php, and block.tpl.php.
|
| 53 |
*/
|
| 54 |
|
| 55 |
|
| 56 |
/**
|
| 57 |
* Override or insert PHPTemplate variables into the page templates.
|
| 58 |
*
|
| 59 |
* @param $vars
|
| 60 |
* A sequential array of variables to pass to the theme template.
|
| 61 |
* @param $hook
|
| 62 |
* The name of the theme function being called ("page" in this case.)
|
| 63 |
*/
|
| 64 |
function ad_redoable_preprocess_page(&$vars, $hook) {
|
| 65 |
global $theme;
|
| 66 |
|
| 67 |
// Optionally add the block editing styles.
|
| 68 |
if (theme_get_setting('ad_redoable_block_editing')) {
|
| 69 |
drupal_add_css(path_to_ad_redoabletheme() . '/block-editing.css', 'theme', 'all');
|
| 70 |
}
|
| 71 |
|
| 72 |
// Allow sub-themes to have an ie.css file
|
| 73 |
$vars['ad_redoabletheme_directory'] = path_to_ad_redoabletheme();
|
| 74 |
|
| 75 |
// Add an optional title to the end of the breadcrumb.
|
| 76 |
if (theme_get_setting('ad_redoable_breadcrumb_title') && $vars['breadcrumb']) {
|
| 77 |
$vars['breadcrumb'] = substr($vars['breadcrumb'], 0, -6) . $vars['title'] . '</div>';
|
| 78 |
}
|
| 79 |
|
| 80 |
// Don't display empty help from node_help().
|
| 81 |
if ($vars['help'] == "<div class=\"help\"><p></p>\n</div>") {
|
| 82 |
$vars['help'] = '';
|
| 83 |
}
|
| 84 |
|
| 85 |
// Classes for body element. Allows advanced theming based on context
|
| 86 |
// (home page, node of certain type, etc.)
|
| 87 |
$body_classes = array($vars['body_classes']);
|
| 88 |
if (!$vars['is_front']) {
|
| 89 |
// Add unique classes for each page and website section
|
| 90 |
$path = drupal_get_path_alias($_GET['q']);
|
| 91 |
list($section, ) = explode('/', $path, 2);
|
| 92 |
$body_classes[] = ad_redoable_id_safe('page-' . $path);
|
| 93 |
$body_classes[] = ad_redoable_id_safe('section-' . $section);
|
| 94 |
if (arg(0) == 'node') {
|
| 95 |
if (arg(1) == 'add') {
|
| 96 |
if ($section == 'node') {
|
| 97 |
array_pop($body_classes); // Remove 'section-node'
|
| 98 |
}
|
| 99 |
$body_classes[] = 'section-node-add'; // Add 'section-node-add'
|
| 100 |
}
|
| 101 |
elseif (is_numeric(arg(1)) && (arg(2) == 'edit' || arg(2) == 'delete')) {
|
| 102 |
if ($section == 'node') {
|
| 103 |
array_pop($body_classes); // Remove 'section-node'
|
| 104 |
}
|
| 105 |
$body_classes[] = 'section-node-' . arg(2); // Add 'section-node-edit' or 'section-node-delete'
|
| 106 |
}
|
| 107 |
}
|
| 108 |
}
|
| 109 |
$vars['body_classes'] = implode(' ', $body_classes); // Concatenate with spaces
|
| 110 |
}
|
| 111 |
|
| 112 |
/**
|
| 113 |
* Override or insert PHPTemplate variables into the node templates.
|
| 114 |
*
|
| 115 |
* @param $vars
|
| 116 |
* A sequential array of variables to pass to the theme template.
|
| 117 |
* @param $hook
|
| 118 |
* The name of the theme function being called ("node" in this case.)
|
| 119 |
*/
|
| 120 |
function ad_redoable_preprocess_node(&$vars, $hook) {
|
| 121 |
global $user;
|
| 122 |
|
| 123 |
// Special classes for nodes
|
| 124 |
$node_classes = array();
|
| 125 |
if ($vars['sticky']) {
|
| 126 |
$node_classes[] = 'sticky';
|
| 127 |
}
|
| 128 |
if (!$vars['node']->status) {
|
| 129 |
$node_classes[] = 'node-unpublished';
|
| 130 |
$vars['unpublished'] = TRUE;
|
| 131 |
}
|
| 132 |
else {
|
| 133 |
$vars['unpublished'] = FALSE;
|
| 134 |
}
|
| 135 |
if ($vars['node']->uid && $vars['node']->uid == $user->uid) {
|
| 136 |
// Node is authored by current user
|
| 137 |
$node_classes[] = 'node-mine';
|
| 138 |
}
|
| 139 |
if ($vars['teaser']) {
|
| 140 |
// Node is displayed as teaser
|
| 141 |
$node_classes[] = 'node-teaser';
|
| 142 |
}
|
| 143 |
// Class for node type: "node-type-page", "node-type-story", "node-type-my-custom-type", etc.
|
| 144 |
$node_classes[] = 'node-type-' . $vars['node']->type;
|
| 145 |
$vars['node_classes'] = implode(' ', $node_classes); // Concatenate with spaces
|
| 146 |
}
|
| 147 |
|
| 148 |
/**
|
| 149 |
* Override or insert PHPTemplate variables into the comment templates.
|
| 150 |
*
|
| 151 |
* @param $vars
|
| 152 |
* A sequential array of variables to pass to the theme template.
|
| 153 |
* @param $hook
|
| 154 |
* The name of the theme function being called ("comment" in this case.)
|
| 155 |
*/
|
| 156 |
function ad_redoable_preprocess_comment(&$vars, $hook) {
|
| 157 |
global $user;
|
| 158 |
|
| 159 |
// We load the node object that the current comment is attached to
|
| 160 |
$node = node_load($vars['comment']->nid);
|
| 161 |
// If the author of this comment is equal to the author of the node, we
|
| 162 |
// set a variable so we can theme this comment uniquely.
|
| 163 |
$vars['author_comment'] = $vars['comment']->uid == $node->uid ? TRUE : FALSE;
|
| 164 |
|
| 165 |
$comment_classes = array();
|
| 166 |
|
| 167 |
// Odd/even handling
|
| 168 |
static $comment_odd = TRUE;
|
| 169 |
$comment_classes[] = $comment_odd ? 'odd' : 'even';
|
| 170 |
$comment_odd = !$comment_odd;
|
| 171 |
|
| 172 |
if ($vars['comment']->status == COMMENT_NOT_PUBLISHED) {
|
| 173 |
$comment_classes[] = 'comment-unpublished';
|
| 174 |
$vars['unpublished'] = TRUE;
|
| 175 |
}
|
| 176 |
else {
|
| 177 |
$vars['unpublished'] = FALSE;
|
| 178 |
}
|
| 179 |
if ($vars['author_comment']) {
|
| 180 |
// Comment is by the node author
|
| 181 |
$comment_classes[] = 'comment-by-author';
|
| 182 |
}
|
| 183 |
if ($vars['comment']->uid == 0) {
|
| 184 |
// Comment is by an anonymous user
|
| 185 |
$comment_classes[] = 'comment-by-anon';
|
| 186 |
}
|
| 187 |
if ($user->uid && $vars['comment']->uid == $user->uid) {
|
| 188 |
// Comment was posted by current user
|
| 189 |
$comment_classes[] = 'comment-mine';
|
| 190 |
}
|
| 191 |
$vars['comment_classes'] = implode(' ', $comment_classes);
|
| 192 |
|
| 193 |
// If comment subjects are disabled, don't display 'em
|
| 194 |
if (variable_get('comment_subject_field', 1) == 0) {
|
| 195 |
$vars['title'] = '';
|
| 196 |
}
|
| 197 |
}
|
| 198 |
|
| 199 |
/**
|
| 200 |
* Override or insert PHPTemplate variables into the block templates.
|
| 201 |
*
|
| 202 |
* @param $vars
|
| 203 |
* A sequential array of variables to pass to the theme template.
|
| 204 |
* @param $hook
|
| 205 |
* The name of the theme function being called ("block" in this case.)
|
| 206 |
*/
|
| 207 |
function ad_redoable_preprocess_block(&$vars, $hook) {
|
| 208 |
$block = $vars['block'];
|
| 209 |
|
| 210 |
// Special classes for blocks
|
| 211 |
$block_classes = array();
|
| 212 |
$block_classes[] = 'block-' . $block->module;
|
| 213 |
$block_classes[] = 'region-' . $vars['block_zebra'];
|
| 214 |
$block_classes[] = $vars['zebra'];
|
| 215 |
$block_classes[] = 'region-count-' . $vars['block_id'];
|
| 216 |
$block_classes[] = 'count-' . $vars['id'];
|
| 217 |
$vars['block_classes'] = implode(' ', $block_classes);
|
| 218 |
|
| 219 |
$vars['edit_links'] = '';
|
| 220 |
if (theme_get_setting('ad_redoable_block_editing') && user_access('administer blocks')) {
|
| 221 |
// Display 'edit block' for custom blocks
|
| 222 |
if ($block->module == 'block') {
|
| 223 |
$edit_links[] = l('<span>' . t('edit block') . '</span>', 'admin/build/block/configure/' . $block->module . '/' . $block->delta,
|
| 224 |
array(
|
| 225 |
'attributes' => array(
|
| 226 |
'title' => t('edit the content of this block'),
|
| 227 |
'class' => 'block-edit',
|
| 228 |
),
|
| 229 |
'query' => drupal_get_destination(),
|
| 230 |
'html' => TRUE,
|
| 231 |
)
|
| 232 |
);
|
| 233 |
}
|
| 234 |
// Display 'configure' for other blocks
|
| 235 |
else {
|
| 236 |
$edit_links[] = l('<span>' . t('configure') . '</span>', 'admin/build/block/configure/' . $block->module . '/' . $block->delta,
|
| 237 |
array(
|
| 238 |
'attributes' => array(
|
| 239 |
'title' => t('configure this block'),
|
| 240 |
'class' => 'block-config',
|
| 241 |
),
|
| 242 |
'query' => drupal_get_destination(),
|
| 243 |
'html' => TRUE,
|
| 244 |
)
|
| 245 |
);
|
| 246 |
}
|
| 247 |
|
| 248 |
// Display 'administer views' for views blocks
|
| 249 |
if ($block->module == 'views' && user_access('administer views')) {
|
| 250 |
$edit_links[] = l('<span>' . t('edit view') . '</span>', 'admin/build/views/' . $block->delta . '/edit',
|
| 251 |
array(
|
| 252 |
'attributes' => array(
|
| 253 |
'title' => t('edit the view that defines this block'),
|
| 254 |
'class' => 'block-edit-view',
|
| 255 |
),
|
| 256 |
'query' => drupal_get_destination(),
|
| 257 |
'fragment' => 'edit-block',
|
| 258 |
'html' => TRUE,
|
| 259 |
)
|
| 260 |
);
|
| 261 |
}
|
| 262 |
// Display 'edit menu' for menu blocks
|
| 263 |
elseif (($block->module == 'menu' || ($block->module == 'user' && $block->delta == 1)) && user_access('administer menu')) {
|
| 264 |
$menu_name = ($block->module == 'user') ? 'navigation' : $block->delta;
|
| 265 |
$edit_links[] = l('<span>' . t('edit menu') . '</span>', 'admin/build/menu-customize/' . $menu_name,
|
| 266 |
array(
|
| 267 |
'attributes' => array(
|
| 268 |
'title' => t('edit the menu that defines this block'),
|
| 269 |
'class' => 'block-edit-menu',
|
| 270 |
),
|
| 271 |
'query' => drupal_get_destination(),
|
| 272 |
'html' => TRUE,
|
| 273 |
)
|
| 274 |
);
|
| 275 |
}
|
| 276 |
$vars['edit_links_array'] = $edit_links;
|
| 277 |
$vars['edit_links'] = '<div class="edit">' . implode(' ', $edit_links) . '</div>';
|
| 278 |
}
|
| 279 |
}
|
| 280 |
|
| 281 |
/**
|
| 282 |
* Converts a string to a suitable html ID attribute.
|
| 283 |
*
|
| 284 |
* http://www.w3.org/TR/html4/struct/global.html#h-7.5.2 specifies what makes a
|
| 285 |
* valid ID attribute in HTML. This function:
|
| 286 |
*
|
| 287 |
* - Ensure an ID starts with an alpha character by optionally adding an 'n'.
|
| 288 |
* - Replaces any character except A-Z, numbers, and underscores with dashes.
|
| 289 |
* - Converts entire string to lowercase.
|
| 290 |
*
|
| 291 |
* @param $string
|
| 292 |
* The string
|
| 293 |
* @return
|
| 294 |
* The converted string
|
| 295 |
*/
|
| 296 |
function ad_redoable_id_safe($string) {
|
| 297 |
// Replace with dashes anything that isn't A-Z, numbers, dashes, or underscores.
|
| 298 |
$string = strtolower(preg_replace('/[^a-zA-Z0-9_-]+/', '-', $string));
|
| 299 |
// If the first character is not a-z, add 'n' in front.
|
| 300 |
if (!ctype_lower($string{0})) { // Don't use ctype_alpha since its locale aware.
|
| 301 |
$string = 'id' . $string;
|
| 302 |
}
|
| 303 |
return $string;
|
| 304 |
}
|
| 305 |
|
| 306 |
/**
|
| 307 |
* Return the path to the main ad_redoable theme directory.
|
| 308 |
*/
|
| 309 |
function path_to_ad_redoabletheme() {
|
| 310 |
static $theme_path;
|
| 311 |
if (!isset($theme_path)) {
|
| 312 |
global $theme;
|
| 313 |
if ($theme == 'ad_redoable') {
|
| 314 |
$theme_path = path_to_theme();
|
| 315 |
}
|
| 316 |
else {
|
| 317 |
$theme_path = drupal_get_path('theme', 'ad_redoable');
|
| 318 |
}
|
| 319 |
}
|
| 320 |
return $theme_path;
|
| 321 |
}
|
| 322 |
|
| 323 |
/**
|
| 324 |
* Implementation of HOOK_theme().
|
| 325 |
*
|
| 326 |
* The ad_redoable base theme uses this function as a work-around for a bug in Drupal
|
| 327 |
* 6.0-6.2: #252430 (Allow BASETHEME_ prefix in preprocessor function names).
|
| 328 |
*
|
| 329 |
* Sub-themes Also use this function by calling it from their HOOK_theme() in
|
| 330 |
* order to get around a design limitation in Drupal 6: #249532 (Allow subthemes
|
| 331 |
* to have preprocess hooks without tpl files.)
|
| 332 |
*
|
| 333 |
* @param $existing
|
| 334 |
* An array of existing implementations that may be used for override purposes.
|
| 335 |
* @param $type
|
| 336 |
* What 'type' is being processed.
|
| 337 |
* @param $theme
|
| 338 |
* The actual name of theme that is being being checked.
|
| 339 |
* @param $path
|
| 340 |
* The directory path of the theme or module, so that it doesn't need to be looked up.
|
| 341 |
*/
|
| 342 |
function ad_redoable_theme(&$existing, $type, $theme, $path) {
|
| 343 |
// Each theme has two possible preprocess functions that can act on a hook.
|
| 344 |
// This function applies to every hook.
|
| 345 |
$functions[0] = $theme . '_preprocess';
|
| 346 |
// Inspect the preprocess functions for every hook in the theme registry.
|
| 347 |
// @TODO: When PHP 5 becomes required (ad_redoable 7.x), use the following faster
|
| 348 |
// implementation: foreach ($existing AS $hook => &$value) {}
|
| 349 |
foreach (array_keys($existing) AS $hook) {
|
| 350 |
// Each theme has two possible preprocess functions that can act on a hook.
|
| 351 |
// This function only applies to this hook.
|
| 352 |
$functions[1] = $theme . '_preprocess_' . $hook;
|
| 353 |
foreach ($functions AS $key => $function) {
|
| 354 |
// Add any functions that are not already in the registry.
|
| 355 |
if (function_exists($function) && !in_array($function, $existing[$hook]['preprocess functions'])) {
|
| 356 |
// We add the preprocess function to the end of the existing list.
|
| 357 |
$existing[$hook]['preprocess functions'][] = $function;
|
| 358 |
}
|
| 359 |
}
|
| 360 |
}
|
| 361 |
|
| 362 |
// Since we are rebuilding the theme registry and the theme settings' default
|
| 363 |
// values may have changed, make sure they are saved in the database properly.
|
| 364 |
ad_redoable_settings_init($theme);
|
| 365 |
|
| 366 |
// Since we modify the $existing cache directly, return nothing.
|
| 367 |
return array();
|
| 368 |
}
|
| 369 |
|
| 370 |
/**
|
| 371 |
* Read the theme settings' default values from the .info and save them into the database.
|
| 372 |
*
|
| 373 |
* @param $theme
|
| 374 |
* The actual name of theme that is being being checked.
|
| 375 |
*/
|
| 376 |
function ad_redoable_settings_init($theme) {
|
| 377 |
$themes = list_themes();
|
| 378 |
|
| 379 |
// Get the default values from the .info file.
|
| 380 |
$defaults = $themes[$theme]->info['settings'];
|
| 381 |
|
| 382 |
// Get the theme settings saved in the database.
|
| 383 |
$settings = theme_get_settings($theme);
|
| 384 |
// Don't save the toggle_node_info_ variables.
|
| 385 |
if (module_exists('node')) {
|
| 386 |
foreach (node_get_types() as $type => $name) {
|
| 387 |
unset($settings['toggle_node_info_' . $type]);
|
| 388 |
}
|
| 389 |
}
|
| 390 |
// Save default theme settings.
|
| 391 |
variable_set(
|
| 392 |
str_replace('/', '_', 'theme_' . $theme . '_settings'),
|
| 393 |
array_merge($defaults, $settings)
|
| 394 |
);
|
| 395 |
// Force refresh of Drupal internals.
|
| 396 |
theme_get_setting('', TRUE);
|
| 397 |
}
|
| 398 |
|
| 399 |
/*
|
| 400 |
* In addition to initializing the theme settings during HOOK_theme(), init them
|
| 401 |
* when viewing/resetting the admin/build/themes/settings/THEME forms.
|
| 402 |
*/
|
| 403 |
if (arg(0) == 'admin' && arg(2) == 'themes' && arg(4)) {
|
| 404 |
global $theme_key;
|
| 405 |
ad_redoable_settings_init($theme_key);
|
| 406 |
}
|