/** * Detects the capabilities of a device from a given user agent and optionally, the HTTP Accept Headers * @param String HTTP User Agent * @param String HTTP Accept Header * @return Bool matching device was found */ public function getDeviceCapabilitiesFromAgent($userAgent = null, $httpAccept = null) { $this->db->numQueries = 0; $this->matchData = array("num_queries" => 0, "actual_root_device" => '', "match_type" => '', "matcher" => '', "match" => false, "lookup_time" => 0, "fall_back_tree" => ''); $this->lookup_start = microtime(true); $this->foundInCache = false; $this->capabilities = array(); // Define User Agent $this->userAgent = is_null($userAgent) ? WurflSupport::getUserAgent() : $userAgent; if (strlen($this->userAgent) > 255) { $this->userAgent = substr($this->userAgent, 0, 255); } // Use the ultra high performance SimpleDesktopMatcher if enabled if (TeraWurflConfig::$SIMPLE_DESKTOP_ENGINE_ENABLE) { require_once realpath(dirname(__FILE__) . '/UserAgentMatchers/SimpleDesktopUserAgentMatcher.php'); if (SimpleDesktopUserAgentMatcher::isDesktopBrowser($userAgent)) { $this->userAgent = WurflConstants::$SIMPLE_DESKTOP_UA; } } // Define HTTP ACCEPT header. Default: DO NOT use HTTP_ACCEPT headers //$this->httpAccept= (is_null($httpAccept))? WurflSupport::getAcceptHeader(): $httpAccept; $this->userAgent = UserAgentUtils::cleanUserAgent($this->userAgent); // Check cache for device if (TeraWurflConfig::$CACHE_ENABLE) { $cacheData = $this->db->getDeviceFromCache($this->userAgent); // Found in cache if ($cacheData !== false) { $this->capabilities = $cacheData; $this->foundInCache = true; $deviceID = $cacheData['id']; } } if (!$this->foundInCache) { require_once realpath(dirname(__FILE__) . '/UserAgentMatchers/SimpleDesktopUserAgentMatcher.php'); // Find appropriate user agent matcher $this->userAgentMatcher = UserAgentFactory::createUserAgentMatcher($this, $this->userAgent); // Find the best matching WURFL ID $deviceID = $this->getDeviceIDFromUALoose($userAgent); // Get the capabilities of this device and all its ancestors $this->getFullCapabilities($deviceID); // Now add in the Tera-WURFL results array $this->lookup_end = microtime(true); $this->matchData['num_queries'] = $this->db->numQueries; $this->matchData['lookup_time'] = $this->lookup_end - $this->lookup_start; // Add the match data to the capabilities array so it gets cached $this->addCapabilities(array($this->matchDataKey => $this->matchData)); } if (TeraWurflConfig::$CACHE_ENABLE == true && !$this->foundInCache) { // Since this device was not cached, cache it now. $this->db->saveDeviceInCache($this->userAgent, $this->capabilities); } return $this->capabilities[$this->matchDataKey]['match']; }
public function recoveryMatch($ua) { // At this point, a recovery match is really no match at all. $this->match_type = "none"; $this->wurfl->toLog("Applying CatchAll Recovery Match", LOG_INFO); $this->match = false; if (SimpleDesktopUserAgentMatcher::isDesktopBrowser($ua)) { return WurflConstants::$GENERIC_WEB_BROWSER; } //Openwave if (self::contains($ua, "UP.Browser/7.2")) { return "opwv_v72_generic"; } if (self::contains($ua, "UP.Browser/7")) { return "opwv_v7_generic"; } if (self::contains($ua, "UP.Browser/6.2")) { return "opwv_v62_generic"; } if (self::contains($ua, "UP.Browser/6")) { return "opwv_v6_generic"; } if (self::contains($ua, "UP.Browser/5")) { return "upgui_generic"; } if (self::contains($ua, "UP.Browser/4")) { return "uptext_generic"; } if (self::contains($ua, "UP.Browser/3")) { return "uptext_generic"; } //Series 60 if (self::contains($ua, "Series60")) { return "nokia_generic_series60"; } // Access/Net Front if (self::contains($ua, "NetFront/3.0") || self::contains($ua, "ACS-NF/3.0")) { return "generic_netfront_ver3"; } if (self::contains($ua, "NetFront/3.1") || self::contains($ua, "ACS-NF/3.1")) { return "generic_netfront_ver3_1"; } if (self::contains($ua, "NetFront/3.2") || self::contains($ua, "ACS-NF/3.2")) { return "generic_netfront_ver3_2"; } if (self::contains($ua, "NetFront/3.3") || self::contains($ua, "ACS-NF/3.3")) { return "generic_netfront_ver3_3"; } if (self::contains($ua, "NetFront/3.4")) { return "generic_netfront_ver3_4"; } if (self::contains($ua, "NetFront/3.5")) { return "generic_netfront_ver3_5"; } // Contains Mozilla/, but not at the beginning of the UA // ie: MOTORAZR V8/R601_G_80.41.17R Mozilla/4.0 (compatible; MSIE 6.0 Linux; MOTORAZR V88.50) Profile/MIDP-2.0 Configuration/CLDC-1.1 Opera 8.50[zh] if (!self::startsWith($ua, "Mozilla/") && self::contains($ua, "Mozilla/")) { return WurflConstants::$GENERIC_XHTML; } if (self::contains($ua, array("ObigoInternetBrowser/Q03C", "AU-MIC/2", "AU-MIC-", "AU-OBIGO/", "Obigo/Q03", "Obigo/Q04", "ObigoInternetBrowser/2", "Teleca Q03B1"))) { return WurflConstants::$GENERIC_XHTML; } // DoCoMo if (self::startsWith($ua, "DoCoMo") || self::startsWith($ua, "KDDI")) { return "docomo_generic_jap_ver1"; } return WurflConstants::$GENERIC; }