| 1 |
<?php
|
| 2 |
/**
|
| 3 |
* $Id: template.php,v 1.1.2.9 2008/02/07 10:01:19 ber Exp $
|
| 4 |
*
|
| 5 |
* Sympal theme is a base theme, so it comes with a lot of pre-built code.
|
| 6 |
* We aim at consistency, so override almost everything here, and represent it
|
| 7 |
* in a consistent way.
|
| 8 |
* Feel free to submit new partial files and patches with _phptemplate_callback
|
| 9 |
* Bèr Kessels carpentered this in webschuur.com for sympal.nl
|
| 10 |
*/
|
| 11 |
|
| 12 |
/**
|
| 13 |
* General core functions
|
| 14 |
*/
|
| 15 |
|
| 16 |
/**
|
| 17 |
* menu and navigation functions
|
| 18 |
* TODO introduce classes like 'active' and 'expanded'
|
| 19 |
*/
|
| 20 |
function sympal_theme_primary_links($links, $id_add = '') {
|
| 21 |
if (!empty($id_add)) {
|
| 22 |
$id_add = '-'. $id_add;
|
| 23 |
}
|
| 24 |
return _phptemplate_callback('primary_links', array('links' => $links, 'id_add' => $id_add));
|
| 25 |
}
|
| 26 |
function sympal_theme_secondary_links($links, $id_add = '') {
|
| 27 |
if (!empty($id_add)) {
|
| 28 |
$id_add = '-'. $id_add;
|
| 29 |
}
|
| 30 |
return _phptemplate_callback('secondary_links', array('links' => $links, 'id_add' => $id_add));
|
| 31 |
}
|
| 32 |
|
| 33 |
function sympal_theme_menu_tree($pid = 1) {
|
| 34 |
if ($tree = menu_tree($pid)) {
|
| 35 |
// TODO a static var that counts the depth.
|
| 36 |
return _phptemplate_callback('menu_tree', array('tree' => $tree, 'pid' => $pid));
|
| 37 |
}
|
| 38 |
}
|
| 39 |
|
| 40 |
/**
|
| 41 |
* Local tasks AKA tabs
|
| 42 |
*/
|
| 43 |
function sympal_theme_menu_local_tasks($id_add = '') {
|
| 44 |
$output = '';
|
| 45 |
if (!empty($id_add)) {
|
| 46 |
$id_add = '-'. $id_add;
|
| 47 |
}
|
| 48 |
//TODO: build the $links not as an ugly string, but rather an array of items!
|
| 49 |
if ($links = menu_primary_local_tasks()) {
|
| 50 |
$output = _phptemplate_callback('menu_local_tasks_primary', array('links' => $links, 'id_add' => $id_add));
|
| 51 |
$links = '';
|
| 52 |
}
|
| 53 |
if ($links = menu_secondary_local_tasks()) {
|
| 54 |
$output .= _phptemplate_callback('menu_local_tasks_secondary', array('links' => $links, 'id_add' => $id_add));
|
| 55 |
}
|
| 56 |
|
| 57 |
return $output;
|
| 58 |
}
|
| 59 |
|
| 60 |
/**
|
| 61 |
* A single Localtask AKA tab
|
| 62 |
*/
|
| 63 |
function sympal_theme_menu_local_task($mid, $active, $primary) {
|
| 64 |
return _phptemplate_callback('menu_local_task', array('mid' => $mid, 'active' => $active));
|
| 65 |
}
|
| 66 |
function sympal_theme_menu_item_link($item, $link_item) {
|
| 67 |
return _phptemplate_callback('menu_item_link', array('item' => $item, 'link_item' => $link_item));
|
| 68 |
}
|
| 69 |
|
| 70 |
/**
|
| 71 |
* Breadcrumbs in a single partial
|
| 72 |
*/
|
| 73 |
function sympal_theme_breadcrumb($breadcrumb) {
|
| 74 |
if (!empty($breadcrumb)) {
|
| 75 |
return _phptemplate_callback('breadcrumb', array('links' => $breadcrumb));
|
| 76 |
}
|
| 77 |
}
|
| 78 |
|
| 79 |
/**
|
| 80 |
* Comment form
|
| 81 |
*/
|
| 82 |
function sympal_theme_comment_form($form) {
|
| 83 |
$vars = array(
|
| 84 |
'admin' => drupal_render($form['admin']),
|
| 85 |
'contact' => drupal_render($form['name']) . drupal_render($form['mail']) . drupal_render($form['homepage']) . drupal_render($form['_author']),
|
| 86 |
'subject' => drupal_render($form['subject']),
|
| 87 |
'comment' => drupal_render($form['comment_filter']['comment']),
|
| 88 |
'filter' => drupal_render($form['comment_filter']['format']),
|
| 89 |
'buttons' => drupal_render($form['submit']) . drupal_render($form['preview']),
|
| 90 |
'rest' => drupal_render($form),
|
| 91 |
);
|
| 92 |
|
| 93 |
return _phptemplate_callback('comment_form', $vars);
|
| 94 |
}
|
| 95 |
|
| 96 |
/**
|
| 97 |
* Render a userpicture (avatar)
|
| 98 |
*
|
| 99 |
* @return string image tag containing the userpicture
|
| 100 |
**/
|
| 101 |
function sympal_theme_user_picture($account) {
|
| 102 |
$out = '';
|
| 103 |
$vars['account'] = $account;
|
| 104 |
|
| 105 |
if (variable_get('user_pictures', 0)) {
|
| 106 |
if ($account->picture && file_exists($account->picture)) {
|
| 107 |
$vars['picture_file'] = file_create_url($account->picture);
|
| 108 |
}
|
| 109 |
else if (variable_get('user_picture_default', '')) {
|
| 110 |
$vars['picture_file'] = variable_get('user_picture_default', '');
|
| 111 |
}
|
| 112 |
|
| 113 |
if (isset($vars['picture_file'])) {
|
| 114 |
$vars['alt'] = t("@user's picture", array('@user' => $account->name ? $account->name : variable_get('anonymous', t('Anonymous'))));
|
| 115 |
|
| 116 |
if (!empty($account->uid) && user_access('access user profiles')) {
|
| 117 |
$vars['has_link'] = TRUE;
|
| 118 |
}
|
| 119 |
|
| 120 |
$out = _phptemplate_callback('user_picture', $vars);
|
| 121 |
}
|
| 122 |
}
|
| 123 |
return $out;
|
| 124 |
}
|
| 125 |
|
| 126 |
/**
|
| 127 |
* Format a news feed.
|
| 128 |
*/
|
| 129 |
function sympal_theme_aggregator_feed($feed) {
|
| 130 |
$vars = array(
|
| 131 |
'icon' => theme('feed_icon', $feed->url),
|
| 132 |
'image' => $feed->image,
|
| 133 |
'description' => aggregator_filter_xss($feed->description),
|
| 134 |
'url' => l($feed->link, $feed->link, array(), NULL, NULL, TRUE),
|
| 135 |
);
|
| 136 |
|
| 137 |
if (user_access('administer news feeds')) {
|
| 138 |
$vars['updated'] = l($updated, 'admin/content/aggregator');
|
| 139 |
}
|
| 140 |
elseif ($feed->checked) {
|
| 141 |
$vars['updated'] = t('@time ago', array('@time' => format_interval(time() - $feed->checked)));
|
| 142 |
}
|
| 143 |
else {
|
| 144 |
$vars['updated'] = t('never');
|
| 145 |
}
|
| 146 |
|
| 147 |
return _phptemplate_callback('aggregator_feed', $vars);
|
| 148 |
}
|
| 149 |
|
| 150 |
/**
|
| 151 |
* Format an individual feed item for display on the aggregator page.
|
| 152 |
*/
|
| 153 |
function sympal_theme_aggregator_page_item($item) {
|
| 154 |
|
| 155 |
$vars['source'] = '';
|
| 156 |
if ($item->ftitle && $item->fid) {
|
| 157 |
$vars['source'] = l($item->ftitle, "aggregator/sources/$item->fid", array('class' => 'feed-item-source'));
|
| 158 |
}
|
| 159 |
|
| 160 |
if (date('Ymd', $item->timestamp) == date('Ymd')) {
|
| 161 |
$vars['source_date'] = t('%ago ago', array('%ago' => format_interval(time() - $item->timestamp)));
|
| 162 |
}
|
| 163 |
else {
|
| 164 |
$vars['source_date'] = format_date($item->timestamp, 'custom', variable_get('date_format_medium', 'D, m/d/Y - H:i'));
|
| 165 |
}
|
| 166 |
|
| 167 |
$vars['description'] = aggregator_filter_xss($item->description);
|
| 168 |
$vars['link'] = check_url($item->link);
|
| 169 |
$vars['title'] = check_plain($item->title);
|
| 170 |
|
| 171 |
$result = db_query('SELECT c.title, c.cid FROM {aggregator_category_item} ci LEFT JOIN {aggregator_category} c ON ci.cid = c.cid WHERE ci.iid = %d ORDER BY c.title', $item->iid);
|
| 172 |
$categories = array();
|
| 173 |
while ($category = db_fetch_object($result)) {
|
| 174 |
$vars['categories'][] = l($category->title, 'aggregator/categories/'. $category->cid);
|
| 175 |
}
|
| 176 |
|
| 177 |
return _phptemplate_callback('aggregator_page_item', $vars);
|
| 178 |
}
|
| 179 |
|
| 180 |
/**
|
| 181 |
* Return a themed item heading for summary pages located at "aggregator/sources"
|
| 182 |
* and "aggregator/categories".
|
| 183 |
*
|
| 184 |
* @param $item The item object from the aggregator module.
|
| 185 |
*/
|
| 186 |
function sympal_theme_aggregator_summary_item($item) {
|
| 187 |
$vars = array(
|
| 188 |
'item' => $item,
|
| 189 |
'item_link' => check_url($item->link),
|
| 190 |
'feed_link' => check_url($item->feed_link),
|
| 191 |
'item_title' => check_plain($item->title),
|
| 192 |
'feed_title' => check_plain($item->feed_title),
|
| 193 |
'age' => t('%age old', array('%age' => format_interval(time() - $item->timestamp))),
|
| 194 |
);
|
| 195 |
|
| 196 |
return _phptemplate_callback('aggregator_summary_item', $vars);
|
| 197 |
}
|
| 198 |
|
| 199 |
/**
|
| 200 |
* Search form functions
|
| 201 |
*/
|
| 202 |
function sympal_theme_search_theme_form($form) {
|
| 203 |
return _phptemplate_callback('search_form', array('form' => $form));
|
| 204 |
}
|
| 205 |
function sympal_theme_search_block_form($form) {
|
| 206 |
return _phptemplate_callback('search_form', array('form' => $form));
|
| 207 |
}
|
| 208 |
|
| 209 |
/**
|
| 210 |
* Warning, error and help messages
|
| 211 |
*/
|
| 212 |
function sympal_theme_status_messages() {
|
| 213 |
if ($data = drupal_get_messages()) {
|
| 214 |
foreach ($data as $type => $messages) {
|
| 215 |
$grouped_messages .= _phptemplate_callback('status_messages_by_type', array(
|
| 216 |
'messages' => $messages,
|
| 217 |
'type' => $type,
|
| 218 |
));
|
| 219 |
}
|
| 220 |
return _phptemplate_callback('status_messages', array(
|
| 221 |
'grouped_messages' => $grouped_messages,
|
| 222 |
));
|
| 223 |
}
|
| 224 |
}
|
| 225 |
|
| 226 |
/**
|
| 227 |
* New functions introduced here, used as helpers or simpler ways to theme stuff.
|
| 228 |
*/
|
| 229 |
/**
|
| 230 |
* Terms are now themed trough a way too general theme_links.
|
| 231 |
* This function is a helper to render terms in a node.
|
| 232 |
*/
|
| 233 |
function sympal_theme_taxonomy_terms_for_node($node) {
|
| 234 |
$links = taxonomy_link('taxonomy terms', $node);
|
| 235 |
if (count($links)) {
|
| 236 |
return _phptemplate_callback('taxonomy_terms_for_node', array('links' => $links, 'terms' => $node->taxonomy, 'node' => $node));
|
| 237 |
}
|
| 238 |
else {
|
| 239 |
return '';
|
| 240 |
}
|
| 241 |
}
|
| 242 |
|
| 243 |
/**
|
| 244 |
* General phptemplate stuff
|
| 245 |
*/
|
| 246 |
/**
|
| 247 |
* Make additional variables available and override some core variables
|
| 248 |
* TODO: add node counters and zebras
|
| 249 |
* TODO: add comment counters and zebras
|
| 250 |
*/
|
| 251 |
function _phptemplate_variables($hook, $vars) {
|
| 252 |
static $count;
|
| 253 |
$count = is_array($count) ? $count : array();
|
| 254 |
$count[$hook] = is_int($count[$hook]) ? $count[$hook] : 1;
|
| 255 |
$vars['zebra'] = ($count[$hook] % 2) ? 'odd' : 'even';
|
| 256 |
$vars['seqid'] = $count[$hook]++;
|
| 257 |
|
| 258 |
switch ($hook) {
|
| 259 |
case 'page':
|
| 260 |
$vars['css'] = _sympal_theme_unset_css($vars['css']);
|
| 261 |
$vars['styles'] = drupal_get_css($vars['css']);
|
| 262 |
break;
|
| 263 |
case 'node':
|
| 264 |
$vars['terms'] = theme('taxonomy_terms_for_node', $vars['node']);
|
| 265 |
break;
|
| 266 |
}
|
| 267 |
|
| 268 |
return $vars;
|
| 269 |
}
|
| 270 |
|
| 271 |
/**
|
| 272 |
* Unset all module and core styles
|
| 273 |
**/
|
| 274 |
function _sympal_theme_unset_css($css) {
|
| 275 |
if (is_array($css['all']['module'])) {
|
| 276 |
$css['all']['module'] = array();
|
| 277 |
}
|
| 278 |
return $css;
|
| 279 |
}
|
| 280 |
|
| 281 |
/**
|
| 282 |
* define regions
|
| 283 |
**/
|
| 284 |
function sympal_theme_regions() {
|
| 285 |
return array(
|
| 286 |
'content' => t('content'),
|
| 287 |
'branding' => t('branding'),
|
| 288 |
'navigation' => t('navigation'),
|
| 289 |
'tools' => t('tools'),
|
| 290 |
'search' => t('search'),
|
| 291 |
'siteinfo' => t('siteinfo'),
|
| 292 |
'content_prefix' => t('before content'),
|
| 293 |
'content_postfix' => t('after content'),
|
| 294 |
);
|
| 295 |
}
|
| 296 |
?>
|