예제 #1
0
 public function applyConclusiveMatch($ua)
 {
     $matches = array();
     if (preg_match('/^Mozilla\\/4\\.0 \\(compatible; MSIE (\\d)\\.(\\d);/', $ua, $matches)) {
         if (TeraWurflConfig::$SIMPLE_DESKTOP_ENGINE_ENABLE) {
             return WurflConstants::$GENERIC_WEB_BROWSER;
         }
         switch ($matches[1]) {
             // cases are intentionally out of sequnce for performance
             case 7:
                 return 'msie_7';
                 break;
             case 8:
                 return 'msie_8';
                 break;
             case 6:
                 return 'msie_6';
                 break;
             case 4:
                 return 'msie_4';
                 break;
             case 5:
                 return $matches[2] == 5 ? 'msie_5_5' : 'msie_5';
                 break;
             default:
                 return 'msie';
                 break;
         }
     }
     $ua = preg_replace('/( \\.NET CLR [\\d\\.]+;?| Media Center PC [\\d\\.]+;?| OfficeLive[a-zA-Z0-9\\.\\d]+;?| InfoPath[\\.\\d]+;?)/', '', $ua);
     $tolerance = UserAgentUtils::firstSlash($ua);
     $this->wurfl->toLog("Applying " . get_class($this) . " Conclusive Match: RIS with threshold {$tolerance}", LOG_INFO);
     return $this->risMatch($ua, $tolerance);
 }
예제 #2
0
 public function applyConclusiveMatch($ua)
 {
     $clean_ua = $ua;
     if (self::contains($ua, "/SN") && !self::contains($ua, "XXXXXXXXXXXX")) {
         //not using RegEx for the time being
         $start_idx = strpos($ua, "/SN") + 3;
         $sub_str = substr($ua, $start_idx);
         $end_idx = strpos($sub_str, " ");
         if ($end_idx !== false && $sub_str != "" && strlen($sub_str) > $end_idx) {
             $num_digits = strlen($sub_str) - $end_idx;
             $new_ua = substr($ua, 0, $start_idx);
             for ($i = 0; $i < $end_idx; $i++) {
                 $new_ua .= "X";
             }
             $new_ua .= substr($ua, $end_idx);
             $clean_ua = $new_ua;
         }
     }
     $tolerance = UserAgentUtils::firstSlash($clean_ua);
     $this->wurfl->toLog("Applying " . get_class($this) . " Conclusive Match: RIS with threshold {$tolerance}", LOG_INFO);
     $match = $this->risMatch($clean_ua, $tolerance);
     if ($match == WurflConstants::$GENERIC) {
         $this->wurfl->toLog("Applying " . get_class($this) . " Conclusive Match: LD", LOG_INFO);
         return $this->ldMatch($ua);
     }
     return $match;
 }
 /**
  * Is the given user agent very likely to be a desktop browser
  * @param String User agent
  * @return Bool
  */
 public static function isDesktopBrowser($ua)
 {
     if (UserAgentUtils::isMobileBrowser($ua)) {
         return false;
     }
     if (self::contains($ua, array('HTC', 'PPC', 'Nintendo'))) {
         return false;
     }
     // Firefox
     if (self::contains($ua, "Firefox") && !self::contains($ua, 'Tablet')) {
         return true;
     }
     if (UserAgentUtils::isDesktopBrowser($ua)) {
         return true;
     }
     if (self::startsWith($ua, 'Opera/')) {
         return true;
     }
     if (self::regexContains($ua, array('/^Mozilla\\/5\\.0 \\(compatible; MSIE 9\\.0; Windows NT \\d\\.\\d/', '/^Mozilla\\/4\\.0 \\(compatible; MSIE \\d\\.\\d; Windows NT \\d\\.\\d/'))) {
         return true;
     }
     if (self::contains($ua, array("Chrome", "yahoo.com", "google.com", "Comcast"))) {
         return true;
     }
     return false;
 }
