"android", "blackberry" => "blackberry", "iphone" => "(iphone|ipod)", "opera" => "opera mini", "palm" => "(avantgo|blazer|elaine|hiptop|palm|plucker|xiino)", "windows" => "(iemobile|ppc|smartphone|windows phone)", "generic" => "(kindle|mobile|mmp|midp|o2|pda|pocket|psp|symbian|smartphone|treo|up.browser|up.link|vodafone|wap)", "ipad" => "ipad" ); /** * Constructor * * @access public * @return void */ public function __construct() { $this->_useragent = $_SERVER['HTTP_USER_AGENT']; foreach ($this->_devices as $device => $regexp) { if ($this->IsDevice($device) && $this->_isMobile == FALSE) { $this->_isMobile = true; } } } /** * Check if surfing with a particular device * * @access private * @param string $device * @return bool */ private function IsDevice($device) { $var = "Is" . ucfirst($device); $return = @$this->$var === null ? (bool) preg_match("/" . $this->_devices[strtolower($device)] . "/i", $this->_useragent) : $this->$var; if ($device != 'generic' && $return == true) { $this->_isGeneric = false; } return $return; } /** * Get the device type * * @param public * @return string */ public function GetDevice(){ foreach($this->_devices as $device_string => $regex){ if( $this->IsDevice($device_string) ){ return $device_string; } } return self::DEVICE_NORMAL; } /** * Call methods like this IsMobile() | IsAndroid() | IsIphone() | IsBlackberry() | IsOpera() | IsPalm() | IsWindows() | IsGeneric() | IsIpad() through IsDevice() * * @access public * @param string $name * @param array $arguments * @return bool */ public function __call($name, $arguments) { $device = substr($name, 2); if ($name == "Is" . ucfirst($device)) { return $this->IsDevice($device); } else { trigger_error("Method $name is not defined", E_USER_ERROR); } } /** * Returns true if surfing on a mobile device * * @access public * @return bool */ public function IsMobile() { return $this->_isMobile; } }