-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy paththeme-settings.php
More file actions
238 lines (214 loc) · 9.36 KB
/
theme-settings.php
File metadata and controls
238 lines (214 loc) · 9.36 KB
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
<?php
/**
* @file
* theme-settings.php
*
* Theme settings file for Bootstrap Lite.
*/
function bootstrap_lite_form_system_theme_settings_alter(&$form, &$form_state, $form_id = NULL) {
if (isset($form_id)) {
return;
}
$theme_name = $form['theme']['#value'];
$form['bootstrap'] = array(
'#type' => 'vertical_tabs',
'#attached' => array(
'js' => array(backdrop_get_path('theme', 'bootstrap_lite') . '/js/theme-settings.js'),
),
'#prefix' => '<h2><small>' . t('Bootstrap Settings') . '</small></h2>',
'#weight' => -10,
);
backdrop_add_css(backdrop_get_path('theme', 'bootstrap_lite') . '/css/settings.css');
// Version and CDN.
$form['bootstrap_lite_cdn'] = array(
'#type' => 'fieldset',
'#title' => t('Version and CDN'),
'#description' => t('You may use the !bootstrapcdn or choose the bundled library to serve the Bootstrap framework files. If you disable these settings, you must provide your own Bootstrap source and/or optional CDN delivery implementation. !warning', array(
'!bootstrapcdn' => l(t('Bootstrap CDN'), 'http://bootstrapcdn.com', array(
'external' => TRUE,
)),
'!warning' => '<div class="alert alert-info messages info"><strong>' . t('NOTE') . ':</strong> ' . t('While the BootstrapCDN (content distribution network) is the preferred method for providing performance gains in load time, this method does depend on using this third party service. BootstrapCDN is under no obligation or commitment to provide guaranteed up-time or service quality for this theme.') . '</div>',
)),
'#group' => 'bootstrap',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['bootstrap_lite_cdn']['bootstrap_lite_cdn'] = array(
'#type' => 'select',
'#title' => t('Bootstrap version'),
'#options' => array(
'3.3.5' => t('3.3.5 (CDN)'),
'3.3.6' => t('3.3.6 (CDN)'),
'3.3.7' => t('3.3.7 (CDN)'),
'3.4.0' => t('3.4.0 (CDN)'),
'3.4.1' => t('3.4.1 (CDN)'),
'module' => t('3.4.1 (bundled)'),
),
'#default_value' => theme_get_setting('bootstrap_lite_cdn', $theme_name),
'#empty_option' => t('Disabled'),
'#empty_value' => NULL,
);
$form['bootstrap_lite_cdn']['bootstrap_lite_font_awesome'] = array(
'#type' => 'select',
'#title' => t('Font Awesome version'),
'#options' => array(
'4.4.0' => t('4.4.0 (CDN)'),
'4.7.0' => t('4.7.0 (CDN)'),
'module' => t('4.7.0 (bundled)'),
),
'#default_value' => theme_get_setting('bootstrap_lite_font_awesome', $theme_name),
'#empty_option' => t('Disabled'),
'#empty_value' => NULL,
);
// Bootswatch
$bootswatch_themes = array();
$default_theme_details = array(
'name' => t('Default'),
'description' => t('Pure Bootstrap CSS'),
'thumbnail' => base_path() . backdrop_get_path('theme', 'bootstrap_lite') . '/preview.jpg',
);
$bootswatch_themes[''] = bootstrap_bootswatch_template($default_theme_details);
$request = backdrop_http_request('https://bootswatch.com/api/3.json');
if ($request && $request->code === '200' && !empty($request->data)) {
if (($api = backdrop_json_decode($request->data)) && is_array($api) && !empty($api['themes'])) {
foreach ($api['themes'] as $bootswatch_theme) {
$bootswatch_themes[strtolower($bootswatch_theme['name'])] = bootstrap_bootswatch_template($bootswatch_theme);
}
}
}
$form['bootswatch'] = array(
'#type' => 'fieldset',
'#title' => t('Bootswatch theme'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#group' => 'bootstrap',
'#description' => t('You can use the default Bootstrap theme or a Bootswatch theme, which you can choose here. If you selected a CDN version of Bootstrap, the Bootswatch theme will be served up from the !bootstrapcdn; otherwise it will use the bundled version.', array(
'!bootstrapcdn' => l(t('BootstrapCDN'), 'http://bootstrapcdn.com', array(
'external' => TRUE,
)),
)),
);
$form['bootswatch']['bootstrap_lite_bootswatch'] = array(
'#type' => 'radios',
'#default_value' => theme_get_setting('bootstrap_lite_bootswatch', $theme_name),
'#options' => $bootswatch_themes,
'#empty_option' => t('Disabled'),
'#empty_value' => NULL,
'#prefix' => '<div class="section-preview">',
'#suffix' => '</div>',
);
if (empty($bootswatch_themes)) {
$form['bootswatch']['bootstrap_lite_bootswatch']['#prefix'] = '<div class="alert alert-danger messages error"><strong>' . t('ERROR') . ':</strong> ' . t('Unable to reach Bootswatch API. Please ensure the server your website is hosted on is able to initiate HTTP requests.') . '</div>';
}
// Navbar
$form['navbar'] = array(
'#type' => 'fieldset',
'#title' => t('Navbar'),
'#description' => t('Navigation bar settings.'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#group' => 'bootstrap',
);
$form['navbar']['bootstrap_lite_navbar_position'] = array(
'#type' => 'select',
'#title' => t('Navbar Position'),
'#description' => t('Select your Navbar position.'),
'#default_value' => theme_get_setting('bootstrap_lite_navbar_position', $theme_name),
'#options' => array(
'static-top' => t('Static Top'),
'fixed-top' => t('Fixed Top'),
'fixed-bottom' => t('Fixed Bottom'),
),
'#empty_option' => t('Normal'),
);
$form['navbar']['bootstrap_lite_navbar_menu_position'] = array(
'#type' => 'select',
'#title' => t('Navbar Menu Position'),
'#description' => t('Select your Navbar Menu position.'),
'#default_value' => theme_get_setting('bootstrap_lite_navbar_menu_position', $theme_name),
'#options' => array(
'navbar-left' => t('Left'),
'navbar-right' => t('Right'),
),
'#empty_option' => t('Normal'),
);
$form['navbar']['bootstrap_lite_navbar_inverse'] = array(
'#type' => 'checkbox',
'#title' => t('Inverse navbar style'),
'#description' => t('Select if you want the inverse navbar style.'),
'#default_value' => theme_get_setting('bootstrap_lite_navbar_inverse', $theme_name),
);
$form['navbar']['bootstrap_lite_navbar_user_menu'] = array(
'#type' => 'checkbox',
'#title' => t('Add cog with user-menu'),
'#description' => t('Select if you want cog style right pulled popup menu.'),
'#default_value' => theme_get_setting('bootstrap_lite_navbar_user_menu', $theme_name),
);
// Breadcrumbs
$form['breadcrumbs'] = array(
'#type' => 'fieldset',
'#title' => t('Breadcrumbs'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#group' => 'bootstrap',
);
$form['breadcrumbs']['bootstrap_lite_breadcrumb_home'] = array(
'#type' => 'checkbox',
'#title' => t('Show "Home" breadcrumb link'),
'#default_value' => theme_get_setting('bootstrap_lite_breadcrumb_home', $theme_name),
'#description' => t('If your site has a module dedicated to handling breadcrumbs already, ensure this setting is enabled.'),
);
$form['breadcrumbs']['bootstrap_lite_breadcrumb_title'] = array(
'#type' => 'checkbox',
'#title' => t('Show current page title at end'),
'#default_value' => theme_get_setting('bootstrap_lite_breadcrumb_title', $theme_name),
'#description' => t('If your site has a module dedicated to handling breadcrumbs already, ensure this setting is disabled.'),
);
// Tweaks
$form['tweaks'] = array(
'#type' => 'fieldset',
'#title' => t('Tweaks'),
'#group' => 'bootstrap',
);
$form['tweaks']['bootstrap_lite_container'] = array(
'#type' => 'select',
'#title' => t('Container type'),
'#default_value' => theme_get_setting('bootstrap_lite_container', $theme_name),
'#description' => t('Switch between full width (fluid) or fixed (max 1170px) width.'),
'#options' => array(
'container' => t('Fixed'),
'container-fluid' => t('Fluid'),
)
);
$form['tweaks']['bootstrap_lite_datetime'] = array(
'#type' => 'checkbox',
'#title' => t('Show "XX time ago".'),
'#default_value' => theme_get_setting('bootstrap_lite_datetime', $theme_name),
'#description' => t('If enabled, replace date output for nodes and comments by "XX time ago".'),
);
$form['tweaks']['bootstrap_lite_image_responsive'] = array(
'#type' => 'checkbox',
'#title' => t('Responsive images'),
'#default_value' => theme_get_setting('bootstrap_lite_image_responsive', $theme_name),
'#description' => t('Images in Bootstrap 3 can be made responsive-friendly via the addition of the <code>.img-responsive</code> class. This applies <code>max-width: 100%;</code> and <code>height: auto;</code> to the image so that it scales nicely to the parent element.'),
);
}
function bootstrap_bootswatch_template($bootswatch_theme){
$output = '<div class="preview">';
if(isset($bootswatch_theme['thumbnail'])){
$output .= '<div class="image">
<img src="' . $bootswatch_theme['thumbnail']. '" class="img-responsive" alt="' . $bootswatch_theme['name'] . '">
</div>';
}
$output .= '<div class="options">
<h3>' . $bootswatch_theme['name'] . '</h3>
<p>' . $bootswatch_theme['description'] . '</p>';
if(isset($bootswatch_theme['preview'])){
$output .= '<div class="btn-group"><a class="btn btn-info" href="' . $bootswatch_theme['preview'] . '" target="_blank">' . t('Preview') . '</a></div>';
}else{
$output .= '<div class="btn-group"><a class="btn btn-default disabled" href="#" target="_blank">' . t('No preview') . '</a></div>';
}
$output .= '</div>
</div>';
return $output;
}