1: <?php
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: $plugin_is_filter = 5|CLASS_PLUGIN;
78: $plugin_description = gettext('Select your theme based on the device connecting to your site');
79: $plugin_author = "Stephen Billard (sbillard)";
80:
81: $option_interface = 'mobileTheme';
82:
83: class mobileTheme {
84:
85: function __construct() {
86: }
87:
88: function getOptionsSupported() {
89: global $_zp_gallery;
90: $themes = array();
91: foreach ($_zp_gallery->getThemes() as $theme=>$details) {
92: $themes[$details['name']] = $theme;
93: }
94: $options = array(gettext('Phone theme') => array('key' => 'mobileTheme_phone', 'type' => OPTION_TYPE_SELECTOR,
95: 'selections'=>$themes,
96: 'null_selection' => gettext('gallery theme'),
97: 'desc' => gettext('Select the theme to be used when a phone device connects.')),
98: gettext('Tablet theme') => array('key' => 'mobileTheme_tablet', 'type' => OPTION_TYPE_SELECTOR,
99: 'selections'=>$themes,
100: 'null_selection' => gettext('gallery theme'),
101: 'desc' => gettext('Select the theme to be used when a tablet device connects.')),
102: gettext('Test mode') => array('key' => 'mobileTheme_test', 'type' => OPTION_TYPE_SELECTOR,
103: 'selections'=>array(gettext('Phone')=>'phone',gettext('Tablet')=>'tablet'),
104: 'null_selection' => gettext('live'),
105: 'desc' => gettext('Put the plugin in <em>test mode</em> and it will simulate the selected device. If <em>live</em> is selected operations are normal.'))
106: );
107: return $options;
108: }
109:
110: function handleOption($option, $currentValue) {
111: }
112:
113: 114: 115: 116: 117:
118: static function theme($theme) {
119: global $_zp_gallery;
120: $detect = new mobile();
121: if ($detect->isMobile()) {
122: if ($detect->isTablet()) {
123: $new = getOption('mobileTheme_tablet');
124: } else {
125: $new = getOption('mobileTheme_phone');
126: }
127: } else {
128: $new = false;
129: }
130: if ($new) {
131: if (array_key_exists($new, $_zp_gallery->getThemes())) {
132: $theme = $new;
133: }
134: }
135: return $theme;
136: }
137:
138: 139: 140: 141: 142:
143: static function controlLink($text=NULL, $before=NULL, $after=Null) {
144: $detect = new mobile();
145: if ($detect->isMobile()) {
146: if (zp_getCookie('mobileTheme_disable')) {
147: if (is_null($text)) {
148: $text = gettext('View the mobile gallery');
149: }
150: $enable = 'on';
151: } else {
152: if (is_null($text)) {
153: $text = gettext('View the normal gallery');
154: }
155: $enable = 'off';
156: }
157: if ($before) {
158: echo '<span class="beforetext">'.html_encode($before).'</span>';
159: }
160: if (MOD_REWRITE) {
161: $link = '?mobileTheme=' . $enable;
162: } else {
163: global $_zp_gallery_page, $_zp_current_images, $_zp_current_album, $_zp_current_zenpage_news, $_zp_current_category, $_zp_current_zenpage_page;
164: switch ($_zp_gallery_page) {
165: case 'index.php':
166: $link = 'index.php?mobileTheme=' . $enable;
167: break;
168: case 'gallery.php':
169: $link = 'index.php?p=gallery&mobileTheme=' . $enable;
170: break;
171: case 'album.php':
172: $link = $_zp_current_album->getLink(null) . '&mobileTheme=' . $enable;
173: break;
174: case 'image.php':
175: $link = $_zp_current_image->getLink(null) . '&mobileTheme=' . $enable;
176: break;
177: case 'news.php':
178: if (is_NewsArticle()) {
179: $link = html_encode($_zp_current_zenpage_news->getLink(null)) . '&mobileTheme=' . $enable;
180: } else if (is_NewsCategory()) {
181: $link = html_encode($_zp_current_category->getLink(null)) . '&mobileTheme=' . $enable;
182: } else {
183: $link = html_encode(getNewsIndexURL()) . '&mobileTheme=' . $enable;
184: }
185: break;
186: case 'pages.php':
187: $link = html_encode($_zp_current_zenpage_page->getLink()) . '&mobileTheme=' . $enable;
188: break;
189: default:
190: $link = html_encode($_zp_gallery_page) . '?mobileTheme=' . $enable;
191: break;
192: }
193: }
194: ?>
195: <span class="mobileThemeControlLink">
196:
197: <a href="<?php echo $link; ?>" rel="external">
198: <?php echo html_encode($text); ?>
199: </a>
200: </span>
201: <?php
202: if ($after) {
203: echo '<span class="aftertext">'.html_encode($after).'</span>';
204: }
205: }
206: }
207:
208: }
209:
210: require_once(SERVERPATH.'/'.ZENFOLDER.'/'.PLUGIN_FOLDER.'/mobileTheme/Mobile_Detect.php');
211:
212: class mobile extends Mobile_Detect {
213:
214: function __construct() {
215: parent::__construct();
216: }
217:
218: 219: 220: 221:
222: function isMobile($userAgent = NULL, $httpHeaders = NULL) {
223: if (getOption('mobileTheme_test')) {
224: return true;
225: }
226: return parent::isMobile();
227: }
228:
229: 230: 231: 232:
233: function isTablet($userAgent = NULL, $httpHeaders = NULL) {
234: if (getOption('mobileTheme_test')=='tablet') {
235: return true;
236: }
237: return parent::isTablet();
238: }
239:
240: }
241:
242: if (isset($_GET['mobileTheme'])) {
243: switch ($_GET['mobileTheme']) {
244: case 'on':
245: zp_setCookie('mobileTheme_disable', 0);
246: break;
247: case 'off':
248: zp_setCookie('mobileTheme_disable', 1);
249: break;
250: }
251: }
252:
253: if (!zp_getCookie('mobileTheme_disable')) {
254: zp_register_filter('setupTheme', 'mobileTheme::theme');
255: }
256:
257: ?>