Jetpack_User_Agent_Info

The Jetpack by WordPress.com Jetpack User Agent Info class.

Defined (1)

The class is defined in the following location(s).

/class.jetpack-user-agent.php  
  1. class Jetpack_User_Agent_Info { 
  2.  
  3. public $useragent; 
  4. public $matched_agent; 
  5. public $isTierIphone; //Stores whether is the iPhone tier of devices. 
  6. public $isTierRichCss; //Stores whether the device can probably support Rich CSS, but JavaScript (jQuery) support is not assumed. 
  7. public $isTierGenericMobile; //Stores whether it is another mobile device, which cannot be assumed to support CSS or JS (eg, older BlackBerry, RAZR) 
  8.  
  9. private $_platform = null; //Stores the device platform name 
  10. const PLATFORM_WINDOWS = 'windows'; 
  11. const PLATFORM_IPHONE = 'iphone'; 
  12. const PLATFORM_IPOD = 'ipod'; 
  13. const PLATFORM_IPAD = 'ipad'; 
  14. const PLATFORM_BLACKBERRY = 'blackberry'; 
  15. const PLATFORM_BLACKBERRY_10 = 'blackberry_10'; 
  16. const PLATFORM_SYMBIAN = 'symbian_series60'; 
  17. const PLATFORM_SYMBIAN_S40 = 'symbian_series40'; 
  18. const PLATFORM_J2ME_MIDP = 'j2me_midp'; 
  19. const PLATFORM_ANDROID = 'android'; 
  20. const PLATFORM_ANDROID_TABLET = 'android_tablet'; 
  21. const PLATFORM_FIREFOX_OS = 'firefoxOS'; 
  22.  
  23. public $dumb_agents = array( 
  24. 'nokia', 'blackberry', 'philips', 'samsung', 'sanyo', 'sony', 'panasonic', 'webos',  
  25. 'ericsson', 'alcatel', 'palm',  
  26. 'windows ce', 'opera mini', 'series60', 'series40',  
  27. 'au-mic, ', 'audiovox', 'avantgo', 'blazer',  
  28. 'danger', 'docomo', 'epoc',  
  29. 'ericy', 'i-mode', 'ipaq', 'midp-',  
  30. 'mot-', 'netfront', 'nitro',  
  31. 'palmsource', 'pocketpc', 'portalmmm',  
  32. 'rover', 'sie-',  
  33. 'symbian', 'cldc-', 'j2me',  
  34. 'smartphone', 'up.browser', 'up.link',  
  35. 'up.link', 'vodafone/', 'wap1.', 'wap2.', 'mobile', 'googlebot-mobile',  
  36. ); 
  37.  
  38. //The constructor. Initializes default variables. 
  39. function __construct() 
  40. if ( !empty( $_SERVER['HTTP_USER_AGENT'] ) ) 
  41. $this->useragent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); 
  42.  
  43. /** 
  44. * This method detects the mobile User Agent name. 
  45. * @return string The matched User Agent name, false otherwise. 
  46. */ 
  47. function get_mobile_user_agent_name() { 
  48. if( $this->is_chrome_for_iOS( ) ) //keep this check before the safari rule 
  49. return 'chrome-for-ios'; 
  50. elseif ( $this->is_iphone_or_ipod( 'iphone-safari' ) ) 
  51. return 'iphone'; 
  52. elseif ( $this->is_ipad( 'ipad-safari' ) ) 
  53. return 'ipad'; 
  54. elseif ( $this->is_android_tablet() ) //keep this check before the android rule 
  55. return 'android_tablet'; 
  56. elseif ( $this->is_android() ) 
  57. return 'android'; 
  58. elseif ( $this->is_blackberry_10() ) 
  59. return 'blackberry_10'; 
  60. elseif ( $this->is_blackbeberry() ) 
  61. return 'blackberry'; 
  62. elseif ( $this->is_WindowsPhone7() ) 
  63. return 'win7'; 
  64. elseif ( $this->is_windows_phone_8() ) 
  65. return 'winphone8'; 
  66. elseif ( $this->is_opera_mini() ) 
  67. return 'opera-mini'; 
  68. elseif ( $this->is_opera_mini_dumb() ) 
  69. return 'opera-mini-dumb'; 
  70. elseif ( $this->is_opera_mobile() ) 
  71. return 'opera-mobi'; 
  72. elseif ( $this->is_blackberry_tablet() ) 
  73. return 'blackberry_tablet'; 
  74. elseif ( $this->is_kindle_fire() ) 
  75. return 'kindle-fire'; 
  76. elseif ( $this->is_PalmWebOS() ) 
  77. return 'webos'; 
  78. elseif ( $this->is_S60_OSSBrowser() ) 
  79. return 'series60'; 
  80. elseif ( $this->is_firefox_os() ) 
  81. return 'firefoxOS'; 
  82. elseif ( $this->is_firefox_mobile() ) 
  83. return 'firefox_mobile'; 
  84. elseif ( $this->is_MaemoTablet() ) 
  85. return 'maemo'; 
  86. elseif ( $this->is_MeeGo() ) 
  87. return 'meego'; 
  88. elseif( $this->is_TouchPad() ) 
  89. return 'hp_tablet'; 
  90. elseif ( $this->is_facebook_for_iphone() ) 
  91. return 'facebook-for-iphone'; 
  92. elseif ( $this->is_facebook_for_ipad() ) 
  93. return 'facebook-for-ipad'; 
  94. elseif ( $this->is_twitter_for_iphone() ) 
  95. return 'twitter-for-iphone'; 
  96. elseif ( $this->is_twitter_for_ipad() ) 
  97. return 'twitter-for-ipad'; 
  98. elseif ( $this->is_wordpress_for_ios() ) 
  99. return 'ios-app'; 
  100. elseif ( $this->is_iphone_or_ipod( 'iphone-not-safari' ) ) 
  101. return 'iphone-unknown'; 
  102. elseif ( $this->is_ipad( 'ipad-not-safari' ) ) 
  103. return 'ipad-unknown'; 
  104. elseif ( $this->is_Nintendo_3DS() ) 
  105. return 'nintendo-3ds'; 
  106. else { 
  107. $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); 
  108. $dumb_agents = $this->dumb_agents; 
  109. foreach ( $dumb_agents as $dumb_agent ) { 
  110. if ( false !== strpos( $agent, $dumb_agent ) ) { 
  111. return $dumb_agent; 
  112.  
  113. return false; 
  114.  
  115. /** 
  116. * This method detects the mobile device's platform. All return strings are from the class constants. 
  117. * Note that this function returns the platform name, not the UA name/type. You should use a different function 
  118. * if you need to test the UA capabilites. 
  119. * @return string Name of the platform, false otherwise. 
  120. */ 
  121. public function get_platform() { 
  122. if ( isset( $this->_platform ) ) { 
  123. return $this->_platform; 
  124.  
  125. if ( strpos( $this->useragent, 'windows phone' ) !== false ) { 
  126. $this->_platform = self::PLATFORM_WINDOWS; 
  127. elseif ( strpos( $this->useragent, 'windows ce' ) !== false ) { 
  128. $this->_platform = self::PLATFORM_WINDOWS; 
  129. elseif ( strpos( $this->useragent, 'ipad' ) !== false ) { 
  130. $this->_platform = self::PLATFORM_IPAD; 
  131. else if ( strpos( $this->useragent, 'ipod' ) !== false ) { 
  132. $this->_platform = self::PLATFORM_IPOD; 
  133. else if ( strpos( $this->useragent, 'iphone' ) !== false ) { 
  134. $this->_platform = self::PLATFORM_IPHONE; 
  135. elseif ( strpos( $this->useragent, 'android' ) !== false ) { 
  136. if ( $this->is_android_tablet() ) 
  137. $this->_platform = self::PLATFORM_ANDROID_TABLET; 
  138. else 
  139. $this->_platform = self::PLATFORM_ANDROID; 
  140. elseif ( $this->is_kindle_fire() ) { 
  141. $this->_platform = self::PLATFORM_ANDROID_TABLET; 
  142. elseif ( $this->is_blackberry_10() ) { 
  143. $this->_platform = self::PLATFORM_BLACKBERRY_10; 
  144. elseif ( strpos( $this->useragent, 'blackberry' ) !== false ) { 
  145. $this->_platform = self::PLATFORM_BLACKBERRY; 
  146. elseif ( $this->is_blackberry_tablet() ) { 
  147. $this->_platform = self::PLATFORM_BLACKBERRY; 
  148. elseif ( $this->is_symbian_platform() ) { 
  149. $this->_platform = self::PLATFORM_SYMBIAN; 
  150. elseif ( $this->is_symbian_s40_platform() ) { 
  151. $this->_platform = self::PLATFORM_SYMBIAN_S40; 
  152. elseif ( $this->is_J2ME_platform() ) { 
  153. $this->_platform = self::PLATFORM_J2ME_MIDP; 
  154. elseif ( $this->is_firefox_os() ) { 
  155. $this->_platform = self::PLATFORM_FIREFOX_OS; 
  156. else 
  157. $this->_platform = false; 
  158.  
  159. return $this->_platform; 
  160.  
  161. /** 
  162. * This method detects for UA which can display iPhone-optimized web content. 
  163. * Includes iPhone, iPod Touch, Android, WebOS, Fennec (Firefox mobile), etc. 
  164. */ 
  165. function isTierIphone() { 
  166. if ( isset( $this->isTierIphone ) ) { 
  167. return $this->isTierIphone; 
  168. if ( $this->is_iphoneOrIpod() ) { 
  169. $this->matched_agent = 'iphone'; 
  170. $this->isTierIphone = true; 
  171. $this->isTierRichCss = false; 
  172. $this->isTierGenericMobile = false; 
  173. elseif ( $this->is_android() ) { 
  174. $this->matched_agent = 'android'; 
  175. $this->isTierIphone = true; 
  176. $this->isTierRichCss = false; 
  177. $this->isTierGenericMobile = false; 
  178. elseif ( $this->is_windows_phone_8() ) { 
  179. $this->matched_agent = 'winphone8'; 
  180. $this->isTierIphone = true; 
  181. $this->isTierRichCss = false; 
  182. $this->isTierGenericMobile = false; 
  183. elseif ( $this->is_WindowsPhone7() ) { 
  184. $this->matched_agent = 'win7'; 
  185. $this->isTierIphone = true; 
  186. $this->isTierRichCss = false; 
  187. $this->isTierGenericMobile = false; 
  188. elseif ( $this->is_blackberry_10() ) { 
  189. $this->matched_agent = 'blackberry-10'; 
  190. $this->isTierIphone = true; 
  191. $this->isTierRichCss = false; 
  192. $this->isTierGenericMobile = false; 
  193. elseif ( $this->is_blackbeberry() && $this->detect_blackberry_browser_version() == 'blackberry-webkit' ) { 
  194. $this->matched_agent = 'blackberry-webkit'; 
  195. $this->isTierIphone = true; 
  196. $this->isTierRichCss = false; 
  197. $this->isTierGenericMobile = false; 
  198. elseif ( $this->is_blackberry_tablet() ) { 
  199. $this->matched_agent = 'blackberry_tablet'; 
  200. $this->isTierIphone = true; 
  201. $this->isTierRichCss = false; 
  202. $this->isTierGenericMobile = false; 
  203. elseif ( $this->is_PalmWebOS() ) { 
  204. $this->matched_agent = 'webos'; 
  205. $this->isTierIphone = true; 
  206. $this->isTierRichCss = false; 
  207. $this->isTierGenericMobile = false; 
  208. elseif ( $this->is_TouchPad() ) { 
  209. $this->matched_agent = 'hp_tablet'; 
  210. $this->isTierIphone = true; 
  211. $this->isTierRichCss = false; 
  212. $this->isTierGenericMobile = false; 
  213. elseif ( $this->is_firefox_os() ) { 
  214. $this->matched_agent = 'firefoxOS'; 
  215. $this->isTierIphone = true; 
  216. $this->isTierRichCss = false; 
  217. $this->isTierGenericMobile = false; 
  218. elseif ( $this->is_firefox_mobile() ) { 
  219. $this->matched_agent = 'fennec'; 
  220. $this->isTierIphone = true; 
  221. $this->isTierRichCss = false; 
  222. $this->isTierGenericMobile = false; 
  223. elseif ( $this->is_opera_mobile() ) { 
  224. $this->matched_agent = 'opera-mobi'; 
  225. $this->isTierIphone = true; 
  226. $this->isTierRichCss = false; 
  227. $this->isTierGenericMobile = false; 
  228. elseif ( $this->is_MaemoTablet() ) { 
  229. $this->matched_agent = 'maemo'; 
  230. $this->isTierIphone = true; 
  231. $this->isTierRichCss = false; 
  232. $this->isTierGenericMobile = false; 
  233. elseif ( $this->is_MeeGo() ) { 
  234. $this->matched_agent = 'meego'; 
  235. $this->isTierIphone = true; 
  236. $this->isTierRichCss = false; 
  237. $this->isTierGenericMobile = false; 
  238. elseif ( $this->is_kindle_touch() ) { 
  239. $this->matched_agent = 'kindle-touch'; 
  240. $this->isTierIphone = true; 
  241. $this->isTierRichCss = false; 
  242. $this->isTierGenericMobile = false; 
  243. elseif ( $this->is_Nintendo_3DS() ) { 
  244. $this->matched_agent = 'nintendo-3ds'; 
  245. $this->isTierIphone = true; 
  246. $this->isTierRichCss = false; 
  247. $this->isTierGenericMobile = false; 
  248. else { 
  249. $this->isTierIphone = false; 
  250. return $this->isTierIphone; 
  251.  
  252. /** 
  253. * This method detects for UA which are likely to be capable 
  254. * but may not necessarily support JavaScript. 
  255. * Excludes all iPhone Tier UA. 
  256. */ 
  257. function isTierRichCss() { 
  258. if ( isset( $this->isTierRichCss ) ) { 
  259. return $this->isTierRichCss; 
  260. if ($this->isTierIphone()) 
  261. return false; 
  262.  
  263. //The following devices are explicitly ok. 
  264. if ( $this->is_S60_OSSBrowser() ) { 
  265. $this->matched_agent = 'series60'; 
  266. $this->isTierIphone = false; 
  267. $this->isTierRichCss = true; 
  268. $this->isTierGenericMobile = false; 
  269. elseif ( $this->is_opera_mini() ) { 
  270. $this->matched_agent = 'opera-mini'; 
  271. $this->isTierIphone = false; 
  272. $this->isTierRichCss = true; 
  273. $this->isTierGenericMobile = false; 
  274. elseif ( $this->is_blackbeberry() ) { 
  275. $detectedDevice = $this->detect_blackberry_browser_version(); 
  276. if ( $detectedDevice === 'blackberry-5' || $detectedDevice == 'blackberry-4.7' || $detectedDevice === 'blackberry-4.6' ) { 
  277. $this->matched_agent = $detectedDevice; 
  278. $this->isTierIphone = false; 
  279. $this->isTierRichCss = true; 
  280. $this->isTierGenericMobile = false; 
  281. else { 
  282. $this->isTierRichCss = false; 
  283.  
  284. return $this->isTierRichCss; 
  285.  
  286. // Detects if the user is using a tablet. 
  287. // props Corey Gilmore, BGR.com 
  288. static function is_tablet() { 
  289. return ( 0 // never true, but makes it easier to manage our list of tablet conditions 
  290. || self::is_ipad() 
  291. || self::is_android_tablet() 
  292. || self::is_blackberry_tablet() 
  293. || self::is_kindle_fire() 
  294. || self::is_MaemoTablet() 
  295. || self::is_TouchPad() 
  296. ); 
  297.  
  298. /** 
  299. * Detects if the current UA is the default iPhone or iPod Touch Browser. 
  300. * DEPRECATED: use is_iphone_or_ipod 
  301. */ 
  302. static function is_iphoneOrIpod() { 
  303.  
  304. if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) 
  305. return false; 
  306.  
  307. $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] ); 
  308. if ( ( strpos( $ua, 'iphone' ) !== false ) || ( strpos( $ua, 'ipod' ) !== false ) ) { 
  309. if ( self::is_opera_mini() || self::is_opera_mobile() || self::is_firefox_mobile() ) 
  310. return false; 
  311. else 
  312. return true; 
  313. else 
  314. return false; 
  315.  
  316.  
  317. /** 
  318. * Detects if the current UA is iPhone Mobile Safari or another iPhone or iPod Touch Browser. 
  319. * They type can check for any iPhone, an iPhone using Safari, or an iPhone using something other than Safari. 
  320. * Note: If you want to check for Opera mini, Opera mobile or Firefox mobile (or any 3rd party iPhone browser),  
  321. * you should put the check condition before the check for 'iphone-any' or 'iphone-not-safari'. 
  322. * Otherwise those browsers will be 'catched' by the iphone string. 
  323. */ 
  324. static function is_iphone_or_ipod( $type = 'iphone-any' ) { 
  325.  
  326. if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) 
  327. return false; 
  328.  
  329. $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] ); 
  330. $is_iphone = ( strpos( $ua, 'iphone' ) !== false ) || ( strpos( $ua, 'ipod' ) !== false ); 
  331. $is_safari = ( false !== strpos( $ua, 'safari' ) ); 
  332.  
  333. if ( 'iphone-safari' == $type ) 
  334. return $is_iphone && $is_safari; 
  335. elseif ( 'iphone-not-safari' == $type ) 
  336. return $is_iphone && !$is_safari; 
  337. else 
  338. return $is_iphone; 
  339.  
  340.  
  341. /** 
  342. * Detects if the current UA is Chrome for iOS 
  343. * The User-Agent string in Chrome for iOS is the same as the Mobile Safari User-Agent, with CriOS/<ChromeRevision> instead of Version/<VersionNum>. 
  344. * - Mozilla/5.0 (iPhone; U; CPU iPhone OS 5_1_1 like Mac OS X; en) AppleWebKit/534.46.0 (KHTML, like Gecko) CriOS/19.0.1084.60 Mobile/9B206 Safari/7534.48.3 
  345. */ 
  346. static function is_chrome_for_iOS( ) { 
  347. if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) 
  348. return false; 
  349.  
  350. if ( self::is_iphone_or_ipod( 'iphone-safari' ) === false ) return false; 
  351.  
  352. $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] ); 
  353.  
  354. if ( strpos( $ua, 'crios/' ) !== false ) 
  355. return true; 
  356. else 
  357. return false; 
  358.  
  359.  
  360. /** 
  361. * Detects if the current UA is Twitter for iPhone 
  362. * Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_5 like Mac OS X; nb-no) AppleWebKit/533.17.9 (KHTML, like Gecko) Mobile/8L1 Twitter for iPhone 
  363. * Mozilla/5.0 (iPhone; CPU iPhone OS 5_1_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Mobile/9B206 Twitter for iPhone 
  364. */ 
  365. static function is_twitter_for_iphone( ) { 
  366. if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) 
  367. return false; 
  368.  
  369. $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] ); 
  370.  
  371. if ( strpos( $ua, 'ipad' ) !== false ) 
  372. return false; 
  373.  
  374. if ( strpos( $ua, 'twitter for iphone' ) !== false ) 
  375. return true; 
  376. else 
  377. return false; 
  378.  
  379. /** 
  380. * Detects if the current UA is Twitter for iPad 
  381. * Old version 4.X - Mozilla/5.0 (iPad; U; CPU OS 4_3_5 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Mobile/8L1 Twitter for iPad 
  382. * Ver 5.0 or Higher - Mozilla/5.0 (iPad; CPU OS 5_1_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Mobile/9B206 Twitter for iPhone 
  383. */ 
  384. static function is_twitter_for_ipad( ) { 
  385. if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) 
  386. return false; 
  387.  
  388. $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] ); 
  389.  
  390. if ( strpos( $ua, 'twitter for ipad' ) !== false ) 
  391. return true; 
  392. elseif( strpos( $ua, 'ipad' ) !== false && strpos( $ua, 'twitter for iphone' ) !== false ) 
  393. return true; 
  394. else 
  395. return false; 
  396.  
  397.  
  398. /** 
  399. * Detects if the current UA is Facebook for iPhone 
  400. * - Facebook 4020.0 (iPhone; iPhone OS 5.0.1; fr_FR) 
  401. * - Mozilla/5.0 (iPhone; U; CPU iPhone OS 5_0 like Mac OS X; en_US) AppleWebKit (KHTML, like Gecko) Mobile [FBAN/FBForIPhone;FBAV/4.0.2;FBBV/4020.0;FBDV/iPhone3, 1;FBMD/iPhone;FBSN/iPhone OS;FBSV/5.0;FBSS/2; FBCR/O2;FBID/phone;FBLC/en_US;FBSF/2.0] 
  402. * - Mozilla/5.0 (iPhone; CPU iPhone OS 5_1_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Mobile/9B206 [FBAN/FBIOS;FBAV/5.0;FBBV/47423;FBDV/iPhone3, 1;FBMD/iPhone;FBSN/iPhone OS;FBSV/5.1.1;FBSS/2; FBCR/3ITA;FBID/phone;FBLC/en_US] 
  403. */ 
  404. static function is_facebook_for_iphone( ) { 
  405. if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) 
  406. return false; 
  407.  
  408. $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] ); 
  409.  
  410. if( strpos( $ua, 'iphone' ) === false ) 
  411. return false; 
  412.  
  413. if ( strpos( $ua, 'facebook' ) !== false && strpos( $ua, 'ipad' ) === false ) 
  414. return true; 
  415. else if ( strpos( $ua, 'fbforiphone' ) !== false && strpos( $ua, 'tablet' ) === false ) 
  416. return true; 
  417. else if ( strpos( $ua, 'fban/fbios;' ) !== false && strpos( $ua, 'tablet' ) === false ) //FB app v5.0 or higher 
  418. return true; 
  419. else 
  420. return false; 
  421.  
  422. /** 
  423. * Detects if the current UA is Facebook for iPad 
  424. * - Facebook 4020.0 (iPad; iPhone OS 5.0.1; en_US) 
  425. * - Mozilla/5.0 (iPad; U; CPU iPhone OS 5_0 like Mac OS X; en_US) AppleWebKit (KHTML, like Gecko) Mobile [FBAN/FBForIPhone;FBAV/4.0.2;FBBV/4020.0;FBDV/iPad2, 1;FBMD/iPad;FBSN/iPhone OS;FBSV/5.0;FBSS/1; FBCR/;FBID/tablet;FBLC/en_US;FBSF/1.0] 
  426. * - Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Mobile/10A403 [FBAN/FBIOS;FBAV/5.0;FBBV/47423;FBDV/iPad2, 1;FBMD/iPad;FBSN/iPhone OS;FBSV/6.0;FBSS/1; FBCR/;FBID/tablet;FBLC/en_US] 
  427. */ 
  428. static function is_facebook_for_ipad( ) { 
  429. if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) 
  430. return false; 
  431.  
  432. $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] ); 
  433.  
  434. if ( strpos( $ua, 'ipad' ) === false ) 
  435. return false; 
  436.  
  437. if ( strpos( $ua, 'facebook' ) !== false || strpos( $ua, 'fbforiphone' ) !== false || strpos( $ua, 'fban/fbios;' ) !== false ) 
  438. return true; 
  439. else 
  440. return false; 
  441.  
  442. /** 
  443. * Detects if the current UA is WordPress for iOS 
  444. */ 
  445. static function is_wordpress_for_ios( ) { 
  446. if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) 
  447. return false; 
  448.  
  449. $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] ); 
  450. if ( strpos( $ua, 'wp-iphone' ) !== false ) 
  451. return true; 
  452. else 
  453. return false; 
  454.  
  455. /** 
  456. * Detects if the current device is an iPad. 
  457. * They type can check for any iPad, an iPad using Safari, or an iPad using something other than Safari. 
  458. * Note: If you want to check for Opera mini, Opera mobile or Firefox mobile (or any 3rd party iPad browser),  
  459. * you should put the check condition before the check for 'iphone-any' or 'iphone-not-safari'. 
  460. * Otherwise those browsers will be 'catched' by the ipad string. 
  461. */ 
  462. static function is_ipad( $type = 'ipad-any' ) { 
  463.  
  464. if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) 
  465. return false; 
  466.  
  467. $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] ); 
  468.  
  469. $is_ipad = ( false !== strpos( $ua, 'ipad' ) ); 
  470. $is_safari = ( false !== strpos( $ua, 'safari' ) ); 
  471.  
  472. if ( 'ipad-safari' == $type ) 
  473. return $is_ipad && $is_safari; 
  474. elseif ( 'ipad-not-safari' == $type ) 
  475. return $is_ipad && !$is_safari; 
  476. else 
  477. return $is_ipad; 
  478.  
  479. /** 
  480. * Detects if the current browser is Firefox Mobile (Fennec) 
  481. * http://www.useragentstring.com/pages/Fennec/ 
  482. * Mozilla/5.0 (Windows NT 6.1; WOW64; rv:2.1.1) Gecko/20110415 Firefox/4.0.2pre Fennec/4.0.1 
  483. * Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1b2pre) Gecko/20081015 Fennec/1.0a1 
  484. */ 
  485. static function is_firefox_mobile( ) { 
  486.  
  487. if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) 
  488. return false; 
  489.  
  490. $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] ); 
  491.  
  492. if ( strpos( $ua, 'fennec' ) !== false ) 
  493. return true; 
  494. else 
  495. return false; 
  496.  
  497.  
  498. /** 
  499. * Detects if the current browser is FirefoxOS Native browser 
  500. * Mozilla/5.0 (Mobile; rv:14.0) Gecko/14.0 Firefox/14.0 
  501. */ 
  502. static function is_firefox_os( ) { 
  503.  
  504. if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) 
  505. return false; 
  506.  
  507. $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] ); 
  508.  
  509. if ( strpos( $ua, 'mozilla' ) !== false && strpos( $ua, 'mobile' ) !== false && strpos( $ua, 'gecko' ) !== false && strpos( $ua, 'firefox' ) !== false) 
  510. return true; 
  511. else 
  512. return false; 
  513.  
  514.  
  515. /** 
  516. * Detects if the current browser is Opera Mobile 
  517. * What is the difference between Opera Mobile and Opera Mini? 
  518. * - Opera Mobile is a full Internet browser for mobile devices. 
  519. * - Opera Mini always uses a transcoder to convert the page for a small display. 
  520. * (it uses Opera advanced server compression technology to compress web content before it gets to a device. 
  521. * The rendering engine is on Opera's server.) 
  522. * Opera/9.80 (Windows NT 6.1; Opera Mobi/14316; U; en) Presto/2.7.81 Version/11.00" 
  523. * Opera/9.50 (Nintendo DSi; Opera/507; U; en-US) 
  524. */ 
  525. static function is_opera_mobile( ) { 
  526.  
  527. if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) 
  528. return false; 
  529.  
  530. $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] ); 
  531.  
  532. if ( strpos( $ua, 'opera' ) !== false && strpos( $ua, 'mobi' ) !== false ) 
  533. return true; 
  534. elseif ( strpos( $ua, 'opera' ) !== false && strpos( $ua, 'nintendo dsi' ) !== false ) 
  535. return true; 
  536. else 
  537. return false; 
  538.  
  539.  
  540. /** 
  541. * Detects if the current browser is Opera Mini 
  542. * Opera/8.01 (J2ME/MIDP; Opera Mini/3.0.6306/1528; en; U; ssr) 
  543. * Opera/9.80 (Android;Opera Mini/6.0.24212/24.746 U;en) Presto/2.5.25 Version/10.5454 
  544. * Opera/9.80 (iPhone; Opera Mini/5.0.019802/18.738; U; en) Presto/2.4.15 
  545. * Opera/9.80 (J2ME/iPhone;Opera Mini/5.0.019802/886; U; ja) Presto/2.4.15 
  546. * Opera/9.80 (J2ME/iPhone;Opera Mini/5.0.019802/886; U; ja) Presto/2.4.15 
  547. * Opera/9.80 (Series 60; Opera Mini/5.1.22783/23.334; U; en) Presto/2.5.25 Version/10.54 
  548. * Opera/9.80 (BlackBerry; Opera Mini/5.1.22303/22.387; U; en) Presto/2.5.25 Version/10.54 
  549. */ 
  550. static function is_opera_mini( ) { 
  551.  
  552. if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) 
  553. return false; 
  554.  
  555. $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] ); 
  556.  
  557. if ( strpos( $ua, 'opera' ) !== false && strpos( $ua, 'mini' ) !== false ) 
  558. return true; 
  559. else 
  560. return false; 
  561.  
  562. /** 
  563. * Detects if the current browser is Opera Mini, but not on a smart device OS(Android, iOS, etc) 
  564. * Used to send users on dumb devices to m.wor 
  565. */ 
  566. static function is_opera_mini_dumb( ) { 
  567.  
  568. if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) 
  569. return false; 
  570. $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] ); 
  571.  
  572. if ( self::is_opera_mini() ) { 
  573. if ( strpos( $ua, 'android' ) !== false || strpos( $ua, 'iphone' ) !== false || strpos( $ua, 'ipod' ) !== false 
  574. || strpos( $ua, 'ipad' ) !== false || strpos( $ua, 'blackberry' ) !== false) 
  575. return false; 
  576. else 
  577. return true; 
  578. } else { 
  579. return false; 
  580.  
  581. /** 
  582. * Detects if the current browser is Opera Mobile or Mini. 
  583. * DEPRECATED: use is_opera_mobile or is_opera_mini 
  584. * Opera Mini 5 Beta: Opera/9.80 (J2ME/MIDP; Opera Mini/5.0.15650/756; U; en) Presto/2.2.0 
  585. * Opera Mini 8: Opera/8.01 (J2ME/MIDP; Opera Mini/3.0.6306/1528; en; U; ssr) 
  586. */ 
  587. static function is_OperaMobile() { 
  588. _deprecated_function( __FUNCTION__, 'always', 'is_opera_mini() or is_opera_mobile()' ); 
  589.  
  590. if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) 
  591. return false; 
  592.  
  593. $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] ); 
  594.  
  595. if ( strpos( $ua, 'opera' ) !== false ) { 
  596. if ( ( strpos( $ua, 'mini' ) !== false ) || ( strpos( $ua, 'mobi' ) !== false ) ) 
  597. return true; 
  598. else 
  599. return false; 
  600. } else { 
  601. return false; 
  602.  
  603. /** 
  604. * Detects if the current browser is a Windows Phone 7 device. 
  605. * ex: Mozilla/4.0 (compatible; MSIE 7.0; Windows Phone OS 7.0; Trident/3.1; IEMobile/7.0; LG; GW910) 
  606. */ 
  607. static function is_WindowsPhone7() { 
  608. if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) 
  609. return false; 
  610.  
  611. $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] ); 
  612.  
  613. if ( strpos( $ua, 'windows phone os 7' ) === false ) { 
  614. return false; 
  615. } else { 
  616. if ( self::is_opera_mini() || self::is_opera_mobile() || self::is_firefox_mobile() ) 
  617. return false; 
  618. else 
  619. return true; 
  620.  
  621. /** 
  622. * Detects if the current browser is a Windows Phone 8 device. 
  623. * ex: Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; ARM; Touch; IEMobile/10.0; <Manufacturer>; <Device> [;<Operator>]) 
  624. */ 
  625. static function is_windows_phone_8() { 
  626. if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) 
  627. return false; 
  628.  
  629. $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] ); 
  630. if ( strpos( $ua, 'windows phone 8' ) === false ) { 
  631. return false; 
  632. } else { 
  633. return true; 
  634.  
  635.  
  636. /** 
  637. * Detects if the current browser is on a Palm device running the new WebOS. This EXCLUDES TouchPad. 
  638. * ex1: Mozilla/5.0 (webOS/1.4.0; U; en-US) AppleWebKit/532.2 (KHTML, like Gecko) Version/1.0 Safari/532.2 Pre/1.1 
  639. * ex2: Mozilla/5.0 (webOS/1.4.0; U; en-US) AppleWebKit/532.2 (KHTML, like Gecko) Version/1.0 Safari/532.2 Pixi/1.1 
  640. */ 
  641. static function is_PalmWebOS() { 
  642. if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) 
  643. return false; 
  644.  
  645. $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] ); 
  646.  
  647. if ( strpos( $ua, 'webos' ) === false ) { 
  648. return false; 
  649. } else { 
  650. if ( self::is_opera_mini() || self::is_opera_mobile() || self::is_firefox_mobile() ) 
  651. return false; 
  652. else 
  653. return true; 
  654.  
  655. /** 
  656. * Detects if the current browser is the HP TouchPad default browser. This excludes phones wt WebOS. 
  657. * TouchPad Emulator: Mozilla/5.0 (hp-desktop; Linux; hpwOS/2.0; U; it-IT) AppleWebKit/534.6 (KHTML, like Gecko) wOSBrowser/233.70 Safari/534.6 Desktop/1.0 
  658. * TouchPad: Mozilla/5.0 (hp-tablet; Linux; hpwOS/3.0.0; U; en-US) AppleWebKit/534.6 (KHTML, like Gecko) wOSBrowser/233.70 Safari/534.6 TouchPad/1.0 
  659. */ 
  660. static function is_TouchPad() { 
  661. if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) 
  662. return false; 
  663.  
  664. $http_user_agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); 
  665. if ( false !== strpos( $http_user_agent, 'hp-tablet' ) || false !== strpos( $http_user_agent, 'hpwos' ) || false !== strpos( $http_user_agent, 'touchpad' ) ) { 
  666. if ( self::is_opera_mini() || self::is_opera_mobile() || self::is_firefox_mobile() ) 
  667. return false; 
  668. else 
  669. return true; 
  670. else 
  671. return false; 
  672.  
  673.  
  674. /** 
  675. * Detects if the current browser is the Series 60 Open Source Browser. 
  676. * OSS Browser 3.2 on E75: Mozilla/5.0 (SymbianOS/9.3; U; Series60/3.2 NokiaE75-1/110.48.125 Profile/MIDP-2.1 Configuration/CLDC-1.1 ) AppleWebKit/413 (KHTML, like Gecko) Safari/413 
  677. * 7.0 Browser (Nokia 5800 XpressMusic (v21.0.025)) : Mozilla/5.0 (SymbianOS/9.4; U; Series60/5.0 Nokia5800d-1/21.0.025; Profile/MIDP-2.1 Configuration/CLDC-1.1 ) AppleWebKit/413 (KHTML, like Gecko) Safari/413 
  678. * Browser 7.1 (Nokia N97 (v12.0.024)) : Mozilla/5.0 (SymbianOS/9.4; Series60/5.0 NokiaN97-1/12.0.024; Profile/MIDP-2.1 Configuration/CLDC-1.1; en-us) AppleWebKit/525 (KHTML, like Gecko) BrowserNG/7.1.12344 
  679. */ 
  680. static function is_S60_OSSBrowser() { 
  681.  
  682. if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) 
  683. return false; 
  684.  
  685. $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); 
  686. if ( self::is_opera_mini() || self::is_opera_mobile() || self::is_firefox_mobile() ) 
  687. return false; 
  688.  
  689. $pos_webkit = strpos( $agent, 'webkit' ); 
  690. if ( $pos_webkit !== false ) { 
  691. //First, test for WebKit, then make sure it's either Symbian or S60. 
  692. if ( strpos( $agent, 'symbian' ) !== false || strpos( $agent, 'series60' ) !== false ) { 
  693. return true; 
  694. } else 
  695. return false; 
  696. } elseif ( strpos( $agent, 'symbianos' ) !== false && strpos( $agent, 'series60' ) !== false ) { 
  697. return true; 
  698. } elseif ( strpos( $agent, 'nokia' ) !== false && strpos( $agent, 'series60' ) !== false ) { 
  699. return true; 
  700.  
  701. return false; 
  702.  
  703. /** 
  704. * Detects if the device platform is the Symbian Series 60. 
  705. */ 
  706. static function is_symbian_platform() { 
  707.  
  708. if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) 
  709. return false; 
  710.  
  711. $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); 
  712.  
  713. $pos_webkit = strpos( $agent, 'webkit' ); 
  714. if ( $pos_webkit !== false ) { 
  715. //First, test for WebKit, then make sure it's either Symbian or S60. 
  716. if ( strpos( $agent, 'symbian' ) !== false || strpos( $agent, 'series60' ) !== false ) { 
  717. return true; 
  718. } else 
  719. return false; 
  720. } elseif ( strpos( $agent, 'symbianos' ) !== false && strpos( $agent, 'series60' ) !== false ) { 
  721. return true; 
  722. } elseif ( strpos( $agent, 'nokia' ) !== false && strpos( $agent, 'series60' ) !== false ) { 
  723. return true; 
  724. } elseif ( strpos( $agent, 'opera mini' ) !== false ) { 
  725. if( strpos( $agent, 'symbianos' ) !== false || strpos( $agent, 'symbos' ) !== false || strpos( $agent, 'series 60' ) !== false ) 
  726. return true; 
  727.  
  728. return false; 
  729.  
  730. /** 
  731. * Detects if the device platform is the Symbian Series 40. 
  732. * Nokia Browser for Series 40 is a proxy based browser, previously known as Ovi Browser. 
  733. * This browser will report 'NokiaBrowser' in the header, however some older version will also report 'OviBrowser'. 
  734. */ 
  735. static function is_symbian_s40_platform() { 
  736.  
  737. if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) 
  738. return false; 
  739.  
  740. $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); 
  741.  
  742. if ( strpos( $agent, 'series40' ) !== false ) { 
  743. if( strpos( $agent, 'nokia' ) !== false || strpos( $agent, 'ovibrowser' ) !== false || strpos( $agent, 'nokiabrowser' ) !== false ) 
  744. return true; 
  745.  
  746. return false; 
  747.  
  748. static function is_J2ME_platform() { 
  749.  
  750. if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) 
  751. return false; 
  752.  
  753. $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); 
  754.  
  755. if ( strpos( $agent, 'j2me/midp' ) !== false ) { 
  756. return true; 
  757. } elseif ( strpos( $agent, 'midp' ) !== false && strpos( $agent, 'cldc' ) ) { 
  758. return true; 
  759.  
  760. return false; 
  761.  
  762.  
  763. /** 
  764. * Detects if the current UA is on one of the Maemo-based Nokia Internet Tablets. 
  765. */ 
  766. static function is_MaemoTablet() { 
  767.  
  768. if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) 
  769. return false; 
  770.  
  771. $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); 
  772.  
  773. $pos_maemo = strpos( $agent, 'maemo' ); 
  774. if ( $pos_maemo === false ) return false; 
  775.  
  776. //Must be Linux + Tablet, or else it could be something else. 
  777. if ( strpos( $agent, 'tablet' ) !== false && strpos( $agent, 'linux' ) !== false ) { 
  778. if ( self::is_opera_mini() || self::is_opera_mobile() || self::is_firefox_mobile() ) 
  779. return false; 
  780. else 
  781. return true; 
  782. } else 
  783. return false; 
  784.  
  785. /** 
  786. * Detects if the current UA is a MeeGo device (Nokia Smartphone). 
  787. */ 
  788. static function is_MeeGo() { 
  789.  
  790. if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) 
  791. return false; 
  792.  
  793. $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] ); 
  794.  
  795. if ( strpos( $ua, 'meego' ) === false ) { 
  796. return false; 
  797. } else { 
  798. if ( self::is_opera_mini() || self::is_opera_mobile() || self::is_firefox_mobile() ) 
  799. return false; 
  800. else 
  801. return true; 
  802.  
  803.  
  804. /** 
  805. is_webkit() can be used to check the User Agent for an webkit generic browser 
  806. */ 
  807. static function is_webkit() { 
  808.  
  809. if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) 
  810. return false; 
  811.  
  812. $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); 
  813.  
  814. $pos_webkit = strpos( $agent, 'webkit' ); 
  815.  
  816. if ( $pos_webkit !== false ) 
  817. return true; 
  818. else 
  819. return false; 
  820.  
  821. /** 
  822. * Detects if the current browser is the Native Android browser. 
  823. * @return boolean true if the browser is Android otherwise false 
  824. */ 
  825. static function is_android() { 
  826. if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) 
  827. return false; 
  828.  
  829. $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); 
  830. $pos_android = strpos( $agent, 'android' ); 
  831. if ( $pos_android !== false ) { 
  832. if ( self::is_opera_mini() || self::is_opera_mobile() || self::is_firefox_mobile() ) 
  833. return false; 
  834. else 
  835. return true; 
  836. else 
  837. return false; 
  838.  
  839.  
  840. /** 
  841. * Detects if the current browser is the Native Android Tablet browser. 
  842. * Assumes 'Android' should be in the user agent, but not 'mobile' 
  843. * @return boolean true if the browser is Android and not 'mobile' otherwise false 
  844. */ 
  845. static function is_android_tablet( ) { 
  846. if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) 
  847. return false; 
  848.  
  849. $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); 
  850.  
  851. $pos_android = strpos( $agent, 'android' ); 
  852. $pos_mobile = strpos( $agent, 'mobile' ); 
  853. $post_android_app = strpos( $agent, 'wp-android' ); 
  854.  
  855. if ( $pos_android !== false && $pos_mobile === false && $post_android_app === false ) { 
  856. if ( self::is_opera_mini() || self::is_opera_mobile() || self::is_firefox_mobile() ) 
  857. return false; 
  858. else 
  859. return true; 
  860. } else 
  861. return false; 
  862.  
  863. /** 
  864. * Detects if the current browser is the Kindle Fire Native browser. 
  865. * Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-us; Silk/1.1.0-84) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16 Silk-Accelerated=true 
  866. * Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-us; Silk/1.1.0-84) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16 Silk-Accelerated=false 
  867. * @return boolean true if the browser is Kindle Fire Native browser otherwise false 
  868. */ 
  869. static function is_kindle_fire( ) { 
  870. if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) 
  871. return false; 
  872.  
  873. $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); 
  874. $pos_silk = strpos( $agent, 'silk/' ); 
  875. $pos_silk_acc = strpos( $agent, 'silk-accelerated=' ); 
  876. if ( $pos_silk !== false && $pos_silk_acc !== false ) 
  877. return true; 
  878. else 
  879. return false; 
  880.  
  881.  
  882. /** 
  883. * Detects if the current browser is the Kindle Touch Native browser 
  884. * Mozilla/5.0 (X11; U; Linux armv7l like Android; en-us) AppleWebKit/531.2+ (KHTML, like Gecko) Version/5.0 Safari/533.2+ Kindle/3.0+ 
  885. * @return boolean true if the browser is Kindle monochrome Native browser otherwise false 
  886. */ 
  887. static function is_kindle_touch( ) { 
  888. if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) 
  889. return false; 
  890. $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); 
  891. $pos_kindle_touch = strpos( $agent, 'kindle/3.0+' ); 
  892. if ( $pos_kindle_touch !== false && self::is_kindle_fire() === false ) 
  893. return true; 
  894. else 
  895. return false; 
  896.  
  897.  
  898. // Detect if user agent is the WordPress.com Windows 8 app (used ONLY on the custom oauth stylesheet) 
  899. static function is_windows8_auth( ) { 
  900. if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) 
  901. return false; 
  902.  
  903. $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); 
  904. $pos = strpos( $agent, 'msauthhost' ); 
  905. if ( $pos !== false ) 
  906. return true; 
  907. else 
  908. return false; 
  909.  
  910. // Detect if user agent is the WordPress.com Windows 8 app. 
  911. static function is_wordpress_for_win8( ) { 
  912. if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) 
  913. return false; 
  914.  
  915. $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); 
  916. $pos = strpos( $agent, 'wp-windows8' ); 
  917. if ( $pos !== false ) 
  918. return true; 
  919. else 
  920. return false; 
  921.  
  922.  
  923. /** 
  924. * is_blackberry_tablet() can be used to check the User Agent for a RIM blackberry tablet 
  925. * The user agent of the BlackBerry Tablet OS follows a format similar to the following: 
  926. * Mozilla/5.0 (PlayBook; U; RIM Tablet OS 1.0.0; en-US) AppleWebKit/534.8+ (KHTML, like Gecko) Version/0.0.1 Safari/534.8+ 
  927. */ 
  928. static function is_blackberry_tablet() { 
  929.  
  930. if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) 
  931. return false; 
  932.  
  933. $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); 
  934. $pos_playbook = stripos( $agent, 'PlayBook' ); 
  935. $pos_rim_tablet = stripos( $agent, 'RIM Tablet' ); 
  936.  
  937. if ( ($pos_playbook === false) || ($pos_rim_tablet === false) ) 
  938. return false; 
  939. } else { 
  940. return true; 
  941.  
  942. /** 
  943. is_blackbeberry() can be used to check the User Agent for a blackberry device 
  944. Note that opera mini on BB matches this rule. 
  945. */ 
  946. static function is_blackbeberry() { 
  947.  
  948. if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) 
  949. return false; 
  950.  
  951. $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); 
  952.  
  953. $pos_blackberry = strpos( $agent, 'blackberry' ); 
  954. if ( $pos_blackberry !== false ) { 
  955. if ( self::is_opera_mini() || self::is_opera_mobile() || self::is_firefox_mobile() ) 
  956. return false; 
  957. else 
  958. return true; 
  959. } else { 
  960. return false; 
  961.  
  962. /** 
  963. is_blackberry_10() can be used to check the User Agent for a BlackBerry 10 device. 
  964. */ 
  965. static function is_blackberry_10() { 
  966. $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); 
  967. return ( strpos( $agent, 'bb10' ) !== false ) && ( strpos( $agent, 'mobile' ) !== false ); 
  968.  
  969. /** 
  970. * Retrieve the blackberry OS version. 
  971. * Return strings are from the following list: 
  972. * - blackberry-10 
  973. * - blackberry-7 
  974. * - blackberry-6 
  975. * - blackberry-torch //only the first edition. The 2nd edition has the OS7 onboard and doesn't need any special rule. 
  976. * - blackberry-5 
  977. * - blackberry-4.7 
  978. * - blackberry-4.6 
  979. * - blackberry-4.5 
  980. * @return string Version of the BB OS. 
  981. * If version is not found, get_blackbeberry_OS_version will return boolean false. 
  982. */ 
  983. static function get_blackbeberry_OS_version() { 
  984.  
  985. if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) 
  986. return false; 
  987.  
  988. if ( self::is_blackberry_10() ) { 
  989. return 'blackberry-10'; 
  990.  
  991. $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); 
  992.  
  993. $pos_blackberry = stripos( $agent, 'blackberry' ); 
  994. if ( $pos_blackberry === false ) { 
  995. // not a blackberry device 
  996. return false; 
  997.  
  998. // blackberry devices OS 6.0 or higher 
  999. // Mozilla/5.0 (BlackBerry; U; BlackBerry 9670; en) AppleWebKit/534.3+ (KHTML, like Gecko) Version/6.0.0.286 Mobile Safari/534.3+ 
  1000. // Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; en) AppleWebKit/534.1+ (KHTML, Like Gecko) Version/6.0.0.141 Mobile Safari/534.1+ 
  1001. // Mozilla/5.0 (BlackBerry; U; BlackBerry 9900; en-US) AppleWebKit/534.11+ (KHTML, like Gecko) Version/7.0.0 Mobile Safari/534.11+ 
  1002. $pos_webkit = stripos( $agent, 'webkit' ); 
  1003. if ( $pos_webkit !== false ) { 
  1004. // detected blackberry webkit browser 
  1005. $pos_torch = stripos( $agent, 'BlackBerry 9800' ); 
  1006. if ( $pos_torch !== false ) { 
  1007. return 'blackberry-torch'; // match the torch first edition. the 2nd edition should use the OS7 and doesn't need any special rule 
  1008. } else { 
  1009. // detecting the BB OS version for devices running OS 6.0 or higher 
  1010. if ( preg_match( '#Version\/([\d\.]+)#i', $agent, $matches ) ) { 
  1011. $version = $matches[1]; 
  1012. $version_num = explode( '.', $version ); 
  1013. if ( is_array( $version_num ) === false || count( $version_num ) <= 1 ) { 
  1014. return 'blackberry-6'; // not a BB device that match our rule. 
  1015. } else { 
  1016. return 'blackberry-' . $version_num[0]; 
  1017. } else { 
  1018. // if doesn't match returns the minimun version with a webkit browser. we should never fall here. 
  1019. return 'blackberry-6'; // not a BB device that match our rule. 
  1020.  
  1021. // blackberry devices <= 5.XX 
  1022. // BlackBerry9000/5.0.0.93 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/179 
  1023. if ( preg_match( '#BlackBerry\w+\/([\d\.]+)#i', $agent, $matches ) ) { 
  1024. $version = $matches[1]; 
  1025. } else { 
  1026. return false; //not a BB device that match our rule. 
  1027.  
  1028. $version_num = explode( '.', $version ); 
  1029.  
  1030. if ( is_array( $version_num ) === false || count( $version_num ) <= 1 ) { 
  1031. return false; 
  1032. if ( $version_num[0] == 5 ) { 
  1033. return 'blackberry-5'; 
  1034. } elseif ( $version_num[0] == 4 && $version_num[1] == 7 ) { 
  1035. return 'blackberry-4.7'; 
  1036. } elseif ( $version_num[0] == 4 && $version_num[1] == 6 ) { 
  1037. return 'blackberry-4.6'; 
  1038. } elseif ( $version_num[0] == 4 && $version_num[1] == 5 ) { 
  1039. return 'blackberry-4.5'; 
  1040. } else { 
  1041. return false; 
  1042.  
  1043.  
  1044. /** 
  1045. * Retrieve the blackberry browser version. 
  1046. * Return string are from the following list: 
  1047. * - blackberry-10 
  1048. * - blackberry-webkit 
  1049. * - blackberry-5 
  1050. * - blackberry-4.7 
  1051. * - blackberry-4.6 
  1052. * @return string Type of the BB browser. 
  1053. * If browser's version is not found, detect_blackbeberry_browser_version will return boolean false. 
  1054. */ 
  1055. static function detect_blackberry_browser_version() { 
  1056.  
  1057. if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { 
  1058. return false; 
  1059.  
  1060. $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); 
  1061.  
  1062. if ( self::is_blackberry_10() ) { 
  1063. return 'blackberry-10'; 
  1064.  
  1065. $pos_blackberry = strpos( $agent, 'blackberry' ); 
  1066. if ( $pos_blackberry === false ) { 
  1067. // not a blackberry device 
  1068. return false; 
  1069.  
  1070. $pos_webkit = strpos( $agent, 'webkit' ); 
  1071.  
  1072. if ( ! ( $pos_webkit === false ) ) { 
  1073. return 'blackberry-webkit'; 
  1074. } else { 
  1075. if ( preg_match( '#BlackBerry\w+\/([\d\.]+)#i', $agent, $matches ) ) { 
  1076. $version = $matches[1]; 
  1077. } else { 
  1078. return false; // not a BB device that match our rule. 
  1079.  
  1080. $version_num = explode( '.', $version ); 
  1081.  
  1082. if ( is_array( $version_num ) === false || count( $version_num ) <= 1 ) { 
  1083. return false; 
  1084.  
  1085. if ( $version_num[0] == 5 ) { 
  1086. return 'blackberry-5'; 
  1087. } elseif ( $version_num[0] == 4 && $version_num[1] == 7 ) { 
  1088. return 'blackberry-4.7'; 
  1089. } elseif ( $version_num[0] == 4 && $version_num[1] == 6 ) { 
  1090. return 'blackberry-4.6'; 
  1091. } else { 
  1092. // A very old BB device is found or this is a BB device that doesn't match our rules. 
  1093. return false; 
  1094.  
  1095.  
  1096. // Checks if a visitor is coming from one of the WordPress mobile apps 
  1097. static function is_mobile_app() { 
  1098.  
  1099. if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) 
  1100. return false; 
  1101.  
  1102. $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); 
  1103.  
  1104. if ( isset( $_SERVER['X_USER_AGENT'] ) && preg_match( '|wp-webos|', $_SERVER['X_USER_AGENT'] ) ) 
  1105. return true; //wp4webos 1.1 or higher 
  1106.  
  1107. $app_agents = array( 'wp-android', 'wp-blackberry', 'wp-iphone', 'wp-nokia', 'wp-webos', 'wp-windowsphone' ); 
  1108. // the mobile reader on iOS has an incorrect UA when loading the reader 
  1109. // currently it is the default one provided by the iOS framework which 
  1110. // causes problems with 2-step-auth 
  1111. // User-Agent WordPress/3.1.4 CFNetwork/609 Darwin/13.0.0 
  1112. $app_agents[] = 'wordpress/3.1'; 
  1113.  
  1114. foreach ( $app_agents as $app_agent ) { 
  1115. if ( false !== strpos( $agent, $app_agent ) ) 
  1116. return true; 
  1117. return false; 
  1118.  
  1119. /** 
  1120. * Detects if the current browser is Nintendo 3DS handheld. 
  1121. * example: Mozilla/5.0 (Nintendo 3DS; U; ; en) Version/1.7498.US 
  1122. * can differ in language, version and region 
  1123. */ 
  1124. static function is_Nintendo_3DS() { 
  1125. if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { 
  1126. return false; 
  1127.  
  1128. $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] ); 
  1129. if ( strpos( $ua, 'nintendo 3ds' ) !== false ) { 
  1130. return true; 
  1131. return false; 
  1132.  
  1133. /** 
  1134. * Was the current request made by a known bot? 
  1135. * @return boolean 
  1136. */ 
  1137. static function is_bot() { 
  1138. static $is_bot = null; 
  1139.  
  1140. if ( is_null( $is_bot ) ) { 
  1141. $is_bot = Jetpack_User_Agent_Info::is_bot_user_agent( $_SERVER['HTTP_USER_AGENT'] ); 
  1142.  
  1143. return $is_bot; 
  1144.  
  1145. /** 
  1146. * Is the given user-agent a known bot? 
  1147. * If you want an is_bot check for the current request's UA, use is_bot() instead of passing a user-agent to this method. 
  1148. * @param $ua (string) A user-agent string 
  1149. * @return boolean 
  1150. */ 
  1151. static function is_bot_user_agent( $ua = null ) { 
  1152.  
  1153. if ( empty( $ua ) ) 
  1154. return false; 
  1155.  
  1156. $bot_agents = array( 
  1157. 'alexa', 'altavista', 'ask jeeves', 'attentio', 'baiduspider', 'bingbot', 'chtml generic', 'crawler', 'fastmobilecrawl',  
  1158. 'feedfetcher-google', 'firefly', 'froogle', 'gigabot', 'googlebot', 'googlebot-mobile', 'heritrix', 'ia_archiver', 'irlbot',  
  1159. 'infoseek', 'jumpbot', 'lycos', 'mediapartners', 'mediobot', 'motionbot', 'msnbot', 'mshots', 'openbot',  
  1160. 'pss-webkit-request', 'pythumbnail', 'scooter', 'slurp', 'snapbot', 'spider', 'taptubot', 'technoratisnoop',  
  1161. 'teoma', 'twiceler', 'yahooseeker', 'yahooysmcm', 'yammybot', 'ahrefsbot', 'pingdom.com_bot', 'kraken', 'yandexbot',  
  1162. 'twitterbot', 'tweetmemebot', 'openhosebot', 'queryseekerspider', 'linkdexbot', 'grokkit-crawler',  
  1163. 'livelapbot', 'germcrawler', 'domaintunocrawler', 'grapeshotcrawler', 'cloudflare-alwaysonline',  
  1164. ); 
  1165.  
  1166. foreach ( $bot_agents as $bot_agent ) { 
  1167. if ( false !== stripos( $ua, $bot_agent ) ) { 
  1168. return true; 
  1169.  
  1170. return false; 
  1171.  
  1172.  
  1173.