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