| 1 |
<?php
|
| 2 |
// $Id: template.php,v 1.14 2008/02/25 17:12:58 m3avrck Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* Override theme_page(). We need to do this in order to set proper page titles.
|
| 6 |
*
|
| 7 |
* In a nutshell we are intercepting the page call, before phptemplate renders everything.
|
| 8 |
*/
|
| 9 |
function blueprint_page($content = '') {
|
| 10 |
$title = drupal_get_title();
|
| 11 |
$headers = drupal_set_header();
|
| 12 |
|
| 13 |
// wrap taxonomy listing pages in quotes and prefix with topic
|
| 14 |
if (arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2))) {
|
| 15 |
$title = t('Topic') .' “'. $title .'”';
|
| 16 |
}
|
| 17 |
// if this is a 403 and they aren't logged in, tell them they need to log in
|
| 18 |
else if (strpos($headers, 'HTTP/1.1 403 Forbidden') && !$user->uid) {
|
| 19 |
$title = t('Please login to continue');
|
| 20 |
}
|
| 21 |
|
| 22 |
drupal_set_title($title);
|
| 23 |
|
| 24 |
return phptemplate_page($content);
|
| 25 |
}
|
| 26 |
|
| 27 |
/**
|
| 28 |
* Intercept template variables
|
| 29 |
*
|
| 30 |
* @param $hook
|
| 31 |
* The name of the theme function being executed
|
| 32 |
* @param $vars
|
| 33 |
* A sequential array of variables passed to the theme function.
|
| 34 |
*/
|
| 35 |
function _phptemplate_variables($hook, $vars = array()) {
|
| 36 |
global $user;
|
| 37 |
$path = base_path() . path_to_theme() .'/';
|
| 38 |
$path_theme = path_to_theme() .'/';
|
| 39 |
|
| 40 |
// global vars
|
| 41 |
$vars['path'] = $path;
|
| 42 |
$vars['user'] = $user;
|
| 43 |
|
| 44 |
switch ($hook) {
|
| 45 |
case 'page':
|
| 46 |
// add in CSS and JS files so they get aggregated and compressed properly
|
| 47 |
drupal_add_css($path_theme .'blueprint/blueprint/screen.css', 'theme', 'screen, projection');
|
| 48 |
drupal_add_css($path_theme .'blueprint/blueprint/print.css', 'theme', 'print');
|
| 49 |
drupal_add_css($path_theme .'css/blueprint.css', 'theme', 'screen, projection');
|
| 50 |
drupal_add_css($path_theme .'css/style.css', 'theme', 'screen, projection');
|
| 51 |
|
| 52 |
// url() handles appending ?q= but in this case, we need to pass in the variable so the path is correct when mod_rewrite is off
|
| 53 |
// use this in jQuery scripts, most notably AJAX ones
|
| 54 |
drupal_add_js(array('basePath' => base_path() . (variable_get('clean_url', 0) ? '' : '?q=')), 'setting');
|
| 55 |
drupal_add_js($path_theme .'scripts/general.js');
|
| 56 |
|
| 57 |
// determine layout
|
| 58 |
// 3 columns
|
| 59 |
if ($vars['layout'] == 'both') {
|
| 60 |
$vars['left'] = '<div class="col-left span-6">'. $vars['sidebar_left'] .'</div>';
|
| 61 |
$vars['right'] = '<div class="col-right span-6 last">'. $vars['sidebar_right'] .'</div>';
|
| 62 |
$vars['center'] = 'col-center span-12';
|
| 63 |
$vars['body_class'] = 'col-3';
|
| 64 |
}
|
| 65 |
// 2 columns
|
| 66 |
else if ($vars['layout'] != 'none') {
|
| 67 |
// left column & center
|
| 68 |
if ($vars['layout'] == 'left') {
|
| 69 |
$vars['left'] = '<div class="col-left span-6">'. $vars['sidebar_left'] .'</div>';
|
| 70 |
$vars['right'] = '';
|
| 71 |
$vars['center'] = 'col-center span-18 last';
|
| 72 |
}
|
| 73 |
// right column & center
|
| 74 |
else if ($vars['layout'] == 'right') {
|
| 75 |
$vars['left'] = '';
|
| 76 |
$vars['right'] = '<div class="col-right span-6 last">'. $vars['sidebar_right'] .'</div>';
|
| 77 |
$vars['center'] = 'col-center span-18';
|
| 78 |
}
|
| 79 |
$vars['body_class'] = 'col-2';
|
| 80 |
}
|
| 81 |
// 1 column
|
| 82 |
else {
|
| 83 |
$vars['left'] = '';
|
| 84 |
$vars['right'] = '';
|
| 85 |
$vars['center'] = 'col-center span-24';
|
| 86 |
$vars['body_class'] = 'col-1';
|
| 87 |
}
|
| 88 |
|
| 89 |
// SEO optimization, add in the node's teaser, or if on the homepage, the mission statement
|
| 90 |
// as a description of the page that appears in search engines
|
| 91 |
if ($vars['is_front'] && $vars['mission'] != '') {
|
| 92 |
$vars['meta'] .= '<meta name="description" content="'. blueprint_trim_text($vars['mission']) .'" />'. "\n";
|
| 93 |
}
|
| 94 |
else if ($vars['node']->teaser != '') {
|
| 95 |
$vars['meta'] .= '<meta name="description" content="'. blueprint_trim_text($vars['node']->teaser) .'" />'. "\n";
|
| 96 |
}
|
| 97 |
// SEO optimization, if the node has tags, use these as keywords for the page
|
| 98 |
if ($vars['node']->taxonomy) {
|
| 99 |
$keywords = array();
|
| 100 |
foreach($vars['node']->taxonomy as $term) {
|
| 101 |
$keywords[] = $term->name;
|
| 102 |
}
|
| 103 |
$vars['meta'] .= '<meta name="keywords" content="'. implode(',', $keywords) .'" />'. "\n";
|
| 104 |
}
|
| 105 |
|
| 106 |
|
| 107 |
/* I like to embed the Google search in various places, uncomment to make use of this
|
| 108 |
// setup search for custom placement
|
| 109 |
$search = module_invoke('google_cse', 'block', 'view', '0');
|
| 110 |
$vars['search'] = $search['content'];
|
| 111 |
*/
|
| 112 |
|
| 113 |
// rebuild CSS and JS after all theme modifications to these structures
|
| 114 |
$new_css = drupal_add_css();
|
| 115 |
// removed unnessecary CSS styles
|
| 116 |
// unset($new_css['all']['all']['sites/all/modules/contrib/tagadelic/tagadelic.css']);
|
| 117 |
|
| 118 |
// rebuild CSS and JS
|
| 119 |
$vars['styles'] = drupal_get_css($new_css);
|
| 120 |
$vars['scripts'] = drupal_get_js();
|
| 121 |
|
| 122 |
break;
|
| 123 |
|
| 124 |
|
| 125 |
case 'node':
|
| 126 |
$node = $vars['node']; // for easy reference
|
| 127 |
// for easy variable adding for different node types
|
| 128 |
switch ($node->type) {
|
| 129 |
case 'page':
|
| 130 |
break;
|
| 131 |
}
|
| 132 |
break;
|
| 133 |
|
| 134 |
|
| 135 |
case 'comment':
|
| 136 |
// if the author of the node comments as well, highlight that comment
|
| 137 |
$node = node_load($vars['comment']->nid);
|
| 138 |
if ($vars['comment']->uid == $node->uid) {
|
| 139 |
$vars['author_comment'] = TRUE;
|
| 140 |
}
|
| 141 |
// only show links for users that can administer links
|
| 142 |
if (!user_access('administer comments')) {
|
| 143 |
$vars['links'] = '';
|
| 144 |
}
|
| 145 |
// if subjects in comments are turned off, don't show the title then
|
| 146 |
if (!variable_get('comment_subject_field', 1)) {
|
| 147 |
$vars['title'] = '';
|
| 148 |
}
|
| 149 |
// if user has no picture, add in a filler
|
| 150 |
if ($vars['picture'] == '') {
|
| 151 |
$vars['picture'] = '<div class="no-picture"> </div>';
|
| 152 |
}
|
| 153 |
|
| 154 |
break;
|
| 155 |
|
| 156 |
|
| 157 |
case 'box':
|
| 158 |
// rename to more common text
|
| 159 |
if (strpos($vars['title'], 'Post new comment') === 0) {
|
| 160 |
$vars['title'] = 'Add your comment';
|
| 161 |
}
|
| 162 |
break;
|
| 163 |
}
|
| 164 |
|
| 165 |
return $vars;
|
| 166 |
}
|
| 167 |
|
| 168 |
/**
|
| 169 |
* Override, add rel="nofollow" to comment poster's homepage, remove "not verified", confusing
|
| 170 |
*
|
| 171 |
* Format a username.
|
| 172 |
*
|
| 173 |
* @param $object
|
| 174 |
* The user object to format, usually returned from user_load().
|
| 175 |
* @return
|
| 176 |
* A string containing an HTML link to the user's page if the passed object
|
| 177 |
* suggests that this is a site user. Otherwise, only the username is returned.
|
| 178 |
*/
|
| 179 |
function phptemplate_username($object) {
|
| 180 |
|
| 181 |
if ($object->uid && $object->name) {
|
| 182 |
// Shorten the name when it is too long or it will break many tables.
|
| 183 |
if (drupal_strlen($object->name) > 20) {
|
| 184 |
$name = drupal_substr($object->name, 0, 15) .'...';
|
| 185 |
}
|
| 186 |
else {
|
| 187 |
$name = $object->name;
|
| 188 |
}
|
| 189 |
|
| 190 |
if (user_access('access user profiles')) {
|
| 191 |
$output = l($name, 'user/'. $object->uid, array('title' => t('View user profile.')));
|
| 192 |
}
|
| 193 |
else {
|
| 194 |
$output = check_plain($name);
|
| 195 |
}
|
| 196 |
}
|
| 197 |
else if ($object->name) {
|
| 198 |
// Sometimes modules display content composed by people who are
|
| 199 |
// not registered members of the site (e.g. mailing list or news
|
| 200 |
// aggregator modules). This clause enables modules to display
|
| 201 |
// the true author of the content.
|
| 202 |
if ($object->homepage) {
|
| 203 |
$output = l($object->name, $object->homepage, array('rel' => 'nofollow'));
|
| 204 |
}
|
| 205 |
else {
|
| 206 |
$output = check_plain($object->name);
|
| 207 |
}
|
| 208 |
}
|
| 209 |
else {
|
| 210 |
$output = variable_get('anonymous', t('Anonymous'));
|
| 211 |
}
|
| 212 |
|
| 213 |
return $output;
|
| 214 |
}
|
| 215 |
|
| 216 |
/**
|
| 217 |
* Override, remove previous/next links for forum topics
|
| 218 |
*
|
| 219 |
* Makes forums look better and is great for performance
|
| 220 |
* More: http://www.sysarchitects.com/node/70
|
| 221 |
*/
|
| 222 |
function phptemplate_forum_topic_navigation($node) {
|
| 223 |
return '';
|
| 224 |
}
|
| 225 |
|
| 226 |
/**
|
| 227 |
* Override, make sure Drupal doesn't return empty <P>
|
| 228 |
*
|
| 229 |
* Return a themed help message.
|
| 230 |
*
|
| 231 |
* @return a string containing the helptext for the current page.
|
| 232 |
*/
|
| 233 |
function phptemplate_help() {
|
| 234 |
$help = menu_get_active_help();
|
| 235 |
// Drupal sometimes returns empty <p></p> so strip tags to check if empty
|
| 236 |
if (strlen(strip_tags($help)) > 1) {
|
| 237 |
return '<div class="help">'. $help .'</div>';
|
| 238 |
}
|
| 239 |
}
|
| 240 |
|
| 241 |
/**
|
| 242 |
* Override, use a better default breadcrumb separator.
|
| 243 |
*
|
| 244 |
* Return a themed breadcrumb trail.
|
| 245 |
*
|
| 246 |
* @param $breadcrumb
|
| 247 |
* An array containing the breadcrumb links.
|
| 248 |
* @return a string containing the breadcrumb output.
|
| 249 |
*/
|
| 250 |
function phptemplate_breadcrumb($breadcrumb) {
|
| 251 |
if (count($breadcrumb) > 1) {
|
| 252 |
$breadcrumb[] = drupal_get_title();
|
| 253 |
return '<div class="breadcrumb">'. implode(' › ', $breadcrumb) .'</div>';
|
| 254 |
}
|
| 255 |
}
|
| 256 |
|
| 257 |
/**
|
| 258 |
* Rewrite of theme_form_element() to suppress ":" if the title ends with a punctuation mark.
|
| 259 |
*/
|
| 260 |
function phptemplate_form_element() {
|
| 261 |
$args = func_get_args();
|
| 262 |
return preg_replace('@([.!?]):\s*(</label>)@i', '$1$2', call_user_func_array('theme_form_element', $args));
|
| 263 |
}
|
| 264 |
|
| 265 |
/**
|
| 266 |
* This override adds an ID to the label for all checkboxes, useful for jQuery.
|
| 267 |
*
|
| 268 |
* Format a checkbox.
|
| 269 |
*
|
| 270 |
* @param $element
|
| 271 |
* An associative array containing the properties of the element.
|
| 272 |
* Properties used: title, value, return_value, description, required
|
| 273 |
* @return
|
| 274 |
* A themed HTML string representing the checkbox.
|
| 275 |
*/
|
| 276 |
function phptemplate_checkbox($element) {
|
| 277 |
_form_set_class($element, array('form-checkbox'));
|
| 278 |
$checkbox = '<input ';
|
| 279 |
$checkbox .= 'type="checkbox" ';
|
| 280 |
$checkbox .= 'name="'. $element['#name'] .'" ';
|
| 281 |
$checkbox .= 'id="'. $element['#id'].'" ' ;
|
| 282 |
$checkbox .= 'value="'. $element['#return_value'] .'" ';
|
| 283 |
$checkbox .= $element['#value'] ? ' checked="checked" ' : ' ';
|
| 284 |
$checkbox .= drupal_attributes($element['#attributes']) . ' />';
|
| 285 |
|
| 286 |
if (!is_null($element['#title'])) {
|
| 287 |
$checkbox = '<label id="checkbox-'. $element['#id'] .'" class="option">'. $checkbox .' '. $element['#title'] .'</label>';
|
| 288 |
}
|
| 289 |
|
| 290 |
unset($element['#title']);
|
| 291 |
return theme('form_element', $element, $checkbox);
|
| 292 |
}
|
| 293 |
|
| 294 |
/**
|
| 295 |
* Set status messages to use Blueprint CSS classes.
|
| 296 |
*/
|
| 297 |
function phptemplate_status_messages($display = NULL) {
|
| 298 |
$output = '';
|
| 299 |
foreach (drupal_get_messages($display) as $type => $messages) {
|
| 300 |
// blueprint can either call this success or notice
|
| 301 |
if ($type == 'status') {
|
| 302 |
$type = 'success';
|
| 303 |
}
|
| 304 |
$output .= "<div class=\"messages $type\">\n";
|
| 305 |
if (count($messages) > 1) {
|
| 306 |
$output .= " <ul>\n";
|
| 307 |
foreach ($messages as $message) {
|
| 308 |
$output .= ' <li>'. $message ."</li>\n";
|
| 309 |
}
|
| 310 |
$output .= " </ul>\n";
|
| 311 |
}
|
| 312 |
else {
|
| 313 |
$output .= $messages[0];
|
| 314 |
}
|
| 315 |
$output .= "</div>\n";
|
| 316 |
}
|
| 317 |
return $output;
|
| 318 |
}
|
| 319 |
|
| 320 |
/**
|
| 321 |
* Override, use better icons, source: http://drupal.org/node/102743#comment-664157
|
| 322 |
*
|
| 323 |
* Format the icon for each individual topic.
|
| 324 |
*
|
| 325 |
* @ingroup themeable
|
| 326 |
*/
|
| 327 |
function phptemplate_forum_icon($new_posts, $num_posts = 0, $comment_mode = 0, $sticky = 0) {
|
| 328 |
if ($num_posts > variable_get('forum_hot_topic', 15)) {
|
| 329 |
$icon = $new_posts ? 'hot-new' : 'hot';
|
| 330 |
}
|
| 331 |
else {
|
| 332 |
$icon = $new_posts ? 'new' : 'default';
|
| 333 |
}
|
| 334 |
|
| 335 |
if ($comment_mode == COMMENT_NODE_READ_ONLY || $comment_mode == COMMENT_NODE_DISABLED) {
|
| 336 |
$icon = 'closed';
|
| 337 |
}
|
| 338 |
|
| 339 |
if ($sticky == 1) {
|
| 340 |
$icon = 'sticky';
|
| 341 |
}
|
| 342 |
|
| 343 |
$output = theme('image', path_to_theme() . "/images/icons/forum-$icon.png");
|
| 344 |
|
| 345 |
if ($new_posts) {
|
| 346 |
$output = "<a name=\"new\">$output</a>";
|
| 347 |
}
|
| 348 |
|
| 349 |
return $output;
|
| 350 |
}
|
| 351 |
|
| 352 |
/**
|
| 353 |
* Override comment wrapper to show you must login to comment.
|
| 354 |
*/
|
| 355 |
function phptemplate_comment_wrapper($content) {
|
| 356 |
global $user;
|
| 357 |
$output = '';
|
| 358 |
|
| 359 |
if (arg(0) == 'node' && is_numeric(arg(1))) {
|
| 360 |
$node = node_load(arg(1));
|
| 361 |
if ($node->type != 'forum') {
|
| 362 |
$count = $node->comment_count .' '. format_plural($node->comment_count, 'comment', 'comments');
|
| 363 |
$comment_text .= ($count > 0) ? $count : 'No comments';
|
| 364 |
$output .= '<h3 id="comment-number">'. $comment_text .'</h3>';
|
| 365 |
}
|
| 366 |
}
|
| 367 |
|
| 368 |
$output .= '<div id="comments">';
|
| 369 |
$msg = '';
|
| 370 |
if (!user_access('post comments')) {
|
| 371 |
$dest = 'destination='. $_GET['q'] .'#comment-form';
|
| 372 |
$msg = '<div id="messages"><div class="error-wrapper"><div class="messages error">'.t('Please <a href="!register">register</a> or <a href="!login">sign in</a> to post a comment.', array('!register' => url("user/register", $dest), '!login' => url('user', $dest))).'</div></div></div>';
|
| 373 |
}
|
| 374 |
$output .= $content;
|
| 375 |
$output .= $msg;
|
| 376 |
return $output .'</div>';
|
| 377 |
}
|
| 378 |
|
| 379 |
/**
|
| 380 |
* Trim a post to a certain number of characters, removing all HTML.
|
| 381 |
*/
|
| 382 |
function blueprint_trim_text($text, $length = 150) {
|
| 383 |
// remove any HTML or line breaks so these don't appear in the text
|
| 384 |
$text = trim(str_replace(array("\n", "\r"), ' ', strip_tags($text)));
|
| 385 |
$text = trim(substr($text, 0, $length));
|
| 386 |
$lastchar = substr($text, -1, 1);
|
| 387 |
// check to see if the last character in the title is a non-alphanumeric character, except for ? or !
|
| 388 |
// if it is strip it off so you don't get strange looking titles
|
| 389 |
if (preg_match('/[^0-9A-Za-z\!\?]/', $lastchar)) {
|
| 390 |
$text = substr($text, 0, -1);
|
| 391 |
}
|
| 392 |
// ? and ! are ok to end a title with since they make sense
|
| 393 |
if ($lastchar != '!' and $lastchar != '?') {
|
| 394 |
$text .= '...';
|
| 395 |
}
|
| 396 |
|
| 397 |
return $text;
|
| 398 |
}
|