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 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 User_Agent_Info, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
19 | class User_Agent_Info { |
||
20 | |||
21 | /** |
||
22 | * Provided or fetched User-Agent string. |
||
23 | * |
||
24 | * @var string |
||
25 | */ |
||
26 | public $useragent; |
||
27 | |||
28 | /** |
||
29 | * A device group matched user agent, e.g. 'iphone'. |
||
30 | * |
||
31 | * @var string |
||
32 | */ |
||
33 | public $matched_agent; |
||
34 | |||
35 | /** |
||
36 | * Stores whether is the iPhone tier of devices. |
||
37 | * |
||
38 | * @var bool |
||
39 | */ |
||
40 | public $isTierIphone; |
||
41 | |||
42 | /** |
||
43 | * Stores whether the device can probably support Rich CSS, but JavaScript (jQuery) support is not assumed. |
||
44 | * |
||
45 | * @var bool |
||
46 | */ |
||
47 | public $isTierRichCss; |
||
48 | |||
49 | /** |
||
50 | * Stores whether it is another mobile device, which cannot be assumed to support CSS or JS (eg, older BlackBerry, RAZR) |
||
51 | * |
||
52 | * @var bool |
||
53 | */ |
||
54 | public $isTierGenericMobile; |
||
55 | |||
56 | /** |
||
57 | * Stores the device platform name |
||
58 | * |
||
59 | * @var null|string |
||
60 | */ |
||
61 | private $platform = null; |
||
62 | const PLATFORM_WINDOWS = 'windows'; |
||
63 | const PLATFORM_IPHONE = 'iphone'; |
||
64 | const PLATFORM_IPOD = 'ipod'; |
||
65 | const PLATFORM_IPAD = 'ipad'; |
||
66 | const PLATFORM_BLACKBERRY = 'blackberry'; |
||
67 | const PLATFORM_BLACKBERRY_10 = 'blackberry_10'; |
||
68 | const PLATFORM_SYMBIAN = 'symbian_series60'; |
||
69 | const PLATFORM_SYMBIAN_S40 = 'symbian_series40'; |
||
70 | const PLATFORM_J2ME_MIDP = 'j2me_midp'; |
||
71 | const PLATFORM_ANDROID = 'android'; |
||
72 | const PLATFORM_ANDROID_TABLET = 'android_tablet'; |
||
73 | const PLATFORM_FIREFOX_OS = 'firefoxOS'; |
||
74 | |||
75 | /** |
||
76 | * A list of dumb-phone user agent parts. |
||
77 | * |
||
78 | * @var array |
||
79 | */ |
||
80 | public $dumb_agents = array( |
||
81 | 'nokia', |
||
82 | 'blackberry', |
||
83 | 'philips', |
||
84 | 'samsung', |
||
85 | 'sanyo', |
||
86 | 'sony', |
||
87 | 'panasonic', |
||
88 | 'webos', |
||
89 | 'ericsson', |
||
90 | 'alcatel', |
||
91 | 'palm', |
||
92 | 'windows ce', |
||
93 | 'opera mini', |
||
94 | 'series60', |
||
95 | 'series40', |
||
96 | 'au-mic,', |
||
97 | 'audiovox', |
||
98 | 'avantgo', |
||
99 | 'blazer', |
||
100 | 'danger', |
||
101 | 'docomo', |
||
102 | 'epoc', |
||
103 | 'ericy', |
||
104 | 'i-mode', |
||
105 | 'ipaq', |
||
106 | 'midp-', |
||
107 | 'mot-', |
||
108 | 'netfront', |
||
109 | 'nitro', |
||
110 | 'palmsource', |
||
111 | 'pocketpc', |
||
112 | 'portalmmm', |
||
113 | 'rover', |
||
114 | 'sie-', |
||
115 | 'symbian', |
||
116 | 'cldc-', |
||
117 | 'j2me', |
||
118 | 'smartphone', |
||
119 | 'up.browser', |
||
120 | 'up.link', |
||
121 | 'up.link', |
||
122 | 'vodafone/', |
||
123 | 'wap1.', |
||
124 | 'wap2.', |
||
125 | 'mobile', |
||
126 | 'googlebot-mobile', |
||
127 | ); |
||
128 | |||
129 | |||
130 | /** |
||
131 | * The constructor. |
||
132 | * |
||
133 | * @param string $ua (Optional) User agent. |
||
134 | */ |
||
135 | public function __construct( $ua = '' ) { |
||
144 | |||
145 | /** |
||
146 | * This method detects the mobile User Agent name. |
||
147 | * |
||
148 | * @return string The matched User Agent name, false otherwise. |
||
149 | */ |
||
150 | public function get_mobile_user_agent_name() { |
||
221 | |||
222 | /** |
||
223 | * This method detects the mobile device's platform. All return strings are from the class constants. |
||
224 | * Note that this function returns the platform name, not the UA name/type. You should use a different function |
||
225 | * if you need to test the UA capabilites. |
||
226 | * |
||
227 | * @return string Name of the platform, false otherwise. |
||
228 | */ |
||
229 | public function get_platform() { |
||
272 | |||
273 | /** |
||
274 | * This method detects for UA which can display iPhone-optimized web content. |
||
275 | * Includes iPhone, iPod Touch, Android, WebOS, Fennec (Firefox mobile), etc. |
||
276 | */ |
||
277 | public function isTierIphone() { |
||
366 | |||
367 | /** |
||
368 | * This method detects for UA which are likely to be capable |
||
369 | * but may not necessarily support JavaScript. |
||
370 | * Excludes all iPhone Tier UA. |
||
371 | */ |
||
372 | public function isTierRichCss() { |
||
409 | |||
410 | /** |
||
411 | * Detects if the user is using a tablet. |
||
412 | * props Corey Gilmore, BGR.com |
||
413 | * |
||
414 | * @return bool |
||
415 | */ |
||
416 | public function is_tablet() { |
||
426 | |||
427 | /** |
||
428 | * Detects if the current UA is the default iPhone or iPod Touch Browser. |
||
429 | * |
||
430 | * DEPRECATED: use is_iphone_or_ipod |
||
431 | */ |
||
432 | public function is_iphoneOrIpod() { |
||
433 | if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { |
||
434 | return false; |
||
435 | } |
||
436 | |||
437 | $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] ); |
||
438 | View Code Duplication | if ( ( strpos( $ua, 'iphone' ) !== false ) || ( strpos( $ua, 'ipod' ) !== false ) ) { |
|
439 | if ( self::is_opera_mini() || self::is_opera_mobile() || self::is_firefox_mobile() ) { |
||
440 | return false; |
||
441 | } else { |
||
442 | return true; |
||
443 | } |
||
444 | } else { |
||
445 | return false; |
||
446 | } |
||
447 | } |
||
448 | |||
449 | |||
450 | /** |
||
451 | * Detects if the current UA is iPhone Mobile Safari or another iPhone or iPod Touch Browser. |
||
452 | * |
||
453 | * They type can check for any iPhone, an iPhone using Safari, or an iPhone using something other than Safari. |
||
454 | * |
||
455 | * Note: If you want to check for Opera mini, Opera mobile or Firefox mobile (or any 3rd party iPhone browser), |
||
456 | * you should put the check condition before the check for 'iphone-any' or 'iphone-not-safari'. |
||
457 | * Otherwise those browsers will be 'catched' by the iphone string. |
||
458 | * |
||
459 | * @param string $type Type of iPhone detection. |
||
460 | */ |
||
461 | public static function is_iphone_or_ipod( $type = 'iphone-any' ) { |
||
478 | |||
479 | |||
480 | /** |
||
481 | * Detects if the current UA is Chrome for iOS |
||
482 | * |
||
483 | * The User-Agent string in Chrome for iOS is the same as the Mobile Safari User-Agent, with CriOS/<ChromeRevision> instead of Version/<VersionNum>. |
||
484 | * - 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 |
||
485 | */ |
||
486 | public static function is_chrome_for_iOS() { |
||
503 | |||
504 | |||
505 | /** |
||
506 | * Detects if the current UA is Twitter for iPhone |
||
507 | * |
||
508 | * 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 |
||
509 | * 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 |
||
510 | */ |
||
511 | public static function is_twitter_for_iphone() { |
||
528 | |||
529 | /** |
||
530 | * Detects if the current UA is Twitter for iPad |
||
531 | * |
||
532 | * 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 |
||
533 | * 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 |
||
534 | */ |
||
535 | public static function is_twitter_for_ipad() { |
||
536 | if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { |
||
537 | return false; |
||
538 | } |
||
539 | |||
540 | $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] ); |
||
541 | |||
542 | if ( strpos( $ua, 'twitter for ipad' ) !== false ) { |
||
543 | return true; |
||
544 | } elseif ( strpos( $ua, 'ipad' ) !== false && strpos( $ua, 'twitter for iphone' ) !== false ) { |
||
545 | return true; |
||
546 | } else { |
||
547 | return false; |
||
548 | } |
||
549 | } |
||
550 | |||
551 | /** |
||
552 | * Detects if the current UA is Facebook for iPhone |
||
553 | * - Facebook 4020.0 (iPhone; iPhone OS 5.0.1; fr_FR) |
||
554 | * - 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] |
||
555 | * - 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] |
||
556 | */ |
||
557 | public static function is_facebook_for_iphone() { |
||
578 | |||
579 | /** |
||
580 | * Detects if the current UA is Facebook for iPad |
||
581 | * - Facebook 4020.0 (iPad; iPhone OS 5.0.1; en_US) |
||
582 | * - 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] |
||
583 | * - 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] |
||
584 | */ |
||
585 | View Code Duplication | public static function is_facebook_for_ipad() { |
|
586 | if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { |
||
587 | return false; |
||
588 | } |
||
589 | |||
590 | $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] ); |
||
591 | |||
592 | if ( false === strpos( $ua, 'ipad' ) ) { |
||
593 | return false; |
||
594 | } |
||
595 | |||
596 | if ( false !== strpos( $ua, 'facebook' ) || false !== strpos( $ua, 'fbforiphone' ) || false !== strpos( $ua, 'fban/fbios;' ) ) { |
||
597 | return true; |
||
598 | } else { |
||
599 | return false; |
||
600 | } |
||
601 | } |
||
602 | |||
603 | /** |
||
604 | * Detects if the current UA is WordPress for iOS |
||
605 | */ |
||
606 | public static function is_wordpress_for_ios() { |
||
618 | |||
619 | /** |
||
620 | * Detects if the current device is an iPad. |
||
621 | * They type can check for any iPad, an iPad using Safari, or an iPad using something other than Safari. |
||
622 | * |
||
623 | * Note: If you want to check for Opera mini, Opera mobile or Firefox mobile (or any 3rd party iPad browser), |
||
624 | * you should put the check condition before the check for 'iphone-any' or 'iphone-not-safari'. |
||
625 | * Otherwise those browsers will be 'catched' by the ipad string. |
||
626 | * |
||
627 | * @param string $type iPad type. |
||
628 | */ |
||
629 | public static function is_ipad( $type = 'ipad-any' ) { |
||
648 | |||
649 | /** |
||
650 | * Detects if the current browser is Firefox Mobile (Fennec) |
||
651 | * |
||
652 | * See http://www.useragentstring.com/pages/Fennec/ |
||
653 | * Mozilla/5.0 (Windows NT 6.1; WOW64; rv:2.1.1) Gecko/20110415 Firefox/4.0.2pre Fennec/4.0.1 |
||
654 | * Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1b2pre) Gecko/20081015 Fennec/1.0a1 |
||
655 | */ |
||
656 | public static function is_firefox_mobile() { |
||
670 | |||
671 | /** |
||
672 | * Detects if the current browser is Firefox for desktop |
||
673 | * |
||
674 | * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent/Firefox |
||
675 | * Mozilla/5.0 (platform; rv:geckoversion) Gecko/geckotrail Firefox/firefoxversion |
||
676 | * The platform section will include 'Mobile' for phones and 'Tablet' for tablets. |
||
677 | */ |
||
678 | View Code Duplication | public static function is_firefox_desktop() { |
|
692 | |||
693 | /** |
||
694 | * Detects if the current browser is FirefoxOS Native browser |
||
695 | * |
||
696 | * Mozilla/5.0 (Mobile; rv:14.0) Gecko/14.0 Firefox/14.0 |
||
697 | */ |
||
698 | View Code Duplication | public static function is_firefox_os() { |
|
699 | |||
700 | if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { |
||
701 | return false; |
||
702 | } |
||
703 | |||
704 | $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] ); |
||
705 | |||
706 | if ( strpos( $ua, 'mozilla' ) !== false && strpos( $ua, 'mobile' ) !== false && strpos( $ua, 'gecko' ) !== false && strpos( $ua, 'firefox' ) !== false ) { |
||
707 | return true; |
||
708 | } else { |
||
709 | return false; |
||
710 | } |
||
711 | } |
||
712 | |||
713 | /** |
||
714 | * Detects if the current browser is Opera Mobile |
||
715 | * |
||
716 | * What is the difference between Opera Mobile and Opera Mini? |
||
717 | * - Opera Mobile is a full Internet browser for mobile devices. |
||
718 | * - Opera Mini always uses a transcoder to convert the page for a small display. |
||
719 | * (it uses Opera advanced server compression technology to compress web content before it gets to a device. |
||
720 | * The rendering engine is on Opera's server.) |
||
721 | * |
||
722 | * Opera/9.80 (Windows NT 6.1; Opera Mobi/14316; U; en) Presto/2.7.81 Version/11.00" |
||
723 | * Opera/9.50 (Nintendo DSi; Opera/507; U; en-US) |
||
724 | */ |
||
725 | View Code Duplication | public static function is_opera_mobile() { |
|
726 | if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { |
||
727 | return false; |
||
728 | } |
||
729 | |||
730 | $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] ); |
||
731 | |||
732 | if ( strpos( $ua, 'opera' ) !== false && strpos( $ua, 'mobi' ) !== false ) { |
||
733 | return true; |
||
734 | } elseif ( strpos( $ua, 'opera' ) !== false && strpos( $ua, 'nintendo dsi' ) !== false ) { |
||
735 | return true; |
||
736 | } else { |
||
737 | return false; |
||
738 | } |
||
739 | } |
||
740 | |||
741 | |||
742 | /** |
||
743 | * Detects if the current browser is Opera Mini |
||
744 | * |
||
745 | * Opera/8.01 (J2ME/MIDP; Opera Mini/3.0.6306/1528; en; U; ssr) |
||
746 | * Opera/9.80 (Android;Opera Mini/6.0.24212/24.746 U;en) Presto/2.5.25 Version/10.5454 |
||
747 | * Opera/9.80 (iPhone; Opera Mini/5.0.019802/18.738; U; en) Presto/2.4.15 |
||
748 | * Opera/9.80 (J2ME/iPhone;Opera Mini/5.0.019802/886; U; ja) Presto/2.4.15 |
||
749 | * Opera/9.80 (J2ME/iPhone;Opera Mini/5.0.019802/886; U; ja) Presto/2.4.15 |
||
750 | * Opera/9.80 (Series 60; Opera Mini/5.1.22783/23.334; U; en) Presto/2.5.25 Version/10.54 |
||
751 | * Opera/9.80 (BlackBerry; Opera Mini/5.1.22303/22.387; U; en) Presto/2.5.25 Version/10.54 |
||
752 | */ |
||
753 | public static function is_opera_mini() { |
||
754 | if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { |
||
755 | return false; |
||
756 | } |
||
757 | |||
758 | $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] ); |
||
759 | |||
760 | if ( strpos( $ua, 'opera' ) !== false && strpos( $ua, 'mini' ) !== false ) { |
||
761 | return true; |
||
762 | } else { |
||
763 | return false; |
||
764 | } |
||
765 | } |
||
766 | |||
767 | /** |
||
768 | * Detects if the current browser is Opera Mini, but not on a smart device OS(Android, iOS, etc) |
||
769 | * Used to send users on dumb devices to m.wor |
||
770 | */ |
||
771 | public static function is_opera_mini_dumb() { |
||
788 | |||
789 | /** |
||
790 | * Detects if the current browser is Opera Mobile or Mini. |
||
791 | * DEPRECATED: use is_opera_mobile or is_opera_mini |
||
792 | * |
||
793 | * Opera Mini 5 Beta: Opera/9.80 (J2ME/MIDP; Opera Mini/5.0.15650/756; U; en) Presto/2.2.0 |
||
794 | * Opera Mini 8: Opera/8.01 (J2ME/MIDP; Opera Mini/3.0.6306/1528; en; U; ssr) |
||
795 | */ |
||
796 | public static function is_OperaMobile() { |
||
797 | _deprecated_function( __FUNCTION__, 'always', 'is_opera_mini() or is_opera_mobile()' ); |
||
798 | |||
799 | if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { |
||
800 | return false; |
||
801 | } |
||
802 | |||
803 | $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] ); |
||
804 | |||
805 | if ( strpos( $ua, 'opera' ) !== false ) { |
||
806 | if ( ( strpos( $ua, 'mini' ) !== false ) || ( strpos( $ua, 'mobi' ) !== false ) ) { |
||
807 | return true; |
||
808 | } else { |
||
809 | return false; |
||
810 | } |
||
811 | } else { |
||
812 | return false; |
||
813 | } |
||
814 | } |
||
815 | |||
816 | /** |
||
817 | * Detects if the current browser is a Windows Phone 7 device. |
||
818 | * ex: Mozilla/4.0 (compatible; MSIE 7.0; Windows Phone OS 7.0; Trident/3.1; IEMobile/7.0; LG; GW910) |
||
819 | */ |
||
820 | View Code Duplication | public static function is_WindowsPhone7() { |
|
821 | if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { |
||
822 | return false; |
||
823 | } |
||
824 | |||
825 | $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] ); |
||
826 | |||
827 | if ( false === strpos( $ua, 'windows phone os 7' ) ) { |
||
828 | return false; |
||
829 | } else { |
||
830 | if ( self::is_opera_mini() || self::is_opera_mobile() || self::is_firefox_mobile() ) { |
||
831 | return false; |
||
832 | } else { |
||
833 | return true; |
||
834 | } |
||
835 | } |
||
836 | } |
||
837 | |||
838 | /** |
||
839 | * Detects if the current browser is a Windows Phone 8 device. |
||
840 | * ex: Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; ARM; Touch; IEMobile/10.0; <Manufacturer>; <Device> [;<Operator>]) |
||
841 | */ |
||
842 | public static function is_windows_phone_8() { |
||
854 | |||
855 | |||
856 | /** |
||
857 | * Detects if the current browser is on a Palm device running the new WebOS. This EXCLUDES TouchPad. |
||
858 | * |
||
859 | * 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 |
||
860 | * 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 |
||
861 | */ |
||
862 | View Code Duplication | public static function is_PalmWebOS() { |
|
863 | if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { |
||
864 | return false; |
||
865 | } |
||
866 | |||
867 | $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] ); |
||
868 | |||
869 | if ( false === strpos( $ua, 'webos' ) ) { |
||
870 | return false; |
||
871 | } else { |
||
872 | if ( self::is_opera_mini() || self::is_opera_mobile() || self::is_firefox_mobile() ) { |
||
873 | return false; |
||
874 | } else { |
||
875 | return true; |
||
876 | } |
||
877 | } |
||
878 | } |
||
879 | |||
880 | /** |
||
881 | * Detects if the current browser is the HP TouchPad default browser. This excludes phones wt WebOS. |
||
882 | * |
||
883 | * 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 |
||
884 | * 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 |
||
885 | */ |
||
886 | public static function is_TouchPad() { |
||
902 | |||
903 | |||
904 | /** |
||
905 | * Detects if the current browser is the Series 60 Open Source Browser. |
||
906 | * |
||
907 | * 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 |
||
908 | * |
||
909 | * 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 |
||
910 | * |
||
911 | * 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 |
||
912 | */ |
||
913 | public static function is_S60_OSSBrowser() { |
||
940 | |||
941 | /** |
||
942 | * Detects if the device platform is the Symbian Series 60. |
||
943 | */ |
||
944 | public static function is_symbian_platform() { |
||
972 | |||
973 | /** |
||
974 | * Detects if the device platform is the Symbian Series 40. |
||
975 | * Nokia Browser for Series 40 is a proxy based browser, previously known as Ovi Browser. |
||
976 | * This browser will report 'NokiaBrowser' in the header, however some older version will also report 'OviBrowser'. |
||
977 | */ |
||
978 | View Code Duplication | public static function is_symbian_s40_platform() { |
|
979 | |||
980 | if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { |
||
981 | return false; |
||
982 | } |
||
983 | |||
984 | $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); |
||
985 | |||
986 | if ( strpos( $agent, 'series40' ) !== false ) { |
||
987 | if ( strpos( $agent, 'nokia' ) !== false || strpos( $agent, 'ovibrowser' ) !== false || strpos( $agent, 'nokiabrowser' ) !== false ) { |
||
988 | return true; |
||
989 | } |
||
990 | } |
||
991 | |||
992 | return false; |
||
993 | } |
||
994 | |||
995 | /** |
||
996 | * Returns if the device belongs to J2ME capable family. |
||
997 | * |
||
998 | * @return bool |
||
999 | */ |
||
1000 | View Code Duplication | public static function is_J2ME_platform() { |
|
1015 | |||
1016 | |||
1017 | /** |
||
1018 | * Detects if the current UA is on one of the Maemo-based Nokia Internet Tablets. |
||
1019 | */ |
||
1020 | public static function is_MaemoTablet() { |
||
1021 | |||
1022 | if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { |
||
1023 | return false; |
||
1024 | } |
||
1025 | |||
1026 | $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); |
||
1027 | |||
1028 | $pos_maemo = strpos( $agent, 'maemo' ); |
||
1029 | if ( false === $pos_maemo ) { |
||
1030 | return false; |
||
1031 | } |
||
1032 | |||
1033 | // Must be Linux + Tablet, or else it could be something else. |
||
1034 | View Code Duplication | if ( strpos( $agent, 'tablet' ) !== false && strpos( $agent, 'linux' ) !== false ) { |
|
1035 | if ( self::is_opera_mini() || self::is_opera_mobile() || self::is_firefox_mobile() ) { |
||
1036 | return false; |
||
1037 | } else { |
||
1038 | return true; |
||
1039 | } |
||
1040 | } else { |
||
1041 | return false; |
||
1042 | } |
||
1043 | } |
||
1044 | |||
1045 | /** |
||
1046 | * Detects if the current UA is a MeeGo device (Nokia Smartphone). |
||
1047 | */ |
||
1048 | View Code Duplication | public static function is_MeeGo() { |
|
1049 | |||
1050 | if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { |
||
1051 | return false; |
||
1052 | } |
||
1053 | |||
1054 | $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] ); |
||
1055 | |||
1056 | if ( false === strpos( $ua, 'meego' ) ) { |
||
1057 | return false; |
||
1058 | } else { |
||
1059 | if ( self::is_opera_mini() || self::is_opera_mobile() || self::is_firefox_mobile() ) { |
||
1060 | return false; |
||
1061 | } else { |
||
1062 | return true; |
||
1063 | } |
||
1064 | } |
||
1065 | } |
||
1066 | |||
1067 | |||
1068 | /** |
||
1069 | * The is_webkit() method can be used to check the User Agent for an webkit generic browser. |
||
1070 | */ |
||
1071 | View Code Duplication | public static function is_webkit() { |
|
1087 | |||
1088 | /** |
||
1089 | * Detects if the current browser is the Native Android browser. |
||
1090 | * |
||
1091 | * @return boolean true if the browser is Android otherwise false |
||
1092 | */ |
||
1093 | View Code Duplication | public static function is_android() { |
|
1094 | if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { |
||
1095 | return false; |
||
1096 | } |
||
1097 | |||
1098 | $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); |
||
1099 | $pos_android = strpos( $agent, 'android' ); |
||
1100 | if ( false !== $pos_android ) { |
||
1101 | if ( self::is_opera_mini() || self::is_opera_mobile() || self::is_firefox_mobile() ) { |
||
1102 | return false; |
||
1103 | } else { |
||
1104 | return true; |
||
1105 | } |
||
1106 | } else { |
||
1107 | return false; |
||
1108 | } |
||
1109 | } |
||
1110 | |||
1111 | |||
1112 | /** |
||
1113 | * Detects if the current browser is the Native Android Tablet browser. |
||
1114 | * Assumes 'Android' should be in the user agent, but not 'mobile' |
||
1115 | * |
||
1116 | * @return boolean true if the browser is Android and not 'mobile' otherwise false |
||
1117 | */ |
||
1118 | public static function is_android_tablet() { |
||
1139 | |||
1140 | /** |
||
1141 | * Detects if the current browser is the Kindle Fire Native browser. |
||
1142 | * |
||
1143 | * 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 |
||
1144 | * 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 |
||
1145 | * |
||
1146 | * @return boolean true if the browser is Kindle Fire Native browser otherwise false |
||
1147 | */ |
||
1148 | public static function is_kindle_fire() { |
||
1162 | |||
1163 | /** |
||
1164 | * Detects if the current browser is the Kindle Touch Native browser |
||
1165 | * |
||
1166 | * 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+ |
||
1167 | * |
||
1168 | * @return boolean true if the browser is Kindle monochrome Native browser otherwise false |
||
1169 | */ |
||
1170 | View Code Duplication | public static function is_kindle_touch() { |
|
1182 | |||
1183 | |||
1184 | /** |
||
1185 | * Detect if user agent is the WordPress.com Windows 8 app (used ONLY on the custom oauth stylesheet) |
||
1186 | */ |
||
1187 | View Code Duplication | public static function is_windows8_auth() { |
|
1200 | |||
1201 | /** |
||
1202 | * Detect if user agent is the WordPress.com Windows 8 app. |
||
1203 | */ |
||
1204 | View Code Duplication | public static function is_wordpress_for_win8() { |
|
1217 | |||
1218 | /** |
||
1219 | * Detect if user agent is the WordPress.com Desktop app. |
||
1220 | */ |
||
1221 | View Code Duplication | public static function is_wordpress_desktop_app() { |
|
1222 | if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { |
||
1223 | return false; |
||
1224 | } |
||
1225 | |||
1226 | $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); |
||
1227 | $pos = strpos( $agent, 'WordPressDesktop' ); |
||
1228 | if ( false !== $pos ) { |
||
1229 | return true; |
||
1230 | } else { |
||
1231 | return false; |
||
1232 | } |
||
1233 | } |
||
1234 | |||
1235 | /** |
||
1236 | * The is_blackberry_tablet() method can be used to check the User Agent for a RIM blackberry tablet. |
||
1237 | * The user agent of the BlackBerry® Tablet OS follows a format similar to the following: |
||
1238 | * 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+ |
||
1239 | */ |
||
1240 | public static function is_blackberry_tablet() { |
||
1256 | |||
1257 | /** |
||
1258 | * The is_blackbeberry() method can be used to check the User Agent for a blackberry device. |
||
1259 | * Note that opera mini on BB matches this rule. |
||
1260 | */ |
||
1261 | View Code Duplication | public static function is_blackbeberry() { |
|
1262 | if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { |
||
1263 | return false; |
||
1264 | } |
||
1265 | |||
1266 | $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); |
||
1267 | |||
1268 | $pos_blackberry = strpos( $agent, 'blackberry' ); |
||
1269 | if ( false !== $pos_blackberry ) { |
||
1270 | if ( self::is_opera_mini() || self::is_opera_mobile() || self::is_firefox_mobile() ) { |
||
1271 | return false; |
||
1272 | } else { |
||
1273 | return true; |
||
1274 | } |
||
1275 | } else { |
||
1276 | return false; |
||
1277 | } |
||
1278 | } |
||
1279 | |||
1280 | /** |
||
1281 | * The is_blackberry_10() method can be used to check the User Agent for a BlackBerry 10 device. |
||
1282 | */ |
||
1283 | public static function is_blackberry_10() { |
||
1287 | |||
1288 | /** |
||
1289 | * Retrieve the blackberry OS version. |
||
1290 | * |
||
1291 | * Return strings are from the following list: |
||
1292 | * - blackberry-10 |
||
1293 | * - blackberry-7 |
||
1294 | * - blackberry-6 |
||
1295 | * - blackberry-torch //only the first edition. The 2nd edition has the OS7 onboard and doesn't need any special rule. |
||
1296 | * - blackberry-5 |
||
1297 | * - blackberry-4.7 |
||
1298 | * - blackberry-4.6 |
||
1299 | * - blackberry-4.5 |
||
1300 | * |
||
1301 | * @return string Version of the BB OS. |
||
1302 | * If version is not found, get_blackbeberry_OS_version will return boolean false. |
||
1303 | */ |
||
1304 | public static function get_blackbeberry_OS_version() { |
||
1379 | |||
1380 | /** |
||
1381 | * Retrieve the blackberry browser version. |
||
1382 | * |
||
1383 | * Return string are from the following list: |
||
1384 | * - blackberry-10 |
||
1385 | * - blackberry-webkit |
||
1386 | * - blackberry-5 |
||
1387 | * - blackberry-4.7 |
||
1388 | * - blackberry-4.6 |
||
1389 | * |
||
1390 | * @return string Type of the BB browser. |
||
1391 | * If browser's version is not found, detect_blackbeberry_browser_version will return boolean false. |
||
1392 | */ |
||
1393 | public static function detect_blackberry_browser_version() { |
||
1444 | |||
1445 | /** |
||
1446 | * Checks if a visitor is coming from one of the WordPress mobile apps. |
||
1447 | * |
||
1448 | * @return bool |
||
1449 | */ |
||
1450 | public static function is_mobile_app() { |
||
1476 | |||
1477 | /** |
||
1478 | * Detects if the current browser is Nintendo 3DS handheld. |
||
1479 | * |
||
1480 | * Example: Mozilla/5.0 (Nintendo 3DS; U; ; en) Version/1.7498.US |
||
1481 | * can differ in language, version and region |
||
1482 | */ |
||
1483 | public static function is_Nintendo_3DS() { |
||
1494 | |||
1495 | /** |
||
1496 | * Was the current request made by a known bot? |
||
1497 | * |
||
1498 | * @return boolean |
||
1499 | */ |
||
1500 | public static function is_bot() { |
||
1509 | |||
1510 | /** |
||
1511 | * Is the given user-agent a known bot? |
||
1512 | * 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. |
||
1513 | * |
||
1514 | * @param string $ua A user-agent string. |
||
1515 | * |
||
1516 | * @return boolean |
||
1517 | */ |
||
1518 | public static function is_bot_user_agent( $ua = null ) { |
||
1593 | } |
||
1594 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..