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: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260:
<?php
$plugin_is_filter = 5|CLASS_PLUGIN;
$plugin_description = gettext('Select your theme based on the device connecting to your site');
$plugin_author = "Stephen Billard (sbillard)";
$plugin_category = gettext('Misc');
$option_interface = 'mobileTheme';
class mobileTheme {
function __construct() {
}
function getOptionsSupported() {
global $_zp_gallery;
$themes = array();
foreach ($_zp_gallery->getThemes() as $theme=>$details) {
$themes[$details['name']] = $theme;
}
$options = array(gettext('Phone theme') => array('key' => 'mobileTheme_phone', 'type' => OPTION_TYPE_SELECTOR,
'selections'=>$themes,
'null_selection' => gettext('gallery theme'),
'desc' => gettext('Select the theme to be used when a phone device connects.')),
gettext('Tablet theme') => array('key' => 'mobileTheme_tablet', 'type' => OPTION_TYPE_SELECTOR,
'selections'=>$themes,
'null_selection' => gettext('gallery theme'),
'desc' => gettext('Select the theme to be used when a tablet device connects.')),
gettext('Test mode') => array('key' => 'mobileTheme_test', 'type' => OPTION_TYPE_SELECTOR,
'selections'=>array(gettext('Phone')=>'phone',gettext('Tablet')=>'tablet'),
'null_selection' => gettext('live'),
'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.'))
);
return $options;
}
function handleOption($option, $currentValue) {
}
static function theme($theme) {
global $_zp_gallery;
$detect = new mobile();
if ($detect->isMobile()) {
if ($detect->isTablet()) {
$new = getOption('mobileTheme_tablet');
} else {
$new = getOption('mobileTheme_phone');
}
} else {
$new = false;
}
if ($new) {
if (array_key_exists($new, $_zp_gallery->getThemes())) {
$theme = $new;
}
}
return $theme;
}
static function controlLink($text=NULL, $before=NULL, $after=Null) {
$detect = new mobile();
if ($detect->isMobile()) {
if (zp_getCookie('zpcms_mobiletheme')) {
if (is_null($text)) {
$text = gettext('View the mobile gallery');
}
$enable = 'on';
} else {
if (is_null($text)) {
$text = gettext('View the normal gallery');
}
$enable = 'off';
}
if ($before) {
echo '<span class="beforetext">'.html_encode($before).'</span>';
}
if (MOD_REWRITE) {
$link = '?mobileTheme=' . $enable;
} else {
global $_zp_gallery_page, $_zp_current_images, $_zp_current_album, $_zp_current_zenpage_news, $_zp_current_category, $_zp_current_zenpage_page;
switch ($_zp_gallery_page) {
case 'index.php':
$link = 'index.php?mobileTheme=' . $enable;
break;
case getCustomGalleryIndexPage():
$link = 'index.php?p=' . stripSuffix(getCustomGalleryIndexPage()) . '&mobileTheme=' . $enable;
break;
case 'album.php':
$link = $_zp_current_album->getLink(null) . '&mobileTheme=' . $enable;
break;
case 'image.php':
$link = $_zp_current_image->getLink(null) . '&mobileTheme=' . $enable;
break;
case 'news.php':
if (is_NewsArticle()) {
$link = html_encode($_zp_current_zenpage_news->getLink(null)) . '&mobileTheme=' . $enable;
} else if (is_NewsCategory()) {
$link = html_encode($_zp_current_category->getLink(null)) . '&mobileTheme=' . $enable;
} else {
$link = html_encode(getNewsIndexURL()) . '&mobileTheme=' . $enable;
}
break;
case 'pages.php':
$link = html_encode($_zp_current_zenpage_page->getLink()) . '&mobileTheme=' . $enable;
break;
default:
$link = html_encode($_zp_gallery_page) . '?mobileTheme=' . $enable;
break;
}
}
?>
<span class="mobileThemeControlLink">
<a href="<?php echo $link; ?>" rel="external">
<?php echo html_encode($text); ?>
</a>
</span>
<?php
if ($after) {
echo '<span class="aftertext">'.html_encode($after).'</span>';
}
}
}
}
require_once(SERVERPATH.'/'.ZENFOLDER.'/'.PLUGIN_FOLDER.'/mobileTheme/Mobile_Detect.php');
class mobile extends Mobile_Detect {
function __construct() {
parent::__construct();
}
function isMobile($userAgent = NULL, $httpHeaders = NULL) {
if (getOption('mobileTheme_test')) {
return true;
}
return parent::isMobile();
}
function isTablet($userAgent = NULL, $httpHeaders = NULL) {
if (getOption('mobileTheme_test')=='tablet') {
return true;
}
return parent::isTablet();
}
}
if (isset($_GET['mobileTheme'])) {
switch ($_GET['mobileTheme']) {
case 'on':
zp_setCookie('zpcms_mobiletheme', 0);
break;
case 'off':
zp_setCookie('zpcms_mobiletheme', 1);
break;
}
}
if (!zp_getCookie('zpcms_mobiletheme')) {
zp_register_filter('setupTheme', 'mobileTheme::theme');
}
?>