Projet

Général

Profil

Paste
Télécharger (42,9 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / themes / mayo / theme-settings.php @ 2734bffc

1
<?php
2
/**
3
 * @file
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
    global $base_url;
10
  drupal_add_js(drupal_get_path('theme', 'mayo') . '/js/mayo.js');
11
    // Get our plugin system functions.
12
  require_once(drupal_get_path('theme', 'mayo') . '/inc/plugins.inc');
13

    
14
  // We need some getters.
15
  require_once(drupal_get_path('theme', 'mayo') . '/inc/get.inc');
16

    
17
  // General "alters" use a form id. Settings should not be set here. The only
18
  // thing useful about this is if you need to alter the form for the running
19
  // theme and *not* the theme setting.
20
  // @see http://drupal.org/node/943212
21
  if (isset($form_id)) {
22
    return;
23
  }
24

    
25
  // Get an array of device groups with option values
26
  $device_group_options = page_layouts_device_group_options('mayo');
27

    
28
  // Unit options
29
  $unit_options = array('%' => '%', 'px' => 'px', 'em' => 'em');
30

    
31
  // Assign $options for each device group
32
  foreach ($device_group_options as $device_group => $options) {
33

    
34
    // About here we need to call a custom sort function, this is what we got for now
35
    sort($options, SORT_STRING);
36

    
37
    foreach ($options as $option) {
38
      if ($device_group === 'bigscreen') {
39
        $bigscreen_options[$option] = drupal_ucfirst(str_replace('_', ' ', $option)); // human readable option names for accessibility
40
      }
41
      if ($device_group === 'tablet_landscape') {
42
        $tablet_landscape_options[$option] = drupal_ucfirst(str_replace('_', ' ', $option));
43
      }
44
      if ($device_group === 'tablet_portrait') {
45
        $tablet_portrait_options[$option] = drupal_ucfirst(str_replace('_', ' ', $option));
46
      }
47
      if ($device_group === 'smalltouch_landscape') {
48
        $smalltouch_landscape_options[$option] = drupal_ucfirst(str_replace('_', ' ', $option));
49
      }
50
    }
51
  }
52

    
53
  /* --------------- Font settings -------------- */
54
  $form['font'] = array(
55
    '#type' => 'fieldset',
56
    '#title' => t('Font settings'),
57
    '#collapsed' => TRUE,
58
    '#collapsible' => TRUE,
59
  );
60
  $form['font']['base_font_size'] = array(
61
    '#type' => 'select',
62
    '#title' => t('Base font size'),
63
    '#default_value' => theme_get_setting('base_font_size'),
64
    '#options' => array(
65
      '75%'    => '75% (=12px)',
66
      '81.25%' => '81.25% (=13px)',
67
      '87.5%'  => '87.5% (=14px)',
68
      '93.75%' => '93.75% (=15px)',
69
      '100%'   => '100% (=16px)',
70
      '112.5%' => '112.5% (=18px)'
71
    ),
72
    '#description' => t('To support text size enlargement/reduction, percent ratio based on the browser\'s regular font size (which is mostly 16px) is used.'),
73
  );
74
  $form['font']['base_font_family'] = array(
75
    '#type' => 'select',
76
    '#title' => t('Base font family'),
77
    '#default_value' => theme_get_setting('base_font_family'),
78
    '#options' => array(
79
      0 => t('Serif: Georgia, Palatino Linotype, Book Antiqua, URW Palladio L, Baskerville, serif'),
80
      1 => t('Sans-Serif: Verdana, Geneva, Arial, Bitstream Vera Sans, DejaVu Sans, sans-serif'),
81
      2 => t('Custom'),
82
    ),
83
    '#description' => t('Font used for most part of the contents.'),
84
  );
85
  $form['font']['base_custom_font_family'] = array(
86
    '#type' => 'textfield',
87
    '#title' => t('Custom base font family'),
88
    '#default_value' => theme_get_setting('base_custom_font_family'),
89
    '#size' => 80,
90
    '#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.'),
91
    '#prefix' => '<div id="base-custom-font-family-wrapper">',
92
    '#suffix' => '</div>',
93
  );
94
  $form['font']['heading_font_family'] = array(
95
    '#type' => 'select',
96
    '#title' => t('Heading font family (except for the site name and slogan)'),
97
    '#default_value' => theme_get_setting('heading_font_family'),
98
    '#options' => array(
99
      0 => t('Serif: Georgia, Palatino Linotype, Book Antiqua, URW Palladio L, Baskerville, serif'),
100
      1 => t('Sans-Serif: Verdana, Geneva, Arial, Bitstream Vera Sans, DejaVu Sans, sans-serif'),
101
      2 => t('Custom'),
102
    ),
103
    '#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.'),
104
  );
105
  $form['font']['heading_custom_font_family'] = array(
106
    '#type' => 'textfield',
107
    '#title' => t('Custom heading font family'),
108
    '#default_value' => theme_get_setting('heading_custom_font_family'),
109
    '#size' => 80,
110
    '#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.'),
111
    '#prefix' => '<div id="heading-custom-font-family-wrapper">',
112
    '#suffix' => '</div>',
113
  );
114

    
115
  /* --------------- Layout settings -------------- */
116
  $form['layout'] = array(
117
    '#type' => 'fieldset',
118
    '#title' => t('Layout settings'),
119
    '#collapsed' => TRUE,
120
    '#collapsible' => TRUE,
121
  );
122
  $form['layout']['base_vmargin'] = array(
123
    '#type' => 'textfield',
124
    '#title' => t('Base vertical (top/bottom) margin'),
125
    '#default_value' => theme_get_setting('base_vmargin'),
126
    '#size' => 12,
127
    '#maxlength' => 8,
128
    '#description' => t('Specify the base vertical (top/bottom) margin which is vertical spaces between page edge and browser screen in px.'),
129
    '#prefix' => '<img src="' . file_create_url(drupal_get_path('theme', 'mayo') . '/images/base-layout.png') . '" /><br />',
130
  );
131
  $form['layout']['page_margin'] = array(
132
    '#type' => 'textfield',
133
    '#title' => t('Page margin'),
134
    '#default_value' => theme_get_setting('page_margin'),
135
    '#size' => 12,
136
    '#maxlength' => 8,
137
    '#description' => t('Specify the page margin which is spaces between page edge and contents in px.'),
138
  );
