isMobile(); self::_setCookie(__METHOD__, $isMobile); } return (bool) $isMobile; } /** * @param null|string $userAgent * @return bool */ public static function isTouchscreen($userAgent = null) { $isTouchscreen = self::_getCookie(__METHOD__); if (null === $isTouchscreen) { if (null !== $userAgent) { self::getUserAgent($userAgent); } $pointingMethod = self::_getDetector()->getPointingMethod(); $isTouchscreen = (Qs_Device_Detector_AbstractDetector::POINTING_METHOD_TOUCHSCREEN == $pointingMethod); self::_setCookie(__METHOD__, $isTouchscreen); } return (bool) $isTouchscreen; } /** * @param string $name * @return bool */ public static function setDetectorName($name) { self::$_detectorName = (string) $name; return true; } /** * @return string */ public static function getDetectorName() { return self::$_detectorName; } /** * @param string $userAgent * @return bool */ public static function setUserAgent($userAgent) { self::_getDetector()->setUserAgent($userAgent); return true; } /** * @return null|string */ protected static function getUserAgent() { self::_getDetector()->getUserAgent(); } /** * @return mixed * @throws Qs_Exception */ protected static function _getDetector() { if (null === self::$_detector) { $className = __CLASS__ . '_Detector_' . self::$_detectorName; if (!class_exists($className)) { throw new Qs_Exception('Unknown detector name: ' . self::$_detectorName); } self::$_detector = new $className; } return self::$_detector; } /** * @param string $name * @param string $value * @return bool */ protected static function _setCookie($name, $value) { $cookieName = self::$_cookieNamePrefix . $name; $cookieExpire = time() + 60 * 60 * 24 * self::$_cookieExpireInDays; if (is_bool($value)) { $cookieValue = ($value) ? '1' : '0'; } else { $cookieValue = (string) $value; } $_COOKIE[$cookieName] = $cookieValue; return setcookie($cookieName, $cookieValue, $cookieExpire); } /** * @param $name * @return mixed */ protected static function _getCookie($name) { $cookieName = self::$_cookieNamePrefix . $name; return Qs_Array::get($_COOKIE, $cookieName); } }