Exemple #1
0
 /**
  * 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'];
 }
 function Wall($ua = false)
 {
     global $_GET, $_SERVER;
     if (!$ua) {
         $this->ua = isset($_GET['UA']) ? $_GET['UA'] : getenv('HTTP_USER_AGENT');
     } else {
         $this->ua = $ua;
     }
     if (defined('WALL_USE_TERA_WURFL') && WALL_USE_TERA_WURFL) {
         switch (TERA_WURFL_VERSION) {
             case 1:
                 require_once WURFL_CLASS_FILE;
                 $this->wurfl = new tera_wurfl();
                 $this->wurfl->getDeviceCapabilitiesFromAgent($this->ua);
                 break;
             case 2:
                 // The class file was loaded in wall_prepend.php
                 $this->wurfl = new TeraWurfl();
                 if (!$ua) {
                     $this->ua = WurflSupport::getUserAgent();
                 }
                 $this->wurfl->getDeviceCapabilitiesFromAgent($this->ua);
                 break;
             case 'webservice':
                 $this->wurfl = new TeraWurflRemoteClient(TERA_WURFL_WEBSERVICE_URL, TeraWurflRemoteClient::$FORMAT_JSON);
                 if (!$ua) {
                     $this->ua = TeraWurflRemoteClient::getUserAgent();
                 }
                 $this->wurfl->getCapabilitiesFromAgent($this->ua, $GLOBALS['WALLWurflCapabilities']);
                 break;
         }
     } else {
         $this->wurfl = new wurfl_class();
         $this->wurfl->getDeviceCapabilitiesFromAgent($this->ua);
     }
     ob_start(array($this, '_obCallBack'));
     register_shutdown_function(array($this, '_obEndFlush'));
 }