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 | * Detects if the current browser is Firefox for desktop |
||
| 700 | * |
||
| 701 | * https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent/Firefox |
||
| 702 | * Mozilla/5.0 (platform; rv:geckoversion) Gecko/geckotrail Firefox/firefoxversion |
||
| 703 | * The platform section will include 'Mobile' for phones and 'Tablet' for tablets. |
||
| 704 | * |
||
| 705 | */ |
||
| 706 | View Code Duplication | static function is_firefox_desktop() { |
|
| 720 | |||
| 721 | /* |
||
| 722 | * Detects if the current browser is FirefoxOS Native browser |
||
| 723 | * |
||
| 724 | * Mozilla/5.0 (Mobile; rv:14.0) Gecko/14.0 Firefox/14.0 |
||
| 725 | * |
||
| 726 | */ |
||
| 727 | View Code Duplication | static function is_firefox_os( ) { |
|
| 739 | |||
| 740 | |||
| 741 | /* |
||
| 742 | * Detects if the current browser is Opera Mobile |
||
| 743 | * |
||
| 744 | * What is the difference between Opera Mobile and Opera Mini? |
||
| 745 | * - Opera Mobile is a full Internet browser for mobile devices. |
||
| 746 | * - Opera Mini always uses a transcoder to convert the page for a small display. |
||
| 747 | * (it uses Opera advanced server compression technology to compress web content before it gets to a device. |
||
| 748 | * The rendering engine is on Opera's server.) |
||
| 749 | * |
||
| 750 | * Opera/9.80 (Windows NT 6.1; Opera Mobi/14316; U; en) Presto/2.7.81 Version/11.00" |
||
| 751 | * Opera/9.50 (Nintendo DSi; Opera/507; U; en-US) |
||
| 752 | */ |
||
| 753 | View Code Duplication | static function is_opera_mobile( ) { |
|
| 767 | |||
| 768 | |||
| 769 | /* |
||
| 770 | * Detects if the current browser is Opera Mini |
||
| 771 | * |
||
| 772 | * Opera/8.01 (J2ME/MIDP; Opera Mini/3.0.6306/1528; en; U; ssr) |
||
| 773 | * Opera/9.80 (Android;Opera Mini/6.0.24212/24.746 U;en) Presto/2.5.25 Version/10.5454 |
||
| 774 | * Opera/9.80 (iPhone; Opera Mini/5.0.019802/18.738; U; en) Presto/2.4.15 |
||
| 775 | * Opera/9.80 (J2ME/iPhone;Opera Mini/5.0.019802/886; U; ja) Presto/2.4.15 |
||
| 776 | * Opera/9.80 (J2ME/iPhone;Opera Mini/5.0.019802/886; U; ja) Presto/2.4.15 |
||
| 777 | * Opera/9.80 (Series 60; Opera Mini/5.1.22783/23.334; U; en) Presto/2.5.25 Version/10.54 |
||
| 778 | * Opera/9.80 (BlackBerry; Opera Mini/5.1.22303/22.387; U; en) Presto/2.5.25 Version/10.54 |
||
| 779 | * |
||
| 780 | */ |
||
| 781 | static function is_opera_mini( ) { |
||
| 793 | |||
| 794 | /* |
||
| 795 | * Detects if the current browser is Opera Mini, but not on a smart device OS(Android, iOS, etc) |
||
| 796 | * Used to send users on dumb devices to m.wor |
||
| 797 | */ |
||
| 798 | static function is_opera_mini_dumb( ) { |
||
| 814 | |||
| 815 | /* |
||
| 816 | * Detects if the current browser is Opera Mobile or Mini. |
||
| 817 | * DEPRECATED: use is_opera_mobile or is_opera_mini |
||
| 818 | * |
||
| 819 | * Opera Mini 5 Beta: Opera/9.80 (J2ME/MIDP; Opera Mini/5.0.15650/756; U; en) Presto/2.2.0 |
||
| 820 | * Opera Mini 8: Opera/8.01 (J2ME/MIDP; Opera Mini/3.0.6306/1528; en; U; ssr) |
||
| 821 | */ |
||
| 822 | static function is_OperaMobile() { |
||
| 839 | |||
| 840 | /* |
||
| 841 | * Detects if the current browser is a Windows Phone 7 device. |
||
| 842 | * ex: Mozilla/4.0 (compatible; MSIE 7.0; Windows Phone OS 7.0; Trident/3.1; IEMobile/7.0; LG; GW910) |
||
| 843 | */ |
||
| 844 | View Code Duplication | static function is_WindowsPhone7() { |
|
| 859 | |||
| 860 | /* |
||
| 861 | * Detects if the current browser is a Windows Phone 8 device. |
||
| 862 | * ex: Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; ARM; Touch; IEMobile/10.0; <Manufacturer>; <Device> [;<Operator>]) |
||
| 863 | */ |
||
| 864 | static function is_windows_phone_8() { |
||
| 875 | |||
| 876 | |||
| 877 | /* |
||
| 878 | * Detects if the current browser is on a Palm device running the new WebOS. This EXCLUDES TouchPad. |
||
| 879 | * |
||
| 880 | * 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 |
||
| 881 | * 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 |
||
| 882 | * |
||
| 883 | */ |
||
| 884 | View Code Duplication | static function is_PalmWebOS() { |
|
| 899 | |||
| 900 | /* |
||
| 901 | * Detects if the current browser is the HP TouchPad default browser. This excludes phones wt WebOS. |
||
| 902 | * |
||
| 903 | * 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 |
||
| 904 | * 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 |
||
| 905 | * |
||
| 906 | */ |
||
| 907 | static function is_TouchPad() { |
||
| 921 | |||
| 922 | |||
| 923 | /* |
||
| 924 | * Detects if the current browser is the Series 60 Open Source Browser. |
||
| 925 | * |
||
| 926 | * 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 |
||
| 927 | * |
||
| 928 | * 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 |
||
| 929 | * |
||
| 930 | * 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 |
||
| 931 | * |
||
| 932 | */ |
||
| 933 | static function is_S60_OSSBrowser() { |
||
| 957 | |||
| 958 | /* |
||
| 959 | * |
||
| 960 | * Detects if the device platform is the Symbian Series 60. |
||
| 961 | * |
||
| 962 | */ |
||
| 963 | static function is_symbian_platform() { |
||
| 988 | |||
| 989 | /* |
||
| 990 | * |
||
| 991 | * Detects if the device platform is the Symbian Series 40. |
||
| 992 | * Nokia Browser for Series 40 is a proxy based browser, previously known as Ovi Browser. |
||
| 993 | * This browser will report 'NokiaBrowser' in the header, however some older version will also report 'OviBrowser'. |
||
| 994 | * |
||
| 995 | */ |
||
| 996 | View Code Duplication | static function is_symbian_s40_platform() { |
|
| 1010 | |||
| 1011 | View Code Duplication | static function is_J2ME_platform() { |
|
| 1026 | |||
| 1027 | |||
| 1028 | /* |
||
| 1029 | * Detects if the current UA is on one of the Maemo-based Nokia Internet Tablets. |
||
| 1030 | */ |
||
| 1031 | static function is_MaemoTablet() { |
||
| 1050 | |||
| 1051 | /* |
||
| 1052 | * Detects if the current UA is a MeeGo device (Nokia Smartphone). |
||
| 1053 | */ |
||
| 1054 | View Code Duplication | static function is_MeeGo() { |
|
| 1070 | |||
| 1071 | |||
| 1072 | /* |
||
| 1073 | is_webkit() can be used to check the User Agent for an webkit generic browser |
||
| 1074 | */ |
||
| 1075 | View Code Duplication | static function is_webkit() { |
|
| 1089 | |||
| 1090 | /** |
||
| 1091 | * Detects if the current browser is the Native Android browser. |
||
| 1092 | * @return boolean true if the browser is Android otherwise false |
||
| 1093 | */ |
||
| 1094 | View Code Duplication | static function is_android() { |
|
| 1109 | |||
| 1110 | |||
| 1111 | /** |
||
| 1112 | * Detects if the current browser is the Native Android Tablet browser. |
||
| 1113 | * Assumes 'Android' should be in the user agent, but not 'mobile' |
||
| 1114 | * |
||
| 1115 | * @return boolean true if the browser is Android and not 'mobile' otherwise false |
||
| 1116 | */ |
||
| 1117 | static function is_android_tablet( ) { |
||
| 1135 | |||
| 1136 | /** |
||
| 1137 | * Detects if the current browser is the Kindle Fire Native browser. |
||
| 1138 | * |
||
| 1139 | * 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 |
||
| 1140 | * 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 |
||
| 1141 | * |
||
| 1142 | * @return boolean true if the browser is Kindle Fire Native browser otherwise false |
||
| 1143 | */ |
||
| 1144 | static function is_kindle_fire( ) { |
||
| 1156 | |||
| 1157 | |||
| 1158 | /** |
||
| 1159 | * Detects if the current browser is the Kindle Touch Native browser |
||
| 1160 | * |
||
| 1161 | * 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+ |
||
| 1162 | * |
||
| 1163 | * @return boolean true if the browser is Kindle monochrome Native browser otherwise false |
||
| 1164 | */ |
||
| 1165 | View Code Duplication | static function is_kindle_touch( ) { |
|
| 1175 | |||
| 1176 | |||
| 1177 | // Detect if user agent is the WordPress.com Windows 8 app (used ONLY on the custom oauth stylesheet) |
||
| 1178 | View Code Duplication | static function is_windows8_auth( ) { |
|
| 1189 | |||
| 1190 | // Detect if user agent is the WordPress.com Windows 8 app. |
||
| 1191 | View Code Duplication | static function is_wordpress_for_win8( ) { |
|
| 1202 | |||
| 1203 | |||
| 1204 | // Detect if user agent is the WordPress.com Desktop app. |
||
| 1205 | static function is_wordpress_desktop_app( ) { |
||
| 1216 | |||
| 1217 | |||
| 1218 | /* |
||
| 1219 | * is_blackberry_tablet() can be used to check the User Agent for a RIM blackberry tablet |
||
| 1220 | * The user agent of the BlackBerry® Tablet OS follows a format similar to the following: |
||
| 1221 | * 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+ |
||
| 1222 | * |
||
| 1223 | */ |
||
| 1224 | static function is_blackberry_tablet() { |
||
| 1240 | |||
| 1241 | /* |
||
| 1242 | is_blackbeberry() can be used to check the User Agent for a blackberry device |
||
| 1243 | Note that opera mini on BB matches this rule. |
||
| 1244 | */ |
||
| 1245 | View Code Duplication | static function is_blackbeberry() { |
|
| 1262 | |||
| 1263 | /* |
||
| 1264 | is_blackberry_10() can be used to check the User Agent for a BlackBerry 10 device. |
||
| 1265 | */ |
||
| 1266 | static function is_blackberry_10() { |
||
| 1270 | |||
| 1271 | /** |
||
| 1272 | * Retrieve the blackberry OS version. |
||
| 1273 | * |
||
| 1274 | * Return strings are from the following list: |
||
| 1275 | * - blackberry-10 |
||
| 1276 | * - blackberry-7 |
||
| 1277 | * - blackberry-6 |
||
| 1278 | * - blackberry-torch //only the first edition. The 2nd edition has the OS7 onboard and doesn't need any special rule. |
||
| 1279 | * - blackberry-5 |
||
| 1280 | * - blackberry-4.7 |
||
| 1281 | * - blackberry-4.6 |
||
| 1282 | * - blackberry-4.5 |
||
| 1283 | * |
||
| 1284 | * @return string Version of the BB OS. |
||
| 1285 | * If version is not found, get_blackbeberry_OS_version will return boolean false. |
||
| 1286 | */ |
||
| 1287 | static function get_blackbeberry_OS_version() { |
||
| 1357 | |||
| 1358 | /** |
||
| 1359 | * Retrieve the blackberry browser version. |
||
| 1360 | * |
||
| 1361 | * Return string are from the following list: |
||
| 1362 | * - blackberry-10 |
||
| 1363 | * - blackberry-webkit |
||
| 1364 | * - blackberry-5 |
||
| 1365 | * - blackberry-4.7 |
||
| 1366 | * - blackberry-4.6 |
||
| 1367 | * |
||
| 1368 | * @return string Type of the BB browser. |
||
| 1369 | * If browser's version is not found, detect_blackbeberry_browser_version will return boolean false. |
||
| 1370 | */ |
||
| 1371 | static function detect_blackberry_browser_version() { |
||
| 1419 | |||
| 1420 | // Checks if a visitor is coming from one of the WordPress mobile apps |
||
| 1421 | static function is_mobile_app() { |
||
| 1444 | |||
| 1445 | /* |
||
| 1446 | * Detects if the current browser is Nintendo 3DS handheld. |
||
| 1447 | * |
||
| 1448 | * example: Mozilla/5.0 (Nintendo 3DS; U; ; en) Version/1.7498.US |
||
| 1449 | * can differ in language, version and region |
||
| 1450 | */ |
||
| 1451 | static function is_Nintendo_3DS() { |
||
| 1462 | |||
| 1463 | /** |
||
| 1464 | * Was the current request made by a known bot? |
||
| 1465 | * |
||
| 1466 | * @return boolean |
||
| 1467 | */ |
||
| 1468 | static function is_bot() { |
||
| 1477 | |||
| 1478 | /** |
||
| 1479 | * Is the given user-agent a known bot? |
||
| 1480 | * 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. |
||
| 1481 | * |
||
| 1482 | * @param $ua (string) A user-agent string |
||
| 1483 | * @return boolean |
||
| 1484 | */ |
||
| 1485 | static function is_bot_user_agent( $ua = null ) { |
||
| 1508 | |||
| 1509 | |||
| 1510 | |||
| 1511 | } |
||
| 1512 |