public function testBasicMethods() { $this->assertNotEmpty($this->detect->getScriptVersion()); $this->detect->setHttpHeaders(array('SERVER_SOFTWARE' => 'Apache/2.2.15 (Linux) Whatever/4.0 PHP/5.2.13', 'REQUEST_METHOD' => 'POST', 'HTTP_HOST' => 'home.ghita.org', 'HTTP_X_REAL_IP' => '1.2.3.4', 'HTTP_X_FORWARDED_FOR' => '1.2.3.5', 'HTTP_CONNECTION' => 'close', 'HTTP_USER_AGENT' => 'Mozilla/5.0 (iPhone; CPU iPhone OS 6_0_1 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A523 Safari/8536.25', 'HTTP_ACCEPT' => 'text/vnd.wap.wml, application/json, text/javascript, */*; q=0.01', 'HTTP_ACCEPT_LANGUAGE' => 'en-us,en;q=0.5', 'HTTP_ACCEPT_ENCODING' => 'gzip, deflate', 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest', 'HTTP_REFERER' => 'http://mobiledetect.net', 'HTTP_PRAGMA' => 'no-cache', 'HTTP_CACHE_CONTROL' => 'no-cache', 'REMOTE_ADDR' => '11.22.33.44', 'REQUEST_TIME' => '01-10-2012 07:57')); //12 because only 12 start with HTTP_ $this->assertCount(12, $this->detect->getHttpHeaders()); $this->assertTrue($this->detect->checkHttpHeadersForMobile()); $this->detect->setUserAgent('Mozilla/5.0 (iPhone; CPU iPhone OS 6_0_1 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A523 Safari/8536.25'); $this->assertNotEmpty($this->detect->getUserAgent()); $this->assertTrue($this->detect->isMobile()); $this->assertFalse($this->detect->isTablet()); $this->assertTrue($this->detect->isIphone()); $this->assertTrue($this->detect->isiphone()); $this->assertTrue($this->detect->isiOS()); $this->assertTrue($this->detect->isios()); $this->assertTrue($this->detect->is('iphone')); $this->assertTrue($this->detect->is('ios')); }
function set_device($user_agent) { global $request_settings; $key = 'di_' . $user_agent; $cache_result = get_cache($key); if ($cache_result) { if (isset($cache_result['device_os'])) { $request_settings['device_os'] = $cache_result['device_os']; } $request_settings['main_device'] = $cache_result['main_device']; return true; } error_reporting(0); require_once 'modules/devicedetection/Mobile_Detect.php'; $detect = new Mobile_Detect($user_agent); if ($detect->isIphone()) { $temp['device_os'] = get_device_osversion(1, $user_agent); $temp['main_device'] = 'IPHONE'; } else { if ($detect->isIpad()) { $temp['device_os'] = get_device_osversion(1, $user_agent); $temp['main_device'] = 'IPAD'; } else { if ($detect->isIpod()) { $temp['device_os'] = get_device_osversion(1, $user_agent); $temp['main_device'] = 'IPOD'; } else { if ($detect->isAndroidOS()) { $temp['device_os'] = get_device_osversion(2, $user_agent); $temp['main_device'] = 'ANDROID'; } else { if ($detect->ismobile()) { $temp['main_device'] = 'OTHER'; } else { $temp['main_device'] = 'NOMOBILE'; if (!MAD_SERVE_NOMOBILE) { print_error(1, 'This ad-server does not serve ads to non-mobile devices.', $request_settings['sdk'], 1); return false; } } } } } } if (isset($temp['device_os']) && !empty($temp['device_os'])) { $request_settings['device_os'] = $temp['device_os']; } $request_settings['main_device'] = $temp['main_device']; set_cache($key, $temp, 1500); }
</tbody> <tbody> <tr> <th colspan="2">Other tests</th> </tr> <tr> <td>isiphone()</td> <td><?php var_dump($detect->isiphone()); ?> </td> </tr> <tr> <td>isIphone()</td> <td><?php var_dump($detect->isIphone()); ?> </td> </tr> <tr> <td>istablet()</td> <td><?php var_dump($detect->istablet()); ?> </td> </tr> <tr> <td>isIOS()</td> <td><?php var_dump($detect->isIOS()); ?>
protected function _initDesign() { if (!$this->_request->isInstalling()) { $request = $this->_request; $this->_prepareBlocks(); } $locale = Zend_Registry::get('Zend_Locale'); $lang = Core_Model_Language::getCurrentLanguage(); $detect = new Mobile_Detect(); $this->getPluginLoader()->addPrefixPath('Siberian_Application_Resource', 'Siberian/Application/Resource'); if (!$this->_request->isInstalling()) { if ($this->_request->isApplication()) { $apptype = 'mobile'; } else { $apptype = 'desktop'; } if ($detect->isMobile() || $apptype == 'mobile') { $device_type = 'mobile'; } else { $device_type = 'desktop'; } $code = 'siberian'; } else { $apptype = 'desktop'; $device_type = 'desktop'; $code = "installer"; } $base_paths = array(APPLICATION_PATH . "/design/email/template/"); define('APPLICATION_TYPE', $apptype); define('DEVICE_TYPE', $device_type); define('DEVICE_IS_IPHONE', $detect->isIphone() || $detect->isIpad()); define('IS_APPLICATION', $detect->isApplication() && $this->_request->isApplication()); Core_Model_Directory::setDesignPath("/app/design/{$apptype}/{$code}"); define('DESIGN_CODE', $code); $resources = array('resources' => array('layout' => array('layoutPath' => APPLICATION_PATH . "/design/{$apptype}/{$code}/template/page"))); $base_paths[] = APPLICATION_PATH . "/design/{$apptype}/{$code}/template/"; $this->setOptions($resources); $this->bootstrap('View'); $view = $this->getResource('View'); $view->doctype('HTML5'); foreach ($base_paths as $base_path) { $view->addBasePath($base_path); } Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->setNeverRender(true); Core_View_Default::setDevice($detect); }
<?php include 'Mobile_Detect.php'; $detect = new Mobile_Detect(); if ($detect->isAndroidtablet() || $detect->isIpad() || $detect->isBlackberrytablet()) { // mostar versión para tablets header("Location: http://*.html"); } elseif ($detect->isAndroid()) { // versión Android header("Location: http://*.html"); } elseif ($detect->isIphone()) { // versión iPhone header("Location: http://*.html"); } elseif ($detect->isMobile()) { // versión para otros móviles header("Location: http://*.html"); } else { // versión "normal" header("Location: http://*.html"); }
protected function _initDesign() { $detect = new Mobile_Detect(); $design_codes = array("desktop" => "siberian", "mobile" => "angular"); Zend_Registry::set("design_codes", $design_codes); if (!$this->getRequest()->isInstalling()) { if ($this->getRequest()->isApplication()) { $apptype = 'mobile'; } else { $apptype = 'desktop'; } if ($detect->isMobile() || $apptype == 'mobile') { $device_type = 'mobile'; } else { $device_type = 'desktop'; } if ($this->getRequest()->isApplication()) { $code = $design_codes["mobile"]; } else { if ($this->_isInstanceOfBackoffice()) { $code = 'backoffice'; } else { $code = $design_codes["desktop"]; } } } else { $apptype = 'desktop'; $device_type = 'desktop'; $code = "installer"; } $base_paths = array(APPLICATION_PATH . "/design/email/template/"); if (!defined("APPLICATION_TYPE")) { define("APPLICATION_TYPE", $apptype); } if (!defined("DEVICE_TYPE")) { define("DEVICE_TYPE", $device_type); } if (!defined("DEVICE_IS_IPHONE")) { define("DEVICE_IS_IPHONE", $detect->isIphone() || $detect->isIpad()); } if (!defined("IS_APPLICATION")) { define("IS_APPLICATION", $detect->isNative() && $this->getRequest()->isApplication()); } if (!defined("DESIGN_CODE")) { define("DESIGN_CODE", $code); } Core_Model_Directory::setDesignPath("/app/design/{$apptype}/{$code}"); $resources = array('resources' => array('layout' => array('layoutPath' => APPLICATION_PATH . "/design/{$apptype}/{$code}/template/page"))); $base_paths[] = APPLICATION_PATH . "/design/{$apptype}/{$code}/template/"; $bootstrap = Zend_Controller_Front::getInstance()->getParam("bootstrap"); $bootstrap->setOptions($resources); $bootstrap->bootstrap('View'); $view = $bootstrap->getResource('View'); $view->doctype('HTML5'); foreach ($base_paths as $base_path) { $view->addBasePath($base_path); } Core_View_Default::setDevice($detect); Application_Controller_Mobile_Default::setDevice($detect); if (!$this->getRequest()->isInstalling()) { $blocks = array(); if ($this->getRequest()->isApplication()) { $blocks = $this->getRequest()->getApplication()->getBlocks(); } else { if (!$this->_isInstanceOfBackoffice()) { $blocks = $this->getRequest()->getWhiteLabelEditor()->getBlocks(); if ($block = $this->getRequest()->getWhiteLabelEditor()->getBlock("area")) { $icon_color = $block->getColor(); Application_Model_Option_Value::setEditorIconColor($icon_color); } } } if (!empty($blocks)) { Core_View_Default::setBlocks($blocks); } } }
/** * Check if you are on an iphone or not * * @return bool * @since 1.0.0 */ function yit_is_iphone() { $mobile = new Mobile_Detect(); return $mobile->isIphone(); }
case $version == 10: $browser = "ie10"; break; default: //do nothing } } if ($detect->isMobile()) { $is_desktop = false; $device = 'mobile'; } if ($detect->isTablet()) { $is_desktop = false; $device = 'tablet'; } $is_ios = $detect->isIphone(); if (!$is_ios) { $is_ios = $detect->isIpad(); } //if we're on ipad or iphone check safari version if ($is_ios) { $ios_vers = substr($detect->version('iOS'), 0, 1); $phoneOs = 'ios'; // $ios_vers = $detect->version('iOS'); // $safari_vers = $detect->version('Safari'); if ($ios_vers < 7) { $ios_vers = "uns-device"; $browser = 'ie8'; } } if ($detect->isAndroidOS()) {