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

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

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


Revision 1.5 - (show annotations) (download) (as text)
Fri Sep 12 18:50:47 2008 UTC (14 months, 2 weeks ago) by frjo
Branch: MAIN
CVS Tags: HEAD
Changes since 1.4: +205 -77 lines
File MIME type: text/x-php
Update to Drupal 6 of the Hiroshigeblue theme.
1 <?php
2 // $Id: template.php,v 1.4 2008/07/14 06:08:14 frjo Exp $
3
4 /**
5 * Override or insert PHPTemplate variables into the page templates.
6 *
7 * @param $vars
8 * A sequential array of variables to pass to the theme template.
9 * @param $hook
10 * The name of the theme function being called ("page" in this case.)
11 */
12 function hiroshigeblue_preprocess_page(&$vars, $hook) {
13 $vars['login_box'] = hiroshigeblue_login_box();
14
15 // Classes for body element. Allows advanced theming based on context
16 // (home page, node of certain type, etc.)
17 if (!$vars['is_front']) {
18 $body_classes = array($vars['body_classes']);
19 // Add unique classes for each page and website section
20 $path = drupal_get_path_alias($_GET['q']);
21 list($section, ) = explode('/', $path, 2);
22 $body_classes[] = hiroshigeblue_id_safe('page-'. $path);
23 $body_classes[] = hiroshigeblue_id_safe('section-'. $section);
24 if (arg(0) == 'node') {
25 if (arg(1) == 'add') {
26 if ($section == 'node') {
27 array_pop($body_classes); // Remove 'section-node'
28 }
29 $body_classes[] = 'section-node-add'; // Add 'section-node-add'
30 }
31 elseif (is_numeric(arg(1)) && (arg(2) == 'edit' || arg(2) == 'delete')) {
32 if ($section == 'node') {
33 array_pop($body_classes); // Remove 'section-node'
34 }
35 $body_classes[] = 'section-node-'. arg(2); // Add 'section-node-edit' or 'section-node-delete'
36 }
37 }
38 $vars['body_classes'] = implode(' ', $body_classes); // Concatenate with spaces
39 }
40
41 // Don't display empty help from node_help().
42 if ($vars['help'] == "<div class=\"help\"><p></p>\n</div>") {
43 $vars['help'] = '';
44 }
45 }
46
47 /**
48 * Override or insert PHPTemplate variables into the node templates.
49 *
50 * @param $vars
51 * A sequential array of variables to pass to the theme template.
52 * @param $hook
53 * The name of the theme function being called ("node" in this case.)
54 */
55 function hiroshigeblue_preprocess_node(&$vars, $hook) {
56 global $user;
57
58 // Special classes for nodes
59 $node_classes = array();
60 if ($vars['sticky']) {
61 $node_classes[] = 'sticky';
62 }
63 if (!$vars['node']->status) {
64 $node_classes[] = 'node-unpublished';
65 $vars['unpublished'] = TRUE;
66 }
67 else {
68 $vars['unpublished'] = FALSE;
69 }
70 if ($vars['node']->uid && $vars['node']->uid == $user->uid) {
71 // Node is authored by current user
72 $node_classes[] = 'node-mine';
73 }
74 if ($vars['teaser']) {
75 // Node is displayed as teaser
76 $node_classes[] = 'node-teaser';
77 }
78 // Class for node type: "node-type-page", "node-type-story", "node-type-my-custom-type", etc.
79 $node_classes[] = 'node-type-'. $vars['node']->type;
80 $vars['node_classes'] = implode(' ', $node_classes); // Concatenate with spaces
81
82 $vars['below_node'] = theme('blocks', 'below_node');
83
84 if (module_exists('taxonomy')) {
85 $vocabs = taxonomy_get_vocabularies();
86 foreach ($vocabs as $vocab) {
87 $tags = array();
88 $terms = taxonomy_node_get_terms_by_vocabulary($vars['node']->nid, $vocab->vid);
89 foreach ($terms as $term) {
90 $tags['taxonomy_term_'. $term->tid] = array(
91 'title' => $term->name,
92 'href' => taxonomy_term_path($term),
93 'attributes' => array('rel' => 'tag', 'title' => strip_tags($term->description))
94 );
95 }
96 if ($tags) {
97 $vars['tags_'. $vocab->vid] = theme('links', $tags, array('class' => 'links inline'));
98 }
99 }
100 }
101 }
102
103 /**
104 * Override or insert PHPTemplate variables into the comment templates.
105 *
106 * @param $vars
107 * A sequential array of variables to pass to the theme template.
108 * @param $hook
109 * The name of the theme function being called ("comment" in this case.)
110 */
111 function hiroshigeblue_preprocess_comment(&$vars, $hook) {
112 global $user;
113
114 // We load the node object that the current comment is attached to
115 $node = node_load($vars['comment']->nid);
116 // If the author of this comment is equal to the author of the node, we
117 // set a variable so we can theme this comment uniquely.
118 $vars['author_comment'] = $vars['comment']->uid == $node->uid ? TRUE : FALSE;
119 // Special classes for comments
120 $comment_classes = array();
121 // Odd/even handling
122 static $comment_odd = TRUE;
123 $comment_classes[] = $comment_odd ? 'odd' : 'even';
124 $comment_odd = !$comment_odd;
125 if ($vars['comment']->status == COMMENT_NOT_PUBLISHED) {
126 $comment_classes[] = 'comment-unpublished';
127 $vars['unpublished'] = TRUE;
128 }
129 else {
130 $vars['unpublished'] = FALSE;
131 }
132 if ($vars['author_comment']) {
133 // Comment is by the node author
134 $comment_classes[] = 'comment-by-author';
135 }
136 if ($vars['comment']->uid == 0) {
137 // Comment is by an anonymous user
138 $comment_classes[] = 'comment-by-anon';
139 }
140 if ($user->uid && $vars['comment']->uid == $user->uid) {
141 // Comment was posted by current user
142 $comment_classes[] = 'comment-mine';
143 }
144 $vars['comment_classes'] = implode(' ', $comment_classes);
145 }
146
147 /**
148 * Format the "submitted" string for nodes and comments.
149 */
150 function hiroshigeblue_node_submitted($node) {
151 return t('!user - <abbr class="created" title="!microdate">!date</abbr>', array(
152 '!user' => theme('username', $node),
153 '!date' => format_date($node->created),
154 '!microdate' => format_date($node->created, 'custom', "Y-m-d\TH:i:sO")
155 ));
156 }
157 function hiroshigeblue_comment_submitted($comment) {
158 return t('!user - <abbr class="created" title="!microdate">!date</abbr>', array(
159 '!user' => theme('username', $comment),
160 '!date' => format_date($comment->timestamp),
161 '!microdate' => format_date($comment->timestamp, 'custom', "Y-m-d\TH:i:sO")
162 ));
163 }
164
165 /**
166 * Allow themable wrapping of all comments.
167 */
168 function hiroshigeblue_comment_wrapper($content, $type = NULL) {
169 static $node_type;
170
171 if (isset($type)) {
172 $node_type = $type;
173 }
174 if (!$content || $node_type == 'forum') {
175 return '<div id="comments">'. $content .'</div>';
176 }
177 else {
178 $output = '<div id="comments">';
179 $output .= '<h2 class="comments">'. t('Comments') .'</h2>';
180 $output .= $content;
181 $output .= '</div>';
182
183 return $output;
184 }
185 }
186
187 /**
188 * Returns the rendered local tasks. The default implementation renders
189 * them as tabs.
190 *
191 * @ingroup themeable
192 */
193 function hiroshigeblue_menu_local_tasks() {
194 $output = '';
195
196 if ($primary = menu_primary_local_tasks()) {
197 $output .= "<ul class=\"tabs primary clear-block\">\n". $primary ."</ul>\n";
198 }
199 if ($secondary = menu_secondary_local_tasks()) {
200 $output .= "<ul class=\"tabs secondary\">\n". $secondary ."</ul>\n";
201 }
202
203 return $output;
204 }
205
206 function hiroshigeblue_login_boxform() {
207 $form = array(
208 '#action' => url($_GET['q'], array('query' => drupal_get_destination())),
209 '#id' => 'user-login-box',
210 '#validate' => user_login_default_validators(),
211 '#submit' => array('user_login_submit'),
212 );
213
214 $form['name'] = array(
215 '#type' => 'textfield',
216 '#title' => t('Username'),
217 '#maxlength' => USERNAME_MAX_LENGTH,
218 '#size' => 15,
219 '#required' => TRUE,
220 '#attributes' => array('tabindex' => '1'),
221 );
222 $form['pass'] = array(
223 '#type' => 'password',
224 '#title' => t('Password'),
225 '#maxlength' => 60,
226 '#size' => 15,
227 '#required' => TRUE,
228 '#attributes' => array('tabindex' => '2'),
229 );
230 $form['submit'] = array(
231 '#type' => 'submit',
232 '#value' => t('Log in'),
233 '#attributes' => array('tabindex' => '3'),
234 );
235 if (variable_get('user_register', 1)) {
236 $form['links'] = array('#value' => l(t('Create new account'), 'user/register', array('attributes' => array('title' => t('Create a new user account.'), 'class' => 'login-links'))));
237 }
238
239 return $form;
240 }
241
242 function hiroshigeblue_login_box() {
243 global $user;
244
245 // For usability's sake, avoid showing two login forms on one page.
246 if (!$user->uid && !(arg(0) == 'user' && !is_numeric(arg(1)))) {
247 $output = drupal_get_form('hiroshigeblue_login_boxform');
248 }
249 else if ($user->uid) {
250 $output = t('You are logged in as !name', array('!name' => theme('username', $user))) .' | '. l(t('log out'), 'logout');
251 }
252
253 return '<div id="login-box">'. $output .'</div>';
254 }
255
256 /**
257 * Converts a string to a suitable html ID attribute.
258 *
259 * http://www.w3.org/TR/html4/struct/global.html#h-7.5.2 specifies what makes a
260 * valid ID attribute in HTML. This function:
261 *
262 * - Ensure an ID starts with an alpha character by optionally adding an 'n'.
263 * - Replaces any character except A-Z, numbers, and underscores with dashes.
264 * - Converts entire string to lowercase.
265 *
266 * @param $string
267 * The string
268 * @return
269 * The converted string
270 */
271 function hiroshigeblue_id_safe($string) {
272 // Replace with dashes anything that isn't A-Z, numbers, dashes, or underscores.
273 $string = strtolower(preg_replace('/[^a-zA-Z0-9_-]+/', '-', $string));
274 // If the first character is not a-z, add 'n' in front.
275 if (!ctype_lower($string{0})) { // Don't use ctype_alpha since its locale aware.
276 $string = 'id'. $string;
277 }
278
279 return $string;
280 }

  ViewVC Help
Powered by ViewVC 1.1.2