| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
//
|
| 5 |
// from ZEN // Override or insert PHPTemplate variables into the page templates.
|
| 6 |
//
|
| 7 |
// This function creates the body classes that are relative to each page
|
| 8 |
//
|
| 9 |
// @param $vars
|
| 10 |
// A sequential array of variables to pass to the theme template.
|
| 11 |
// @param $hook
|
| 12 |
// The name of the theme function being called ("page" in this case.)
|
| 13 |
//
|
| 14 |
|
| 15 |
function phptemplate_preprocess_page(&$vars, $hook) {
|
| 16 |
global $theme;
|
| 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 |
// (home page, node of certain type, etc.)
|
| 25 |
$body_classes = array($vars['body_classes']);
|
| 26 |
if (!$vars['is_front']) {
|
| 27 |
// Add unique classes for each page and website section
|
| 28 |
$path = drupal_get_path_alias($_GET['q']);
|
| 29 |
list($section, ) = explode('/', $path, 2);
|
| 30 |
$body_classes[] = phptemplate_id_safe('page-'. $path);
|
| 31 |
$body_classes[] = phptemplate_id_safe('section-'. $section);
|
| 32 |
if (arg(0) == 'node') {
|
| 33 |
if (arg(1) == 'add') {
|
| 34 |
if ($section == 'node') {
|
| 35 |
array_pop($body_classes); // Remove 'section-node'
|
| 36 |
}
|
| 37 |
$body_classes[] = 'section-node-add'; // Add 'section-node-add'
|
| 38 |
}
|
| 39 |
elseif (is_numeric(arg(1)) && (arg(2) == 'edit' || arg(2) == 'delete')) {
|
| 40 |
if ($section == 'node') {
|
| 41 |
array_pop($body_classes); // Remove 'section-node'
|
| 42 |
}
|
| 43 |
$body_classes[] = 'section-node-'. arg(2); // Add 'section-node-edit' or 'section-node-delete'
|
| 44 |
}
|
| 45 |
}
|
| 46 |
}
|
| 47 |
$vars['body_classes'] = implode(' ', $body_classes); // Concatenate with spaces
|
| 48 |
}
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
//
|
| 53 |
// from ZEN // Override or insert PHPTemplate variables into the node templates.
|
| 54 |
//
|
| 55 |
// This function creates the NODES classes, like 'node-unpublished' for nodes
|
| 56 |
// that are not published, or 'node-mine' for node posted by the connected user...
|
| 57 |
//
|
| 58 |
// @param $vars
|
| 59 |
// A sequential array of variables to pass to the theme template.
|
| 60 |
// @param $hook
|
| 61 |
// The name of the theme function being called ("node" in this case.)
|
| 62 |
//
|
| 63 |
|
| 64 |
function phptemplate_preprocess_node(&$vars, $hook) {
|
| 65 |
global $user;
|
| 66 |
|
| 67 |
// Special classes for nodes
|
| 68 |
$node_classes = array();
|
| 69 |
if ($vars['sticky']) {
|
| 70 |
$node_classes[] = 'sticky';
|
| 71 |
}
|
| 72 |
if (!$vars['node']->status) {
|
| 73 |
$node_classes[] = 'node-unpublished';
|
| 74 |
$vars['unpublished'] = TRUE;
|
| 75 |
}
|
| 76 |
else {
|
| 77 |
$vars['unpublished'] = FALSE;
|
| 78 |
}
|
| 79 |
if ($vars['node']->uid && $vars['node']->uid == $user->uid) {
|
| 80 |
// Node is authored by current user
|
| 81 |
$node_classes[] = 'node-mine';
|
| 82 |
}
|
| 83 |
if ($vars['teaser']) {
|
| 84 |
// Node is displayed as teaser
|
| 85 |
$node_classes[] = 'node-teaser';
|
| 86 |
}
|
| 87 |
// Class for node type: "node-type-page", "node-type-story", "node-type-my-custom-type", etc.
|
| 88 |
$node_classes[] = 'node-type-'. $vars['node']->type;
|
| 89 |
$vars['node_classes'] = implode(' ', $node_classes); // Concatenate with spaces
|
| 90 |
}
|
| 91 |
|
| 92 |
|
| 93 |
//
|
| 94 |
// from ZEN // Override or insert PHPTemplate variables into the block templates.
|
| 95 |
//
|
| 96 |
// This function create the EDIT LINKS for blocks and menus blocks.
|
| 97 |
// When overing a block (except in IE6), some links appear to edit
|
| 98 |
// or configure the block. You can then edit the block, and once you are
|
| 99 |
// done, brought back to the first page.
|
| 100 |
//
|
| 101 |
// @param $vars
|
| 102 |
// A sequential array of variables to pass to the theme template.
|
| 103 |
// @param $hook
|
| 104 |
// The name of the theme function being called ("block" in this case.)
|
| 105 |
//
|
| 106 |
|
| 107 |
function phptemplate_preprocess_block(&$vars, $hook) {
|
| 108 |
$block = $vars['block'];
|
| 109 |
|
| 110 |
if (user_access('administer blocks')) {
|
| 111 |
// Display 'edit block' for custom blocks
|
| 112 |
if ($block->module == 'block') {
|
| 113 |
$edit_links[] = l( t('edit block'), 'admin/build/block/configure/'. $block->module .'/'. $block->delta, array('title' => t('edit the content of this block'), 'class' => 'block-edit'), drupal_get_destination(), NULL, FALSE, TRUE);
|
| 114 |
}
|
| 115 |
// Display 'configure' for other blocks
|
| 116 |
else {
|
| 117 |
$edit_links[] = l(t('configure'), 'admin/build/block/configure/'. $block->module .'/'. $block->delta, array('title' => t('configure this block'), 'class' => 'block-config'), drupal_get_destination(), NULL, FALSE, TRUE);
|
| 118 |
}
|
| 119 |
|
| 120 |
// Display 'edit menu' for menu blocks
|
| 121 |
if (($block->module == 'menu' || ($block->module == 'user' && $block->delta == 1)) && user_access('administer menu')) {
|
| 122 |
$edit_links[] = l(t('edit menu'), 'admin/build/menu', array('title' => t('edit the menu that defines this block'), 'class' => 'block-edit-menu'), drupal_get_destination(), NULL, FALSE, TRUE);
|
| 123 |
}
|
| 124 |
$vars['edit_links_array'] = $edit_links;
|
| 125 |
$vars['edit_links'] = '<div class="edit">'. implode(' ', $edit_links) .'</div>';
|
| 126 |
}
|
| 127 |
}
|
| 128 |
|
| 129 |
|
| 130 |
//
|
| 131 |
// Create some custom classes for comments
|
| 132 |
//
|
| 133 |
|
| 134 |
function comment_classes($comment) {
|
| 135 |
$node = node_load($comment->nid);
|
| 136 |
global $user;
|
| 137 |
|
| 138 |
$output .= ($comment->new) ? ' comment-new' : '';
|
| 139 |
$output .= ' '. $status .' ';
|
| 140 |
if ($node->name == $comment->name) {
|
| 141 |
$output .= 'node-author';
|
| 142 |
}
|
| 143 |
if ($user->name == $comment->name) {
|
| 144 |
$output .= ' mine';
|
| 145 |
}
|
| 146 |
return $output;
|
| 147 |
}
|
| 148 |
|
| 149 |
|
| 150 |
//
|
| 151 |
// Customize the PRIMARY and SECONDARY LINKS, to allow the admin tabs to work on all browsers
|
| 152 |
// Generate the HTML representing a given menu item ID.
|
| 153 |
// An implementation of theme_menu_item_link()
|
| 154 |
//
|
| 155 |
// @param $link
|
| 156 |
// array The menu item to render.
|
| 157 |
// @return
|
| 158 |
// string The rendered menu item.
|
| 159 |
//
|
| 160 |
|
| 161 |
function phptemplate_menu_item_link($link) {
|
| 162 |
if (empty($link['options'])) {
|
| 163 |
$link['options'] = array();
|
| 164 |
}
|
| 165 |
|
| 166 |
// If an item is a LOCAL TASK, render it as a tab
|
| 167 |
if ($link['type'] & MENU_IS_LOCAL_TASK) {
|
| 168 |
$link['title'] = '<span class="tab">'. check_plain($link['title']) .'</span>';
|
| 169 |
$link['options']['html'] = TRUE;
|
| 170 |
}
|
| 171 |
|
| 172 |
if (empty($link['type'])) {
|
| 173 |
$true = TRUE;
|
| 174 |
}
|
| 175 |
|
| 176 |
return l($link['title'], $link['href'], $link['options']);
|
| 177 |
}
|
| 178 |
|
| 179 |
/**
|
| 180 |
* Duplicate of theme_menu_local_tasks() but adds clear-block to tabs.
|
| 181 |
*/
|
| 182 |
function phptemplate_menu_local_tasks() {
|
| 183 |
$output = '';
|
| 184 |
|
| 185 |
if ($primary = menu_primary_local_tasks()) {
|
| 186 |
$output .= "<ul class=\"tabs primary clear-block\">\n". $primary ."</ul>\n";
|
| 187 |
}
|
| 188 |
if ($secondary = menu_secondary_local_tasks()) {
|
| 189 |
$output .= "<ul class=\"tabs secondary clear-block\">\n". $secondary ."</ul>\n";
|
| 190 |
}
|
| 191 |
|
| 192 |
return $output;
|
| 193 |
}
|
| 194 |
|
| 195 |
|
| 196 |
//
|
| 197 |
// Converts a string to a suitable html ID attribute.
|
| 198 |
//
|
| 199 |
// http://www.w3.org/TR/html4/struct/global.html#h-7.5.2 specifies what makes a
|
| 200 |
// valid ID attribute in HTML. This function:
|
| 201 |
//
|
| 202 |
// - Ensure an ID starts with an alpha character by optionally adding an 'n'.
|
| 203 |
// - Replaces any character except A-Z, numbers, and underscores with dashes.
|
| 204 |
// - Converts entire string to lowercase.
|
| 205 |
//
|
| 206 |
// @param $string
|
| 207 |
// The string
|
| 208 |
// @return
|
| 209 |
// The converted string
|
| 210 |
//
|
| 211 |
|
| 212 |
|
| 213 |
function phptemplate_id_safe($string) {
|
| 214 |
// Replace with dashes anything that isn't A-Z, numbers, dashes, or underscores.
|
| 215 |
$string = strtolower(preg_replace('/[^a-zA-Z0-9_-]+/', '-', $string));
|
| 216 |
// If the first character is not a-z, add 'n' in front.
|
| 217 |
if (!ctype_lower($string{0})) { // Don't use ctype_alpha since its locale aware.
|
| 218 |
$string = 'id'. $string;
|
| 219 |
}
|
| 220 |
return $string;
|
| 221 |
}
|
| 222 |
|
| 223 |
//
|
| 224 |
// from STEVE KRUEGER truncate text characters
|
| 225 |
//
|
| 226 |
// You can use this function in the node templates to maximize the number of words
|
| 227 |
// of an item. For example, if you wish to have a teaser of the body, limited to
|
| 228 |
// 15 words, use this :
|
| 229 |
//
|
| 230 |
// print truncate($node->body,15)
|
| 231 |
//
|
| 232 |
// This function also remove all markup, like <a> or <strong> to preserve the integrity
|
| 233 |
// of the markup
|
| 234 |
|
| 235 |
|
| 236 |
function truncate($phrase, $max_words) {
|
| 237 |
$phrase = strip_tags($phrase);
|
| 238 |
$phrase_array = explode(' ', $phrase);
|
| 239 |
if(count($phrase_array) > $max_words && $max_words > 0)
|
| 240 |
$phrase = implode(' ', array_slice($phrase_array, 0, $max_words)) .'...';
|
| 241 |
return $phrase;
|
| 242 |
}
|
| 243 |
|
| 244 |
//
|
| 245 |
// Return a themed breadcrumb trail.
|
| 246 |
// Alow you to customize the breadcrumb markup
|
| 247 |
//
|
| 248 |
|
| 249 |
function phptemplate_breadcrumb($breadcrumb) {
|
| 250 |
if (!empty($breadcrumb)) {
|
| 251 |
return '<div class="breadcrumb">'. implode(' ยป ', $breadcrumb) .'</div>';
|
| 252 |
}
|
| 253 |
}
|