PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 7.3.4
Jetpack – WP Security, Backup, Speed, & Growth v7.3.4
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 7.3.4, at class.jetpack-user-agent.php

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