Created
May 2, 2012 16:50
-
-
Save ramayac/2578149 to your computer and use it in GitHub Desktop.
CakePHP Mobile Component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* @author: Rodrigo Amaya | |
* @description: Detecta si el cliente es un navegador movil, según el user agent. | |
* Este componente esta basado en WPTap. | |
* | |
* File: /app/controllers/components/mobile.php | |
* | |
*/ | |
class MobileComponent extends Object { | |
public $useragents = array( | |
'iPhone/iPod' => 'iPhone|iPod|aspen|webmate', | |
'Android' => 'android|dream|cupcake', | |
'BlackBerry Storm' => 'blackberry9500|blackberry9530', | |
'Nokia' => 'series60|series40|nokia|Nokia', | |
'Apple iPad' => 'ipad|iPad', | |
'Opera' => 'opera mini|Opera Mobi|Presto', | |
'Palm' => 'pre\/|palm os|palm|hiptop|avantgo|plucker|xiino|blazer|elaine', | |
'Windows Smartphone' => 'iris|3g_t|windows ce|opera mobi|windows ce; smartphone;|windows ce; iemobile', | |
'Blackberry' => 'blackberry|Blackberry' | |
//solo para DEPURAR: | |
//'Chrome' => 'Chrome|chrome' | |
); | |
function mobileDetect() { | |
$container = $_SERVER['HTTP_USER_AGENT']; | |
//$this->log($container); | |
$mobile_current_id = null; | |
foreach ($this->useragents as $mobile_id => $useragent) { | |
$useragent = explode('|', $useragent); | |
foreach ($useragent as $agent) { | |
if (eregi($agent, $container)) { | |
$mobile_current_id = $mobile_id; | |
break; | |
} | |
} | |
} | |
return $mobile_current_id; | |
} | |
function isMobile(){ | |
if($this->mobileDetect() == null){ | |
return false; | |
} else { | |
return true; | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment