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

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

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


Revision 1.9 - (show annotations) (download) (as text)
Tue Nov 3 22:22:04 2009 UTC (3 weeks ago) by jmburnz
Branch: MAIN
CVS Tags: DRUPAL-6--4-1, DRUPAL-6--4-0, HEAD
Changes since 1.8: +4 -4 lines
File MIME type: text/x-php
coder cleanup
1 <?php // $Id: template.php,v 1.8 2009/11/03 19:55:39 jmburnz Exp $
2 /**
3 * @file
4 * template.php
5 */
6 /**
7 * Sets a body-tag class.
8 * Adds 'four-column', 'three-column', 'two-column' or 'one-column' class as needed.
9 *
10 * Do not use these classes to set the width of the main columns!
11 * See 'function newswire_col_width' and layout.css for setting the column widths.
12 *
13 * @param $left, $content, $right, $right_2
14 * The main column regions
15 */
16 function newswire_column_count_class($left, $content, $right, $right_2) {
17 if ($content && $left && $right && $right_2) {
18 $class = 'four-column'; // all four columns active
19 }
20 else {
21 if (($content && $left && $right) or ($content && $left && $right_2) or ($content && $right && $right_2)) {
22 $class = 'three-column'; // three columns active
23 }
24 else {
25 if (($content && $left) or ($content && $right) or ($content && $right_2)) {
26 $class = 'two-column'; // two columns active
27 }
28 else {
29 if ($content != '') {
30 $class = 'one-column'; //one column (content itelf) active
31 }
32 }
33 }
34 }
35 if (isset($class)) {
36 print $class;
37 }
38 }
39 /**
40 * Set the width of the content region.
41 *
42 * Adds a width selector to $content depending on the cols are being used.
43 * To change the widths see 'layout.css' and choose the selectors that match
44 * the widths you require. Be careful not to exceed width-48-950 (960px) unless you
45 * modify the #container width.
46 *
47 * @param $left, $content, $right, $right_2
48 * The main column regions
49 */
50 function newswire_col_width($left, $content, $right, $right_2) {
51 if ($content && $left && $right && $right_2) {
52 $class = 'width-18-350'; //if 4 col, content will be 350px
53 }
54 else {
55 if (($content && $left && $right) or ($content && $right && $right_2) or ($content && $left && $right_2)) {
56 $class = 'width-28-550'; //if 3 col content will be 550px
57 }
58 else {
59 if (($content && $left) or ($content && $right_2) or ($content && $right)) {
60 $class = 'width-38-750'; //if 2 col content will be 750px
61 }
62 else {
63 if ($content != '') {
64 $class = 'width-48-950'; //if 1 col content will be 950px
65 }
66 }
67 }
68 }
69 if (isset($class)) {
70 print $class;
71 }
72 }
73
74 /**
75 * Initialize theme settings
76 */
77 if (is_null(theme_get_setting('newswire_color_global'))) { // <-- change this line
78 global $theme_key;
79
80 /*
81 * The default values for the theme variables. Make sure $defaults exactly
82 * matches the $defaults in the theme-settings.php file.
83 */
84 $defaults = array( // <-- change this array
85 'newswire_color_global' => 'newswire_tan',
86 'newswire_color_highlight' => 'newswire_red',
87 );
88
89 // Get default theme settings.
90 $settings = theme_get_settings($theme_key);
91 // Don't save the toggle_node_info_ variables.
92 if (module_exists('node')) {
93 foreach (node_get_types() as $type => $name) {
94 unset($settings['toggle_node_info_'. $type]);
95 }
96 }
97 // Save default theme settings.
98 variable_set(
99 str_replace('/', '_', 'theme_'. $theme_key .'_settings'),
100 array_merge($defaults, $settings)
101 );
102 // Force refresh of Drupal internals.
103 theme_get_setting('', TRUE);
104 }
105
106 $color_global = theme_get_setting('newswire_color_global');
107 $color_highlight = theme_get_setting('newswire_color_highlight');
108 // Add the style sheets.
109 drupal_add_css(drupal_get_path('theme', 'newswire') .'/css/'. $color_global .'.css', 'theme');
110 drupal_add_css(drupal_get_path('theme', 'newswire') .'/css/'. $color_highlight .'.css', 'theme');
111
112 /**
113 * Override or insert preprocess variables into page templates.
114 *
115 * @param $vars
116 * A sequential array of variables to pass to the theme template.
117 * @param $hook
118 * The name of the theme function being called ("page" in this case.)
119 */
120 function newswire_preprocess_page(&$vars) {
121 global $theme;
122
123 // Modify the html for $logo and $site_name depending on the context.
124 if ($vars['is_front']) {
125 if ($vars['logo']) {
126 $vars['logo'] = '<h1 class="brand"><a href="'. $vars['front_page'] .'" title="'. $vars['site_name'] .'"><img src="'. $vars['logo'] .'" alt="'. $vars['site_name'] .'" /></a></h1>';
127 }
128 elseif ($vars['site_name']) {
129 $vars['site_name'] = '<h1 class="brand"><a href="'. $vars['front_page'] .'" title="'. $vars['site_name'] .'">'. $vars['site_name'] .'</a></h1>';
130 }
131 }
132 else {
133 if ($vars['logo']) {
134 $vars['logo'] = '<div class="brand"><a href="'. $vars['front_page'] .'" title="'. $vars['site_name'] .'"><img src="'. $vars['logo'] .'" alt="'. $vars['site_name'] .'" /></a></div>';
135 }
136 elseif ($vars['site_name']) {
137 $vars['site_name'] = '<div class="brand"><a href="'. $vars['front_page'] .'" title="'. $vars['site_name'] .'">'. $vars['site_name'] .'</a></div>';
138 }
139 }
140
141 // Modify the html for $title depending on the context.
142 if ($vars['title']) {
143 if (arg(0) == 'taxonomy' && arg(1)=='term' && is_numeric(arg(2))) {
144 $vars['title'] = '<h1 class="title category clearfix">'. $vars['feed_icons'] .'<span>'. $vars['title'] .'</span></h1>';
145 }
146 else {
147 $vars['title'] = '<h1 class="title">'. $vars['title'] .'</h1>';
148 }
149 }
150
151 // Don't display empty help from node_help().
152 // @see http://drupal.org/project/zen
153 if ($vars['help'] == "<div class=\"help\"><p></p>\n</div>") {
154 $vars['help'] = '';
155 }
156
157 // Classes for body element. Allows advanced theming based on context
158 // (home page, node of certain type, etc.)
159 $body_class = array($vars['body_class']);
160 if ($vars['content']) {
161 // Add a class that tells us whether we're on the front page or not.
162 $body_class[] = $vars['is_front'] ? 'front' : 'not-front';
163 // Add a class that tells us whether the page is viewed by an authenticated user or not.
164 $body_class[] = $vars['logged_in'] ? 'logged-in' : 'not-logged-in';
165 }
166 // If on an individual node page, add the node type.
167 if (isset($vars['node']) && $vars['node']->type) {
168 $body_class[] = 'node-type-'. newswire_id_safe($vars['node']->type);
169 }
170 if (!$vars['is_front']) {
171 // Add unique class for each page and website section.
172 // This is borrowed from the Zen theme http://drupal.org/project/zen.
173 $path = drupal_get_path_alias($_GET['q']);
174 list($section, ) = explode('/', $path, 2);
175 $body_class[] = newswire_id_safe('page-'. $path);
176 $body_class[] = newswire_id_safe('section-'. $section);
177 if (arg(0) == 'node') {
178 if (arg(1) == 'add') {
179 if ($section == 'node') {
180 array_pop($body_class); // Remove 'section-node'
181 }
182 $body_class[] = 'section-node-add'; // Add 'section-node-add'
183 }
184 elseif (is_numeric(arg(1)) && (arg(2) == 'edit' || arg(2) == 'delete')) {
185 if ($section == 'node') {
186 array_pop($body_class); // Remove 'section-node'
187 }
188 $body_class[] = 'section-node-'. arg(2); // Add 'section-node-edit' or 'section-node-delete'
189 }
190 }
191 }
192 $vars['body_class'] = implode(' ', $body_class); // Concatenate with spaces
193 }
194
195 /**
196 * Override or insert preprocess variables into the node templates.
197 *
198 * @param $vars
199 * A sequential array of variables to pass to the theme template.
200 * @param $hook
201 * The name of the theme function being called ("node" in this case.)
202 *
203 * @see http://drupal.org/project/zen
204 */
205 function newswire_preprocess_node(&$vars) {
206 global $user;
207
208 // Special classes for nodes
209 $node_classes = array();
210 if ($vars['sticky']) {
211 $node_classes[] = 'sticky';
212 }
213 if (!$vars['node']->status) {
214 $node_classes[] = 'node-unpublished';
215 $vars['unpublished'] = TRUE;
216 }
217 else {
218 $vars['unpublished'] = FALSE;
219 }
220 if ($vars['node']->uid && $vars['node']->uid == $user->uid) {
221 // Node is authored by current user
222 $node_classes[] = 'node-mine';
223 }
224 if ($vars['teaser']) {
225 // Node is displayed as teaser
226 $node_classes[] = 'node-teaser';
227 }
228 // Class for node type: "node-type-page", "node-type-story", "node-type-my-custom-type", etc.
229 $node_classes[] = 'node-type-'. $vars['node']->type;
230 $vars['node_classes'] = implode(' ', $node_classes); // Concatenate with spaces
231
232 // Add $node_region region to node.tpl.php
233 $vars['node_region'] = theme('blocks', 'node_region');
234 }
235 /**
236 * Override or insert preprocess variables into the comment templates.
237 *
238 * @param $vars
239 * A sequential array of variables to pass to the theme template.
240 * @param $hook
241 * The name of the theme function being called ("comment" in this case.)
242 *
243 * @see http://drupal.org/project/zen
244 */
245 function newswire_preprocess_comment(&$vars) {
246 global $user;
247
248 // We load the node object that the current comment is attached to
249 $node = node_load($vars['comment']->nid);
250 // If the author of this comment is equal to the author of the node, we
251 // set a variable so we can theme this comment uniquely.
252 $vars['author_comment'] = $vars['comment']->uid == $node->uid ? TRUE : FALSE;
253
254 $comment_classes = array();
255
256 // Odd/even handling
257 static $comment_odd = TRUE;
258 $comment_classes[] = $comment_odd ? 'odd' : 'even';
259 $comment_odd = !$comment_odd;
260
261 if ($vars['comment']->status == COMMENT_NOT_PUBLISHED) {
262 $comment_classes[] = 'comment-unpublished';
263 $vars['unpublished'] = TRUE;
264 }
265 else {
266 $vars['unpublished'] = FALSE;
267 }
268 if ($vars['author_comment']) {
269 // Comment is by the node author
270 $comment_classes[] = 'comment-by-author';
271 }
272 if ($vars['comment']->uid == 0) {
273 // Comment is by an anonymous user
274 $comment_classes[] = 'comment-by-anon';
275 }
276 if ($user->uid && $vars['comment']->uid == $user->uid) {
277 // Comment was posted by current user
278 $comment_classes[] = 'comment-mine';
279 }
280 $vars['comment_classes'] = implode(' ', $comment_classes);
281
282 // If comment subjects are disabled, don't display 'em
283 if (variable_get('comment_subject_field', 1) == 0) {
284 $vars['title'] = '';
285 }
286 //dpm($vars['comment']);
287 }
288 /**
289 * Override or insert PHPTemplate variables into the block templates.
290 *
291 * @param $vars
292 * A sequential array of variables to pass to the theme template.
293 * @param $hook
294 * The name of the theme function being called ("block" in this case.)
295 *
296 * @see http://drupal.org/project/zen
297 */
298 function newswire_preprocess_block(&$vars) {
299 $block = $vars['block'];
300
301 // Special classes for blocks
302 $block_classes = array();
303 $block_classes[] = 'block-'. $block->module;
304 $block_classes[] = 'region-'. $vars['block_zebra'];
305 $block_classes[] = $vars['zebra'];
306 $block_classes[] = 'region-count-'. $vars['block_id'];
307 $block_classes[] = 'count-'. $vars['id'];
308 $vars['block_classes'] = implode(' ', $block_classes);
309
310 }
311 /**
312 * Converts a string to a suitable html ID attribute.
313 *
314 * http://www.w3.org/TR/html4/struct/global.html#h-7.5.2 specifies what makes a
315 * valid ID attribute in HTML. This function:
316 *
317 * - Ensure an ID starts with an alpha character by optionally adding an 'n'.
318 * - Replaces any character except A-Z, numbers, and underscores with dashes.
319 * - Converts entire string to lowercase.
320 *
321 * @param $string
322 * The string
323 * @return
324 * The converted string
325 *
326 * @see http://drupal.org/project/zen
327 */
328 function newswire_id_safe($string) {
329 // Replace with dashes anything that isn't A-Z, numbers, dashes, or underscores.
330 $string = strtolower(preg_replace('/[^a-zA-Z0-9_-]+/', '-', $string));
331 // If the first character is not a-z, add 'n' in front.
332 if (!ctype_lower($string{0})) { // Don't use ctype_alpha since its locale aware.
333 $string = 'id'. $string;
334 }
335 return $string;
336 }

  ViewVC Help
Powered by ViewVC 1.1.2