-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathasu_brand.admin.inc
288 lines (242 loc) · 12.3 KB
/
asu_brand.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
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
<?php
/**
* ASU Brand administration functions.
*/
function asu_brand_get_block_configure_form($delta) {
$form['asu_brand'] = array(
'#type' => 'fieldset',
'#title' => t('ASU Brand settings'),
'#description' => t('This block is cached for %lifetime. To update now, <a href="@link">clear the cache</a>.', array('%lifetime' => format_interval(ASU_BRAND_CACHE_LIFETIME), '@link' => url('admin/config/development/performance'))),
);
switch ($delta) {
case ASU_BRAND_HEADER_DELTA:
$form['asu_brand']['asu_brand_header_basepath'] = array(
'#type' => 'textfield',
'#title' => t('ASU theme basepath'),
'#default_value' => variable_get('asu_brand_header_basepath', ASU_BRAND_HEADER_BASEPATH_DEFAULT),
'#description' => t('This setting is shared between all ASU Brand blocks. The default is %default. To use a local path, use %local_path', array('%default' => ASU_BRAND_HEADER_BASEPATH_DEFAULT, '%local_path' => '/afs/asu.edu/www/asuthemes')),
'#required' => TRUE,
'#ajax' => array(
'event' => 'change',
'callback' => 'asu_brand_basepath_ajax_callback',
'wrapper' => 'dropdown_header_version_replace',
),
);
$form['asu_brand']['asu_brand_header_version'] = array(
'#type' => 'select',
'#title' => t('ASU header version'),
'#description' => t('Select the version of the ASU header. <strong>This setting is shared between all ASU Brand blocks.</strong>'),
'#options' => asu_brand_get_version_options(FALSE, (!empty($form_state['values']['asu_brand_header_basepath'])) ? $form_state['values']['asu_brand_header_basepath'] : variable_get('asu_brand_header_basepath', ASU_BRAND_HEADER_BASEPATH_DEFAULT)),
'#default_value' => variable_get('asu_brand_header_version', ASU_BRAND_HEADER_VERSION_DEFAULT),
'#required' => TRUE,
'#prefix' => '<div id="dropdown_header_version_replace">',
'#suffix' => '</div>',
);
$form['asu_brand']['asu_brand_preview_pages'] = array(
'#type' => 'textarea',
'#title' => t('Preview pages'),
'#default_value' => variable_get('asu_brand_preview_pages', ASU_BRAND_PREVIEW_PAGES_DEFAULT),
'#description' => t('This setting is shared between all ASU Brand blocks.<br />Specify "preview pages" by using their paths. Enter one path per line. The \'*\' character is a wildcard. Example paths are blog for the blog page and blog/* for every personal blog. <front> is the front page.<br />The default is %default.', array('%default' => ASU_BRAND_PREVIEW_PAGES_DEFAULT)),
'#required' => TRUE,
);
$form['asu_brand']['asu_brand_header_template'] = array(
'#type' => 'textfield',
'#title' => t('ASU header template key'),
'#default_value' => variable_get('asu_brand_header_template', ASU_BRAND_HEADER_TEMPLATE_DEFAULT),
'#description' => t('The default is %default. For a list of template keys, visit <a href="@template_path">@template_path</a>.', array('%default' => ASU_BRAND_HEADER_TEMPLATE_DEFAULT, '@template_path' => url('https://asu.edu/asuthemes/' . variable_get('asu_brand_header_version', ASU_BRAND_HEADER_VERSION_DEFAULT) . '/heads/'))),
'#required' => TRUE,
);
$form['asu_brand']['site_menu'] = array(
'#type' => 'fieldset',
'#title' => t('Site menu injection'),
'#collapsed' => FALSE,
);
$form['asu_brand']['site_menu']['asu_brand_sitemenu_injection_flag'] = array(
'#type' => 'checkbox',
'#title' => t('Append local site menu into ASU header menu and display in responsive state.'),
'#default_value' => variable_get('asu_brand_sitemenu_injection_flag', 1),
);
$form['asu_brand']['site_menu']['asu_brand_sitemenu_name'] = array(
'#type' => 'select',
'#title' => t('Menu to inject'),
'#description' => t('Select the site menu to inject.'),
'#options' => asu_brand_get_site_menu_options(),
'#default_value' => variable_get('asu_brand_sitemenu_name', ASU_BRAND_SITE_MENU_NAME_DEFAULT),
'#states' => array(
'visible' => array(
':input[name="asu_brand_sitemenu_injection_flag"]' => array('checked' => TRUE),
),
),
);
$form['asu_brand']['gtm'] = array(
'#type' => 'fieldset',
'#title' => t('Override Google Tag Manager (GTM) settings'),
'#description' => t('ASU Universal GTM settings are automatically set. Overriding is not common.'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['asu_brand']['gtm']['asu_brand_gtm_override'] = array(
'#type' => 'textarea',
'#title' => t('Custom GTM Script'),
'#default_value' => variable_get('asu_brand_gtm_override', ''),
'#description' => t('This script should be provided by the ASU google Analytics Administrator.'),
);
$form['asu_brand']['do_not_override'] = array(
'#type' => 'fieldset',
'#title' => t('Do Not Override Login URL'),
'#description' => t('If host is added to list, the brand module will not override the login URL with the CAS module path.'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
// format our do not override list array as a comma-delimted list in the form field, for easy editing
$overrides = drupal_json_decode(variable_get('asu_brand_do_not_override', '["www.asu.edu"]'));
$fstring = implode(', ', $overrides);
$form['asu_brand']['do_not_override']['asu_brand_do_not_override'] = array(
'#type' => 'textarea',
'#title' => t('Do Not Override List'),
'#description' => t('Add hosts to list, separated by commas.'),
'#default_value' => $fstring,
);
$form['asu_brand']['custom_title'] = array(
'#type' => 'fieldset',
'#title' => t('Site Name/URL Settings'),
'#description' => t('Settings to override the site name link URL. Also allows setting a parent organization name and URL.'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['asu_brand']['custom_title']['asu_brand_override_url'] = array(
'#type' => 'textfield',
'#title' => t('Override Site Name Base URL'),
'#default_value' => variable_get('asu_brand_override_url', '/'),
'#description' => t("Overrides the URL for the site name link in the header. If not provided, the link will be set to the root '/'"),
);
$form['asu_brand']['custom_title']['asu_brand_parent_org_title'] = array(
'#type' => 'textfield',
'#title' => t('Parent Organization Title'),
'#default_value' => variable_get('asu_brand_parent_org_title', ''),
'#description' => t('The parent org name will be placed before the site title in the header, and separated by a \'|\'.'),
);
$form['asu_brand']['custom_title']['asu_brand_parent_org_url'] = array(
'#type' => 'textfield',
'#title' => t('Parent Organization URL'),
'#default_value' => variable_get('asu_brand_parent_org_url', ''),
'#description' => t('The href value for the parent organization link.'),
);
break;
case 'asu_brand_footer':
// Footer standardized with no color options
$form['asu_brand']['#title'] = t('ASU Brand Footer settings');
break;
case 'asu_brand_students_footer':
break;
}
return $form;
}
/**
* Implements hook_form_ID_alter().
* Rebuild the version options and deselect item.
*/
function asu_brand_form_block_admin_configure_alter(&$form, $form_state) {
if ($form['module']['#value'] == 'asu_brand' && $form['delta']['#value'] == 'asu_brand_header') {
// if form state is set (ajax call) then set the header version options to match the base path.
if (isset($form_state['values'])) {
$options = asu_brand_get_version_options(FALSE, $form_state['values']['asu_brand_header_basepath']);
$form['settings']['asu_brand']['asu_brand_header_version']['#options'] = $options;
}
}
}
/**
* Selects just the asu_brand_header_version to be returned for re-rendering
* @param array $form
* @param array $form_state
* @return renderable array (asu_brand_header_version)
*/
function asu_brand_basepath_ajax_callback($form, $form_state) {
// force user to select header version again as basepath has changed.
// available header versions can differ between DEV, QA and PROD.
$form['settings']['asu_brand']['asu_brand_header_version']['#value'] = '';
return $form['settings']['asu_brand']['asu_brand_header_version'];
}
/**
* Get the header version options as an associative array in the form of
* array(
* 'version' => description text,
* );
*/
function asu_brand_get_version_options($reset = FALSE, $basepath = '') {
// disabling the caching of version options to enable sensitivity to basepath changes.
//$options = &drupal_static(__FUNCTION__);
if ($reset || !isset($options)) {
$options = array('' => t('Select a version'));
// Use internal xml errors to provide user readable errors.
libxml_use_internal_errors(TRUE);
try {
$items = new SimpleXMLElement((($basepath != '') ? $basepath : variable_get('asu_brand_header_basepath', ASU_BRAND_HEADER_BASEPATH_DEFAULT)).'/gtmheaders.xml', 0, TRUE);
if ($items) {
$brand_module_info = system_get_info('module', $name = 'asu_brand');
$brand_module_version = (isset($brand_module_info['version'])) ? $brand_module_info['version'] : null;
foreach ($items->header as $header) {
$dep_min = (isset($header->compatibility->brand_module->min)) ? $header->compatibility->brand_module->min : null;
$dep_max = (isset($header->compatibility->brand_module->max)) ? $header->compatibility->brand_module->max : null;
if (asu_brand_dependencies_met($brand_module_version, $dep_min, $dep_max)) {
$options[(string) $header->version] = t((string) $header->name);
}
}
// Save options to variable table in case xml is not available at a later time.
variable_set('asu_brand_version_options', $options);
}
else {
// There was an error with loading the xml. Get versions from the
// variable table.
$options = variable_get('asu_brand_version_options', $options);
$log_message = "Failed loading ASU header version XML file\n";
foreach(libxml_get_errors() as $error) {
$log_message .= "\t" . $error->message;
}
drupal_set_message($log_message, 'error');
}
}
catch (Exception $e) {
// There was an error with loading the xml. Get versions from the
// variable table.
$options = variable_get('asu_brand_version_options', $options);
drupal_set_message('Failed loading ASU header version XML file. Please try again later. The full error description has been logged.', 'error');
watchdog('asu_brand', $e, array(), WATCHDOG_ERROR);
}
}
return $options;
}
function asu_brand_get_site_menu_options() {
return menu_get_menus();
}
/**
* Checks if passed brand module version meets the minimum
* and maximum versino dependancies
* @param string $current_version
* @param string $min_version
* @param string $mac_version
* @return boolean
*/
function asu_brand_dependencies_met($current_version, $min_version, $max_version) {
if(count($curr_varr = explode('-', $current_version)) < 2) return FALSE;
if(count($min_varr = explode('-', $min_version)) < 2) return FALSE;
// min check
if(floatval($curr_varr[0]) != floatval($min_varr[0])) return FALSE;
$min_varr = explode('.', $min_varr[1]);
$curr_varr = explode('.', $curr_varr[1]);
if (count($min_varr) < 2 || count($curr_varr) < 2) return FALSE;
if (floatval($curr_varr[1]) < floatval($min_varr[1])) return FALSE;
// max check (optional)
/* todo: get rid of this check?
if ($max_version) {
$max_varr = explode('-', $max_version);
$curr_varr = explode('-', $current_version);
if (count($max_varr) < 2) return FALSE;
if ($curr_varr[0] != $max_varr[0]) return FALSE;
$max_varr = explode('.', $max_varr[1]);
$curr_varr = explode('.', $curr_varr[1]);
if(intval($curr_varr[1]) > intval($max_varr[1])) return FALSE;
}*/
// all checks successful
return TRUE;
}