function styleswitcher_active_style_path in Style Switcher 7.2
Same name and namespace in other branches
- 6.2 styleswitcher.module \styleswitcher_active_style_path()
Finds the style active for current user and returns its path.
This function is called at every page request before styleswitcher_switch() or JS' Drupal.styleSwitcher.switchStyle() so we can update old user cookies here once and not bother about it in other places.
Parameters
string $theme: Name of the theme to find the active style for.
Return value
string|null The path property of active style. It can be NULL if active style is the blank one.
See also
Drupal.styleSwitcher.switchStyle()
1 call to styleswitcher_active_style_path()
- styleswitcher_css in ./
styleswitcher.module - Page callback: Redirects to CSS file of currently active style.
File
- ./
styleswitcher.module, line 686 - Module's hooks implementations and helper functions.
Code
function styleswitcher_active_style_path($theme) {
if (isset($_COOKIE['styleswitcher'])) {
$cookie = $_COOKIE['styleswitcher'];
if (!is_array($cookie)) {
// This style with its settings belongs to the theme which was default
// before styleswitcher_update_7206(). If there's no variable, try the
// default theme, it could still be the same one.
$style_theme = variable_get('styleswitcher_7206_theme_default', variable_get('theme_default', 'bartik'));
if (strpos($cookie, '/')) {
if (styleswitcher_style_load($cookie, $style_theme)) {
$name = $cookie;
}
}
elseif (($style = styleswitcher_style_load($cookie, $style_theme, 'theme')) || ($style = styleswitcher_style_load($cookie, $style_theme, 'custom'))) {
$name = $style['name'];
}
// Remove this old cookie.
setcookie('styleswitcher', '', 0, base_path());
$cookie = array();
if (isset($name)) {
// And save the new one.
styleswitcher_save_user_preference($style_theme, $name);
$cookie[$style_theme] = $name;
}
}
if (isset($cookie[$theme])) {
$active = styleswitcher_style_load($cookie[$theme], $theme);
}
}
elseif (isset($_COOKIE['styleSwitcher'])) {
$name = 'theme/' . _styleswitcher_style_name($_COOKIE['styleSwitcher']);
// Remove this old cookie.
setcookie('styleSwitcher', '', 0, base_path());
// We actually do not know what theme was used (it was a global $theme) when
// user switched to this style. So let us just set this style as active for
// every theme which has a style with this name.
foreach (array_keys(list_themes()) as $style_theme) {
if ($style = styleswitcher_style_load($name, $style_theme)) {
styleswitcher_save_user_preference($style_theme, $name);
if ($theme == $style_theme) {
$active = $style;
}
}
}
}
if (empty($active)) {
$active = styleswitcher_style_load(styleswitcher_default_style_key($theme), $theme);
}
return $active['path'];
}