예제 #4
0
 public function applyConclusiveMatch($ua)
 {
     $deviceId = '';
     $tolerance = UserAgentUtils::indexOfOrLength($ua, ';', 0);
     $this->wurfl->toLog("Applying " . get_class($this) . " Conclusive Match: RIS with threshold  {$tolerance}", LOG_INFO);
     $deviceId = $this->risMatch($ua, $tolerance);
     return $deviceId;
 }
 protected function parseDevice()
 {
     if (count($this->pendingInsert) > 0) {
         foreach ($this->pendingInsert as $device) {
             $matcher = UserAgentFactory::userAgentType($this->wurfl, $device['user_agent']);
             $uatable = TeraWurflConfig::$TABLE_PREFIX . '_' . $matcher;
         }
         $this->pendingInsert = array();
     }
     $this->pendingInsert[$this->xml->getAttribute('id')] = array();
     $device =& $this->pendingInsert[$this->xml->getAttribute('id')];
     $device = array('id' => $this->xml->getAttribute('id'), 'user_agent' => UserAgentUtils::cleanUserAgent($this->xml->getAttribute('user_agent')), 'fall_back' => $this->xml->getAttribute('fall_back'));
     if ($this->xml->getAttribute('actual_device_root')) {
         $device['actual_device_root'] = $this->xml->getAttribute('actual_device_root') == "true" ? 1 : 0;
     }
     $groupdevice = '';
     $groupname = '';
     $filtering = TeraWurflConfig::$CAPABILITY_FILTER ? true : false;
     $includegroup = false;
     while ($this->xml->read()) {
         if ($this->xml->nodeType != XMLReader::ELEMENT) {
             continue;
         }
         // recurse back into this function for the rest of the devices
         switch ($this->xml->name) {
             case "device":
                 $this->parseDevice();
                 break;
             case "group":
                 $groupname = $this->xml->getAttribute('id');
                 if ($filtering && $this->enabled($this->xml->getAttribute('id'))) {
                     $includegroup = true;
                 } else {
                     $includegroup = false;
                     continue;
                 }
                 $device[$groupname] = array();
                 break;
             case "capability":
                 if (!$filtering || $filtering && $includegroup) {
                     // the groupdevice array must already exist
                     $device[$groupname][$this->xml->getAttribute('name')] = self::cleanValue($this->xml->getAttribute('value'));
                     continue;
                 }
                 if ($filtering && !$includegroup && $this->enabled($this->xml->getAttribute('name'))) {
                     // the groupdevice array might already exists
                     if (!array_key_exists($groupname, $device)) {
                         $device[$groupname] = array();
                     }
                     $device[$groupname][$this->xml->getAttribute('name')] = self::cleanValue($this->xml->getAttribute('value'));
                     continue;
                 }
                 break;
         }
     }
 }
 public function applyConclusiveMatch($ua)
 {
     if (self::startsWith($ua, "BlackBerry;")) {
         $tolerance = UserAgentUtils::ordinalIndexOf($ua, ';', 3);
     } else {
         $tolerance = UserAgentUtils::firstSlash($ua);
     }
     $this->wurfl->toLog("Applying " . get_class($this) . " Conclusive Match: RIS with threshold  {$tolerance}", LOG_INFO);
     return $this->risMatch($ua, $tolerance);
 }
 public function applyConclusiveMatch($ua)
 {
     if (self::startsWith($ua, 'KDDI/')) {
         $tolerance = UserAgentUtils::secondSlash($ua);
     } else {
         $tolerance = UserAgentUtils::firstSlash($ua);
     }
     $this->wurfl->toLog("Applying " . get_class($this) . " Conclusive Match: RIS with threshold {$tolerance}", LOG_INFO);
     return $this->risMatch($ua, $tolerance);
 }
 public function recoveryMatch($ua)
 {
     if (self::startsWith($ua, "SAMSUNG")) {
         $tolerance = 8;
         return $this->ldMatch($ua, $tolerance);
     } else {
         $tolerance = UserAgentUtils::indexOfOrLength($ua, '/', strpos($ua, 'Samsung'));
         return $this->risMatch($ua, $tolerance);
     }
 }
