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

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

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


Revision 1.2 - (show annotations) (download) (as text)
Tue Dec 11 06:51:59 2007 UTC (23 months, 2 weeks ago) by themester
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +5 -4 lines
File MIME type: text/x-php
w3c validation
1 <?php
2
3 /*
4 * Declare the available regions implemented by this engine.
5 *
6 * @return
7 * An array of regions. The first array element will be used as the default region for themes.
8 * Each array element takes the format: variable_name => t('human readable name')
9 */
10 function ad_agency_regions() {
11 return array(
12 'left' => t('left sidebar'),
13 'right' => t('right sidebar'),
14 'content_top' => t('content top'),
15 'content_bottom' => t('content bottom'),
16 'header' => t('header'),
17 'footer' => t('footer')
18 );
19 }
20
21 /*
22 * CREATE OR MODIFY VARIABLES FOR YOUR THEME
23 *
24 * The most powerful function available to themers is the _phptemplate_variables() function. It allows you
25 * to pass newly created variables to different template (tpl.php) files in your theme. Or even unset ones you don't want
26 * to use.
27 *
28 * It works by switching on the hook, or name of the theme function, such as:
29 * - page
30 * - node
31 * - comment
32 * - block
33 *
34 * By switching on this hook you can send different variables to page.tpl.php file, node.tpl.php
35 * (and any other derivative node template file, like node-forum.tpl.php), comment.tpl.php, and block.tpl.php
36 *
37 */
38
39
40 /**
41 * Intercept template variables
42 *
43 * @param $hook
44 * The name of the theme function being executed
45 * @param $vars
46 * A sequential array of variables passed to the theme function.
47 */
48
49 function _phptemplate_variables($hook, $vars = array()) {
50 switch ($hook) {
51 // Send a new variable, $logged_in, to page.tpl.php to tell us if the current user is logged in or out.
52 case 'page':
53 // get the currently logged in user
54 global $user;
55
56 // An anonymous user has a user id of zero.
57 if ($user->uid > 0) {
58 // The user is logged in.
59 $vars['logged_in'] = TRUE;
60 }
61 else {
62 // The user has logged out.
63 $vars['logged_in'] = FALSE;
64 }
65
66 $body_classes = array();
67 // classes for body element
68 // allows advanced theming based on context (home page, node of certain type, etc.)
69 $body_classes[] = ($vars['is_front']) ? 'front' : 'not-front';
70 $body_classes[] = ($vars['logged_in']) ? 'logged-in' : 'not-logged-in';
71 if ($vars['node']->type) {
72 $body_classes[] = 'ntype-'. ad_agency_id_safe($vars['node']->type);
73 }
74 switch (TRUE) {
75 case $vars['sidebar_left'] && $vars['sidebar_right'] :
76 $body_classes[] = 'both-sidebars';
77 break;
78 case $vars['sidebar_left'] :
79 $body_classes[] = 'sidebar-left';
80 break;
81 case $vars['sidebar_right'] :
82 $body_classes[] = 'sidebar-right';
83 break;
84 }
85 // implode with spaces
86 $vars['body_classes'] = implode(' ', $body_classes);
87
88 break;
89
90 case 'node':
91 // get the currently logged in user
92 global $user;
93
94 // set a new $is_admin variable
95 // this is determined by looking at the currently logged in user and seeing if they are in the role 'admin'
96 $vars['is_admin'] = in_array('admin', $user->roles);
97
98 $node_classes = array('node');
99 if ($vars['sticky']) {
100 $node_classes[] = 'sticky';
101 }
102 if (!$vars['node']->status) {
103 $node_classes[] = 'node-unpublished';
104 }
105 $node_classes[] = 'ntype-'. ad_agency_id_safe($vars['node']->type);
106 // implode with spaces
107 $vars['node_classes'] = implode(' ', $node_classes);
108
109 break;
110
111 case 'comment':
112 // we load the node object that the current comment is attached to
113 $node = node_load($vars['comment']->nid);
114 // if the author of this comment is equal to the author of the node, we set a variable
115 // then in our theme we can theme this comment differently to stand out
116 $vars['author_comment'] = $vars['comment']->uid == $node->uid ? TRUE : FALSE;
117 break;
118 }
119
120 return $vars;
121 }
122
123 /**
124 * Converts a string to a suitable html ID attribute.
125 * - Preceeds initial numeric with 'n' character.
126 * - Replaces space and underscore with dash.
127 * - Converts entire string to lowercase.
128 * - Works for classes too!
129 *
130 * @param string $string
131 * the string
132 * @return
133 * the converted string
134 */
135 function ad_agency_id_safe($string) {
136 if (is_numeric($string{0})) {
137 // if the first character is numeric, add 'n' in front
138 $string = 'n'. $string;
139 }
140 return strtolower(preg_replace('/[^a-zA-Z0-9-]+/', '-', $string));
141 }
142
143 /**
144 * Allow themable wrapping of all comments.
145 */
146 function phptemplate_comment_wrapper($content, $type = null) {
147 static $node_type;
148 if (isset($type)) $node_type = $type;
149
150 if (!$content || $node_type == 'forum') {
151 return '<div id="comments">'. $content . '</div>';
152 }
153 else {
154 return '<h3 id="comments">'. t('Comments') .'</h3><ol class="commentlist">'. $content .'</ol>';
155 }
156 }
157

  ViewVC Help
Powered by ViewVC 1.1.2