Projet

Général

Profil

Paste
Télécharger (18 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / themes / mayo / theme-settings.php @ 03574fc5

1
<?php
2

    
3
/**
4
 * Implements hook_form_system_theme_settings_alter().
5
 *
6
 * Custom theme settings
7
 */
8
function mayo_form_system_theme_settings_alter(&$form, &$form_state) {
9

    
10
  drupal_add_js(drupal_get_path('theme', 'mayo') . '/js/mayo.js');
11

    
12
  /*--------------- Font settings --------------*/
13
  $form['font'] = array(
14
    '#type' => 'fieldset',
15
    '#title' => t('Font settings'),
16
    '#collapsed' => TRUE,
17
    '#collapsible' => TRUE,
18
  );
19
  $form['font']['base_font_size'] = array(
20
    '#type' => 'select',
21
    '#title' => t('Base font size'),
22
    '#default_value' => theme_get_setting('base_font_size'),
23
    '#options' => array(
24
      '75%'    => '75% (=12px)',
25
      '81.25%' => '81.25% (=13px)',
26
      '87.5%'  => '87.5% (=14px)',
27
      '93.75%' => '93.75% (=15px)',
28
      '100%'   => '100% (=16px)',
29
      '112.5%' => '112.5% (=18px)'
30
    ),
31
    '#description' => t('To support text size enlargement/reduction, percent ratio based on the browser\'s regular font size (which is mostly 16px) is used.'),
32
  );
33
  $form['font']['base_font_family'] = array(
34
    '#type' => 'select',
35
    '#title' => t('Base font family'),
36
    '#default_value' => theme_get_setting('base_font_family'),
37
    '#options' => array(
38
      0 => t('Serif: Georgia, Palatino Linotype, Book Antiqua, URW Palladio L, Baskerville, serif'),
39
      1 => t('Sans-Serif: Verdana, Geneva, Arial, Bitstream Vera Sans, DejaVu Sans, sans-serif'),
40
      2 => t('Custom'),
41
    ),
42
    '#description' => t('Font used for most part of the contents.'),
43
  );
44
  $form['font']['base_custom_font_family'] = array(
45
    '#type' => 'textfield',
46
    '#title' => t('Custom base font family'),
47
    '#default_value' => theme_get_setting('base_custom_font_family'),
48
    '#size' => 80,
49
    '#description' => t('Enter the base font-family you want to use. No need to start with <b>font-family:</b> and end with <b>;</b>. Just enter comma separated font names.'),
50
    '#prefix' => '<div id="base-custom-font-family-wrapper">',
51
    '#suffix' => '</div>',
52
  );
53
  $form['font']['heading_font_family'] = array(
54
    '#type' => 'select',
55
    '#title' => t('Heading font family (except for the site name and slogan)'),
56
    '#default_value' => theme_get_setting('heading_font_family'),
57
    '#options' => array(
58
      0 => t('Serif: Georgia, Palatino Linotype, Book Antiqua, URW Palladio L, Baskerville, serif'),
59
      1 => t('Sans-Serif: Verdana, Geneva, Arial, Bitstream Vera Sans, DejaVu Sans, sans-serif'),
60
      2 => t('Custom'),
61
    ),
62
    '#description' => t('Font used for the headings (h1, h2, h3, h4, h5). Font used for the site name and slogan can not be changed here. If you want to change it, please manually edit style.css in the theme\'s css subdirectory.'),
63
  );
64
  $form['font']['heading_custom_font_family'] = array(
65
    '#type' => 'textfield',
66
    '#title' => t('Custom heading font family'),
67
    '#default_value' => theme_get_setting('heading_custom_font_family'),
68
    '#size' => 80,
69
    '#description' => t('Enter the font-family you want to use for the headings. No need to start with <b>font-family:</b> and end with <b>;</b>. Just enter comma separated font names.'),
70
    '#prefix' => '<div id="heading-custom-font-family-wrapper">',
71
    '#suffix' => '</div>',
72
  );
73

    
74
  /*--------------- Layout settings --------------*/
75
  $form['layout'] = array(
76
    '#type' => 'fieldset',
77
    '#title' => t('Layout settings'),
78
    '#collapsed' => TRUE,
79
    '#collapsible' => TRUE,
80
  );
81
  $form['layout']['base_vmargin'] = array(
82
    '#type' => 'textfield',
83
    '#title' => t('Base vertical (top/bottom) margin'),
84
    '#default_value' => theme_get_setting('base_vmargin'),
85
    '#size' => 12,
86
    '#maxlength' => 8,
87
    '#description' => t('Specify the base vertical (top/bottom) margin which is vertical spaces between page edge and browser screen in px.'),
88
    '#prefix' => '<img src="/' . drupal_get_path('theme', 'mayo') . '/images/base-layout.png" /><br />',
89
  );
90
  $form['layout']['page_width'] = array(
91
    '#type' => 'textfield',
92
    '#title' => t('Page width'),
93
    '#default_value' => theme_get_setting('page_width'),
94
    '#size' => 12,
95
    '#maxlength' => 8,
96
    '#description' => t('Specify the page width including sidebars either in percent ratio (50-100%) for liquid layout, or in px (700-1600px) for fixed layout. If an invalid value is specified, the default value (90%) is used instead. You can leave this field blank to use the default value. Do not forget to add either % or px after the number.'),
97
    '#element_validate' => array('mayo_page_width_validate'),
98
  );
99
  $form['layout']['page_margin'] = array(
100
    '#type' => 'textfield',
101
    '#title' => t('Page margin'),
102
    '#default_value' => theme_get_setting('page_margin'),
103
    '#size' => 12,
104
    '#maxlength' => 8,
105
    '#description' => t('Specify the page margin which is spaces between page edge and contents in px.'),
106
  );
107
  $form['layout']['layout_style'] = array(
108
    '#type' => 'radios',
109
    '#title' => t('Layout style'),
110
    '#default_value' => theme_get_setting('layout_style'),
111
    '#options' => array(
112
      1 => t('1. Apply page margin to all (header, footer and main contents).'),
113
      2 => t('2. Apply page margin to main contents only.'),
114
    ),
115
    '#description' => '<img src="/' . drupal_get_path('theme', 'mayo') . '/images/page-layout.png" /><br />' . t('When the layout 2 is selected, or header background image is selected, header borders are not drawn to make it looks better.'),
116
  );
117

    
118
  /*--------------- Advanced sidebar settings --------------*/
119
  $form['layout']['sidebar'] = array(
120
    '#type' => 'fieldset',
121
    '#title' => t('Sidebar layout settings'),
122
    '#collapsible' => TRUE,
123
    '#collapsed' => TRUE,
124
  );
125
  $form['layout']['sidebar']['sidebar_layout_style'] = array(
126
    '#type' => 'radios',
127
    '#title' => t('Sidebar layout style'),
128
    '#default_value' => theme_get_setting('sidebar_layout_style'),
129
    '#options' => array(
130
      1 => t('1. Sidebar first comes left, sidebar second comes right.'),
131
      2 => t('2. Both sidebars come left.'),
132
      3 => t('3. Both sidebars come right.'),
133
    ),
134
    '#prefix' => '<img src="/' . drupal_get_path('theme', 'mayo') . '/images/sidebar-layout.png" />',
135
  );
136
  $form['layout']['sidebar']['sidebar_first_width'] = array(
137
    '#type' => 'textfield',
138
    '#title' => t('Sidebar first width'),
139
    '#default_value' => theme_get_setting('sidebar_first_width'),
140
    '#size' => 12,
141
    '#maxlength' => 8,
142
    '#description' => t('Specify the width of the sidebar first in % (15-40%). px value can not be used.'),
143
    '#element_validate' => array('mayo_sidebar_width_validate'),
144
  );
145
  $form['layout']['sidebar']['sidebar_second_width'] = array(
146
    '#type' => 'textfield',
147
    '#title' => t('Sidebar second width'),
148
    '#default_value' => theme_get_setting('sidebar_second_width'),
149
    '#size' => 12,
150
    '#maxlength' => 8,
151
    '#description' => t('Specify the width of the sidebar first in % (15-40%). px value can not be used.'),
152
    '#element_validate' => array('mayo_sidebar_width_validate'),
153
  );
154
  $form['layout']['sidebar']['note'] = array(
155
    '#type' => 'item',
156
    '#title' => t('Note:'),
157
    '#markup' => t('Main contents width is automatically determined based on the width of the sidebar and number of sidebar used.'),
158
  );
159

    
160

    
161
  /*--------------- Style settings --------------*/
162
  $form['style'] = array(
163
    '#type' => 'fieldset',
164
    '#title' => t('Style settings'),
165
    '#collapsible' => TRUE,
166
    '#collapsed' => TRUE,
167
  );
168
  $form['style']['round_corners'] = array(
169
    '#type' => 'select',
170
    '#title' => t('Content box round corners'),
171
    '#default_value' => theme_get_setting('round_corners'),
172
    '#description' => t('Make the corner of sidebar block and/or node rounded.<br/><b>Note:</b> This feature does not work with IE. Currently, it works with Safari, Firefox, Opera, Google Chrome.'),
173
    '#options' => array(
174
      0 => t('No round corners'),
175
      1 => t('Sidebar block only'),
176
      2 => t('Node only'),
177
      3 => t('Both sidebar block and node'),
178
    ),
179
    '#suffix' => '<img src="/' . drupal_get_path('theme', 'mayo') . '/images/round-corners.png" /><br />',
180
  );
181

    
182
  $form['style']['menubar_style'] = array(
183
    '#type' => 'radios',
184
    '#title' => t('Menubar style'),
185
    '#default_value' => theme_get_setting('menubar_style'),
186
    '#options' => array(
187
      1 => t('1. Normal (based on the colors specified by the color set)'),
188
      2 => t('2. Gloss black image background.'),
189
    ),
190
    '#suffix' => '<img src="/' . drupal_get_path('theme', 'mayo') . '/images/menubar-type.png" />',
191
  );
192
  $form['style']['note'] = array(
193
    '#type' => 'item',
194
    '#title' => t('Note:'),
195
    '#markup' => t('When the menubar type 2 is selected, the menu text color, menu highlight color, menu divier color from the color set are ignored and the fixed colors that match to the menubar are used instead.  Besides, highlight color and menu divider color from the color set are still used for other places such as tabs and sub-menubar for superfish and nice_menus menu.'),
196
  );
197

    
198
  /*--------------- Advanced header settings --------------*/
199
  $form['adv_header'] = array(
200
    '#type' => 'fieldset',
201
    '#title' => t('Advanced header settings'),
202
    '#collapsible' => TRUE,
203
    '#collapsed' => TRUE,
204
  );
205
  $form['adv_header']['header_searchbox'] = array(
206
    '#type' => 'checkbox',
207
    '#title' => t('Add search form to the header'),
208
    '#default_value' => theme_get_setting('header_searchbox'),
209
    '#description' => t('Check here if you want to add search form block to the right side of the header.'),
210
  );
211
  $form['adv_header']['header_fontsizer'] = array(
212
    '#type' => 'checkbox',
213
    '#title' => t('Add font resizing controls'),
214
    '#default_value' => theme_get_setting('header_fontsizer'),
215
    '#description' => t('Check here if you want to add font resizing controls at side of the header.'),
216
  );
217
  $form['adv_header']['header_height'] = array(
218
    '#type' => 'textfield',
219
    '#title' => t('Header height'),
220
    '#default_value' => theme_get_setting('header_height'),
221
    '#size' => 12,
222
    '#maxlength' => 8,
223
    '#description' => t('Specify the header height in px.'),
224
    '#prefix' => '<img src="/' . drupal_get_path('theme', 'mayo') . '/images/header-layout.png" /><br />',
225
  );
226
  $form['adv_header']['header_border_width'] = array(
227
    '#type' => 'textfield',
228
    '#title' => t('Header border width'),
229
    '#default_value' => theme_get_setting('header_border_width'),
230
    '#size' => 12,
231
    '#maxlength' => 8,
232
    '#description' => t('Specify the header border width in px. Note that header border is not drawn when you use header background image or when you use layout style 2.'),
233
  );
234
  $form['adv_header']['logo_left_margin'] = array(
235
    '#type' => 'textfield',
236
    '#title' => t('Logo left margin'),
237
    '#default_value' => theme_get_setting('logo_left_margin'),
238
    '#size' => 12,
239
    '#maxlength' => 8,
240
    '#description' => t('Specify the left margin of the logo in px. This setting is used only when the logo option is enabled.'),
241
  );
242
  $form['adv_header']['logo_top_margin'] = array(
243
    '#type' => 'textfield',
244
    '#title' => t('Logo top margin'),
245
    '#default_value' => theme_get_setting('logo_top_margin'),
246
    '#size' => 12,
247
    '#maxlength' => 8,
248
    '#description' => t('Specify the top margin of the logo in px. This setting is used only when the logo option is enabled.'),
249
  );
250
  $form['adv_header']['sitename_left_margin'] = array(
251
    '#type' => 'textfield',
252
    '#title' => t('Site name left margin'),
253
    '#default_value' => theme_get_setting('sitename_left_margin'),
254
    '#size' => 12,
255
    '#maxlength' => 8,
256
    '#description' => t('Specify the left margin of the site name in px. This setting is used only when the sitename option is enabled.'),
257
  );
258
  $form['adv_header']['sitename_top_margin'] = array(
259
    '#type' => 'textfield',
260
    '#title' => t('Site name top margin'),
261
    '#default_value' => theme_get_setting('sitename_top_margin'),
262
    '#size' => 12,
263
    '#maxlength' => 8,
264
    '#description' => t('Specify the top margin of the site name in px. This setting is used only when the sitename option is enabled.'),
265
  );
266
  $form['adv_header']['searchbox_right_margin'] = array(
267
    '#type' => 'textfield',
268
    '#title' => t('Search form right margin'),
269
    '#default_value' => theme_get_setting('searchbox_right_margin'),
270
    '#size' => 12,
271
    '#maxlength' => 8,
272
    '#description' => t('Specify the right margin of the search form in px. This setting is used only when the header search form option is enabled.'),
273
  );
274
  $form['adv_header']['searchbox_top_margin'] = array(
275
    '#type' => 'textfield',
276
    '#title' => t('Search form top margin'),
277
    '#default_value' => theme_get_setting('searchbox_top_margin'),
278
    '#size' => 12,
279
    '#maxlength' => 8,
280
    '#description' => t('Specify the right margin of the search form in px. This setting is used only when the header search form option is enabled.'),
281
  );
282
  $form['adv_header']['searchbox_size'] = array(
283
    '#type' => 'textfield',
284
    '#title' => t('Search form textfield width'),
285
    '#default_value' => theme_get_setting('searchbox_size'),
286
    '#size' => 10,
287
    '#maxlength' => 6,
288
    '#description' => t('Specify the width of the text field of the search forms in characters. This size is also applied for the search form in a block. NOTE: do not add px since this is not px size.'),
289
  );
290
  $form['adv_header']['header_bg_file'] = array(
291
    '#type' => 'textfield',
292
    '#title' => t('URL of the header background image'),
293
    '#default_value' => theme_get_setting('header_bg_file'),
294
    '#description' => t('If the background image is bigger than the header area, it is clipped. If it\'s smaller than the header area, it is tiled to fill the header area. To remove the background image, blank this field and save the settings.'),
295
    '#size' => 40,
296
    '#maxlength' => 120,
297
  );
298
  $form['adv_header']['header_bg'] = array(
299
    '#type' => 'file',
300
    '#title' => t('Upload header background image'),
301
    '#size' => 40,
302
    '#attributes' => array('enctype' => 'multipart/form-data'),
303
    '#description' => t('If you don\'t jave direct access to the server, use this field to upload your header background image'),
304
    '#element_validate' => array('mayo_header_bg_validate'),
305
  );
306
  $form['adv_header']['header_bg_alignment'] = array(
307
    '#type' => 'select',
308
    '#title' => t('Header backgeround image alignment'),
309
    '#default_value' => theme_get_setting('header_bg_alignment'),
310
    '#description' => t('Select the alignment of the header background image.'),
311
    '#options' => array(
312
      'top left' => t('Top left'),
313
      'top center' => t('Top center'),
314
      'top right' => t('Top right'),
315
      'center left' => t('Center left'),
316
      'center center' => t('Center center'),
317
      'center right' => t('Center right'),
318
      'bottom left' => t('Bottom left'),
319
      'bottom center' => t('Bottom center'),
320
      'bottom right' => t('Bottom right'),
321
    ),
322
  );
323
  $form['adv_header']['header_watermark'] = array(
324
    '#type' => 'select',
325
    '#title' => t('Header watermark'),
326
    '#default_value' => theme_get_setting('header_watermark'),
327
    '#description' => t('Select the watermark you want from the list below. The sample below is scaled down and the actual size of the watermark is bigger.'),
328
    '#options' => array(
329
      0 => t('-None-'),
330
      1 => t('Pixture'),
331
      2 => t('Wave'),
332
      3 => t('Bubble'),
333
      4 => t('Flower'),
334
      5 => t('Star'),
335
      6 => t('Metal'),
336
    ),
337
    '#suffix' => '<img src="/' . drupal_get_path('theme', 'mayo') . '/images/watermark-sample.png" /><br />',
338
  );
339

    
340
  /*--------------- Misellanenous settings --------------*/
341
  $form['misc'] = array(
342
    '#type' => 'fieldset',
343
    '#title' => t('Miscellaneous settings'),
344
    '#collapsible' => TRUE,
345
    '#collapsed' => TRUE,
346
  );
347
  $form['misc']['display_breadcrumb'] = array(
348
    '#type' => 'checkbox',
349
    '#title' => t('Display breadcrumb'),
350
    '#default_value' => theme_get_setting('display_breadcrumb'),
351
    '#description' => t('Check here if you want to display breadcrumb.'),
352
  );
353
  $form['misc']['dark_messages'] = array(
354
    '#type' => 'checkbox',
355
    '#title' => t('Use dark message colors'),
356
    '#default_value' => theme_get_setting('dark_messages'),
357
    '#description' => t('Check here if you use the dark color set. Colors for the status/warning/error messages are adjusted.'),
358
  );
359

    
360
}
361

    
362
/**
363
 * Check and save the uploaded header background image
364
 */
365
function mayo_header_bg_validate($element, &$form_state) {
366
  global $base_url;
367

    
368
  $validators = array('file_validate_is_image' => array());
369
  $file = file_save_upload('header_bg', $validators, "public://", FILE_EXISTS_REPLACE);
370

    
371
  if ($file) {
372
    // change file's status from temporary to permanent and update file database
373
    $file->status = FILE_STATUS_PERMANENT;
374
    file_save($file);
375

    
376
    $file_url = file_create_url($file->uri);
377
    $file_url = str_ireplace($base_url, '', $file_url);
378

    
379
    // set to form
380
    $form_state['values']['header_bg_file'] = $file_url;
381
  }
382
}
383

    
384
/**
385
 * Validate page width
386
 */
387
function mayo_page_width_validate($element, &$form_state) {
388
  if (!empty($element['#value'])) {
389
    $width = $element['#value'];
390

    
391
    // check if it is liquid (%) or fixed width (px)
392
    if(preg_match("/(\d+)\s*%/", $width, $match)) {
393
      $num = intval($match[0]);
394
      if(50 <= $num && $num <= 100) {
395
        return;
396
      }
397
      else {
398
        form_error($element, t('The width for the liquid layout must be a value between 50% and 100%.'));
399
      }
400
    }
401
    else if(preg_match("/(\d+)\s*px/", $width, $match)) {
402
      $num = intval($match[0]);
403
      if(700 <= $num && $num < 1600) {
404
        return;
405
      }
406
      else {
407
        form_error($element, t('The width for the fixed layout must be a value between 700px and 1600px.'));
408
      }
409
    }
410
  }
411
}
412

    
413
/**
414
 * Validate sidebar width
415
 */
416
function mayo_sidebar_width_validate($element, &$form_state) {
417
  if (!empty($element['#value'])) {
418
    $width = $element['#value'];
419

    
420
    // check if it is liquid (%) or fixed width (px)
421
    if(preg_match("/(\d+)\s*%/", $width, $match)) {
422
      $num = intval($match[0]);
423
      if(15 <= $num && $num <= 40) {
424
        return;
425
      }
426
      else {
427
        form_error($element, t('The width of the sidebar must be a value between 15% and 40%.'));
428
      }
429
    }
430
    else if(preg_match("/(\d+)\s*px/", $width, $match)) {
431
      form_error($element, t('The width of the sidebar must be a value between 15% and 40%. Do not forget to add % character.'));
432
    }
433
  }
434
}