-
Notifications
You must be signed in to change notification settings - Fork 0
/
swftools_goswf.admin.inc
88 lines (74 loc) · 2.38 KB
/
swftools_goswf.admin.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
function swftools_goswf_admin_form() {
// Get saved settings
$saved = _swftools_goswf_settings();
// See if colorpicker 2 is loaded
$can_pick = function_exists('colorpicker_2_or_later');
// Initialise array
$form = array();
//Colors
$form['color'] = array(
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#title' => t('Colors'),
'#weight' => -1,
);
$form['color']['bg'] = array(
'#type' => ($can_pick ? 'colorpicker_' : '') .'textfield',
'#size' => 8,
'#maxlength' => 8,
'#default_value' => $saved['bg'],
'#title' => t('Background Color'),
'#description' => t('Choose a hexadecimal colorcode for the background'),
);
$form['color']['nav'] = array(
'#type' => ($can_pick ? 'colorpicker_' : '') .'textfield',
'#default_value' => $saved['nav'],
'#size' => 8,
'#maxlength' => 8,
'#title' => t('Navigation Color'),
'#description' => t('Choose a hexadecimal colorcode for the navigation bar'),
);
// Size
$form['size'] = array(
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#title' => t('Size'),
'#weight' => 0,
);
$form['size']['height'] = array(
'#type' => 'textfield',
'#default_value' => $saved['height'],
'#size' => 8,
'#title' => t('Height'),
'#description' => t('The height of the player in pixels.'),
);
$form['size']['width'] = array(
'#type' => 'textfield',
'#default_value' => $saved['width'],
'#size' => 8,
'#title' => t('Width'),
'#description' => t('The width of the player in pixels.'),
);
// Initialise tree as we want to store arrays
$form['swftools_goswf']['#tree'] = TRUE;
// Add custom form handler to ensure colors are coded properly
$form['#submit'][] = 'swftools_goswf_admin_submit';
// Add custom form handler to flush cache upon submit
$form['#submit'][] = 'swftools_admin_settings_submit';
// Return finished form
return system_settings_form($form);
}
/**
* Custom form handler to encode colors properly when using color picker module.
*/
function swftools_goswf_admin_submit($form, &$form_state) {
// Make sure colors are coded properly
if (function_exists('colorpicker_2_or_later')) {
foreach (array_keys($form_state['values']) AS $key) {
$form_state['values'][$key] = preg_replace(array('/^#\s*$/', '/^#/'), array('', '0x'), $form_state['values'][$key]);
}
}
}