139
  $form['layout']['layout_style'] = array(
140
    '#type' => 'radios',
141
    '#title' => t('Layout style'),
142
    '#default_value' => theme_get_setting('layout_style'),
143
    '#options' => array(
144
      1 => t('1. Apply page margin to all (header, footer and main contents).'),
145
      2 => t('2. Apply page margin to main contents only.'),
146
    ),
147
    '#description' => '<img src="' . file_create_url(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 look better.'),
148
  );
149

    
150
  /* --------------- Responsive sidebar layout settings -------------- */
151
  /* -----------Big screen as in desktop pc monitor------------- */
152
  $form['layout']['bigscreen'] = array(
153
    '#type' => 'fieldset',
154
    '#title' => t('Big Screen Sidebar layout'),
155
    '#collapsible' => TRUE,
156
    '#collapsed' => TRUE,
157
    '#attributes' => array(
158
      'class' => array('mayo-layout-form'),
159
    ),
160
  );
161

    
162
    // Big screen Layout
163
  $form['layout']['bigscreen']['bigscreen-layout-wrapper'] = array(
164
    '#type' => 'fieldset',
165
    '#title' => t('Choose sidebar layout'),
166
  );
167
    // Options
168

    
169
  $form['layout']['bigscreen']['bigscreen-layout-wrapper']['bigscreen_layout'] = array(
170
     '#type' => 'radios',
171
     '#title' => t('<strong>Choose sidebar positions</strong>'),
172
     '#default_value' => str_replace('-', '_', theme_get_setting('bigscreen_layout')),
173
     '#options' => $bigscreen_options,
174
  );
175

    
176
  // Sidebars
177
  $form['layout']['bigscreen']['bigscreen-sidebar-wrapper'] = array(
178
    '#type' => 'fieldset',
179
    '#title' => t('Set sidebar widths'),
180
    '#description' => t('<strong>Set the width of each sidebar</strong>'),
181
    '#collapsible' => FALSE,
182
  );
183

    
184
  // Units
185
  $form['layout']['bigscreen']['bigscreen-sidebar-wrapper']['bigscreen_sidebar_unit'] = array(
186
    '#type' => 'select',
187
    '#title' => t('Unit'),
188
    '#default_value' => theme_get_setting('bigscreen_sidebar_unit'),
189
    '#options' => $unit_options,
190
  );
191

    
192
  // Sidebar first
193
  $form['layout']['bigscreen']['bigscreen-sidebar-wrapper']['bigscreen_sidebar_first'] = array(
194
    '#type' => 'textfield',
195
    '#title' => t('First sidebar'),
196
    '#default_value' => check_plain(theme_get_setting('bigscreen_sidebar_first')),
197
    '#size' => 4,
198
    '#maxlenght' => 4,
199
    '#states' => array(
200
      'required' => array(
201
        array('input[name="bigscreen_layout"]' => array('value' => 'three_col_grail')),
202
        array('input[name="bigscreen_layout"]' => array('value' => 'two_sidebars_left')),
203
        array('input[name="bigscreen_layout"]' => array('value' => 'two_sidebars_right')),
204
      ),
205
    ),
206
  );
207

    
208
  // Sidebar second
209
  $form['layout']['bigscreen']['bigscreen-sidebar-wrapper']['bigscreen_sidebar_second'] = array(
210
    '#type' => 'textfield',
211
    '#title' => t('Second sidebar'),
212
    '#default_value' => check_plain(theme_get_setting('bigscreen_sidebar_second')),
213
    '#size' => 4,
214
    '#maxlenght' => 4,
215
    '#states' => array(
216
      'required' => array(
217
        array('input[name="bigscreen_layout"]' => array('value' => 'three_col_grail')),
218
        array('input[name="bigscreen_layout"]' => array('value' => 'two_sidebars_left')),
219
        array('input[name="bigscreen_layout"]' => array('value' => 'two_sidebars_right')),
220
      ),
221
    ),
222
  );
223

    
224
  // Page width
225
  $form['layout']['bigscreen']['bigscreen-width-wrapper'] = array(
226
    '#type' => 'fieldset',
227
    '#title' => t('Set the page width'),
228
    '#description' => t('<strong>Set the page width</strong>'),
229
  );
230

    
231
  // Unit
232
  $form['layout']['bigscreen']['bigscreen-width-wrapper']['bigscreen_page_unit'] = array(
233
    '#type' => 'select',
234
    '#title' => t('Unit'),
235
    '#default_value' => theme_get_setting('bigscreen_page_unit'),
236
    '#options' => $unit_options,
237
  );
238

    
239
  // Width
240
  $form['layout']['bigscreen']['bigscreen-width-wrapper']['bigscreen_page_width'] = array(
241
    '#type'  => 'textfield',
242
    '#title' => t('Page width'),
243
    '#default_value' => check_plain(theme_get_setting('bigscreen_page_width')),
244
    '#size' => 4,
245
    '#maxlenght' => 4,
246
    '#required' => TRUE,
247
  );
248

    
249
  // Media queries
250
  $form['layout']['bigscreen']['media-queries-wrapper'] = array(
251
    '#type' => 'fieldset',
252
    '#title' => t('Standard Screen Media Queries'),
253
    '#weight' => 1,
254
    '#attributes' => array(
255
      'class' => array('at-media-queries'),
256
    ),
257
  );
258

    
259
  // Media query
260
  $form['layout']['bigscreen']['media-queries-wrapper']['bigscreen_media_query'] = array(
261
    '#type' => 'textfield',
262
    '#title' => t('Media query for this layout'),
263
    '#default_value' => check_plain(theme_get_setting('bigscreen_media_query')),
264
    '#description' => t('Do not include @media, it\'s included automatically.'),
265
    '#size' => 100,
266
    '#required' => TRUE,
267
  );
268

    
269
  /* ****************************************************************************
270
   *
271
   * Tablet
272
   *
273
   * ************************************************************************** */
274

    
275
  $form['layout']['tablet'] = array(
276
    '#type' => 'fieldset',
277
    '#title' => t('Tablet Sidebar Layout'),
278
    '#description' => t('<h3>Tablet Layout</h3><p>Tablet devices such as iPad, Android and Windows tablets have two orientations - landscape and portrait, which can also be thought of as wide and narrow tablets. You can configure a different layout for each orientation.</p>'),
279
    '#attributes' => array(
280
      'class' => array('mayo-layout-form'),
281
    ),
282
    '#collapsible' => TRUE,
283
    '#collapsed' => TRUE,
284
  );
285

    
286
  /* ******************
287
   * Tablet landscape
288
   * **************** */
289

    
290
  $form['layout']['tablet']['landscape'] = array(
291
    '#type' => 'fieldset',
292
    '#title' => t('Landscape'),
293
    '#description' => t('<h4>Landscape tablet <span class="field-description-info">(wide)</span></h4>'),
294
    '#collapsible' => TRUE,
295
    '#collapsed' => TRUE,
296
  );
297

    
298
  // Tablet landscape Layout options
299
  $form['layout']['tablet']['landscape']['tablet-landscape-layout-wrapper'] = array(
300
    '#type' => 'fieldset',
301
    '#title' => t('Choose sidebar layout'),
302
  );
303

    
304
  // Options
305
  $form['layout']['tablet']['landscape']['tablet-landscape-layout-wrapper']['tablet_landscape_layout'] = array(
306
    '#type' => 'radios',
307
    '#title' => t('<strong>Choose sidebar positions</strong>'),
308
    '#default_value' => str_replace('-', '_', theme_get_setting('tablet_landscape_layout')),
309
    '#options' => $tablet_landscape_options,
310
  );
311

    
312
  // Sidebars
313
  $form['layout']['tablet']['landscape']['tablet-landscape-sidebar-width-wrapper'] = array(
314
    '#type' => 'fieldset',
315
    '#title' => t('Set sidebar widths'),
316
    '#description' => t('<strong>Set the width of each sidebar</strong>'),
317
  );
318

    
319
  // Units
320
  $form['layout']['tablet']['landscape']['tablet-landscape-sidebar-width-wrapper']['tablet_landscape_sidebar_unit'] = array(
321
    '#type' => 'select',
322
    '#title' => t('Unit'),
323
    '#default_value' => theme_get_setting('tablet_landscape_sidebar_unit'),
324
    '#options' => $unit_options,
325
  );
326

    
327
  // Sidebar first
328
  $form['layout']['tablet']['landscape']['tablet-landscape-sidebar-width-wrapper']['tablet_landscape_sidebar_first'] = array(
329
    '#type' => 'textfield',
330
    '#title' => t('First sidebar'),
331
    '#default_value' => check_plain(theme_get_setting('tablet_landscape_sidebar_first')),
332
    '#size' => 4,
333
    '#maxlenght' => 4,
334
    '#states' => array(
335
      'required' => array(
336
        array('input[name="tablet_landscape_layout"]' => array('value' => 'three_col_grail')),
337
        array('input[name="tablet_landscape_layout"]' => array('value' => 'two_sidebars_left')),
338
        array('input[name="tablet_landscape_layout"]' => array('value' => 'two_sidebars_left_stack')),
339
        array('input[name="tablet_landscape_layout"]' => array('value' => 'two_sidebars_right')),
340
        array('input[name="tablet_landscape_layout"]' => array('value' => 'two_sidebars_right_stack')),
341
      ),
342
    ),
343
  );
344

    
345
  // Sidebar second
346
  $form['layout']['tablet']['landscape']['tablet-landscape-sidebar-width-wrapper']['tablet_landscape_sidebar_second'] = array(
347
    '#type' => 'textfield',
348
    '#title' => t('Second sidebar'),
349
    '#default_value' => check_plain(theme_get_setting('tablet_landscape_sidebar_second')),
350
    '#size' => 4,
351
    '#maxlenght' => 4,
352
    '#states' => array(
353
      'invisible' => array(
354
        array('input[name="tablet_landscape_layout"]' => array('value' => 'two_sidebars_left_stack')),
355
        array('input[name="tablet_landscape_layout"]' => array('value' => 'two_sidebars_right_stack')),
356
      ),
357
      'required' => array(
358
        array('input[name="tablet_landscape_layout"]' => array('value' => 'three_col_grail')),
359
        array('input[name="tablet_landscape_layout"]' => array('value' => 'two_sidebars_left')),
360
        array('input[name="tablet_landscape_layout"]' => array('value' => 'two_sidebars_right')),
361
      ),
362
    ),
363
  );
364

    
365
  // Conditional messages for sidebar layouts
366
  $form['layout']['tablet']['landscape']['tablet-landscape-sidebar-width-wrapper']['tablet-landscape-sidebar-message-wrapper'] = array(
367
    '#type' => 'fieldset',
368
    '#states' => array(
369
      'invisible' => array(
370
        array('input[name="tablet_landscape_layout"]' => array('value' => 'three_col_grail')),
371
        array('input[name="tablet_landscape_layout"]' => array('value' => 'two_sidebars_left')),
372
        array('input[name="tablet_landscape_layout"]' => array('value' => 'two_sidebars_right')),
373
      ),
374
    ),
375
  );
376
  $form['layout']['tablet']['landscape']['tablet-landscape-sidebar-width-wrapper']['tablet-landscape-sidebar-message-wrapper']['message'] = array(
377
    '#markup' => t('<div class="description">In this layout <em>Second sidebar</em> wraps below.</div>'),
378
  );
379

    
380
  // Page width
381
  $form['layout']['tablet']['landscape']['tablet-landscape-page-width-wrapper'] = array(
382
    '#type' => 'fieldset',
383
    '#title' => t('Set the page width'),
384
    '#description' => t('<strong>Set the page width</strong>'),
385
  );
386

    
387
  // Unit
388
  $form['layout']['tablet']['landscape']['tablet-landscape-page-width-wrapper']['tablet_landscape_page_unit'] = array(
389
    '#type' => 'select',
390
    '#title' => t('Unit'),
391
    '#default_value' => theme_get_setting('tablet_landscape_page_unit'),
392
    '#options' => $unit_options,
393
  );
394

    
395
  // Width
396
  $form['layout']['tablet']['landscape']['tablet-landscape-page-width-wrapper']['tablet_landscape_page_width'] = array(
397
    '#type'  => 'textfield',
398
    '#title' => t('Page width'),
399
    '#default_value' => check_plain(theme_get_setting('tablet_landscape_page_width')),
400
    '#size' => 4,
401
    '#maxlenght' => 4,
402
    '#required' => TRUE,
403
  );
404

    
405
  // Media Queries
406
  $form['layout']['tablet']['landscape']['tablet-landscape-media-queries-wrapper'] = array(
407
    '#type' => 'fieldset',
408
    '#title' => t('Tablet Landscape Media Queries'),
409
    '#weight' => 1,
410
    '#attributes' => array(
411
      'class' => array(
412
        'at-media-queries',
413
      ),
414
    ),
415
  );
416

    
417
  // Media query
418
  $form['layout']['tablet']['landscape']['tablet-landscape-media-queries-wrapper']['tablet_landscape_media_query'] = array(
419
    '#type' => 'textfield',
420
    '#title' => t('Media query for this layout'),
421
    '#default_value' => check_plain(theme_get_setting('tablet_landscape_media_query')),
422
    '#description' => t('Do not include @media, it\'s included automatically.'),
423
    '#size' => 100,
424
    '#required' => TRUE,
425
  );
426

    
427

    
428
  /* *****************
429
   * Tablet portrait
430
   * *************** */
431

    
432
  $form['layout']['tablet']['portrait'] = array(
433
    '#type' => 'fieldset',
434
    '#title' => t('Portrait'),
435
    '#description' => t('<h4>Portrait tablet <span class="field-description-info">(narrow)</span></h4>'),
436
    '#collapsible' => TRUE,
437
    '#collapsed' => TRUE,
438
  );
439

    
440
  // Tablet portrait Layout options
441
  $form['layout']['tablet']['portrait']['tablet-portrait-layout-wrapper'] = array(
442
    '#type' => 'fieldset',
443
    '#title' => t('Choose sidebar layout'),
444
  );
445

    
446
  // Options
447
  $form['layout']['tablet']['portrait']['tablet-portrait-layout-wrapper']['tablet_portrait_layout'] = array(
448
    '#type' => 'radios',
449
    '#title' => t('<strong>Choose sidebar positions</strong>'),
450
    '#default_value' => str_replace('-', '_', theme_get_setting('tablet_portrait_layout')),
451
    '#options' => $tablet_portrait_options,
452
  );
453

    
454
  // Tablet portrait Sidebars
455
  $form['layout']['tablet']['portrait']['tablet-portrait-sidebar-width-wrapper'] = array(
456
    '#type' => 'fieldset',
457
    '#title' => t('Set sidebar widths'),
458
    '#description' => t('<strong>Set the width of each sidebar</strong>'),
459
    '#states' => array(
460
      'invisible' => array('input[name="tablet_portrait_layout"]' => array('value' => 'one_col_stack')),
461
    ),
462
  );
463

    
464
  // Units
465
  $form['layout']['tablet']['portrait']['tablet-portrait-sidebar-width-wrapper']['tablet_portrait_sidebar_unit'] = array(
466
    '#type' => 'select',
467
    '#title' => t('Unit'),
468
    '#default_value' => theme_get_setting('tablet_portrait_sidebar_unit'),
469
    '#options' => $unit_options,
470
  );
471

    
472
  // Sidebar first
473
  $form['layout']['tablet']['portrait']['tablet-portrait-sidebar-width-wrapper']['tablet_portrait_sidebar_first'] = array(
474
    '#type' => 'textfield',
475
    '#title' => t('First sidebar'),
476
    '#default_value' => check_plain(theme_get_setting('tablet_portrait_sidebar_first')),
477
    '#size' => 4,
478
    '#maxlenght' => 4,
479
    '#states' => array(
480
      'invisible' => array(
481
        array('input[name="tablet_portrait_layout"]' => array('value' => 'one_col_stack')),
482
      ),
483
      'required' => array(
484
        array('input[name="tablet_portrait_layout"]' => array('value' => 'one_col_vert')),
485
        array('input[name="tablet_portrait_layout"]' => array('value' => 'two_sidebars_left_stack')),
486
        array('input[name="tablet_portrait_layout"]' => array('value' => 'two_sidebars_right_stack')),
487
      ),
488
    ),
489
  );
490

    
491
  // Sidebar second
492
  $form['layout']['tablet']['portrait']['tablet-portrait-sidebar-width-wrapper']['tablet_portrait_sidebar_second'] = array(
493
    '#type' => 'textfield',
494
    '#title' => t('Second sidebar'),
495
    '#default_value' => check_plain(theme_get_setting('tablet_portrait_sidebar_second')),
496
    '#size' => 4,
497
    '#maxlenght' => 4,
498
    '#states' => array(
499
      'invisible' => array(
500
        array('input[name="tablet_portrait_layout"]' => array('value' => 'one_col_stack')),
501
        array('input[name="tablet_portrait_layout"]' => array('value' => 'two_sidebars_left_stack')),
502
        array('input[name="tablet_portrait_layout"]' => array('value' => 'two_sidebars_right_stack')),
503
      ),
504
      'required' => array(
505
        array('input[name="tablet_portrait_layout"]' => array('value' => 'one_col_vert')),
506
      ),
507
    ),
508
  );
509

    
510
  // Conditional messages for sidebar layouts
511
  $form['layout']['tablet']['portrait']['tablet-portrait-sidebar-width-wrapper']['tablet-portrait-sidebar-message-wrapper'] = array(
512
    '#type' => 'fieldset',
513
    '#states' => array(
514
      'invisible' => array(
515
        array('input[name="tablet_portrait_layout"]' => array('value' => 'one_col_vert')),
516
        array('input[name="tablet_portrait_layout"]' => array('value' => 'one_col_stack')),
517
      ),
518
    ),
519
  );
520
  $form['layout']['tablet']['portrait']['tablet-portrait-sidebar-width-wrapper']['tablet-portrait-sidebar-message-wrapper']['message'] = array(
521
    '#markup' => t('<div class="description">In this layout <em>Second sidebar</em> wraps below.</div>'),
522
  );
523

    
524
  // Tablet portrait Page width
525
  $form['layout']['tablet']['portrait']['tablet-portrait-page-width-wrapper'] = array(
526
    '#type' => 'fieldset',
527
    '#title' => t('Set the page width'),
528
    '#description' => t('<strong>Set the page width</strong>'),
529
  );
530

    
531
  // Unit
532
  $form['layout']['tablet']['portrait']['tablet-portrait-page-width-wrapper']['tablet_portrait_page_unit'] = array(
533
    '#type' => 'select',
534
    '#title' => t('Unit'),
535
    '#default_value' => theme_get_setting('tablet_portrait_page_unit'),
536
    '#options' => $unit_options,
537
  );
538

    
539
  // Width
540
  $form['layout']['tablet']['portrait']['tablet-portrait-page-width-wrapper']['tablet_portrait_page_width'] = array(
541
    '#type'  => 'textfield',
542
    '#title' => t('Page width'),
543
    '#default_value' => check_plain(theme_get_setting('tablet_portrait_page_width')),
544
    '#size' => 4,
545
    '#maxlenght' => 4,
546
    '#required' => TRUE,
547
  );
548

    
549
  // Tablet portrait Media queries
550
  $form['layout']['tablet']['portrait']['tablet-portrait-media-queries-wrapper'] = array(
551
    '#type' => 'fieldset',
552
    '#title' => t('Tablet Portrait Media Queries'),
553
    '#weight' => 1,
554
    '#attributes' => array(
555
      'class' => array('at-media-queries'),
556
    ),
557
  );
558

    
559
  // Media query
560
  $form['layout']['tablet']['portrait']['tablet-portrait-media-queries-wrapper']['tablet_portrait_media_query'] = array(
561
    '#type' => 'textfield',
562
    '#title' => t('Media query for this layout'),
563
    '#default_value' => check_plain(theme_get_setting('tablet_portrait_media_query')),
564
    '#description' => t('Do not include @media, it\'s included automatically.'),
565
    '#size' => 100,
566
    '#required' => TRUE,
567
  );
568
  /* ****************************************************************************
569
   *
570
   * Smalltouch
571
   *
572
   * ************************************************************************** */
573

    
574
  $form['layout']['smalltouch'] = array(
575
    '#type' => 'fieldset',
576
    '#title' => t('Smalltouch Sidebar Layout'),
577
    '#description' => t('<h3>Smalltouch Layout</h3><p>Smalltouch devices such as iPhone, Android and Windows phones have two orientations - landscape and portrait, which can also be thought of as wide and arrow smalltouch devices. You can configure a layout for landscape orientation only - portrait orientation (narrow) will always display in one column (all regions full width and stacked) with sidebars below the main content.</p>'),
578
    '#attributes' => array(
579
      'class' => array('mayo-layout-form'),
580
    ),
581
    '#collapsible' => TRUE,
582
    '#collapsed' => TRUE,
583
  );
584

    
585
  /* **********************
586
   * Smalltouch landscape
587
   * ******************** */
588

    
589
  $form['layout']['smalltouch']['landscape'] = array(
590
    '#type' => 'fieldset',
591
    '#title' => t('Landscape'),
592
    '#description' => t('<h4>Landscape smalltouch <span class="field-description-info">(wide)</span></h4>'),
593
    '#collapsible' => TRUE,
594
    '#collapsed' => TRUE,
595
  );
596

    
597
  $form['layout']['smalltouch']['landscape']['smalltouch-landscape-layout-wrapper'] = array(
598
    '#type' => 'fieldset',
599
    '#title' => t('Choose sidebar layout'),
600
  );
601

    
602
  $form['layout']['smalltouch']['landscape']['smalltouch-landscape-layout-wrapper']['smalltouch_landscape_layout'] = array(
603
    '#type' => 'radios',
604
    '#title' => t('<strong>Choose sidebar positions</strong>'),
605
    '#default_value' => theme_get_setting('smalltouch_landscape_layout') ? str_replace('-', '_', theme_get_setting('smalltouch_landscape_layout')) : str_replace('-', '_', theme_get_setting('smartphone_landscape_layout')),
606
    '#options' => $smalltouch_landscape_options,
607
  );
608

    
609
  $form['layout']['smalltouch']['landscape']['smalltouch-landscape-sidebar-width-wrapper'] = array(
610
    '#type' => 'fieldset',
611
    '#title' => t('Set sidebar widths'),
612
    '#description' => t('<strong>Set the width of each sidebar</strong>'),
613
    '#states' => array(
614
      '!visible' => array('input[name="smalltouch_landscape_layout"]' => array('value' => 'one_col_stack')),
615
    ),
616
  );
617

    
618
  $form['layout']['smalltouch']['landscape']['smalltouch-landscape-sidebar-width-wrapper']['smalltouch_landscape_sidebar_unit'] = array(
619
    '#type' => 'select',
620
    '#title' => t('Unit'),
621
    '#default_value' => theme_get_setting('smalltouch_landscape_sidebar_unit') ? theme_get_setting('smalltouch_landscape_sidebar_unit') : theme_get_setting('smartphone_landscape_sidebar_unit'),
622
    '#options' => $unit_options,
623
  );
624

    
625
  $form['layout']['smalltouch']['landscape']['smalltouch-landscape-sidebar-width-wrapper']['smalltouch_landscape_sidebar_first'] = array(
626
    '#type' => 'textfield',
627
    '#title' => t('First sidebar'),
628
    '#default_value' => theme_get_setting('smalltouch_landscape_sidebar_first') ? check_plain(theme_get_setting('smalltouch_landscape_sidebar_first')) : check_plain(theme_get_setting('smartphone_landscape_sidebar_first')),
629
    '#size' => 4,
630
    '#maxlenght' => 4,
631
    '#states' => array(
632
      'required' => array('input[name="smalltouch_landscape_layout"]' => array('value' => 'one_col_vert')),
633
    ),
634
  );
635

    
636
  $form['layout']['smalltouch']['landscape']['smalltouch-landscape-sidebar-width-wrapper']['smalltouch_landscape_sidebar_second'] = array(
637
    '#type' => 'textfield',
638
    '#title' => t('Second sidebar'),
639
    '#default_value' => theme_get_setting('smalltouch_landscape_sidebar_second') ? check_plain(theme_get_setting('smalltouch_landscape_sidebar_second')) : check_plain(theme_get_setting('smartphone_landscape_sidebar_second')),
640
    '#size' => 4,
641
    '#maxlenght' => 4,
642
    '#states' => array(
643
      'required' => array('input[name="smalltouch_landscape_layout"]' => array('value' => 'one_col_vert')),
644
    ),
645
  );
646

    
647
  $form['layout']['smalltouch']['landscape']['smalltouch-landscape-media-queries-wrapper'] = array(
648
    '#type' => 'fieldset',
649
    '#title' => t('Smalltouch Landscape Media Queries'),
650
    '#weight' => 1,
651
    '#attributes' => array(
652
      'class' => array('at-media-queries'),
653
    ),
654
  );
655

    
656
  $form['layout']['smalltouch']['landscape']['smalltouch-landscape-media-queries-wrapper']['smalltouch_landscape_media_query'] = array(
657
    '#type' => 'textfield',
658
    '#title' => t('Media query for this layout'),
659
    '#default_value' => theme_get_setting('smalltouch_landscape_media_query') ? check_plain(theme_get_setting('smalltouch_landscape_media_query')) : check_plain(theme_get_setting('smartphone_landscape_media_query')),
660
    '#description' => t('Do not include @media, it\'s included automatically.'),
661
    '#size' => 100,
662
    //'#required' => TRUE,
663
  );
664

    
665
  // Pass hidden values to the sumbit function, these values are required but the user can't change them via the UI
666
  $form['layout']['smalltouch']['landscape']['hidden']['smalltouch_landscape_page_width'] = array(
667
    '#type' => 'hidden',
668
    '#default_value' => theme_get_setting('smalltouch_landscape_page_width') ? check_plain(theme_get_setting('smalltouch_landscape_page_width')) : check_plain(theme_get_setting('smartphone_landscape_page_width')),
669
  );
670
  $form['layout']['smalltouch']['landscape']['hidden']['smalltouch_landscape_page_unit'] = array(
671
    '#type' => 'hidden',
672
    '#default_value' => theme_get_setting('smalltouch_landscape_page_unit') ? theme_get_setting('smalltouch_landscape_page_unit') : theme_get_setting('smartphone_landscape_page_unit'),
673
  );
674

    
675
  /* *********************
676
   * Smalltouch portrait
677
   * ******************* */
678

    
679
  $form['layout']['smalltouch']['portrait'] = array(
680
    '#type' => 'fieldset',
681
    '#title' => t('Portrait'),
682
    '#description' => t('<h4>Portrait smalltouch <span class="field-description-info">(narrow)</span></h4><div class="smalltouch-portrait-layout">One column</div><p>The smalltouch portrait layout always displays in one column with sidebars stacked horizontally below the main content. All widths are always 100%.</p>'),
683
    '#collapsible' => TRUE,
684
    '#collapsed' => TRUE,
685
  );
686

    
687
  $form['layout']['smalltouch']['portrait']['smalltouch-portrait-media-queries-wrapper'] = array(
688
    '#type' => 'fieldset',
689
    '#title' => t('Smalltouch Portrait Media Queries'),
690
    '#weight' => 1,
691
    '#attributes' => array(
692
      'class' => array('at-media-queries'),
693
    ),
694
  );
695

    
696
  $form['layout']['smalltouch']['portrait']['smalltouch-portrait-media-queries-wrapper']['smalltouch_portrait_media_query'] = array(
697
    '#type' => 'textfield',
698
    '#title' => t('Media query for this layout'),
699
    '#default_value' => theme_get_setting('smalltouch_portrait_media_query') ? check_plain(theme_get_setting('smalltouch_portrait_media_query')) : check_plain(theme_get_setting('smartphone_portrait_media_query')),
700
    '#description' => t('Do not include @media, it\'s included automatically.'),
701
    '#size' => 100,
702
  );
703

    
704
  // Pass hidden values to the sumbit function, these values are required but the user can't change them via the UI
705
  $form['layout']['smalltouch']['portrait']['hidden']['smalltouch_portrait_page_width'] = array(
706
    '#type' => 'hidden',
707
    '#default_value' => theme_get_setting('smalltouch_portrait_page_width') ? check_plain(theme_get_setting('smalltouch_portrait_page_width')) : check_plain(theme_get_setting('smartphone_portrait_page_width')),
708
  );
709

    
710
  $form['layout']['smalltouch']['portrait']['hidden']['smalltouch_portrait_page_unit'] = array(
711
    '#type' => 'hidden',
712
    '#default_value' => theme_get_setting('smalltouch_portrait_page_unit') ? theme_get_setting('smalltouch_portrait_page_unit') : theme_get_setting('smartphone_portrait_page_unit'),
713
  );
714

    
715
  $form['layout']['smalltouch']['portrait']['hidden']['smalltouch_portrait_sidebar_first'] = array(
716
    '#type' => 'hidden',
717
    '#default_value' => theme_get_setting('smalltouch_portrait_sidebar_first') ? check_plain(theme_get_setting('smalltouch_portrait_sidebar_first')) : check_plain(theme_get_setting('smartphone_portrait_sidebar_first')),
718
  );
719

    
720
  $form['layout']['smalltouch']['portrait']['hidden']['smalltouch_portrait_sidebar_second'] = array(
721
    '#type' => 'hidden',
722
    '#default_value' => theme_get_setting('smalltouch_portrait_sidebar_second') ? check_plain(theme_get_setting('smalltouch_portrait_sidebar_second')) : check_plain(theme_get_setting('smartphone_portrait_sidebar_second')),
723
  );
724

    
725
  $form['layout']['smalltouch']['portrait']['hidden']['smalltouch_portrait_sidebar_unit'] = array(
726
    '#type' => 'hidden',
727
    '#default_value' => theme_get_setting('smalltouch_portrait_sidebar_unit') ? check_plain(theme_get_setting('smalltouch_portrait_sidebar_unit')) : check_plain(theme_get_setting('smartphone_portrait_sidebar_unit')),
728
  );
729

    
730
  $form['layout']['smalltouch']['portrait']['hidden']['smalltouch_portrait_layout'] = array(
731
    '#type' => 'hidden',
732
    '#default_value' => theme_get_setting('smalltouch_portrait_layout') ? str_replace('-', '_', theme_get_setting('smalltouch_portrait_layout')) : str_replace('-', '_', theme_get_setting('smartphone_portrait_layout')),
733
  );
734

    
735
   /* --------------- Style settings -------------- */
736
  $form['style'] = array(
737
    '#type' => 'fieldset',
738
    '#title' => t('Style settings'),
739
    '#collapsible' => TRUE,
740
    '#collapsed' => TRUE,
741
  );
742
  $form['style']['legacy_superfish_styles'] = array(
743
    '#type' => 'checkbox',
744
    '#title' => t('Use old legacy MAYO styles for Superfish.'),
745
    '#default_value' => theme_get_setting('legacy_superfish_styles'),
746
    '#description' => t('Check here if you want to add mayo-superfish.css.'),
747
  );
748
  $form['style']['superfish_note'] = array(
749
    '#type' => 'item',
750
    '#title' => t('Note:'),
751
    '#markup' => t('Use this only when coming from the older non-responsive versions of MAYO
752
     and your Superfish menu is broken without it. If you haven\'t been using Superfish or are
753
     installing MAYO for the first time you shouldn\'t need it and can leave it unchecked.'),
754
  );
755
  $form['style']['round_corners'] = array(
756
    '#type' => 'select',
757
    '#title' => t('Content box round corners'),
758
    '#default_value' => theme_get_setting('round_corners'),
759
    '#description' => t('Make the corner of sidebar block and/or node rounded.'),
760
    '#options' => array(
761
      'rc-0' => t('No round corners'),
762
      'rc-1' => t('Sidebar block only'),
763
      'rc-2' => t('Node only'),
764
      'rc-3' => t('Both sidebar block and node'),
765
    ),
766
    '#suffix' => '<img src="' . file_create_url(drupal_get_path('theme', 'mayo') . '/images/round-corners.png') . '" /><br />',
767
  );
768

    
769
  $form['style']['menubar_style'] = array(
770
    '#type' => 'radios',
771
    '#title' => t('Menubar style'),
772
    '#default_value' => theme_get_setting('menubar_style'),
773
    '#options' => array(
774
      1 => t('1. Normal (based on the colors specified by the color set)'),
775
      2 => t('2. Gloss black image background.'),
776
    ),
777
    '#suffix' => '<img src="' . file_create_url(drupal_get_path('theme', 'mayo') . '/images/menubar-type.png') . '" />',
778
  );
779
  $form['style']['note'] = array(
780
    '#type' => 'item',
781
    '#title' => t('Note:'),
782
    '#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.'),
783
  );
