1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Generate or get classes, mainly classes used on the body element and called
|
6 |
|
|
* via themename_preprocess_html().
|
7 |
|
|
*/
|
8 |
|
|
|
9 |
|
|
/**
|
10 |
|
|
* Return an array of classes to be used for body classes in html.tpl.php
|
11 |
|
|
*
|
12 |
|
|
* @param $vars, passed in the adaptivetheme_preprocess_html()
|
13 |
|
|
* @param $theme_name, the active theme.
|
14 |
|
|
*/
|
15 |
74f6bef0
|
Assos Assos
|
function at_generate_html_classes(&$vars, $theme_name) {
|
16 |
85ad3d82
|
Assos Assos
|
$classes_array = &drupal_static(__FUNCTION__, array());
|
17 |
|
|
if (empty($classes_array)) {
|
18 |
|
|
|
19 |
|
|
// Add a body class if the site name is hidden - state driven dynamic
|
20 |
|
|
// classes are very useful and AT does this a lot
|
21 |
|
|
if (at_get_setting('toggle_name', $theme_name) === 0) {
|
22 |
|
|
$classes_array[] = 'site-name-hidden';
|
23 |
|
|
}
|
24 |
|
|
|
25 |
|
|
// Add debugging classes
|
26 |
|
|
if (at_get_setting('expose_regions', $theme_name) === 1 || at_get_setting('load_all_panels', $theme_name) === 1) {
|
27 |
|
|
$classes_array[] = 'debug-regions';
|
28 |
|
|
}
|
29 |
|
|
if (at_get_setting('load_all_panels', $theme_name) === 1 && drupal_is_front_page()) {
|
30 |
|
|
$classes_array[] = 'debug-panels';
|
31 |
|
|
}
|
32 |
|
|
|
33 |
74f6bef0
|
Assos Assos
|
// Base theme classes, I use these to aid in debugging clients themes, you
|
34 |
|
|
// could use them to hook a specific minor version. Note that version is
|
35 |
|
|
// only included in Drupal.org archives, its missing when you clone GIT.
|
36 |
|
|
$info = at_get_info('adaptivetheme');
|
37 |
|
|
if (isset($info['release'])) {
|
38 |
|
|
$classes_array[] = 'atr-' . $info['release'];
|
39 |
|
|
}
|
40 |
|
|
if (isset($info['version'])) {
|
41 |
|
|
$classes_array[] = 'atv-' . $info['version'];
|
42 |
|
|
}
|
43 |
|
|
|
44 |
85ad3d82
|
Assos Assos
|
// Extra Classes
|
45 |
|
|
if (at_get_setting('extra_page_classes', $theme_name) === 1) {
|
46 |
|
|
|
47 |
|
|
// Set a class based on the language
|
48 |
|
|
if (function_exists('locale')) {
|
49 |
|
|
$classes_array[] = 'lang-' . $vars['language']->language;
|
50 |
|
|
}
|
51 |
|
|
|
52 |
|
|
// Site name class, for multi site installs that need to target styles
|
53 |
|
|
// at each site seperately (mitigates things like block-id clashes)
|
54 |
|
|
if (!empty($vars['head_title_array']['name'])) {
|
55 |
|
|
$head_title = check_plain($vars['head_title_array']['name']);
|
56 |
|
|
$classes_array[] = 'site-name-' . drupal_html_class($head_title);
|
57 |
|
|
}
|
58 |
|
|
|
59 |
74f6bef0
|
Assos Assos
|
// Classes for theming based on section
|
60 |
85ad3d82
|
Assos Assos
|
if (!$vars['is_front']) {
|
61 |
74f6bef0
|
Assos Assos
|
$path = drupal_get_path_alias(check_plain($_GET['q']));
|
62 |
85ad3d82
|
Assos Assos
|
list($section, ) = explode('/', $path, 2);
|
63 |
|
|
$classes_array[] = drupal_html_class('section-' . $section);
|
64 |
|
|
}
|
65 |
|
|
}
|
66 |
|
|
|
67 |
|
|
// Set classes for views and panels pages
|
68 |
|
|
$vars['menu_item'] = menu_get_item();
|
69 |
|
|
switch ($vars['menu_item']['page_callback']) {
|
70 |
|
|
case 'views_page':
|
71 |
|
|
// Is this a Views page?
|
72 |
|
|
$classes_array[] = 'page-views';
|
73 |
|
|
break;
|
74 |
|
|
case 'page_manager_page_execute':
|
75 |
|
|
case 'page_manager_node_view':
|
76 |
|
|
case 'page_manager_contact_site':
|
77 |
|
|
// Is this a Panels page?
|
78 |
|
|
$classes_array[] = 'page-panels';
|
79 |
|
|
break;
|
80 |
|
|
}
|
81 |
|
|
}
|
82 |
|
|
|
83 |
|
|
return $classes_array;
|
84 |
|
|
}
|
85 |
|
|
|
86 |
|
|
/**
|
87 |
|
|
* Return an array of classes to be used for page classes in page.tpl.php
|
88 |
|
|
*
|
89 |
|
|
* @param $vars, passed in the adaptivetheme_preprocess_page()
|
90 |
|
|
* @param $theme_name, the active theme.
|
91 |
|
|
*/
|
92 |
74f6bef0
|
Assos Assos
|
function at_generate_page_classes(&$vars, $theme_name) {
|
93 |
85ad3d82
|
Assos Assos
|
$classes_array = &drupal_static(__FUNCTION__, array());
|
94 |
|
|
if (empty($classes_array)) {
|
95 |
|
|
|
96 |
|
|
// Site name classes
|
97 |
|
|
if (isset($vars['hide_site_name']) && $vars['hide_site_name'] === FALSE) {
|
98 |
|
|
if (at_get_setting('enable_heading_settings', $theme_name) === 1) {
|
99 |
|
|
$site_name_settings_array = array(
|
100 |
|
|
'site_name_case',
|
101 |
|
|
'site_name_weight',
|
102 |
|
|
'site_name_alignment',
|
103 |
|
|
'site_name_shadow',
|
104 |
|
|
);
|
105 |
|
|
foreach ($site_name_settings_array as $site_name_setting) {
|
106 |
|
|
if ($site_name_setting = at_get_setting($site_name_setting, $theme_name)) {
|
107 |
|
|
$classes_array[] = $site_name_setting;
|
108 |
|
|
}
|
109 |
|
|
}
|
110 |
|
|
}
|
111 |
|
|
}
|
112 |
|
|
|
113 |
|
|
// Slogan classes
|
114 |
|
|
if (isset($vars['site_slogan'])) {
|
115 |
|
|
if (at_get_setting('enable_heading_settings', $theme_name) === 1) {
|
116 |
|
|
$site_slogan_settings_array= array(
|
117 |
|
|
'site_slogan_case',
|
118 |
|
|
'site_slogan_weight',
|
119 |
|
|
'site_slogan_alignment',
|
120 |
|
|
'site_slogan_shadow',
|
121 |
|
|
);
|
122 |
|
|
foreach ($site_slogan_settings_array as $site_slogan_setting) {
|
123 |
|
|
if ($site_slogan_setting = at_get_setting($site_slogan_setting, $theme_name)) {
|
124 |
|
|
$classes_array[] = $site_slogan_setting;
|
125 |
|
|
}
|
126 |
|
|
}
|
127 |
|
|
}
|
128 |
|
|
}
|
129 |
|
|
|
130 |
|
|
// Block title classes
|
131 |
|
|
if (at_get_setting('enable_heading_settings', $theme_name) === 1) {
|
132 |
|
|
$block_title_settings_array = array(
|
133 |
|
|
'block_title_case',
|
134 |
|
|
'block_title_weight',
|
135 |
|
|
'block_title_alignment',
|
136 |
|
|
'block_title_shadow',
|
137 |
|
|
);
|
138 |
|
|
foreach ($block_title_settings_array as $setting) {
|
139 |
|
|
if ($block_title_setting = at_get_setting($setting, $theme_name)) {
|
140 |
|
|
$classes_array[] = $block_title_setting;
|
141 |
|
|
}
|
142 |
|
|
}
|
143 |
|
|
}
|
144 |
|
|
|
145 |
|
|
// Node title classes
|
146 |
|
|
if (at_get_setting('enable_heading_settings', $theme_name) === 1) {
|
147 |
|
|
$node_title_settings_array = array(
|
148 |
|
|
'node_title_case',
|
149 |
|
|
'node_title_weight',
|
150 |
|
|
'node_title_alignment',
|
151 |
|
|
'node_title_shadow',
|
152 |
|
|
);
|
153 |
|
|
foreach ($node_title_settings_array as $setting) {
|
154 |
|
|
if ($node_title_setting = at_get_setting($setting, $theme_name)) {
|
155 |
|
|
$classes_array[] = $node_title_setting;
|
156 |
|
|
}
|
157 |
|
|
}
|
158 |
|
|
}
|
159 |
|
|
|
160 |
|
|
// Comment title classes
|
161 |
|
|
if (at_get_setting('comments_hide_title', $theme_name) !== 1) {
|
162 |
|
|
if (at_get_setting('enable_heading_settings', $theme_name) === 1) {
|
163 |
|
|
$comment_title_settings_array = array(
|
164 |
|
|
'comment_title_case',
|
165 |
|
|
'comment_title_weight',
|
166 |
|
|
'comment_title_alignment',
|
167 |
|
|
'comment_title_shadow',
|
168 |
|
|
);
|
169 |
|
|
foreach ($comment_title_settings_array as $setting) {
|
170 |
|
|
if ($comment_title_setting = at_get_setting($setting, $theme_name)) {
|
171 |
|
|
$classes_array[] = $comment_title_setting;
|
172 |
|
|
}
|
173 |
|
|
}
|
174 |
|
|
}
|
175 |
|
|
}
|
176 |
|
|
|
177 |
|
|
// Page title classes
|
178 |
|
|
if (at_get_setting('enable_heading_settings', $theme_name) === 1) {
|
179 |
|
|
$page_title_settings_array = array(
|
180 |
|
|
'page_title_case',
|
181 |
|
|
'page_title_weight',
|
182 |
|
|
'page_title_alignment',
|
183 |
|
|
'page_title_shadow',
|
184 |
|
|
);
|
185 |
|
|
foreach ($page_title_settings_array as $setting) {
|
186 |
|
|
if ($page_title_setting = at_get_setting($setting, $theme_name)) {
|
187 |
|
|
$classes_array[] = $page_title_setting;
|
188 |
|
|
}
|
189 |
|
|
}
|
190 |
|
|
}
|
191 |
74f6bef0
|
Assos Assos
|
|
192 |
|
|
// Page class for at menu toggle
|
193 |
|
|
if (at_get_setting('enable_menu_toggle', $theme_name) === 1) {
|
194 |
|
|
$classes_array[] = 'at-mt';
|
195 |
|
|
}
|
196 |
85ad3d82
|
Assos Assos
|
}
|
197 |
|
|
|
198 |
|
|
return $classes_array;
|
199 |
|
|
}
|
200 |
|
|
|
201 |
|
|
/**
|
202 |
|
|
* Add classes for platforms and browsers.
|
203 |
|
|
* This is very simple and can never replace something like WURFL or Mobile
|
204 |
|
|
* Smart, in the future I intend to build a module to replace this.
|
205 |
74f6bef0
|
Assos Assos
|
* Note - this is too dangerous to namespace since legacy themes use it.
|
206 |
85ad3d82
|
Assos Assos
|
*
|
207 |
|
|
* @param null $ua
|
208 |
|
|
*/
|
209 |
|
|
function css_browser_selector($ua = NULL) {
|
210 |
|
|
if ($ua == NULL && !isset($_SERVER['HTTP_USER_AGENT'])) {
|
211 |
|
|
return;
|
212 |
|
|
}
|
213 |
|
|
$ua = ($ua) ? strtolower($ua) : strtolower($_SERVER['HTTP_USER_AGENT']);
|
214 |
|
|
|
215 |
|
|
$g = 'gecko';
|
216 |
|
|
$w = 'webkit';
|
217 |
|
|
$s = 'safari';
|
218 |
|
|
$o = 'opera';
|
219 |
|
|
|
220 |
|
|
$b = array();
|
221 |
|
|
if (!preg_match('/opera|webtv/i', $ua) && preg_match('/msie\s(\d)/', $ua, $array)) {
|
222 |
|
|
$b[] = 'ie ie' . $array[1];
|
223 |
|
|
}
|
224 |
|
|
elseif (strstr($ua, 'firefox')) {
|
225 |
|
|
$b[] = $g . ' firefox';
|
226 |
|
|
}
|
227 |
|
|
elseif (strstr($ua, 'gecko/')) {
|
228 |
|
|
$b[] = $g;
|
229 |
|
|
}
|
230 |
|
|
elseif (preg_match('/opera(\s|\/)(\d+)/', $ua, $array)) {
|
231 |
|
|
$b[] = $o;
|
232 |
|
|
}
|
233 |
|
|
elseif (strstr($ua, 'konqueror')) {
|
234 |
|
|
$b[] = 'konqueror';
|
235 |
|
|
}
|
236 |
|
|
elseif (strstr($ua, 'chrome')) {
|
237 |
|
|
$b[] = $w . ' chrome';
|
238 |
|
|
}
|
239 |
|
|
elseif (strstr($ua, 'applewebkit/')) {
|
240 |
|
|
$b[] = (preg_match('/version\/(\d+)/i', $ua, $array)) ? $w . ' ' . $s . ' ' . $s . $array[1] : $w . ' ' . $s;
|
241 |
|
|
}
|
242 |
|
|
elseif (strstr($ua, 'mozilla/')) {
|
243 |
|
|
$b[] = $g;
|
244 |
|
|
}
|
245 |
|
|
if (strstr($ua, 'j2me')) {
|
246 |
|
|
$b[] = 'mobile';
|
247 |
|
|
}
|
248 |
|
|
elseif (strstr($ua, 'iphone')) {
|
249 |
|
|
$b[] = 'iphone';
|
250 |
|
|
}
|
251 |
|
|
elseif (strstr($ua, 'ipod')) {
|
252 |
|
|
$b[] = 'ipod';
|
253 |
|
|
}
|
254 |
|
|
elseif (strstr($ua, 'ipad')) {
|
255 |
|
|
$b[] = 'ipad';
|
256 |
|
|
}
|
257 |
|
|
elseif (strstr($ua, 'android')) {
|
258 |
|
|
$b[] = 'android';
|
259 |
|
|
}
|
260 |
|
|
elseif (strstr($ua, 'googletv')) {
|
261 |
|
|
$b[] = 'googletv';
|
262 |
|
|
}
|
263 |
|
|
elseif (strstr($ua, 'xoom')) {
|
264 |
|
|
$b[] = 'xoom';
|
265 |
|
|
}
|
266 |
|
|
elseif (strstr($ua, 'nuvifone')) {
|
267 |
|
|
$b[] = 'nuvifone';
|
268 |
|
|
}
|
269 |
|
|
elseif (strstr($ua, 'symbian')) {
|
270 |
|
|
$b[] = 'symbian';
|
271 |
|
|
}
|
272 |
|
|
elseif (strstr($ua, 'blackberry')) {
|
273 |
|
|
$b[] = 'blackberry';
|
274 |
|
|
}
|
275 |
|
|
elseif (strstr($ua, 'windows phone os 7')) {
|
276 |
|
|
$b[] = 'windows-phone-7';
|
277 |
|
|
}
|
278 |
|
|
elseif (strstr($ua, 'windows ce')) {
|
279 |
|
|
$b[] = 'windows-ce';
|
280 |
|
|
}
|
281 |
|
|
elseif (strstr($ua, 'iemobile')) {
|
282 |
|
|
$b[] = 'iemobile';
|
283 |
|
|
}
|
284 |
|
|
elseif (strstr($ua, 'palm')) {
|
285 |
|
|
$b[] = 'palm';
|
286 |
|
|
}
|
287 |
|
|
elseif (strstr($ua, 'webos')) {
|
288 |
|
|
$b[] = 'webos';
|
289 |
|
|
}
|
290 |
|
|
elseif (strstr($ua, 'kindle')) {
|
291 |
|
|
$b[] = 'kindle';
|
292 |
|
|
}
|
293 |
|
|
elseif (strstr($ua, 'mac')) {
|
294 |
|
|
$b[] = 'mac';
|
295 |
|
|
}
|
296 |
|
|
elseif (strstr($ua, 'darwin')) {
|
297 |
|
|
$b[] = 'mac';
|
298 |
|
|
}
|
299 |
|
|
elseif (strstr($ua, 'webtv')) {
|
300 |
|
|
$b[] = 'webtv';
|
301 |
|
|
}
|
302 |
|
|
elseif (strstr($ua, 'win')) {
|
303 |
|
|
$b[] = 'win';
|
304 |
|
|
}
|
305 |
|
|
elseif (strstr($ua, 'freebsd')) {
|
306 |
|
|
$b[] = 'freebsd';
|
307 |
|
|
}
|
308 |
|
|
elseif (strstr($ua, 'x11') || strstr($ua, 'linux')) {
|
309 |
|
|
$b[] = 'linux';
|
310 |
|
|
}
|
311 |
|
|
return join(' ', $b);
|
312 |
|
|
}
|
313 |
|
|
|
314 |
|
|
/**
|
315 |
|
|
* Returns the active color scheme.
|
316 |
|
|
*
|
317 |
|
|
* Process the color info and return the active color scheme. We use this to
|
318 |
|
|
* load a body class for the active color scheme, very useful for CSS tweaks
|
319 |
|
|
* required for a particular scheme. This is not enabled by default, you have to
|
320 |
|
|
* call it in template_preprocess_html(). Mostly ripped from Color module.
|
321 |
74f6bef0
|
Assos Assos
|
* Note - this is too dangerous to namespace since legacy themes use it.
|
322 |
85ad3d82
|
Assos Assos
|
*
|
323 |
|
|
* @param $theme_name
|
324 |
|
|
*/
|
325 |
|
|
function get_color_scheme_name($theme_name) {
|
326 |
74f6bef0
|
Assos Assos
|
$scheme_name = &drupal_static(__FUNCTION__, array());
|
327 |
85ad3d82
|
Assos Assos
|
if (empty($scheme_name)) {
|
328 |
|
|
if (module_exists('color')) {
|
329 |
|
|
|
330 |
|
|
$info = color_get_info($theme_name);
|
331 |
|
|
$info['schemes'][''] = array('title' => t('Custom'), 'colors' => array());
|
332 |
|
|
$schemes = array();
|
333 |
|
|
|
334 |
|
|
foreach ($info['schemes'] as $key => $scheme) {
|
335 |
|
|
$schemes[$key] = $scheme['colors'];
|
336 |
|
|
}
|
337 |
|
|
|
338 |
|
|
$current_scheme = variable_get('color_' . $theme_name . '_palette', array());
|
339 |
|
|
|
340 |
|
|
foreach ($schemes as $key => $scheme) {
|
341 |
|
|
if ($current_scheme == $scheme) {
|
342 |
|
|
$scheme_name = $key;
|
343 |
|
|
break;
|
344 |
|
|
}
|
345 |
|
|
}
|
346 |
|
|
if (empty($scheme_name)) {
|
347 |
|
|
if (empty($current_scheme)) {
|
348 |
|
|
$scheme_name = 'default';
|
349 |
|
|
}
|
350 |
|
|
else {
|
351 |
|
|
$scheme_name = 'custom';
|
352 |
|
|
}
|
353 |
|
|
}
|
354 |
|
|
}
|
355 |
|
|
}
|
356 |
|
|
|
357 |
|
|
return $scheme_name;
|
358 |
|
|
}
|
359 |
74f6bef0
|
Assos Assos
|
|
360 |
|
|
/**
|
361 |
|
|
* Generate default classes for Panels layouts
|
362 |
|
|
* Done because for some unknown reason setting these
|
363 |
|
|
* in template_preprocess does not work, aka the variable
|
364 |
|
|
* does not appear in the panel layout preprocess function.
|
365 |
|
|
*/
|
366 |
|
|
function at_panels_classes_array() {
|
367 |
|
|
$output = array(
|
368 |
|
|
'at-panel',
|
369 |
|
|
'panel-display',
|
370 |
|
|
'clearfix',
|
371 |
|
|
);
|
372 |
|
|
|
373 |
|
|
return $output;
|
374 |
|
|
} |