/[drupal]/contributions/themes/sky/theme-settings.php
ViewVC logotype

Contents of /contributions/themes/sky/theme-settings.php

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


Revision 1.4 - (show annotations) (download) (as text)
Sun Jun 21 16:28:25 2009 UTC (5 months, 1 week ago) by jgirlygirl
Branch: MAIN
CVS Tags: DRUPAL-6--3-8, DRUPAL-6--3-9, DRUPAL-6--3-6, DRUPAL-6--3-7, DRUPAL-6--3-4, DRUPAL-6--3-5, HEAD
Changes since 1.3: +1 -1 lines
File MIME type: text/x-php
Fixed breadcrumb theme setting #496060
1 <?php
2 // $Id$
3
4 /**
5 * @file
6 * Handles the custom theme settings
7 */
8
9 /**
10 * Implementation of _settings() theme function.
11 *
12 * PHP Template users: Do NOT put this function in your
13 * template.php file; it won't work.
14 *
15 * @return array
16 */
17
18 function sky_settings($saved_settings) {
19 // Set the default values for the theme variables
20 $defaults = array(
21 'sky_background' => NULL,
22 'sky_background_header' => NULL,
23 'sky_breadcrumbs' => 0,
24 'sky_breadcrumbs_sep' => '&raquo;',
25 'sky_links' => NULL,
26 'sky_links_active' => NULL,
27 'sky_links_hover' => NULL,
28 'sky_links_visited' => NULL,
29 'sky_font' => 'lucida',
30 'sky_font_headings' => 'lucida',
31 'sky_font_size' => '12px',
32 'sky_header_height' => 'auto',
33 'sky_layout' => 'fixed_960',
34 'sky_custom_layout' => NULL,
35 'sky_nav_alignment' => 'center',
36 'sky_sub_navigation_size' => '15em',
37 );
38
39 // Merge the variables and their default values
40 $settings = array_merge($defaults, $saved_settings);
41
42 // Breadcrumb Settings
43 $form['sky_breadcrumbs'] = array(
44 '#type' => 'checkbox',
45 '#title' => t('Disable Breadcrumbs'),
46 '#default_value' => $settings['sky_breadcrumbs'],
47 );
48
49 // Breadcrumb Separator
50 $breadcrumbs_status = $settings['sky_breadcrumbs_sep'] ? TRUE : FALSE;
51 $breadcrumbs_desc = $breadcrumbs_status ? t('Select a breadcrumb separator.') : t('Breadcrumbs must be enabled to use this feature.');
52
53 $form['sky_breadcrumbs_sep'] = array(
54 '#type' => 'select',
55 '#title' => t('Breadcrumb Separator'),
56 '#default_value' => $settings['sky_breadcrumbs_sep'],
57 '#options' => array(
58 '&raquo;' => '»',
59 '&rsaquo;' => '›',
60 '&rarr;' => '→',
61 '/' => t('/'),
62 ),
63 '#description' => $breadcrumbs_desc,
64 '#disabled' => $breadcrumbs_status,
65 );
66
67 // Layout Options
68 $form['layout'] = array(
69 '#type' => 'fieldset',
70 '#title' => 'Layout Options',
71 '#collapsible' => TRUE,
72 '#collapsed' => FALSE,
73 );
74
75 // Layout Type
76 $form['layout']['sky_layout'] = array(
77 '#type' => 'select',
78 '#title' => t('Layout Type'),
79 '#default_value' => $settings['sky_layout'],
80 '#options' => array(
81 'fixed_960' => t('Fixed - 960px'),
82 'fluid_98' => t('Fluid - 98%'),
83 'fluid' => t('Fluid - 100%'),
84 ),
85 '#description' => t('This will determine the width of your site layout. Fixed layouts are center aligned.
86 <ul class="tips">
87 <li><strong>Fixed - 960px:</strong> A standard size for targeting: 1024 x 768 resolution.</li>
88 <li><strong>Fluid - 98%:</strong> Will automatically size to fit the 98% the screen width, leaving room for the background image.</li>
89 <li><strong>Fluid - 100%:</strong> Will automatically size to fit the 100% the screen width.</li>
90 </ul>'),
91 );
92
93 $form['layout']['sky_custom_layout'] = array(
94 '#type' => 'textfield',
95 '#title' => t('Custom Layout Width'),
96 '#default_value' => $settings['sky_custom_layout'],
97 '#size' => 8,
98 '#description' => t('Set your own layout width. Be sure to specify units (px, em, %, etc). NOTE: If any value is set here, it will override the above layout options.'),
99 );
100
101 // Alignment of Navigation
102 $form['layout']['sky_nav_alignment'] = array(
103 '#type' => 'select',
104 '#title' => t('Header Navigation Alignment'),
105 '#default_value' => $settings['sky_nav_alignment'],
106 '#options' => array(
107 'left' => t('Left'),
108 'right' => t('Right'),
109 'center' => t('Center'),
110 ),
111 '#description' => t('The alignment of the header navigation bar.'),
112 );
113
114 // Width of Dropdown menus
115 $form['layout']['sky_sub_navigation_size'] = array(
116 '#type' => 'select',
117 '#title' => t('Dropdown Menus Second Level Menu Width'),
118 '#default_value' => $settings['sky_sub_navigation_size'],
119 '#options' => sky_size_range(10, 30, 'em', 15),
120 '#description' => t('The drop-down menus need a width. IF you find your menu items need to be adjusted smaller or larger, you can tweak the settings here.'),
121 );
122
123 // Adjust the height of the header, commonly requested in the issue queue.
124 $form['layout']['sky_header_height'] = array(
125 '#type' => 'textfield',
126 '#title' => t('Height of Header (default is "95px")'),
127 '#default_value' => $settings['sky_header_height'],
128 '#description' => t('To tweak the height of the header, please enter the height in pixels or ems, ie. 100px, 5em'),
129 );
130
131 // Colors
132 $form['colors'] = array(
133 '#type' => 'fieldset',
134 '#title' => 'Color Options',
135 '#collapsible' => TRUE,
136 '#collapsed' => FALSE,
137 );
138
139 // Body Background Color
140 $form['colors']['sky_background'] = array(
141 '#type' => 'textfield',
142 '#title' => t('Body Background'),
143 '#default_value' => $settings['sky_background'],
144 '#description' => t('Example: If you want a black background enter <code>#000000</code>. If you want to include a background image, upload it to your server, and enter something like: <code>#fff url(\'/full/path/to/background/image.jpg\') repeat-x bottom left;</code>'),
145 );
146
147 // Heading Background Color
148 $form['colors']['sky_background_header'] = array(
149 '#type' => 'textfield',
150 '#title' => t('Header Background'),
151 '#default_value' => $settings['sky_background_header'],
152 '#description' => t('Example: If you want a black background enter <code>#000000</code>. If you want to include a background image, upload it to your server, and enter something like: <code>#fff url(\'/full/path/to/background/image.jpg\') repeat-x bottom left;</code>'),
153 );
154
155 // Fonts
156 $form['fonts'] = array(
157 '#type' => 'fieldset',
158 '#title' => 'Font Options',
159 '#collapsible' => TRUE,
160 '#collapsed' => FALSE,
161 );
162 // Base Font Size
163 $form['fonts']['sky_font_size'] = array(
164 '#type' => 'select',
165 '#title' => t('Base Font Size'),
166 '#default_value' => $settings['sky_font_size'],
167 '#options' => sky_size_range(11, 16, 'px', 12),
168 '#description' => t('Select the base font size for the theme.'),
169 );
170
171 // Base Font
172 $form['fonts']['sky_font'] = array(
173 '#type' => 'select',
174 '#title' => t('Base Font'),
175 '#default_value' => $settings['sky_font'],
176 '#options' => sky_font_list(),
177 '#description' => t('Select the base font for the theme.'),
178 );
179
180 // Headings Font
181 $form['fonts']['sky_font_headings'] = array(
182 '#type' => 'select',
183 '#title' => t('Headings Font'),
184 '#default_value' => $settings['sky_font_headings'],
185 '#options' => sky_font_list(),
186 '#description' => t('Select the base font for the heading (block, page titles and heading tags).'),
187 );
188
189 // Links
190 $form['colors']['sky_links'] = array(
191 '#type' => 'textfield',
192 '#title' => t('Links: Normal'),
193 '#default_value' => $settings['sky_links'],
194 '#description' => t('Example: <code>#314C74</code> or <code>blue</code> NOTE: This will only change the links that are blue by default.'),
195 );
196
197 // Links: Active
198 $form['colors']['sky_links_active'] = array(
199 '#type' => 'textfield',
200 '#title' => t('Links: Active'),
201 '#default_value' => $settings['sky_links_active'],
202 '#description' => t('Example: <code>#314C74</code> or <code>blue</code> NOTE: This will only change the links that are blue by default'),
203 );
204
205 // Links: Hover
206 $form['colors']['sky_links_hover'] = array(
207 '#type' => 'textfield',
208 '#title' => t('Links: Hover'),
209 '#default_value' => $settings['sky_links_hover'],
210 '#description' => t('Example: <code>#314C74</code> or <code>blue</code> NOTE: This will only change the links that are blue by default'),
211 );
212
213 // Links: Visited
214 $form['colors']['sky_links_visited'] = array(
215 '#type' => 'textfield',
216 '#title' => t('Links: Visited'),
217 '#default_value' => $settings['sky_links_visited'],
218 '#description' => t('Example: <code>#314C74</code> or <code>blue</code> NOTE: This will only change the links that are blue by default'),
219 );
220
221 // Generate custom.css and display a link to the file
222 $form['sky_css'] = array(
223 '#type' => 'fieldset',
224 '#title' => 'Custom CSS Generation',
225 '#description' => sky_write_css(), // This is the function that creates the custom.css file is created... Do not remove.
226 '#collapsible' => TRUE,
227 '#collapsed' => FALSE,
228 );
229
230 return $form;
231 }
232
233 function sky_build_css() {
234 // Grab the current theme settings
235 $theme_settings = variable_get('theme_sky_settings', '');
236 if (!empty($theme_settings)) {
237 // Build an array of only the theme related settings
238 $setting = array();
239 foreach ($theme_settings as $key => $value) {
240 if (strpos($key, 'sky_') !== FALSE) {
241 $setting[$key] = $value;
242 }
243 }
244 // Handle custom settings for each case
245 $custom_css = array();
246 foreach ($setting as $key => $value) {
247 switch ($key) {
248 // Layout
249 case 'sky_layout':
250 // If a custom value is set for use "sky_custom_layout", ignore "sky_layout".
251 if ($setting['sky_custom_layout'] != '') {
252 $custom_css[] = '#wrapper, #footer { width: '. $setting['sky_custom_layout'] .'; }';
253 }
254 else {
255 switch ($value) {
256 case 'fluid':
257 $width = '100%';
258 break;
259 case 'fluid_98':
260 $width = '98%';
261 break;
262 case 'fixed': default:
263 $width = '960px';
264 break;
265 }
266 $custom_css[] = '#wrapper, #footer { width: '. $width .'; }';
267 }
268 break;
269 case 'sky_header_height':
270 $custom_css[] = '#header { height: '. $value .'; }';
271 break;
272 case 'sky_sub_navigation_size':
273 $custom_css[] = '#navigation ul ul, #navigation ul ul li { width: '. $value .'; }';
274 $custom_css[] = '#navigation li .expanded ul { margin: -2.65em 0 0 '. $value .'!important; }';
275 break;
276
277 // Colors
278 case 'sky_background':
279 $custom_css[] = (!empty($value)) ? 'html, body { background: '. $value .'; }' : '';
280 break;
281 case 'sky_background_header':
282 $custom_css[] = (!empty($value)) ? '#header { background: '. $value .'; }' : '';
283 break;
284 case 'sky_links':
285 $custom_css[] = (!empty($value)) ? 'a { color: '. $value .'; }' : '';
286 break;
287 case 'sky_links_hover':
288 $custom_css[] = (!empty($value)) ? 'a:hover, a:visited:hover { color: '. $value .'; }' : '';
289 break;
290 case 'sky_links_active':
291 $custom_css[] = (!empty($value)) ? 'a.active, li a.active { color: '. $value .'; }' : '';
292 break;
293 case 'sky_links_visited':
294 $custom_css[] = (!empty($value)) ? 'a:visited { color: '. $value .'; }' : '';
295 break;
296
297 // Fonts
298 case 'sky_font_size':
299 $custom_css[] = (!empty($value)) ? '#wrapper { font-size: '. $value .'; }' : '';
300 break;
301 case 'sky_font':
302 $custom_css[] = 'html, body, .form-radio, .form-checkbox, .form-file, .form-select, select, .form-text, input, .form-textarea, textarea { font-family: '. sky_font_stack($value) .'; }';
303 break;
304 case 'sky_font_headings':
305 $custom_css[] = 'h1, h2, h3, h4, h5, h6 { font-family: '. sky_font_stack($value) .'; }';
306 break;
307 }
308 }
309 return implode("\r\n", $custom_css);
310 }
311 }
312
313 function sky_write_css() {
314 // Set the location of the custom.css file
315 $file_path = file_directory_path() .'/sky/custom.css';
316
317 // If the directory doesn't exist, create it
318 file_check_directory(dirname($file_path), FILE_CREATE_DIRECTORY);
319
320 // Generate the CSS
321 $file_contents = sky_build_css();
322 $output = '<div class="description">'. t('This CSS is generated by the settings chosen above and placed in the files directory: '. l($file_path, $file_path) .'. The file is generated each time this page (and only this page) is loaded. <strong class="marker">Make sure to refresh your page to see the changes</strong>') .'</div>';
323
324 file_save_data($file_contents, $file_path, FILE_EXISTS_REPLACE);
325
326 return $output;
327
328 }
329
330 /**
331 * Helper function to provide a list of fonts for select list in theme settings.
332 */
333 function sky_font_list() {
334 $fonts = array(
335 'Sans-serif' => array(
336 'verdana' => t('Verdana'),
337 'helvetica' => t('Helvetica, Arial'),
338 'lucida' => t('Lucida Grande, Lucida Sans Unicode'),
339 'geneva' => t('Geneva'),
340 'tahoma' => t('Tahoma'),
341 'century' => t('Century Gothic'),
342 ),
343 'Serif' => array(
344 'georgia' => t('Georgia'),
345 'palatino' => t('Palatino Linotype, Book Antiqua'),
346 'times' => t('Times New Roman'),
347 ),
348 );
349 return $fonts;
350 }
351
352 /**
353 * Provides Font Stack values for theme settings which are written to custom.css
354 * @see sky_font_list()
355 * @param $attributes
356 * @return string
357 */
358 function sky_font_stack($font) {
359 if ($font) {
360 $fonts = array(
361 'verdana' => '"Bitstream Vera Sans", Verdana, Arial, sans-serif',
362 'helvetica' => 'Helvetica, Arial, "Nimbus Sans L", "Liberation Sans", "FreeSans", sans-serif',
363 'lucida' => '"Lucida Grande", "Lucida Sans", "Lucida Sans Unicode", "DejaVu Sans", Arial, sans-serif',
364 'geneva' => '"Geneva", "Bitstream Vera Serif", "Tahoma", sans-serif',
365 'tahoma' => 'Tahoma, Geneva, "DejaVu Sans Condensed", sans-serif',
366 'century' => '"Century Gothic", "URW Gothic L", Helvetica, Arial, sans-serif',
367 'georgia' => 'Georgia, "Bitstream Vera Serif", serif',
368 'palatino' => '"Palatino Linotype", "URW Palladio L", "Book Antiqua", "Palatino", serif',
369 'times' => '"Free Serif", "Times New Roman", Times, serif',
370 );
371
372 foreach ($fonts as $key => $value) {
373 if ($font == $key) {
374 $output = $value;
375 }
376 }
377 }
378 return $output;
379 }
380
381 /**
382 * Helper function to provide a list of sizes for use in theme settings.
383 */
384 function sky_size_range($start = 11, $end = 16, $unit = 'px', $default = NULL) {
385 $range = '';
386 if (is_numeric($start) && is_numeric($end)) {
387 $range = array();
388 $size = $start;
389 while ($size >= $start && $size <= $end) {
390 if ($size == $default) {
391 $range[$size . $unit] = $size . $unit .' (default)';
392 }
393 else {
394 $range[$size . $unit] = $size . $unit;
395 }
396 $size++;
397 }
398 }
399 return $range;
400 }

  ViewVC Help
Powered by ViewVC 1.1.2