source: trunk/include/mdetect.php @ 14308

Last change on this file since 14308 was 13172, checked in by patdenice, 13 years ago

feature:2577
Add functionnality in core files.

File size: 35.9 KB
Line 
1<?php
2
3/* *******************************************
4// Copyright 2010-2012, Anthony Hand
5//
6// File version date: January 21, 2012
7//              Update:
8//              - Added the constructor method per new features in PHP 5.0: __construct().
9//              - Moved Windows Phone 7 to the iPhone Tier. WP7.5's IE 9-based browser is good enough now. 
10//              - Added a new variable for 2 versions of the new BlackBerry Bold Touch (9900 and 9930): deviceBBBoldTouch.
11//              - Updated DetectBlackBerryTouch() to support the 2 versions of the new BlackBerry Bold Touch (9900 and 9930).
12//              - Updated DetectKindle() to focus on eInk devices only. The Kindle Fire should be detected as a regular Android device.
13//
14// File version date: August 22, 2011
15//              Update:
16//              - Updated DetectAndroidTablet() to fix a bug introduced in the last fix! The true/false returns were mixed up.
17//
18// File version date: August 16, 2011
19//              Update:
20//              - Updated DetectAndroidTablet() to exclude Opera Mini, which was falsely reporting as running on a tablet device when on a phone.
21//
22// File version date: August 7, 2011
23//              Update:
24//              - The Opera for Android browser doesn't follow Google's recommended useragent string guidelines, so some fixes were needed.
25//              - Updated DetectAndroidPhone() and DetectAndroidTablet() to properly detect devices running Opera Mobile.
26//              - Created 2 new methods: DetectOperaAndroidPhone() and DetectOperaAndroidTablet().
27//              - Updated DetectTierIphone(). Removed the call to DetectMaemoTablet(), an obsolete mobile OS.
28//
29//
30// LICENSE INFORMATION
31// Licensed under the Apache License, Version 2.0 (the "License");
32// you may not use this file except in compliance with the License.
33// You may obtain a copy of the License at
34//        http://www.apache.org/licenses/LICENSE-2.0
35// Unless required by applicable law or agreed to in writing,
36// software distributed under the License is distributed on an
37// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
38// either express or implied. See the License for the specific
39// language governing permissions and limitations under the License.
40//
41//
42// ABOUT THIS PROJECT
43//   Project Owner: Anthony Hand
44//   Email: anthony.hand@gmail.com
45//   Web Site: http://www.mobileesp.com
46//   Source Files: http://code.google.com/p/mobileesp/
47//   
48//   Versions of this code are available for:
49//      PHP, JavaScript, Java, ASP.NET (C#), and Ruby
50//
51// *******************************************
52*/
53
54
55
56//**************************
57// The uagent_info class encapsulates information about
58//   a browser's connection to your web site.
59//   You can use it to find out whether the browser asking for
60//   your site's content is probably running on a mobile device.
61//   The methods were written so you can be as granular as you want.
62//   For example, enquiring whether it's as specific as an iPod Touch or
63//   as general as a smartphone class device.
64//   The object's methods return 1 for true, or 0 for false.
65class uagent_info
66{
67   var $useragent = "";
68   var $httpaccept = "";
69
70   //standardized values for true and false.
71   var $true = 1;
72   var $false = 0;
73
74   //Let's store values for quickly accessing the same info multiple times.
75   var $isIphone = 0; //Stores whether the device is an iPhone or iPod Touch.
76   var $isAndroidPhone = 0; //Stores whether the device is a (small-ish) Android phone or media player.
77   var $isTierTablet = 0; //Stores whether is the Tablet (HTML5-capable, larger screen) tier of devices.
78   var $isTierIphone = 0; //Stores whether is the iPhone tier of devices.
79   var $isTierRichCss = 0; //Stores whether the device can probably support Rich CSS, but JavaScript support is not assumed. (e.g., newer BlackBerry, Windows Mobile)
80   var $isTierGenericMobile = 0; //Stores whether it is another mobile device, which cannot be assumed to support CSS or JS (eg, older BlackBerry, RAZR)
81
82   //Initialize some initial smartphone string variables.
83   var $engineWebKit = 'webkit';
84   var $deviceIphone = 'iphone';
85   var $deviceIpod = 'ipod';
86   var $deviceIpad = 'ipad';
87   var $deviceMacPpc = 'macintosh'; //Used for disambiguation
88
89   var $deviceAndroid = 'android';
90   var $deviceGoogleTV = 'googletv';
91   var $deviceXoom = 'xoom'; //Motorola Xoom
92   var $deviceHtcFlyer = 'htc_flyer'; //HTC Flyer
93   
94   var $deviceNuvifone = 'nuvifone'; //Garmin Nuvifone
95
96   var $deviceSymbian = 'symbian';
97   var $deviceS60 = 'series60';
98   var $deviceS70 = 'series70';
99   var $deviceS80 = 'series80';
100   var $deviceS90 = 'series90';
101   
102   var $deviceWinPhone7 = 'windows phone os 7'; 
103   var $deviceWinMob = 'windows ce';
104   var $deviceWindows = 'windows'; 
105   var $deviceIeMob = 'iemobile';
106   var $devicePpc = 'ppc'; //Stands for PocketPC
107   var $enginePie = 'wm5 pie'; //An old Windows Mobile
108   
109   var $deviceBB = 'blackberry';   
110   var $vndRIM = 'vnd.rim'; //Detectable when BB devices emulate IE or Firefox
111   var $deviceBBStorm = 'blackberry95';  //Storm 1 and 2
112   var $deviceBBBold = 'blackberry97'; //Bold 97x0 (non-touch)
113   var $deviceBBBoldTouch = 'blackberry 99'; //Bold 99x0 (touchscreen)
114   var $deviceBBTour = 'blackberry96'; //Tour
115   var $deviceBBCurve = 'blackberry89'; //Curve2
116   var $deviceBBTorch = 'blackberry 98'; //Torch
117   var $deviceBBPlaybook = 'playbook'; //PlayBook tablet
118   
119   var $devicePalm = 'palm';
120   var $deviceWebOS = 'webos'; //For Palm's line of WebOS devices
121   var $deviceWebOShp = 'hpwos'; //For HP's line of WebOS devices
122   
123   var $engineBlazer = 'blazer'; //Old Palm browser
124   var $engineXiino = 'xiino'; //Another old Palm
125   
126   var $deviceKindle = 'kindle'; //Amazon Kindle, eInk one.
127   
128   //Initialize variables for mobile-specific content.
129   var $vndwap = 'vnd.wap';
130   var $wml = 'wml';   
131   
132   //Initialize variables for other random devices and mobile browsers.
133   var $deviceTablet = 'tablet'; //Generic term for slate and tablet devices
134   var $deviceBrew = 'brew';
135   var $deviceDanger = 'danger';
136   var $deviceHiptop = 'hiptop';
137   var $devicePlaystation = 'playstation';
138   var $deviceNintendoDs = 'nitro';
139   var $deviceNintendo = 'nintendo';
140   var $deviceWii = 'wii';
141   var $deviceXbox = 'xbox';
142   var $deviceArchos = 'archos';
143   
144   var $engineOpera = 'opera'; //Popular browser
145   var $engineNetfront = 'netfront'; //Common embedded OS browser
146   var $engineUpBrowser = 'up.browser'; //common on some phones
147   var $engineOpenWeb = 'openweb'; //Transcoding by OpenWave server
148   var $deviceMidp = 'midp'; //a mobile Java technology
149   var $uplink = 'up.link';
150   var $engineTelecaQ = 'teleca q'; //a modern feature phone browser
151   
152   var $devicePda = 'pda'; //some devices report themselves as PDAs
153   var $mini = 'mini';  //Some mobile browsers put 'mini' in their names.
154   var $mobile = 'mobile'; //Some mobile browsers put 'mobile' in their user agent strings.
155   var $mobi = 'mobi'; //Some mobile browsers put 'mobi' in their user agent strings.
156   
157   //Use Maemo, Tablet, and Linux to test for Nokia's Internet Tablets.
158   var $maemo = 'maemo';
159   var $linux = 'linux';
160   var $qtembedded = 'qt embedded'; //for Sony Mylo and others
161   var $mylocom2 = 'com2'; //for Sony Mylo also
162   
163   //In some UserAgents, the only clue is the manufacturer.
164   var $manuSonyEricsson = "sonyericsson";
165   var $manuericsson = "ericsson";
166   var $manuSamsung1 = "sec-sgh";
167   var $manuSony = "sony";
168   var $manuHtc = "htc"; //Popular Android and WinMo manufacturer
169
170   //In some UserAgents, the only clue is the operator.
171   var $svcDocomo = "docomo";
172   var $svcKddi = "kddi";
173   var $svcVodafone = "vodafone";
174
175   //Disambiguation strings.
176   var $disUpdate = "update"; //pda vs. update
177
178
179   //**************************
180   //The constructor. Allows the latest PHP (5.0+) to locate a constructor object and initialize the object.
181   function __construct()
182   {
183                $this->uagent_info();
184   }
185
186
187   //**************************
188   //The object initializer. Initializes several default variables.
189   function uagent_info()
190   { 
191                $this->useragent = isset($_SERVER['HTTP_USER_AGENT'])?strtolower($_SERVER['HTTP_USER_AGENT']):'';
192                $this->httpaccept = isset($_SERVER['HTTP_ACCEPT'])?strtolower($_SERVER['HTTP_ACCEPT']):'';
193               
194                //Let's initialize some values to save cycles later.
195                $this->InitDeviceScan();
196   }
197   
198   //**************************
199   // Initialize Key Stored Values.
200   function InitDeviceScan()
201   {
202        global $isIphone, $isAndroidPhone, $isTierTablet, $isTierIphone;
203       
204        //We'll use these 4 variables to speed other processing. They're super common.
205        $this->isIphone = $this->DetectIphoneOrIpod();
206        $this->isAndroidPhone = $this->DetectAndroidPhone();
207        $this->isTierIphone = $this->DetectTierIphone();
208        $this->isTierTablet = $this->DetectTierTablet();
209       
210        //Optional: Comment these out if you don't need them.
211        global $isTierRichCss, $isTierGenericMobile;
212        $this->isTierRichCss = $this->DetectTierRichCss();
213        $this->isTierGenericMobile = $this->DetectTierOtherPhones();
214   }
215
216   //**************************
217   //Returns the contents of the User Agent value, in lower case.
218   function Get_Uagent()
219   { 
220       return $this->useragent;
221   }
222
223   //**************************
224   //Returns the contents of the HTTP Accept value, in lower case.
225   function Get_HttpAccept()
226   { 
227       return $this->httpaccept;
228   }
229   
230
231   //**************************
232   // Detects if the current device is an iPhone.
233   function DetectIphone()
234   {
235      if (stripos($this->useragent, $this->deviceIphone) > -1)
236      {
237         //The iPad and iPod Touch say they're an iPhone. So let's disambiguate.
238         if ($this->DetectIpad() == $this->true ||
239             $this->DetectIpod() == $this->true)
240            return $this->false;
241         //Yay! It's an iPhone!
242         else
243            return $this->true; 
244      }
245      else
246         return $this->false; 
247   }
248
249   //**************************
250   // Detects if the current device is an iPod Touch.
251   function DetectIpod()
252   {
253      if (stripos($this->useragent, $this->deviceIpod) > -1)
254         return $this->true; 
255      else
256         return $this->false; 
257   }
258   
259   //**************************
260   // Detects if the current device is an iPad tablet.
261   function DetectIpad()
262   {
263      if (stripos($this->useragent, $this->deviceIpad) > -1 &&
264          $this->DetectWebkit() == $this->true)
265         return $this->true; 
266      else
267         return $this->false; 
268   }
269
270   //**************************
271   // Detects if the current device is an iPhone or iPod Touch.
272   function DetectIphoneOrIpod()
273   {
274       //We repeat the searches here because some iPods may report themselves as an iPhone, which would be okay.
275       if (stripos($this->useragent, $this->deviceIphone) > -1 ||
276           stripos($this->useragent, $this->deviceIpod) > -1)
277         return $this->true; 
278      else
279         return $this->false; 
280   }
281
282   //**************************
283   // Detects *any* iOS device: iPhone, iPod Touch, iPad.
284   function DetectIos()
285   {
286      if (($this->DetectIphoneOrIpod() == $this->true) ||
287        ($this->DetectIpad() == $this->true))
288         return $this->true; 
289      else
290         return $this->false;
291   }
292
293
294   //**************************
295   // Detects *any* Android OS-based device: phone, tablet, and multi-media player.
296   // Also detects Google TV.
297   function DetectAndroid()
298   {
299      if ((stripos($this->useragent, $this->deviceAndroid) > -1) ||
300         ($this->DetectGoogleTV() == $this->true))
301         return $this->true; 
302      //Special check for the HTC Flyer 7" tablet
303      if ((stripos($this->useragent, $this->deviceHtcFlyer) > -1))
304         return $this->true; 
305      else
306         return $this->false; 
307   }
308
309   //**************************
310   // Detects if the current device is a (small-ish) Android OS-based device
311   // used for calling and/or multi-media (like a Samsung Galaxy Player).
312   // Google says these devices will have 'Android' AND 'mobile' in user agent.
313   // Ignores tablets (Honeycomb and later).
314   function DetectAndroidPhone()
315   {
316      if (($this->DetectAndroid() == $this->true) &&
317                (stripos($this->useragent, $this->mobile) > -1))
318         return $this->true; 
319      //Special check for Android phones with Opera Mobile. They should report here.
320      if (($this->DetectOperaAndroidPhone() == $this->true))
321         return $this->true; 
322      //Special check for the HTC Flyer 7" tablet. It should report here.
323      if ((stripos($this->useragent, $this->deviceHtcFlyer) > -1))
324         return $this->true; 
325      else
326         return $this->false; 
327   }
328
329   //**************************
330   // Detects if the current device is a (self-reported) Android tablet.
331   // Google says these devices will have 'Android' and NOT 'mobile' in their user agent.
332   function DetectAndroidTablet()
333   {
334      //First, let's make sure we're on an Android device.
335      if ($this->DetectAndroid() == $this->false)
336         return $this->false; 
337
338      //Special check for Opera Android Phones. They should NOT report here.
339      if ($this->DetectOperaMobile() == $this->true)
340         return $this->false; 
341      //Special check for the HTC Flyer 7" tablet. It should NOT report here.
342      if ((stripos($this->useragent, $this->deviceHtcFlyer) > -1))
343         return $this->false; 
344         
345      //Otherwise, if it's Android and does NOT have 'mobile' in it, Google says it's a tablet.
346      if (stripos($this->useragent, $this->mobile) > -1)
347         return $this->false;
348      else
349         return $this->true; 
350   }
351
352   //**************************
353   // Detects if the current device is an Android OS-based device and
354   //   the browser is based on WebKit.
355   function DetectAndroidWebKit()
356   {
357      if (($this->DetectAndroid() == $this->true) &&
358                ($this->DetectWebkit() == $this->true))
359         return $this->true; 
360      else
361         return $this->false; 
362   }
363
364   //**************************
365   // Detects if the current device is a GoogleTV.
366   function DetectGoogleTV()
367   {
368      if (stripos($this->useragent, $this->deviceGoogleTV) > -1)
369         return $this->true; 
370      else
371         return $this->false; 
372   }
373
374   //**************************
375   // Detects if the current browser is based on WebKit.
376   function DetectWebkit()
377   {
378      if (stripos($this->useragent, $this->engineWebKit) > -1)
379         return $this->true; 
380      else
381         return $this->false; 
382   }
383
384
385   //**************************
386   // Detects if the current browser is the Nokia S60 Open Source Browser.
387   function DetectS60OssBrowser()
388   {
389      //First, test for WebKit, then make sure it's either Symbian or S60.
390      if ($this->DetectWebkit() == $this->true)
391      {
392        if (stripos($this->useragent, $this->deviceSymbian) > -1 ||
393            stripos($this->useragent, $this->deviceS60) > -1)
394        {
395           return $this->true;
396        }
397        else
398           return $this->false; 
399      }
400      else
401         return $this->false; 
402   }
403   
404   //**************************
405   // Detects if the current device is any Symbian OS-based device,
406   //   including older S60, Series 70, Series 80, Series 90, and UIQ,
407   //   or other browsers running on these devices.
408   function DetectSymbianOS()
409   {
410       if (stripos($this->useragent, $this->deviceSymbian) > -1 || 
411           stripos($this->useragent, $this->deviceS60) > -1 ||
412           stripos($this->useragent, $this->deviceS70) > -1 || 
413           stripos($this->useragent, $this->deviceS80) > -1 ||
414           stripos($this->useragent, $this->deviceS90) > -1)
415         return $this->true; 
416      else
417         return $this->false; 
418   }
419
420   //**************************
421   // Detects if the current browser is a
422   // Windows Phone 7 device.
423   function DetectWindowsPhone7()
424   {
425      if (stripos($this->useragent, $this->deviceWinPhone7) > -1)
426         return $this->true; 
427      else
428         return $this->false; 
429   }
430
431   //**************************
432   // Detects if the current browser is a Windows Mobile device.
433   // Excludes Windows Phone 7 devices.
434   // Focuses on Windows Mobile 6.xx and earlier.
435   function DetectWindowsMobile()
436   {
437      if ($this->DetectWindowsPhone7() == $this->true)
438         return $this->false; 
439      //Most devices use 'Windows CE', but some report 'iemobile'
440      //  and some older ones report as 'PIE' for Pocket IE.
441      if (stripos($this->useragent, $this->deviceWinMob) > -1 ||
442          stripos($this->useragent, $this->deviceIeMob) > -1 ||
443          stripos($this->useragent, $this->enginePie) > -1)
444         return $this->true; 
445      //Test for Windows Mobile PPC but not old Macintosh PowerPC.
446          if (stripos($this->useragent, $this->devicePpc) > -1
447                  && !(stripos($this->useragent, $this->deviceMacPpc) > 1))
448         return $this->true; 
449      //Test for certain Windwos Mobile-based HTC devices.
450      if (stripos($this->useragent, $this->manuHtc) > -1 &&
451          stripos($this->useragent, $this->deviceWindows) > -1)
452         return $this->true; 
453      if ($this->DetectWapWml() == $this->true &&
454          stripos($this->useragent, $this->deviceWindows) > -1) 
455         return $this->true; 
456      else
457         return $this->false; 
458   }
459
460   //**************************
461   // Detects if the current browser is any BlackBerry device.
462   // Includes the PlayBook.
463   function DetectBlackBerry()
464   {
465       if ((stripos($this->useragent, $this->deviceBB) > -1) ||
466          (stripos($this->httpaccept, $this->vndRIM) > -1))
467         return $this->true; 
468       else
469         return $this->false; 
470   }
471   
472   //**************************
473   // Detects if the current browser is on a BlackBerry tablet device.
474   //    Examples: PlayBook
475   function DetectBlackBerryTablet()
476   {
477      if ((stripos($this->useragent, $this->deviceBBPlaybook) > -1))
478         return $this->true; 
479      else
480        return $this->false; 
481   }
482
483   //**************************
484   // Detects if the current browser is a BlackBerry phone device AND uses a
485   //    WebKit-based browser. These are signatures for the new BlackBerry OS 6.
486   //    Examples: Torch. Includes the Playbook.
487   function DetectBlackBerryWebKit()
488   {
489      if (($this->DetectBlackBerry() == $this->true) &&
490                ($this->DetectWebkit() == $this->true))
491         return $this->true; 
492      else
493        return $this->false; 
494   }
495
496   //**************************
497   // Detects if the current browser is a BlackBerry Touch phone
498   //    device, such as the Storm, Torch, and Bold Touch. Excludes the Playbook.
499   function DetectBlackBerryTouch()
500   {
501       if ((stripos($this->useragent, $this->deviceBBStorm) > -1) ||
502                (stripos($this->useragent, $this->deviceBBTorch) > -1) ||
503                (stripos($this->useragent, $this->deviceBBBoldTouch) > -1))
504         return $this->true; 
505       else
506         return $this->false; 
507   }
508   
509   //**************************
510   // Detects if the current browser is a BlackBerry OS 5 device AND
511   //    has a more capable recent browser. Excludes the Playbook.
512   //    Examples, Storm, Bold, Tour, Curve2
513   //    Excludes the new BlackBerry OS 6 and 7 browser!!
514   function DetectBlackBerryHigh()
515   {
516      //Disambiguate for BlackBerry OS 6 or 7 (WebKit) browser
517      if ($this->DetectBlackBerryWebKit() == $this->true)
518         return $this->false; 
519      if ($this->DetectBlackBerry() == $this->true)
520      {
521          if (($this->DetectBlackBerryTouch() == $this->true) ||
522            stripos($this->useragent, $this->deviceBBBold) > -1 ||
523            stripos($this->useragent, $this->deviceBBTour) > -1 ||
524            stripos($this->useragent, $this->deviceBBCurve) > -1)
525          {
526             return $this->true; 
527          }
528          else
529            return $this->false; 
530      }
531      else
532        return $this->false; 
533   }
534
535   //**************************
536   // Detects if the current browser is a BlackBerry device AND
537   //    has an older, less capable browser.
538   //    Examples: Pearl, 8800, Curve1.
539   function DetectBlackBerryLow()
540   {
541      if ($this->DetectBlackBerry() == $this->true)
542      {
543          //Assume that if it's not in the High tier, then it's Low.
544          if (($this->DetectBlackBerryHigh() == $this->true) ||
545                        ($this->DetectBlackBerryWebKit() == $this->true))
546             return $this->false; 
547          else
548            return $this->true; 
549      }
550      else
551        return $this->false; 
552   }
553
554   //**************************
555   // Detects if the current browser is on a PalmOS device.
556   function DetectPalmOS()
557   {
558      //Most devices nowadays report as 'Palm', but some older ones reported as Blazer or Xiino.
559      if (stripos($this->useragent, $this->devicePalm) > -1 ||
560          stripos($this->useragent, $this->engineBlazer) > -1 ||
561          stripos($this->useragent, $this->engineXiino) > -1)
562      {
563         //Make sure it's not WebOS first
564         if ($this->DetectPalmWebOS() == $this->true)
565            return $this->false;
566         else
567            return $this->true; 
568      }
569      else
570         return $this->false; 
571   }
572
573
574   //**************************
575   // Detects if the current browser is on a Palm device
576   //   running the new WebOS.
577   function DetectPalmWebOS()
578   {
579      if (stripos($this->useragent, $this->deviceWebOS) > -1)
580         return $this->true; 
581      else
582         return $this->false; 
583   }
584
585   //**************************
586   // Detects if the current browser is on an HP tablet running WebOS.
587   function DetectWebOSTablet()
588   {
589      if ((stripos($this->useragent, $this->deviceWebOShp) > -1)
590                        && (stripos($this->useragent, $this->deviceTablet) > -1))
591         return $this->true; 
592      else
593         return $this->false; 
594   }
595
596   //**************************
597   // Detects if the current browser is a
598   //   Garmin Nuvifone.
599   function DetectGarminNuvifone()
600   {
601      if (stripos($this->useragent, $this->deviceNuvifone) > -1)
602         return $this->true; 
603      else
604         return $this->false; 
605   }
606
607
608   //**************************
609   // Check to see whether the device is any device
610   //   in the 'smartphone' category.
611   function DetectSmartphone()
612   {
613      global $isIphone, $isAndroidPhone, $isTierIphone;
614
615      if (($this->isIphone == $this->true)
616                        || ($this->isAndroidPhone == $this->true)
617                        || ($this->isTierIphone == $this->true)
618                        || ($this->DetectS60OssBrowser() == $this->true)
619                        || ($this->DetectSymbianOS() == $this->true) 
620                        || ($this->DetectWindowsMobile() == $this->true)
621                        || ($this->DetectWindowsPhone7() == $this->true)
622                        || ($this->DetectBlackBerry() == $this->true)
623                        || ($this->DetectPalmWebOS() == $this->true)
624                        || ($this->DetectPalmOS() == $this->true)
625                        || ($this->DetectGarminNuvifone() == $this->true))
626         return $this->true; 
627      else
628         return $this->false; 
629   }
630
631
632   //**************************
633   // Detects whether the device is a Brew-powered device.
634   function DetectBrewDevice()
635   {
636       if (stripos($this->useragent, $this->deviceBrew) > -1)
637         return $this->true; 
638      else
639         return $this->false; 
640   }
641
642   //**************************
643   // Detects the Danger Hiptop device.
644   function DetectDangerHiptop()
645   {
646      if (stripos($this->useragent, $this->deviceDanger) > -1 ||
647          stripos($this->useragent, $this->deviceHiptop) > -1)
648         return $this->true; 
649      else
650         return $this->false; 
651   }
652
653   //**************************
654   // Detects if the current browser is Opera Mobile or Mini.
655   function DetectOperaMobile()
656   {
657      if (stripos($this->useragent, $this->engineOpera) > -1)
658      {
659         if ((stripos($this->useragent, $this->mini) > -1) ||
660          (stripos($this->useragent, $this->mobi) > -1))
661            return $this->true; 
662         else
663            return $this->false; 
664      }
665      else
666         return $this->false; 
667   }
668
669   //**************************
670   // Detects if the current browser is Opera Mobile
671   // running on an Android phone.
672   function DetectOperaAndroidPhone()
673   {
674      if ((stripos($this->useragent, $this->engineOpera) > -1) &&
675        (stripos($this->useragent, $this->deviceAndroid) > -1) &&
676                (stripos($this->useragent, $this->mobi) > -1))
677         return $this->true; 
678      else
679         return $this->false; 
680   }
681
682   //**************************
683   // Detects if the current browser is Opera Mobile
684   // running on an Android tablet. 
685   function DetectOperaAndroidTablet()
686   {
687      if ((stripos($this->useragent, $this->engineOpera) > -1) &&
688        (stripos($this->useragent, $this->deviceAndroid) > -1) &&
689                (stripos($this->useragent, $this->deviceTablet) > -1))
690         return $this->true; 
691      else
692         return $this->false; 
693   }
694
695   //**************************
696   // Detects whether the device supports WAP or WML.
697   function DetectWapWml()
698   {
699       if (stripos($this->httpaccept, $this->vndwap) > -1 ||
700           stripos($this->httpaccept, $this->wml) > -1)
701         return $this->true; 
702      else
703         return $this->false; 
704   }
705   
706   //**************************
707   // Detects if the current device is an Amazon Kindle (eInk devices only).
708   // Note: For the Kindle Fire, use the normal Android methods.
709   function DetectKindle()
710   {
711      if (stripos($this->useragent, $this->deviceKindle) > -1 &&
712          DetectAndroid() == $this->false)
713         return $this->true; 
714      else
715         return $this->false; 
716   }
717   
718   
719   //**************************
720   // The quick way to detect for a mobile device.
721   //   Will probably detect most recent/current mid-tier Feature Phones
722   //   as well as smartphone-class devices. Excludes Apple iPads and other modern tablets.
723   function DetectMobileQuick()
724   {
725      //Let's exclude tablets
726      if ($this->isTierTablet == $this->true) 
727         return $this->false;
728
729      //Most mobile browsing is done on smartphones
730      if ($this->DetectSmartphone() == $this->true) 
731         return $this->true;
732
733      if (($this->DetectWapWml() == $this->true) 
734                        || ($this->DetectBrewDevice() == $this->true) 
735                        || ($this->DetectOperaMobile() == $this->true))
736         return $this->true;
737         
738      if ((stripos($this->useragent, $this->engineNetfront) > -1)
739                        || (stripos($this->useragent, $this->engineUpBrowser) > -1)
740                        || (stripos($this->useragent, $this->engineOpenWeb) > -1))
741         return $this->true; 
742         
743      if (($this->DetectDangerHiptop() == $this->true) 
744                        || ($this->DetectMidpCapable() == $this->true) 
745                        || ($this->DetectMaemoTablet() == $this->true) 
746                        || ($this->DetectArchos() == $this->true))
747         return $this->true; 
748
749       if ((stripos($this->useragent, $this->devicePda) > -1) &&
750                 !(stripos($this->useragent, $this->disUpdate) > -1))
751         return $this->true; 
752       if (stripos($this->useragent, $this->mobile) > -1)
753         return $this->true; 
754
755      else
756         return $this->false; 
757   }
758   
759   //**************************
760   // Detects if the current device is a Sony Playstation.
761   function DetectSonyPlaystation()
762   {
763      if (stripos($this->useragent, $this->devicePlaystation) > -1)
764         return $this->true; 
765      else
766         return $this->false; 
767   }
768
769   //**************************
770   // Detects if the current device is a Nintendo game device.
771   function DetectNintendo()
772   {
773      if (stripos($this->useragent, $this->deviceNintendo) > -1 || 
774           stripos($this->useragent, $this->deviceWii) > -1 ||
775           stripos($this->useragent, $this->deviceNintendoDs) > -1)
776         return $this->true; 
777      else
778         return $this->false; 
779   }
780
781   //**************************
782   // Detects if the current device is a Microsoft Xbox.
783   function DetectXbox()
784   {
785      if (stripos($this->useragent, $this->deviceXbox) > -1)
786         return $this->true; 
787      else
788         return $this->false; 
789   }
790   
791   //**************************
792   // Detects if the current device is an Internet-capable game console.
793   function DetectGameConsole()
794   {
795      if ($this->DetectSonyPlaystation() == $this->true) 
796         return $this->true; 
797      else if ($this->DetectNintendo() == $this->true) 
798         return $this->true; 
799      else if ($this->DetectXbox() == $this->true) 
800         return $this->true; 
801      else
802         return $this->false; 
803   }
804   
805   //**************************
806   // Detects if the current device supports MIDP, a mobile Java technology.
807   function DetectMidpCapable()
808   {
809       if (stripos($this->useragent, $this->deviceMidp) > -1 || 
810           stripos($this->httpaccept, $this->deviceMidp) > -1)
811         return $this->true; 
812      else
813         return $this->false; 
814   }
815   
816   //**************************
817   // Detects if the current device is on one of the Maemo-based Nokia Internet Tablets.
818   function DetectMaemoTablet()
819   {
820      if (stripos($this->useragent, $this->maemo) > -1)
821         return $this->true; 
822      //For Nokia N810, must be Linux + Tablet, or else it could be something else.
823      if ((stripos($this->useragent, $this->linux) > -1)
824                && (stripos($this->useragent, $this->deviceTablet) > -1) 
825                && ($this->DetectWebOSTablet() == $this->false)
826                && ($this->DetectAndroid() == $this->false))
827         return $this->true; 
828      else
829         return $this->false; 
830   }
831
832   //**************************
833   // Detects if the current device is an Archos media player/Internet tablet.
834   function DetectArchos()
835   {
836      if (stripos($this->useragent, $this->deviceArchos) > -1)
837         return $this->true; 
838      else
839         return $this->false; 
840   }
841
842   //**************************
843   // Detects if the current browser is a Sony Mylo device.
844   function DetectSonyMylo()
845   {
846      if (stripos($this->useragent, $this->manuSony) > -1)
847      {
848         if ((stripos($this->useragent, $this->qtembedded) > -1) ||
849          (stripos($this->useragent, $this->mylocom2) > -1))
850         {
851            return $this->true; 
852         }
853         else
854            return $this->false; 
855      }
856      else
857         return $this->false; 
858   }
859   
860 
861   //**************************
862   // The longer and more thorough way to detect for a mobile device.
863   //   Will probably detect most feature phones,
864   //   smartphone-class devices, Internet Tablets,
865   //   Internet-enabled game consoles, etc.
866   //   This ought to catch a lot of the more obscure and older devices, also --
867   //   but no promises on thoroughness!
868   function DetectMobileLong()
869   {
870      if ($this->DetectMobileQuick() == $this->true) 
871         return $this->true; 
872      if ($this->DetectGameConsole() == $this->true) 
873         return $this->true; 
874      if ($this->DetectSonyMylo() == $this->true) 
875         return $this->true; 
876
877       //Detect older phones from certain manufacturers and operators.
878       if (stripos($this->useragent, $this->uplink) > -1)
879         return $this->true; 
880       if (stripos($this->useragent, $this->manuSonyEricsson) > -1)
881         return $this->true; 
882       if (stripos($this->useragent, $this->manuericsson) > -1)
883         return $this->true; 
884
885       if (stripos($this->useragent, $this->manuSamsung1) > -1)
886         return $this->true; 
887       if (stripos($this->useragent, $this->svcDocomo) > -1)
888         return $this->true; 
889       if (stripos($this->useragent, $this->svcKddi) > -1)
890         return $this->true; 
891       if (stripos($this->useragent, $this->svcVodafone) > -1)
892         return $this->true; 
893
894      else
895         return $this->false; 
896   }
897
898
899
900  //*****************************
901  // For Mobile Web Site Design
902  //*****************************
903
904   //**************************
905   // The quick way to detect for a tier of devices.
906   //   This method detects for the new generation of
907   //   HTML 5 capable, larger screen tablets.
908   //   Includes iPad, Android (e.g., Xoom), BB Playbook, WebOS, etc.
909   function DetectTierTablet()
910   {
911      if (($this->DetectIpad() == $this->true) 
912         || ($this->DetectAndroidTablet() == $this->true) 
913         || ($this->DetectBlackBerryTablet() == $this->true) 
914         || ($this->DetectWebOSTablet() == $this->true))
915         return $this->true; 
916      else
917         return $this->false; 
918   }
919
920
921   //**************************
922   // The quick way to detect for a tier of devices.
923   //   This method detects for devices which can
924   //   display iPhone-optimized web content.
925   //   Includes iPhone, iPod Touch, Android, Windows Phone 7, WebOS, etc.
926   function DetectTierIphone()
927   {
928      if (($this->isIphone == $this->true) ||
929                        ($this->isAndroidPhone == $this->true))
930         return $this->true; 
931   
932      if (($this->DetectBlackBerryWebKit() == $this->true) &&
933                ($this->DetectBlackBerryTouch() == $this->true))
934         return $this->true; 
935      if ($this->DetectWindowsPhone7() == $this->true)
936         return $this->true; 
937      if ($this->DetectPalmWebOS() == $this->true) 
938         return $this->true; 
939      if ($this->DetectGarminNuvifone() == $this->true) 
940         return $this->true; 
941      else
942         return $this->false; 
943   }
944   
945   //**************************
946   // The quick way to detect for a tier of devices.
947   //   This method detects for devices which are likely to be capable
948   //   of viewing CSS content optimized for the iPhone,
949   //   but may not necessarily support JavaScript.
950   //   Excludes all iPhone Tier devices.
951   function DetectTierRichCss()
952   {
953      if ($this->DetectMobileQuick() == $this->true) 
954      {
955        if (($this->DetectTierIphone() == $this->true))
956           return $this->false;
957           
958        //The following devices are explicitly ok.
959        if ($this->DetectWebkit() == $this->true) //Any WebKit
960           return $this->true;
961        if ($this->DetectS60OssBrowser() == $this->true)
962           return $this->true;
963           
964        //Note: 'High' BlackBerry devices ONLY
965        if ($this->DetectBlackBerryHigh() == $this->true)
966           return $this->true;
967       
968        //Older Windows 'Mobile' isn't good enough for iPhone Tier.
969        if ($this->DetectWindowsMobile() == $this->true)
970           return $this->true;
971        if (stripos($this->useragent, $this->engineTelecaQ) > -1)
972           return $this->true; 
973           
974        //default
975        else
976           return $this->false;
977      }
978      else
979         return $this->false; 
980   }
981
982   //**************************
983   // The quick way to detect for a tier of devices.
984   //   This method detects for all other types of phones,
985   //   but excludes the iPhone and RichCSS Tier devices.
986   function DetectTierOtherPhones()
987   {
988      //Exclude devices in the other 2 categories
989      if (($this->DetectMobileLong() == $this->true)
990                && ($this->DetectTierIphone() == $this->false)
991                && ($this->DetectTierRichCss() == $this->false))
992           return $this->true;
993      else
994         return $this->false; 
995   }
996     
997
998}
999
1000?>
Note: See TracBrowser for help on using the repository browser.