1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20:
21: $plugin_is_filter = 500 | CLASS_PLUGIN;
22: $plugin_description = gettext('Allow a visitor to select the theme of the gallery.');
23: $plugin_author = "Stephen Billard (sbillard)";
24:
25: $option_interface = 'themeSwitcher';
26:
27: class themeSwitcher {
28:
29: function __construct() {
30: global $_zp_gallery;
31: $themes = $_zp_gallery->getThemes();
32: foreach ($themes as $key => $theme) {
33: setOptionDefault('themeSwitcher_theme_' . $key, 1);
34: $themelist[$key] = getOption('themeSwitcher_theme_' . $key);
35: }
36: setOptionDefault('themeSwitcher_timeout', 60 * 2);
37: setOptionDefault('themeSwitcher_css', ".themeSwitcherControlLink {\n" .
38: " position: fixed;\n" .
39: " z-index: 10000;\n" .
40: " left: 0px;\n" .
41: " top: 0px;\n" .
42: " border-bottom: 1px solid #444;\n" .
43: " border-left: 1px solid #444;\n" .
44: " color: black;\n" .
45: " padding: 2px;\n" .
46: " background-color: #f5f5f5 !important;\n" .
47: "}\n"
48: );
49: setOptionDefault('themeSwitcher_css_loggedin', ".themeSwitcherControlLink {\n" .
50: " position: fixed;\n" .
51: " z-index: 10000;\n" .
52: " left: 0px;\n" .
53: " top: 30px;\n" .
54: " border-bottom: 1px solid #444;\n" .
55: " border-left: 1px solid #444;\n" .
56: " color: black;\n" .
57: " padding: 2px;\n" .
58: " background-color: #f5f5f5 !important;\n" .
59: "}\n"
60: );
61: setOptionDefault('themeSwitcher_adminOnly', 1);
62: }
63:
64: function getOptionsSupported() {
65: global $_zp_gallery;
66: $themes = $_zp_gallery->getThemes();
67: $list = array();
68: foreach ($themes as $key => $theme) {
69: $list[$theme['name']] = 'themeSwitcher_theme_' . $key;
70: }
71: $options = array(gettext('Cookie duration') => array('key' => 'themeSwitcher_timeout', 'type' => OPTION_TYPE_TEXTBOX,
72: 'desc' => gettext('The time in minutes that the theme switcher cookie lasts.')),
73: gettext('Selector CSS') => array('key' => 'themeSwitcher_css', 'type' => OPTION_TYPE_TEXTAREA,
74: 'multilingual' => false,
75: 'desc' => gettext('Change this box if you wish to style the theme switcher selector for your themes.')),
76: gettext('Selector CSS Loggedin') => array('key' => 'themeSwitcher_css_loggedin', 'type' => OPTION_TYPE_TEXTAREA,
77: 'multilingual' => false,
78: '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.')),
79: gettext('Private') => array('key' => 'themeSwitcher_adminOnly', 'type' => OPTION_TYPE_CHECKBOX,
80: 'desc' => gettext('Only users with <em>Themes</em> rights will see the selector if this is checked.')),
81: gettext('Theme list') => array('key' => 'themeSwitcher_list', 'type' => OPTION_TYPE_CHECKBOX_UL,
82: 'checkboxes' => $list,
83: 'desc' => gettext('These are the themes that may be selected among.'))
84: );
85: return $options;
86: }
87:
88: function handleOption($option, $currentValue) {
89:
90: }
91:
92: 93: 94: 95: 96:
97: static function theme($theme) {
98: global $_zp_gallery;
99: $new = zp_getCookie('themeSwitcher_theme');
100: if ($new) {
101: if (array_key_exists($new, $_zp_gallery->getThemes())) {
102: $theme = $new;
103: }
104: }
105: return $theme;
106: }
107:
108: static function head($css) {
109: global $_themeSwitcherThemelist;
110: if (getOption('themeSwitcher_css')) {
111: ?>
112: <style type="text/css">
113: <?php
114: if(zp_loggedin()) {
115: echo zp_apply_filter('themeSwitcher_css', getOption('themeSwitcher_css_loggedin'));
116: } else {
117: echo zp_apply_filter('themeSwitcher_css', getOption('themeSwitcher_css'));
118: }
119: ?>
120: </style>
121: <?php
122: }
123: ?>
124: <script type="text/javascript">
125:
126: function switchTheme(reloc) {
127: window.location = reloc.replace(/%t/, $('#themeSwitcher').val());
128: }
129:
130: </script>
131: <?php
132: $_themeSwitcherThemelist = zp_apply_filter('themeSwitcher_head', $_themeSwitcherThemelist);
133: return $css;
134: }
135:
136: 137: 138: 139: 140:
141: static function controlLink($textIn = NULL) {
142: global $_zp_gallery, $_themeSwitcherThemelist, $_zp_gallery_page;
143: if (self::active()) {
144: $themes = array();
145: foreach ($_zp_gallery->getThemes() as $theme => $details) {
146: if ($_themeSwitcherThemelist[$theme]) {
147: if (getPlugin($_zp_gallery_page, $theme)) {
148: $themes[$details['name']] = $theme;
149: }
150: }
151: }
152: $text = $textIn;
153: if (empty($text)) {
154: $text = gettext('Theme');
155: }
156: $reloc = pathurlencode(trim(preg_replace('~themeSwitcher=.*?&~', '', getRequestURI() . '&'), '?&'));
157: if (strpos($reloc, '?')) {
158: $reloc .= '&themeSwitcher=%t';
159: } else {
160: $reloc .= '?themeSwitcher=%t';
161: }
162: $theme = $_zp_gallery->getCurrentTheme();
163: ?>
164: <span class="themeSwitcherControlLink">
165: <span title="<?php echo gettext("Themes will not show in this list if selecting them would result in a “not error."); ?>">
166: <?php echo $text; ?>
167: <select name="themeSwitcher" id="themeSwitcher" onchange="switchTheme('<?php echo html_encode($reloc); ?>')">
168: <?php generateListFromArray(array($theme), $themes, false, true); ?>
169: </select>
170: </span>
171: <?php zp_apply_filter('themeSwitcher_Controllink', $theme); ?>
172: </span>
173: <?php
174: }
175: return $textIn;
176: }
177:
178: static function active() {
179: global $_showNotLoggedin_real_auth;
180: if (is_object($_showNotLoggedin_real_auth)) {
181: $loggedin = $_showNotLoggedin_real_auth->getRights();
182: } else {
183: $loggedin = zp_loggedin();
184: }
185: return !getOption('themeSwitcher_adminOnly') || $loggedin & (ADMIN_RIGHTS | THEMES_RIGHTS);
186: }
187:
188: }
189:
190: $_themeSwitcherThemelist = array();
191: foreach ($_zp_gallery->getThemes() as $__key => $__theme) {
192: $set = getOption('themeSwitcher_theme_' . $__key);
193: if (is_null($set))
194: $set = 1;
195: $_themeSwitcherThemelist[$__key] = $set;
196: }
197: unset($__key);
198: unset($__theme);
199: if (isset($_GET['themeSwitcher'])) {
200: zp_setCookie('themeSwitcher_theme', sanitize($_GET['themeSwitcher']), getOption('themeSwitcher_timeout') * 60);
201: }
202:
203: if (zp_getCookie('themeSwitcher_theme')) {
204: zp_register_filter('setupTheme', 'themeSwitcher::theme');
205: }
206: zp_register_filter('theme_head', 'themeSwitcher::head', 999);
207: zp_register_filter('theme_body_open', 'themeSwitcher::controlLink');
208: ?>