/** * Detects the capabilities from a given request object ($_SERVER) * @param array $request_headers Request object ($_SERVER contains this data) * @return boolean Match */ public function getDeviceCapabilitiesFromRequest($request_headers = null) { $this->httpRequest = $request_headers instanceof TeraWurflHttpRequest ? $request_headers : new TeraWurflHttpRequest($request_headers); $this->db->numQueries = 0; $this->matchData = array("num_queries" => 0, "match_type" => '', "matcher" => '', "match" => false, "lookup_time" => 0); $this->lookup_start = microtime(true); $this->foundInCache = false; $this->capabilities = array(); // Use the ultra high performance SimpleDesktopMatcher if enabled if (TeraWurflConfig::$SIMPLE_DESKTOP_ENGINE_ENABLE) { require_once realpath(dirname(__FILE__) . '/UserAgentMatchers/SimpleDesktopUserAgentMatcher.php'); if (SimpleDesktopUserAgentMatcher::isDesktopBrowserHeavyDutyAnalysis($this->httpRequest)) { $this->httpRequest->user_agent->set(WurflConstants::SIMPLE_DESKTOP_UA); } } // Check cache for device if (TeraWurflConfig::$CACHE_ENABLE) { $cacheData = $this->db->getDeviceFromCache($this->httpRequest->user_agent->cleaned); // 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 = UserAgentMatcherFactory::createUserAgentMatcher($this, $this->httpRequest); // Find the best matching WURFL ID $deviceID = $this->getDeviceIDFromRequestLoose(); // 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->httpRequest->user_agent->cleaned, $this->capabilities); } return $this->capabilities[$this->matchDataKey]['match']; }