| 1 |
<?php
|
| 2 |
// $Id: template.php,v 1.12 2007/11/29 18:49:40 zarabadoo Exp $
|
| 3 |
|
| 4 |
/*
|
| 5 |
* New regions for blocks are easy to add. Just put it in here so you have a
|
| 6 |
* new place for extra blocks. The first part is the name of the variable to
|
| 7 |
* place into your page.tpl.php and the second part is the human readable name
|
| 8 |
* that will show up in your blocks administration. You may notice that I have
|
| 9 |
* not used the traditional right_sidebar and left_sidebar. The reason for this
|
| 10 |
* is I want people to break the mindset that the regions are only for
|
| 11 |
* sidebars. This theme does use them for such since I wanted to provide a
|
| 12 |
* template that had the proper CSS for compensating for appearing and
|
| 13 |
* disappearing sidebars.
|
| 14 |
*/
|
| 15 |
|
| 16 |
function hunchbaque_regions() {
|
| 17 |
return array(
|
| 18 |
'main_supplements' => t('Primary blocks'),
|
| 19 |
'secondary_supplements' => t('Secondary blocks'),
|
| 20 |
'footer' => t('Footer')
|
| 21 |
);
|
| 22 |
}
|
| 23 |
|
| 24 |
/*
|
| 25 |
* In working more and more with Drupal in a team environment and with version
|
| 26 |
* control, one stylesheet can be a bit of a bottleneck. Only one person can
|
| 27 |
* really work on the theming. Any more than that, there are version conflicts
|
| 28 |
* and it just ends up being a mess. Beings Drupal now has the handy function
|
| 29 |
* to consolidate all CSS into onw cached file, we may as well take advantage
|
| 30 |
* of it and split things up so multiple people can work on a theme at once. We
|
| 31 |
* will assume you will be putting all stylesheets in the css folder of the
|
| 32 |
* theme since we want to keep things tidy. So in the array below, just add the
|
| 33 |
* name of the stylesheet you want to load with the page. The function below
|
| 34 |
* will take care of the rest.
|
| 35 |
*/
|
| 36 |
|
| 37 |
function hunchbaque_theme_styles() {
|
| 38 |
$output['screen, projection'] = array(
|
| 39 |
'reset.css',
|
| 40 |
'typography.css',
|
| 41 |
'forms.css',
|
| 42 |
'screen-layout.css',
|
| 43 |
'screen-block.css',
|
| 44 |
);
|
| 45 |
$output['print'] = array(
|
| 46 |
'print-layout.css',
|
| 47 |
'print.css',
|
| 48 |
);
|
| 49 |
$output['handheld'] = array(
|
| 50 |
'handheld-layout.css',
|
| 51 |
);
|
| 52 |
return $output;
|
| 53 |
}
|
| 54 |
|
| 55 |
/*
|
| 56 |
* Support for IE specific stylesheets. Just use the 'ie' (ie. $output['ie'])
|
| 57 |
* array for all versions of Internet Explorer of the version number (ie.
|
| 58 |
* $output['6']). Support for lt, lte, gt and gte will come at a later date.
|
| 59 |
*/
|
| 60 |
|
| 61 |
function hunchbaque_ie_styles() {
|
| 62 |
$output['ie'] = array(
|
| 63 |
'ie.css',
|
| 64 |
);
|
| 65 |
|
| 66 |
return $output;
|
| 67 |
}
|
| 68 |
|
| 69 |
function hunchbaque_styles() {
|
| 70 |
$theme_css = hunchbaque_theme_styles();
|
| 71 |
foreach ($theme_css as $media => $value) {
|
| 72 |
foreach ($value as $stylesheet) {
|
| 73 |
drupal_add_css(path_to_theme().'/'.$stylesheet, 'theme', $media, 'true');
|
| 74 |
}
|
| 75 |
}
|
| 76 |
$css = drupal_add_css();
|
| 77 |
print drupal_get_css($css);
|
| 78 |
|
| 79 |
$ie_css = hunchbaque_ie_styles();
|
| 80 |
$output = "\n";
|
| 81 |
foreach ($ie_css as $version => $value) {
|
| 82 |
if($version == 'ie'){
|
| 83 |
$output .= '<!--[if IE]>'."\n";
|
| 84 |
} else {
|
| 85 |
$output .= '<!--[if IE '.$version.']>'."\n";
|
| 86 |
}
|
| 87 |
foreach ($value as $stylesheet) {
|
| 88 |
$output .= ' <style type="text/css" media="screen, projection">@import "'.base_path().path_to_theme().'/'.$stylesheet.'";</style>'."\n";
|
| 89 |
}
|
| 90 |
$output .= '<![endif]-->'."\n";
|
| 91 |
}
|
| 92 |
print $output;
|
| 93 |
}
|
| 94 |
|
| 95 |
/*
|
| 96 |
* The below function is to construct a set of classes for the body tag. I will
|
| 97 |
* admit, this is pretty much taken from the Zen theme. I have added some minor
|
| 98 |
* changes to make it easier to compensate for additional regions that you may
|
| 99 |
* want to put into your template. I have documented those further down below.
|
| 100 |
*/
|
| 101 |
|
| 102 |
function _phptemplate_variables($hook, $vars = array()) {
|
| 103 |
switch ($hook) {
|
| 104 |
// Send a new variable, $logged_in, to page.tpl.php to tell us if the current user is logged in or out.
|
| 105 |
case 'page':
|
| 106 |
// get the currently logged in user
|
| 107 |
global $user;
|
| 108 |
|
| 109 |
// An anonymous user has a user id of zero.
|
| 110 |
if ($user->uid > 0) {
|
| 111 |
// The user is logged in.
|
| 112 |
$vars['logged_in'] = TRUE;
|
| 113 |
}
|
| 114 |
else {
|
| 115 |
// The user has logged out.
|
| 116 |
$vars['logged_in'] = FALSE;
|
| 117 |
}
|
| 118 |
|
| 119 |
$body_classes = array();
|
| 120 |
// classes for body element
|
| 121 |
// allows advanced theming based on context (home page, node of certain type, etc.)
|
| 122 |
$body_classes[] = ($vars['is_front']) ? 'front' : 'not-front';
|
| 123 |
$body_classes[] = ($vars['logged_in']) ? 'logged-in' : 'not-logged-in';
|
| 124 |
if ($vars['node']->type) {
|
| 125 |
$body_classes[] = 'ntype-'. hunchbaque_id_safe($vars['node']->type);
|
| 126 |
}
|
| 127 |
|
| 128 |
// This following bit of code sets flags for if sidebars exist. If you
|
| 129 |
// have multiple regions in the sidebars, add them to the conditional.
|
| 130 |
// The first is for the left side and the second for the right.
|
| 131 |
if ($vars['search_box']||$vars['main_supplements']) {
|
| 132 |
$leftBar = true;
|
| 133 |
}
|
| 134 |
|
| 135 |
if ($vars['secondary_supplements']) {
|
| 136 |
$rightBar = true;
|
| 137 |
}
|
| 138 |
|
| 139 |
|
| 140 |
switch (TRUE) {
|
| 141 |
case $leftBar && $rightBar :
|
| 142 |
$body_classes[] = 'sidebars';
|
| 143 |
break;
|
| 144 |
case $leftBar :
|
| 145 |
$body_classes[] = 'main-sidebar';
|
| 146 |
break;
|
| 147 |
case $rightBar :
|
| 148 |
$body_classes[] = 'secondary-sidebar';
|
| 149 |
break;
|
| 150 |
}
|
| 151 |
// implode with spaces
|
| 152 |
$vars['body_classes'] = implode(' ', $body_classes);
|
| 153 |
|
| 154 |
break;
|
| 155 |
|
| 156 |
case 'node':
|
| 157 |
// get the currently logged in user
|
| 158 |
global $user;
|
| 159 |
|
| 160 |
// set a new $is_admin variable
|
| 161 |
// this is determined by looking at the currently logged in user and
|
| 162 |
// seeing if they are in the role 'admin'
|
| 163 |
$vars['is_admin'] = in_array('admin', $user->roles);
|
| 164 |
|
| 165 |
$node_classes = array('node');
|
| 166 |
if ($vars['sticky']) {
|
| 167 |
$node_classes[] = 'sticky';
|
| 168 |
}
|
| 169 |
if (!$vars['node']->status) {
|
| 170 |
$node_classes[] = 'node-unpublished';
|
| 171 |
}
|
| 172 |
$node_classes[] = 'ntype-'. hunchbaque_id_safe($vars['node']->type);
|
| 173 |
// implode with spaces
|
| 174 |
$vars['node_classes'] = implode(' ', $node_classes);
|
| 175 |
|
| 176 |
break;
|
| 177 |
|
| 178 |
case 'comment':
|
| 179 |
// we load the node object that the current comment is attached to
|
| 180 |
$node = node_load($vars['comment']->nid);
|
| 181 |
// if the author of this comment is equal to the author of the node, we set a variable
|
| 182 |
// then in our theme we can theme this comment differently to stand out
|
| 183 |
$vars['author_comment'] = $vars['comment']->uid == $node->uid ? TRUE : FALSE;
|
| 184 |
break;
|
| 185 |
}
|
| 186 |
|
| 187 |
return $vars;
|
| 188 |
}
|
| 189 |
|
| 190 |
function hunchbaque_id_safe($string) {
|
| 191 |
if (is_numeric($string{0})) {
|
| 192 |
// if the first character is numeric, add 'n' in front
|
| 193 |
$string = 'n'. $string;
|
| 194 |
}
|
| 195 |
return strtolower(preg_replace('/[^a-zA-Z0-9-]+/', '-', $string));
|
| 196 |
}
|
| 197 |
|
| 198 |
/*
|
| 199 |
* The next three functions sole purpose is to make a better menu. In a
|
| 200 |
* nutshell, it applies "first" and "last" classes like in the primary and
|
| 201 |
* secondary menus.
|
| 202 |
*/
|
| 203 |
|
| 204 |
function phptemplate_menu_tree($pid = 1) {
|
| 205 |
if ($tree = phptemplate_menu_tree_improved($pid)) {
|
| 206 |
return "\n<ul class=\"menu\">\n". $tree ."</ul>\n";
|
| 207 |
}
|
| 208 |
}
|
| 209 |
|
| 210 |
function phptemplate_menu_tree_improved($pid = 1) {
|
| 211 |
$menu = menu_get_menu();
|
| 212 |
$output = '';
|
| 213 |
|
| 214 |
if (isset($menu['visible'][$pid]) && $menu['visible'][$pid]['children']) {
|
| 215 |
$num_children = count($menu['visible'][$pid]['children']);
|
| 216 |
for ($i=0; $i < $num_children; ++$i) {
|
| 217 |
$mid = $menu['visible'][$pid]['children'][$i];
|
| 218 |
$type = isset($menu['visible'][$mid]['type']) ? $menu['visible'][$mid]['type'] : NULL;
|
| 219 |
$children = isset($menu['visible'][$mid]['children']) ? $menu['visible'][$mid]['children'] : NULL;
|
| 220 |
$extraclass = $i == 0 ? 'first' : ($i == $num_children-1 ? 'last' : '');
|
| 221 |
$output .= theme('menu_item', $mid, menu_in_active_trail($mid) || ($type & MENU_EXPANDED) ? theme('menu_tree', $mid) : '', count($children) == 0, $extraclass);
|
| 222 |
}
|
| 223 |
}
|
| 224 |
|
| 225 |
return $output;
|
| 226 |
}
|
| 227 |
|
| 228 |
function phptemplate_menu_item($mid, $children = '', $leaf = TRUE, $extraclass = '') {
|
| 229 |
return ' <li class="'. ($leaf ? 'leaf' : ($children ? 'expanded' : 'collapsed')) . ($extraclass ? ' ' . $extraclass : '') . '">'. menu_item_link($mid, TRUE, $extraclass) . $children ."</li>\n";
|
| 230 |
}
|
| 231 |
|
| 232 |
/*
|
| 233 |
* This is being reworked to accommodate the hCard microformat. Now all
|
| 234 |
* contacts will show as an exportable in supporting browsers and browser
|
| 235 |
* addons.
|
| 236 |
*
|
| 237 |
* While I was at it, I removed the "(Not Verified)" text and instead added
|
| 238 |
* classes for verified and not-verified users.
|
| 239 |
*/
|
| 240 |
function phptemplate_username($object) {
|
| 241 |
|
| 242 |
if ($object->uid && $object->name) {
|
| 243 |
// Shorten the name when it is too long or it will break many tables.
|
| 244 |
if (drupal_strlen($object->name) > 20) {
|
| 245 |
$name = drupal_substr($object->name, 0, 15) .'...';
|
| 246 |
}
|
| 247 |
else {
|
| 248 |
$name = $object->name;
|
| 249 |
}
|
| 250 |
|
| 251 |
if (user_access('access user profiles')) {
|
| 252 |
$output = '<span class="vcard author">'.l($name, 'user/'. $object->uid, array('class' => 'fn url verified','title' => "$name".t("'s profile."))).'</span>';
|
| 253 |
}
|
| 254 |
else {
|
| 255 |
$output = '<span class="vcard author"><span class="fn">'.check_plain($name).'</span></span>';
|
| 256 |
}
|
| 257 |
}
|
| 258 |
else if ($object->name) {
|
| 259 |
// Sometimes modules display content composed by people who are
|
| 260 |
// not registered members of the site (e.g. mailing list or news
|
| 261 |
// aggregator modules). This clause enables modules to display
|
| 262 |
// the true author of the content.
|
| 263 |
if ($object->homepage) {
|
| 264 |
$output = '<span class="vcard author">'.l($object->name, $object->homepage, array('class' => 'fn url not-verified', 'title' => $object->name.t("'s homepage"), 'rel' => 'no-follow')).'</span>';
|
| 265 |
}
|
| 266 |
else {
|
| 267 |
$output = check_plain($object->name);
|
| 268 |
}
|
| 269 |
|
| 270 |
}
|
| 271 |
else {
|
| 272 |
$output = '<span class="vcard author"><span class="fn">'.variable_get('anonymous', t('Anonymous')).'</span></span>';
|
| 273 |
}
|
| 274 |
|
| 275 |
return $output;
|
| 276 |
}
|
| 277 |
|
| 278 |
/*
|
| 279 |
* This is a bit of code so that one can easily edit the code that appears
|
| 280 |
* around all of the comments in a theme. This is not to be confused with what
|
| 281 |
* comment.tpl.php does. That is for individual comments.
|
| 282 |
*/
|
| 283 |
|
| 284 |
function phptemplate_comment_wrapper($content, $type = null) {
|
| 285 |
static $node_type;
|
| 286 |
if (isset($type)) $node_type = $type;
|
| 287 |
|
| 288 |
if (!$content || $node_type == 'forum') {
|
| 289 |
return "<div id=\"comments\">\n ". $content . "\n</div>\n";
|
| 290 |
}
|
| 291 |
else {
|
| 292 |
return "<div id=\"comments\">\n <h2 class=\"comments\">". t('Comments') ."</h2>\n <div class=\"hfeed\">". $content ." </div>\n</div> <!-- /#comments -->\n\n";
|
| 293 |
}
|
| 294 |
}
|