/[drupal]/contributions/sandbox/mfredrickson/themes/nautilus/template.php
ViewVC logotype

Contents of /contributions/sandbox/mfredrickson/themes/nautilus/template.php

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


Revision 1.6 - (show annotations) (download) (as text)
Thu Jun 22 15:37:12 2006 UTC (3 years, 5 months ago) by mfredrickson
Branch: MAIN
CVS Tags: HEAD
Changes since 1.5: +1 -1 lines
File MIME type: text/x-php
fixed bug in grid - grid stuff
1 <?php
2
3 // template.php for nautilus theme
4 define(NAUTILUS_DEBUG, 1); // chooses debug or normal (compressed) CSS
5
6 function _phptemplate_variables($hook, $vars) {
7 switch($hook) {
8 case 'page':
9 // include yahoo CSS files
10 $tpath = $vars['base_path'] . '/' . drupal_get_path('theme', 'nautilus');
11 if (NAUTILUS_DEBUG) {
12 $styles = theme('stylesheet_import', $tpath . '/common/yuicss/reset.css')
13 . theme('stylesheet_import', $tpath . '/common/yuicss/fonts.css')
14 . theme('stylesheet_import', $tpath . '/common/yuicss/grids.css');
15 } else {
16 $styles = theme('stylesheet_import', $tpath . '/common/yuicss/combined-min.css');
17 }
18
19 $styles .= theme('stylesheet_import', $tpath . '/style.php');
20
21 $vars['nautilus_styles'] = $styles;
22 $vars['index'] = url();
23 $vars['breadcrumb'] = $vars['breadcrumb'] != '' ?
24 '<div class = "breadcrumb">' . $vars['breadcrumb'] . ' &gt; ' . $vars['title'] . '</div>' : '' ;
25
26 // add the tabs to the main content
27 $vars['content'] = $vars['tabs'] . $vars['content'];
28
29 // see if the main content needs the messages prepended...
30 $message_location = variable_get('nautilustheme_messages', 'none');
31 if ($message_location == 'none') {
32 $vars['content'] = $vars['messages'] . $vars['content'];
33 }
34
35 // now do it for the other regions
36 foreach(array_keys(nautilus_regions()) as $region) {
37 if($message_location == $region) {
38 $vars[$region] = $vars['messages'] . $vars[$region];
39 }
40 $vars[$region] = "<div id=\"region-$region\" class = \"region\">" . $vars[$region] . '</div>';
41 }
42
43 // now, the fun part, split up the regions based on the settings
44 $main_grid = variable_get('nautilustheme_primarygrid', 'none');
45 $secondary_grid = variable_get('nautilustheme_secondarygrid', 'none');
46
47 // choosing a new location for the content swaps the content and the "alpha" region
48 switch (variable_get('nautilustheme_contentlocation', 'main')) {
49 case 'main':
50 $new_content = $vars['content'];
51 $new_alpha = $vars['alpha'];
52 break;
53 case 'secondary':
54 $new_content = $vars['alpha'];
55 $new_alpha = $vars['content'];
56 break;
57 }
58
59 /* Just for reference....
60
61 $gridoptions = array (
62 'none' => t('No inner grid'),
63 '50-50' => t('Two columns, 50% - 50%'),
64 '66-33' => t('Two columns, 66% - 33%'),
65 '33-66' => t('Two columns, 33% - 66%'),
66 '75-25' => t('Two columns, 75% - 25%'),
67 '25-75' => t('Two columns, 25%-75%'),
68 '50-25-25' => t('Three columns, 50% - 25% - 25%'),
69 '25-25-50' => t('Three columns, 25%-25%-50%'),
70 '33-33-33' => t('Three columns, 33%-33%-33%'),
71 '25-25-25-25' => t('Four columns, 25 - 25% - 25% - 25%'),
72 );
73 */
74 switch ($main_grid) {
75 case '50-50':
76 case '66-33':
77 case '75-25':
78 $columns = array (
79 '#type' => $main_grid,
80 '#first' => $new_content,
81 '#second' => $vars['beta'],
82 );
83 $vars['primary_column'] = nautilus_grid($columns);
84 break;
85
86 case '33-66':
87 case '25-75':
88 $columns = array (
89 '#type' => $main_grid,
90 '#first' => $vars['beta'],
91 '#second' => $new_content,
92 );
93 $vars['primary_column'] = nautilus_grid($columns);
94 break;
95
96 case '50-25-25':
97 $columns = array (
98 '#type' => '50-50',
99 '#first' => $new_content,
100 '#second' => array (
101 '#type' => '50-50',
102 '#first' => $vars['beta'],
103 '#second' => $vars['delta'],
104 ),
105 );
106 $vars['primary_column'] = nautilus_grid($columns);
107 break;
108
109 case '25-25-50':
110 $columns = array (
111 '#type' => '50-50',
112 '#first' => array (
113 '#type' => '50-50',
114 '#first' => $vars['beta'],
115 '#second' => $vars['delta'],
116 ),
117 '#second' => $new_content,
118 );
119 $vars['primary_column'] = nautilus_grid($columns);
120 break;
121
122 case '33-33-33':
123 $columns = array (
124 '#type' => '33-33-33',
125 '#first' => $new_content,
126 '#second' => $vars['beta'],
127 '#third' => $vars['delta'],
128 );
129 $vars['primary_column'] = nautilus_grid($columns);
130 break;
131
132 case '25-25-25-25':
133 $columns = array (
134 '#type' => '50-50',
135 '#first' => array (
136 '#type' => '50-50',
137 '#first' => $new_content,
138 '#second' => $vars['beta'],
139 ),
140 '#second' => array (
141 '#type' => '50-50',
142 '#first' => $vars['gamma'],
143 '#second' => $vars['delta'],
144 ),
145 );
146 $vars['primary_column'] = nautilus_grid($columns);
147 break;
148
149 default:
150 // main column is just the "primary" content
151 $vars['primary_column'] = $new_content;
152 break;
153 }
154
155 // now me make the secondary column
156 switch ($main_grid) {
157 case '50-50':
158 case '66-33':
159 case '33-66':
160 case '75-25':
161 case '25-75':
162 switch($secondary_grid) {
163 case '50-50':
164 case '66-33':
165 case '75-25':
166 $columns = array (
167 '#type' => $secondary_grid,
168 '#first' => $new_alpha,
169 '#second' => $vars['gamma'] . $vars['delta'],
170 );
171 $vars['secondary_column'] = nautilus_grid($columns);
172 break;
173
174 case '25-75':
175 case '33-66':
176 $columns = array (
177 '#type' => $secondary_grid,
178 '#first' => $vars['gamma'] . $vars['delta'],
179 '#second' => $new_alpha,
180 );
181 $vars['secondary_column'] = nautilus_grid($columns);
182 break;
183
184 case '50-25-25':
185 $columns = array (
186 '#type' => '50-50',
187 '#first' => $new_alpha,
188 '#second' => array (
189 '#type' => '50-50',
190 '#first' => $vars['gamma'],
191 '#second' => $vars['delta'],
192 ),
193 );
194 $vars['secondary_column'] = nautilus_grid($columns);
195 break;
196
197 case '25-25-50':
198 $columns = array (
199 '#type' => '50-50',
200 '#first' => array (
201 '#type' => '50-50',
202 '#first' => $vars['gamma'],
203 '#second' => $vars['delta'],
204 ),
205 '#second' => $new_alpha,
206 );
207 $vars['secondary_column'] = nautilus_grid($columns);
208 break;
209
210 // there are not enough regions for 2 in the main column and 4 in the secondary, so it behaves like 3 columns
211 case '33-33-33':
212 case '25-25-25-25':
213 $columns = array (
214 '#type' => '33-33-33',
215 '#first' => $new_alpha,
216 '#second' => $vars['gamma'],
217 '#third' => $vars['delta'],
218 );
219 $vars['secondary_column'] = nautilus_grid($columns);
220 break;
221 default:
222 // "alpha" + "gamma" + "delta"
223 $vars['secondary_column'] = $new_alpha . $vars['gamma'] . $vars['delta'];
224 break;
225 }
226 break;
227
228 case '50-25-25':
229 case '25-25-50':
230 case '33-33-33':
231 switch ($secondary_grid) {
232 case '50-25-25':
233 case '25-25-50':
234 case '33-33-33':
235 case '25-25-25-25':
236 // none of these are valid options, so they will behave like 50-50s
237 $secondary_grid = '50-50';
238 // fold into the 50-50 section ...
239 case '50-50':
240 case '66-33':
241 case '75-25':
242 $columns = array (
243 '#type' => $secondary_grid,
244 '#first' => $new_alpha,
245 '#second' => $vars['delta'],
246 );
247 $vars['secondary_column'] = nautilus_grid($columns);
248 break;
249
250 case '25-75':
251 case '33-66':
252 $columns = array (
253 '#type' => $secondary_grid,
254 '#first' => $vars['delta'],
255 '#second' => $new_alpha,
256 );
257 $vars['secondary_column'] = nautilus_grid($columns);
258 break;
259
260 default:
261 $vars['secondary_column'] = $new_alpha . $vars['delta'];
262 break;
263 }
264 break;
265 case '25-25-25-25':
266 // only one option for the 4-up - we ignore what the user has asked for, 'cause they can't have it. :-)
267 $vars['secondary_column'] = $new_alpha;
268 break;
269
270 default:
271 switch ($secondary_grid) {
272 case '50-50':
273 case '66-33':
274 case '75-25':
275 $columns = array (
276 '#type' => $secondary_grid,
277 '#first' => $new_alpha . $vars['gamma'],
278 '#second' => $vars['beta'] . $vars['delta'],
279 );
280 $vars['secondary_column'] = nautilus_grid($columns);
281 break;
282
283 case '33-66':
284 case '25-75':
285 $columns = array (
286 '#type' => $secondary_grid,
287 '#first' => $vars['beta'] . $vars['delta'],
288 '#second' => $new_alpha . $vars['gamma'],
289 );
290 $vars['secondary_column'] = nautilus_grid($columns);
291 break;
292
293 case '50-25-25':
294 $columns = array (
295 '#type' => '50-50',
296 '#first' => $new_alpha . $vars['gamma'],
297 '#second' => array (
298 '#type' => '50-50',
299 '#first' => $vars['beta'],
300 '#second' => $vars['delta'],
301 ),
302 );
303 $vars['secondary_column'] = nautilus_grid($columns);
304 break;
305
306 case '25-25-50':
307 $columns = array (
308 '#type' => '50-50',
309 '#first' => array (
310 '#type' => '50-50',
311 '#first' => $vars['beta'],
312 '#second' => $vars['delta'],
313 ),
314 '#second' => $new_alpha . $vars['gamma'],
315 );
316 $vars['secondary_column'] = nautilus_grid($columns);
317 break;
318
319 case '33-33-33':
320 $columns = array (
321 '#type' => '33-33-33',
322 '#first' => $new_alpha . $vars['gamma'],
323 '#second' => $vars['beta'],
324 '#third' => $vars['delta'],
325 );
326 $vars['secondary_column'] = nautilus_grid($columns);
327 break;
328
329 case '25-25-25-25':
330 $columns = array (
331 '#type' => '50-50',
332 '#first' => array (
333 '#type' => '50-50',
334 '#first' => $new_alpha,
335 '#second' => $vars['beta'],
336 ),
337 '#second' => array (
338 '#type' => '50-50',
339 '#first' => $vars['gamma'],
340 '#second' => $vars['delta'],
341 ),
342 );
343 $vars['secondary_column'] = nautilus_grid($columns);
344 break;
345
346 default:
347 // main column is just the "primary" content
348 $vars['secondary_column'] = $new_alpha . $vars['beta'] . $vars['gamma'] . $vars['delta'];
349 break;
350 }
351 break;
352 }
353
354 }
355 return $vars;
356 }
357
358
359 function nautilus_regions() {
360 return array(
361 'alpha' => t('Alpha: Highest priority region'),
362 'beta' => t('Beta: Second highest priority region'),
363 'gamma' => t('Gamma: Third highest priority region'),
364 'delta' => t('Delta: Lowest priority region'),
365 'content' => t('Content: Region below the content of a page'),
366 'footer' => t('Footer: Region in the footer message'),
367 'predoc' => t('Predoc: Region before the page frame'),
368 'postdoc' => t('Postdoc: Region after below the page frame'),
369 );
370 }
371
372 function nautilus_breadcrumb($breadcrumb) {
373 if (!empty($breadcrumb)) {
374 return implode(' &gt; ', $breadcrumb);
375 }
376 }
377
378
379 function nautilus_stylesheet_import($path, $media = 'all') {
380 if ($path != base_path() .'misc/drupal.css' || variable_get('nautilustheme_drupalcss', true)) {
381 return '<style type="text/css" media="'. $media .'">@import "'. $path .'";</style>';
382 }
383 }
384
385 function nautilus_block($block) {
386 $output = "<div class=\"block block-$block->module\" id=\"block-$block->module-$block->delta\">\n";
387 $output .= " <h3 class=\"title\">$block->subject</h3>\n";
388 $output .= " <div class=\"content\">$block->content</div>\n";
389 $output .= "</div>\n";
390 return $output;
391 }
392
393 /* Some functions to use the YUI grid system */
394 function nautilus_grid(&$columns, $first = false) {
395
396 $only_grids = true;
397 $yui_grid_class = 'yui-g';
398
399 switch($columns['#type']) {
400 case '66-33':
401 $yui_grid_class = 'yui-gc';
402 break;
403 case '33-66':
404 $yui_grid_class = 'yui-gd';
405 break;
406 case '33-33-33':
407 $yui_grid_class = 'yui-gb';
408 if (gettype($columns['#third']) == 'string') {
409 $third = '<div class = "yui-u">' . $columns['#third'] . '</div>';
410 $only_grids = false; // set a flag to show that is is not a grid inside a grid
411 } else {
412 $third = nautilus_grid($columns['#third'], false);
413 }
414 break;
415 case '75-25':
416 $yui_grid_class = 'yui-ge';
417 break;
418 case '25-75':
419 $yui_grid_class = 'yui-gf';
420 break;
421 case '50-50':
422 // leave $yui_grid_class as the default (yui-g)
423 default:
424
425 break;
426 }
427
428 /* figure out if we need to recurse on the first and second columns */
429
430 if (gettype($columns['#second']) == 'string') {
431 $second = '<div class = "yui-u">' . $columns['#second'] . '</div>';
432 $only_grids = false;
433 } else {
434 $second = nautilus_grid($columns['#second'], false);
435 }
436
437 if (gettype($columns['#first']) == 'string') {
438 $first = '<div class = "yui-u first">' . $columns['#first'] . '</div>';
439 } else {
440 $first = nautilus_grid($columns['#first'], $only_grids);
441 }
442
443 $grid = '<div class ="' . $yui_grid_class . ' ' . $columns['#attributes'] . ' ' . ($first ? "first" : "") . '">' . $first . $second . $third . '</div>';
444 //$grid = '<div class ="' . $yui_grid_class . ' ' . $columns['#attributes'] . '">' . $first . $second . $third . '</div>';
445 return $grid;
446 }

  ViewVC Help
Powered by ViewVC 1.1.2