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
|
$form['zen_dataportal_colors'] = array(
|
30
|
'#type' => 'fieldset',
|
31
|
'#title' => t('Colors'),
|
32
|
'#description' => t('Configure colors where.'),
|
33
|
'#attributes' => array('class' => array('theme-settings-bottom')),
|
34
|
);
|
35
|
$form['zen_dataportal_colors']['site_name_color'] = array(
|
36
|
'#type' => 'textfield',
|
37
|
'#title' => t('Site name color'),
|
38
|
'#default_value' => theme_get_setting('site_name_color'),
|
39
|
'#description' => t('Set the color of the site name which is shown in the header. Must be a css color value like: #000000'),
|
40
|
);
|
41
|
|
42
|
//
|
43
|
// custom images for banner, body and page backgrounds
|
44
|
//
|
45
|
foreach(_zen_dataportal_imagenames() as $which_image) {
|
46
|
zen_dataportal_form_widget_image($form, $which_image);
|
47
|
}
|
48
|
|
49
|
|
50
|
$form['#validate'][] = 'zen_dataportal_theme_settings_validate';
|
51
|
$form['#submit'][] = 'zen_dataportal_theme_settings_submit';
|
52
|
// We are editing the $form in place, so we don't need to return anything.
|
53
|
}
|
54
|
|
55
|
/**
|
56
|
* Process zen_dataportal admin form submissions.
|
57
|
* @param $form
|
58
|
* Nested array of form elements that comprise the form.
|
59
|
* @param $form_state
|
60
|
* A keyed array containing the current state of the form.
|
61
|
*/
|
62
|
function zen_dataportal_theme_settings_submit($form, &$form_state) {
|
63
|
|
64
|
|
65
|
foreach(_zen_dataportal_imagenames() as $which_image) {
|
66
|
zen_dataportal_form_widget_image_submit($form_state, $which_image);
|
67
|
}
|
68
|
|
69
|
// update logo information like wich one to use and size, this is needed to
|
70
|
// offset the banner and menu bar
|
71
|
$values = &$form_state['values'];
|
72
|
if(!theme_get_setting('default_logo')) {
|
73
|
$logo_file = path_to_theme() . '/logo.png';
|
74
|
} else {
|
75
|
$logo_file = theme_get_setting('logo_path');
|
76
|
}
|
77
|
$logo_file_info = image_get_info($logo_file);
|
78
|
if(isset($logo_file_info['width'])) {
|
79
|
$values['logo_size'] = array('width' => $logo_file_info['width'], 'height' => $logo_file_info['height']);
|
80
|
}
|
81
|
|
82
|
|
83
|
|
84
|
/*
|
85
|
* Ok, we are done here the $values will be saved in the theme
|
86
|
* variable by system_theme_settings_submit($form, &$form_state)
|
87
|
* in modules/system/system.admin.inc
|
88
|
*/
|
89
|
}
|
90
|
|
91
|
/**
|
92
|
* Validator for the system_theme_settings() form.
|
93
|
* @param $form
|
94
|
* Nested array of form elements that comprise the form.
|
95
|
* @param $form_state
|
96
|
* A keyed array containing the current state of the form.
|
97
|
*/
|
98
|
function zen_dataportal_theme_settings_validate($form, &$form_state) {
|
99
|
|
100
|
foreach(_zen_dataportal_imagenames() as $which_image) {
|
101
|
zen_dataportal_form_widget_image_validate($form_state, $which_image);
|
102
|
}
|
103
|
}
|
104
|
|
105
|
/*******************************************************************
|
106
|
* form widget functions
|
107
|
*******************************************************************/
|
108
|
|
109
|
/**
|
110
|
*
|
111
|
* Enter description here ...
|
112
|
* @param $form
|
113
|
* Nested array of form elements that comprise the form.
|
114
|
* @param unknown_type $which_image
|
115
|
*/
|
116
|
function zen_dataportal_form_widget_image(&$form, $which_image){
|
117
|
$image_label = str_replace('_', ' ', $which_image);
|
118
|
$form['zen_dataportal_' . $which_image] = array(
|
119
|
'#type' => 'fieldset',
|
120
|
'#title' => ucfirst(t($image_label)) . ' ' . t('image settings'),
|
121
|
'#description' => t('If toggled on, the following image will be displayed.'),
|
122
|
'#attributes' => array('class' => array('theme-settings-bottom')),
|
123
|
);
|
124
|
$form['zen_dataportal_' . $which_image]['default_' . $which_image] = array(
|
125
|
'#type' => 'checkbox',
|
126
|
'#title' => t('Use the default') . t($which_image),
|
127
|
'#default_value' => theme_get_setting('default_' . $which_image),
|
128
|
'#tree' => FALSE,
|
129
|
'#description' => t('Check here if you want the theme to use the image supplied with it.')
|
130
|
);
|
131
|
$form['zen_dataportal_' . $which_image]['settings'] = array(
|
132
|
'#type' => 'container',
|
133
|
'#states' => array(
|
134
|
// Hide the logo settings when using the default logo.
|
135
|
'invisible' => array(
|
136
|
'input[name="default_' . $which_image . '"]' => array('checked' => TRUE),
|
137
|
),
|
138
|
),
|
139
|
);
|
140
|
|
141
|
// If $path is a public:// URI, display the path relative to the files
|
142
|
// directory; stream wrappers are not end-user friendly.
|
143
|
$path = theme_get_setting($which_image . '_path');
|
144
|
$image = '';
|
145
|
if (file_uri_scheme($path) == 'public') {
|
146
|
$url = file_create_url($path);
|
147
|
$path = file_uri_target($path);
|
148
|
$form['zen_dataportal_' . $which_image]['settings'][$which_image . '_preview'] = array(
|
149
|
'#type' => 'item',
|
150
|
'#title' => t('Preview'),
|
151
|
'#markup' => '<div class="image-preview"><img src="' . $url . '"/></div>',
|
152
|
);
|
153
|
} // FIXME manully entered files without scheme public: are omitted here
|
154
|
$form['zen_dataportal_' . $which_image]['settings'][$which_image . '_path'] = array(
|
155
|
'#type' => 'textfield',
|
156
|
'#title' => t('Path to custom') . ' ' . t($image_label),
|
157
|
'#description' => t('The path to the file you would like to use as your') . ' ' . t($image_label),
|
158
|
'#default_value' => $path,
|
159
|
);
|
160
|
$form['zen_dataportal_' . $which_image]['settings'][$which_image . '_upload'] = array(
|
161
|
'#type' => 'file',
|
162
|
'#title' => t('Upload') . ' ' . t($image_label) . t(' image'),
|
163
|
'#maxlength' => 40,
|
164
|
'#description' => t("If you don't have direct file access to the server, use this field to upload your image.")
|
165
|
);
|
166
|
}
|
167
|
|
168
|
/**
|
169
|
*
|
170
|
* Enter description here ...
|
171
|
* @param $form_state
|
172
|
* A keyed array containing the current state of the form.
|
173
|
* @param unknown_type $which_image
|
174
|
*/
|
175
|
function zen_dataportal_form_widget_image_submit(&$form_state, $which_image){
|
176
|
// If the user uploaded a new image, save it to a permanent location
|
177
|
// and use it in place of the default theme-provided file.
|
178
|
$values = &$form_state['values'];
|
179
|
if ($file = $values[$which_image . '_upload']) {
|
180
|
unset($values[$which_image . '_upload']);
|
181
|
$filename = file_unmanaged_copy($file->uri);
|
182
|
$values['default_' .$which_image ] = 0;
|
183
|
$values[$which_image . '_path'] = $filename;
|
184
|
$values['toggle_' . $which_image] = 1;
|
185
|
}
|
186
|
if (!empty($values[$which_image . '_path'])) {
|
187
|
$values[$which_image . '_path'] = _system_theme_settings_validate_path($values[$which_image . '_path']);
|
188
|
}
|
189
|
}
|
190
|
|
191
|
/**
|
192
|
*
|
193
|
* Enter description here ...
|
194
|
* @param $form_state
|
195
|
* A keyed array containing the current state of the form.
|
196
|
* @param unknown_type $which_image
|
197
|
*/
|
198
|
function zen_dataportal_form_widget_image_validate(&$form_state, $which_image){
|
199
|
$validators = array('file_validate_is_image' => array('gif', 'jpg', 'png'));
|
200
|
// Check for a new uploaded logo.
|
201
|
$file = file_save_upload($which_image . '_upload', $validators);
|
202
|
if (isset($file)) {
|
203
|
// File upload was attempted.
|
204
|
if ($file) {
|
205
|
// Put the temporary file in form_values so we can save it on submit.
|
206
|
$form_state['values'][$which_image . '_upload'] = $file;
|
207
|
}
|
208
|
else {
|
209
|
// File upload failed.
|
210
|
form_set_error($which_image . '_upload', t('The image could not be uploaded.'));
|
211
|
}
|
212
|
}
|
213
|
}
|