private static function detectContext() { if (self::$context !== null) { return; } if (defined('OW_USE_CONTEXT')) { switch (true) { case OW_USE_CONTEXT == 1: self::$context = self::CONTEXT_DESKTOP; return; case OW_USE_CONTEXT == 1 << 1: self::$context = self::CONTEXT_MOBILE; return; case OW_USE_CONTEXT == 1 << 2: self::$context = self::CONTEXT_API; return; } } $context = self::CONTEXT_DESKTOP; try { $isSmart = UTIL_Browser::isSmartphone(); } catch (Exception $e) { return; } if (defined('OW_CRON')) { $context = self::CONTEXT_DESKTOP; } else { if (self::getSession()->isKeySet(OW_Application::CONTEXT_NAME)) { $context = self::getSession()->get(OW_Application::CONTEXT_NAME); } else { if ($isSmart) { $context = self::CONTEXT_MOBILE; } } } if (defined('OW_USE_CONTEXT')) { if ((OW_USE_CONTEXT & 1 << 1) == 0 && $context == self::CONTEXT_MOBILE) { $context = self::CONTEXT_DESKTOP; } if ((OW_USE_CONTEXT & 1 << 2) == 0 && $context == self::CONTEXT_API) { $context = self::CONTEXT_DESKTOP; } } if ((bool) OW::getConfig()->getValue('base', 'disable_mobile_context') && $context == self::CONTEXT_MOBILE) { $context = self::CONTEXT_DESKTOP; } //temp API context detection //TODO remake $uri = UTIL_Url::getRealRequestUri(OW::getRouter()->getBaseUrl(), $_SERVER['REQUEST_URI']); if (mb_strstr($uri, '/')) { if (trim(mb_substr($uri, 0, mb_strpos($uri, '/'))) == 'api') { $context = self::CONTEXT_API; } } else { if (trim($uri) == 'api') { $context = self::CONTEXT_API; } } self::$context = $context; }
private static function detectContext() { if (self::$context !== null) { return; } if (defined('OW_USE_CONTEXT')) { switch (true) { case OW_USE_CONTEXT == 1: self::$context = self::CONTEXT_DESKTOP; return; case OW_USE_CONTEXT == 1 << 1: self::$context = self::CONTEXT_MOBILE; return; case OW_USE_CONTEXT == 1 << 2: self::$context = self::CONTEXT_API; return; } } $context = self::CONTEXT_DESKTOP; try { $isSmart = UTIL_Browser::isSmartphone(); } catch (Exception $e) { return; } if (defined('OW_CRON')) { $context = self::CONTEXT_DESKTOP; } else { if (self::getSession()->isKeySet(OW_Application::CONTEXT_NAME)) { $context = self::getSession()->get(OW_Application::CONTEXT_NAME); } else { if ($isSmart) { $context = self::CONTEXT_MOBILE; } } } if (defined('OW_USE_CONTEXT')) { if ((OW_USE_CONTEXT & 1 << 1) == 0 && $context == self::CONTEXT_MOBILE) { $context = self::CONTEXT_DESKTOP; } if ((OW_USE_CONTEXT & 1 << 2) == 0 && $context == self::CONTEXT_API) { $context = self::CONTEXT_DESKTOP; } } self::$context = $context; }
/** * Indicates if user agent is mobile. * * @return boolean */ public function isMobileUserAgent() { return UTIL_Browser::isMobile($_SERVER['HTTP_USER_AGENT']); }