| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
// Rebuild theme registry if setting is activated.
|
| 5 |
if (theme_get_setting('newhorizon_rebuild_registry')) {
|
| 6 |
drupal_rebuild_theme_registry();
|
| 7 |
if (theme_get_setting('newhorizon_registry_reminder')) {
|
| 8 |
drupal_set_message(t('The theme registry has been rebuilt. <a href="!link">Turn off</a> this feature on production websites. (<a href="!link">Don\'t show this</a>.)', array('!link' => base_path() . 'admin/build/themes/settings/' . $GLOBALS['theme'])), 'warning');
|
| 9 |
}
|
| 10 |
}
|
| 11 |
|
| 12 |
/**
|
| 13 |
* Create useful body classes that are page-specific.
|
| 14 |
* Edit this theme to add custom body classes.
|
| 15 |
*/
|
| 16 |
function newhorizon_preprocess_page(&$vars, $hook) {
|
| 17 |
|
| 18 |
// Don't display empty help from node_help().
|
| 19 |
if ($vars['help'] == "<div class=\"help\"><p></p>\n</div>") {
|
| 20 |
$vars['help'] = '';
|
| 21 |
}
|
| 22 |
|
| 23 |
// Classes for body element. Allows advanced theming based on context
|
| 24 |
$body_classes = array($vars['body_classes']);
|
| 25 |
if (user_access('administer blocks')) {
|
| 26 |
$body_classes[] = 'admin';
|
| 27 |
}
|
| 28 |
if (theme_get_setting('newhorizon_wireframe')) {
|
| 29 |
$body_classes[] = 'with-wireframes'; // Optionally add the wireframes style.
|
| 30 |
}
|
| 31 |
if (!$vars['is_front']) {
|
| 32 |
// Add unique classes for each page and website section
|
| 33 |
$path = drupal_get_path_alias($_GET['q']);
|
| 34 |
list($section, ) = explode('/', $path, 2);
|
| 35 |
$body_classes[] = newhorizon_id_safe('page-'. $path);
|
| 36 |
$body_classes[] = newhorizon_id_safe('section-'. $section);
|
| 37 |
|
| 38 |
if (arg(0) == 'node') {
|
| 39 |
if (arg(1) == 'add') {
|
| 40 |
if ($section == 'node') {
|
| 41 |
array_pop($body_classes); // Remove 'section-node'
|
| 42 |
}
|
| 43 |
$body_classes[] = 'section-node-add'; // Add 'section-node-add'
|
| 44 |
}
|
| 45 |
elseif (is_numeric(arg(1)) && (arg(2) == 'edit' || arg(2) == 'delete')) {
|
| 46 |
if ($section == 'node') {
|
| 47 |
array_pop($body_classes); // Remove 'section-node'
|
| 48 |
}
|
| 49 |
$body_classes[] = 'section-node-'. arg(2); // Add 'section-node-edit' or 'section-node-delete'
|
| 50 |
}
|
| 51 |
}
|
| 52 |
}
|
| 53 |
$vars['body_classes'] = implode(' ', $body_classes); // Concatenate with spaces
|
| 54 |
}
|
| 55 |
|
| 56 |
/**
|
| 57 |
* Override or insert variables into node classes for custom theming.
|
| 58 |
* Modify this function to add your own custom classes.
|
| 59 |
*/
|
| 60 |
function newhorizon_preprocess_node(&$vars, $hook) {
|
| 61 |
// Special classes for nodes
|
| 62 |
$classes = array('node');
|
| 63 |
if ($vars['sticky']) {
|
| 64 |
$classes[] = 'sticky';
|
| 65 |
}
|
| 66 |
if (!$vars['status']) {
|
| 67 |
$classes[] = 'node-unpublished';
|
| 68 |
$vars['unpublished'] = TRUE;
|
| 69 |
}
|
| 70 |
else {
|
| 71 |
$vars['unpublished'] = FALSE;
|
| 72 |
}
|
| 73 |
if ($vars['uid'] && $vars['uid'] == $GLOBALS['user']->uid) {
|
| 74 |
$classes[] = 'node-mine'; // Node is authored by current user.
|
| 75 |
}
|
| 76 |
if ($vars['teaser']) {
|
| 77 |
$classes[] = 'node-teaser'; // Node is displayed as teaser.
|
| 78 |
}
|
| 79 |
// Class for node type: "node-type-page", "node-type-story", "node-type-my-custom-type", etc.
|
| 80 |
$classes[] = newhorizon_id_safe('node-type-' . $vars['type']);
|
| 81 |
$vars['classes'] = implode(' ', $classes); // Concatenate with spaces
|
| 82 |
}
|
| 83 |
|
| 84 |
/**
|
| 85 |
* Override or insert variables into block classes for custom theming.
|
| 86 |
* Also display edit block links if setting is enabled.
|
| 87 |
* Modify this function to add your own custom classes.
|
| 88 |
*/
|
| 89 |
function newhorizon_preprocess_block(&$vars, $hook) {
|
| 90 |
$block = $vars['block'];
|
| 91 |
|
| 92 |
if (theme_get_setting('newhorizon_block_editing') && user_access('administer blocks')) {
|
| 93 |
// Display 'edit block' for custom blocks.
|
| 94 |
if ($block->module == 'block') {
|
| 95 |
$edit_links[] = l('<span>' . t('edit block') . '</span>', 'admin/build/block/configure/' . $block->module . '/' . $block->delta,
|
| 96 |
array(
|
| 97 |
'attributes' => array(
|
| 98 |
'title' => t('edit the content of this block'),
|
| 99 |
'class' => 'block-edit',
|
| 100 |
),
|
| 101 |
'query' => drupal_get_destination(),
|
| 102 |
'html' => TRUE,
|
| 103 |
)
|
| 104 |
);
|
| 105 |
}
|
| 106 |
// Display 'configure' for other blocks.
|
| 107 |
else {
|
| 108 |
$edit_links[] = l('<span>' . t('configure') . '</span>', 'admin/build/block/configure/' . $block->module . '/' . $block->delta,
|
| 109 |
array(
|
| 110 |
'attributes' => array(
|
| 111 |
'title' => t('configure this block'),
|
| 112 |
'class' => 'block-config',
|
| 113 |
),
|
| 114 |
'query' => drupal_get_destination(),
|
| 115 |
'html' => TRUE,
|
| 116 |
)
|
| 117 |
);
|
| 118 |
}
|
| 119 |
|
| 120 |
// Display 'edit view' for Views blocks.
|
| 121 |
if ($block->module == 'views' && user_access('administer views')) {
|
| 122 |
list($view_name, $view_block) = explode('-block', $block->delta);
|
| 123 |
$edit_links[] = l('<span>' . t('edit view') . '</span>', 'admin/build/views/edit/' . $view_name,
|
| 124 |
array(
|
| 125 |
'attributes' => array(
|
| 126 |
'title' => t('edit the view that defines this block'),
|
| 127 |
'class' => 'block-edit-view',
|
| 128 |
),
|
| 129 |
'query' => drupal_get_destination(),
|
| 130 |
'fragment' => 'views-tab-block' . $view_block,
|
| 131 |
'html' => TRUE,
|
| 132 |
)
|
| 133 |
);
|
| 134 |
}
|
| 135 |
// Display 'edit menu' for Menu blocks.
|
| 136 |
elseif (($block->module == 'menu' || ($block->module == 'user' && $block->delta == 1)) && user_access('administer menu')) {
|
| 137 |
$menu_name = ($block->module == 'user') ? 'navigation' : $block->delta;
|
| 138 |
$edit_links[] = l('<span>' . t('edit menu') . '</span>', 'admin/build/menu-customize/' . $menu_name,
|
| 139 |
array(
|
| 140 |
'attributes' => array(
|
| 141 |
'title' => t('edit the menu that defines this block'),
|
| 142 |
'class' => 'block-edit-menu',
|
| 143 |
),
|
| 144 |
'query' => drupal_get_destination(),
|
| 145 |
'html' => TRUE,
|
| 146 |
)
|
| 147 |
);
|
| 148 |
}
|
| 149 |
// Display 'edit menu' for Menu block blocks.
|
| 150 |
elseif ($block->module == 'menu_block' && user_access('administer menu')) {
|
| 151 |
list($menu_name, ) = split(':', variable_get("menu_block_{$block->delta}_parent", 'navigation:0'));
|
| 152 |
$edit_links[] = l('<span>' . t('edit menu') . '</span>', 'admin/build/menu-customize/' . $menu_name,
|
| 153 |
array(
|
| 154 |
'attributes' => array(
|
| 155 |
'title' => t('edit the menu that defines this block'),
|
| 156 |
'class' => 'block-edit-menu',
|
| 157 |
),
|
| 158 |
'query' => drupal_get_destination(),
|
| 159 |
'html' => TRUE,
|
| 160 |
)
|
| 161 |
);
|
| 162 |
}
|
| 163 |
|
| 164 |
$vars['edit_links_array'] = $edit_links;
|
| 165 |
$vars['edit_links'] = '<div class="edit">' . implode(' ', $edit_links) . '</div>';
|
| 166 |
}
|
| 167 |
}
|
| 168 |
|
| 169 |
/**
|
| 170 |
* Override or insert variables into comment classes for custom theming.
|
| 171 |
* Modify this function to add your own custom classes.
|
| 172 |
*/
|
| 173 |
function newhorizon_preprocess_comment(&$vars, $hook) {
|
| 174 |
// Add an "unpublished" flag.
|
| 175 |
$vars['unpublished'] = ($vars['comment']->status == COMMENT_NOT_PUBLISHED);
|
| 176 |
|
| 177 |
// If comment subjects are disabled, don't display them.
|
| 178 |
if (variable_get('comment_subject_field_' . $vars['node']->type, 1) == 0) {
|
| 179 |
$vars['title'] = '';
|
| 180 |
}
|
| 181 |
|
| 182 |
// Special classes for comments.
|
| 183 |
$classes = array('comment');
|
| 184 |
if ($vars['comment']->new) {
|
| 185 |
$classes[] = 'comment-new';
|
| 186 |
}
|
| 187 |
$classes[] = $vars['status'];
|
| 188 |
$classes[] = $vars['zebra'];
|
| 189 |
if ($vars['id'] == 1) {
|
| 190 |
$classes[] = 'first';
|
| 191 |
}
|
| 192 |
if ($vars['id'] == $vars['node']->comment_count) {
|
| 193 |
$classes[] = 'last';
|
| 194 |
}
|
| 195 |
if ($vars['comment']->uid == 0) {
|
| 196 |
// Comment is by an anonymous user.
|
| 197 |
$classes[] = 'comment-by-anon';
|
| 198 |
}
|
| 199 |
else {
|
| 200 |
if ($vars['comment']->uid == $vars['node']->uid) {
|
| 201 |
// Comment is by the node author.
|
| 202 |
$classes[] = 'comment-by-author';
|
| 203 |
}
|
| 204 |
if ($vars['comment']->uid == $GLOBALS['user']->uid) {
|
| 205 |
// Comment was posted by current user.
|
| 206 |
$classes[] = 'comment-mine';
|
| 207 |
}
|
| 208 |
}
|
| 209 |
$vars['classes'] = implode(' ', $classes);
|
| 210 |
}
|
| 211 |
|
| 212 |
/**
|
| 213 |
* Customize the PRIMARY and SECONDARY LINKS, to allow the admin tabs to work on all browsers
|
| 214 |
* An implementation of theme_menu_item_link()
|
| 215 |
*/
|
| 216 |
function newhorizon_menu_item_link($link) {
|
| 217 |
if (empty($link['options'])) {
|
| 218 |
$link['options'] = array();
|
| 219 |
}
|
| 220 |
|
| 221 |
// If an item is a LOCAL TASK, render it as a tab
|
| 222 |
if ($link['type'] & MENU_IS_LOCAL_TASK) {
|
| 223 |
$link['title'] = '<span class="tab">'. check_plain($link['title']) .'</span>';
|
| 224 |
$link['options']['html'] = TRUE;
|
| 225 |
}
|
| 226 |
if (empty($link['type'])) {
|
| 227 |
$true = TRUE;
|
| 228 |
}
|
| 229 |
return l($link['title'], $link['href'], $link['options']);
|
| 230 |
}
|
| 231 |
|
| 232 |
function newhorizon_node_submitted($node) {
|
| 233 |
return t('Submitted by !username on @datetime',
|
| 234 |
array(
|
| 235 |
'!username' => theme('username', $node),
|
| 236 |
'@datetime' => format_date($node->created),
|
| 237 |
));
|
| 238 |
}
|
| 239 |
|
| 240 |
/**
|
| 241 |
* Duplicate of theme_menu_local_tasks() but adds clear-block to tabs.
|
| 242 |
*/
|
| 243 |
function newhorizon_menu_local_tasks() {
|
| 244 |
$output = '';
|
| 245 |
if ($primary = menu_primary_local_tasks()) {
|
| 246 |
$output .= "<ul class=\"tabs primary clear-block\">\n". $primary ."</ul>\n";
|
| 247 |
}
|
| 248 |
if ($secondary = menu_secondary_local_tasks()) {
|
| 249 |
$output .= "<ul class=\"tabs secondary clear-block\">\n". $secondary ."</ul>\n";
|
| 250 |
}
|
| 251 |
return $output;
|
| 252 |
}
|
| 253 |
|
| 254 |
/**
|
| 255 |
* Add custom classes to menu item.
|
| 256 |
*/
|
| 257 |
function newhorizon_menu_item($link, $has_children, $menu = '', $in_active_trail = FALSE, $extra_class = NULL) {
|
| 258 |
$class = ($menu ? 'expanded' : ($has_children ? 'collapsed' : 'leaf'));
|
| 259 |
if (!empty($extra_class)) {
|
| 260 |
$class .= ' '. $extra_class;
|
| 261 |
}
|
| 262 |
if ($in_active_trail) {
|
| 263 |
$class .= ' active-trail';
|
| 264 |
}
|
| 265 |
$css_class = newhorizon_id_safe(str_replace(' ', '_', strip_tags($link)));
|
| 266 |
return '<li class="'. $class . ' ' . $css_class . '">' . $link . $menu ."</li>\n";
|
| 267 |
}
|
| 268 |
|
| 269 |
/**
|
| 270 |
* Converts a string to a suitable html ID attribute, including:
|
| 271 |
* - Ensure an ID starts with an alpha character by optionally adding 'id_'.
|
| 272 |
* - Replaces any character except A-Z, numbers, and underscores with dashes.
|
| 273 |
* - Converts entire string to lowercase.
|
| 274 |
*/
|
| 275 |
function newhorizon_id_safe($string) {
|
| 276 |
// Replace with dashes anything that isn't A-Z, numbers, dashes, or underscores.
|
| 277 |
$string = strtolower(preg_replace('/[^a-zA-Z0-9_-]+/', '-', $string));
|
| 278 |
// If the first character is not a-z, add 'id_' in front.
|
| 279 |
if (!ctype_lower($string{0})) { // Don't use ctype_alpha since its locale aware.
|
| 280 |
$string = 'id_'. $string;
|
| 281 |
}
|
| 282 |
return $string;
|
| 283 |
}
|
| 284 |
|
| 285 |
/**
|
| 286 |
* Returns a themed breadcrumb trail.
|
| 287 |
* Modify this to change the breacrumb separator, etc.
|
| 288 |
*/
|
| 289 |
function newhorizon_breadcrumb($breadcrumb) {
|
| 290 |
if (!empty($breadcrumb)) {
|
| 291 |
return '<div class="breadcrumb">'. implode(' ยป ', $breadcrumb) .'</div>';
|
| 292 |
}
|
| 293 |
}
|