784

    
785
  $form['style']['menubar_background'] = array(
786
    '#type' => 'checkbox',
787
    '#title' => t('Allow Menubar background color.'),
788
    '#default_value' => theme_get_setting('menubar_background'),
789
    '#description' => t('Add your own hex background color below.'),
790
  );
791

    
792
  $form['style']['menubar_bg_value'] = array(
793
    '#type' => 'textfield',
794
    '#title' => t('Meubar background color'),
795
    '#default_value' => theme_get_setting('menubar_bg_value'),
796
    '#size' => 7,
797
    '#maxlength' => 7,
798
    '#description' => t('Specify the background color for the menubar. This setting is used only when the <em>Allow Meubar background</em> option is checked above.'),
799
  );
800

    
801
  /* --------------- Advanced header settings -------------- */
802
  $form['adv_header'] = array(
803
    '#type' => 'fieldset',
804
    '#title' => t('Advanced header settings'),
805
    '#collapsible' => TRUE,
806
    '#collapsed' => TRUE,
807
  );
808
  $form['adv_header']['header_searchbox'] = array(
809
    '#type' => 'checkbox',
810
    '#title' => t('Add search form to the header'),
811
    '#default_value' => theme_get_setting('header_searchbox'),
812
    '#description' => t('Check here if you want to add search form block to the right side of the header.'),
813
  );
