コード例 #1
0
 /**
  * Determines the use of a mobile device.
  *
  * @param bool $check Flag requiring to check and update the value of field nomobile in user's PHP session.
  *     If set to true, the following actions are performed:
  *       - If the GET request contains variable named 'nomobile' with a value equivalent to true, then field 'nomobile'
  *         in user's PHP session is set to true. If the value of this variable is equivalent to false, then field
  *         'nomobile' is removed from user's session.
  *       - If the GET request contains no variable named 'nomobile' and does contain a variable named 'mobile' with
  *         a value equivalent to true, then field 'nomobile' is removed from user's session.
  *       - If, upon execution of the above actions, the value of field 'nomobile' in user's PHP session is equal to
  *         true, then method returns false. Otherwise the method continues its operation so as if the value of this
  *         flag were equal to false.
  *     If the flag's value is set to false, the use of a mobile device is determined by the contents of
  *     HTTP_USER_AGENT header.
  *
  * @return string|bool If mobile device is detected, one of these identifiers is returned: 'android', 'blackberry',
  *     'iphone', 'opera', 'palm', 'windows', 'generic'; otherwise method return false.
  */
 public static function isMobile($check = true)
 {
     if ($check) {
         if (self::get('nomobile') !== null) {
             if (self::get('nomobile')) {
                 waSystem::getInstance()->getStorage()->write('nomobile', true);
             } else {
                 waSystem::getInstance()->getStorage()->remove('nomobile');
             }
         } elseif (self::get('mobile')) {
             waSystem::getInstance()->getStorage()->remove('nomobile');
         }
         if (waSystem::getInstance()->getStorage()->read('nomobile')) {
             return false;
         }
     }
     if (self::$mobile !== null) {
         return self::$mobile;
     }
     $user_agent = self::server('HTTP_USER_AGENT');
     $desktop_platforms = array('ipad' => 'ipad', 'galaxy-tab' => 'android.*?GT\\-P');
     foreach ($desktop_platforms as $pattern) {
         if (preg_match('/' . $pattern . '/i', $user_agent)) {
             self::$mobile = false;
             return false;
         }
     }
     $mobile_platforms = array("google-mobile" => "googlebot\\-mobile", "android" => "android", "blackberry" => "(blackberry|rim tablet os)", "iphone" => "(iphone|ipod)", "opera" => "opera (mini|mobi|mobile)", "palm" => "(palmos|avantgo|blazer|elaine|hiptop|palm|plucker|xiino)", "windows" => "windows\\sce;\\s(iemobile|ppc|smartphone)", "generic" => "(kindle|mobile|mmp|midp|o2|pda|pocket|psp|symbian|smartphone|treo|up.browser|up.link|vodafone|wap)");
     foreach ($mobile_platforms as $id => $pattern) {
         if (preg_match('/' . $pattern . '/i', $user_agent)) {
             self::$mobile = $id;
             return $id;
         }
     }
     self::$mobile = false;
     return false;
 }