Looking at using this for our agency mobile site. I had to make a few modifications of my own though as we wanted to have the ability to switch between mobile and desktop versions (even if viewing on wrong environment). My code is a bit rough (more of a front-end guy) but I changed MobileSiteControllerExtension.php onBeforeInit function to this:
public function onBeforeInit() {
$config = SiteConfig::current_site_config();
$env = '';
//Get cookie value
if(isset($_COOKIE['env'])&&($_COOKIE['env']=="m"||$_COOKIE['env']=="d")){
$env = $_COOKIE['env'];
}
// Redirect users to the full site if requested (cookie expires in 30 minutes)
if(isset($_GET['env'])) {
if($_GET['env']=="d"){
$_COOKIE['env'] = "d";
setcookie('env', "d", time() + self::$cookie_expire_time);
$env = "d";
}elseif($_GET['env']=="m"){
$_COOKIE['env'] = "m";
setcookie('env', "m", time() + self::$cookie_expire_time);
$env = "m";
}
}
// Redirect to the full site if user requested
if($this->onMobileDomain() && $config->MobileSiteType == 'RedirectToDomain' && $env == "d") {
return $this->owner->redirect($config->FullSiteDomain);
} elseif($env == "d") {
return; // nothing more to be done
}
// If the user requested the mobile domain, set the right theme
if($this->onMobileDomain()) {
SSViewer::set_theme($config->MobileTheme);
}
// User just wants to see a theme, but no redirect occurs
if((MobileBrowserDetector::is_mobile()||$env=="m") && $config->MobileSiteType == 'MobileThemeOnly') {
SSViewer::set_theme($config->MobileTheme);
}
// If on a mobile device, but not on the mobile domain and has been setup for redirection
if(!$this->onMobileDomain() && (MobileBrowserDetector::is_mobile()||$env=="m") && $config->MobileSiteType == 'RedirectToDomain') {
return $this->owner->redirect($config->MobileDomain);
}
}
In order to switch to mobile, just add ?env=m, and to switch to desktop use ?env=d.
Sure someone else could make it a little more efficient though :)