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

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

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


Revision 1.8 - (show annotations) (download) (as text)
Mon May 4 21:34:31 2009 UTC (6 months, 3 weeks ago) by jmburnz
Branch: MAIN
CVS Tags: DRUPAL-6--3-2, DRUPAL-6--3-1, HEAD
Changes since 1.7: +1 -32 lines
File MIME type: text/x-php
updates for 31, new color schemes, minor page tpl edit, remove theme settings for
 overlabel, fix css
1 <?php // $Id: template.php,v 1.7 2009/05/04 20:52:54 jmburnz Exp $
2
3 /**
4 * @file
5 * template.php
6 */
7
8 /**
9 * Initialize theme settings for page width.
10 */
11 $pixture_width = theme_get_setting('pixture_width');
12 pixture_validate_page_width($pixture_width);
13
14 /**
15 * Check the page width theme settings and reset to default
16 * if the value is null, or invalid value is specified
17 */
18 function pixture_validate_page_width($width) {
19 global $theme_key;
20
21 /**
22 * The default values for the theme variables. Make sure $defaults exactly
23 * matches the $defaults in the theme-settings.php file.
24 */
25 $defaults = array( // <-- change this array
26 'pixture_width' => '85%',
27 );
28
29 // check if it is liquid (%) or fixed width (px)
30 if (preg_match("/(\d+)\s*%/", $width, $match)) {
31 $liquid = 1;
32 $num = intval($match[0]);
33 if (50 <= $num && $num <= 100) {
34 return $num ."%"; // OK!
35 }
36 }
37 else if (preg_match("/(\d+)\s*px/", $width, $match)) {
38 $fixed = 1;
39 $num = intval($match[0]);
40 if (800 <= $num && $num < 1600) {
41 return $num ."px"; // OK
42 }
43 }
44
45 // reset to default value
46 variable_set(
47 str_replace('/', '_', 'theme_'. $theme_key .'_settings'),
48 array_merge($defaults, theme_get_settings($theme_key))
49 );
50 // Force refresh of Drupal internals
51 theme_get_setting('', TRUE);
52 return $defaults['pixture_width'];
53 }
54
55 /**
56 * Initialize theme settings for superfish.
57 */
58 if (is_null(theme_get_setting('pixture_superfish'))) { // <-- change this line
59 global $theme_key;
60
61 /**
62 * The default values for the theme variables. Make sure $defaults exactly
63 * matches the $defaults in the theme-settings.php file.
64 */
65 $defaults = array( // <-- change this array
66 'pixture_superfish' => 0,
67 );
68
69 // Get default theme settings.
70 $settings = theme_get_settings($theme_key);
71
72 // Save default theme settings.
73 variable_set(
74 str_replace('/', '_', 'theme_'. $theme_key .'_settings'),
75 array_merge($defaults, $settings)
76 );
77 // Force refresh of Drupal internals.
78 theme_get_setting('', TRUE);
79 return $defaults['pixture_superfish'];
80 }
81 // Conditionally load the Superfish JS
82 if (theme_get_setting('pixture_superfish')) {
83 drupal_add_css(drupal_get_path('theme', 'pixture_reloaded') .'/sf/css/superfish.css', 'theme', 'all', FALSE);
84 drupal_add_js(drupal_get_path('theme', 'pixture_reloaded') .'/sf/js/superfish.js', 'theme');
85 }
86
87 /**
88 * Override or insert PHPTemplate variables into the page templates.
89 *
90 * @param $vars
91 * A sequential array of variables to pass to the theme template.
92 * @param $hook
93 * The name of the theme function being called ("page" in this case.)
94 */
95 function pixture_reloaded_preprocess_page(&$vars, $hook) {
96 global $theme;
97
98 // Hook into color.module
99 if (module_exists('color')) {
100 _color_page_alter($vars);
101 }
102
103 // Don't display empty help from node_help().
104 if ($vars['help'] == "<div class=\"help\"><p></p>\n</div>") {
105 $vars['help'] = '';
106 }
107
108 // Set variables for the logo and site_name.
109 if (!empty($vars['logo'])) {
110 $vars['site_logo'] = '<a href="'. $vars['front_page'] .'" title="'. t('Home page') .'" rel="home"><img src="'. $vars['logo'] .'" alt="'. $vars['site_name'] .' '. t('logo') .'" /></a>';
111 }
112 if (!empty($vars['site_name'])) {
113 $vars['site_name'] = '<a href="'. $vars['front_page'] .'" title="'. t('Home page') .'" rel="home">'. $vars['site_name'] .'</a>';
114 }
115
116 // Set variables for the primary and secondary links.
117 if (!empty($vars['primary_links'])) {
118 $vars['primary_menu'] = theme('links', $vars['primary_links'], array('class' => 'links primary-links'));
119 }
120
121 // Classes for body element. Allows advanced theming based on context
122 // (home page, node of certain type, etc.)
123 $body_classes = array($vars['body_classes']);
124 if (!$vars['is_front']) {
125 // Add unique classes for each page and website section
126 $path = drupal_get_path_alias($_GET['q']);
127 list($section, ) = explode('/', $path, 2);
128 $body_classes[] = pixture_reloaded_id_safe('page-'. $path);
129 $body_classes[] = pixture_reloaded_id_safe('section-'. $section);
130 if (arg(0) == 'node') {
131 if (arg(1) == 'add') {
132 if ($section == 'node') {
133 array_pop($body_classes); // Remove 'section-node'
134 }
135 $body_classes[] = 'section-node-add'; // Add 'section-node-add'
136 }
137 elseif (is_numeric(arg(1)) && (arg(2) == 'edit' || arg(2) == 'delete')) {
138 if ($section == 'node') {
139 array_pop($body_classes); // Remove 'section-node'
140 }
141 $body_classes[] = 'section-node-'. arg(2); // Add 'section-node-edit' or 'section-node-delete'
142 }
143 }
144 // Add a unique class when viewing a node
145 if (arg(0) == 'node' && is_numeric(arg(1))) {
146 $body_classes[] = 'node-full-view'; // Add 'node-full-view'
147 }
148 }
149 $vars['body_classes'] = implode(' ', $body_classes); // Concatenate with spaces
150 }
151
152 /**
153 * Override or insert PHPTemplate variables into the node templates.
154 *
155 * @param $vars
156 * A sequential array of variables to pass to the theme template.
157 * @param $hook
158 * The name of the theme function being called ("node" in this case.)
159 */
160 function pixture_reloaded_preprocess_node(&$vars, $hook) {
161 global $user;
162
163 // Special classes for nodes
164 $node_classes = array();
165 if ($vars['sticky']) {
166 $node_classes[] = 'sticky';
167 }
168 if (!$vars['node']->status) {
169 $node_classes[] = 'node-unpublished';
170 $vars['unpublished'] = TRUE;
171 }
172 else {
173 $vars['unpublished'] = FALSE;
174 }
175 if ($vars['node']->uid && $vars['node']->uid == $user->uid) {
176 // Node is authored by current user
177 $node_classes[] = 'node-mine';
178 }
179 if ($vars['teaser']) {
180 // Node is displayed as teaser
181 $node_classes[] = 'node-teaser';
182 }
183 if ($vars['$is_front']) {
184 // Node is displayed on the front page
185 $node_classes[] = 'front-node';
186 }
187 // Class for node type: "node-type-page", "node-type-story", "node-type-my-custom-type", etc.
188 $node_classes[] = 'node-type-'. $vars['node']->type;
189 $vars['node_classes'] = implode(' ', $node_classes); // Concatenate with spaces
190 }
191
192 /**
193 * Override or insert PHPTemplate variables into the comment templates.
194 *
195 * @param $vars
196 * A sequential array of variables to pass to the theme template.
197 * @param $hook
198 * The name of the theme function being called ("comment" in this case.)
199 */
200 function pixture_reloaded_preprocess_comment(&$vars, $hook) {
201 global $user;
202
203 // We load the node object that the current comment is attached to
204 $node = node_load($vars['comment']->nid);
205 // If the author of this comment is equal to the author of the node, we
206 // set a variable so we can theme this comment uniquely.
207 $vars['author_comment'] = $vars['comment']->uid == $node->uid ? TRUE : FALSE;
208
209 $comment_classes = array();
210
211 // Odd/even handling
212 static $comment_odd = TRUE;
213 $comment_classes[] = $comment_odd ? 'odd' : 'even';
214 $comment_odd = !$comment_odd;
215
216 if ($vars['comment']->status == COMMENT_NOT_PUBLISHED) {
217 $comment_classes[] = 'comment-unpublished';
218 $vars['unpublished'] = TRUE;
219 }
220 else {
221 $vars['unpublished'] = FALSE;
222 }
223 if ($vars['author_comment']) {
224 // Comment is by the node author
225 $comment_classes[] = 'comment-by-author';
226 }
227 if ($vars['comment']->uid == 0) {
228 // Comment is by an anonymous user
229 $comment_classes[] = 'comment-by-anon';
230 }
231 if ($user->uid && $vars['comment']->uid == $user->uid) {
232 // Comment was posted by current user
233 $comment_classes[] = 'comment-mine';
234 }
235 $vars['comment_classes'] = implode(' ', $comment_classes);
236
237 // If comment subjects are disabled, don't display 'em
238 if (variable_get('comment_subject_field', 1) == 0) {
239 $vars['title'] = '';
240 }
241 }
242
243 /**
244 * Override or insert PHPTemplate variables into the block templates.
245 *
246 * @param $vars
247 * A sequential array of variables to pass to the theme template.
248 * @param $hook
249 * The name of the theme function being called ("block" in this case.)
250 */
251 function pixture_reloaded_preprocess_block(&$vars, $hook) {
252 $block = $vars['block'];
253
254 // Special classes for blocks
255 $block_classes = array();
256 $block_classes[] = 'block-'. $block->module;
257 $block_classes[] = 'region-'. $vars['block_zebra'];
258 $block_classes[] = $vars['zebra'];
259 $block_classes[] = 'region-count-'. $vars['block_id'];
260 $block_classes[] = 'count-'. $vars['id'];
261 $vars['block_classes'] = implode(' ', $block_classes);
262
263 }
264
265 /**
266 * Converts a string to a suitable html ID attribute.
267 *
268 * - Preceeds initial numeric with 'n' character.
269 * - Replaces space and underscore with dash.
270 * - Converts entire string to lowercase.
271 * - Works for classes too!
272 *
273 * @param string $string
274 * The string
275 * @return
276 * The converted string
277 */
278 function pixture_reloaded_id_safe($string) {
279 if (is_numeric($string{0})) {
280 // If the first character is numeric, add 'n' in front
281 $string = 'n'. $string;
282 }
283 return strtolower(preg_replace('/[^a-zA-Z0-9-]+/', '-', $string));
284 }

  ViewVC Help
Powered by ViewVC 1.1.2