1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* Provides the image names which can be configured in the theme settings to all
|
5
|
* theme setting functions.
|
6
|
*
|
7
|
* @return multitype:string
|
8
|
* the list of image names which can be configured in the theme settings
|
9
|
*/
|
10
|
function _zen_dataportal_imagenames() {
|
11
|
static $image_list = array('banner', 'body_background', 'page_background');
|
12
|
return $image_list;
|
13
|
}
|
14
|
|
15
|
/**
|
16
|
* Implements hook_form_system_theme_settings_alter().
|
17
|
*
|
18
|
* @param $form
|
19
|
* Nested array of form elements that comprise the form.
|
20
|
* @param $form_state
|
21
|
* A keyed array containing the current state of the form.
|
22
|
*/
|
23
|
function zen_dataportal_form_system_theme_settings_alter(&$form, &$form_state, $form_id = NULL) {
|
24
|
// Work-around for a core bug affecting admin themes. See issue #943212.
|
25
|
if (isset($form_id)) {
|
26
|
return;
|
27
|
}
|
28
|
|
29
|
// will be available in the page.tpl.php
|
30
|
$form['zen_dataportal_misc'] = array(
|
31
|
'#type' => 'fieldset',
|
32
|
'#title' => t('Miscellaneous settings'),
|
33
|
'#description' => t('Miscellaneous settings for the DataPoral Zen theme.')
|
34
|
);
|
35
|
$form['zen_dataportal_misc']['site_name_position'] = array(
|
36
|
'#type' => 'select',
|
37
|
'#title' => t('Site name posistion'),
|
38
|
'#description' => t('The site name can be positioned over the banner or below the banner.'
|
39
|
. '<br/><stong>NOTE:</strong> If your are choosing to position the site name below the banner you may also want to '
|
40
|
. 'adapt the <em>site name color</em>.' ),
|
41
|
'#options' => array(
|
42
|
'hide' => t('Hidden'),
|
43
|
'over_banner' => t('Over banner'),
|
44
|
'below_banner' => t('Below banner'),
|
45
|
),
|
46
|
'#default_value' => theme_get_setting('site_name_position'),
|
47
|
);
|
48
|
$form['zen_dataportal_misc']['header_margin_bottom'] = array(
|
49
|
'#type' => 'textfield',
|
50
|
'#title' => t('Header margin at bottom'),
|
51
|
'#default_value' => theme_get_setting('header_margin_bottom'),
|
52
|
'#disabled' => theme_get_setting('site_name_position') == 'below_banner',
|
53
|
'#description' => t('This margin instroduces space between the header and the main menu. This setting not applies if @site-name-pos" is set to "@below-banner'
|
54
|
. 'The entered value can be any css length measurement. It is a <number> immediately followed by a length unit (px, em, pc, in, mm, …). See @link for more information',
|
55
|
array(
|
56
|
'@site-name-pos' => '<b>' . t('Site name posistion') . '</b>',
|
57
|
'@below-banner' => '<b>' . t('Below banner') . '</b>',
|
58
|
'@link' => l('https://developer.mozilla.org/en-US/docs/CSS/length', 'https://developer.mozilla.org/en-US/docs/CSS/length'),
|
59
|
)
|
60
|
),
|
61
|
);
|
62
|
|
63
|
// TODO : site-name shadow: text-shadow: black 0 10px 20px, black 0 5px
|
64
|
|
65
|
|
66
|
drupal_add_css(path_to_theme() . '/js/colorpicker/css/colorpicker.css', 'file');
|
67
|
drupal_add_js(path_to_theme() . '/js/colorpicker/js/colorpicker.js', 'file');
|
68
|
drupal_add_js(path_to_theme() . '/js/settings-ui.js', 'file');
|
69
|
$form['zen_dataportal_colors'] = array(
|
70
|
'#type' => 'fieldset',
|
71
|
'#title' => t('Colors'),
|
72
|
'#description' => t('Configure colors where.'),
|
73
|
'#attributes' => array('class' => array('theme-settings-bottom')),
|
74
|
);
|
75
|
zen_dataportal_form_widget_color(
|
76
|
$form['zen_dataportal_colors'],
|
77
|
'site-name_color',
|
78
|
t('The color of the site name which is shown in the header.')
|
79
|
);
|
80
|
zen_dataportal_form_widget_color(
|
81
|
$form['zen_dataportal_colors'],
|
82
|
'main-menu_background-color',
|
83
|
t('The color of the menu background.')
|
84
|
);
|
85
|
zen_dataportal_form_widget_color(
|
86
|
$form['zen_dataportal_colors'],
|
87
|
'main-menu_background-color-2',
|
88
|
t('The second color of the menu background. If this is also set the menu background will have a grandiend.')
|
89
|
);
|
90
|
zen_dataportal_form_widget_color(
|
91
|
$form['zen_dataportal_colors'],
|
92
|
'sub-header_background-color',
|
93
|
t('The background color sub-header.')
|
94
|
);
|
95
|
|
96
|
|
97
|
//
|
98
|
// custom images for banner, body and page backgrounds
|
99
|
//
|
100
|
foreach(_zen_dataportal_imagenames() as $which_image) {
|
101
|
zen_dataportal_form_widget_image($form, $which_image);
|
102
|
}
|
103
|
|
104
|
|
105
|
$form['#validate'][] = 'zen_dataportal_theme_settings_validate';
|
106
|
$form['#submit'][] = 'zen_dataportal_theme_settings_submit';
|
107
|
// We are editing the $form in place, so we don't need to return anything.
|
108
|
}
|
109
|
|
110
|
/**
|
111
|
* Process zen_dataportal admin form submissions.
|
112
|
* @param $form
|
113
|
* Nested array of form elements that comprise the form.
|
114
|
* @param $form_state
|
115
|
* A keyed array containing the current state of the form.
|
116
|
*/
|
117
|
function zen_dataportal_theme_settings_submit($form, &$form_state) {
|
118
|
|
119
|
foreach(_zen_dataportal_imagenames() as $which_image) {
|
120
|
zen_dataportal_form_widget_image_submit($form_state, $which_image);
|
121
|
}
|
122
|
|
123
|
// update logo information like wich one to use and size, this is needed to
|
124
|
// offset the banner and menu bar
|
125
|
$values = &$form_state['values'];
|
126
|
if($values['default_logo']) {
|
127
|
$logo_file = path_to_theme() . '/logo.png';
|
128
|
} else {
|
129
|
$logo_file = 'public://' . $values['logo_path'];
|
130
|
}
|
131
|
$logo_file_info = image_get_info($logo_file);
|
132
|
if(isset($logo_file_info['width'])) {
|
133
|
$values['logo_size'] = array('width' => $logo_file_info['width'], 'height' => $logo_file_info['height']);
|
134
|
}
|
135
|
|
136
|
/*
|
137
|
* Ok, we are done here the $values will be saved in the theme
|
138
|
* variable by system_theme_settings_submit($form, &$form_state)
|
139
|
* in modules/system/system.admin.inc
|
140
|
*/
|
141
|
}
|
142
|
|
143
|
/**
|
144
|
* Validator for the system_theme_settings() form.
|
145
|
* @param $form
|
146
|
* Nested array of form elements that comprise the form.
|
147
|
* @param $form_state
|
148
|
* A keyed array containing the current state of the form.
|
149
|
*/
|
150
|
function zen_dataportal_theme_settings_validate($form, &$form_state) {
|
151
|
|
152
|
foreach(_zen_dataportal_imagenames() as $which_image) {
|
153
|
zen_dataportal_form_widget_image_validate($form_state, $which_image);
|
154
|
}
|
155
|
}
|
156
|
|
157
|
/*******************************************************************
|
158
|
* form widget functions
|
159
|
*******************************************************************/
|
160
|
|
161
|
/**
|
162
|
*
|
163
|
* Enter description here ...
|
164
|
* @param $form
|
165
|
* Nested array of form elements that comprise the form.
|
166
|
* @param unknown_type $which_image
|
167
|
*/
|
168
|
function zen_dataportal_form_widget_image(&$form, $which_image){
|
169
|
$label = str_replace('_', ' ', $which_image);
|
170
|
$form['zen_dataportal_' . $which_image] = array(
|
171
|
'#type' => 'fieldset',
|
172
|
'#title' => ucfirst(t($label)) . ' ' . t('image settings'),
|
173
|
'#description' => t('If toggled on, the following image will be displayed.'),
|
174
|
'#attributes' => array('class' => array('theme-settings-bottom')),
|
175
|
);
|
176
|
$form['zen_dataportal_' . $which_image]['default_' . $which_image] = array(
|
177
|
'#type' => 'checkbox',
|
178
|
'#title' => t('Use the default') . t($which_image),
|
179
|
'#default_value' => theme_get_setting('default_' . $which_image),
|
180
|
'#tree' => FALSE,
|
181
|
'#description' => t('Check here if you want the theme to use the image supplied with it.')
|
182
|
);
|
183
|
$form['zen_dataportal_' . $which_image]['settings'] = array(
|
184
|
'#type' => 'container',
|
185
|
'#states' => array(
|
186
|
// Hide the logo settings when using the default logo.
|
187
|
'invisible' => array(
|
188
|
'input[name="default_' . $which_image . '"]' => array('checked' => TRUE),
|
189
|
),
|
190
|
),
|
191
|
);
|
192
|
|
193
|
|
194
|
// If $path is a public:// URI, display the path relative to the files
|
195
|
// directory; stream wrappers are not end-user friendly.
|
196
|
$path = theme_get_setting($which_image . '_path');
|
197
|
$image = '';
|
198
|
if (file_uri_scheme($path) == 'public') {
|
199
|
$url = file_create_url($path);
|
200
|
$path = file_uri_target($path);
|
201
|
$form['zen_dataportal_' . $which_image]['settings'][$which_image . '_preview'] = array(
|
202
|
'#type' => 'item',
|
203
|
'#title' => t('Preview'),
|
204
|
'#markup' => '<div class="image-preview"><img src="' . $url . '"/></div>',
|
205
|
);
|
206
|
} // FIXME manully entered files without scheme public: are omitted here
|
207
|
$form['zen_dataportal_' . $which_image]['settings'][$which_image . '_path'] = array(
|
208
|
'#type' => 'textfield',
|
209
|
'#title' => t('Path to custom') . ' ' . t($label),
|
210
|
'#description' => t('The path to the file you would like to use as your') . ' ' . t($label),
|
211
|
'#default_value' => $path,
|
212
|
);
|
213
|
$form['zen_dataportal_' . $which_image]['settings'][$which_image . '_upload'] = array(
|
214
|
'#type' => 'file',
|
215
|
'#title' => t('Upload') . ' ' . t($label) . t(' image'),
|
216
|
'#maxlength' => 40,
|
217
|
'#description' => t("If you don't have direct file access to the server, use this field to upload your image.")
|
218
|
);
|
219
|
}
|
220
|
|
221
|
/**
|
222
|
*
|
223
|
* Enter description here ...
|
224
|
* @param $color_settings_key
|
225
|
*
|
226
|
*/
|
227
|
function zen_dataportal_form_widget_color(&$form, $color_settings_key, $description) {
|
228
|
$label = str_replace('_', ' ', $color_settings_key);
|
229
|
$form['zen_dataportal_colors'][$color_settings_key] = array(
|
230
|
'#type' => 'textfield',
|
231
|
'#title' => ucfirst(t($label)),
|
232
|
'#default_value' => theme_get_setting($color_settings_key),
|
233
|
'#description' => $description, //t('Set the color of the site name which is shown in the header. Must be a css color value like: #000000'),
|
234
|
'#attributes' => array(
|
235
|
'class' => array('color-picker'),
|
236
|
'size' => '7',
|
237
|
),
|
238
|
);
|
239
|
}
|
240
|
|
241
|
/**
|
242
|
*
|
243
|
* Enter description here ...
|
244
|
* @param $form_state
|
245
|
* A keyed array containing the current state of the form.
|
246
|
* @param unknown_type $which_image
|
247
|
*/
|
248
|
function zen_dataportal_form_widget_image_submit(&$form_state, $which_image){
|
249
|
// If the user uploaded a new image, save it to a permanent location
|
250
|
// and use it in place of the default theme-provided file.
|
251
|
$values = &$form_state['values'];
|
252
|
if ($file = $values[$which_image . '_upload']) {
|
253
|
unset($values[$which_image . '_upload']);
|
254
|
$filename = file_unmanaged_copy($file->uri);
|
255
|
$values['default_' .$which_image ] = 0;
|
256
|
$values[$which_image . '_path'] = $filename;
|
257
|
$values['toggle_' . $which_image] = 1;
|
258
|
}
|
259
|
if (!empty($values[$which_image . '_path'])) {
|
260
|
$values[$which_image . '_path'] = _system_theme_settings_validate_path($values[$which_image . '_path']);
|
261
|
}
|
262
|
}
|
263
|
|
264
|
/**
|
265
|
*
|
266
|
* Enter description here ...
|
267
|
* @param $form_state
|
268
|
* A keyed array containing the current state of the form.
|
269
|
* @param unknown_type $which_image
|
270
|
*/
|
271
|
function zen_dataportal_form_widget_image_validate(&$form_state, $which_image){
|
272
|
$validators = array('file_validate_is_image' => array('gif', 'jpg', 'png'));
|
273
|
// Check for a new uploaded logo.
|
274
|
$file = file_save_upload($which_image . '_upload', $validators);
|
275
|
if (isset($file)) {
|
276
|
// File upload was attempted.
|
277
|
if ($file) {
|
278
|
// Put the temporary file in form_values so we can save it on submit.
|
279
|
$form_state['values'][$which_image . '_upload'] = $file;
|
280
|
}
|
281
|
else {
|
282
|
// File upload failed.
|
283
|
form_set_error($which_image . '_upload', t('The image could not be uploaded.'));
|
284
|
}
|
285
|
}
|
286
|
}
|