814
  $form['adv_header']['header_fontsizer'] = array(
815
    '#type' => 'checkbox',
816
    '#title' => t('Add font resizing controls'),
817
    '#default_value' => theme_get_setting('header_fontsizer'),
818
    '#description' => t('Check here if you want to add font resizing controls at side of the header.'),
819
  );
820
  $form['adv_header']['header_border_width'] = array(
821
    '#type' => 'textfield',
822
    '#title' => t('Header border width'),
823
    '#default_value' => theme_get_setting('header_border_width'),
824
    '#size' => 12,
825
    '#maxlength' => 8,
826
    '#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.'),
827
  );
828
  $form['adv_header']['searchbox_size'] = array(
829
    '#type' => 'textfield',
830
    '#title' => t('Search form textfield width'),
831
    '#default_value' => theme_get_setting('searchbox_size'),
832
    '#size' => 10,
833
    '#maxlength' => 6,
834
    '#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.'),
835
  );
836
  $form['adv_header']['header_bg_file'] = array(
837
    '#type' => 'textfield',
838
    '#title' => t('URL of the header background image'),
839
    '#default_value' => theme_get_setting('header_bg_file'),
840
    '#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.'),
841
    '#size' => 40,
842
    '#maxlength' => 120,
843
  );
844
  $form['adv_header']['header_bg'] = array(
845
    '#type' => 'file',
846
    '#title' => t('Upload header background image'),
847
    '#size' => 40,
848
    '#attributes' => array('enctype' => 'multipart/form-data'),
849
    '#description' => t('If you don\'t jave direct access to the server, use this field to upload your header background image'),
850
    '#element_validate' => array('mayo_header_bg_validate'),
851
  );