예제 #9
0
 public function applyConclusiveMatch($ua)
 {
     if (self::contains($ua, "MobilePhone")) {
         $tolerance = UserAgentUtils::indexOfOrLength($ua, '/', strpos($ua, "MobilePhone"));
     } else {
         $tolerance = UserAgentUtils::firstSlash($ua);
     }
     $this->wurfl->toLog("Applying " . get_class($this) . " Conclusive Match: RIS with threshold {$tolerance}", LOG_INFO);
     return $this->risMatch($ua, $tolerance);
 }
 public function applyConclusiveMatch($ua)
 {
     // firstSlash() - 1 because some UAs have revisions that aren't getting detected properly:
     // SonyEricssonW995a/R1FA Browser/NetFront/3.4 Profile/MIDP-2.1 Configuration/CLDC-1.1 JavaPlatform/JP-8.4.3
     $tolerance = UserAgentUtils::firstSlash($ua) - 1;
     $this->wurfl->toLog("Applying " . get_class($this) . " Conclusive Match: RIS with threshold {$tolerance}", LOG_INFO);
     if (self::startsWith($ua, "SonyEricsson")) {
         return $this->risMatch($ua, $tolerance);
     }
     $tolerance = UserAgentUtils::secondSlash($ua);
     return $this->risMatch($ua, $tolerance);
 }
예제 #11
0
 public function applyConclusiveMatch($ua)
 {
     $deviceId = '';
     if (UserAgentUtils::numSlashes($ua) >= 2) {
         $tolerance = UserAgentUtils::secondSlash($ua);
     } else {
         //  DoCoMo/2.0 F01A(c100;TB;W24H17)
         $tolerance = UserAgentUtils::firstOpenParen($ua);
     }
     $this->wurfl->toLog("Applying " . get_class($this) . " Conclusive Match: RIS with threshold {$tolerance}", LOG_INFO);
     $deviceId = $this->risMatch($ua, $tolerance);
     return $deviceId;
 }
 public function applyConclusiveMatch($ua)
 {
     $deviceId = '';
     if (self::startsWith($ua, 'Apple')) {
         if (($tolerance = UserAgentUtils::ordinalIndexOf($ua, ' ', 3)) == -1) {
             $tolerance = strlen($ua);
         }
     } else {
         $tolerance = UserAgentUtils::indexOfOrLength($ua, ';', 0);
     }
     $this->wurfl->toLog("Applying " . get_class($this) . " Conclusive Match: RIS with threshold  {$tolerance}", LOG_INFO);
     $deviceId = $this->risMatch($ua, $tolerance);
     return $deviceId;
 }
예제 #13
0
 public function applyConclusiveMatch($ua)
 {
     if (UserAgentUtils::checkIfContains($ua, "Opera/10")) {
         return "opera_10";
     } elseif (UserAgentUtils::checkIfContains($ua, "Opera/9")) {
         return "opera_9";
     } elseif (UserAgentUtils::checkIfContains($ua, "Opera/8")) {
         return "opera_8";
     } elseif (UserAgentUtils::checkIfContains($ua, "Opera/7")) {
         return "opera_7";
     }
     $tolerance = 5;
     $this->wurfl->toLog("Applying " . get_class($this) . " Conclusive Match: LD with threshold {$tolerance}", LOG_INFO);
     return $this->ldMatch($ua, $tolerance);
 }
예제 #14
0
 public function recoveryMatch($ua)
 {
     if (UserAgentUtils::checkIfContains($ua, 'Froyo')) {
         return 'generic_android_ver2_2';
     }
     if (preg_match('#Android[\\s/](\\d)\\.(\\d)#', $ua, $matches)) {
         $version = 'generic_android_ver' . $matches[1] . '_' . $matches[2];
         if ($version == 'generic_android_ver2_0') {
             $version = 'generic_android_ver2';
         }
         if (in_array($version, self::$constantIDs)) {
             return $version;
         }
     }
     return 'generic_android';
 }
