<?php

/**
 * Snippet to test if the visitor is using a mobile browser.
 *
 * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 * @package clearFusionCMS\snippet\isMobile
 * @copyright Copyright (c) 2012 clearFusionCMS. All rights reserved.
 * @link http://clearfusioncms.com
 */

/* @var $tplEngine cfTemplateEngine */
$request = $tplEngine->controller->getRequest();

// If not forced to desktop
$isMobile = false;
if(!$request->hasCookie('__usedesktopsite')) {
	// Set a session cookie if forced to desktop
	if($request->hasParam('usedesktopsite'))
		$tplEngine->controller->getResponse()->setCookie('__usedesktopsite', 1);
	else
		$isMobile = $request->isMobile();
}

// If redirect given
if(isset($redirectTo)) {
	if($isMobile)
		$tplEngine->controller->getResponse()->redirectTo($redirectTo);
}
else
	echo $isMobile ? '1' : '0';
