| 1 |
<?php |
<?php |
| 2 |
// $Id: switchtheme.module,v 1.10.2.5 2008/11/02 13:32:56 sun Exp $ |
// $Id: switchtheme.module,v 1.10.2.6 2009/08/02 23:42:17 sun Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 173 |
function switchtheme_switch_form_submit($form, &$form_state) { |
function switchtheme_switch_form_submit($form, &$form_state) { |
| 174 |
global $user; |
global $user; |
| 175 |
|
|
| 176 |
if ($user->uid > 0) { |
$themes = switchtheme_options(); |
| 177 |
// Save the setting for authenticated users, if the "select different theme" |
// Bail out if we do not have a valid theme name. |
| 178 |
// permission has been granted. |
if (empty($form_state['values']['theme']) || !isset($themes[$form_state['values']['theme']])) { |
| 179 |
if (user_access('select different theme')) { |
return; |
| 180 |
$user = user_save($user, array('theme' => $form_state['values']['theme'])); |
} |
| 181 |
} |
// Save the setting for authenticated users, if the "select different theme" |
| 182 |
// Otherwise save the setting in the session, just like for anonymous users. |
// permission has been granted. |
| 183 |
else { |
if ($user->uid > 0 && user_access('select different theme')) { |
| 184 |
$_SESSION['custom_theme'] = $form_state['values']['theme']; |
$user = user_save($user, array('theme' => $form_state['values']['theme'])); |
|
} |
|
| 185 |
} |
} |
| 186 |
|
// Otherwise save the setting in the user's session. |
| 187 |
elseif (user_access('switch theme')) { |
elseif (user_access('switch theme')) { |
|
// Save the setting in the session for anonymous users. |
|
| 188 |
$_SESSION['custom_theme'] = $form_state['values']['theme']; |
$_SESSION['custom_theme'] = $form_state['values']['theme']; |
| 189 |
} |
} |
| 190 |
} |
} |
| 195 |
* @todo Probably should come back here and cache the theme list. |
* @todo Probably should come back here and cache the theme list. |
| 196 |
*/ |
*/ |
| 197 |
function switchtheme_options() { |
function switchtheme_options() { |
|
$options = array(); |
|
| 198 |
$themes = list_themes(); |
$themes = list_themes(); |
| 199 |
foreach ($themes as $name => $attr) { |
foreach ($themes as $name => $attr) { |
| 200 |
if ($attr->status) { |
if ($attr->status) { |
| 201 |
$options[] = $attr->name; |
$options[$attr->name] = $attr->name; |
| 202 |
} |
} |
| 203 |
} |
} |
| 204 |
return $options; |
return $options; |