Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Jetpack_User_Agent_Info often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Jetpack_User_Agent_Info, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
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() |
||
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() { |
||
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() { |
||
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 | View Code Duplication | 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 | View Code Duplication | 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 | View Code Duplication | 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 | View Code Duplication | 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 | View Code Duplication | 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 | View Code Duplication | 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 | View Code Duplication | 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 | View Code Duplication | 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(){ |
||
461 | |||
462 | // Detects if the user is using a tablet. |
||
463 | // props Corey Gilmore, BGR.com |
||
464 | static function is_tablet() { |
||
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(){ |
||
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' ) { |
||
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( ) { |
||
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( ) { |
||
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 | View Code Duplication | static function is_twitter_for_ipad( ) { |
|
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( ) { |
||
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 | View Code Duplication | static function is_facebook_for_ipad( ) { |
|
636 | |||
637 | /* |
||
638 | * Detects if the current UA is WordPress for iOS |
||
639 | */ |
||
640 | static function is_wordpress_for_ios( ) { |
||
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' ) { |
||
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( ) { |
||
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 | View Code Duplication | static function is_firefox_os( ) { |
|
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 | View Code Duplication | static function is_opera_mobile( ) { |
|
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( ) { |
||
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( ) { |
||
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() { |
||
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 | View Code Duplication | static function is_WindowsPhone7() { |
|
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() { |
||
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 | View Code Duplication | static function is_PalmWebOS() { |
|
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() { |
||
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() { |
||
935 | |||
936 | /* |
||
937 | * |
||
938 | * Detects if the device platform is the Symbian Series 60. |
||
939 | * |
||
940 | */ |
||
941 | static function is_symbian_platform() { |
||
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 | View Code Duplication | static function is_symbian_s40_platform() { |
|
988 | |||
989 | View Code Duplication | static function is_J2ME_platform() { |
|
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() { |
||
1028 | |||
1029 | /* |
||
1030 | * Detects if the current UA is a MeeGo device (Nokia Smartphone). |
||
1031 | */ |
||
1032 | View Code Duplication | static function is_MeeGo() { |
|
1048 | |||
1049 | |||
1050 | /* |
||
1051 | is_webkit() can be used to check the User Agent for an webkit generic browser |
||
1052 | */ |
||
1053 | View Code Duplication | static function is_webkit() { |
|
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 | View Code Duplication | static function is_android() { |
|
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( ) { |
||
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( ) { |
||
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 | View Code Duplication | static function is_kindle_touch( ) { |
|
1153 | |||
1154 | |||
1155 | // Detect if user agent is the WordPress.com Windows 8 app (used ONLY on the custom oauth stylesheet) |
||
1156 | View Code Duplication | static function is_windows8_auth( ) { |
|
1167 | |||
1168 | // Detect if user agent is the WordPress.com Windows 8 app. |
||
1169 | View Code Duplication | static function is_wordpress_for_win8( ) { |
|
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() { |
||
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 | View Code Duplication | static function is_blackbeberry() { |
|
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() { |
||
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() { |
||
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() { |
||
1383 | |||
1384 | // Checks if a visitor is coming from one of the WordPress mobile apps |
||
1385 | static function is_mobile_app() { |
||
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() { |
||
1426 | |||
1427 | /** |
||
1428 | * Was the current request made by a known bot? |
||
1429 | * |
||
1430 | * @return boolean |
||
1431 | */ |
||
1432 | static function is_bot() { |
||
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 ) { |
||
1472 | |||
1473 | |||
1474 | |||
1475 | } |
||
1476 |