852
  $form['adv_header']['header_bg_alignment'] = array(
853
    '#type' => 'select',
854
    '#title' => t('Header backgeround image alignment'),
855
    '#default_value' => theme_get_setting('header_bg_alignment'),
856
    '#description' => t('Select the alignment of the header background image.'),
857
    '#options' => array(
858
      'top left' => t('Top left'),
859
      'top center' => t('Top center'),
860
      'top right' => t('Top right'),
861
      'center left' => t('Center left'),
862
      'center center' => t('Center center'),
863
      'center right' => t('Center right'),
864
      'bottom left' => t('Bottom left'),
865
      'bottom center' => t('Bottom center'),
866
      'bottom right' => t('Bottom right'),
867
    ),
868
  );
869
  $form['adv_header']['header_watermark'] = array(
870
    '#type' => 'select',
871
    '#title' => t('Header watermark'),
872
    '#default_value' => theme_get_setting('header_watermark'),
873
    '#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.'),
874
    '#options' => array(
875
      0 => t('-None-'),
876
      1 => t('Pixture'),
877
      2 => t('Wave'),
878
      3 => t('Bubble'),
879
      4 => t('Flower'),
880
      5 => t('Star'),
881
      6 => t('Metal'),
882
    ),
883
    '#suffix' => '<img src="' . file_create_url(drupal_get_path('theme', 'mayo') . '/images/watermark-sample.png') . '" /><br />',
