當前位置: 首頁>>代碼示例>>PHP>>正文


PHP UserAgentMatcher類代碼示例

本文整理匯總了PHP中UserAgentMatcher的典型用法代碼示例。如果您正苦於以下問題:PHP UserAgentMatcher類的具體用法?PHP UserAgentMatcher怎麽用?PHP UserAgentMatcher使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了UserAgentMatcher類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: createUserAgentMatcher

 /**
  * 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');
//.........這裏部分代碼省略.........
開發者ID:anubhaBhargava,項目名稱:OpenRecommender,代碼行數:101,代碼來源:UserAgentFactory.php

示例2: getDeviceFromUA_RIS

 public function getDeviceFromUA_RIS($userAgent, $tolerance, UserAgentMatcher &$matcher)
 {
     $this->numQueries++;
     $query = sprintf("CALL " . TeraWurflConfig::$TABLE_PREFIX . "_RIS(%s,%s,%s)", $this->SQLPrep($userAgent), $tolerance, $this->SQLPrep($matcher->tableSuffix()));
     $res = $this->dbcon->query($query);
     if (!$res) {
         throw new Exception(sprintf("Error in DB RIS Query: %s. \nQuery: %s\n", $this->dbcon->error, $query));
         exit;
     }
     $data = $res->fetch_assoc();
     $this->cleanConnection();
     $wurflid = $data['DeviceID'];
     return $wurflid == 'NULL' || is_null($wurflid) ? WurflConstants::$GENERIC : $wurflid;
 }
開發者ID:vuong93st,項目名稱:w-game,代碼行數:14,代碼來源:TeraWurflDatabase_MySQL5.php

示例3: getDeviceFromUA_RIS

 public function getDeviceFromUA_RIS($userAgent, $tolerance, UserAgentMatcher &$matcher)
 {
     $this->numQueries++;
     $query = sprintf("EXEC " . TeraWurflConfig::$TABLE_PREFIX . "_RIS %s,%s,%s", $this->SQLPrep($userAgent), $tolerance, $this->SQLPrep($matcher->tableSuffix()));
     $result = sqlsrv_query($this->dbcon, $query);
     if (!$result) {
         throw new Exception(sprintf("Error in DB RIS Query: %s. \nQuery: %s\n", $this->lastDBError(), $query));
     }
     $data = sqlsrv_fetch_array($result);
     sqlsrv_free_stmt($result);
     $wurflid = $data['DeviceID'];
     return $wurflid == 'NULL' || is_null($wurflid) ? WurflConstants::NO_MATCH : $wurflid;
 }
開發者ID:pwodaniilea,項目名稱:t3x-contexts_wurfl,代碼行數:13,代碼來源:TeraWurflDatabase_MSSQL2005.php

示例4: getDeviceFromUA_RIS

 public function getDeviceFromUA_RIS($userAgent, $tolerance, UserAgentMatcher &$matcher)
 {
     $this->numQueries++;
     $stmt = $this->dbcon->prepare('CALL ' . TeraWurflConfig::$TABLE_PREFIX . '_RIS(?, ?, ?)');
     if (!$stmt->execute(array($userAgent, $tolerance, $matcher->tableSuffix()))) {
         $error = $stmt->errorInfo();
         throw new Exception(sprintf("Error in DB RIS Query: %s\n", $error[2]));
     }
     $data = $stmt->fetch(PDO::FETCH_ASSOC);
     $stmt = null;
     $wurflid = $data['DeviceID'];
     return $wurflid == 'NULL' || is_null($wurflid) ? WurflConstants::NO_MATCH : $wurflid;
 }
開發者ID:pwodaniilea,項目名稱:t3x-contexts_wurfl,代碼行數:13,代碼來源:TeraWurflDatabase_PDO.php

示例5: getDeviceFromUA_RIS

 /**
  * RIS == Reduction in String (reduce string one char at a time)
  *
  * @param string $userAgent
  * @param int $tolerance
  * @param UserAgentMatcher $matcher
  * @return string A TW Device ID
  */
 public function getDeviceFromUA_RIS($userAgent, $tolerance, UserAgentMatcher $matcher)
 {
     $toexec = 'function(ua, tolerance, matcher) { return performRis(ua, tolerance, matcher) }';
     $args = array(utf8_encode($userAgent), $tolerance, $matcher->tableSuffix());
     $this->numQueries++;
     $response = $this->dbcon->execute($toexec, $args);
     if (!empty($response['ok']) && $response['ok'] == 1 && !empty($response['retval'])) {
         return $response['retval'];
     }
     return WurflConstants::$GENERIC;
 }
