| 1 |
<?php
|
| 2 |
/* $Id: zengine.engine,v 1.2 2007/05/06 00:36:34 jjeff Exp $
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
88
|
| 7 |
""
|
| 8 |
|
| 9 |
888888888 ,adPPYba, 8b,dPPYba, ,adPPYb,d8 88 8b,dPPYba, ,adPPYba,
|
| 10 |
a8P" a8P_____88 88P' `"8a a8" `Y88 88 88P' `"8a a8P_____88
|
| 11 |
,d8P' 8PP""""""" 88 88 8b 88 88 88 88 8PP"""""""
|
| 12 |
,d8" "8b, ,aa 88 88 "8a, ,d88 88 88 88 "8b, ,aa
|
| 13 |
888888888 `"Ybbd8"' 88 88 `"YbbdP"Y8 88 88 88 `"Ybbd8"'
|
| 14 |
aa, ,88
|
| 15 |
"Y8bbdP" The theme engine for Drupal
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
*/
|
| 24 |
|
| 25 |
/**
|
| 26 |
* @file
|
| 27 |
* PHPTemplate-based theme engine for Drupal
|
| 28 |
*/
|
| 29 |
|
| 30 |
// zengine implements allmost any of its magic through calls to phptemplate.engine
|
| 31 |
require_once('themes/engines/phptemplate/phptemplate.engine');
|
| 32 |
|
| 33 |
function zengine_init($template) {
|
| 34 |
return phptemplate_init($template);
|
| 35 |
}
|
| 36 |
|
| 37 |
function zengine_templates($directory = 'themes') {
|
| 38 |
$files = drupal_system_listing('\.info$', $directory, 'filename');
|
| 39 |
foreach ($files as $file) {
|
| 40 |
$info = parse_ini_file($file->filename);
|
| 41 |
if ($info['engine'] == 'zengine') {
|
| 42 |
$themes[] = $file;
|
| 43 |
}
|
| 44 |
}
|
| 45 |
return $themes;
|
| 46 |
}
|
| 47 |
|
| 48 |
function zengine_regions() {
|
| 49 |
return array(
|
| 50 |
'left' => t('left sidebar'),
|
| 51 |
'right' => t('right sidebar'),
|
| 52 |
'content_top' => t('content top'),
|
| 53 |
'content_bottom' => t('content bottom'),
|
| 54 |
'header' => t('header'),
|
| 55 |
'footer' => t('footer')
|
| 56 |
);
|
| 57 |
}
|
| 58 |
|
| 59 |
// rewrite of _phptemplate_default()
|
| 60 |
// changes are commented
|
| 61 |
function _zengine_default($hook, $variables, $suggestions = array(), $extension = '.zen.php') {
|
| 62 |
global $theme_engine;
|
| 63 |
|
| 64 |
// Loop through any suggestions in FIFO order.
|
| 65 |
$suggestions = array_reverse($suggestions);
|
| 66 |
foreach ($suggestions as $suggestion) {
|
| 67 |
if (!empty($suggestion) && file_exists(path_to_theme() .'/'. $suggestion . $extension)) {
|
| 68 |
$file = path_to_theme() .'/'. $suggestion . $extension;
|
| 69 |
break;
|
| 70 |
}
|
| 71 |
}
|
| 72 |
|
| 73 |
if (!isset($file)) {
|
| 74 |
if (file_exists(path_to_theme() ."/$hook$extension")) {
|
| 75 |
$file = path_to_theme() ."/$hook$extension";
|
| 76 |
}
|
| 77 |
else {
|
| 78 |
// <-- added 'page' to the following line -->
|
| 79 |
if (in_array($hook, array('node', 'block', 'box', 'comment', 'page'))) {
|
| 80 |
// <-- end changes -->
|
| 81 |
$file = path_to_engine() .'/'. $hook . $extension;
|
| 82 |
}
|
| 83 |
else {
|
| 84 |
$variables['hook'] = $hook;
|
| 85 |
watchdog('error', t('%engine.engine was instructed to override the %name theme function, but no valid template file was found.', array('%engine' => $theme_engine, '%name' => $hook)));
|
| 86 |
$file = path_to_engine() .'/default'. $extension;
|
| 87 |
}
|
| 88 |
}
|
| 89 |
}
|
| 90 |
|
| 91 |
if (isset($file)) {
|
| 92 |
return call_user_func('_'. $theme_engine .'_render', $file, $variables);
|
| 93 |
}
|
| 94 |
}
|
| 95 |
|
| 96 |
function zengine_features() {
|
| 97 |
return phptemplate_features();
|
| 98 |
}
|
| 99 |
|
| 100 |
function zengine_page($content, $show_blocks = TRUE) {
|
| 101 |
return phptemplate_page($content, $show_blocks);
|
| 102 |
}
|
| 103 |
|
| 104 |
function zengine_node($node, $teaser = 0, $page = 0) {
|
| 105 |
return phptemplate_node($node, $teaser, $page);
|
| 106 |
}
|
| 107 |
|
| 108 |
function zengine_comment($comment, $links = 0) {
|
| 109 |
return phptemplate_comment($comment, $links);
|
| 110 |
}
|
| 111 |
|
| 112 |
function zengine_block($block) {
|
| 113 |
return phptemplate_block($block);
|
| 114 |
}
|
| 115 |
|
| 116 |
function zengine_box($title, $content, $region = 'main') {
|
| 117 |
return phptemplate_box($title, $content, $region);
|
| 118 |
}
|
| 119 |
|
| 120 |
function _zengine_render($file, $variables) {
|
| 121 |
return _phptemplate_render($file, $variables);
|
| 122 |
}
|
| 123 |
|
| 124 |
function _zengine_variables($hook, $vars = array()) {
|
| 125 |
// get the currently logged in user
|
| 126 |
global $user;
|
| 127 |
|
| 128 |
static $counters = array();
|
| 129 |
$vars['count'] = $counters[$hook]['count']++;
|
| 130 |
|
| 131 |
// An anonymous user has a user id of zero.
|
| 132 |
$vars['logged_in'] = ($user->uid > 0);
|
| 133 |
|
| 134 |
// set a new $is_admin variable
|
| 135 |
// this variable is available to all templates
|
| 136 |
$vars['is_admin'] = user_access('access administration pages');
|
| 137 |
|
| 138 |
switch ($hook) {
|
| 139 |
// Send a new variable, $logged_in, to page.tpl.php to tell us if the current user is logged in or out.
|
| 140 |
case 'page':
|
| 141 |
|
| 142 |
global $theme, $theme_key;
|
| 143 |
|
| 144 |
// maybe this should get abstracted
|
| 145 |
$zen_css_files = array(
|
| 146 |
array('file' => 'fonts.css', 'scope' => 'all'),
|
| 147 |
array('file' => 'zengine.css', 'scope' => 'all'),
|
| 148 |
array('file' => 'layout.css', 'scope' => 'all'),
|
| 149 |
array('file' => 'icons.css', 'scope' => 'all'),
|
| 150 |
array('file' => 'colors.css', 'scope' => 'all'),
|
| 151 |
array('file' => 'print.css', 'scope' => 'print'),
|
| 152 |
);
|
| 153 |
|
| 154 |
foreach ($zen_css_files as $css_file) {
|
| 155 |
if (file_exists(path_to_theme() .'/'. $css_file['file'])) {
|
| 156 |
$css_path = path_to_theme() .'/'. $css_file['file'];
|
| 157 |
}
|
| 158 |
else {
|
| 159 |
$css_path = path_to_engine() .'/'. $css_file['file'];
|
| 160 |
}
|
| 161 |
$vars['css'] = drupal_add_css($css_path, 'theme', $css_file['scope'] ? $css_file['scope'] : 'all');
|
| 162 |
}
|
| 163 |
|
| 164 |
if (file_exists(path_to_theme() .'/style.css')) {
|
| 165 |
$styles_path = path_to_theme() .'/style.css';
|
| 166 |
} else {
|
| 167 |
$styles_path = path_to_engine() .'/style.css';
|
| 168 |
}
|
| 169 |
|
| 170 |
unset($vars['css']['all']['theme'][$vars['directory'] .'/style.css']);
|
| 171 |
$vars['css']['all']['theme'][$styles_path] = 1;
|
| 172 |
$vars['styles'] = drupal_get_css($vars['css']);
|
| 173 |
|
| 174 |
// @todo: IE hacks using conditional comments?
|
| 175 |
|
| 176 |
$body_classes = array();
|
| 177 |
// classes for body element
|
| 178 |
// allows advanced theming based on context (home page, node of certain type, etc.)
|
| 179 |
$body_classes[] = ($vars['is_front']) ? 'front' : 'not-front';
|
| 180 |
$body_classes[] = ($vars['logged_in']) ? 'logged-in' : 'not-logged-in';
|
| 181 |
if ($vars['node']->type) {
|
| 182 |
// if on an individual node page, put the node type in the body classes
|
| 183 |
$body_classes[] = 'ntype-'. form_clean_id($vars['node']->type);
|
| 184 |
}
|
| 185 |
switch (TRUE) {
|
| 186 |
case $vars['sidebar_left'] && $vars['sidebar_right'] :
|
| 187 |
$body_classes[] = 'both-sidebars';
|
| 188 |
break;
|
| 189 |
case $vars['sidebar_left'] :
|
| 190 |
$body_classes[] = 'sidebar-left';
|
| 191 |
break;
|
| 192 |
case $vars['sidebar_right'] :
|
| 193 |
$body_classes[] = 'sidebar-right';
|
| 194 |
break;
|
| 195 |
}
|
| 196 |
// implode with spaces
|
| 197 |
$vars['body_classes'] = implode(' ', $body_classes);
|
| 198 |
|
| 199 |
break;
|
| 200 |
|
| 201 |
case 'node':
|
| 202 |
if ($vars['submitted']) {
|
| 203 |
// we redefine the format for submitted
|
| 204 |
// adding microformats
|
| 205 |
$vars['submitted'] =
|
| 206 |
t('Posted <abbr class="created" title="!microdate">@date</abbr> by !username',
|
| 207 |
array(
|
| 208 |
'!username' => theme('username', $vars['node']),
|
| 209 |
'@date' => format_date($vars['node']->created,'custom', "F jS, Y"),
|
| 210 |
'!microdate' => format_date($vars['node']->created,'custom', "Y-m-d\TH:i:sO")
|
| 211 |
)
|
| 212 |
);
|
| 213 |
}
|
| 214 |
|
| 215 |
// special classes for nodes
|
| 216 |
$node_classes = array('node');
|
| 217 |
if ($vars['sticky']) {
|
| 218 |
$node_classes[] = 'sticky';
|
| 219 |
}
|
| 220 |
if (!$vars['node']->status) {
|
| 221 |
$node_classes[] = 'node-unpublished';
|
| 222 |
}
|
| 223 |
if ($vars['node']->uid && $vars['node']->uid == $user->uid) {
|
| 224 |
// node is authored by current user
|
| 225 |
$node_classes[] = 'node-mine';
|
| 226 |
}
|
| 227 |
// class for node type: "ntype-page", "ntype-story", "ntype-my-custom-type", etc.
|
| 228 |
$node_classes[] = 'ntype-'. form_clean_id($vars['node']->type);
|
| 229 |
|
| 230 |
$node_classes[] = $vars['zebra'];
|
| 231 |
|
| 232 |
// implode with spaces
|
| 233 |
$vars['node_classes'] = implode(' ', $node_classes);
|
| 234 |
|
| 235 |
break;
|
| 236 |
|
| 237 |
case 'comment':
|
| 238 |
// we load the node object that the current comment is attached to
|
| 239 |
$node = node_load($vars['comment']->nid);
|
| 240 |
// if the author of this comment is equal to the author of the node, we set a variable
|
| 241 |
// then in our theme we can theme this comment differently to stand out
|
| 242 |
$vars['author_comment'] = $vars['comment']->uid == $node->uid ? TRUE : FALSE;
|
| 243 |
|
| 244 |
$comment_classes = array('comment');
|
| 245 |
|
| 246 |
if ($vars['comment']->status == COMMENT_NOT_PUBLISHED) {
|
| 247 |
$comment_classes[] = 'comment-unpublished';
|
| 248 |
}
|
| 249 |
if ($vars['author_comment']) {
|
| 250 |
// comment is by the node author
|
| 251 |
$comment_classes[] = 'comment-by-author';
|
| 252 |
}
|
| 253 |
if ($vars['comment']->uid == 0) {
|
| 254 |
// comment is by an anonymous user
|
| 255 |
$comment_classes[] = 'comment-by-anon';
|
| 256 |
}
|
| 257 |
if ($user->uid && $vars['comment']->uid == $user->uid) {
|
| 258 |
// comment was posted by current user
|
| 259 |
$comment_classes[] = 'comment-mine';
|
| 260 |
}
|
| 261 |
$comment_classes[] = $vars['zebra'];
|
| 262 |
|
| 263 |
$vars['comment_classes'] = implode(' ', $comment_classes);
|
| 264 |
|
| 265 |
// if comment subjects are disabled, don't display 'em
|
| 266 |
if (variable_get('comment_subject_field', 1) == 0) {
|
| 267 |
$vars['title'] = '';
|
| 268 |
}
|
| 269 |
|
| 270 |
break;
|
| 271 |
|
| 272 |
case 'block' :
|
| 273 |
$block = $vars['block'];
|
| 274 |
$block_classes[] = 'block';
|
| 275 |
$block_classes[] = 'block-'. form_clean_id($block->module);
|
| 276 |
$block_classes[] = $vars['zebra'];
|
| 277 |
$vars['block_classes'] = implode(' ', $block_classes);
|
| 278 |
|
| 279 |
if (user_access('administer blocks')) {
|
| 280 |
$edit_links = '<div class="edit">';
|
| 281 |
$edit_links .= "[". l(t('configure'), 'admin/build/block/configure/'. $block->module .'/'. $block->delta, array(), drupal_get_destination()) ."]";
|
| 282 |
|
| 283 |
if ($block->module == 'views') {
|
| 284 |
$view = views_get_view($block->delta);
|
| 285 |
$edit_links .= " [". l(t('edit view'), 'admin/build/views/'. $view->vid .'/edit', array(), drupal_get_destination(), 'edit-block') ."]";
|
| 286 |
}
|
| 287 |
elseif ($block->module == 'menu' || ($block->module == 'user' && $block->delta == 1)) {
|
| 288 |
$edit_links .= " [". l(t('edit menu'), 'admin/build/menu', array(), drupal_get_destination()) ."]";
|
| 289 |
}
|
| 290 |
$edit_links .= "</div>";
|
| 291 |
$vars['edit_links'] = $edit_links;
|
| 292 |
}
|
| 293 |
|
| 294 |
}
|
| 295 |
|
| 296 |
return $vars;
|
| 297 |
}
|