884
  );
885

    
886
  /* --------------- Misellanenous settings -------------- */
887
  $form['misc'] = array(
888
    '#type' => 'fieldset',
889
    '#title' => t('Miscellaneous settings'),
890
    '#collapsible' => TRUE,
891
    '#collapsed' => TRUE,
892
  );
893
  $form['misc']['display_breadcrumb'] = array(
894
    '#type' => 'checkbox',
895
    '#title' => t('Display breadcrumb'),
896
    '#default_value' => theme_get_setting('display_breadcrumb'),
897
    '#description' => t('Check here if you want to display breadcrumb.'),
898
  );
899
    $form['misc']['homeless_breadcrumb'] = array(
900
    '#type' => 'checkbox',
901
    '#title' => t('Display Mayo style breadcrumb'),
902
    '#default_value' => theme_get_setting('homeless_breadcrumb'),
903
    '#description' => t('Check here if you want to display breadcrumb with \'Home\' link removed and \'>\' seperator at end.'),
904
  );
905
  $form['misc']['dark_messages'] = array(
906
    '#type' => 'checkbox',
907
    '#title' => t('Use dark message colors'),
908
    '#default_value' => theme_get_setting('dark_messages'),
909
    '#return_value' => 'dark-messages',
910
    '#description' => t('Check here if you use the dark color set. Colors for the status/warning/error messages are adjusted.'),
911
  );
