Skip to content

Instantly share code, notes, and snippets.

@inogo
Last active August 29, 2015 14:06
Show Gist options
  • Save inogo/4e9b4d7dd5939655d328 to your computer and use it in GitHub Desktop.
Save inogo/4e9b4d7dd5939655d328 to your computer and use it in GitHub Desktop.
MODX Mobile Switch Context Plugin
<?php
/* see:
* http://rtfm.modx.com/revolution/2.x/administering-your-site/contexts/using-one-gateway-plugin-to-manage-multiple-domains
* "mobileContext" - mobile version context name
*/
if (!isset($scriptProperties['mobileContext']) || empty($scriptProperties['mobileContext'])) {
return;
}
/* don't execute if in the Manager */
if ($modx->context->get('key') == 'mgr') {
return;
}
/* get mobile context */
$mctx = $modx->getContext($scriptProperties['mobileContext']);
if ($mctx) {
if ($_SERVER['HTTP_HOST'] == $mctx->getOption('http_host')) {
$modx->switchContext($mctx->key);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment