/** * @dataProvider provideTestIsTablet */ public function testIsTablet($expected, $userAgent) { $detector = new DeviceDetection(); $device = $detector->detectDeviceProperties($userAgent, ''); $this->assertEquals((bool) $expected, $device->isTablet()); if ($expected) { $this->assertTrue($device->isMobileDevice(), 'Tablets are always mobile devices'); } }
function system_device_detection($debug = false) { platform_launch(PLATFORM_SANDBOX_SYSTEM_VENDORS_PATH . DS . PLATFORM_VENDORS_OPENDDR . DS . 'BuilderDataSource.class.php'); platform_launch(PLATFORM_SANDBOX_SYSTEM_VENDORS_PATH . DS . PLATFORM_VENDORS_OPENDDR . DS . 'DeviceDetection.class.php'); $device_detection = new DeviceDetection($_SERVER['HTTP_USER_AGENT']); $device_options = $device_detection->getAllCapabilities(); $device_type = 'Unknown'; if ($device_options['all']) { $user_agent = detect_user_agent(); $device_type = get_device_type(); } else { $device_type = $device_options['vendor'] . ' ' . $device_options['model']; } if ($debug) { echo "<h2>Device Info</h2>"; echo "<h3>User Agent: " . $user_agent . "</h3>"; echo "<pre>"; print_r($device_options); echo "</pre>"; } unset($device_detection); return $device_type; }
/** * @dataProvider provideTestFormatName */ public function testFormatName($format, $userAgent) { $detector = new DeviceDetection(); $this->assertEquals($format, $detector->formatName($userAgent)); }
/** * @param $out OutputPage * @param $text String * @return bool */ public function beforePageDisplayHTML(&$out, &$text) { global $wgContLang, $wgRequest, $wgMemc, $wgUser; wfProfileIn(__METHOD__); $userAgent = $_SERVER['HTTP_USER_AGENT']; $acceptHeader = isset($_SERVER["HTTP_ACCEPT"]) ? $_SERVER["HTTP_ACCEPT"] : ''; $uAmd5 = md5($userAgent); $key = wfMemcKey('mobile', 'ua', $uAmd5); $props = null; try { $props = $wgMemc->get($key); if (!$props) { $wurflConfigFile = RESOURCES_DIR . 'wurfl-config.xml'; $wurflConfig = new WURFL_Configuration_XmlConfig($wurflConfigFile); $wurflManagerFactory = new WURFL_WURFLManagerFactory($wurflConfig); $wurflManager = $wurflManagerFactory->create(); $device = $wurflManager->getDeviceForHttpRequest($_SERVER); if ($device->isSpecific() === true) { $props = $device->getAllCapabilities(); $wgMemc->set($key, $props, 86400); } else { $wgMemc->set($key, 'generic', 86400); $props = 'generic'; } } } catch (Exception $e) { // echo $e->getMessage(); } // Note: The WebRequest Class calls are made in this block because // since PHP 5.1.x, all objects have their destructors called // before the output buffer callback function executes. // Thus, globalized objects will not be available as expected in the function. // This is stated to be intended behavior, as per the following: [http://bugs.php.net/bug.php?id=40104] $xDevice = isset($_SERVER['HTTP_X_DEVICE']) ? $_SERVER['HTTP_X_DEVICE'] : ''; self::$useFormat = $wgRequest->getText('useformat'); $mobileAction = $wgRequest->getText('mobileaction'); $action = $wgRequest->getText('action'); if (self::$useFormat !== 'mobile' && self::$useFormat !== 'mobile-wap' && !$xDevice) { wfProfileOut(__METHOD__); return true; } if ($action === 'edit' || $mobileAction === 'view_normal_site') { wfProfileOut(__METHOD__); return true; } self::$title = $out->getTitle(); if (self::$title->isMainPage()) { self::$isMainPage = true; } if (self::$title->getNamespace() == NS_FILE) { self::$isFilePage = true; } self::$htmlTitle = $out->getHTMLTitle(); self::$disableImages = $wgRequest->getText('disableImages', 0); self::$enableImages = $wgRequest->getText('enableImages', 0); self::$displayNoticeId = $wgRequest->getText('noticeid', ''); if (self::$disableImages == 1) { $wgRequest->response()->setcookie('disableImages', 1); $location = str_replace('?disableImages=1', '', str_replace('&disableImages=1', '', $wgRequest->getFullRequestURL())); $location = str_replace('&mfi=1', '', str_replace('&mfi=0', '', $location)); $location = $this->getRelativeURL($location); $wgRequest->response()->header('Location: ' . $location . '&mfi=0'); } elseif (self::$disableImages == 0) { $disableImages = $wgRequest->getCookie('disableImages'); if ($disableImages) { self::$disableImages = $disableImages; } } if (self::$enableImages == 1) { $disableImages = $wgRequest->getCookie('disableImages'); if ($disableImages) { $wgRequest->response()->setcookie('disableImages', ''); } $location = str_replace('?enableImages=1', '', str_replace('&enableImages=1', '', $wgRequest->getFullRequestURL())); $location = str_replace('&mfi=1', '', str_replace('&mfi=0', '', $location)); $location = $this->getRelativeURL($location); $wgRequest->response()->header('Location: ' . $location . '&mfi=1'); } self::$format = $wgRequest->getText('format'); self::$callback = $wgRequest->getText('callback'); self::$requestedSegment = $wgRequest->getText('seg', 0); self::$search = $wgRequest->getText('search'); self::$searchField = $wgRequest->getText('search', ''); $device = new DeviceDetection(); if ($xDevice) { $formatName = $xDevice; } else { $formatName = $device->formatName($userAgent, $acceptHeader); } self::$device = $device->format($formatName); if (self::$device['view_format'] === 'wml') { $this->contentFormat = 'WML'; } elseif (self::$device['view_format'] === 'html') { $this->contentFormat = 'XHTML'; } if (self::$useFormat === 'mobile-wap') { $this->contentFormat = 'WML'; } if ($mobileAction == 'leave_feedback') { echo $this->renderLeaveFeedbackXHTML(); wfProfileOut(__METHOD__); exit; } if ($mobileAction == 'leave_feedback_post') { $this->getMsg(); $subject = $wgRequest->getText('subject', ''); $message = $wgRequest->getText('message', ''); $token = $wgRequest->getText('edittoken', ''); $title = Title::newFromText(self::$messages['mobile-frontend-feedback-page']); if ($title->userCan('edit') && !$wgUser->isBlockedFrom($title) && $wgUser->matchEditToken($token)) { $article = new Article($title, 0); $rawtext = $article->getRawText(); $rawtext .= "\n== {$subject} == \n {$message} ~~~~ \n <small>User agent: {$userAgent}</small> "; $article->doEdit($rawtext, ''); } $location = str_replace('&mobileaction=leave_feedback_post', '', $wgRequest->getFullRequestURL() . '¬iceid=1&useformat=mobile'); $location = $this->getRelativeURL($location); $wgRequest->response()->header('Location: ' . $location); wfProfileOut(__METHOD__); exit; } if ($mobileAction == 'disable_mobile_site' && $this->contentFormat == 'XHTML') { echo $this->renderDisableMobileSiteXHTML(); wfProfileOut(__METHOD__); exit; } if ($mobileAction == 'opt_in_mobile_site' && $this->contentFormat == 'XHTML') { echo $this->renderOptInMobileSiteXHTML(); wfProfileOut(__METHOD__); exit; } if ($mobileAction == 'opt_out_mobile_site' && $this->contentFormat == 'XHTML') { echo $this->renderOptOutMobileSiteXHTML(); wfProfileOut(__METHOD__); exit; } if ($mobileAction == 'opt_in_cookie') { wfIncrStats('mobile.opt_in_cookie_set'); $this->setOptInOutCookie('1'); $this->disableCaching(); $location = wfExpandUrl(Title::newMainPage()->getFullURL(), PROTO_CURRENT); $wgRequest->response()->header('Location: ' . $location); } if ($mobileAction == 'opt_out_cookie') { $this->setOptInOutCookie(''); } $this->getMsg(); $this->disableCaching(); $this->sendXDeviceVaryHeader(); $this->sendApplicationVersionVaryHeader(); $this->checkUserStatus(); $this->checkUserLoggedIn(); if (self::$title->isSpecial('Userlogin') && self::$isBetaGroupMember) { self::$wsLoginToken = $wgRequest->getSessionData('wsLoginToken'); $q = array('action' => 'submitlogin', 'type' => 'login'); $returnToVal = $wgRequest->getVal('returnto'); if ($returnToVal) { $q['returnto'] = $returnToVal; } self::$wsLoginFormAction = self::$title->getLocalURL($q); } $this->setDefaultLogo(); ob_start(array($this, 'DOMParse')); wfProfileOut(__METHOD__); return true; }
function getUserDevice() { $detect = new DeviceDetection(); if ($detect->isBlackberrytablet()) { //$detect->isMobile() return "BlackBerry Tablet"; } elseif ($detect->isAndroidtablet()) { //$detect->isMobile() return "Android Tablet"; } elseif ($detect->isWindowsphone()) { //$detect->isMobile() return "Windows Phone"; } elseif ($detect->isWindows()) { //$detect->isMobile() return "Windows Mobile"; } elseif ($detect->isIpad()) { //$detect->isMobile() return "iPad"; } elseif ($detect->isIphone()) { //$detect->isMobile() return "iPhone"; } elseif ($detect->isBlackberry()) { return "BlackBerry Mobile"; } elseif ($detect->isAndroid()) { //$detect->isMobile() return "Android Mobile"; } elseif ($detect->isPalm()) { //$detect->isMobile() return "Palm"; } elseif ($detect->isGeneric()) { //$detect->isMobile() return "Generic"; } else { return "PC"; } }
/** * Gets the current device description * @return IDeviceProperties */ public function getDevice() { $mobileHeader = $this->getMFConfig()->get('MFMobileHeader'); if ($this->device) { return $this->device; } $detector = DeviceDetection::factory(); $request = $this->getRequest(); if ($mobileHeader && $this->getRequest()->getHeader($mobileHeader) !== false) { $this->device = new HtmlDeviceProperties(); } else { $userAgent = $request->getHeader('User-agent'); $acceptHeader = $request->getHeader('Accept'); $acceptHeader = $acceptHeader === false ? '' : $acceptHeader; $this->device = $detector->detectDeviceProperties($userAgent, $acceptHeader); } return $this->device; }