source: branches/2.6/include/mdetect.php @ 27715

Last change on this file since 27715 was 18967, checked in by patdenice, 11 years ago

bug:2687
bug:2778
Unable to switch from mobile theme to classic theme with incompatible plugins.
Detect blackberry and symbian for mobile theme.
Update mdetect class.

File size: 37.3 KB
Line 
1<?php
2
3/* *******************************************
4// Copyright 2010-2012, Anthony Hand
5//
6// File version date: April 23, 2012
7//              Update:
8//              - Updated DetectAmazonSilk(): Fixed an issue in the detection logic. 
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. 
15//
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.
37//
38//
39// LICENSE INFORMATION
40// Licensed under the Apache License, Version 2.0 (the "License");
41// you may not use this file except in compliance with the License.
42// You may obtain a copy of the License at
43//        http://www.apache.org/licenses/LICENSE-2.0
44// Unless required by applicable law or agreed to in writing,
45// software distributed under the License is distributed on an
46// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
47// either express or implied. See the License for the specific
48// language governing permissions and limitations under the License.
49//
50//
51// ABOUT THIS PROJECT
52//   Project Owner: Anthony Hand
53//   Email: anthony.hand@gmail.com
54//   Web Site: http://www.mobileesp.com
55//   Source Files: http://code.google.com/p/mobileesp/
56//   
57//   Versions of this code are available for:
58//      PHP, JavaScript, Java, ASP.NET (C#), and Ruby
59//
60// *******************************************
61*/
62
63
64
65//**************************
66// The uagent_info class encapsulates information about
67//   a browser's connection to your web site.
68//   You can use it to find out whether the browser asking for
69//   your site's content is probably running on a mobile device.
70//   The methods were written so you can be as granular as you want.
71//   For example, enquiring whether it's as specific as an iPod Touch or
72//   as general as a smartphone class device.
73//   The object's methods return 1 for true, or 0 for false.
74class uagent_info
75{
76   var $useragent = "";
77   var $httpaccept = "";
78
79   //standardized values for true and false.
80   var $true = 1;
81   var $false = 0;
82
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)
90
91   //Initialize some initial smartphone string variables.
92   var $engineWebKit = 'webkit';
93   var $deviceIphone = 'iphone';
94   var $deviceIpod = 'ipod';
95   var $deviceIpad = 'ipad';
96   var $deviceMacPpc = 'macintosh'; //Used for disambiguation
97
98   var $deviceAndroid = 'android';
99   var $deviceGoogleTV = 'googletv';
100   var $deviceXoom = 'xoom'; //Motorola Xoom
101   var $deviceHtcFlyer = 'htc_flyer'; //HTC Flyer
102   
103   var $deviceNuvifone = 'nuvifone'; //Garmin Nuvifone
104
105   var $deviceSymbian = 'symbian';
106   var $deviceS60 = 'series60';
107   var $deviceS70 = 'series70';
108   var $deviceS80 = 'series80';
109   var $deviceS90 = 'series90';
110   
111   var $deviceWinPhone7 = 'windows phone os 7'; 
112   var $deviceWinMob = 'windows ce';
113   var $deviceWindows = 'windows'; 
114   var $deviceIeMob = 'iemobile';
115   var $devicePpc = 'ppc'; //Stands for PocketPC
116   var $enginePie = 'wm5 pie'; //An old Windows Mobile
117   
118   var $deviceBB = 'blackberry';   
119   var $vndRIM = 'vnd.rim'; //Detectable when BB devices emulate IE or Firefox
120   var $deviceBBStorm = 'blackberry95';  //Storm 1 and 2
121   var $deviceBBBold = 'blackberry97'; //Bold 97x0 (non-touch)
122   var $deviceBBBoldTouch = 'blackberry 99'; //Bold 99x0 (touchscreen)
123   var $deviceBBTour = 'blackberry96'; //Tour
124   var $deviceBBCurve = 'blackberry89'; //Curve2
125   var $deviceBBCurveTouch = 'blackberry 938'; //Curve Touch
126   var $deviceBBTorch = 'blackberry 98'; //Torch
127   var $deviceBBPlaybook = 'playbook'; //PlayBook tablet
128   
129   var $devicePalm = 'palm';
130   var $deviceWebOS = 'webos'; //For Palm's line of WebOS devices
131   var $deviceWebOShp = 'hpwos'; //For HP's line of WebOS devices
132   
133   var $engineBlazer = 'blazer'; //Old Palm browser
134   var $engineXiino = 'xiino'; //Another old Palm
135   
136   var $deviceKindle = 'kindle'; //Amazon Kindle, eInk one
137   var $engineSilk = 'silk'; //Amazon's accelerated Silk browser for Kindle Fire
138   
139   //Initialize variables for mobile-specific content.
140   var $vndwap = 'vnd.wap';
141   var $wml = 'wml';   
142   
143   //Initialize variables for other random devices and mobile browsers.
144   var $deviceTablet = 'tablet'; //Generic term for slate and tablet devices
145   var $deviceBrew = 'brew';
146   var $deviceDanger = 'danger';
147   var $deviceHiptop = 'hiptop';
148   var $devicePlaystation = 'playstation';
149   var $deviceNintendoDs = 'nitro';
150   var $deviceNintendo = 'nintendo';
151   var $deviceWii = 'wii';
152   var $deviceXbox = 'xbox';
153   var $deviceArchos = 'archos';
154   
155   var $engineOpera = 'opera'; //Popular browser
156   var $engineNetfront = 'netfront'; //Common embedded OS browser
157   var $engineUpBrowser = 'up.browser'; //common on some phones
158   var $engineOpenWeb = 'openweb'; //Transcoding by OpenWave server
159   var $deviceMidp = 'midp'; //a mobile Java technology
160   var $uplink = 'up.link';
161   var $engineTelecaQ = 'teleca q'; //a modern feature phone browser
162   
163   var $devicePda = 'pda'; //some devices report themselves as PDAs
164   var $mini = 'mini';  //Some mobile browsers put 'mini' in their names.
165   var $mobile = 'mobile'; //Some mobile browsers put 'mobile' in their user agent strings.
166   var $mobi = 'mobi'; //Some mobile browsers put 'mobi' in their user agent strings.
167   
168   //Use Maemo, Tablet, and Linux to test for Nokia's Internet Tablets.
169   var $maemo = 'maemo';
170   var $linux = 'linux';
171   var $qtembedded = 'qt embedded'; //for Sony Mylo and others
172   var $mylocom2 = 'com2'; //for Sony Mylo also
173   
174   //In some UserAgents, the only clue is the manufacturer.
175   var $manuSonyEricsson = "sonyericsson";
176   var $manuericsson = "ericsson";
177   var $manuSamsung1 = "sec-sgh";
178   var $manuSony = "sony";
179   var $manuHtc = "htc"; //Popular Android and WinMo manufacturer
180
181   //In some UserAgents, the only clue is the operator.
182   var $svcDocomo = "docomo";
183   var $svcKddi = "kddi";
184   var $svcVodafone = "vodafone";
185
186   //Disambiguation strings.
187   var $disUpdate = "update"; //pda vs. update
188
189
190   //**************************
191   //The constructor. Allows the latest PHP (5.0+) to locate a constructor object and initialize the object.
192   function __construct()
193   {
194                $this->uagent_info();
195   }
196
197
198   //**************************
199   //The object initializer. Initializes several default variables.
200   function uagent_info()
201   { 
202                $this->useragent = isset($_SERVER['HTTP_USER_AGENT'])?strtolower($_SERVER['HTTP_USER_AGENT']):'';
203                $this->httpaccept = isset($_SERVER['HTTP_ACCEPT'])?strtolower($_SERVER['HTTP_ACCEPT']):'';
204               
205                //Let's initialize some values to save cycles later.
206                $this->InitDeviceScan();
207   }
208   
209   //**************************
210   // Initialize Key Stored Values.
211   function InitDeviceScan()
212   {
213        global $isIphone, $isAndroidPhone, $isTierTablet, $isTierIphone;
214       
215        //We'll use these 4 variables to speed other processing. They're super common.
216        $this->isIphone = $this->DetectIphoneOrIpod();
217        $this->isAndroidPhone = $this->DetectAndroidPhone();
218        $this->isTierIphone = $this->DetectTierIphone();
219        $this->isTierTablet = $this->DetectTierTablet();
220       
221        //Optional: Comment these out if you don't need them.
222        global $isTierRichCss, $isTierGenericMobile;
223        $this->isTierRichCss = $this->DetectTierRichCss();
224        $this->isTierGenericMobile = $this->DetectTierOtherPhones();
225   }
226
227   //**************************
228   //Returns the contents of the User Agent value, in lower case.
229   function Get_Uagent()
230   { 
231       return $this->useragent;
232   }
233
234   //**************************
235   //Returns the contents of the HTTP Accept value, in lower case.
236   function Get_HttpAccept()
237   { 
238       return $this->httpaccept;
239   }
240   
241
242   //**************************
243   // Detects if the current device is an iPhone.
244   function DetectIphone()
245   {
246      if (stripos($this->useragent, $this->deviceIphone) > -1)
247      {
248         //The iPad and iPod Touch say they're an iPhone. So let's disambiguate.
249         if ($this->DetectIpad() == $this->true ||
250             $this->DetectIpod() == $this->true)
251            return $this->false;
252         //Yay! It's an iPhone!
253         else
254            return $this->true; 
255      }
256      else
257         return $this->false; 
258   }
259
260   //**************************
261   // Detects if the current device is an iPod Touch.
262   function DetectIpod()
263   {
264      if (stripos($this->useragent, $this->deviceIpod) > -1)
265         return $this->true; 
266      else
267         return $this->false; 
268   }
269   
270   //**************************
271   // Detects if the current device is an iPad tablet.
272   function DetectIpad()
273   {
274      if (stripos($this->useragent, $this->deviceIpad) > -1 &&
275          $this->DetectWebkit() == $this->true)
276         return $this->true; 
277      else
278         return $this->false; 
279   }
280
281   //**************************
282   // Detects if the current device is an iPhone or iPod Touch.
283   function DetectIphoneOrIpod()
284   {
285       //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)
288         return $this->true; 
289      else
290         return $this->false; 
291   }
292
293   //**************************
294   // Detects *any* iOS device: iPhone, iPod Touch, iPad.
295   function DetectIos()
296   {
297      if (($this->DetectIphoneOrIpod() == $this->true) ||
298        ($this->DetectIpad() == $this->true))
299         return $this->true; 
300      else
301         return $this->false;
302   }
303
304
305   //**************************
306   // Detects *any* Android OS-based device: phone, tablet, and multi-media player.
307   // Also detects Google TV.
308   function DetectAndroid()
309   {
310      if ((stripos($this->useragent, $this->deviceAndroid) > -1) ||
311         ($this->DetectGoogleTV() == $this->true))
312         return $this->true; 
313      //Special check for the HTC Flyer 7" tablet
314      if ((stripos($this->useragent, $this->deviceHtcFlyer) > -1))
315         return $this->true; 
316      else
317         return $this->false; 
318   }
319
320   //**************************
321   // Detects if the current device is a (small-ish) Android OS-based device
322   // used for calling and/or multi-media (like a Samsung Galaxy Player).
323   // Google says these devices will have 'Android' AND 'mobile' in user agent.
324   // Ignores tablets (Honeycomb and later).
325   function DetectAndroidPhone()
326   {
327      if (($this->DetectAndroid() == $this->true) &&
328                (stripos($this->useragent, $this->mobile) > -1))
329         return $this->true; 
330      //Special check for Android phones with Opera Mobile. They should report here.
331      if (($this->DetectOperaAndroidPhone() == $this->true))
332         return $this->true; 
333      //Special check for the HTC Flyer 7" tablet. It should report here.
334      if ((stripos($this->useragent, $this->deviceHtcFlyer) > -1))
335         return $this->true; 
336      else
337         return $this->false; 
338   }
339
340   //**************************
341   // Detects if the current device is a (self-reported) Android tablet.
342   // Google says these devices will have 'Android' and NOT 'mobile' in their user agent.
343   function DetectAndroidTablet()
344   {
345      //First, let's make sure we're on an Android device.
346      if ($this->DetectAndroid() == $this->false)
347         return $this->false; 
348
349      //Special check for Opera Android Phones. They should NOT report here.
350      if ($this->DetectOperaMobile() == $this->true)
351         return $this->false; 
352      //Special check for the HTC Flyer 7" tablet. It should NOT report here.
353      if ((stripos($this->useragent, $this->deviceHtcFlyer) > -1))
354         return $this->false; 
355         
356      //Otherwise, if it's Android and does NOT have 'mobile' in it, Google says it's a tablet.
357      if (stripos($this->useragent, $this->mobile) > -1)
358         return $this->false;
359      else
360         return $this->true; 
361   }
362
363   //**************************
364   // Detects if the current device is an Android OS-based device and
365   //   the browser is based on WebKit.
366   function DetectAndroidWebKit()
367   {
368      if (($this->DetectAndroid() == $this->true) &&
369                ($this->DetectWebkit() == $this->true))
370         return $this->true; 
371      else
372         return $this->false; 
373   }
374
375   //**************************
376   // Detects if the current device is a GoogleTV.
377   function DetectGoogleTV()
378   {
379      if (stripos($this->useragent, $this->deviceGoogleTV) > -1)
380         return $this->true; 
381      else
382         return $this->false; 
383   }
384
385   //**************************
386   // Detects if the current browser is based on WebKit.
387   function DetectWebkit()
388   {
389      if (stripos($this->useragent, $this->engineWebKit) > -1)
390         return $this->true; 
391      else
392         return $this->false; 
393   }
394
395
396   //**************************
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.
434   function DetectWindowsPhone7()
435   {
436      if (stripos($this->useragent, $this->deviceWinPhone7) > -1)
437         return $this->true; 
438      else
439         return $this->false; 
440   }
441
442   //**************************
443   // Detects if the current browser is a Windows Mobile device.
444   // Excludes Windows Phone 7 devices.
445   // Focuses on Windows Mobile 6.xx and earlier.
446   function DetectWindowsMobile()
447   {
448      if ($this->DetectWindowsPhone7() == $this->true)
449         return $this->false; 
450      //Most devices use 'Windows CE', but some report 'iemobile'
451      //  and some older ones report as 'PIE' for Pocket IE.
452      if (stripos($this->useragent, $this->deviceWinMob) > -1 ||
453          stripos($this->useragent, $this->deviceIeMob) > -1 ||
454          stripos($this->useragent, $this->enginePie) > -1)
455         return $this->true; 
456      //Test for Windows Mobile PPC but not old Macintosh PowerPC.
457          if (stripos($this->useragent, $this->devicePpc) > -1
458                  && !(stripos($this->useragent, $this->deviceMacPpc) > 1))
459         return $this->true; 
460      //Test for certain Windwos Mobile-based HTC devices.
461      if (stripos($this->useragent, $this->manuHtc) > -1 &&
462          stripos($this->useragent, $this->deviceWindows) > -1)
463         return $this->true; 
464      if ($this->DetectWapWml() == $this->true &&
465          stripos($this->useragent, $this->deviceWindows) > -1) 
466         return $this->true; 
467      else
468         return $this->false; 
469   }
470
471   //**************************
472   // Detects if the current browser is any BlackBerry device.
473   // Includes the PlayBook.
474   function DetectBlackBerry()
475   {
476       if ((stripos($this->useragent, $this->deviceBB) > -1) ||
477          (stripos($this->httpaccept, $this->vndRIM) > -1))
478         return $this->true; 
479       else
480         return $this->false; 
481   }
482   
483   //**************************
484   // Detects if the current browser is on a BlackBerry tablet device.
485   //    Examples: PlayBook
486   function DetectBlackBerryTablet()
487   {
488      if ((stripos($this->useragent, $this->deviceBBPlaybook) > -1))
489         return $this->true; 
490      else
491        return $this->false; 
492   }
493
494   //**************************
495   // Detects if the current browser is a BlackBerry phone device AND uses a
496   //    WebKit-based browser. These are signatures for the new BlackBerry OS 6.
497   //    Examples: Torch. Includes the Playbook.
498   function DetectBlackBerryWebKit()
499   {
500      if (($this->DetectBlackBerry() == $this->true) &&
501                ($this->DetectWebkit() == $this->true))
502         return $this->true; 
503      else
504        return $this->false; 
505   }
506
507   //**************************
508   // Detects if the current browser is a BlackBerry Touch phone device with
509   //    a large screen, such as the Storm, Torch, and Bold Touch. Excludes the Playbook.
510   function DetectBlackBerryTouch()
511   { 
512       if ((stripos($this->useragent, $this->deviceBBStorm) > -1) ||
513                (stripos($this->useragent, $this->deviceBBTorch) > -1) ||
514                (stripos($this->useragent, $this->deviceBBBoldTouch) > -1) ||
515                (stripos($this->useragent, $this->deviceBBCurveTouch) > -1))
516         return $this->true; 
517       else
518         return $this->false; 
519   }
520   
521   //**************************
522   // Detects if the current browser is a BlackBerry OS 5 device AND
523   //    has a more capable recent browser. Excludes the Playbook.
524   //    Examples, Storm, Bold, Tour, Curve2
525   //    Excludes the new BlackBerry OS 6 and 7 browser!!
526   function DetectBlackBerryHigh()
527   {
528      //Disambiguate for BlackBerry OS 6 or 7 (WebKit) browser
529      if ($this->DetectBlackBerryWebKit() == $this->true)
530         return $this->false; 
531      if ($this->DetectBlackBerry() == $this->true)
532      {
533          if (($this->DetectBlackBerryTouch() == $this->true) ||
534            stripos($this->useragent, $this->deviceBBBold) > -1 ||
535            stripos($this->useragent, $this->deviceBBTour) > -1 ||
536            stripos($this->useragent, $this->deviceBBCurve) > -1)
537          {
538             return $this->true; 
539          }
540          else
541            return $this->false; 
542      }
543      else
544        return $this->false; 
545   }
546
547   //**************************
548   // Detects if the current browser is a BlackBerry device AND
549   //    has an older, less capable browser.
550   //    Examples: Pearl, 8800, Curve1.
551   function DetectBlackBerryLow()
552   {
553      if ($this->DetectBlackBerry() == $this->true)
554      {
555          //Assume that if it's not in the High tier, then it's Low.
556          if (($this->DetectBlackBerryHigh() == $this->true) ||
557                        ($this->DetectBlackBerryWebKit() == $this->true))
558             return $this->false; 
559          else
560            return $this->true; 
561      }
562      else
563        return $this->false; 
564   }
565
566   //**************************
567   // Detects if the current browser is on a PalmOS device.
568   function DetectPalmOS()
569   {
570      //Most devices nowadays report as 'Palm', but some older ones reported as Blazer or Xiino.
571      if (stripos($this->useragent, $this->devicePalm) > -1 ||
572          stripos($this->useragent, $this->engineBlazer) > -1 ||
573          stripos($this->useragent, $this->engineXiino) > -1)
574      {
575         //Make sure it's not WebOS first
576         if ($this->DetectPalmWebOS() == $this->true)
577            return $this->false;
578         else
579            return $this->true; 
580      }
581      else
582         return $this->false; 
583   }
584
585
586   //**************************
587   // Detects if the current browser is on a Palm device
588   //   running the new WebOS.
589   function DetectPalmWebOS()
590   {
591      if (stripos($this->useragent, $this->deviceWebOS) > -1)
592         return $this->true; 
593      else
594         return $this->false; 
595   }
596
597   //**************************
598   // Detects if the current browser is on an HP tablet running WebOS.
599   function DetectWebOSTablet()
600   {
601      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   }
664
665   //**************************
666   // Detects if the current browser is Opera Mobile or Mini.
667   function DetectOperaMobile()
668   {
669      if (stripos($this->useragent, $this->engineOpera) > -1)
670      {
671         if ((stripos($this->useragent, $this->mini) > -1) ||
672          (stripos($this->useragent, $this->mobi) > -1))
673            return $this->true; 
674         else
675            return $this->false; 
676      }
677      else
678         return $this->false; 
679   }
680
681   //**************************
682   // Detects if the current browser is Opera Mobile
683   // running on an Android phone.
684   function DetectOperaAndroidPhone()
685   {
686      if ((stripos($this->useragent, $this->engineOpera) > -1) &&
687        (stripos($this->useragent, $this->deviceAndroid) > -1) &&
688                (stripos($this->useragent, $this->mobi) > -1))
689         return $this->true; 
690      else
691         return $this->false; 
692   }
693
694   //**************************
695   // Detects if the current browser is Opera Mobile
696   // running on an Android tablet. 
697   function DetectOperaAndroidTablet()
698   {
699      if ((stripos($this->useragent, $this->engineOpera) > -1) &&
700        (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   
718   //**************************
719   // Detects if the current device is an Amazon Kindle (eInk devices only).
720   // Note: For the Kindle Fire, use the normal Android methods.
721   function DetectKindle()
722   {
723      if (stripos($this->useragent, $this->deviceKindle) > -1 &&
724          $this->DetectAndroid() == $this->false)
725         return $this->true; 
726      else
727         return $this->false; 
728   }
729   
730   //**************************
731   // Detects if the current Amazon device is using the Silk Browser.
732   // Note: Typically used by the the Kindle Fire.
733   function DetectAmazonSilk()
734   {
735      if (stripos($this->useragent, $this->engineSilk) > -1)
736         return $this->true; 
737      else
738         return $this->false; 
739   }
740   
741   
742   //**************************
743   // The quick way to detect for a mobile device.
744   //   Will probably detect most recent/current mid-tier Feature Phones
745   //   as well as smartphone-class devices. Excludes Apple iPads and other modern tablets.
746   function DetectMobileQuick()
747   {
748      //Let's exclude tablets
749      if ($this->isTierTablet == $this->true) 
750         return $this->false;
751     
752      //Most mobile browsing is done on smartphones
753      if ($this->DetectSmartphone() == $this->true) 
754         return $this->true;
755
756      if (($this->DetectWapWml() == $this->true) 
757                        || ($this->DetectBrewDevice() == $this->true) 
758                        || ($this->DetectOperaMobile() == $this->true))
759         return $this->true;
760         
761      if ((stripos($this->useragent, $this->engineNetfront) > -1)
762                        || (stripos($this->useragent, $this->engineUpBrowser) > -1)
763                        || (stripos($this->useragent, $this->engineOpenWeb) > -1))
764         return $this->true; 
765         
766      if (($this->DetectDangerHiptop() == $this->true) 
767                        || ($this->DetectMidpCapable() == $this->true) 
768                        || ($this->DetectMaemoTablet() == $this->true) 
769                        || ($this->DetectArchos() == $this->true))
770         return $this->true; 
771
772       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
778      //We also look for Kindle devices
779      if ($this->DetectKindle() == $this->true ||
780         $this->DetectAmazonSilk() == $this->true) 
781         return $this->true;
782
783      else
784         return $this->false; 
785   }
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      else
794         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      else
806         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      else
816         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      else
830         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      else
841         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      else
857         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      else
867         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         else
882            return $this->false; 
883      }
884      else
885         return $this->false; 
886   }
887   
888 
889   //**************************
890   // The longer and more thorough way to detect for a mobile device.
891   //   Will probably detect most feature phones,
892   //   smartphone-class devices, Internet Tablets,
893   //   Internet-enabled game consoles, etc.
894   //   This ought to catch a lot of the more obscure and older devices, also --
895   //   but no promises on thoroughness!
896   function DetectMobileLong()
897   {
898      if ($this->DetectMobileQuick() == $this->true) 
899         return $this->true; 
900      if ($this->DetectGameConsole() == $this->true) 
901         return $this->true; 
902      if ($this->DetectSonyMylo() == $this->true) 
903         return $this->true; 
904
905       //Detect older phones from certain manufacturers and operators.
906       if (stripos($this->useragent, $this->uplink) > -1)
907         return $this->true; 
908       if (stripos($this->useragent, $this->manuSonyEricsson) > -1)
909         return $this->true; 
910       if (stripos($this->useragent, $this->manuericsson) > -1)
911         return $this->true; 
912
913       if (stripos($this->useragent, $this->manuSamsung1) > -1)
914         return $this->true; 
915       if (stripos($this->useragent, $this->svcDocomo) > -1)
916         return $this->true; 
917       if (stripos($this->useragent, $this->svcKddi) > -1)
918         return $this->true; 
919       if (stripos($this->useragent, $this->svcVodafone) > -1)
920         return $this->true; 
921
922      else
923         return $this->false; 
924   }
925
926
927
928  //*****************************
929  // For Mobile Web Site Design
930  //*****************************
931
932   //**************************
933   // The quick way to detect for a tier of devices.
934   //   This method detects for the new generation of
935   //   HTML 5 capable, larger screen tablets.
936   //   Includes iPad, Android (e.g., Xoom), BB Playbook, WebOS, etc.
937   function DetectTierTablet()
938   {
939      if (($this->DetectIpad() == $this->true) 
940         || ($this->DetectAndroidTablet() == $this->true) 
941         || ($this->DetectBlackBerryTablet() == $this->true) 
942         || ($this->DetectWebOSTablet() == $this->true))
943         return $this->true; 
944      else
945         return $this->false; 
946   }
947
948
949   //**************************
950   // The quick way to detect for a tier of devices.
951   //   This method detects for devices which can
952   //   display iPhone-optimized web content.
953   //   Includes iPhone, iPod Touch, Android, Windows Phone 7, WebOS, etc.
954   function DetectTierIphone()
955   {
956      if (($this->isIphone == $this->true) ||
957                        ($this->isAndroidPhone == $this->true))
958         return $this->true; 
959   
960      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; 
969      else
970         return $this->false; 
971   }
972   
973   //**************************
974   // The quick way to detect for a tier of devices.
975   //   This method detects for devices which are likely to be capable
976   //   of viewing CSS content optimized for the iPhone,
977   //   but may not necessarily support JavaScript.
978   //   Excludes all iPhone Tier devices.
979   function DetectTierRichCss()
980   {
981      if ($this->DetectMobileQuick() == $this->true) 
982      {
983        //Exclude iPhone Tier and e-Ink Kindle devices
984        if (($this->DetectTierIphone() == $this->true) ||
985            ($this->DetectKindle() == $this->true))
986           return $this->false;
987           
988        //The following devices are explicitly ok.
989        if ($this->DetectWebkit() == $this->true) //Any WebKit
990           return $this->true;
991        if ($this->DetectS60OssBrowser() == $this->true)
992           return $this->true;
993           
994        //Note: 'High' BlackBerry devices ONLY
995        if ($this->DetectBlackBerryHigh() == $this->true)
996           return $this->true;
997       
998        //Older Windows 'Mobile' isn't good enough for iPhone Tier.
999        if ($this->DetectWindowsMobile() == $this->true)
1000           return $this->true;
1001        if (stripos($this->useragent, $this->engineTelecaQ) > -1)
1002           return $this->true;
1003         
1004        //default
1005        else
1006           return $this->false;
1007      }
1008      else
1009         return $this->false; 
1010   }
1011
1012   //**************************
1013   // The quick way to detect for a tier of devices.
1014   //   This method detects for all other types of phones,
1015   //   but excludes the iPhone and RichCSS Tier devices.
1016   function DetectTierOtherPhones()
1017   {
1018      //Exclude devices in the other 2 categories
1019      if (($this->DetectMobileLong() == $this->true)
1020                && ($this->DetectTierIphone() == $this->false)
1021                && ($this->DetectTierRichCss() == $this->false))
1022           return $this->true;
1023      else
1024         return $this->false; 
1025   }
1026     
1027
1028}
1029
1030
1031//Was informed by a MobileESP user that it's a best practice
1032//  to omit the closing ?&gt; marks here. They can sometimes
1033//  cause errors with HTML headers.
Note: See TracBrowser for help on using the repository browser.