예제 #15
0
 public function applyConclusiveMatch($ua)
 {
     $this->match_type = "conclusive";
     $tolerance = UserAgentUtils::firstSlash($ua);
     if (self::startsWith($ua, "Mozilla")) {
         $tolerance = 5;
         $this->wurfl->toLog("Applying CatchAll Conclusive Match: LD {$tolerance}, UA:\n{$ua}", LOG_INFO);
         $deviceID = $this->ldMatch($ua, $tolerance);
         if ($deviceID != WurflConstants::$GENERIC) {
             $this->match = true;
         }
         return $deviceID;
     }
     $this->wurfl->toLog("Applying " . get_class($this) . " Conclusive Match: RIS with threshold {$tolerance}", LOG_INFO);
     $deviceID = $this->risMatch($ua, $tolerance);
     if ($deviceID != WurflConstants::$GENERIC) {
         $this->match = true;
     }
     return $deviceID;
 }
 public function recoveryMatch($ua)
 {
     // BlackBerry
     $ua = preg_replace('/^BlackBerry (\\d+.*)$/', 'BlackBerry$1', $ua);
     $this->wurfl->toLog("Applying " . get_class($this) . " recovery match ({$ua})", LOG_INFO);
     if (self::startsWith($ua, "BlackBerry")) {
         $position = UserAgentUtils::firstSlash($ua);
         if ($position !== false && $position + 4 <= strlen($ua)) {
             $version = substr($ua, $position + 1, $position + 4);
             $this->wurfl->toLog("BlackBerry version substring is {$version}", LOG_INFO);
             if (self::startsWith($version, "2.")) {
                 return "blackberry_generic_ver2";
             }
             if (self::startsWith($version, "3.2")) {
                 return "blackberry_generic_ver3_sub2";
             }
             if (self::startsWith($version, "3.3")) {
                 return "blackberry_generic_ver3_sub30";
             }
             if (self::startsWith($version, "3.5")) {
                 return "blackberry_generic_ver3_sub50";
             }
             if (self::startsWith($version, "3.6")) {
                 return "blackberry_generic_ver3_sub60";
             }
             if (self::startsWith($version, "3.7")) {
                 return "blackberry_generic_ver3_sub70";
             }
             if (self::startsWith($version, "4.")) {
                 return "blackberry_generic_ver4";
             }
             $this->wurfl->toLog("No version matched, User-Agent: {$ua} version: {$version}", LOG_INFO);
         }
     }
     return WurflConstants::$GENERIC;
 }
 /**
  * Attempts to match given user agent string to a device from the database by calculating their Levenshtein Distance (LD)
  * @param String User agent
  * @param int Tolerance, how much difference is allowed
  * @return String WURFL ID
  */
 public function ldMatch($ua, $tolerance = NULL)
 {
     if ($this->wurfl->db->db_implements_ld) {
         return $this->wurfl->db->getDeviceFromUA_LD($ua, $tolerance, $this);
     }
     $this->updateDeviceList();
     return UserAgentUtils::ldMatch($ua, $tolerance, $this);
 }
