PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 3.2.5
Jetpack – WP Security, Backup, Speed, & Growth v3.2.5
16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 All 501 releases
jetpack / class.jetpack-user-agent.php

class.jetpack-user-agent.php in Jetpack – WP Security, Backup, Speed, & Growth 3.2.5, at class.jetpack-user-agent.php

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