-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy paththeme-settings.php
208 lines (198 loc) · 8.08 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
198
199
200
201
202
203
204
205
206
207
208
<?php
/**
* Implements hook_form_system_theme_settings_alter().
* Done as THEMENAME_form_system_theme_settings_alter(), reference http://drupal.org/node/177868
*/
function unl_wdn_form_system_theme_settings_alter(&$form, &$form_state) {
global $user;
// Add checkboxes to the Toggle Display form to hide UNL template items on an affiliate site
$form['theme_settings'] += array(
'toggle_unl_banner' => array(
'#type' => 'checkbox',
'#title' => t('UNL affiliate banner'),
'#default_value' => theme_get_setting('toggle_unl_banner'),
'#access' => theme_get_setting('unl_affiliate'),
),
'toggle_unl_branding' => array(
'#type' => 'checkbox',
'#title' => t('UNL branding elements'),
'#default_value' => theme_get_setting('toggle_unl_branding'),
'#access' => theme_get_setting('unl_affiliate'),
),
'toggle_unl_breadcrumb' => array(
'#type' => 'checkbox',
'#title' => t('UNL breadcrumb'),
'#default_value' => theme_get_setting('toggle_unl_breadcrumb'),
'#access' => theme_get_setting('unl_affiliate'),
),
'toggle_unl_search' => array(
'#type' => 'checkbox',
'#title' => t('UNL search box'),
'#default_value' => theme_get_setting('toggle_unl_search'),
'#access' => theme_get_setting('unl_affiliate'),
),
'toggle_unl_tools' => array(
'#type' => 'checkbox',
'#title' => t('UNL tools'),
'#default_value' => theme_get_setting('toggle_unl_tools'),
'#access' => theme_get_setting('unl_affiliate'),
),
);
$form['intermediate_breadcrumbs'] = array(
'#type' => 'fieldset',
'#title' => t('Intermediate breadcrumbs'),
'#description' => t('Breadcrumbs that are displayed between the UNL breadcrumb and this site\'s breadcrumb'),
'site_name_abbreviation' => array(
'#type' => 'textfield',
'#title' => t('Site name abbreviation'),
'#default_value' => theme_get_setting('site_name_abbreviation'),
'#description' => t('An abbreviated version of your site\'s name to use in breadcrumbs when not on the front page.'),
'#weight' => 10,
),
);
$intermediate_breadcrumbs = theme_get_setting('intermediate_breadcrumbs');
for ($i = 0; $i < 3; $i++) {
$form['intermediate_breadcrumbs'][] = array(
'text' => array(
'#type' => 'textfield',
'#field_prefix' => t('Text ' . ($i + 1)),
'#default_value' => isset($intermediate_breadcrumbs[$i]) ? $intermediate_breadcrumbs[$i]['text'] : '',
'#parents' => array('intermediate_breadcrumbs' , $i, 'text'),
),
'href' => array(
'#type' => 'textfield',
'#field_prefix' => t(' URL ' . ($i + 1)),
'#default_value' => isset($intermediate_breadcrumbs[$i]) ? $intermediate_breadcrumbs[$i]['href'] : '',
'#parents' => array('intermediate_breadcrumbs' , $i, 'href'),
),
);
}
$form['unl_head'] = array(
'#type' => 'fieldset',
'#title' => t('Site specific CSS and JavaScript'),
'#weight' => -45,
'unl_css' => array(
'#title' => t('CSS'),
'#description' => t('Custom CSS rules for this site. Do not include @style tags.', array('@style' => '<style>')),
'#type' => 'textarea',
'#rows' => 16,
'#default_value' => theme_get_setting('unl_css'),
),
'unl_js' => array(
'#title' => t('JavaScript'),
'#description' => t('Custom Javascript for this site. Do not include @script tags.', array('@script' => '<script>')),
'#type' => 'textarea',
'#rows' => 16,
'#default_value' => theme_get_setting('unl_js'),
),
'head_html' => array(
'#title' => t('Head HTML'),
'#description' => t('HTML to be added inside the @head tags.', array('@head' => '<head>')),
'#type' => 'textarea',
'#rows' => 3,
'#default_value' => theme_get_setting('head_html'),
),
);
$form['advanced_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Advanced settings'),
'sidebar_first_width' => array(
'#type' => 'textfield',
'#title' => t('Sidebar first grid size'),
'#default_value' => theme_get_setting('sidebar_first_width'),
'#description' => t('Enter only the numeral, for grid4 just enter 4.'),
),
'sidebar_second_width' => array(
'#type' => 'textfield',
'#title' => t('Sidebar second grid size'),
'#default_value' => theme_get_setting('sidebar_second_width'),
'#description' => t('Enter only the numeral, for grid4 just enter 4.'),
),
'disable_drill_down' => array(
'#type' => 'checkbox',
'#title' => t('Disable drill-down menus'),
'#default_value' => theme_get_setting('disable_drill_down'),
'#description' => t('Turns off changing the navigation if you are 2+ levels deep with even deeper enabled menu links.'),
),
'zen_forms' => array(
'#type' => 'checkbox',
'#title' => t('Use zen forms'),
'#default_value' => theme_get_setting('zen_forms'),
'#description' => t('Transforms all forms into the list-based zen forms.'),
),
'wdn_beta' => array(
'#type' => 'checkbox',
'#title' => t('Use WDN beta/development CSS and JavaScript'),
'#default_value' => theme_get_setting('wdn_beta'),
'#description' => t('Replaces the links in <head> to the stable /wdn directory with the latest development versions.'),
'#access' => _unl_wdn_use_wdn_beta(),
),
'unl_affiliate' => array(
'#type' => 'checkbox',
'#title' => t('Affiliate site'),
'#default_value' => theme_get_setting('unl_affiliate'),
'#description' => t('Grants access to the Color scheme picker, Logo image settings, Shortcut icon settings on this page for customizing the UNL template.'),
),
);
$form['#submit'][] = 'unl_wdn_form_system_theme_settings_submit';
_unl_wdn_attach_syntax_highlighting($form['unl_head']);
}
/**
* Form submit callback.
*/
function unl_wdn_form_system_theme_settings_submit($form, &$form_state) {
// Delete existing files, then save them.
foreach (array('css', 'js') as $type) {
_unl_wdn_delete_file('custom.' . $type);
if (drupal_strlen(trim($form_state['values']['unl_' . $type])) !== 0) {
_unl_wdn_save_file($form_state['values']['unl_' . $type], 'custom.' . $type);
drupal_set_message('File saved to custom/custom.' . $type . ' and will be automatically included on all pages.');
}
}
drupal_flush_all_caches();
}
/**
* Saves CSS & Javascript in the file system (but only if not empty).
*/
function _unl_wdn_save_file($data, $filename) {
$path = variable_get('unl_custom_code_path', 'public://custom');
file_prepare_directory($path, FILE_CREATE_DIRECTORY);
return file_unmanaged_save_data($data, $path . '/' . $filename, FILE_EXISTS_REPLACE);
}
/**
* Deletes CSS & Javascript from the file system (but only if it exists).
*/
function _unl_wdn_delete_file($filename) {
$path = variable_get('unl_custom_code_path', 'public://custom') . '/' . $filename;
if (file_exists($path)) {
return file_unmanaged_delete($path);
}
return FALSE;
}
/**
* Attaches syntax highlighting to a form element.
*/
function _unl_wdn_attach_syntax_highlighting(&$form, $css = TRUE, $js = TRUE) {
$form['#attached']['js'][] = 'sites/all/libraries/codemirror/lib/codemirror.js';
$form['#attached']['css'][] = 'sites/all/libraries/codemirror/lib/codemirror.css';
if ($css) {
$form['#attached']['js'][] = 'sites/all/libraries/codemirror/mode/css/css.js';
}
if ($js) {
$form['#attached']['js'][] = 'sites/all/libraries/codemirror/mode/javascript/javascript.js';
}
$form['#attached']['css'][] = 'sites/all/libraries/codemirror/theme/default.css';
$form['#attached']['js'][] = drupal_get_path('theme', 'unl_wdn') . '/codemirror/unl.js';
$form['#attached']['css'][] = drupal_get_path('theme', 'unl_wdn') . '/codemirror/unl.css';
}
/**
* Custom access function to determine if it is staging or live since the live site should not allow WDN dev code to be used.
* @TODO: Make this better using something other than site_name.
*/
function _unl_wdn_use_wdn_beta() {
$site_name = variable_get('site_name');
if (strpos($site_name, 'STAGING') === 0) {
return TRUE;
}
return FALSE;
}