912

    
913
  /*
914
   * Originally posted by dvessel (http://drupal.org/user/56782).
915
   * The following will be processed even if the theme is inactive.
916
   * If you are on a theme specific settings page but it is not an active
917
   * theme (example.com/admin/apearance/settings/THEME_NAME), it will
918
   * still be processed.
919
   *
920
   * Build a list of themes related to the theme specific form. If the form
921
   * is specific to a sub-theme, all parent themes leading to it will have
922
   * hook_form_theme_settings invoked. For example, if a theme named
923
   * 'grandchild' has its settings form in focus, the following will be invoked.
924
   * - parent_form_theme_settings()
925
   * - child_form_theme_settings()
926
   * - grandchild_form_theme_settings()
927
   *
928
   * If 'child' was in focus it will invoke:
929
   * - parent_form_theme_settings()
930
   * - child_form_theme_settings()
931
   *
932
   *  @see http://drupal.org/node/943212
933
   */
934
  $form_themes = array();
935
  $themes = list_themes();
936
  $_theme = $GLOBALS['theme_key'];
937
  while (isset($_theme)) {
938
    $form_themes[$_theme] = $_theme;
939
    $_theme = isset($themes[$_theme]->base_theme) ? $themes[$_theme]->base_theme : NULL;
940
  }
