Beispiel #1
0
 /**
  * Sets up some standard variables as well as starts the user agent parsing process
  *
  * @return {Object}       the result of the user agent parsing
  */
 public static function parse($ua = NULL)
 {
     self::$ua = $ua ? $ua : strip_tags($_SERVER["HTTP_USER_AGENT"]);
     self::$accept = empty($_SERVER["HTTP_ACCEPT"]) ? '' : strip_tags($_SERVER["HTTP_ACCEPT"]);
     if (empty(self::$regexes)) {
         if (file_exists(__DIR__ . "/resources/regexes.yaml")) {
             self::$regexes = Spyc::YAMLLoad(__DIR__ . "/resources/regexes.yaml");
         } else {
             print "<h1>Error</h1>\n\t\t\t\t\t   <p>Please download the regexes.yaml file before using UAParser.php.</p>\n\t\t\t\t\t   <p>You can type the following at the command line to download the latest version:</p>\n\t\t\t\t\t   <blockquote>\n\t\t\t\t\t\t<code>%: cd /path/to/UAParser</code><br />\n\t\t\t\t\t   \t<code>%: php UAParser.php -get</code>\n\t\t\t\t\t   </blockquote>";
             exit;
         }
     }
     // run the regexes to match things up
     $uaRegexes = self::$regexes['user_agent_parsers'];
     foreach ($uaRegexes as $uaRegex) {
         if ($result = self::uaParser($uaRegex)) {
             $result->uaOriginal = self::$ua;
             break;
         }
     }
     // if no browser was found check to see if it can be matched at least against a device (e.g. spider, generic feature phone or generic smartphone)
     if (!$result) {
         if (($result = self::deviceParser()) && $result->device != 'Spider') {
             $result->isMobile = true;
             $result->isMobileDevice = true;
             $result->uaOriginal = self::$ua;
         } else {
             if (isset($result) && isset($result->device) && $result->device == "Spider") {
                 $result->isMobile = false;
                 $result->isSpider = true;
                 $result->uaOriginal = self::$ua;
             }
         }
     }
     // still false?! see if it's a really dumb feature phone, if not just mark it as unknown
     if (!$result) {
         if (strpos(self::$accept, 'text/vnd.wap.wml') > 0 || strpos(self::$accept, 'application/vnd.wap.xhtml+xml') > 0 || isset($_SERVER['HTTP_X_WAP_PROFILE']) || isset($_SERVER['HTTP_PROFILE'])) {
             $result = new stdClass();
             $result->device = "Generic Feature Phone";
             $result->deviceFull = "Generic Feature Phone";
             $result->isMobile = true;
             $result->isMobileDevice = true;
             $result->uaOriginal = self::$ua;
         } else {
             $result = new stdClass();
             $result->device = "Unknown";
             $result->deviceFull = "Unknown";
             $result->isMobile = false;
             $result->isMobileDevice = false;
             $result->isComputer = true;
             $result->uaOriginal = self::$ua;
         }
     }
     // log the results when testing
     if (self::$debug) {
         self::log($result);
     }
     return $result;
 }