Changeset 28068 for trunk/include/mdetect.php
- Timestamp:
- Apr 4, 2014, 6:20:34 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/mdetect.php
r18967 r28068 2 2 3 3 /* ******************************************* 4 // Copyright 2010-201 2, Anthony Hand4 // Copyright 2010-2013, Anthony Hand 5 5 // 6 // File version date: April 23, 20127 // Update:8 // - Updated DetectAmazonSilk(): Fixed an issue in the detection logic.6 // File version 2013.10.27 (October 27, 2013) 7 // Updates: 8 // - Made minor update to the InitDeviceScan. Should check Tablet Tier first, then iPhone Tier, then Quick Mobile. 9 9 // 10 // File version date: April 22, 2012 - Second update 11 // Update: To address additional Kindle issues... 12 // - Updated DetectRichCSS(): Excluded e-Ink Kindle devices. 13 // - Created DetectAmazonSilk(): Created to detect Kindle Fire devices in Silk mode. 14 // - Updated DetectMobileQuick(): Updated to include e-Ink Kindle devices and the Kindle Fire in Silk mode. 10 // File version 2013.08.01 (August 1, 2013) 11 // Updates: 12 // - Updated DetectMobileQuick(). Moved the 'Exclude Tablets' logic to the top of the method to fix a logic bug. 15 13 // 16 // File version date: April 11, 2012 17 // Update: 18 // - Added a new variable for the new BlackBerry Curve Touch (9380): deviceBBCurveTouch. 19 // - Updated DetectBlackBerryTouch() to support the new BlackBerry Curve Touch (9380). 20 // - Updated DetectKindle(): Added the missing 'this' class identifier for the DetectAndroid() call. 21 // 22 // File version date: January 21, 2012 23 // Update: 24 // - Added the constructor method per new features in PHP 5.0: __construct(). 25 // - Moved Windows Phone 7 to the iPhone Tier. WP7.5's IE 9-based browser is good enough now. 26 // - Added a new variable for 2 versions of the new BlackBerry Bold Touch (9900 and 9930): deviceBBBoldTouch. 27 // - Updated DetectBlackBerryTouch() to support the 2 versions of the new BlackBerry Bold Touch (9900 and 9930). 28 // - Updated DetectKindle() to focus on eInk devices only. The Kindle Fire should be detected as a regular Android device. 29 // 30 // File version date: August 22, 2011 31 // Update: 32 // - Updated DetectAndroidTablet() to fix a bug introduced in the last fix! The true/false returns were mixed up. 33 // 34 // File version date: August 16, 2011 35 // Update: 36 // - Updated DetectAndroidTablet() to exclude Opera Mini, which was falsely reporting as running on a tablet device when on a phone. 14 // File version 2013.07.13 (July 13, 2013) 15 // Updates: 16 // - Added support for Tizen: variable and DetectTizen(). 17 // - Added support for Meego: variable and DetectMeego(). 18 // - Added support for Windows Phone 8: variable and DetectWindowsPhone8(). 19 // - Added a generic Windows Phone method: DetectWindowsPhone(). 20 // - Added support for BlackBerry 10 OS: variable and DetectBlackBerry10Phone(). 21 // - Added support for PlayStation Vita handheld: variable and DetectGamingHandheld(). 22 // - Updated DetectTierIphone(). Added Tizen; updated the Windows Phone, BB10, and PS Vita support. 23 // - Updated DetectWindowsMobile(). Uses generic DetectWindowsPhone() method rather than WP7. 24 // - Updated DetectSmartphone(). Uses the IsTierIphone variable. 25 // - Updated DetectSonyMylo() with more efficient code. 26 // - Removed DetectGarminNuvifone() from DetectTierIphone(). How many are left in market in 2013? It is detected as a RichCSS Tier device. 27 // - Removed the deviceXoom variable. It was unused. 28 // - Added detection support for the Obigo mobile browser to DetectMobileQuick(). 37 29 // 38 30 // … … 81 73 var $false = 0; 82 74 83 //Let's store values for quickly accessing the same info multiple times. 84 var $isIphone = 0; //Stores whether the device is an iPhone or iPod Touch. 85 var $isAndroidPhone = 0; //Stores whether the device is a (small-ish) Android phone or media player. 86 var $isTierTablet = 0; //Stores whether is the Tablet (HTML5-capable, larger screen) tier of devices. 87 var $isTierIphone = 0; //Stores whether is the iPhone tier of devices. 88 var $isTierRichCss = 0; //Stores whether the device can probably support Rich CSS, but JavaScript support is not assumed. (e.g., newer BlackBerry, Windows Mobile) 89 var $isTierGenericMobile = 0; //Stores whether it is another mobile device, which cannot be assumed to support CSS or JS (eg, older BlackBerry, RAZR) 75 //Let's store values for quickly accessing the same info multiple times. InitCompleted 76 var $initCompleted = 0; //Stores whether we're currently initializing the most popular functions. 77 var $isWebkit = 0; //Stores the result of DetectWebkit() 78 var $isMobilePhone = 0; //Stores the result of DetectMobileQuick() 79 var $isIphone = 0; //Stores the result of DetectIphone() 80 var $isAndroid = 0; //Stores the result of DetectAndroid() 81 var $isAndroidPhone = 0; //Stores the result of DetectAndroidPhone() 82 var $isTierTablet = 0; //Stores the result of DetectTierTablet() 83 var $isTierIphone = 0; //Stores the result of DetectTierIphone() 84 var $isTierRichCss = 0; //Stores the result of DetectTierRichCss() 85 var $isTierGenericMobile = 0; //Stores the result of DetectTierOtherPhones() 90 86 91 87 //Initialize some initial smartphone string variables. 92 88 var $engineWebKit = 'webkit'; 89 93 90 var $deviceIphone = 'iphone'; 94 91 var $deviceIpod = 'ipod'; … … 98 95 var $deviceAndroid = 'android'; 99 96 var $deviceGoogleTV = 'googletv'; 100 var $deviceXoom = 'xoom'; //Motorola Xoom101 97 var $deviceHtcFlyer = 'htc_flyer'; //HTC Flyer 102 98 103 var $deviceNuvifone = 'nuvifone'; //Garmin Nuvifone104 105 var $deviceSymbian = 'symbian';106 var $deviceS60 = 'series60';107 var $deviceS70 = 'series70';108 var $deviceS80 = 'series80';109 var $deviceS90 = 'series90';110 111 99 var $deviceWinPhone7 = 'windows phone os 7'; 100 var $deviceWinPhone8 = 'windows phone 8'; 112 101 var $deviceWinMob = 'windows ce'; 113 102 var $deviceWindows = 'windows'; … … 117 106 118 107 var $deviceBB = 'blackberry'; 108 var $deviceBB10 = 'bb10'; //For the new BB 10 OS 119 109 var $vndRIM = 'vnd.rim'; //Detectable when BB devices emulate IE or Firefox 120 110 var $deviceBBStorm = 'blackberry95'; //Storm 1 and 2 … … 127 117 var $deviceBBPlaybook = 'playbook'; //PlayBook tablet 128 118 119 var $deviceSymbian = 'symbian'; 120 var $deviceS60 = 'series60'; 121 var $deviceS70 = 'series70'; 122 var $deviceS80 = 'series80'; 123 var $deviceS90 = 'series90'; 124 129 125 var $devicePalm = 'palm'; 130 126 var $deviceWebOS = 'webos'; //For Palm's line of WebOS devices 131 127 var $deviceWebOShp = 'hpwos'; //For HP's line of WebOS devices 132 133 128 var $engineBlazer = 'blazer'; //Old Palm browser 134 129 var $engineXiino = 'xiino'; //Another old Palm 135 130 131 var $deviceNuvifone = 'nuvifone'; //Garmin Nuvifone 132 var $deviceBada = 'bada'; //Samsung's Bada OS 133 var $deviceTizen = 'tizen'; //Tizen OS 134 var $deviceMeego = 'meego'; //Meego OS 135 136 136 var $deviceKindle = 'kindle'; //Amazon Kindle, eInk one 137 var $engineSilk = 'silk '; //Amazon's accelerated Silk browser for Kindle Fire137 var $engineSilk = 'silk-accelerated'; //Amazon's accelerated Silk browser for Kindle Fire 138 138 139 139 //Initialize variables for mobile-specific content. … … 147 147 var $deviceHiptop = 'hiptop'; 148 148 var $devicePlaystation = 'playstation'; 149 var $devicePlaystationVita = 'vita'; 149 150 var $deviceNintendoDs = 'nitro'; 150 151 var $deviceNintendo = 'nintendo'; … … 160 161 var $uplink = 'up.link'; 161 162 var $engineTelecaQ = 'teleca q'; //a modern feature phone browser 163 var $engineObigo = 'obigo'; //W 10 is a modern feature phone browser 162 164 163 165 var $devicePda = 'pda'; //some devices report themselves as PDAs … … 177 179 var $manuSamsung1 = "sec-sgh"; 178 180 var $manuSony = "sony"; 179 var $manuHtc = "htc"; //Popular Android and WinMo manufacturer181 var $manuHtc = "htc"; 180 182 181 183 //In some UserAgents, the only clue is the operator. … … 192 194 function __construct() 193 195 { 194 196 $this->uagent_info(); 195 197 } 196 198 … … 200 202 function uagent_info() 201 203 { 202 203 204 205 206 204 $this->useragent = isset($_SERVER['HTTP_USER_AGENT'])?strtolower($_SERVER['HTTP_USER_AGENT']):''; 205 $this->httpaccept = isset($_SERVER['HTTP_ACCEPT'])?strtolower($_SERVER['HTTP_ACCEPT']):''; 206 207 //Let's initialize some values to save cycles later. 208 $this->InitDeviceScan(); 207 209 } 208 210 … … 211 213 function InitDeviceScan() 212 214 { 213 global $isIphone, $isAndroidPhone, $isTierTablet, $isTierIphone; 215 //Save these properties to speed processing 216 global $isWebkit, $isIphone, $isAndroid, $isAndroidPhone; 217 $this->isWebkit = $this->DetectWebkit(); 218 $this->isIphone = $this->DetectIphone(); 219 $this->isAndroid = $this->DetectAndroid(); 220 $this->isAndroidPhone = $this->DetectAndroidPhone(); 214 221 215 // We'll use these 4 variables to speed other processing. They're super common.216 $this->isIphone = $this->DetectIphoneOrIpod();217 $this->is AndroidPhone = $this->DetectAndroidPhone();218 $this->isTierIphone = $this->DetectTierIphone(); 219 $this->is TierTablet = $this->DetectTierTablet();222 //These tiers are the most useful for web development 223 global $isMobilePhone, $isTierTablet, $isTierIphone; 224 $this->isTierTablet = $this->DetectTierTablet(); //Do first 225 $this->isTierIphone = $this->DetectTierIphone(); //Do second 226 $this->isMobilePhone = $this->DetectMobileQuick(); //Do third 220 227 221 //Optional: Comment these out if you don't needthem.228 //Optional: Comment these out if you NEVER use them. 222 229 global $isTierRichCss, $isTierGenericMobile; 223 230 $this->isTierRichCss = $this->DetectTierRichCss(); 224 231 $this->isTierGenericMobile = $this->DetectTierOtherPhones(); 232 233 $this->initCompleted = $this->true; 225 234 } 226 235 … … 244 253 function DetectIphone() 245 254 { 255 if ($this->initCompleted == $this->true || 256 $this->isIphone == $this->true) 257 return $this->isIphone; 258 246 259 if (stripos($this->useragent, $this->deviceIphone) > -1) 247 260 { … … 284 297 { 285 298 //We repeat the searches here because some iPods may report themselves as an iPhone, which would be okay. 286 if (stripos($this->useragent, $this->deviceIphone) > -1||287 stripos($this->useragent, $this->deviceIpod) > -1)299 if ($this->DetectIphone() == $this->true || 300 $this->DetectIpod() == $this->true) 288 301 return $this->true; 289 302 else … … 308 321 function DetectAndroid() 309 322 { 310 if ((stripos($this->useragent, $this->deviceAndroid) > -1) || 311 ($this->DetectGoogleTV() == $this->true)) 323 if ($this->initCompleted == $this->true || 324 $this->isAndroid == $this->true) 325 return $this->isAndroid; 326 327 if ((stripos($this->useragent, $this->deviceAndroid) > -1) 328 || ($this->DetectGoogleTV() == $this->true)) 312 329 return $this->true; 313 330 //Special check for the HTC Flyer 7" tablet … … 325 342 function DetectAndroidPhone() 326 343 { 344 if ($this->initCompleted == $this->true || 345 $this->isAndroidPhone == $this->true) 346 return $this->isAndroidPhone; 347 327 348 if (($this->DetectAndroid() == $this->true) && 328 (stripos($this->useragent, $this->mobile) > -1)) 329 return $this->true; 349 (stripos($this->useragent, $this->mobile) > -1)) 350 return $this->true; 351 330 352 //Special check for Android phones with Opera Mobile. They should report here. 331 353 if (($this->DetectOperaAndroidPhone() == $this->true)) … … 333 355 //Special check for the HTC Flyer 7" tablet. It should report here. 334 356 if ((stripos($this->useragent, $this->deviceHtcFlyer) > -1)) 335 return $this->true; 357 return $this->true; 358 336 359 else 337 360 return $this->false; … … 367 390 { 368 391 if (($this->DetectAndroid() == $this->true) && 369 392 ($this->DetectWebkit() == $this->true)) 370 393 return $this->true; 371 394 else … … 387 410 function DetectWebkit() 388 411 { 412 if ($this->initCompleted == $this->true || 413 $this->isWebkit == $this->true) 414 return $this->isWebkit; 415 389 416 if (stripos($this->useragent, $this->engineWebKit) > -1) 390 417 return $this->true; … … 395 422 396 423 //************************** 397 // Detects if the current browser is the Nokia S60 Open Source Browser. 398 function DetectS60OssBrowser() 399 { 400 //First, test for WebKit, then make sure it's either Symbian or S60. 401 if ($this->DetectWebkit() == $this->true) 402 { 403 if (stripos($this->useragent, $this->deviceSymbian) > -1 || 404 stripos($this->useragent, $this->deviceS60) > -1) 405 { 406 return $this->true; 407 } 408 else 409 return $this->false; 410 } 411 else 412 return $this->false; 413 } 414 415 //************************** 416 // Detects if the current device is any Symbian OS-based device, 417 // including older S60, Series 70, Series 80, Series 90, and UIQ, 418 // or other browsers running on these devices. 419 function DetectSymbianOS() 420 { 421 if (stripos($this->useragent, $this->deviceSymbian) > -1 || 422 stripos($this->useragent, $this->deviceS60) > -1 || 423 stripos($this->useragent, $this->deviceS70) > -1 || 424 stripos($this->useragent, $this->deviceS80) > -1 || 425 stripos($this->useragent, $this->deviceS90) > -1) 426 return $this->true; 427 else 428 return $this->false; 429 } 430 431 //************************** 432 // Detects if the current browser is a 433 // Windows Phone 7 device. 424 // Detects if the current browser is EITHER a 425 // Windows Phone 7.x OR 8 device. 426 function DetectWindowsPhone() 427 { 428 if (($this->DetectWindowsPhone8() == $this->true) 429 || ($this->DetectWindowsPhone7() == $this->true)) 430 return $this->true; 431 else 432 return $this->false; 433 } 434 435 //************************** 436 // Detects a Windows Phone 7.x device (in mobile browsing mode). 434 437 function DetectWindowsPhone7() 435 438 { … … 439 442 return $this->false; 440 443 } 444 445 //************************** 446 // Detects a Windows Phone 8 device (in mobile browsing mode). 447 function DetectWindowsPhone8() 448 { 449 if (stripos($this->useragent, $this->deviceWinPhone8) > -1) 450 return $this->true; 451 else 452 return $this->false; 453 } 441 454 442 455 //************************** 443 456 // Detects if the current browser is a Windows Mobile device. 444 // Excludes Windows Phone 7 devices.457 // Excludes Windows Phone 7 and later devices. 445 458 // Focuses on Windows Mobile 6.xx and earlier. 446 459 function DetectWindowsMobile() 447 460 { 448 if ($this->DetectWindowsPhone7() == $this->true) 449 return $this->false; 461 if ($this->DetectWindowsPhone() == $this->true) 462 return $this->false; 463 450 464 //Most devices use 'Windows CE', but some report 'iemobile' 451 465 // and some older ones report as 'PIE' for Pocket IE. … … 455 469 return $this->true; 456 470 //Test for Windows Mobile PPC but not old Macintosh PowerPC. 457 458 471 if (stripos($this->useragent, $this->devicePpc) > -1 472 && !(stripos($this->useragent, $this->deviceMacPpc) > 1)) 459 473 return $this->true; 460 474 //Test for certain Windwos Mobile-based HTC devices. … … 471 485 //************************** 472 486 // Detects if the current browser is any BlackBerry device. 473 // Includes the PlayBook.487 // Includes BB10 OS, but excludes the PlayBook. 474 488 function DetectBlackBerry() 475 489 { 476 490 if ((stripos($this->useragent, $this->deviceBB) > -1) || 477 491 (stripos($this->httpaccept, $this->vndRIM) > -1)) 492 return $this->true; 493 if ($this->DetectBlackBerry10Phone() == $this->true) 494 return $this->true; 495 else 496 return $this->false; 497 } 498 499 //************************** 500 // Detects if the current browser is a BlackBerry 10 OS phone. 501 // Excludes tablets. 502 function DetectBlackBerry10Phone() 503 { 504 if ((stripos($this->useragent, $this->deviceBB10) > -1) && 505 (stripos($this->useragent, $this->mobile) > -1)) 478 506 return $this->true; 479 507 else … … 499 527 { 500 528 if (($this->DetectBlackBerry() == $this->true) && 501 529 ($this->DetectWebkit() == $this->true)) 502 530 return $this->true; 503 531 else … … 511 539 { 512 540 if ((stripos($this->useragent, $this->deviceBBStorm) > -1) || 513 514 515 541 (stripos($this->useragent, $this->deviceBBTorch) > -1) || 542 (stripos($this->useragent, $this->deviceBBBoldTouch) > -1) || 543 (stripos($this->useragent, $this->deviceBBCurveTouch) > -1)) 516 544 return $this->true; 517 545 else … … 555 583 //Assume that if it's not in the High tier, then it's Low. 556 584 if (($this->DetectBlackBerryHigh() == $this->true) || 557 585 ($this->DetectBlackBerryWebKit() == $this->true)) 558 586 return $this->false; 559 587 else … … 564 592 } 565 593 594 595 //************************** 596 // Detects if the current browser is the Nokia S60 Open Source Browser. 597 function DetectS60OssBrowser() 598 { 599 //First, test for WebKit, then make sure it's either Symbian or S60. 600 if ($this->DetectWebkit() == $this->true) 601 { 602 if (stripos($this->useragent, $this->deviceSymbian) > -1 || 603 stripos($this->useragent, $this->deviceS60) > -1) 604 { 605 return $this->true; 606 } 607 else 608 return $this->false; 609 } 610 else 611 return $this->false; 612 } 613 614 //************************** 615 // Detects if the current device is any Symbian OS-based device, 616 // including older S60, Series 70, Series 80, Series 90, and UIQ, 617 // or other browsers running on these devices. 618 function DetectSymbianOS() 619 { 620 if (stripos($this->useragent, $this->deviceSymbian) > -1 || 621 stripos($this->useragent, $this->deviceS60) > -1 || 622 stripos($this->useragent, $this->deviceS70) > -1 || 623 stripos($this->useragent, $this->deviceS80) > -1 || 624 stripos($this->useragent, $this->deviceS90) > -1) 625 return $this->true; 626 else 627 return $this->false; 628 } 629 630 566 631 //************************** 567 632 // Detects if the current browser is on a PalmOS device. 568 633 function DetectPalmOS() 569 634 { 635 //Make sure it's not WebOS first 636 if ($this->DetectPalmWebOS() == $this->true) 637 return $this->false; 638 570 639 //Most devices nowadays report as 'Palm', but some older ones reported as Blazer or Xiino. 571 640 if (stripos($this->useragent, $this->devicePalm) > -1 || 572 641 stripos($this->useragent, $this->engineBlazer) > -1 || 573 642 stripos($this->useragent, $this->engineXiino) > -1) 574 {575 //Make sure it's not WebOS first576 if ($this->DetectPalmWebOS() == $this->true)577 return $this->false;578 else579 643 return $this->true; 580 }581 644 else 582 645 return $this->false; … … 600 663 { 601 664 if ((stripos($this->useragent, $this->deviceWebOShp) > -1) 602 && (stripos($this->useragent, $this->deviceTablet) > -1)) 603 return $this->true; 604 else 605 return $this->false; 606 } 607 608 //************************** 609 // Detects if the current browser is a 610 // Garmin Nuvifone. 611 function DetectGarminNuvifone() 612 { 613 if (stripos($this->useragent, $this->deviceNuvifone) > -1) 614 return $this->true; 615 else 616 return $this->false; 617 } 618 619 620 //************************** 621 // Check to see whether the device is any device 622 // in the 'smartphone' category. 623 function DetectSmartphone() 624 { 625 global $isIphone, $isAndroidPhone, $isTierIphone; 626 627 if (($this->isIphone == $this->true) 628 || ($this->isAndroidPhone == $this->true) 629 || ($this->isTierIphone == $this->true) 630 || ($this->DetectS60OssBrowser() == $this->true) 631 || ($this->DetectSymbianOS() == $this->true) 632 || ($this->DetectWindowsMobile() == $this->true) 633 || ($this->DetectWindowsPhone7() == $this->true) 634 || ($this->DetectBlackBerry() == $this->true) 635 || ($this->DetectPalmWebOS() == $this->true) 636 || ($this->DetectPalmOS() == $this->true) 637 || ($this->DetectGarminNuvifone() == $this->true)) 638 return $this->true; 639 else 640 return $this->false; 641 } 642 643 644 //************************** 645 // Detects whether the device is a Brew-powered device. 646 function DetectBrewDevice() 647 { 648 if (stripos($this->useragent, $this->deviceBrew) > -1) 649 return $this->true; 650 else 651 return $this->false; 652 } 653 654 //************************** 655 // Detects the Danger Hiptop device. 656 function DetectDangerHiptop() 657 { 658 if (stripos($this->useragent, $this->deviceDanger) > -1 || 659 stripos($this->useragent, $this->deviceHiptop) > -1) 660 return $this->true; 661 else 662 return $this->false; 663 } 665 && (stripos($this->useragent, $this->deviceTablet) > -1)) 666 return $this->true; 667 else 668 return $this->false; 669 } 670 671 664 672 665 673 //************************** … … 686 694 if ((stripos($this->useragent, $this->engineOpera) > -1) && 687 695 (stripos($this->useragent, $this->deviceAndroid) > -1) && 688 696 (stripos($this->useragent, $this->mobi) > -1)) 689 697 return $this->true; 690 698 else … … 699 707 if ((stripos($this->useragent, $this->engineOpera) > -1) && 700 708 (stripos($this->useragent, $this->deviceAndroid) > -1) && 701 (stripos($this->useragent, $this->deviceTablet) > -1)) 702 return $this->true; 703 else 704 return $this->false; 705 } 706 707 //************************** 708 // Detects whether the device supports WAP or WML. 709 function DetectWapWml() 710 { 711 if (stripos($this->httpaccept, $this->vndwap) > -1 || 712 stripos($this->httpaccept, $this->wml) > -1) 713 return $this->true; 714 else 715 return $this->false; 716 } 717 709 (stripos($this->useragent, $this->deviceTablet) > -1)) 710 return $this->true; 711 else 712 return $this->false; 713 } 714 718 715 //************************** 719 716 // Detects if the current device is an Amazon Kindle (eInk devices only). … … 729 726 730 727 //************************** 731 // Detects if the current Amazon device is using the Silk Browser.728 // Detects if the current Amazon device has turned on the Silk accelerated browsing feature. 732 729 // Note: Typically used by the the Kindle Fire. 733 730 function DetectAmazonSilk() … … 738 735 return $this->false; 739 736 } 740 741 737 738 //************************** 739 // Detects if a Garmin Nuvifone device. 740 function DetectGarminNuvifone() 741 { 742 if (stripos($this->useragent, $this->deviceNuvifone) > -1) 743 return $this->true; 744 else 745 return $this->false; 746 } 747 748 //************************** 749 // Detects a device running the Bada smartphone OS from Samsung. 750 function DetectBada() 751 { 752 if (stripos($this->useragent, $this->deviceBada) > -1) 753 return $this->true; 754 else 755 return $this->false; 756 } 757 758 //************************** 759 // Detects a device running the Tizen smartphone OS. 760 function DetectTizen() 761 { 762 if (stripos($this->useragent, $this->deviceTizen) > -1) 763 return $this->true; 764 else 765 return $this->false; 766 } 767 768 //************************** 769 // Detects a device running the Meego OS. 770 function DetectMeego() 771 { 772 if (stripos($this->useragent, $this->deviceMeego) > -1) 773 return $this->true; 774 else 775 return $this->false; 776 } 777 778 //************************** 779 // Detects the Danger Hiptop device. 780 function DetectDangerHiptop() 781 { 782 if (stripos($this->useragent, $this->deviceDanger) > -1 || 783 stripos($this->useragent, $this->deviceHiptop) > -1) 784 return $this->true; 785 else 786 return $this->false; 787 } 788 789 //************************** 790 // Detects if the current browser is a Sony Mylo device. 791 function DetectSonyMylo() 792 { 793 if ((stripos($this->useragent, $this->manuSony) > -1) && 794 ((stripos($this->useragent, $this->qtembedded) > -1) || 795 (stripos($this->useragent, $this->mylocom2) > -1))) 796 return $this->true; 797 else 798 return $this->false; 799 } 800 801 //************************** 802 // Detects if the current device is on one of the Maemo-based Nokia Internet Tablets. 803 function DetectMaemoTablet() 804 { 805 if (stripos($this->useragent, $this->maemo) > -1) 806 return $this->true; 807 //For Nokia N810, must be Linux + Tablet, or else it could be something else. 808 if ((stripos($this->useragent, $this->linux) > -1) 809 && (stripos($this->useragent, $this->deviceTablet) > -1) 810 && ($this->DetectWebOSTablet() == $this->false) 811 && ($this->DetectAndroid() == $this->false)) 812 return $this->true; 813 else 814 return $this->false; 815 } 816 817 //************************** 818 // Detects if the current device is an Archos media player/Internet tablet. 819 function DetectArchos() 820 { 821 if (stripos($this->useragent, $this->deviceArchos) > -1) 822 return $this->true; 823 else 824 return $this->false; 825 } 826 827 //************************** 828 // Detects if the current device is an Internet-capable game console. 829 // Includes many handheld consoles. 830 function DetectGameConsole() 831 { 832 if (($this->DetectSonyPlaystation() == $this->true) || 833 ($this->DetectNintendo() == $this->true) || 834 ($this->DetectXbox() == $this->true)) 835 return $this->true; 836 else 837 return $this->false; 838 } 839 840 //************************** 841 // Detects if the current device is a Sony Playstation. 842 function DetectSonyPlaystation() 843 { 844 if (stripos($this->useragent, $this->devicePlaystation) > -1) 845 return $this->true; 846 else 847 return $this->false; 848 } 849 850 //************************** 851 // Detects if the current device is a handheld gaming device with 852 // a touchscreen and modern iPhone-class browser. Includes the Playstation Vita. 853 function DetectGamingHandheld() 854 { 855 if ((stripos($this->useragent, $this->devicePlaystation) > -1) && 856 (stripos($this->useragent, $this->devicePlaystationVita) > -1)) 857 return $this->true; 858 else 859 return $this->false; 860 } 861 862 //************************** 863 // Detects if the current device is a Nintendo game device. 864 function DetectNintendo() 865 { 866 if (stripos($this->useragent, $this->deviceNintendo) > -1 || 867 stripos($this->useragent, $this->deviceWii) > -1 || 868 stripos($this->useragent, $this->deviceNintendoDs) > -1) 869 return $this->true; 870 else 871 return $this->false; 872 } 873 874 //************************** 875 // Detects if the current device is a Microsoft Xbox. 876 function DetectXbox() 877 { 878 if (stripos($this->useragent, $this->deviceXbox) > -1) 879 return $this->true; 880 else 881 return $this->false; 882 } 883 884 //************************** 885 // Detects whether the device is a Brew-powered device. 886 function DetectBrewDevice() 887 { 888 if (stripos($this->useragent, $this->deviceBrew) > -1) 889 return $this->true; 890 else 891 return $this->false; 892 } 893 894 //************************** 895 // Detects whether the device supports WAP or WML. 896 function DetectWapWml() 897 { 898 if (stripos($this->httpaccept, $this->vndwap) > -1 || 899 stripos($this->httpaccept, $this->wml) > -1) 900 return $this->true; 901 else 902 return $this->false; 903 } 904 905 //************************** 906 // Detects if the current device supports MIDP, a mobile Java technology. 907 function DetectMidpCapable() 908 { 909 if (stripos($this->useragent, $this->deviceMidp) > -1 || 910 stripos($this->httpaccept, $this->deviceMidp) > -1) 911 return $this->true; 912 else 913 return $this->false; 914 } 915 916 917 918 //***************************** 919 // Device Classes 920 //***************************** 921 922 //************************** 923 // Check to see whether the device is *any* 'smartphone'. 924 // Note: It's better to use DetectTierIphone() for modern touchscreen devices. 925 function DetectSmartphone() 926 { 927 //Exclude duplicates from TierIphone 928 if (($this->DetectTierIphone() == $this->true) 929 || ($this->DetectS60OssBrowser() == $this->true) 930 || ($this->DetectSymbianOS() == $this->true) 931 || ($this->DetectWindowsMobile() == $this->true) 932 || ($this->DetectBlackBerry() == $this->true) 933 || ($this->DetectPalmWebOS() == $this->true)) 934 return $this->true; 935 else 936 return $this->false; 937 } 938 742 939 //************************** 743 940 // The quick way to detect for a mobile device. … … 750 947 return $this->false; 751 948 949 if ($this->initCompleted == $this->true || 950 $this->isMobilePhone == $this->true) 951 return $this->isMobilePhone; 952 752 953 //Most mobile browsing is done on smartphones 753 954 if ($this->DetectSmartphone() == $this->true) 754 955 return $this->true; 755 956 957 if (stripos($this->useragent, $this->mobile) > -1) 958 return $this->true; 959 756 960 if (($this->DetectWapWml() == $this->true) 757 758 961 || ($this->DetectBrewDevice() == $this->true) 962 || ($this->DetectOperaMobile() == $this->true)) 759 963 return $this->true; 760 964 761 if ((stripos($this->useragent, $this->engineNetfront) > -1) 762 || (stripos($this->useragent, $this->engineUpBrowser) > -1) 763 || (stripos($this->useragent, $this->engineOpenWeb) > -1)) 965 if ((stripos($this->useragent, $this->engineObigo) > -1) 966 || (stripos($this->useragent, $this->engineNetfront) > -1) 967 || (stripos($this->useragent, $this->engineUpBrowser) > -1) 968 || (stripos($this->useragent, $this->engineOpenWeb) > -1)) 764 969 return $this->true; 765 970 766 971 if (($this->DetectDangerHiptop() == $this->true) 767 768 769 972 || ($this->DetectMidpCapable() == $this->true) 973 || ($this->DetectMaemoTablet() == $this->true) 974 || ($this->DetectArchos() == $this->true)) 770 975 return $this->true; 771 976 772 977 if ((stripos($this->useragent, $this->devicePda) > -1) && 773 !(stripos($this->useragent, $this->disUpdate) > -1)) 774 return $this->true; 775 if (stripos($this->useragent, $this->mobile) > -1) 776 return $this->true; 777 978 !(stripos($this->useragent, $this->disUpdate) > -1)) 979 return $this->true; 980 778 981 //We also look for Kindle devices 779 982 if ($this->DetectKindle() == $this->true || … … 784 987 return $this->false; 785 988 } 786 787 //**************************788 // Detects if the current device is a Sony Playstation.789 function DetectSonyPlaystation()790 {791 if (stripos($this->useragent, $this->devicePlaystation) > -1)792 return $this->true;793 else794 return $this->false;795 }796 797 //**************************798 // Detects if the current device is a Nintendo game device.799 function DetectNintendo()800 {801 if (stripos($this->useragent, $this->deviceNintendo) > -1 ||802 stripos($this->useragent, $this->deviceWii) > -1 ||803 stripos($this->useragent, $this->deviceNintendoDs) > -1)804 return $this->true;805 else806 return $this->false;807 }808 809 //**************************810 // Detects if the current device is a Microsoft Xbox.811 function DetectXbox()812 {813 if (stripos($this->useragent, $this->deviceXbox) > -1)814 return $this->true;815 else816 return $this->false;817 }818 819 //**************************820 // Detects if the current device is an Internet-capable game console.821 function DetectGameConsole()822 {823 if ($this->DetectSonyPlaystation() == $this->true)824 return $this->true;825 else if ($this->DetectNintendo() == $this->true)826 return $this->true;827 else if ($this->DetectXbox() == $this->true)828 return $this->true;829 else830 return $this->false;831 }832 833 //**************************834 // Detects if the current device supports MIDP, a mobile Java technology.835 function DetectMidpCapable()836 {837 if (stripos($this->useragent, $this->deviceMidp) > -1 ||838 stripos($this->httpaccept, $this->deviceMidp) > -1)839 return $this->true;840 else841 return $this->false;842 }843 844 //**************************845 // Detects if the current device is on one of the Maemo-based Nokia Internet Tablets.846 function DetectMaemoTablet()847 {848 if (stripos($this->useragent, $this->maemo) > -1)849 return $this->true;850 //For Nokia N810, must be Linux + Tablet, or else it could be something else.851 if ((stripos($this->useragent, $this->linux) > -1)852 && (stripos($this->useragent, $this->deviceTablet) > -1)853 && ($this->DetectWebOSTablet() == $this->false)854 && ($this->DetectAndroid() == $this->false))855 return $this->true;856 else857 return $this->false;858 }859 860 //**************************861 // Detects if the current device is an Archos media player/Internet tablet.862 function DetectArchos()863 {864 if (stripos($this->useragent, $this->deviceArchos) > -1)865 return $this->true;866 else867 return $this->false;868 }869 870 //**************************871 // Detects if the current browser is a Sony Mylo device.872 function DetectSonyMylo()873 {874 if (stripos($this->useragent, $this->manuSony) > -1)875 {876 if ((stripos($this->useragent, $this->qtembedded) > -1) ||877 (stripos($this->useragent, $this->mylocom2) > -1))878 {879 return $this->true;880 }881 else882 return $this->false;883 }884 else885 return $this->false;886 }887 888 989 889 990 //************************** … … 910 1011 if (stripos($this->useragent, $this->manuericsson) > -1) 911 1012 return $this->true; 912 913 1013 if (stripos($this->useragent, $this->manuSamsung1) > -1) 914 1014 return $this->true; 1015 915 1016 if (stripos($this->useragent, $this->svcDocomo) > -1) 916 1017 return $this->true; … … 923 1024 return $this->false; 924 1025 } 925 926 1026 927 1027 … … 937 1037 function DetectTierTablet() 938 1038 { 1039 if ($this->initCompleted == $this->true || 1040 $this->isTierTablet == $this->true) 1041 return $this->isTierTablet; 1042 939 1043 if (($this->DetectIpad() == $this->true) 940 1044 || ($this->DetectAndroidTablet() == $this->true) … … 951 1055 // This method detects for devices which can 952 1056 // display iPhone-optimized web content. 953 // Includes iPhone, iPod Touch, Android, Windows Phone 7 , WebOS, etc.1057 // Includes iPhone, iPod Touch, Android, Windows Phone 7 and 8, BB10, WebOS, Playstation Vita, etc. 954 1058 function DetectTierIphone() 955 1059 { 956 if (($this->isIphone == $this->true) || 957 ($this->isAndroidPhone == $this->true)) 958 return $this->true; 959 1060 if ($this->initCompleted == $this->true || 1061 $this->isTierIphone == $this->true) 1062 return $this->isTierIphone; 1063 1064 if (($this->DetectIphoneOrIpod() == $this->true) 1065 || ($this->DetectAndroidPhone() == $this->true) 1066 || ($this->DetectWindowsPhone() == $this->true) 1067 || ($this->DetectBlackBerry10Phone() == $this->true) 1068 || ($this->DetectPalmWebOS() == $this->true) 1069 || ($this->DetectBada() == $this->true) 1070 || ($this->DetectTizen() == $this->true) 1071 || ($this->DetectGamingHandheld() == $this->true)) 1072 return $this->true; 1073 1074 //Note: BB10 phone is in the previous paragraph 960 1075 if (($this->DetectBlackBerryWebKit() == $this->true) && 961 ($this->DetectBlackBerryTouch() == $this->true)) 962 return $this->true; 963 if ($this->DetectWindowsPhone7() == $this->true) 964 return $this->true; 965 if ($this->DetectPalmWebOS() == $this->true) 966 return $this->true; 967 if ($this->DetectGarminNuvifone() == $this->true) 968 return $this->true; 1076 ($this->DetectBlackBerryTouch() == $this->true)) 1077 return $this->true; 1078 969 1079 else 970 1080 return $this->false; … … 979 1089 function DetectTierRichCss() 980 1090 { 1091 if ($this->initCompleted == $this->true || 1092 $this->isTierRichCss == $this->true) 1093 return $this->isTierRichCss; 1094 981 1095 if ($this->DetectMobileQuick() == $this->true) 982 1096 { … … 1016 1130 function DetectTierOtherPhones() 1017 1131 { 1132 if ($this->initCompleted == $this->true || 1133 $this->isTierGenericMobile == $this->true) 1134 return $this->isTierGenericMobile; 1135 1018 1136 //Exclude devices in the other 2 categories 1019 1137 if (($this->DetectMobileLong() == $this->true) 1020 1021 1138 && ($this->DetectTierIphone() == $this->false) 1139 && ($this->DetectTierRichCss() == $this->false)) 1022 1140 return $this->true; 1023 1141 else
Note: See TracChangeset
for help on using the changeset viewer.