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

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

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


Revision 1.2 - (show annotations) (download) (as text)
Fri Sep 12 18:48:38 2008 UTC (14 months, 1 week ago) by frjo
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--1
Changes since 1.1: +209 -61 lines
File MIME type: text/x-php
Update to Drupal 6 of the Blommor01 theme.
1 <?php
2 // $Id: template.php,v 1.1 2008/02/09 21:36:21 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 blommor01_preprocess_page(&$vars, $hook) {
13 // Classes for body element. Allows advanced theming based on context
14 // (home page, node of certain type, etc.)
15 if (!$vars['is_front']) {
16 $body_classes = array($vars['body_classes']);
17 // Add unique classes for each page and website section
18 $path = drupal_get_path_alias($_GET['q']);
19 list($section, ) = explode('/', $path, 2);
20 $body_classes[] = blommor01_id_safe('page-'. $path);
21 $body_classes[] = blommor01_id_safe('section-'. $section);
22 if (arg(0) == 'node') {
23 if (arg(1) == 'add') {
24 if ($section == 'node') {
25 array_pop($body_classes); // Remove 'section-node'
26 }
27 $body_classes[] = 'section-node-add'; // Add 'section-node-add'
28 }
29 elseif (is_numeric(arg(1)) && (arg(2) == 'edit' || arg(2) == 'delete')) {
30 if ($section == 'node') {
31 array_pop($body_classes); // Remove 'section-node'
32 }
33 $body_classes[] = 'section-node-'. arg(2); // Add 'section-node-edit' or 'section-node-delete'
34 }
35 }
36 $vars['body_classes'] = implode(' ', $body_classes); // Concatenate with spaces
37 }
38
39 // Don't display empty help from node_help().
40 if ($vars['help'] == "<div class=\"help\"><p></p>\n</div>") {
41 $vars['help'] = '';
42 }
43 }
44
45 /**
46 * Override or insert PHPTemplate variables into the node templates.
47 *
48 * @param $vars
49 * A sequential array of variables to pass to the theme template.
50 * @param $hook
51 * The name of the theme function being called ("node" in this case.)
52 */
53 function blommor01_preprocess_node(&$vars, $hook) {
54 global $user;
55
56 // Special classes for nodes
57 $node_classes = array();
58 if ($vars['sticky']) {
59 $node_classes[] = 'sticky';
60 }
61 if (!$vars['node']->status) {
62 $node_classes[] = 'node-unpublished';
63 $vars['unpublished'] = TRUE;
64 }
65 else {
66 $vars['unpublished'] = FALSE;
67 }
68 if ($vars['node']->uid && $vars['node']->uid == $user->uid) {
69 // Node is authored by current user
70 $node_classes[] = 'node-mine';
71 }
72 if ($vars['teaser']) {
73 // Node is displayed as teaser
74 $node_classes[] = 'node-teaser';
75 }
76 // Class for node type: "node-type-page", "node-type-story", "node-type-my-custom-type", etc.
77 $node_classes[] = 'node-type-'. $vars['node']->type;
78 $vars['node_classes'] = implode(' ', $node_classes); // Concatenate with spaces
79
80 $vars['below_node'] = theme('blocks', 'below_node');
81
82 if (module_exists('taxonomy')) {
83 $vocabs = taxonomy_get_vocabularies();
84 foreach ($vocabs as $vocab) {
85 $tags = array();
86 $terms = taxonomy_node_get_terms_by_vocabulary($vars['node']->nid, $vocab->vid);
87 foreach ($terms as $term) {
88 $tags['taxonomy_term_'. $term->tid] = array(
89 'title' => $term->name,
90 'href' => taxonomy_term_path($term),
91 'attributes' => array('rel' => 'tag', 'title' => strip_tags($term->description))
92 );
93 }
94 if ($tags) {
95 $vars['tags_'. $vocab->vid] = theme('links', $tags, array('class' => 'links inline'));
96 }
97 }
98 }
99 }
100
101 /**
102 * Override or insert PHPTemplate variables into the comment templates.
103 *
104 * @param $vars
105 * A sequential array of variables to pass to the theme template.
106 * @param $hook
107 * The name of the theme function being called ("comment" in this case.)
108 */
109 function blommor01_preprocess_comment(&$vars, $hook) {
110 global $user;
111
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
115 // set a variable so we can theme this comment uniquely.
116 $vars['author_comment'] = $vars['comment']->uid == $node->uid ? TRUE : FALSE;
117 // Special classes for comments
118 $comment_classes = array();
119 // Odd/even handling
120 static $comment_odd = TRUE;
121 $comment_classes[] = $comment_odd ? 'odd' : 'even';
122 $comment_odd = !$comment_odd;
123 if ($vars['comment']->status == COMMENT_NOT_PUBLISHED) {
124 $comment_classes[] = 'comment-unpublished';
125 $vars['unpublished'] = TRUE;
126 }
127 else {
128 $vars['unpublished'] = FALSE;
129 }
130 if ($vars['author_comment']) {
131 // Comment is by the node author
132 $comment_classes[] = 'comment-by-author';
133 }
134 if ($vars['comment']->uid == 0) {
135 // Comment is by an anonymous user
136 $comment_classes[] = 'comment-by-anon';
137 }
138 if ($user->uid && $vars['comment']->uid == $user->uid) {
139 // Comment was posted by current user
140 $comment_classes[] = 'comment-mine';
141 }
142 $vars['comment_classes'] = implode(' ', $comment_classes);
143 }
144
145 /**
146 * Format the "submitted" string for nodes and comments.
147 */
148 function blommor01_node_submitted($node) {
149 return t('!user - <abbr class="created" title="!microdate">!date</abbr>', array(
150 '!user' => theme('username', $node),
151 '!date' => format_date($node->created),
152 '!microdate' => format_date($node->created, 'custom', "Y-m-d\TH:i:sO")
153 ));
154 }
155 function blommor01_comment_submitted($comment) {
156 return t('!user - <abbr class="created" title="!microdate">!date</abbr>', array(
157 '!user' => theme('username', $comment),
158 '!date' => format_date($comment->timestamp),
159 '!microdate' => format_date($comment->timestamp, 'custom', "Y-m-d\TH:i:sO")
160 ));
161 }
162
163 /**
164 * Allow themable wrapping of all comments.
165 */
166 function blommor01_comment_wrapper($content, $type = NULL) {
167 static $node_type;
168
169 if (isset($type)) {
170 $node_type = $type;
171 }
172 if (!$content || $node_type == 'forum') {
173 return '<div id="comments">'. $content .'</div>';
174 }
175 else {
176 $output = '<div id="comments">';
177 $output .= '<h2 class="comments">'. t('Comments') .'</h2>';
178 $output .= $content;
179 $output .= '</div>';
180
181 return $output;
182 }
183 }
184
185 /**
186 * Returns the rendered local tasks. The default implementation renders
187 * them as tabs.
188 *
189 * @ingroup themeable
190 */
191 function blommor01_menu_local_tasks() {
192 $output = '';
193
194 if ($primary = menu_primary_local_tasks()) {
195 $output .= "<ul class=\"tabs primary clear-block\">\n". $primary ."</ul>\n";
196 }
197 if ($secondary = menu_secondary_local_tasks()) {
198 $output .= "<ul class=\"tabs secondary\">\n". $secondary ."</ul>\n";
199 }
200
201 return $output;
202 }
203
204 /**
205 * Converts a string to a suitable html ID attribute.
206 *
207 * http://www.w3.org/TR/html4/struct/global.html#h-7.5.2 specifies what makes a
208 * valid ID attribute in HTML. This function:
209 *
210 * - Ensure an ID starts with an alpha character by optionally adding an 'n'.
211 * - Replaces any character except A-Z, numbers, and underscores with dashes.
212 * - Converts entire string to lowercase.
213 *
214 * @param $string
215 * The string
216 * @return
217 * The converted string
218 */
219 function blommor01_id_safe($string) {
220 // Replace with dashes anything that isn't A-Z, numbers, dashes, or underscores.
221 $string = strtolower(preg_replace('/[^a-zA-Z0-9_-]+/', '-', $string));
222 // If the first character is not a-z, add 'n' in front.
223 if (!ctype_lower($string{0})) { // Don't use ctype_alpha since its locale aware.
224 $string = 'id'. $string;
225 }
226
227 return $string;
228 }

  ViewVC Help
Powered by ViewVC 1.1.2