forked from SU-SWS/open_framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
theme-settings.php
164 lines (146 loc) · 5.65 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
<?php
function open_framework_form_system_theme_settings_alter(&$form, &$form_state) {
// Page Layout
$form['layout_container'] = array(
'#type' => 'fieldset',
'#title' => t('Layout'),
'#description' => t('Use these settings to adjust the page layout.'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$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']['toggle_search'] = array(
'#type' => 'checkbox',
'#title' => t('Display search box in header region'),
'#default_value' => theme_get_setting('toggle_search'),
);
$form['layout_container']['breadcrumb_classes'] = array(
'#type' => 'radios',
'#title' => t('Breadcrumbs'),
'#default_value' => theme_get_setting('header_padding_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('Background Images'),
'#description' => t('Use these settings to select different background images.'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
// Body Background Image
$form['background_container']['body_bg_type'] = array(
'#type' => 'radios',
'#title' => t('Body background image type'),
'#default_value' => theme_get_setting('body_bg_type'),
'#options' => array(
'' => t('Wallpaper pattern - <strong><em>Default</em></strong>'),
'photobg ' => t('Photo image'),
),
);
$form['background_container']['body_bg_classes'] = array(
'#type' => 'radios',
'#title' => t('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 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 background image',
'#description' => 'You can upload the following image file types: *.jpg, *.gif, or *.png',
);
// Border Style
$form['border_container'] = array(
'#type' => 'fieldset',
'#title' => t('Borders'),
'#description' => t('Use these settings to change the border style.'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$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)'),
),
);
// 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.'));
}
}
}