941
  $form_themes = array_reverse($form_themes);
942

    
943
  foreach ($form_themes as $theme_key) {
944
    if (function_exists($form_settings = "{$theme_key}_form_theme_settings")) {
945
      $form_settings($form, $form_state);
946
    }
947
  }
948

    
949
  // Include custom form validation and submit functions
950
  require_once(drupal_get_path('theme', 'mayo') . '/inc/forms/mayo.validate.inc');
951
  require_once(drupal_get_path('theme', 'mayo') . '/inc/forms/mayo.submit.inc');
952

    
953
  // Custom validate and submit functions
954
  $form['#validate'][] = 'mayo_settings_validate';
955
  $form['#submit'][] = 'mayo_settings_submit';
956
}
957

    
958
/**
959
 * Check and save the uploaded header background image
960
 */
961
function mayo_header_bg_validate($element, &$form_state) {
962
  global $base_url;
963

    
964
  $validators = array('file_validate_is_image' => array());
965
  $file = file_save_upload('header_bg', $validators, "public://", FILE_EXISTS_REPLACE);
966

    
967
  if ($file) {
968
    // change file's status from temporary to permanent and update file database
969
    $file->status = FILE_STATUS_PERMANENT;
970
    file_save($file);
971

    
972
    $file_url = file_create_url($file->uri);
973
    $file_url = str_ireplace($base_url, '', $file_url);
974

    
975
    // set to form
976
    $form_state['values']['header_bg_file'] = $file_url;
977
  }
978
}
979

    
980
/**
981
 * Validate page width
982
 */
983
function mayo_page_width_validate($element, &$form_state) {
984
  if (!empty($element['#value'])) {
985
    $width = $element['#value'];
986

    
987
    // check if it is liquid (%) or fixed width (px)
988
    if (preg_match("/(\d+)\s*%/", $width, $match)) {
989
      $num = intval($match[0]);
990
      if (50 <= $num && $num <= 100) {
991
        return;
992
      }
993
      else {
994
        form_error($element, t('The width for the liquid layout must be a value between 50% and 100%.'));
995
      }
996
    }
997
    elseif (preg_match("/(\d+)\s*px/", $width, $match)) {
998
      $num = intval($match[0]);
999
      if (700 <= $num && $num < 1600) {
1000
        return;
1001
      }
1002
      else {
1003
        form_error($element, t('The width for the fixed layout must be a value between 700px and 1600px.'));
1004
      }
1005
    }
1006
  }
1007
}
1008

    
1009
/**
1010
 * Validate sidebar width
1011
 */
1012
function mayo_sidebar_width_validate($element, &$form_state) {
1013
  if (!empty($element['#value'])) {
1014
    $width = $element['#value'];
1015

    
1016
    // check if it is liquid (%) or fixed width (px)
1017
    if (preg_match("/(\d+)\s*%/", $width, $match)) {
1018
      $num = intval($match[0]);
1019
      if (15 <= $num && $num <= 40) {
1020
        return;
1021
      }
1022
      else {
1023
        form_error($element, t('The width of the sidebar must be a value between 15% and 40%.'));
1024
      }
1025
    }
1026
    elseif (preg_match("/(\d+)\s*px/", $width, $match)) {
1027
      form_error($element, t('The width of the sidebar must be a value between 15% and 40%. Do not forget to add % character.'));
1028
    }
1029
  }
1030
}