/[drupal]/contributions/themes/abarre/template.php
ViewVC logotype

Contents of /contributions/themes/abarre/template.php

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download) (as text)
Fri Jul 18 04:17:45 2008 UTC (16 months, 1 week ago) by couzinhub
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-5, DRUPAL-6--1
File MIME type: text/x-php
Initial commit of the Abarre theme
1 <?php
2 // $Id$
3
4 /*
5 * Declare the available regions implemented by this engine.
6 *
7 * @return
8 * An array of regions. The first array element will be used as the default region for themes.
9 * Each array element takes the format: variable_name => t('human readable name')
10 */
11
12 function abarre_regions() {
13 return array(
14 'left' => t('left sidebar'),
15 'content_top' => t('content top'),
16 'content_bottom' => t('content bottom'),
17 'header' => t('header'),
18 'footer' => t('footer')
19 );
20 }
21
22
23 /**
24 * Intercept template variables
25 *
26 * @param $hook
27 * The name of the theme function being executed
28 * @param $vars
29 * A sequential array of variables passed to the theme function.
30 */
31
32 function _phptemplate_variables($hook, $vars = array()) {
33 switch ($hook) {
34 // Send a new variable, $logged_in, to page.tpl.php to tell us if the current user is logged in or out.
35 case 'page':
36 // get the currently logged in user
37 global $user;
38
39 // An anonymous user has a user id of zero.
40 if ($user->uid > 0) {
41 // The user is logged in.
42 $vars['logged_in'] = TRUE;
43 }
44 else {
45 // The user has logged out.
46 $vars['logged_in'] = FALSE;
47 }
48
49 $body_classes = array();
50 // classes for body element
51 // allows advanced theming based on context (home page, node of certain type, etc.)
52 $body_classes[] = ($vars['is_front']) ? 'front' : 'not-front';
53 $body_classes[] = ($vars['logged_in']) ? 'logged-in' : 'not-logged-in';
54 if ($vars['node']->type) {
55 $body_classes[] = 'ntype-'. abarre_id_safe($vars['node']->type);
56 }
57 // implode with spaces
58 $vars['body_classes'] = implode(' ', $body_classes);
59
60 break;
61
62 case 'node':
63 // get the currently logged in user
64 global $user;
65
66 // set a new $is_admin variable
67 // this is determined by looking at the currently logged in user and seeing if they are in the role 'admin'
68 $vars['is_admin'] = in_array('admin', $user->roles);
69
70 $node_classes = array('node');
71 if ($vars['sticky']) {
72 $node_classes[] = 'sticky';
73 }
74 if (!$vars['node']->status) {
75 $node_classes[] = 'node-unpublished';
76 }
77 $node_classes[] = 'ntype-'. abarre_id_safe($vars['node']->type);
78 // implode with spaces
79 $vars['node_classes'] = implode(' ', $node_classes);
80
81 break;
82
83 case 'comment':
84 // we load the node object that the current comment is attached to
85 $node = node_load($vars['comment']->nid);
86 // if the author of this comment is equal to the author of the node, we set a variable
87 // then in our theme we can theme this comment differently to stand out
88 $vars['author_comment'] = $vars['comment']->uid == $node->uid ? TRUE : FALSE;
89 break;
90 }
91
92 return $vars;
93 }
94
95 /**
96 * Converts a string to a suitable html ID attribute.
97 * - Preceeds initial numeric with 'n' character.
98 * - Replaces space and underscore with dash.
99 * - Converts entire string to lowercase.
100 * - Works for classes too!
101 *
102 * @param string $string
103 * the string
104 * @return
105 * the converted string
106 */
107 function abarre_id_safe($string) {
108 if (is_numeric($string{0})) {
109 // if the first character is numeric, add 'n' in front
110 $string = 'n'. $string;
111 }
112 return strtolower(preg_replace('/[^a-zA-Z0-9-]+/', '-', $string));
113 }

  ViewVC Help
Powered by ViewVC 1.1.2