| 1 |
<?php
|
| 2 |
|
| 3 |
// Nearly all of this is directly from the Hunchbaque theme, which in turn
|
| 4 |
// borrowed several things from Zen. Isn't open-source-evolution awesome!! :-)
|
| 5 |
// (thank you very much to the authors of both of those projects)
|
| 6 |
//////////////////////////////////////////////////////////////////////////////////////////
|
| 7 |
|
| 8 |
// Overriding existing css is often much more of a pain than just figuring out how to
|
| 9 |
// style something custom/new. Therefore we disable a lot of the core css so that we spend
|
| 10 |
// less time 'undo-ing' and more time 'doing'. The only ones left are the
|
| 11 |
// admin.css and system.css.
|
| 12 |
|
| 13 |
// The format below should be pretty easy to figure out so you can even remove
|
| 14 |
// other module's default styles if you find that they are difficult to
|
| 15 |
// override. (Or for that matter, put one back in if you like the drupal
|
| 16 |
// stuff.) I have tried to put the most crucial styles into this theme's
|
| 17 |
// style.css so that you have a good starting point though. I even included
|
| 18 |
// the .clear-block class sinc ethat is a very handy class to have.
|
| 19 |
|
| 20 |
// One other caveat to this approach is that if you want to use the non-drupal
|
| 21 |
// style method, you have to use atck_styles() in your page.tpl.php
|
| 22 |
// instead of the common $styles veriable. On the plus side, you can simply
|
| 23 |
// use the $styles variable if you don't like the approach here. Choice is good.
|
| 24 |
|
| 25 |
function atck_id_safe($string) {
|
| 26 |
if (is_numeric($string{0})) {
|
| 27 |
// if the first character is numeric, add 'n' in front
|
| 28 |
$string = 'n'. $string;
|
| 29 |
}
|
| 30 |
return strtolower(preg_replace('/[^a-zA-Z0-9-]+/', '-', $string));
|
| 31 |
}
|
| 32 |
|
| 33 |
function atck_styles() {
|
| 34 |
$css = drupal_add_css(path_to_theme() .'/css/style.css', 'theme', 'all');
|
| 35 |
$css = drupal_add_css(path_to_theme() .'/css/page-layout.css', 'theme', 'all');
|
| 36 |
$css = drupal_add_css();
|
| 37 |
unset($css['all']['module']['modules/node/node.css']);
|
| 38 |
unset($css['all']['module']['modules/system/defaults.css']);
|
| 39 |
unset($css['all']['module']['modules/system/system.css']);
|
| 40 |
unset($css['all']['module']['modules/system/system-menus.css']);
|
| 41 |
unset($css['all']['module']['modules/user/user.css']);
|
| 42 |
return drupal_get_css($css);
|
| 43 |
}
|
| 44 |
|
| 45 |
function atck_preprocess_page($vars) {
|
| 46 |
|
| 47 |
// Determine if the page is the front page and apply pertinent classes
|
| 48 |
// if it is. Otherwise use that arg variables to construct the class and
|
| 49 |
// id names.
|
| 50 |
switch (TRUE) {
|
| 51 |
case ($vars['is_front']):
|
| 52 |
$body_id = 'id="front-page"';
|
| 53 |
$body_class[] = 'front';
|
| 54 |
break;
|
| 55 |
|
| 56 |
case (!$vars['is_front']):
|
| 57 |
$body_class[] = 'not-front';
|
| 58 |
break;
|
| 59 |
}
|
| 60 |
|
| 61 |
switch (TRUE) {
|
| 62 |
case (!arg(0)):
|
| 63 |
$body_id = 'id="error-page"';
|
| 64 |
$body_class[] = 'is-error';
|
| 65 |
break;
|
| 66 |
|
| 67 |
case (!$vars['is_front']):
|
| 68 |
$path_alias = drupal_get_path_alias(arg(0).'/'.arg(1));
|
| 69 |
$body_id = 'id="'.atck_id_safe($path_alias).'-page"';
|
| 70 |
$path_explode = explode('/', $path_alias);
|
| 71 |
$body_class[] = $path_explode[0].'-section';
|
| 72 |
break;
|
| 73 |
}
|
| 74 |
|
| 75 |
// Check the logged in state, and add the appropriate class if so.
|
| 76 |
if ($vars['logged_in']) {
|
| 77 |
$body_class[] = 'logged-in';
|
| 78 |
}
|
| 79 |
|
| 80 |
// If we are looking at a full node view, construct a class to specify
|
| 81 |
// the node type.
|
| 82 |
if (isset($vars['node'])) {
|
| 83 |
$body_class[] = 'ntype-'.atck_id_safe($vars['node']->type);
|
| 84 |
}
|
| 85 |
|
| 86 |
// If editting a node, add a special class just for that.
|
| 87 |
if (arg(2) == 'edit') {
|
| 88 |
$body_class[] = 'edit';
|
| 89 |
}
|
| 90 |
|
| 91 |
// Normally Drupal can give me all the classes I need for the body, but
|
| 92 |
// beings I use a non-standard regions setup, we have to make our own.
|
| 93 |
switch (TRUE) {
|
| 94 |
case ($vars['main_supplements'] && $vars['secondary_supplements']):
|
| 95 |
$body_class[] = 'sidebars';
|
| 96 |
break;
|
| 97 |
|
| 98 |
case ($vars['main_supplements']):
|
| 99 |
$body_class[] = 'main-sidebar';
|
| 100 |
break;
|
| 101 |
|
| 102 |
case ($vars['secondary_supplements']):
|
| 103 |
$body_class[] = 'secondary-sidebar';
|
| 104 |
break;
|
| 105 |
|
| 106 |
default:
|
| 107 |
$body_class[] = 'no-sidebars';
|
| 108 |
break;
|
| 109 |
}
|
| 110 |
|
| 111 |
// Now we take all those classes and ids that were created for the body
|
| 112 |
// and compile them into a single variable.
|
| 113 |
$vars['body_attributes'] = $body_id.' class="'.implode(' ', $body_class).'"';
|
| 114 |
}
|
| 115 |
|
| 116 |
/**
|
| 117 |
The following function compiles classes and ids for the individual nodes
|
| 118 |
and then loaded them into a $attributes variable for the template.
|
| 119 |
*/
|
| 120 |
|
| 121 |
function atck_preprocess_node($vars) {
|
| 122 |
$node_id = 'node-'.$vars['type'].'-'.$vars['nid'];
|
| 123 |
$node_class[] = 'node';
|
| 124 |
$node_class[] = 'ntype-'.$vars['type'];
|
| 125 |
if ($vars['teaser']) {
|
| 126 |
$node_class[] = 'teaser';
|
| 127 |
}
|
| 128 |
if (!$vars['status']) {
|
| 129 |
$node_class[] = 'not-published';
|
| 130 |
}
|
| 131 |
if ($vars['promote']) {
|
| 132 |
$node_class[] = 'promoted-to-front';
|
| 133 |
}
|
| 134 |
if ($vars['sticky']) {
|
| 135 |
$node_class[] = 'sticky';
|
| 136 |
}
|
| 137 |
$node_class[] = $vars['zebra'];
|
| 138 |
|
| 139 |
$vars['attributes'] = 'id="'.$node_id.'" class="'.implode(' ', $node_class).'"';
|
| 140 |
}
|
| 141 |
|
| 142 |
/**
|
| 143 |
Comments need proper ids and classes too. This is pretty much the same
|
| 144 |
process as the page and nodes.
|
| 145 |
*/
|
| 146 |
|
| 147 |
function atck_preprocess_comment($vars) {
|
| 148 |
$comment_id = 'node-'.$vars['node']->nid.'-comment-'.$vars['comment']->cid;
|
| 149 |
$comment_class[] = 'comment';
|
| 150 |
if ($vars['comment']->uid == $vars['node']->uid) {
|
| 151 |
$comment_class[] = 'author';
|
| 152 |
}
|
| 153 |
if ($vars['comment']->status) {
|
| 154 |
$comment_class[] = 'not-published';
|
| 155 |
}
|
| 156 |
if ($vars['comment']->new) {
|
| 157 |
$comment_class[] = 'new';
|
| 158 |
}
|
| 159 |
$comment_class[] = $vars['zebra'];
|
| 160 |
|
| 161 |
$vars['attributes'] = 'id="'.$comment_id.'" class="'.implode(' ', $comment_class).'"';
|
| 162 |
}
|
| 163 |
|
| 164 |
/**
|
| 165 |
Set the block classes.
|
| 166 |
*/
|
| 167 |
|
| 168 |
function atck_preprocess_block($vars) {
|
| 169 |
$block_id = 'block-'.$vars['block']->module.'-'.$vars['block']->bid;
|
| 170 |
$block_class[] = 'block';
|
| 171 |
$block_class[] = 'btype-'.$vars['block']->module;
|
| 172 |
$block_class[] = $vars['zebra'];
|
| 173 |
|
| 174 |
$vars['attributes'] = 'id="'.$block_id.'" class="'.implode(' ', $block_class).'"';
|
| 175 |
}
|
| 176 |
|
| 177 |
/**
|
| 178 |
I had to wrap the profile with some extra containers to make it more
|
| 179 |
themeable out of the box, so I decided some extra class and id
|
| 180 |
information would also be handy.
|
| 181 |
*/
|
| 182 |
|
| 183 |
function atck_preprocess_user_profile($vars) {
|
| 184 |
$profile_id = 'user-profile-'.$vars['account']->uid;
|
| 185 |
$profile_class[] = 'user-profile';
|
| 186 |
if ($vars['is_admin']) {
|
| 187 |
$profile_class[] = 'administrator';
|
| 188 |
}
|
| 189 |
$profile_class[] = $vars['zebra'];
|
| 190 |
|
| 191 |
$vars['attributes'] = 'id="'.$profile_id.'" class="'.implode(' ', $profile_class).'"';
|
| 192 |
}
|
| 193 |
|
| 194 |
function atck_preprocess_node_add_list($vars) {
|
| 195 |
$ntype_add_id = 'content-add-listing';
|
| 196 |
$ntype_add_class[] = 'content-add';
|
| 197 |
$ntype_add_class[] = 'edit';
|
| 198 |
|
| 199 |
$vars['attributes'] = 'id="'.$ntype_add_id.'" class="'.implode(' ', $ntype_add_class).'"';
|
| 200 |
|
| 201 |
$vars['node_list'] = '<dl class="ntype-add-list">'."\n";
|
| 202 |
foreach($vars['content'] as $item) {
|
| 203 |
$vars['node_list'] .= ' <dt>'.l($item['link_title'], $item['link_path'], $item['options']).'</dt>'."\n";
|
| 204 |
$vars['node_list'] .= ' <dd>'.$item['options']['attributes']['title'].'</dd>'."\n";
|
| 205 |
}
|
| 206 |
$vars['node_list'] .= '</dl>'."\n";
|
| 207 |
}
|