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 |
||
129 | class Jetpack_User_Agent_Info { |
||
130 | |||
131 | public $useragent; |
||
132 | public $matched_agent; |
||
133 | public $isTierIphone; // Stores whether is the iPhone tier of devices. |
||
134 | public $isTierRichCss; // Stores whether the device can probably support Rich CSS, but JavaScript (jQuery) support is not assumed. |
||
135 | public $isTierGenericMobile; // Stores whether it is another mobile device, which cannot be assumed to support CSS or JS (eg, older BlackBerry, RAZR) |
||
136 | |||
137 | private $_platform = null; // Stores the device platform name |
||
138 | const PLATFORM_WINDOWS = 'windows'; |
||
139 | const PLATFORM_IPHONE = 'iphone'; |
||
140 | const PLATFORM_IPOD = 'ipod'; |
||
141 | const PLATFORM_IPAD = 'ipad'; |
||
142 | const PLATFORM_BLACKBERRY = 'blackberry'; |
||
143 | const PLATFORM_BLACKBERRY_10 = 'blackberry_10'; |
||
144 | const PLATFORM_SYMBIAN = 'symbian_series60'; |
||
145 | const PLATFORM_SYMBIAN_S40 = 'symbian_series40'; |
||
146 | const PLATFORM_J2ME_MIDP = 'j2me_midp'; |
||
147 | const PLATFORM_ANDROID = 'android'; |
||
148 | const PLATFORM_ANDROID_TABLET = 'android_tablet'; |
||
149 | const PLATFORM_FIREFOX_OS = 'firefoxOS'; |
||
150 | |||
151 | public $dumb_agents = array( |
||
152 | 'nokia', |
||
153 | 'blackberry', |
||
154 | 'philips', |
||
155 | 'samsung', |
||
156 | 'sanyo', |
||
157 | 'sony', |
||
158 | 'panasonic', |
||
159 | 'webos', |
||
160 | 'ericsson', |
||
161 | 'alcatel', |
||
162 | 'palm', |
||
163 | 'windows ce', |
||
164 | 'opera mini', |
||
165 | 'series60', |
||
166 | 'series40', |
||
167 | 'au-mic,', |
||
168 | 'audiovox', |
||
169 | 'avantgo', |
||
170 | 'blazer', |
||
171 | 'danger', |
||
172 | 'docomo', |
||
173 | 'epoc', |
||
174 | 'ericy', |
||
175 | 'i-mode', |
||
176 | 'ipaq', |
||
177 | 'midp-', |
||
178 | 'mot-', |
||
179 | 'netfront', |
||
180 | 'nitro', |
||
181 | 'palmsource', |
||
182 | 'pocketpc', |
||
183 | 'portalmmm', |
||
184 | 'rover', |
||
185 | 'sie-', |
||
186 | 'symbian', |
||
187 | 'cldc-', |
||
188 | 'j2me', |
||
189 | 'smartphone', |
||
190 | 'up.browser', |
||
191 | 'up.link', |
||
192 | 'up.link', |
||
193 | 'vodafone/', |
||
194 | 'wap1.', |
||
195 | 'wap2.', |
||
196 | 'mobile', |
||
197 | 'googlebot-mobile', |
||
198 | ); |
||
199 | |||
200 | // The constructor. Initializes default variables. |
||
201 | function __construct() { |
||
206 | |||
207 | /** |
||
208 | * This method detects the mobile User Agent name. |
||
209 | * |
||
210 | * @return string The matched User Agent name, false otherwise. |
||
211 | */ |
||
212 | function get_mobile_user_agent_name() { |
||
283 | |||
284 | /** |
||
285 | * This method detects the mobile device's platform. All return strings are from the class constants. |
||
286 | * Note that this function returns the platform name, not the UA name/type. You should use a different function |
||
287 | * if you need to test the UA capabilites. |
||
288 | * |
||
289 | * @return string Name of the platform, false otherwise. |
||
290 | */ |
||
291 | public function get_platform() { |
||
334 | |||
335 | /* |
||
336 | * This method detects for UA which can display iPhone-optimized web content. |
||
337 | * Includes iPhone, iPod Touch, Android, WebOS, Fennec (Firefox mobile), etc. |
||
338 | * |
||
339 | */ |
||
340 | function isTierIphone() { |
||
429 | |||
430 | /* |
||
431 | * This method detects for UA which are likely to be capable |
||
432 | * but may not necessarily support JavaScript. |
||
433 | * Excludes all iPhone Tier UA. |
||
434 | * |
||
435 | */ |
||
436 | function isTierRichCss() { |
||
469 | |||
470 | // Detects if the user is using a tablet. |
||
471 | // props Corey Gilmore, BGR.com |
||
472 | static function is_tablet() { |
||
482 | |||
483 | /* |
||
484 | * Detects if the current UA is the default iPhone or iPod Touch Browser. |
||
485 | * |
||
486 | * DEPRECATED: use is_iphone_or_ipod |
||
487 | * |
||
488 | */ |
||
489 | static function is_iphoneOrIpod() { |
||
506 | |||
507 | |||
508 | /* |
||
509 | * Detects if the current UA is iPhone Mobile Safari or another iPhone or iPod Touch Browser. |
||
510 | * |
||
511 | * They type can check for any iPhone, an iPhone using Safari, or an iPhone using something other than Safari. |
||
512 | * |
||
513 | * Note: If you want to check for Opera mini, Opera mobile or Firefox mobile (or any 3rd party iPhone browser), |
||
514 | * you should put the check condition before the check for 'iphone-any' or 'iphone-not-safari'. |
||
515 | * Otherwise those browsers will be 'catched' by the iphone string. |
||
516 | * |
||
517 | */ |
||
518 | static function is_iphone_or_ipod( $type = 'iphone-any' ) { |
||
536 | |||
537 | |||
538 | /* |
||
539 | * Detects if the current UA is Chrome for iOS |
||
540 | * |
||
541 | * The User-Agent string in Chrome for iOS is the same as the Mobile Safari User-Agent, with CriOS/<ChromeRevision> instead of Version/<VersionNum>. |
||
542 | * - 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 |
||
543 | */ |
||
544 | static function is_chrome_for_iOS() { |
||
561 | |||
562 | |||
563 | /* |
||
564 | * Detects if the current UA is Twitter for iPhone |
||
565 | * |
||
566 | * 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 |
||
567 | * 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 |
||
568 | * |
||
569 | */ |
||
570 | static function is_twitter_for_iphone() { |
||
587 | |||
588 | /* |
||
589 | * Detects if the current UA is Twitter for iPad |
||
590 | * |
||
591 | * 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 |
||
592 | * 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 |
||
593 | * |
||
594 | */ |
||
595 | static function is_twitter_for_ipad() { |
||
596 | if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { |
||
597 | return false; |
||
598 | } |
||
599 | |||
600 | $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] ); |
||
601 | |||
602 | if ( strpos( $ua, 'twitter for ipad' ) !== false ) { |
||
603 | return true; |
||
604 | View Code Duplication | } elseif ( strpos( $ua, 'ipad' ) !== false && strpos( $ua, 'twitter for iphone' ) !== false ) { |
|
605 | return true; |
||
606 | } else { |
||
607 | return false; |
||
608 | } |
||
609 | } |
||
610 | |||
611 | |||
612 | /* |
||
613 | * Detects if the current UA is Facebook for iPhone |
||
614 | * - Facebook 4020.0 (iPhone; iPhone OS 5.0.1; fr_FR) |
||
615 | * - 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] |
||
616 | * - 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] |
||
617 | */ |
||
618 | static function is_facebook_for_iphone() { |
||
639 | |||
640 | /* |
||
641 | * Detects if the current UA is Facebook for iPad |
||
642 | * - Facebook 4020.0 (iPad; iPhone OS 5.0.1; en_US) |
||
643 | * - 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] |
||
644 | * - 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] |
||
645 | */ |
||
646 | View Code Duplication | static function is_facebook_for_ipad() { |
|
663 | |||
664 | /* |
||
665 | * Detects if the current UA is WordPress for iOS |
||
666 | */ |
||
667 | static function is_wordpress_for_ios() { |
||
679 | |||
680 | /* |
||
681 | * Detects if the current device is an iPad. |
||
682 | * They type can check for any iPad, an iPad using Safari, or an iPad using something other than Safari. |
||
683 | * |
||
684 | * Note: If you want to check for Opera mini, Opera mobile or Firefox mobile (or any 3rd party iPad browser), |
||
685 | * you should put the check condition before the check for 'iphone-any' or 'iphone-not-safari'. |
||
686 | * Otherwise those browsers will be 'catched' by the ipad string. |
||
687 | * |
||
688 | */ |
||
689 | static function is_ipad( $type = 'ipad-any' ) { |
||
708 | |||
709 | /* |
||
710 | * Detects if the current browser is Firefox Mobile (Fennec) |
||
711 | * |
||
712 | * http://www.useragentstring.com/pages/Fennec/ |
||
713 | * Mozilla/5.0 (Windows NT 6.1; WOW64; rv:2.1.1) Gecko/20110415 Firefox/4.0.2pre Fennec/4.0.1 |
||
714 | * Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1b2pre) Gecko/20081015 Fennec/1.0a1 |
||
715 | */ |
||
716 | static function is_firefox_mobile() { |
||
730 | |||
731 | /* |
||
732 | * Detects if the current browser is Firefox for desktop |
||
733 | * |
||
734 | * https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent/Firefox |
||
735 | * Mozilla/5.0 (platform; rv:geckoversion) Gecko/geckotrail Firefox/firefoxversion |
||
736 | * The platform section will include 'Mobile' for phones and 'Tablet' for tablets. |
||
737 | * |
||
738 | */ |
||
739 | View Code Duplication | static function is_firefox_desktop() { |
|
753 | |||
754 | /* |
||
755 | * Detects if the current browser is FirefoxOS Native browser |
||
756 | * |
||
757 | * Mozilla/5.0 (Mobile; rv:14.0) Gecko/14.0 Firefox/14.0 |
||
758 | * |
||
759 | */ |
||
760 | View Code Duplication | static function is_firefox_os() { |
|
774 | |||
775 | |||
776 | /* |
||
777 | * Detects if the current browser is Opera Mobile |
||
778 | * |
||
779 | * What is the difference between Opera Mobile and Opera Mini? |
||
780 | * - Opera Mobile is a full Internet browser for mobile devices. |
||
781 | * - Opera Mini always uses a transcoder to convert the page for a small display. |
||
782 | * (it uses Opera advanced server compression technology to compress web content before it gets to a device. |
||
783 | * The rendering engine is on Opera's server.) |
||
784 | * |
||
785 | * Opera/9.80 (Windows NT 6.1; Opera Mobi/14316; U; en) Presto/2.7.81 Version/11.00" |
||
786 | * Opera/9.50 (Nintendo DSi; Opera/507; U; en-US) |
||
787 | */ |
||
788 | View Code Duplication | static function is_opera_mobile() { |
|
804 | |||
805 | |||
806 | /* |
||
807 | * Detects if the current browser is Opera Mini |
||
808 | * |
||
809 | * Opera/8.01 (J2ME/MIDP; Opera Mini/3.0.6306/1528; en; U; ssr) |
||
810 | * Opera/9.80 (Android;Opera Mini/6.0.24212/24.746 U;en) Presto/2.5.25 Version/10.5454 |
||
811 | * Opera/9.80 (iPhone; Opera Mini/5.0.019802/18.738; U; en) Presto/2.4.15 |
||
812 | * Opera/9.80 (J2ME/iPhone;Opera Mini/5.0.019802/886; U; ja) Presto/2.4.15 |
||
813 | * Opera/9.80 (J2ME/iPhone;Opera Mini/5.0.019802/886; U; ja) Presto/2.4.15 |
||
814 | * Opera/9.80 (Series 60; Opera Mini/5.1.22783/23.334; U; en) Presto/2.5.25 Version/10.54 |
||
815 | * Opera/9.80 (BlackBerry; Opera Mini/5.1.22303/22.387; U; en) Presto/2.5.25 Version/10.54 |
||
816 | * |
||
817 | */ |
||
818 | static function is_opera_mini() { |
||
819 | |||
820 | if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { |
||
821 | return false; |
||
822 | } |
||
823 | |||
824 | $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] ); |
||
825 | |||
826 | View Code Duplication | if ( strpos( $ua, 'opera' ) !== false && strpos( $ua, 'mini' ) !== false ) { |
|
827 | return true; |
||
828 | } else { |
||
829 | return false; |
||
830 | } |
||
831 | } |
||
832 | |||
833 | /* |
||
834 | * Detects if the current browser is Opera Mini, but not on a smart device OS(Android, iOS, etc) |
||
835 | * Used to send users on dumb devices to m.wor |
||
836 | */ |
||
837 | static function is_opera_mini_dumb() { |
||
855 | |||
856 | /* |
||
857 | * Detects if the current browser is Opera Mobile or Mini. |
||
858 | * DEPRECATED: use is_opera_mobile or is_opera_mini |
||
859 | * |
||
860 | * Opera Mini 5 Beta: Opera/9.80 (J2ME/MIDP; Opera Mini/5.0.15650/756; U; en) Presto/2.2.0 |
||
861 | * Opera Mini 8: Opera/8.01 (J2ME/MIDP; Opera Mini/3.0.6306/1528; en; U; ssr) |
||
862 | */ |
||
863 | static function is_OperaMobile() { |
||
864 | _deprecated_function( __FUNCTION__, 'always', 'is_opera_mini() or is_opera_mobile()' ); |
||
865 | |||
866 | if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { |
||
867 | return false; |
||
868 | } |
||
869 | |||
870 | $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] ); |
||
871 | |||
872 | if ( strpos( $ua, 'opera' ) !== false ) { |
||
873 | View Code Duplication | if ( ( strpos( $ua, 'mini' ) !== false ) || ( strpos( $ua, 'mobi' ) !== false ) ) { |
|
874 | return true; |
||
875 | } else { |
||
876 | return false; |
||
877 | } |
||
878 | } else { |
||
879 | return false; |
||
880 | } |
||
881 | } |
||
882 | |||
883 | /* |
||
884 | * Detects if the current browser is a Windows Phone 7 device. |
||
885 | * ex: Mozilla/4.0 (compatible; MSIE 7.0; Windows Phone OS 7.0; Trident/3.1; IEMobile/7.0; LG; GW910) |
||
886 | */ |
||
887 | View Code Duplication | static function is_WindowsPhone7() { |
|
904 | |||
905 | /* |
||
906 | * Detects if the current browser is a Windows Phone 8 device. |
||
907 | * ex: Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; ARM; Touch; IEMobile/10.0; <Manufacturer>; <Device> [;<Operator>]) |
||
908 | */ |
||
909 | static function is_windows_phone_8() { |
||
921 | |||
922 | |||
923 | /* |
||
924 | * Detects if the current browser is on a Palm device running the new WebOS. This EXCLUDES TouchPad. |
||
925 | * |
||
926 | * 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 |
||
927 | * 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 |
||
928 | * |
||
929 | */ |
||
930 | View Code Duplication | static function is_PalmWebOS() { |
|
947 | |||
948 | /* |
||
949 | * Detects if the current browser is the HP TouchPad default browser. This excludes phones wt WebOS. |
||
950 | * |
||
951 | * 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 |
||
952 | * 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 |
||
953 | * |
||
954 | */ |
||
955 | static function is_TouchPad() { |
||
971 | |||
972 | |||
973 | /* |
||
974 | * Detects if the current browser is the Series 60 Open Source Browser. |
||
975 | * |
||
976 | * 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 |
||
977 | * |
||
978 | * 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 |
||
979 | * |
||
980 | * 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 |
||
981 | * |
||
982 | */ |
||
983 | static function is_S60_OSSBrowser() { |
||
1010 | |||
1011 | /* |
||
1012 | * |
||
1013 | * Detects if the device platform is the Symbian Series 60. |
||
1014 | * |
||
1015 | */ |
||
1016 | static function is_symbian_platform() { |
||
1044 | |||
1045 | /* |
||
1046 | * |
||
1047 | * Detects if the device platform is the Symbian Series 40. |
||
1048 | * Nokia Browser for Series 40 is a proxy based browser, previously known as Ovi Browser. |
||
1049 | * This browser will report 'NokiaBrowser' in the header, however some older version will also report 'OviBrowser'. |
||
1050 | * |
||
1051 | */ |
||
1052 | View Code Duplication | static function is_symbian_s40_platform() { |
|
1068 | |||
1069 | View Code Duplication | static function is_J2ME_platform() { |
|
1070 | |||
1071 | if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { |
||
1072 | return false; |
||
1073 | } |
||
1074 | |||
1075 | $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); |
||
1076 | |||
1077 | if ( strpos( $agent, 'j2me/midp' ) !== false ) { |
||
1078 | return true; |
||
1079 | } elseif ( strpos( $agent, 'midp' ) !== false && strpos( $agent, 'cldc' ) ) { |
||
1080 | return true; |
||
1081 | } |
||
1082 | |||
1083 | return false; |
||
1084 | } |
||
1085 | |||
1086 | |||
1087 | /* |
||
1088 | * Detects if the current UA is on one of the Maemo-based Nokia Internet Tablets. |
||
1089 | */ |
||
1090 | static function is_MaemoTablet() { |
||
1114 | |||
1115 | /* |
||
1116 | * Detects if the current UA is a MeeGo device (Nokia Smartphone). |
||
1117 | */ |
||
1118 | View Code Duplication | static function is_MeeGo() { |
|
1136 | |||
1137 | |||
1138 | /* |
||
1139 | is_webkit() can be used to check the User Agent for an webkit generic browser |
||
1140 | */ |
||
1141 | View Code Duplication | static function is_webkit() { |
|
1142 | |||
1143 | if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { |
||
1144 | return false; |
||
1145 | } |
||
1146 | |||
1147 | $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); |
||
1148 | |||
1149 | $pos_webkit = strpos( $agent, 'webkit' ); |
||
1150 | |||
1151 | if ( $pos_webkit !== false ) { |
||
1152 | return true; |
||
1153 | } else { |
||
1154 | return false; |
||
1155 | } |
||
1156 | } |
||
1157 | |||
1158 | /** |
||
1159 | * Detects if the current browser is the Native Android browser. |
||
1160 | * |
||
1161 | * @return boolean true if the browser is Android otherwise false |
||
1162 | */ |
||
1163 | View Code Duplication | static function is_android() { |
|
1180 | |||
1181 | |||
1182 | /** |
||
1183 | * Detects if the current browser is the Native Android Tablet browser. |
||
1184 | * Assumes 'Android' should be in the user agent, but not 'mobile' |
||
1185 | * |
||
1186 | * @return boolean true if the browser is Android and not 'mobile' otherwise false |
||
1187 | */ |
||
1188 | static function is_android_tablet() { |
||
1209 | |||
1210 | /** |
||
1211 | * Detects if the current browser is the Kindle Fire Native browser. |
||
1212 | * |
||
1213 | * 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 |
||
1214 | * 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 |
||
1215 | * |
||
1216 | * @return boolean true if the browser is Kindle Fire Native browser otherwise false |
||
1217 | */ |
||
1218 | static function is_kindle_fire() { |
||
1232 | |||
1233 | |||
1234 | /** |
||
1235 | * Detects if the current browser is the Kindle Touch Native browser |
||
1236 | * |
||
1237 | * 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+ |
||
1238 | * |
||
1239 | * @return boolean true if the browser is Kindle monochrome Native browser otherwise false |
||
1240 | */ |
||
1241 | View Code Duplication | static function is_kindle_touch() { |
|
1242 | if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { |
||
1243 | return false; |
||
1244 | } |
||
1245 | $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); |
||
1246 | $pos_kindle_touch = strpos( $agent, 'kindle/3.0+' ); |
||
1247 | if ( false !== $pos_kindle_touch && false === self::is_kindle_fire() ) { |
||
1248 | return true; |
||
1249 | } else { |
||
1250 | return false; |
||
1251 | } |
||
1252 | } |
||
1253 | |||
1254 | |||
1255 | // Detect if user agent is the WordPress.com Windows 8 app (used ONLY on the custom oauth stylesheet) |
||
1256 | View Code Duplication | static function is_windows8_auth() { |
|
1257 | if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { |
||
1258 | return false; |
||
1259 | } |
||
1260 | |||
1261 | $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); |
||
1262 | $pos = strpos( $agent, 'msauthhost' ); |
||
1263 | if ( false !== $pos ) { |
||
1264 | return true; |
||
1265 | } else { |
||
1266 | return false; |
||
1267 | } |
||
1268 | } |
||
1269 | |||
1270 | // Detect if user agent is the WordPress.com Windows 8 app. |
||
1271 | View Code Duplication | static function is_wordpress_for_win8() { |
|
1272 | if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { |
||
1273 | return false; |
||
1274 | } |
||
1275 | |||
1276 | $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); |
||
1277 | $pos = strpos( $agent, 'wp-windows8' ); |
||
1278 | if ( false !== $pos ) { |
||
1279 | return true; |
||
1280 | } else { |
||
1281 | return false; |
||
1282 | } |
||
1283 | } |
||
1284 | |||
1285 | |||
1286 | // Detect if user agent is the WordPress.com Desktop app. |
||
1287 | static function is_wordpress_desktop_app() { |
||
1300 | |||
1301 | |||
1302 | /* |
||
1303 | * is_blackberry_tablet() can be used to check the User Agent for a RIM blackberry tablet |
||
1304 | * The user agent of the BlackBerry® Tablet OS follows a format similar to the following: |
||
1305 | * 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+ |
||
1306 | * |
||
1307 | */ |
||
1308 | static function is_blackberry_tablet() { |
||
1324 | |||
1325 | /* |
||
1326 | is_blackbeberry() can be used to check the User Agent for a blackberry device |
||
1327 | Note that opera mini on BB matches this rule. |
||
1328 | */ |
||
1329 | View Code Duplication | static function is_blackbeberry() { |
|
1348 | |||
1349 | /* |
||
1350 | is_blackberry_10() can be used to check the User Agent for a BlackBerry 10 device. |
||
1351 | */ |
||
1352 | static function is_blackberry_10() { |
||
1356 | |||
1357 | /** |
||
1358 | * Retrieve the blackberry OS version. |
||
1359 | * |
||
1360 | * Return strings are from the following list: |
||
1361 | * - blackberry-10 |
||
1362 | * - blackberry-7 |
||
1363 | * - blackberry-6 |
||
1364 | * - blackberry-torch //only the first edition. The 2nd edition has the OS7 onboard and doesn't need any special rule. |
||
1365 | * - blackberry-5 |
||
1366 | * - blackberry-4.7 |
||
1367 | * - blackberry-4.6 |
||
1368 | * - blackberry-4.5 |
||
1369 | * |
||
1370 | * @return string Version of the BB OS. |
||
1371 | * If version is not found, get_blackbeberry_OS_version will return boolean false. |
||
1372 | */ |
||
1373 | static function get_blackbeberry_OS_version() { |
||
1444 | |||
1445 | /** |
||
1446 | * Retrieve the blackberry browser version. |
||
1447 | * |
||
1448 | * Return string are from the following list: |
||
1449 | * - blackberry-10 |
||
1450 | * - blackberry-webkit |
||
1451 | * - blackberry-5 |
||
1452 | * - blackberry-4.7 |
||
1453 | * - blackberry-4.6 |
||
1454 | * |
||
1455 | * @return string Type of the BB browser. |
||
1456 | * If browser's version is not found, detect_blackbeberry_browser_version will return boolean false. |
||
1457 | */ |
||
1458 | static function detect_blackberry_browser_version() { |
||
1506 | |||
1507 | // Checks if a visitor is coming from one of the WordPress mobile apps |
||
1508 | static function is_mobile_app() { |
||
1534 | |||
1535 | /* |
||
1536 | * Detects if the current browser is Nintendo 3DS handheld. |
||
1537 | * |
||
1538 | * example: Mozilla/5.0 (Nintendo 3DS; U; ; en) Version/1.7498.US |
||
1539 | * can differ in language, version and region |
||
1540 | */ |
||
1541 | static function is_Nintendo_3DS() { |
||
1552 | |||
1553 | /** |
||
1554 | * Was the current request made by a known bot? |
||
1555 | * |
||
1556 | * @return boolean |
||
1557 | */ |
||
1558 | static function is_bot() { |
||
1567 | |||
1568 | /** |
||
1569 | * Is the given user-agent a known bot? |
||
1570 | * 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. |
||
1571 | * |
||
1572 | * @param $ua (string) A user-agent string |
||
1573 | * @return boolean |
||
1574 | */ |
||
1575 | static function is_bot_user_agent( $ua = null ) { |
||
1650 | |||
1651 | |||
1652 | |||
1653 | } |
||
1654 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.