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