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:
<?php
$plugin_is_filter = 500 | CLASS_PLUGIN;
$plugin_description = gettext('Allow a visitor to select the theme of the gallery.');
$plugin_author = "Stephen Billard (sbillard)";
$plugin_category = gettext('Admin');
$option_interface = 'themeSwitcher';
class themeSwitcher {
function __construct() {
global $_zp_gallery;
$themes = $_zp_gallery->getThemes();
foreach ($themes as $key => $theme) {
setOptionDefault('themeSwitcher_theme_' . $key, 1);
$themelist[$key] = getOption('themeSwitcher_theme_' . $key);
}
setOptionDefault('themeSwitcher_timeout', 60 * 2);
setOptionDefault('themeSwitcher_css', ".themeSwitcherControlLink {\n" .
" position: fixed;\n" .
" z-index: 10000;\n" .
" left: 0px;\n" .
" top: 0px;\n" .
" border-bottom: 1px solid #444;\n" .
" border-left: 1px solid #444;\n" .
" color: black;\n" .
" padding: 2px;\n" .
" background-color: #f5f5f5 !important;\n" .
"}\n"
);
setOptionDefault('themeSwitcher_css_loggedin', ".themeSwitcherControlLink {\n" .
" position: fixed;\n" .
" z-index: 10000;\n" .
" left: 0px;\n" .
" top: 30px;\n" .
" border-bottom: 1px solid #444;\n" .
" border-left: 1px solid #444;\n" .
" color: black;\n" .
" padding: 2px;\n" .
" background-color: #f5f5f5 !important;\n" .
"}\n"
);
setOptionDefault('themeSwitcher_adminOnly', 1);
}
function getOptionsSupported() {
global $_zp_gallery;
$themes = $_zp_gallery->getThemes();
$list = array();
foreach ($themes as $key => $theme) {
$list[$theme['name']] = 'themeSwitcher_theme_' . $key;
}
$options = array(gettext('Cookie duration') => array('key' => 'themeSwitcher_timeout', 'type' => OPTION_TYPE_TEXTBOX,
'desc' => gettext('The time in minutes that the theme switcher cookie lasts.')),
gettext('Selector CSS') => array('key' => 'themeSwitcher_css', 'type' => OPTION_TYPE_TEXTAREA,
'multilingual' => false,
'desc' => gettext('Change this box if you wish to style the theme switcher selector for your themes.')),
gettext('Selector CSS Loggedin') => array('key' => 'themeSwitcher_css_loggedin', 'type' => OPTION_TYPE_TEXTAREA,
'multilingual' => false,
'desc' => gettext('Change this box if you wish to style the theme switcher selector for your themes. Only if loggedin to cover the admin toolbox.')),
gettext('Private') => array('key' => 'themeSwitcher_adminOnly', 'type' => OPTION_TYPE_CHECKBOX,
'desc' => gettext('Only users with <em>Themes</em> rights will see the selector if this is checked.')),
gettext('Theme list') => array('key' => 'themeSwitcher_list', 'type' => OPTION_TYPE_CHECKBOX_UL,
'checkboxes' => $list,
'desc' => gettext('These are the themes that may be selected among.'))
);
return $options;
}
function handleOption($option, $currentValue) {
}
static function theme($theme) {
global $_zp_gallery;
$new = zp_getCookie('zpcms_themeswitcher_theme');
if ($new) {
if (array_key_exists($new, $_zp_gallery->getThemes())) {
$theme = $new;
}
}
return $theme;
}
static function head($css) {
global $_themeSwitcherThemelist;
if (getOption('themeSwitcher_css')) {
?>
<style type="text/css">
<?php
if(zp_loggedin()) {
echo zp_apply_filter('themeSwitcher_css', getOption('themeSwitcher_css_loggedin'));
} else {
echo zp_apply_filter('themeSwitcher_css', getOption('themeSwitcher_css'));
}
?>
</style>
<?php
}
?>
<script type="text/javascript">
function switchTheme(reloc) {
window.location = reloc.replace(/%t/, $('#themeSwitcher').val());
}
</script>
<?php
$_themeSwitcherThemelist = zp_apply_filter('themeSwitcher_head', $_themeSwitcherThemelist);
return $css;
}
static function controlLink($textIn = NULL) {
global $_zp_gallery, $_themeSwitcherThemelist, $_zp_gallery_page;
if (self::active()) {
$themes = array();
foreach ($_zp_gallery->getThemes() as $theme => $details) {
if ($_themeSwitcherThemelist[$theme]) {
if (getPlugin($_zp_gallery_page, $theme)) {
$themes[$details['name']] = $theme;
}
}
}
$text = $textIn;
if (empty($text)) {
$text = gettext('Theme');
}
$reloc = pathurlencode(trim(preg_replace('~themeSwitcher=.*?&~', '', getRequestURI() . '&'), '?&'));
if (strpos($reloc, '?')) {
$reloc .= '&themeSwitcher=%t';
} else {
$reloc .= '?themeSwitcher=%t';
}
$theme = $_zp_gallery->getCurrentTheme();
?>
<span class="themeSwitcherControlLink">
<span title="<?php echo gettext("Themes will not show in this list if selecting them would result in a “not found” error."); ?>">
<?php echo $text; ?>
<select name="themeSwitcher" id="themeSwitcher" onchange="switchTheme('<?php echo html_encode($reloc); ?>')">
<?php generateListFromArray(array($theme), $themes, false, true); ?>
</select>
</span>
<?php zp_apply_filter('themeSwitcher_Controllink', $theme); ?>
</span>
<?php
}
return $textIn;
}
static function active() {
global $_showNotLoggedin_real_auth;
if (is_object($_showNotLoggedin_real_auth)) {
$loggedin = $_showNotLoggedin_real_auth->getRights();
} else {
$loggedin = zp_loggedin();
}
return !getOption('themeSwitcher_adminOnly') || $loggedin & (ADMIN_RIGHTS | THEMES_RIGHTS);
}
}
$_themeSwitcherThemelist = array();
foreach ($_zp_gallery->getThemes() as $__key => $__theme) {
$set = getOption('themeSwitcher_theme_' . $__key);
if (is_null($set))
$set = 1;
$_themeSwitcherThemelist[$__key] = $set;
}
unset($__key);
unset($__theme);
if (isset($_GET['themeSwitcher'])) {
zp_setCookie('zpcms_themeswitcher_theme', sanitize($_GET['themeSwitcher']), getOption('themeSwitcher_timeout') * 60);
}
if (zp_getCookie('zpcms_themeswitcher_theme')) {
zp_register_filter('setupTheme', 'themeSwitcher::theme');
}
zp_register_filter('theme_head', 'themeSwitcher::head', 999);
zp_register_filter('theme_body_open', 'themeSwitcher::controlLink');
?>