예제 #18
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'];
 }
 /**
  * Determines which UserAgentMatcher is the best fit for the incoming user agent and returns it
  * @param TeraWurfl $wurfl
  * @param String $userAgent
  * @return UserAgentMatcher
  */
 public static function createUserAgentMatcher(TeraWurfl $wurfl, $userAgent)
 {
     // $isMobile means it IS MOBILE, $isDesktop means it IS DESKTOP
     // $isMobile does NOT mean it IS DESKTOP and vica-versa
     $isMobile = UserAgentUtils::isMobileBrowser($userAgent);
     $isDesktop = UserAgentUtils::isDesktopBrowser($userAgent);
     $userAgent_lcase = strtolower($userAgent);
     // Process exceptions
     if (TeraWurflConfig::$SIMPLE_DESKTOP_ENGINE_ENABLE && $userAgent == WurflConstants::$SIMPLE_DESKTOP_UA) {
         // SimpleDesktopUserAgentMatcher is included via require_once realpath(dirname(__FILE__).'/in TeraWurfl.php
         return new SimpleDesktopUserAgentMatcher($wurfl);
     }
     // Process MOBILE user agents
     if (!$isDesktop) {
         // High workload UAMs go first
         // Nokia
         if (UserAgentMatcher::contains($userAgent_lcase, 'nokia')) {
             require_once realpath(dirname(__FILE__) . '/UserAgentMatchers/NokiaUserAgentMatcher.php');
             return new NokiaUserAgentMatcher($wurfl);
         }
         // Samsung
         if (UserAgentMatcher::contains($userAgent, array("Samsung/SGH", "SAMSUNG-SGH")) || UserAgentMatcher::startsWith($userAgent, array("SEC-", "Samsung", "SAMSUNG", "SPH", "SGH", "SCH")) || stripos($userAgent, 'samsung') !== false) {
             require_once realpath(dirname(__FILE__) . '/UserAgentMatchers/SamsungUserAgentMatcher.php');
             return new SamsungUserAgentMatcher($wurfl);
         }
         // Blackberry
         if (stripos($userAgent, "blackberry") !== false) {
             require_once realpath(dirname(__FILE__) . '/UserAgentMatchers/BlackBerryUserAgentMatcher.php');
             return new BlackBerryUserAgentMatcher($wurfl);
         }
         // SonyEricsson
         if (UserAgentMatcher::contains($userAgent, 'Sony')) {
             require_once realpath(dirname(__FILE__) . '/UserAgentMatchers/SonyEricssonUserAgentMatcher.php');
             return new SonyEricssonUserAgentMatcher($wurfl);
         }
         // Motorola
         if (UserAgentMatcher::startsWith($userAgent, array('Mot-', 'MOT-', 'MOTO', 'moto')) || UserAgentMatcher::contains($userAgent, 'Motorola')) {
             require_once realpath(dirname(__FILE__) . '/UserAgentMatchers/MotorolaUserAgentMatcher.php');
             return new MotorolaUserAgentMatcher($wurfl);
         }
         // Continue processing UAMs in alphabetical order
         // Alcatel
         if (UserAgentMatcher::startsWith($userAgent_lcase, "alcatel")) {
             require_once realpath(dirname(__FILE__) . '/UserAgentMatchers/AlcatelUserAgentMatcher.php');
             return new AlcatelUserAgentMatcher($wurfl);
         }
         // Apple
         if (UserAgentMatcher::contains($userAgent, array("iPhone", "iPod", "iPad", "(iphone"))) {
             require_once realpath(dirname(__FILE__) . '/UserAgentMatchers/AppleUserAgentMatcher.php');
             return new AppleUserAgentMatcher($wurfl);
         }
         // BenQ
         if (UserAgentMatcher::startsWith($userAgent_lcase, "benq")) {
             require_once realpath(dirname(__FILE__) . '/UserAgentMatchers/BenQUserAgentMatcher.php');
             return new BenQUserAgentMatcher($wurfl);
         }
         // DoCoMo
         if (UserAgentMatcher::startsWith($userAgent, "DoCoMo")) {
             require_once realpath(dirname(__FILE__) . '/UserAgentMatchers/DoCoMoUserAgentMatcher.php');
             return new DoCoMoUserAgentMatcher($wurfl);
         }
         // Grundig
         if (UserAgentMatcher::startsWith($userAgent_lcase, "grundig")) {
             require_once realpath(dirname(__FILE__) . '/UserAgentMatchers/GrundigUserAgentMatcher.php');
             return new GrundigUserAgentMatcher($wurfl);
         }
         // HTC
         if (UserAgentMatcher::contains($userAgent, array("HTC", "XV6875"))) {
             require_once realpath(dirname(__FILE__) . '/UserAgentMatchers/HTCUserAgentMatcher.php');
             return new HTCUserAgentMatcher($wurfl);
         }
         // KDDI
         if (UserAgentMatcher::contains($userAgent, "KDDI-")) {
             require_once realpath(dirname(__FILE__) . '/UserAgentMatchers/KddiUserAgentMatcher.php');
             return new KddiUserAgentMatcher($wurfl);
         }
         // Kyocera
         if (UserAgentMatcher::startsWith($userAgent, array("kyocera", "QC-", "KWC-"))) {
             require_once realpath(dirname(__FILE__) . '/UserAgentMatchers/KyoceraUserAgentMatcher.php');
             return new KyoceraUserAgentMatcher($wurfl);
         }
         // LG
         if (UserAgentMatcher::startsWith($userAgent_lcase, "lg")) {
             require_once realpath(dirname(__FILE__) . '/UserAgentMatchers/LGUserAgentMatcher.php');
             return new LGUserAgentMatcher($wurfl);
         }
         // Mitsubishi
         if (UserAgentMatcher::startsWith($userAgent, "Mitsu")) {
             require_once realpath(dirname(__FILE__) . '/UserAgentMatchers/MitsubishiUserAgentMatcher.php');
             return new MitsubishiUserAgentMatcher($wurfl);
         }
         // NEC
         if (UserAgentMatcher::startsWith($userAgent, array("NEC-", "KGT"))) {
             require_once realpath(dirname(__FILE__) . '/UserAgentMatchers/NecUserAgentMatcher.php');
             return new NecUserAgentMatcher($wurfl);
         }
         // Nintendo
         if (UserAgentMatcher::contains($userAgent, "Nintendo") || UserAgentMatcher::startsWith($userAgent, 'Mozilla/') && UserAgentMatcher::contains($userAgent, "Nitro") && UserAgentMatcher::contains($userAgent, "Opera")) {
             require_once realpath(dirname(__FILE__) . '/UserAgentMatchers/NintendoUserAgentMatcher.php');
             return new NintendoUserAgentMatcher($wurfl);
         }
         // Panasonic
         if (UserAgentMatcher::startsWith($userAgent, "Panasonic")) {
             require_once realpath(dirname(__FILE__) . '/UserAgentMatchers/PanasonicUserAgentMatcher.php');
             return new PanasonicUserAgentMatcher($wurfl);
         }
         // Pantech
         if (UserAgentMatcher::startsWith($userAgent, array("Pantech", "PT-", "PANTECH", "PG-"))) {
             require_once realpath(dirname(__FILE__) . '/UserAgentMatchers/PantechUserAgentMatcher.php');
             return new PantechUserAgentMatcher($wurfl);
         }
         // Philips
         if (UserAgentMatcher::startsWith($userAgent_lcase, "philips")) {
             require_once realpath(dirname(__FILE__) . '/UserAgentMatchers/PhilipsUserAgentMatcher.php');
             return new PhilipsUserAgentMatcher($wurfl);
         }
         // Portalmmm
         if (UserAgentMatcher::startsWith($userAgent, "portalmmm")) {
             require_once realpath(dirname(__FILE__) . '/UserAgentMatchers/PortalmmmUserAgentMatcher.php');
             return new PortalmmmUserAgentMatcher($wurfl);
         }
         // Qtek
         if (UserAgentMatcher::startsWith($userAgent, "Qtek")) {
             require_once realpath(dirname(__FILE__) . '/UserAgentMatchers/QtekUserAgentMatcher.php');
             return new QtekUserAgentMatcher($wurfl);
         }
         // Sagem
         if (UserAgentMatcher::startsWith($userAgent_lcase, "sagem")) {
             require_once realpath(dirname(__FILE__) . '/UserAgentMatchers/SagemUserAgentMatcher.php');
             return new SagemUserAgentMatcher($wurfl);
         }
         // Sanyo
         if (UserAgentMatcher::startsWith($userAgent_lcase, "sanyo") || UserAgentMatcher::contains($userAgent, "MobilePhone")) {
             require_once realpath(dirname(__FILE__) . '/UserAgentMatchers/SanyoUserAgentMatcher.php');
             return new SanyoUserAgentMatcher($wurfl);
         }
         // Sharp
         if (UserAgentMatcher::startsWith($userAgent_lcase, "sharp")) {
             require_once realpath(dirname(__FILE__) . '/UserAgentMatchers/SharpUserAgentMatcher.php');
             return new SharpUserAgentMatcher($wurfl);
         }
         // Siemens
         if (UserAgentMatcher::startsWith($userAgent, "SIE-")) {
             require_once realpath(dirname(__FILE__) . '/UserAgentMatchers/SiemensUserAgentMatcher.php');
             return new SiemensUserAgentMatcher($wurfl);
         }
         // SPV
         if (UserAgentMatcher::contains($userAgent, 'SPV')) {
             require_once realpath(dirname(__FILE__) . '/UserAgentMatchers/SPVUserAgentMatcher.php');
             return new SPVUserAgentMatcher($wurfl);
         }
         // Toshiba
         if (UserAgentMatcher::startsWith($userAgent, "Toshiba")) {
             require_once realpath(dirname(__FILE__) . '/UserAgentMatchers/ToshibaUserAgentMatcher.php');
             return new ToshibaUserAgentMatcher($wurfl);
         }
         // Vodafone
         if (UserAgentMatcher::startsWith($userAgent, 'Vodafone')) {
             require_once realpath(dirname(__FILE__) . '/UserAgentMatchers/VodafoneUserAgentMatcher.php');
             return new VodafoneUserAgentMatcher($wurfl);
         }
         // Process mobile browsers after mobile devices
         // Android
         if (UserAgentMatcher::contains($userAgent, "Android")) {
             require_once realpath(dirname(__FILE__) . '/UserAgentMatchers/AndroidUserAgentMatcher.php');
             return new AndroidUserAgentMatcher($wurfl);
         }
         // Opera Mini
         if (UserAgentMatcher::contains($userAgent, array('Opera Mini', 'Opera Mobi'))) {
             require_once realpath(dirname(__FILE__) . '/UserAgentMatchers/OperaMiniUserAgentMatcher.php');
             return new OperaMiniUserAgentMatcher($wurfl);
         }
         // Windows CE
         if (UserAgentMatcher::contains($userAgent, "Mozilla/") && UserAgentMatcher::contains($userAgent, "Windows CE")) {
             require_once realpath(dirname(__FILE__) . '/UserAgentMatchers/WindowsCEUserAgentMatcher.php');
             return new WindowsCEUserAgentMatcher($wurfl);
         }
     }
     // End if(!$isDesktop)
     // Process Robots (Web Crawlers and the like)
     if (UserAgentUtils::isRobot($userAgent)) {
         require_once realpath(dirname(__FILE__) . '/UserAgentMatchers/BotUserAgentMatcher.php');
         return new BotUserAgentMatcher($wurfl);
     }
     // Process NON-MOBILE user agents
     if (!$isMobile) {
         // MSIE
         if (UserAgentMatcher::startsWith($userAgent, "Mozilla") && UserAgentMatcher::contains($userAgent, "MSIE") && !UserAgentMatcher::contains($userAgent, array("Opera", "armv", "MOTO", "BREW"))) {
             require_once realpath(dirname(__FILE__) . '/UserAgentMatchers/MSIEUserAgentMatcher.php');
             return new MSIEUserAgentMatcher($wurfl);
         }
         // Firefox
         if (UserAgentMatcher::contains($userAgent, "Firefox") && !UserAgentMatcher::contains($userAgent, array("Sony", "Novarra", "Opera"))) {
             require_once realpath(dirname(__FILE__) . '/UserAgentMatchers/FirefoxUserAgentMatcher.php');
             return new FirefoxUserAgentMatcher($wurfl);
         }
         // Chrome
         if (UserAgentMatcher::contains($userAgent, "Chrome")) {
             require_once realpath(dirname(__FILE__) . '/UserAgentMatchers/ChromeUserAgentMatcher.php');
             return new ChromeUserAgentMatcher($wurfl);
         }
         // Konqueror
         if (UserAgentMatcher::contains($userAgent, "Konqueror")) {
             require_once realpath(dirname(__FILE__) . '/UserAgentMatchers/KonquerorUserAgentMatcher.php');
             return new KonquerorUserAgentMatcher($wurfl);
         }
         // Opera
         if (UserAgentMatcher::contains($userAgent, "Opera")) {
             require_once realpath(dirname(__FILE__) . '/UserAgentMatchers/OperaUserAgentMatcher.php');
             return new OperaUserAgentMatcher($wurfl);
         }
         // Safari
         if (UserAgentMatcher::startsWith($userAgent, "Mozilla") && UserAgentMatcher::contains($userAgent, "Safari")) {
             require_once realpath(dirname(__FILE__) . '/UserAgentMatchers/SafariUserAgentMatcher.php');
             return new SafariUserAgentMatcher($wurfl);
         }
         // AOL
         if (UserAgentMatcher::contains($userAgent, array("AOL", "America Online")) || UserAgentMatcher::contains($userAgent_lcase, "aol 9")) {
             require_once realpath(dirname(__FILE__) . '/UserAgentMatchers/AOLUserAgentMatcher.php');
             return new AOLUserAgentMatcher($wurfl);
         }
     }
     // Nothing has matched so we will have to use the CatchAllUserAgentMatcher
     return new CatchAllUserAgentMatcher($wurfl);
 }
 public function applyConclusiveMatch($ua)
 {
     $tolerance = UserAgentUtils::firstSlash($ua);
     $this->wurfl->toLog("Applying " . get_class($this) . " Conclusive Match: RIS with threshold {$tolerance}", LOG_INFO);
     return $this->risMatch($ua, $tolerance);
 }
 protected function loadDeviceXMLToArray(&$device)
 {
     $id = (string) $device['id'];
     $this->devices[$id] = array('id' => $id);
     $filtering = TeraWurflConfig::$CAPABILITY_FILTER ? true : false;
     $includegroup = false;
     if (isset($device['fall_back'])) {
         $this->devices[$id]['fall_back'] = (string) $device['fall_back'];
     }
     if (isset($device['user_agent'])) {
         $this->devices[$id]['user_agent'] = UserAgentUtils::cleanUserAgent((string) $device['user_agent']);
     }
     if (isset($device['actual_device_root'])) {
         $this->devices[$id]['actual_device_root'] = (string) $device['actual_device_root'];
         $this->devices[$id]['actual_device_root'] = $this->devices[$id]['actual_device_root'] ? 1 : 0;
     }
     foreach ($device->group as $group) {
         $groupname = (string) $group['id'];
         if ($filtering && $this->enabled($groupname)) {
             $includegroup = true;
         } else {
             $includegroup = false;
         }
         $groupdata = array();
         foreach ($group->capability as $cap) {
             $capname = (string) $cap['name'];
             if (!$filtering || $filtering && $includegroup || $filtering && !$includegroup && $this->enabled($capname)) {
                 $groupdata[$capname] = $this->cleanValue((string) $cap['value']);
             }
         }
         if (count($groupdata) > 0) {
             $this->devices[$id][$groupname] = $groupdata;
         }
         unset($groupdata);
     }
 }
예제 #22
0
 public function applyConclusiveMatch($ua)
 {
     $tolerance = UserAgentUtils::indexOfOrLength($ua, '/', strpos($ua, 'Chrome'));
     $this->wurfl->toLog("Applying " . get_class($this) . " Conclusive Match: RIS with threshold {$tolerance}", LOG_INFO);
     return $this->risMatch($ua, $tolerance);
 }
 /**
  * Attempts to match given user agent string to a device from the database by calculating their Levenshtein Distance (LD)
  * @param int $tolerance Tolerance, how much difference is allowed
  * @return string WURFL ID
  */
 public function ldMatch($tolerance = null)
 {
     if ($this->simulation) {
         return WurflConstants::NO_MATCH;
     }
     if ($this->wurfl->db->db_implements_ld) {
         return $this->wurfl->db->getDeviceFromUA_LD($this->userAgent->normalized, $tolerance, $this);
     }
     $this->updateDeviceList();
     return UserAgentUtils::ldMatch($this->userAgent->normalized, $tolerance, $this);
 }