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

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

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


Revision 1.14 - (show annotations) (download) (as text)
Sat Dec 27 04:53:32 2008 UTC (10 months, 4 weeks ago) by brauerranch
Branch: MAIN
CVS Tags: HEAD
Changes since 1.13: +43 -4 lines
File MIME type: text/x-php
#289971 request to have additional body classes borrowed from Zen
1 <?php
2 // $Id: template.php,v 1.13 2008/06/01 04:13:46 brauerranch Exp $
3
4 /**
5 * @file
6 * template.php for the Light Fantastic theme for Drupal 6.
7 *
8 * This file provides overrides and theme-specific functions for the Light
9 * Fantastic theme for Drupal 6 and higher.
10 */
11
12 /**
13 * Override or insert variables into the page template.
14 */
15 function lightfantastic_preprocess_page(&$vars) {
16
17 $vars['site_title'] = !empty($vars['site_name']) ? check_plain($vars['site_name']) : '';
18 $vars['ie6_styles'] = '<link type="text/css" rel="stylesheet" media="all" href="' . base_path() . path_to_theme() . '/assets/style/ie6.css" />'. "\n";
19 $vars['ie7_styles'] = '<link type="text/css" rel="stylesheet" media="all" href="' . base_path() . path_to_theme() . '/assets/style/ie7.css" />'. "\n";
20 $vars['primary_nav'] = isset($vars['primary_links']) ? theme('links', $vars['primary_links'], array('id' => 'main-menu')) : FALSE;
21 $vars['tabs2'] = menu_secondary_local_tasks();
22
23 /**
24 * Set width for the site and two sidebars:
25 * This theme allows the site to have a fluid or fixed width layout.
26 * Setting a value for the fixed width will force the layout to be fixed.
27 * For fluid layouts, maximum and minimum widths could be set.
28 * For any layout, Left and Right column widths could be set.
29 * If fixed width, maximum and minimum widths would be ignored.
30 */
31
32 $site_fixed_width = '960px'; // Width if fixed-width layout. Leave blank ('') for fluid layout.
33 $site_min_width = '760px'; // Minimum width if fluid layout.
34 $site_max_width = '960px'; // Maximum width if fluid layout.
35 $left_sidebar_width = '240px'; // Width of left column.
36 $right_sidebar_width = '240px'; // Width of right column.
37 $secondary_nav = "left";
38
39 // Set page width.
40 if ($site_fixed_width == "") {
41 $site_fixed_width = (($site_max_width - $site_min_width) < 0 ) ? "960px" : "" ;
42 }
43 $site_width = ($site_fixed_width != "") ? "width: $site_fixed_width;" : "max-width: $site_max_width; min-width: $site_min_width;" ;
44
45 if ($site_fixed_width == "") {
46 $site_fixed_width = (($site_max_width - $site_min_width) < 0 ) ? "1" : "" ;
47 }
48 $is_fixed_width = ($site_fixed_width != "") ? "0" : "1" ;
49
50 // Secondary navigation position.
51 $vars['secondary_nav'] = $secondary_nav == 'right' ? 'right' : 'left';
52
53 $style = "";
54 $style .= '<style type="text/css">';
55 $style .= "div#container { $site_width }";
56
57 if ($vars['sidebar_left'] || $vars['navigation_left'] || ($vars['secondary_links'] && $vars['secondary_nav'] == 'left')) {
58 $style .= "div#content-wrap div#content-inter-wrap { margin-left: -$left_sidebar_width; }";
59 $style .= "div#content-wrap div#sidebar-left { width: $left_sidebar_width; }";
60 $background = 1000 - $left_sidebar_width;
61 $style .= "div#content-outer-wrap { background-position: -". $background ."px top; }";
62 $style .= "div#content-wrap div#content { margin-left: $left_sidebar_width; }";
63 }
64
65 if (($vars['sidebar_left'] || $vars['navigation_left'] || ($vars['secondary_links'] && $vars['secondary_nav'] == 'left'))
66 && ($vars['sidebar_right'] || $vars['navigation_right'] || ($vars['secondary_links'] && $vars['secondary_nav'] == 'right'))) {
67 $style .= "div#content-wrap div#content { margin-left: $left_sidebar_width; }";
68 }
69
70 if ($vars['sidebar_right'] || $vars['navigation_right'] || ($vars['secondary_links'] && $vars['secondary_nav'] == 'right')) {
71 $style .= "div#container div#main-content { margin-left: -$right_sidebar_width; }";
72 $style .= "div#container div#main { margin-left: $right_sidebar_width; }";
73 $style .= "div#container div#sidebar-right { width: $right_sidebar_width; }";
74 }
75
76 $style .= '</style>';
77
78 if ($is_fixed_width) {
79 // IE6 min-width, max-width expression.
80 $style .= '
81 <!--[if lte IE 6]>
82 <style type="text/css">
83 div#container { width: expression(document.body.clientWidth < '. ($site_min_width + 1) .' ? "'. $site_min_width .'" : document.body.clientWidth > '. ($site_max_width + 1) .' ? "'. $site_max_width .'" : "100%"); }
84 </style>
85 <![endif]-->';
86 }
87
88 $vars['layout_style'] = $style;
89
90 // Sets the body-tag class attribute.
91 // Adds 'sidebar-left', 'sidebar-right' or 'sidebars' classes as needed.
92 $vars['body_class'] = isset($vars['body_class']) ? $vars['body_class'] : '';
93 if ((($vars['sidebar_left'] || $vars['navigation_left'] || ($vars['secondary_links'] && ($vars['secondary_nav'] == 'left'))))
94 && ($vars['sidebar_right'] || $vars['navigation_right'] || ($vars['secondary_links'] && ($vars['secondary_nav'] == 'right')))) {
95 $body_class = 'sidebars';
96 }
97 else {
98 if ($vars['sidebar_left'] || $vars['navigation_left'] || ($vars['secondary_links'] && ($vars['secondary_nav'] == 'left'))) {
99 $body_class = 'sidebar-left';
100 }
101 if ($vars['sidebar_right'] || $vars['navigation_right'] || ($vars['secondary_links'] && ($vars['secondary_nav'] == 'right'))) {
102 $body_class = 'sidebar-right';
103 }
104 }
105
106 // Get published block in 'additional' region and set 'additional_chunk' variable.
107 switch (count(block_list('additional'))) {
108 case 0:
109 $vars['additional_chunk'] = "";
110 break;
111 case 1:
112 $vars['additional_chunk'] = "chunk-one";
113 break;
114 case 2:
115 $vars['additional_chunk'] = "chunk-two";
116 break;
117 case 3:
118 $vars['additional_chunk'] = "chunk-three";
119 break;
120 default:
121 $vars['additional_chunk'] = "chunk-unknown";
122 }
123
124 // Get published block in 'banner' region and set 'banner_chunk' variable.
125 switch (count(block_list('banner'))) {
126 case 0:
127 $vars['banner_chunk'] = "";
128 break;
129 case 1:
130 $vars['banner_chunk'] = "chunk-one";
131 break;
132 case 2:
133 $vars['banner_chunk'] = "chunk-two";
134 break;
135 case 3:
136 $vars['banner_chunk'] = "chunk-three";
137 break;
138 default:
139 $vars['banner_chunk'] = "chunk-unknown";
140 }
141
142 // Classes for body elemets as written for the Zen theme and used here with gratitude
143 // Classes for body element. Allows advanced theming based on context
144 // (home page, node of certain type, etc.)
145 $body_classes = array($vars['body_classes']);
146 if (!$vars['is_front']) {
147 // Add unique classes for each page and website section
148 $path = drupal_get_path_alias($_GET['q']);
149 list($section,) = explode('/', $path, 2);
150 $body_classes[] = lightfantastic_id_safe('page-'. $path);
151 $body_classes[] = lightfantastic_id_safe('section-'. $section);
152 }
153 $body_classes = implode(' ', $body_classes); // implode with spaces
154 if (isset($body_class) || isset($body_classes)) {
155 $vars['body_class'] = ' class="'. $body_class . ' ' . $body_classes .'"';
156 }
157 }
158
159 /**
160 * Return a themed breadcrumb trail.
161 *
162 * @param $breadcrumb
163 * An array containing the breadcrumb links.
164 * @return a string containing the breadcrumb output.
165 */
166 function lightfantastic_breadcrumb($breadcrumb) {
167 if (!empty($breadcrumb)) {
168 return '<div id="breadcrumb">'. implode(' &raquo; ', $breadcrumb) .'</div>';
169 }
170 else {
171 return '<div id="breadcrumb">&nbsp;</div>';
172 }
173 }
174
175 /**
176 * Allow themable wrapping of all comments.
177 */
178 function lightfantastic_comment_wrapper($content, $node) {
179 if (!$content || $node->type == 'forum') {
180 return '<div id="comments">'. $content .'</div>';
181 }
182 else {
183 return '<div id="comments"><h2 class="comments">'. t('Comments') .'</h2>'. $content .'</div>';
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 lightfantastic_menu_local_tasks() {
194 $output = '';
195
196 if ($primary = menu_primary_local_tasks()) {
197 $output .= "<ul class=\"tabs primary\">\n". $primary ."</ul>\n";
198 }
199
200 return $output;
201 }
202
203 function lightfantastic_comment_submitted($comment) {
204 return t('!datetime — !username',
205 array(
206 '!username' => theme('username', $comment),
207 '!datetime' => format_date($comment->timestamp)
208 ));
209 }
210
211 function lightfantastic_node_submitted($node) {
212 return t('!datetime — !username',
213 array(
214 '!username' => theme('username', $node),
215 '!datetime' => format_date($node->created),
216 ));
217 }
218
219 /**
220 * Converts a string to a suitable html ID attribute.
221 *
222 * This was graciously borrowed from the Zen theme.
223 *
224 * http://www.w3.org/TR/html4/struct/global.html#h-7.5.2 specifies what makes a
225 * valid ID attribute in HTML. This function:
226 *
227 * - Ensure an ID starts with an alpha character by optionally adding an 'n'.
228 * - Replaces any character except A-Z, numbers, and underscores with dashes.
229 * - Converts entire string to lowercase.
230 *
231 * @param $string
232 * The string
233 * @return
234 * The converted string
235 */
236 function lightfantastic_id_safe($string) {
237 // Replace with dashes anything that isn't A-Z, numbers, dashes, or underscores.
238 $string = strtolower(preg_replace('/[^a-zA-Z0-9_-]+/', '-', $string));
239 // If the first character is not a-z, add 'n' in front.
240 if (!ctype_lower($string{0})) { // Don't use ctype_alpha since its locale aware.
241 $string = 'id' . $string;
242 }
243 return $string;
244 }

  ViewVC Help
Powered by ViewVC 1.1.2