開發者ID:vallejos,項目名稱:samples,代碼行數:19,代碼來源:TeraWurflDatabase_MongoDB.php

示例6: isMobileBrowser

 /**
  * The given user agent is definitely from a mobile device
  * @param String User agent
  * @return Bool
  */
 public static function isMobileBrowser($ua)
 {
     $lowerua = strtolower($ua);
     if (self::isDesktopBrowser($ua)) {
         return false;
     }
     if (UserAgentMatcher::contains($lowerua, WurflConstants::$MOBILE_BROWSERS)) {
         return true;
     }
     if (UserAgentMatcher::regexContains($ua, array('/[^\\d]\\d{3}x\\d{3}/'))) {
         return true;
     }
     return false;
 }
開發者ID:vallejos,項目名稱:samples,代碼行數:19,代碼來源:UserAgentUtils.php

示例7: getDeviceIDFromRequestLoose

 /**
  * Returns the matching WURFL ID for a given User Agent
  * @return string WURFL ID
  */
 protected function getDeviceIDFromRequestLoose()
 {
     $this->matcherHistory = array();
     // Return generic UA if userAgent is empty
     if (strlen($this->httpRequest->user_agent) == 0) {
         $this->matchData['matcher'] = "none";
         $this->matchData['match_type'] = "none";
         $this->matchData['match'] = false;
         $this->setMatcherHistory();
         if ($this->httpRequest->uaprof instanceof TeraWurflUserAgentProfile && $this->httpRequest->uaprof->containsValidUrl()) {
             return WurflConstants::GENERIC_MOBILE;
         } else {
             return WurflConstants::NO_MATCH;
         }
     }
     // Check for exact match
     if (TeraWurflConfig::$SIMPLE_DESKTOP_ENGINE_ENABLE && $this->httpRequest->user_agent == WurflConstants::SIMPLE_DESKTOP_UA) {
         // SimpleDesktop UA Matching avoids querying the database here
         $this->matchData['matcher'] = $this->userAgentMatcher->matcherName();
         $this->matchData['match_type'] = "high_performance";
         $this->matchData['match'] = true;
         $this->matcherHistory[] = $this->matchData['matcher'] . "(high_performance)";
         $this->setMatcherHistory();
         return WurflConstants::GENERIC_WEB_BROWSER;
     } else {
         $deviceID = $this->db->getDeviceFromUA($this->httpRequest->user_agent->normalized);
     }
     $this->matcherHistory[] = $this->userAgentMatcher->matcherName() . "(exact)";
     if ($deviceID !== false) {
         $this->matchData['matcher'] = $this->userAgentMatcher->matcherName();
         $this->matchData['match_type'] = "exact";
         $this->matchData['match'] = true;
         $this->setMatcherHistory();
         return $deviceID;
     }
     // Check for a conclusive match
     $deviceID = $this->userAgentMatcher->applyConclusiveMatch($this->httpRequest);
     $this->matcherHistory[] = $this->userAgentMatcher->matcherName() . "(conclusive)";
     if ($deviceID != WurflConstants::NO_MATCH) {
         $this->matchData['matcher'] = $this->userAgentMatcher->matcherName();
         $this->matchData['match_type'] = "conclusive";
         $this->matchData['match'] = true;
         $this->setMatcherHistory();
         return $deviceID;
     }
     /*
     // Check for Vodafone magic
     if ($this->userAgentMatcher->matcherName()!="VodafoneUserAgentMatcher" && $this->httpRequest->user_agent->contains("Vodafone")) {
     	@require_once realpath(dirname(__FILE__).'/UserAgentMatchers/VodafoneUserAgentMatcher.php');
     	$vodafoneUserAgentMatcher = new VodafoneUserAgentMatcher($this);
     	$this->matcherHistory[] = $vodafoneUserAgentMatcher->matcherName() . "(conclusive)";
     	$deviceID = $vodafoneUserAgentMatcher->applyConclusiveMatch($this->httpRequest);
     	if ($deviceID != WurflConstants::NO_MATCH) {
     		$this->matchData['matcher'] = $vodafoneUserAgentMatcher->matcherName();
     		$this->matchData['match_type'] = "conclusive";
     		$this->matchData['match'] = true;
     		$this->setMatcherHistory();
     		return $deviceID;
     	}
     }
     */
     // Check for recovery match
     $deviceID = $this->userAgentMatcher->applyRecoveryMatch($this->httpRequest);
     $this->matcherHistory[] = $this->userAgentMatcher->matcherName() . "(recovery)";
     if ($deviceID != WurflConstants::NO_MATCH) {
         $this->matchData['matcher'] = $this->userAgentMatcher->matcherName();
         $this->matchData['match_type'] = "recovery";
         $this->matchData['match'] = false;
         $this->setMatcherHistory();
         return $deviceID;
     }
     // Check CatchAll if it's not already in use
     if ($this->userAgentMatcher->matcherName() != "CatchAllUserAgentMatcher") {
         $catchAllUserAgentMatcher = new CatchAllUserAgentMatcher($this);
         $this->matcherHistory[] = $catchAllUserAgentMatcher->matcherName() . "(recovery)";
         $deviceID = $catchAllUserAgentMatcher->applyRecoveryMatch($this->httpRequest);
         if ($deviceID != WurflConstants::NO_MATCH) {
             // The CatchAll matcher is intelligent enough to determine the match properties
             $this->matchData['matcher'] = $catchAllUserAgentMatcher->matcher;
             $this->matchData['match_type'] = $catchAllUserAgentMatcher->match_type;
             $this->matchData['match'] = $catchAllUserAgentMatcher->match;
             $this->setMatcherHistory();
             return $deviceID;
         }
     }
     // A matching device still hasn't been found - check HTTP ACCEPT headers
     if ($this->httpRequest->accept->length() > 0) {
         $this->matcherHistory[] = 'http_accept';
         if ($this->httpRequest->accept->contains('application/vnd.wap.xhtml+xml')) {
             $this->matchData['matcher'] = 'http_accept';
             $this->matchData['match_type'] = 'recovery';
             // This isn't really a match, it's a suggestion
             $this->matchData['match'] = false;
             $this->setMatcherHistory();
             return WurflConstants::GENERIC_MOBILE;
         }
//.........這裏部分代碼省略.........
開發者ID:pwodaniilea,項目名稱:t3x-contexts_wurfl,代碼行數:101,代碼來源:TeraWurfl.php

示例8: __construct

 public function __construct(TeraWurfl $wurfl)
 {
     parent::__construct($wurfl);
 }
開發者ID:vuong93st,項目名稱:w-game,代碼行數:4,代碼來源:MSIEUserAgentMatcher.php

示例9: fullTableName

 public function fullTableName()
 {
     return TeraWurflConfig::$TABLE_PREFIX . '_' . $this->userAgentMatcher->tableSuffix();
 }
開發者ID:vuong93st,項目名稱:w-game,代碼行數:4,代碼來源:TeraWurfl.php

示例10: __construct

 public function __construct(TeraWurfl $wurfl)
 {
     parent::__construct($wurfl);
     $this->matcher = $this->matcherName();
 }
開發者ID:pwodaniilea,項目名稱:t3x-contexts_wurfl,代碼行數:5,代碼來源:CatchAllUserAgentMatcher.php


注:本文中的UserAgentMatcher類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。