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

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