-
Notifications
You must be signed in to change notification settings - Fork 85
/
theme-settings.php
197 lines (176 loc) · 6.9 KB
/
theme-settings.php
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<?php
function open_framework_form_system_theme_settings_alter(&$form, &$form_state) {
// Responsive Behavior
$form['responsive_container'] = array(
'#type' => 'fieldset',
'#title' => t('Responsive'),
'#description' => t('Use these settings to adjust the responsive behavior.'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['responsive_container']['content_order_classes'] = array(
'#type' => 'radios',
'#title' => t('Content order in mobile'),
'#default_value' => theme_get_setting('content_order_classes'),
'#options' => array(
'' => t('Show first sidebar content before main content - <strong><em>Default</em></strong>'),
'content-first ' => t('Show main content before sidebar content'),
),
);
// Page Layout
$form['layout_container'] = array(
'#type' => 'fieldset',
'#title' => t('Layout'),
'#description' => t('Use these settings to adjust the page layout.'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['layout_container']['front_heading_classes'] = array(
'#type' => 'radios',
'#title' => t('Page heading'),
'#default_value' => theme_get_setting('front_heading_classes'),
'#options' => array(
'' => t('Hide heading on front page - <strong><em>Default</em></strong>'),
'show-title ' => t('Show heading on front page'),
),
);
$form['layout_container']['breadcrumb_classes'] = array(
'#type' => 'radios',
'#title' => t('Breadcrumbs'),
'#default_value' => theme_get_setting('breadcrumb_classes'),
'#options' => array(
'' => t('Hide breadcrumbs - <strong><em>Default</em></strong>'),
'show-breadcrumb ' => t('Show breadcrumbs'),
),
);
// Background Section
$form['background_container'] = array(
'#type' => 'fieldset',
'#title' => t('Body background'),
'#description' => t('Use these settings to select a different body background image.'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
// Body Background Image
$form['background_container']['body_bg_classes'] = array(
'#type' => 'radios',
'#title' => t('Enable body background image'),
'#default_value' => theme_get_setting('body_bg_classes'),
'#options' => array(
'' => t('None - <strong><em>Default</em></strong>'),
'bodybg ' => t('Use my image (upload below):'),
),
);
// Default path for image
$body_bg_path = theme_get_setting('body_bg_path');
if (file_uri_scheme($body_bg_path) == 'public') {
$body_bg_path = file_uri_target($body_bg_path);
}
// Helpful text showing the file name, disabled to avoid the user thinking it can be used for any purpose.
$form['background_container']['body_bg_path'] = array(
'#type' => 'hidden',
'#title' => 'Path to body background image',
'#default_value' => $body_bg_path,
);
if (!empty($body_bg_path)) {
$form['background_container']['body_bg_preview'] = array(
'#markup' => !empty($body_bg_path) ?
theme('image', array('path' => theme_get_setting('body_bg_path'))) : '',
);
}
// Upload field
$form['background_container']['body_bg_upload'] = array(
'#type' => 'file',
'#title' => 'Upload body background image',
'#description' => 'You can upload the following image file types: *.jpg, *.gif, or *.png',
);
// Body Background Image Style
$form['background_container']['body_bg_type'] = array(
'#type' => 'radios',
'#title' => t('Choose body background style'),
'#default_value' => theme_get_setting('body_bg_type'),
'#options' => array(
'' => t('Wallpaper pattern - <strong><em>Default</em></strong>'),
'photobg ' => t('Stretch to fill body'),
),
);
// Border Style
$form['border_container'] = array(
'#type' => 'fieldset',
'#title' => t('Borders'),
'#description' => t('Use these settings to change the border style.'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['border_container']['border_classes'] = array(
'#type' => 'radios',
'#title' => t('Border style for content section'),
'#default_value' => theme_get_setting('border_classes'),
'#options' => array(
'' => t('No borders - <strong><em>Default</em></strong>'),
'borders' => t('Show borders'),
),
);
$form['border_container']['corner_classes'] = array(
'#type' => 'radios',
'#title' => t('Corner style'),
'#default_value' => theme_get_setting('corner_classes'),
'#options' => array(
'' => t('Straight corners - <strong><em>Default</em></strong>'),
'roundedcorners' => t('Rounded corners (not supported in Internet Explorer 8 or below)'),
),
);
// Packages
$form['packages_container'] = array(
'#type' => 'fieldset',
'#title' => t('Packages'),
'#description' => t('Select font package.'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['packages_container']['font_awesome_version'] = array(
'#type' => 'radios',
'#title' => t('Font Awesome'),
'#default_value' => theme_get_setting('font_awesome_version'),
'#options' => array(
'font-awesome-3' => t('Version 3.2.1 [<a href="http://fontawesome.io/3.2.1/" title="Font Awesome 3.2.1 official documentation">documentation</a>]'),
'font-awesome-4' => t('Version 4.7.0 [<a href="http://fontawesome.io/" title="Font Awesome 4.7.0 official documentation">documentation</a>]'),
),
);
// Attach custom submit handler to the form
$form['#submit'][] = 'open_framework_settings_submit';
$form['#validate'][] = 'open_framework_settings_validate';
}
function open_framework_settings_submit($form, &$form_state) {
$settings = array();
// Get the previous value
$previous = 'public://' . $form['background_container']['body_bg_path']['#default_value'];
$file = file_save_upload('body_bg_upload');
if ($file) {
$parts = pathinfo($file->filename);
$destination = 'public://' . $parts['basename'];
$file->status = FILE_STATUS_PERMANENT;
if(file_copy($file, $destination, FILE_EXISTS_REPLACE)) {
$_POST['body_bg_path'] = $form_state['values']['body_bg_path'] = $destination;
}
} else {
// Avoid error when the form is submitted without specifying a new image
$_POST['body_bg_path'] = $form_state['values']['body_bg_path'] = $previous;
}
}
function open_framework_settings_validate($form, &$form_state) {
$validators = array('file_validate_is_image' => array());
// Check for a new uploaded logo.
$file = file_save_upload('body_bg_upload', $validators);
if (isset($file)) {
// File upload was attempted.
if ($file) {
// Put the temporary file in form_values so we can save it on submit.
$form_state['values']['body_bg_upload'] = $file;
}
else {
// File upload failed.
form_set_error('body_bg_upload', t('The background image could not be uploaded.'));
}
}
}