1
|
|
|
<?php |
2
|
|
|
namespace SimpleCalendar; |
3
|
|
|
/** |
4
|
|
|
* File: Browser.php |
5
|
|
|
* Author: Chris Schuld (http://chrisschuld.com/) |
6
|
|
|
* Last Modified: July 4th, 2014 |
7
|
|
|
* @version 1.9 |
8
|
|
|
* @package PegasusPHP |
9
|
|
|
* |
10
|
|
|
* Copyright (C) 2008-2010 Chris Schuld ([email protected]) |
11
|
|
|
* |
12
|
|
|
* This program is free software; you can redistribute it and/or |
13
|
|
|
* modify it under the terms of the GNU General Public License as |
14
|
|
|
* published by the Free Software Foundation; either version 2 of |
15
|
|
|
* the License, or (at your option) any later version. |
16
|
|
|
* |
17
|
|
|
* This program is distributed in the hope that it will be useful, |
18
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
19
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
20
|
|
|
* GNU General Public License for more details at: |
21
|
|
|
* http://www.gnu.org/copyleft/gpl.html |
22
|
|
|
* |
23
|
|
|
* |
24
|
|
|
* Typical Usage: |
25
|
|
|
* |
26
|
|
|
* $browser = new Browser(); |
27
|
|
|
* if( $browser->getBrowser() == Browser::BROWSER_FIREFOX && $browser->getVersion() >= 2 ) { |
28
|
|
|
* echo 'You have FireFox version 2 or greater'; |
29
|
|
|
* } |
30
|
|
|
* |
31
|
|
|
* User Agents Sampled from: http://www.useragentstring.com/ |
32
|
|
|
* |
33
|
|
|
* This implementation is based on the original work from Gary White |
34
|
|
|
* http://apptools.com/phptools/browser/ |
35
|
|
|
* |
36
|
|
|
* |
37
|
|
|
* Modified Version by Moonstone Media |
38
|
|
|
* |
39
|
|
|
* Changelog: |
40
|
|
|
* - Changed class constructor from Browser() to __construct() |
41
|
|
|
*/ |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
|
45
|
|
|
class Browser |
46
|
|
|
{ |
47
|
|
|
private $_agent = ''; |
48
|
|
|
private $_browser_name = ''; |
49
|
|
|
private $_version = ''; |
50
|
|
|
private $_platform = ''; |
51
|
|
|
private $_os = ''; |
52
|
|
|
private $_is_aol = false; |
53
|
|
|
private $_is_mobile = false; |
54
|
|
|
private $_is_tablet = false; |
55
|
|
|
private $_is_robot = false; |
56
|
|
|
private $_is_facebook = false; |
57
|
|
|
private $_aol_version = ''; |
58
|
|
|
|
59
|
|
|
const BROWSER_UNKNOWN = 'unknown'; |
60
|
|
|
const VERSION_UNKNOWN = 'unknown'; |
61
|
|
|
|
62
|
|
|
const BROWSER_OPERA = 'Opera'; // http://www.opera.com/ |
63
|
|
|
const BROWSER_OPERA_MINI = 'Opera Mini'; // http://www.opera.com/mini/ |
64
|
|
|
const BROWSER_WEBTV = 'WebTV'; // http://www.webtv.net/pc/ |
65
|
|
|
const BROWSER_IE = 'Internet Explorer'; // http://www.microsoft.com/ie/ |
66
|
|
|
const BROWSER_POCKET_IE = 'Pocket Internet Explorer'; // http://en.wikipedia.org/wiki/Internet_Explorer_Mobile |
67
|
|
|
const BROWSER_KONQUEROR = 'Konqueror'; // http://www.konqueror.org/ |
68
|
|
|
const BROWSER_ICAB = 'iCab'; // http://www.icab.de/ |
69
|
|
|
const BROWSER_OMNIWEB = 'OmniWeb'; // http://www.omnigroup.com/applications/omniweb/ |
70
|
|
|
const BROWSER_FIREBIRD = 'Firebird'; // http://www.ibphoenix.com/ |
71
|
|
|
const BROWSER_FIREFOX = 'Firefox'; // http://www.mozilla.com/en-US/firefox/firefox.html |
72
|
|
|
const BROWSER_ICEWEASEL = 'Iceweasel'; // http://www.geticeweasel.org/ |
73
|
|
|
const BROWSER_SHIRETOKO = 'Shiretoko'; // http://wiki.mozilla.org/Projects/shiretoko |
74
|
|
|
const BROWSER_MOZILLA = 'Mozilla'; // http://www.mozilla.com/en-US/ |
75
|
|
|
const BROWSER_AMAYA = 'Amaya'; // http://www.w3.org/Amaya/ |
76
|
|
|
const BROWSER_LYNX = 'Lynx'; // http://en.wikipedia.org/wiki/Lynx |
77
|
|
|
const BROWSER_SAFARI = 'Safari'; // http://apple.com |
78
|
|
|
const BROWSER_IPHONE = 'iPhone'; // http://apple.com |
79
|
|
|
const BROWSER_IPOD = 'iPod'; // http://apple.com |
80
|
|
|
const BROWSER_IPAD = 'iPad'; // http://apple.com |
81
|
|
|
const BROWSER_CHROME = 'Chrome'; // http://www.google.com/chrome |
82
|
|
|
const BROWSER_ANDROID = 'Android'; // http://www.android.com/ |
83
|
|
|
const BROWSER_GOOGLEBOT = 'GoogleBot'; // http://en.wikipedia.org/wiki/Googlebot |
84
|
|
|
const BROWSER_SLURP = 'Yahoo! Slurp'; // http://en.wikipedia.org/wiki/Yahoo!_Slurp |
85
|
|
|
const BROWSER_W3CVALIDATOR = 'W3C Validator'; // http://validator.w3.org/ |
86
|
|
|
const BROWSER_BLACKBERRY = 'BlackBerry'; // http://www.blackberry.com/ |
87
|
|
|
const BROWSER_ICECAT = 'IceCat'; // http://en.wikipedia.org/wiki/GNU_IceCat |
88
|
|
|
const BROWSER_NOKIA_S60 = 'Nokia S60 OSS Browser'; // http://en.wikipedia.org/wiki/Web_Browser_for_S60 |
89
|
|
|
const BROWSER_NOKIA = 'Nokia Browser'; // * all other WAP-based browsers on the Nokia Platform |
90
|
|
|
const BROWSER_MSN = 'MSN Browser'; // http://explorer.msn.com/ |
91
|
|
|
const BROWSER_MSNBOT = 'MSN Bot'; // http://search.msn.com/msnbot.htm |
92
|
|
|
const BROWSER_BINGBOT = 'Bing Bot'; // http://en.wikipedia.org/wiki/Bingbot |
93
|
|
|
|
94
|
|
|
const BROWSER_NETSCAPE_NAVIGATOR = 'Netscape Navigator'; // http://browser.netscape.com/ (DEPRECATED) |
95
|
|
|
const BROWSER_GALEON = 'Galeon'; // http://galeon.sourceforge.net/ (DEPRECATED) |
96
|
|
|
const BROWSER_NETPOSITIVE = 'NetPositive'; // http://en.wikipedia.org/wiki/NetPositive (DEPRECATED) |
97
|
|
|
const BROWSER_PHOENIX = 'Phoenix'; // http://en.wikipedia.org/wiki/History_of_Mozilla_Firefox (DEPRECATED) |
98
|
|
|
|
99
|
|
|
const PLATFORM_UNKNOWN = 'unknown'; |
100
|
|
|
const PLATFORM_WINDOWS = 'Windows'; |
101
|
|
|
const PLATFORM_WINDOWS_CE = 'Windows CE'; |
102
|
|
|
const PLATFORM_APPLE = 'Apple'; |
103
|
|
|
const PLATFORM_LINUX = 'Linux'; |
104
|
|
|
const PLATFORM_OS2 = 'OS/2'; |
105
|
|
|
const PLATFORM_BEOS = 'BeOS'; |
106
|
|
|
const PLATFORM_IPHONE = 'iPhone'; |
107
|
|
|
const PLATFORM_IPOD = 'iPod'; |
108
|
|
|
const PLATFORM_IPAD = 'iPad'; |
109
|
|
|
const PLATFORM_BLACKBERRY = 'BlackBerry'; |
110
|
|
|
const PLATFORM_NOKIA = 'Nokia'; |
111
|
|
|
const PLATFORM_FREEBSD = 'FreeBSD'; |
112
|
|
|
const PLATFORM_OPENBSD = 'OpenBSD'; |
113
|
|
|
const PLATFORM_NETBSD = 'NetBSD'; |
114
|
|
|
const PLATFORM_SUNOS = 'SunOS'; |
115
|
|
|
const PLATFORM_OPENSOLARIS = 'OpenSolaris'; |
116
|
|
|
const PLATFORM_ANDROID = 'Android'; |
117
|
|
|
|
118
|
|
|
const OPERATING_SYSTEM_UNKNOWN = 'unknown'; |
119
|
|
|
|
120
|
|
|
public function __construct($userAgent = "") |
121
|
|
|
{ |
122
|
|
|
$this->reset(); |
123
|
|
|
if ($userAgent != "") { |
124
|
|
|
$this->setUserAgent($userAgent); |
125
|
|
|
} else { |
126
|
|
|
$this->determine(); |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Reset all properties |
132
|
|
|
*/ |
133
|
|
|
public function reset() |
|
|
|
|
134
|
|
|
{ |
135
|
|
|
$this->_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ""; |
136
|
|
|
$this->_browser_name = self::BROWSER_UNKNOWN; |
137
|
|
|
$this->_version = self::VERSION_UNKNOWN; |
138
|
|
|
$this->_platform = self::PLATFORM_UNKNOWN; |
139
|
|
|
$this->_os = self::OPERATING_SYSTEM_UNKNOWN; |
140
|
|
|
$this->_is_aol = false; |
141
|
|
|
$this->_is_mobile = false; |
142
|
|
|
$this->_is_tablet = false; |
143
|
|
|
$this->_is_robot = false; |
144
|
|
|
$this->_is_facebook = false; |
145
|
|
|
$this->_aol_version = self::VERSION_UNKNOWN; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Check to see if the specific browser is valid |
150
|
|
|
* @param string $browserName |
151
|
|
|
* @return bool True if the browser is the specified browser |
152
|
|
|
*/ |
153
|
|
|
function isBrowser($browserName) |
|
|
|
|
154
|
|
|
{ |
155
|
|
|
return (0 == strcasecmp($this->_browser_name, trim($browserName))); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* The name of the browser. All return types are from the class contants |
160
|
|
|
* @return string Name of the browser |
161
|
|
|
*/ |
162
|
|
|
public function getBrowser() |
163
|
|
|
{ |
164
|
|
|
return $this->_browser_name; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* Set the name of the browser |
169
|
|
|
* @param $browser string The name of the Browser |
170
|
|
|
*/ |
171
|
|
|
public function setBrowser($browser) |
172
|
|
|
{ |
173
|
|
|
$this->_browser_name = $browser; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* The name of the platform. All return types are from the class contants |
178
|
|
|
* @return string Name of the browser |
179
|
|
|
*/ |
180
|
|
|
public function getPlatform() |
181
|
|
|
{ |
182
|
|
|
return $this->_platform; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* Set the name of the platform |
187
|
|
|
* @param string $platform The name of the Platform |
188
|
|
|
*/ |
189
|
|
|
public function setPlatform($platform) |
190
|
|
|
{ |
191
|
|
|
$this->_platform = $platform; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* The version of the browser. |
196
|
|
|
* @return string Version of the browser (will only contain alpha-numeric characters and a period) |
197
|
|
|
*/ |
198
|
|
|
public function getVersion() |
199
|
|
|
{ |
200
|
|
|
return $this->_version; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* Set the version of the browser |
205
|
|
|
* @param string $version The version of the Browser |
206
|
|
|
*/ |
207
|
|
|
public function setVersion($version) |
208
|
|
|
{ |
209
|
|
|
$this->_version = preg_replace('/[^0-9,.,a-z,A-Z-]/', '', $version); |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* The version of AOL. |
214
|
|
|
* @return string Version of AOL (will only contain alpha-numeric characters and a period) |
215
|
|
|
*/ |
216
|
|
|
public function getAolVersion() |
217
|
|
|
{ |
218
|
|
|
return $this->_aol_version; |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* Set the version of AOL |
223
|
|
|
* @param string $version The version of AOL |
224
|
|
|
*/ |
225
|
|
|
public function setAolVersion($version) |
226
|
|
|
{ |
227
|
|
|
$this->_aol_version = preg_replace('/[^0-9,.,a-z,A-Z]/', '', $version); |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* Is the browser from AOL? |
232
|
|
|
* @return boolean True if the browser is from AOL otherwise false |
233
|
|
|
*/ |
234
|
|
|
public function isAol() |
235
|
|
|
{ |
236
|
|
|
return $this->_is_aol; |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
/** |
240
|
|
|
* Is the browser from a mobile device? |
241
|
|
|
* @return boolean True if the browser is from a mobile device otherwise false |
242
|
|
|
*/ |
243
|
|
|
public function isMobile() |
244
|
|
|
{ |
245
|
|
|
return $this->_is_mobile; |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* Is the browser from a tablet device? |
250
|
|
|
* @return boolean True if the browser is from a tablet device otherwise false |
251
|
|
|
*/ |
252
|
|
|
public function isTablet() |
253
|
|
|
{ |
254
|
|
|
return $this->_is_tablet; |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
/** |
258
|
|
|
* Is the browser from a robot (ex Slurp,GoogleBot)? |
259
|
|
|
* @return boolean True if the browser is from a robot otherwise false |
260
|
|
|
*/ |
261
|
|
|
public function isRobot() |
262
|
|
|
{ |
263
|
|
|
return $this->_is_robot; |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
/** |
267
|
|
|
* Is the browser from facebook? |
268
|
|
|
* @return boolean True if the browser is from facebook otherwise false |
269
|
|
|
*/ |
270
|
|
|
public function isFacebook() |
271
|
|
|
{ |
272
|
|
|
return $this->_is_facebook; |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
/** |
276
|
|
|
* Set the browser to be from AOL |
277
|
|
|
* @param $isAol |
278
|
|
|
*/ |
279
|
|
|
public function setAol($isAol) |
280
|
|
|
{ |
281
|
|
|
$this->_is_aol = $isAol; |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
/** |
285
|
|
|
* Set the Browser to be mobile |
286
|
|
|
* @param boolean $value is the browser a mobile browser or not |
287
|
|
|
*/ |
288
|
|
|
protected function setMobile($value = true) |
289
|
|
|
{ |
290
|
|
|
$this->_is_mobile = $value; |
291
|
|
|
} |
292
|
|
|
|
293
|
|
|
/** |
294
|
|
|
* Set the Browser to be tablet |
295
|
|
|
* @param boolean $value is the browser a tablet browser or not |
296
|
|
|
*/ |
297
|
|
|
protected function setTablet($value = true) |
298
|
|
|
{ |
299
|
|
|
$this->_is_tablet = $value; |
300
|
|
|
} |
301
|
|
|
|
302
|
|
|
/** |
303
|
|
|
* Set the Browser to be a robot |
304
|
|
|
* @param boolean $value is the browser a robot or not |
305
|
|
|
*/ |
306
|
|
|
protected function setRobot($value = true) |
307
|
|
|
{ |
308
|
|
|
$this->_is_robot = $value; |
309
|
|
|
} |
310
|
|
|
|
311
|
|
|
/** |
312
|
|
|
* Set the Browser to be a Facebook request |
313
|
|
|
* @param boolean $value is the browser a robot or not |
314
|
|
|
*/ |
315
|
|
|
protected function setFacebook($value = true) |
316
|
|
|
{ |
317
|
|
|
$this->_is_facebook = $value; |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
/** |
321
|
|
|
* Get the user agent value in use to determine the browser |
322
|
|
|
* @return string The user agent from the HTTP header |
323
|
|
|
*/ |
324
|
|
|
public function getUserAgent() |
325
|
|
|
{ |
326
|
|
|
return $this->_agent; |
327
|
|
|
} |
328
|
|
|
|
329
|
|
|
/** |
330
|
|
|
* Set the user agent value (the construction will use the HTTP header value - this will overwrite it) |
331
|
|
|
* @param string $agent_string The value for the User Agent |
332
|
|
|
*/ |
333
|
|
|
public function setUserAgent($agent_string) |
334
|
|
|
{ |
335
|
|
|
$this->reset(); |
336
|
|
|
$this->_agent = $agent_string; |
337
|
|
|
$this->determine(); |
338
|
|
|
} |
339
|
|
|
|
340
|
|
|
/** |
341
|
|
|
* Used to determine if the browser is actually "chromeframe" |
342
|
|
|
* @since 1.7 |
343
|
|
|
* @return boolean True if the browser is using chromeframe |
344
|
|
|
*/ |
345
|
|
|
public function isChromeFrame() |
346
|
|
|
{ |
347
|
|
|
return (strpos($this->_agent, "chromeframe") !== false); |
348
|
|
|
} |
349
|
|
|
|
350
|
|
|
/** |
351
|
|
|
* Returns a formatted string with a summary of the details of the browser. |
352
|
|
|
* @return string formatted string with a summary of the browser |
353
|
|
|
*/ |
354
|
|
|
public function __toString() |
355
|
|
|
{ |
356
|
|
|
return "<strong>Browser Name:</strong> {$this->getBrowser()}<br/>\n" . |
357
|
|
|
"<strong>Browser Version:</strong> {$this->getVersion()}<br/>\n" . |
358
|
|
|
"<strong>Browser User Agent String:</strong> {$this->getUserAgent()}<br/>\n" . |
359
|
|
|
"<strong>Platform:</strong> {$this->getPlatform()}<br/>"; |
360
|
|
|
} |
361
|
|
|
|
362
|
|
|
/** |
363
|
|
|
* Protected routine to calculate and determine what the browser is in use (including platform) |
364
|
|
|
*/ |
365
|
|
|
protected function determine() |
366
|
|
|
{ |
367
|
|
|
$this->checkPlatform(); |
368
|
|
|
$this->checkBrowsers(); |
369
|
|
|
$this->checkForAol(); |
370
|
|
|
} |
371
|
|
|
|
372
|
|
|
/** |
373
|
|
|
* Protected routine to determine the browser type |
374
|
|
|
* @return boolean True if the browser was detected otherwise false |
375
|
|
|
*/ |
376
|
|
|
protected function checkBrowsers() |
377
|
|
|
{ |
378
|
|
|
return ( |
379
|
|
|
// well-known, well-used |
380
|
|
|
// Special Notes: |
381
|
|
|
// (1) Opera must be checked before FireFox due to the odd |
382
|
|
|
// user agents used in some older versions of Opera |
383
|
|
|
// (2) WebTV is strapped onto Internet Explorer so we must |
384
|
|
|
// check for WebTV before IE |
385
|
|
|
// (3) (deprecated) Galeon is based on Firefox and needs to be |
386
|
|
|
// tested before Firefox is tested |
387
|
|
|
// (4) OmniWeb is based on Safari so OmniWeb check must occur |
388
|
|
|
// before Safari |
389
|
|
|
// (5) Netscape 9+ is based on Firefox so Netscape checks |
390
|
|
|
// before FireFox are necessary |
391
|
|
|
$this->checkBrowserWebTv() || |
392
|
|
|
$this->checkBrowserInternetExplorer() || |
393
|
|
|
$this->checkBrowserOpera() || |
394
|
|
|
$this->checkBrowserGaleon() || |
395
|
|
|
$this->checkBrowserNetscapeNavigator9Plus() || |
396
|
|
|
$this->checkBrowserFirefox() || |
397
|
|
|
$this->checkBrowserChrome() || |
398
|
|
|
$this->checkBrowserOmniWeb() || |
399
|
|
|
|
400
|
|
|
// common mobile |
401
|
|
|
$this->checkBrowserAndroid() || |
402
|
|
|
$this->checkBrowseriPad() || |
403
|
|
|
$this->checkBrowseriPod() || |
404
|
|
|
$this->checkBrowseriPhone() || |
405
|
|
|
$this->checkBrowserBlackBerry() || |
406
|
|
|
$this->checkBrowserNokia() || |
407
|
|
|
|
408
|
|
|
// common bots |
409
|
|
|
$this->checkBrowserGoogleBot() || |
410
|
|
|
$this->checkBrowserMSNBot() || |
411
|
|
|
$this->checkBrowserBingBot() || |
412
|
|
|
$this->checkBrowserSlurp() || |
413
|
|
|
|
414
|
|
|
// check for facebook external hit when loading URL |
415
|
|
|
$this->checkFacebookExternalHit() || |
416
|
|
|
|
417
|
|
|
// WebKit base check (post mobile and others) |
418
|
|
|
$this->checkBrowserSafari() || |
419
|
|
|
|
420
|
|
|
// everyone else |
421
|
|
|
$this->checkBrowserNetPositive() || |
422
|
|
|
$this->checkBrowserFirebird() || |
423
|
|
|
$this->checkBrowserKonqueror() || |
424
|
|
|
$this->checkBrowserIcab() || |
425
|
|
|
$this->checkBrowserPhoenix() || |
426
|
|
|
$this->checkBrowserAmaya() || |
427
|
|
|
$this->checkBrowserLynx() || |
428
|
|
|
$this->checkBrowserShiretoko() || |
429
|
|
|
$this->checkBrowserIceCat() || |
430
|
|
|
$this->checkBrowserIceweasel() || |
431
|
|
|
$this->checkBrowserW3CValidator() || |
432
|
|
|
$this->checkBrowserMozilla() /* Mozilla is such an open standard that you must check it last */ |
433
|
|
|
); |
434
|
|
|
} |
435
|
|
|
|
436
|
|
|
/** |
437
|
|
|
* Determine if the user is using a BlackBerry (last updated 1.7) |
438
|
|
|
* @return boolean True if the browser is the BlackBerry browser otherwise false |
439
|
|
|
*/ |
440
|
|
|
protected function checkBrowserBlackBerry() |
441
|
|
|
{ |
442
|
|
|
if (stripos($this->_agent, 'blackberry') !== false) { |
443
|
|
|
$aresult = explode("/", stristr($this->_agent, "BlackBerry")); |
444
|
|
|
if (isset($aresult[1])) { |
445
|
|
|
$aversion = explode(' ', $aresult[1]); |
446
|
|
|
$this->setVersion($aversion[0]); |
447
|
|
|
$this->_browser_name = self::BROWSER_BLACKBERRY; |
448
|
|
|
$this->setMobile(true); |
449
|
|
|
return true; |
450
|
|
|
} |
451
|
|
|
} |
452
|
|
|
return false; |
453
|
|
|
} |
454
|
|
|
|
455
|
|
|
/** |
456
|
|
|
* Determine if the user is using an AOL User Agent (last updated 1.7) |
457
|
|
|
* @return boolean True if the browser is from AOL otherwise false |
458
|
|
|
*/ |
459
|
|
|
protected function checkForAol() |
460
|
|
|
{ |
461
|
|
|
$this->setAol(false); |
462
|
|
|
$this->setAolVersion(self::VERSION_UNKNOWN); |
463
|
|
|
|
464
|
|
|
if (stripos($this->_agent, 'aol') !== false) { |
465
|
|
|
$aversion = explode(' ', stristr($this->_agent, 'AOL')); |
466
|
|
|
if (isset($aversion[1])) { |
467
|
|
|
$this->setAol(true); |
468
|
|
|
$this->setAolVersion(preg_replace('/[^0-9\.a-z]/i', '', $aversion[1])); |
469
|
|
|
return true; |
470
|
|
|
} |
471
|
|
|
} |
472
|
|
|
return false; |
473
|
|
|
} |
474
|
|
|
|
475
|
|
|
/** |
476
|
|
|
* Determine if the browser is the GoogleBot or not (last updated 1.7) |
477
|
|
|
* @return boolean True if the browser is the GoogletBot otherwise false |
478
|
|
|
*/ |
479
|
|
|
protected function checkBrowserGoogleBot() |
480
|
|
|
{ |
481
|
|
|
if (stripos($this->_agent, 'googlebot') !== false) { |
482
|
|
|
$aresult = explode('/', stristr($this->_agent, 'googlebot')); |
483
|
|
|
if (isset($aresult[1])) { |
484
|
|
|
$aversion = explode(' ', $aresult[1]); |
485
|
|
|
$this->setVersion(str_replace(';', '', $aversion[0])); |
486
|
|
|
$this->_browser_name = self::BROWSER_GOOGLEBOT; |
487
|
|
|
$this->setRobot(true); |
488
|
|
|
return true; |
489
|
|
|
} |
490
|
|
|
} |
491
|
|
|
return false; |
492
|
|
|
} |
493
|
|
|
|
494
|
|
|
/** |
495
|
|
|
* Determine if the browser is the MSNBot or not (last updated 1.9) |
496
|
|
|
* @return boolean True if the browser is the MSNBot otherwise false |
497
|
|
|
*/ |
498
|
|
|
protected function checkBrowserMSNBot() |
499
|
|
|
{ |
500
|
|
|
if (stripos($this->_agent, "msnbot") !== false) { |
501
|
|
|
$aresult = explode("/", stristr($this->_agent, "msnbot")); |
502
|
|
|
if (isset($aresult[1])) { |
503
|
|
|
$aversion = explode(" ", $aresult[1]); |
504
|
|
|
$this->setVersion(str_replace(";", "", $aversion[0])); |
505
|
|
|
$this->_browser_name = self::BROWSER_MSNBOT; |
506
|
|
|
$this->setRobot(true); |
507
|
|
|
return true; |
508
|
|
|
} |
509
|
|
|
} |
510
|
|
|
return false; |
511
|
|
|
} |
512
|
|
|
|
513
|
|
|
/** |
514
|
|
|
* Determine if the browser is the BingBot or not (last updated 1.9) |
515
|
|
|
* @return boolean True if the browser is the BingBot otherwise false |
516
|
|
|
*/ |
517
|
|
|
protected function checkBrowserBingBot() |
518
|
|
|
{ |
519
|
|
|
if (stripos($this->_agent, "bingbot") !== false) { |
520
|
|
|
$aresult = explode("/", stristr($this->_agent, "bingbot")); |
521
|
|
|
if (isset($aresult[1])) { |
522
|
|
|
$aversion = explode(" ", $aresult[1]); |
523
|
|
|
$this->setVersion(str_replace(";", "", $aversion[0])); |
524
|
|
|
$this->_browser_name = self::BROWSER_BINGBOT; |
525
|
|
|
$this->setRobot(true); |
526
|
|
|
return true; |
527
|
|
|
} |
528
|
|
|
} |
529
|
|
|
return false; |
530
|
|
|
} |
531
|
|
|
|
532
|
|
|
/** |
533
|
|
|
* Determine if the browser is the W3C Validator or not (last updated 1.7) |
534
|
|
|
* @return boolean True if the browser is the W3C Validator otherwise false |
535
|
|
|
*/ |
536
|
|
|
protected function checkBrowserW3CValidator() |
537
|
|
|
{ |
538
|
|
|
if (stripos($this->_agent, 'W3C-checklink') !== false) { |
539
|
|
|
$aresult = explode('/', stristr($this->_agent, 'W3C-checklink')); |
540
|
|
|
if (isset($aresult[1])) { |
541
|
|
|
$aversion = explode(' ', $aresult[1]); |
542
|
|
|
$this->setVersion($aversion[0]); |
543
|
|
|
$this->_browser_name = self::BROWSER_W3CVALIDATOR; |
544
|
|
|
return true; |
545
|
|
|
} |
546
|
|
|
} else if (stripos($this->_agent, 'W3C_Validator') !== false) { |
547
|
|
|
// Some of the Validator versions do not delineate w/ a slash - add it back in |
548
|
|
|
$ua = str_replace("W3C_Validator ", "W3C_Validator/", $this->_agent); |
549
|
|
|
$aresult = explode('/', stristr($ua, 'W3C_Validator')); |
550
|
|
|
if (isset($aresult[1])) { |
551
|
|
|
$aversion = explode(' ', $aresult[1]); |
552
|
|
|
$this->setVersion($aversion[0]); |
553
|
|
|
$this->_browser_name = self::BROWSER_W3CVALIDATOR; |
554
|
|
|
return true; |
555
|
|
|
} |
556
|
|
|
} else if (stripos($this->_agent, 'W3C-mobileOK') !== false) { |
557
|
|
|
$this->_browser_name = self::BROWSER_W3CVALIDATOR; |
558
|
|
|
$this->setMobile(true); |
559
|
|
|
return true; |
560
|
|
|
} |
561
|
|
|
return false; |
562
|
|
|
} |
563
|
|
|
|
564
|
|
|
/** |
565
|
|
|
* Determine if the browser is the Yahoo! Slurp Robot or not (last updated 1.7) |
566
|
|
|
* @return boolean True if the browser is the Yahoo! Slurp Robot otherwise false |
567
|
|
|
*/ |
568
|
|
|
protected function checkBrowserSlurp() |
569
|
|
|
{ |
570
|
|
|
if (stripos($this->_agent, 'slurp') !== false) { |
571
|
|
|
$aresult = explode('/', stristr($this->_agent, 'Slurp')); |
572
|
|
|
if (isset($aresult[1])) { |
573
|
|
|
$aversion = explode(' ', $aresult[1]); |
574
|
|
|
$this->setVersion($aversion[0]); |
575
|
|
|
$this->_browser_name = self::BROWSER_SLURP; |
576
|
|
|
$this->setRobot(true); |
577
|
|
|
$this->setMobile(false); |
578
|
|
|
return true; |
579
|
|
|
} |
580
|
|
|
} |
581
|
|
|
return false; |
582
|
|
|
} |
583
|
|
|
|
584
|
|
|
/** |
585
|
|
|
* Determine if the browser is Internet Explorer or not (last updated 1.7) |
586
|
|
|
* @return boolean True if the browser is Internet Explorer otherwise false |
587
|
|
|
*/ |
588
|
|
|
protected function checkBrowserInternetExplorer() |
589
|
|
|
{ |
590
|
|
|
// Test for IE11 |
591
|
|
|
if (stripos($this->_agent, 'Trident/7.0; rv:11.0') !== false) { |
592
|
|
|
$this->setBrowser(self::BROWSER_IE); |
593
|
|
|
$this->setVersion('11.0'); |
594
|
|
|
return true; |
595
|
|
|
} // Test for v1 - v1.5 IE |
596
|
|
|
else if (stripos($this->_agent, 'microsoft internet explorer') !== false) { |
597
|
|
|
$this->setBrowser(self::BROWSER_IE); |
598
|
|
|
$this->setVersion('1.0'); |
599
|
|
|
$aresult = stristr($this->_agent, '/'); |
600
|
|
|
if (preg_match('/308|425|426|474|0b1/i', $aresult)) { |
601
|
|
|
$this->setVersion('1.5'); |
602
|
|
|
} |
603
|
|
|
return true; |
604
|
|
|
} // Test for versions > 1.5 |
605
|
|
|
else if (stripos($this->_agent, 'msie') !== false && stripos($this->_agent, 'opera') === false) { |
606
|
|
|
// See if the browser is the odd MSN Explorer |
607
|
|
View Code Duplication |
if (stripos($this->_agent, 'msnb') !== false) { |
|
|
|
|
608
|
|
|
$aresult = explode(' ', stristr(str_replace(';', '; ', $this->_agent), 'MSN')); |
609
|
|
|
if (isset($aresult[1])) { |
610
|
|
|
$this->setBrowser(self::BROWSER_MSN); |
611
|
|
|
$this->setVersion(str_replace(array('(', ')', ';'), '', $aresult[1])); |
612
|
|
|
return true; |
613
|
|
|
} |
614
|
|
|
} |
615
|
|
|
$aresult = explode(' ', stristr(str_replace(';', '; ', $this->_agent), 'msie')); |
616
|
|
|
if (isset($aresult[1])) { |
617
|
|
|
$this->setBrowser(self::BROWSER_IE); |
618
|
|
|
$this->setVersion(str_replace(array('(', ')', ';'), '', $aresult[1])); |
619
|
|
|
if (stripos($this->_agent, 'IEMobile') !== false) { |
620
|
|
|
$this->setBrowser(self::BROWSER_POCKET_IE); |
621
|
|
|
$this->setMobile(true); |
622
|
|
|
} |
623
|
|
|
return true; |
624
|
|
|
} |
625
|
|
|
} // Test for versions > IE 10 |
626
|
|
|
else if (stripos($this->_agent, 'trident') !== false) { |
627
|
|
|
$this->setBrowser(self::BROWSER_IE); |
628
|
|
|
$result = explode('rv:', $this->_agent); |
629
|
|
|
if (isset($result[1])) { |
630
|
|
|
$this->setVersion(preg_replace('/[^0-9.]+/', '', $result[1])); |
631
|
|
|
$this->_agent = str_replace(array("Mozilla", "Gecko"), "MSIE", $this->_agent); |
632
|
|
|
} |
633
|
|
|
} // Test for Pocket IE |
634
|
|
|
else if (stripos($this->_agent, 'mspie') !== false || stripos($this->_agent, 'pocket') !== false) { |
635
|
|
|
$aresult = explode(' ', stristr($this->_agent, 'mspie')); |
636
|
|
|
if (isset($aresult[1])) { |
637
|
|
|
$this->setPlatform(self::PLATFORM_WINDOWS_CE); |
638
|
|
|
$this->setBrowser(self::BROWSER_POCKET_IE); |
639
|
|
|
$this->setMobile(true); |
640
|
|
|
|
641
|
|
|
if (stripos($this->_agent, 'mspie') !== false) { |
642
|
|
|
$this->setVersion($aresult[1]); |
643
|
|
|
} else { |
644
|
|
|
$aversion = explode('/', $this->_agent); |
645
|
|
|
if (isset($aversion[1])) { |
646
|
|
|
$this->setVersion($aversion[1]); |
647
|
|
|
} |
648
|
|
|
} |
649
|
|
|
return true; |
650
|
|
|
} |
651
|
|
|
} |
652
|
|
|
return false; |
653
|
|
|
} |
654
|
|
|
|
655
|
|
|
/** |
656
|
|
|
* Determine if the browser is Opera or not (last updated 1.7) |
657
|
|
|
* @return boolean True if the browser is Opera otherwise false |
658
|
|
|
*/ |
659
|
|
|
protected function checkBrowserOpera() |
660
|
|
|
{ |
661
|
|
|
if (stripos($this->_agent, 'opera mini') !== false) { |
662
|
|
|
$resultant = stristr($this->_agent, 'opera mini'); |
663
|
|
|
if (preg_match('/\//', $resultant)) { |
664
|
|
|
$aresult = explode('/', $resultant); |
665
|
|
|
if (isset($aresult[1])) { |
666
|
|
|
$aversion = explode(' ', $aresult[1]); |
667
|
|
|
$this->setVersion($aversion[0]); |
668
|
|
|
} |
669
|
|
|
} else { |
670
|
|
|
$aversion = explode(' ', stristr($resultant, 'opera mini')); |
671
|
|
|
if (isset($aversion[1])) { |
672
|
|
|
$this->setVersion($aversion[1]); |
673
|
|
|
} |
674
|
|
|
} |
675
|
|
|
$this->_browser_name = self::BROWSER_OPERA_MINI; |
676
|
|
|
$this->setMobile(true); |
677
|
|
|
return true; |
678
|
|
|
} else if (stripos($this->_agent, 'opera') !== false) { |
679
|
|
|
$resultant = stristr($this->_agent, 'opera'); |
680
|
|
|
if (preg_match('/Version\/(1*.*)$/', $resultant, $matches)) { |
681
|
|
|
$this->setVersion($matches[1]); |
682
|
|
|
} else if (preg_match('/\//', $resultant)) { |
683
|
|
|
$aresult = explode('/', str_replace("(", " ", $resultant)); |
684
|
|
|
if (isset($aresult[1])) { |
685
|
|
|
$aversion = explode(' ', $aresult[1]); |
686
|
|
|
$this->setVersion($aversion[0]); |
687
|
|
|
} |
688
|
|
|
} else { |
689
|
|
|
$aversion = explode(' ', stristr($resultant, 'opera')); |
690
|
|
|
$this->setVersion(isset($aversion[1]) ? $aversion[1] : ""); |
691
|
|
|
} |
692
|
|
|
if (stripos($this->_agent, 'Opera Mobi') !== false) { |
693
|
|
|
$this->setMobile(true); |
694
|
|
|
} |
695
|
|
|
$this->_browser_name = self::BROWSER_OPERA; |
696
|
|
|
return true; |
697
|
|
|
} else if (stripos($this->_agent, 'OPR') !== false) { |
698
|
|
|
$resultant = stristr($this->_agent, 'OPR'); |
699
|
|
|
if (preg_match('/\//', $resultant)) { |
700
|
|
|
$aresult = explode('/', str_replace("(", " ", $resultant)); |
701
|
|
|
if (isset($aresult[1])) { |
702
|
|
|
$aversion = explode(' ', $aresult[1]); |
703
|
|
|
$this->setVersion($aversion[0]); |
704
|
|
|
} |
705
|
|
|
} |
706
|
|
|
if (stripos($this->_agent, 'Mobile') !== false) { |
707
|
|
|
$this->setMobile(true); |
708
|
|
|
} |
709
|
|
|
$this->_browser_name = self::BROWSER_OPERA; |
710
|
|
|
return true; |
711
|
|
|
} |
712
|
|
|
return false; |
713
|
|
|
} |
714
|
|
|
|
715
|
|
|
/** |
716
|
|
|
* Determine if the browser is Chrome or not (last updated 1.7) |
717
|
|
|
* @return boolean True if the browser is Chrome otherwise false |
718
|
|
|
*/ |
719
|
|
|
protected function checkBrowserChrome() |
720
|
|
|
{ |
721
|
|
|
if (stripos($this->_agent, 'Chrome') !== false) { |
722
|
|
|
$aresult = explode('/', stristr($this->_agent, 'Chrome')); |
723
|
|
|
if (isset($aresult[1])) { |
724
|
|
|
$aversion = explode(' ', $aresult[1]); |
725
|
|
|
$this->setVersion($aversion[0]); |
726
|
|
|
$this->setBrowser(self::BROWSER_CHROME); |
727
|
|
|
//Chrome on Android |
728
|
|
View Code Duplication |
if (stripos($this->_agent, 'Android') !== false) { |
|
|
|
|
729
|
|
|
if (stripos($this->_agent, 'Mobile') !== false) { |
730
|
|
|
$this->setMobile(true); |
731
|
|
|
} else { |
732
|
|
|
$this->setTablet(true); |
733
|
|
|
} |
734
|
|
|
} |
735
|
|
|
return true; |
736
|
|
|
} |
737
|
|
|
} |
738
|
|
|
return false; |
739
|
|
|
} |
740
|
|
|
|
741
|
|
|
|
742
|
|
|
/** |
743
|
|
|
* Determine if the browser is WebTv or not (last updated 1.7) |
744
|
|
|
* @return boolean True if the browser is WebTv otherwise false |
745
|
|
|
*/ |
746
|
|
View Code Duplication |
protected function checkBrowserWebTv() |
|
|
|
|
747
|
|
|
{ |
748
|
|
|
if (stripos($this->_agent, 'webtv') !== false) { |
749
|
|
|
$aresult = explode('/', stristr($this->_agent, 'webtv')); |
750
|
|
|
if (isset($aresult[1])) { |
751
|
|
|
$aversion = explode(' ', $aresult[1]); |
752
|
|
|
$this->setVersion($aversion[0]); |
753
|
|
|
$this->setBrowser(self::BROWSER_WEBTV); |
754
|
|
|
return true; |
755
|
|
|
} |
756
|
|
|
} |
757
|
|
|
return false; |
758
|
|
|
} |
759
|
|
|
|
760
|
|
|
/** |
761
|
|
|
* Determine if the browser is NetPositive or not (last updated 1.7) |
762
|
|
|
* @return boolean True if the browser is NetPositive otherwise false |
763
|
|
|
*/ |
764
|
|
|
protected function checkBrowserNetPositive() |
765
|
|
|
{ |
766
|
|
View Code Duplication |
if (stripos($this->_agent, 'NetPositive') !== false) { |
|
|
|
|
767
|
|
|
$aresult = explode('/', stristr($this->_agent, 'NetPositive')); |
768
|
|
|
if (isset($aresult[1])) { |
769
|
|
|
$aversion = explode(' ', $aresult[1]); |
770
|
|
|
$this->setVersion(str_replace(array('(', ')', ';'), '', $aversion[0])); |
771
|
|
|
$this->setBrowser(self::BROWSER_NETPOSITIVE); |
772
|
|
|
return true; |
773
|
|
|
} |
774
|
|
|
} |
775
|
|
|
return false; |
776
|
|
|
} |
777
|
|
|
|
778
|
|
|
/** |
779
|
|
|
* Determine if the browser is Galeon or not (last updated 1.7) |
780
|
|
|
* @return boolean True if the browser is Galeon otherwise false |
781
|
|
|
*/ |
782
|
|
View Code Duplication |
protected function checkBrowserGaleon() |
|
|
|
|
783
|
|
|
{ |
784
|
|
|
if (stripos($this->_agent, 'galeon') !== false) { |
785
|
|
|
$aresult = explode(' ', stristr($this->_agent, 'galeon')); |
786
|
|
|
$aversion = explode('/', $aresult[0]); |
787
|
|
|
if (isset($aversion[1])) { |
788
|
|
|
$this->setVersion($aversion[1]); |
789
|
|
|
$this->setBrowser(self::BROWSER_GALEON); |
790
|
|
|
return true; |
791
|
|
|
} |
792
|
|
|
} |
793
|
|
|
return false; |
794
|
|
|
} |
795
|
|
|
|
796
|
|
|
/** |
797
|
|
|
* Determine if the browser is Konqueror or not (last updated 1.7) |
798
|
|
|
* @return boolean True if the browser is Konqueror otherwise false |
799
|
|
|
*/ |
800
|
|
View Code Duplication |
protected function checkBrowserKonqueror() |
|
|
|
|
801
|
|
|
{ |
802
|
|
|
if (stripos($this->_agent, 'Konqueror') !== false) { |
803
|
|
|
$aresult = explode(' ', stristr($this->_agent, 'Konqueror')); |
804
|
|
|
$aversion = explode('/', $aresult[0]); |
805
|
|
|
if (isset($aversion[1])) { |
806
|
|
|
$this->setVersion($aversion[1]); |
807
|
|
|
$this->setBrowser(self::BROWSER_KONQUEROR); |
808
|
|
|
return true; |
809
|
|
|
} |
810
|
|
|
} |
811
|
|
|
return false; |
812
|
|
|
} |
813
|
|
|
|
814
|
|
|
/** |
815
|
|
|
* Determine if the browser is iCab or not (last updated 1.7) |
816
|
|
|
* @return boolean True if the browser is iCab otherwise false |
817
|
|
|
*/ |
818
|
|
View Code Duplication |
protected function checkBrowserIcab() |
|
|
|
|
819
|
|
|
{ |
820
|
|
|
if (stripos($this->_agent, 'icab') !== false) { |
821
|
|
|
$aversion = explode(' ', stristr(str_replace('/', ' ', $this->_agent), 'icab')); |
822
|
|
|
if (isset($aversion[1])) { |
823
|
|
|
$this->setVersion($aversion[1]); |
824
|
|
|
$this->setBrowser(self::BROWSER_ICAB); |
825
|
|
|
return true; |
826
|
|
|
} |
827
|
|
|
} |
828
|
|
|
return false; |
829
|
|
|
} |
830
|
|
|
|
831
|
|
|
/** |
832
|
|
|
* Determine if the browser is OmniWeb or not (last updated 1.7) |
833
|
|
|
* @return boolean True if the browser is OmniWeb otherwise false |
834
|
|
|
*/ |
835
|
|
View Code Duplication |
protected function checkBrowserOmniWeb() |
|
|
|
|
836
|
|
|
{ |
837
|
|
|
if (stripos($this->_agent, 'omniweb') !== false) { |
838
|
|
|
$aresult = explode('/', stristr($this->_agent, 'omniweb')); |
839
|
|
|
$aversion = explode(' ', isset($aresult[1]) ? $aresult[1] : ""); |
840
|
|
|
$this->setVersion($aversion[0]); |
841
|
|
|
$this->setBrowser(self::BROWSER_OMNIWEB); |
842
|
|
|
return true; |
843
|
|
|
} |
844
|
|
|
return false; |
845
|
|
|
} |
846
|
|
|
|
847
|
|
|
/** |
848
|
|
|
* Determine if the browser is Phoenix or not (last updated 1.7) |
849
|
|
|
* @return boolean True if the browser is Phoenix otherwise false |
850
|
|
|
*/ |
851
|
|
View Code Duplication |
protected function checkBrowserPhoenix() |
|
|
|
|
852
|
|
|
{ |
853
|
|
|
if (stripos($this->_agent, 'Phoenix') !== false) { |
854
|
|
|
$aversion = explode('/', stristr($this->_agent, 'Phoenix')); |
855
|
|
|
if (isset($aversion[1])) { |
856
|
|
|
$this->setVersion($aversion[1]); |
857
|
|
|
$this->setBrowser(self::BROWSER_PHOENIX); |
858
|
|
|
return true; |
859
|
|
|
} |
860
|
|
|
} |
861
|
|
|
return false; |
862
|
|
|
} |
863
|
|
|
|
864
|
|
|
/** |
865
|
|
|
* Determine if the browser is Firebird or not (last updated 1.7) |
866
|
|
|
* @return boolean True if the browser is Firebird otherwise false |
867
|
|
|
*/ |
868
|
|
View Code Duplication |
protected function checkBrowserFirebird() |
|
|
|
|
869
|
|
|
{ |
870
|
|
|
if (stripos($this->_agent, 'Firebird') !== false) { |
871
|
|
|
$aversion = explode('/', stristr($this->_agent, 'Firebird')); |
872
|
|
|
if (isset($aversion[1])) { |
873
|
|
|
$this->setVersion($aversion[1]); |
874
|
|
|
$this->setBrowser(self::BROWSER_FIREBIRD); |
875
|
|
|
return true; |
876
|
|
|
} |
877
|
|
|
} |
878
|
|
|
return false; |
879
|
|
|
} |
880
|
|
|
|
881
|
|
|
/** |
882
|
|
|
* Determine if the browser is Netscape Navigator 9+ or not (last updated 1.7) |
883
|
|
|
* NOTE: (http://browser.netscape.com/ - Official support ended on March 1st, 2008) |
884
|
|
|
* @return boolean True if the browser is Netscape Navigator 9+ otherwise false |
885
|
|
|
*/ |
886
|
|
|
protected function checkBrowserNetscapeNavigator9Plus() |
887
|
|
|
{ |
888
|
|
|
if (stripos($this->_agent, 'Firefox') !== false && preg_match('/Navigator\/([^ ]*)/i', $this->_agent, $matches)) { |
889
|
|
|
$this->setVersion($matches[1]); |
890
|
|
|
$this->setBrowser(self::BROWSER_NETSCAPE_NAVIGATOR); |
891
|
|
|
return true; |
892
|
|
|
} else if (stripos($this->_agent, 'Firefox') === false && preg_match('/Netscape6?\/([^ ]*)/i', $this->_agent, $matches)) { |
893
|
|
|
$this->setVersion($matches[1]); |
894
|
|
|
$this->setBrowser(self::BROWSER_NETSCAPE_NAVIGATOR); |
895
|
|
|
return true; |
896
|
|
|
} |
897
|
|
|
return false; |
898
|
|
|
} |
899
|
|
|
|
900
|
|
|
/** |
901
|
|
|
* Determine if the browser is Shiretoko or not (https://wiki.mozilla.org/Projects/shiretoko) (last updated 1.7) |
902
|
|
|
* @return boolean True if the browser is Shiretoko otherwise false |
903
|
|
|
*/ |
904
|
|
View Code Duplication |
protected function checkBrowserShiretoko() |
|
|
|
|
905
|
|
|
{ |
906
|
|
|
if (stripos($this->_agent, 'Mozilla') !== false && preg_match('/Shiretoko\/([^ ]*)/i', $this->_agent, $matches)) { |
907
|
|
|
$this->setVersion($matches[1]); |
908
|
|
|
$this->setBrowser(self::BROWSER_SHIRETOKO); |
909
|
|
|
return true; |
910
|
|
|
} |
911
|
|
|
return false; |
912
|
|
|
} |
913
|
|
|
|
914
|
|
|
/** |
915
|
|
|
* Determine if the browser is Ice Cat or not (http://en.wikipedia.org/wiki/GNU_IceCat) (last updated 1.7) |
916
|
|
|
* @return boolean True if the browser is Ice Cat otherwise false |
917
|
|
|
*/ |
918
|
|
View Code Duplication |
protected function checkBrowserIceCat() |
|
|
|
|
919
|
|
|
{ |
920
|
|
|
if (stripos($this->_agent, 'Mozilla') !== false && preg_match('/IceCat\/([^ ]*)/i', $this->_agent, $matches)) { |
921
|
|
|
$this->setVersion($matches[1]); |
922
|
|
|
$this->setBrowser(self::BROWSER_ICECAT); |
923
|
|
|
return true; |
924
|
|
|
} |
925
|
|
|
return false; |
926
|
|
|
} |
927
|
|
|
|
928
|
|
|
/** |
929
|
|
|
* Determine if the browser is Nokia or not (last updated 1.7) |
930
|
|
|
* @return boolean True if the browser is Nokia otherwise false |
931
|
|
|
*/ |
932
|
|
|
protected function checkBrowserNokia() |
933
|
|
|
{ |
934
|
|
|
if (preg_match("/Nokia([^\/]+)\/([^ SP]+)/i", $this->_agent, $matches)) { |
935
|
|
|
$this->setVersion($matches[2]); |
936
|
|
|
if (stripos($this->_agent, 'Series60') !== false || strpos($this->_agent, 'S60') !== false) { |
937
|
|
|
$this->setBrowser(self::BROWSER_NOKIA_S60); |
938
|
|
|
} else { |
939
|
|
|
$this->setBrowser(self::BROWSER_NOKIA); |
940
|
|
|
} |
941
|
|
|
$this->setMobile(true); |
942
|
|
|
return true; |
943
|
|
|
} |
944
|
|
|
return false; |
945
|
|
|
} |
946
|
|
|
|
947
|
|
|
/** |
948
|
|
|
* Determine if the browser is Firefox or not (last updated 1.7) |
949
|
|
|
* @return boolean True if the browser is Firefox otherwise false |
950
|
|
|
*/ |
951
|
|
|
protected function checkBrowserFirefox() |
952
|
|
|
{ |
953
|
|
|
if (stripos($this->_agent, 'safari') === false) { |
954
|
|
|
if (preg_match("/Firefox[\/ \(]([^ ;\)]+)/i", $this->_agent, $matches)) { |
955
|
|
|
$this->setVersion($matches[1]); |
956
|
|
|
$this->setBrowser(self::BROWSER_FIREFOX); |
957
|
|
|
//Firefox on Android |
958
|
|
View Code Duplication |
if (stripos($this->_agent, 'Android') !== false) { |
|
|
|
|
959
|
|
|
if (stripos($this->_agent, 'Mobile') !== false) { |
960
|
|
|
$this->setMobile(true); |
961
|
|
|
} else { |
962
|
|
|
$this->setTablet(true); |
963
|
|
|
} |
964
|
|
|
} |
965
|
|
|
return true; |
966
|
|
|
} else if (preg_match("/Firefox$/i", $this->_agent, $matches)) { |
967
|
|
|
$this->setVersion(""); |
968
|
|
|
$this->setBrowser(self::BROWSER_FIREFOX); |
969
|
|
|
return true; |
970
|
|
|
} |
971
|
|
|
} |
972
|
|
|
return false; |
973
|
|
|
} |
974
|
|
|
|
975
|
|
|
/** |
976
|
|
|
* Determine if the browser is Firefox or not (last updated 1.7) |
977
|
|
|
* @return boolean True if the browser is Firefox otherwise false |
978
|
|
|
*/ |
979
|
|
View Code Duplication |
protected function checkBrowserIceweasel() |
|
|
|
|
980
|
|
|
{ |
981
|
|
|
if (stripos($this->_agent, 'Iceweasel') !== false) { |
982
|
|
|
$aresult = explode('/', stristr($this->_agent, 'Iceweasel')); |
983
|
|
|
if (isset($aresult[1])) { |
984
|
|
|
$aversion = explode(' ', $aresult[1]); |
985
|
|
|
$this->setVersion($aversion[0]); |
986
|
|
|
$this->setBrowser(self::BROWSER_ICEWEASEL); |
987
|
|
|
return true; |
988
|
|
|
} |
989
|
|
|
} |
990
|
|
|
return false; |
991
|
|
|
} |
992
|
|
|
|
993
|
|
|
/** |
994
|
|
|
* Determine if the browser is Mozilla or not (last updated 1.7) |
995
|
|
|
* @return boolean True if the browser is Mozilla otherwise false |
996
|
|
|
*/ |
997
|
|
|
protected function checkBrowserMozilla() |
998
|
|
|
{ |
999
|
|
|
if (stripos($this->_agent, 'mozilla') !== false && preg_match('/rv:[0-9].[0-9][a-b]?/i', $this->_agent) && stripos($this->_agent, 'netscape') === false) { |
1000
|
|
|
$aversion = explode(' ', stristr($this->_agent, 'rv:')); |
1001
|
|
|
preg_match('/rv:[0-9].[0-9][a-b]?/i', $this->_agent, $aversion); |
1002
|
|
|
$this->setVersion(str_replace('rv:', '', $aversion[0])); |
1003
|
|
|
$this->setBrowser(self::BROWSER_MOZILLA); |
1004
|
|
|
return true; |
1005
|
|
|
} else if (stripos($this->_agent, 'mozilla') !== false && preg_match('/rv:[0-9]\.[0-9]/i', $this->_agent) && stripos($this->_agent, 'netscape') === false) { |
1006
|
|
|
$aversion = explode('', stristr($this->_agent, 'rv:')); |
1007
|
|
|
$this->setVersion(str_replace('rv:', '', $aversion[0])); |
1008
|
|
|
$this->setBrowser(self::BROWSER_MOZILLA); |
1009
|
|
|
return true; |
1010
|
|
|
} else if (stripos($this->_agent, 'mozilla') !== false && preg_match('/mozilla\/([^ ]*)/i', $this->_agent, $matches) && stripos($this->_agent, 'netscape') === false) { |
1011
|
|
|
$this->setVersion($matches[1]); |
1012
|
|
|
$this->setBrowser(self::BROWSER_MOZILLA); |
1013
|
|
|
return true; |
1014
|
|
|
} |
1015
|
|
|
return false; |
1016
|
|
|
} |
1017
|
|
|
|
1018
|
|
|
/** |
1019
|
|
|
* Determine if the browser is Lynx or not (last updated 1.7) |
1020
|
|
|
* @return boolean True if the browser is Lynx otherwise false |
1021
|
|
|
*/ |
1022
|
|
View Code Duplication |
protected function checkBrowserLynx() |
|
|
|
|
1023
|
|
|
{ |
1024
|
|
|
if (stripos($this->_agent, 'lynx') !== false) { |
1025
|
|
|
$aresult = explode('/', stristr($this->_agent, 'Lynx')); |
1026
|
|
|
$aversion = explode(' ', (isset($aresult[1]) ? $aresult[1] : "")); |
1027
|
|
|
$this->setVersion($aversion[0]); |
1028
|
|
|
$this->setBrowser(self::BROWSER_LYNX); |
1029
|
|
|
return true; |
1030
|
|
|
} |
1031
|
|
|
return false; |
1032
|
|
|
} |
1033
|
|
|
|
1034
|
|
|
/** |
1035
|
|
|
* Determine if the browser is Amaya or not (last updated 1.7) |
1036
|
|
|
* @return boolean True if the browser is Amaya otherwise false |
1037
|
|
|
*/ |
1038
|
|
View Code Duplication |
protected function checkBrowserAmaya() |
|
|
|
|
1039
|
|
|
{ |
1040
|
|
|
if (stripos($this->_agent, 'amaya') !== false) { |
1041
|
|
|
$aresult = explode('/', stristr($this->_agent, 'Amaya')); |
1042
|
|
|
if (isset($aresult[1])) { |
1043
|
|
|
$aversion = explode(' ', $aresult[1]); |
1044
|
|
|
$this->setVersion($aversion[0]); |
1045
|
|
|
$this->setBrowser(self::BROWSER_AMAYA); |
1046
|
|
|
return true; |
1047
|
|
|
} |
1048
|
|
|
} |
1049
|
|
|
return false; |
1050
|
|
|
} |
1051
|
|
|
|
1052
|
|
|
/** |
1053
|
|
|
* Determine if the browser is Safari or not (last updated 1.7) |
1054
|
|
|
* @return boolean True if the browser is Safari otherwise false |
1055
|
|
|
*/ |
1056
|
|
|
protected function checkBrowserSafari() |
1057
|
|
|
{ |
1058
|
|
|
if (stripos($this->_agent, 'Safari') !== false |
1059
|
|
|
&& stripos($this->_agent, 'iPhone') === false |
1060
|
|
|
&& stripos($this->_agent, 'iPod') === false |
1061
|
|
|
) { |
1062
|
|
|
|
1063
|
|
|
$aresult = explode('/', stristr($this->_agent, 'Version')); |
1064
|
|
|
if (isset($aresult[1])) { |
1065
|
|
|
$aversion = explode(' ', $aresult[1]); |
1066
|
|
|
$this->setVersion($aversion[0]); |
1067
|
|
|
} else { |
1068
|
|
|
$this->setVersion(self::VERSION_UNKNOWN); |
1069
|
|
|
} |
1070
|
|
|
$this->setBrowser(self::BROWSER_SAFARI); |
1071
|
|
|
return true; |
1072
|
|
|
} |
1073
|
|
|
return false; |
1074
|
|
|
} |
1075
|
|
|
|
1076
|
|
|
/** |
1077
|
|
|
* Detect if URL is loaded from FacebookExternalHit |
1078
|
|
|
* @return boolean True if it detects FacebookExternalHit otherwise false |
1079
|
|
|
*/ |
1080
|
|
|
protected function checkFacebookExternalHit() |
1081
|
|
|
{ |
1082
|
|
|
if (stristr($this->_agent, 'FacebookExternalHit')) { |
1083
|
|
|
$this->setRobot(true); |
1084
|
|
|
$this->setFacebook(true); |
1085
|
|
|
return true; |
1086
|
|
|
} |
1087
|
|
|
return false; |
1088
|
|
|
} |
1089
|
|
|
|
1090
|
|
|
/** |
1091
|
|
|
* Detect if URL is being loaded from internal Facebook browser |
1092
|
|
|
* @return boolean True if it detects internal Facebook browser otherwise false |
1093
|
|
|
*/ |
1094
|
|
|
protected function checkForFacebookIos() |
1095
|
|
|
{ |
1096
|
|
|
if (stristr($this->_agent, 'FBIOS')) { |
1097
|
|
|
$this->setFacebook(true); |
1098
|
|
|
return true; |
1099
|
|
|
} |
1100
|
|
|
return false; |
1101
|
|
|
} |
1102
|
|
|
|
1103
|
|
|
/** |
1104
|
|
|
* Detect Version for the Safari browser on iOS devices |
1105
|
|
|
* @return boolean True if it detects the version correctly otherwise false |
1106
|
|
|
*/ |
1107
|
|
View Code Duplication |
protected function getSafariVersionOnIos() |
|
|
|
|
1108
|
|
|
{ |
1109
|
|
|
$aresult = explode('/', stristr($this->_agent, 'Version')); |
1110
|
|
|
if (isset($aresult[1])) { |
1111
|
|
|
$aversion = explode(' ', $aresult[1]); |
1112
|
|
|
$this->setVersion($aversion[0]); |
1113
|
|
|
return true; |
1114
|
|
|
} |
1115
|
|
|
return false; |
1116
|
|
|
} |
1117
|
|
|
|
1118
|
|
|
/** |
1119
|
|
|
* Detect Version for the Chrome browser on iOS devices |
1120
|
|
|
* @return boolean True if it detects the version correctly otherwise false |
1121
|
|
|
*/ |
1122
|
|
View Code Duplication |
protected function getChromeVersionOnIos() |
|
|
|
|
1123
|
|
|
{ |
1124
|
|
|
$aresult = explode('/', stristr($this->_agent, 'CriOS')); |
1125
|
|
|
if (isset($aresult[1])) { |
1126
|
|
|
$aversion = explode(' ', $aresult[1]); |
1127
|
|
|
$this->setVersion($aversion[0]); |
1128
|
|
|
$this->setBrowser(self::BROWSER_CHROME); |
1129
|
|
|
return true; |
1130
|
|
|
} |
1131
|
|
|
return false; |
1132
|
|
|
} |
1133
|
|
|
|
1134
|
|
|
/** |
1135
|
|
|
* Determine if the browser is iPhone or not (last updated 1.7) |
1136
|
|
|
* @return boolean True if the browser is iPhone otherwise false |
1137
|
|
|
*/ |
1138
|
|
View Code Duplication |
protected function checkBrowseriPhone() |
|
|
|
|
1139
|
|
|
{ |
1140
|
|
|
if (stripos($this->_agent, 'iPhone') !== false) { |
1141
|
|
|
$this->setVersion(self::VERSION_UNKNOWN); |
1142
|
|
|
$this->setBrowser(self::BROWSER_IPHONE); |
1143
|
|
|
$this->getSafariVersionOnIos(); |
1144
|
|
|
$this->getChromeVersionOnIos(); |
1145
|
|
|
$this->checkForFacebookIos(); |
1146
|
|
|
$this->setMobile(true); |
1147
|
|
|
return true; |
1148
|
|
|
} |
1149
|
|
|
return false; |
1150
|
|
|
} |
1151
|
|
|
|
1152
|
|
|
/** |
1153
|
|
|
* Determine if the browser is iPad or not (last updated 1.7) |
1154
|
|
|
* @return boolean True if the browser is iPad otherwise false |
1155
|
|
|
*/ |
1156
|
|
View Code Duplication |
protected function checkBrowseriPad() |
|
|
|
|
1157
|
|
|
{ |
1158
|
|
|
if (stripos($this->_agent, 'iPad') !== false) { |
1159
|
|
|
$this->setVersion(self::VERSION_UNKNOWN); |
1160
|
|
|
$this->setBrowser(self::BROWSER_IPAD); |
1161
|
|
|
$this->getSafariVersionOnIos(); |
1162
|
|
|
$this->getChromeVersionOnIos(); |
1163
|
|
|
$this->checkForFacebookIos(); |
1164
|
|
|
$this->setTablet(true); |
1165
|
|
|
return true; |
1166
|
|
|
} |
1167
|
|
|
return false; |
1168
|
|
|
} |
1169
|
|
|
|
1170
|
|
|
/** |
1171
|
|
|
* Determine if the browser is iPod or not (last updated 1.7) |
1172
|
|
|
* @return boolean True if the browser is iPod otherwise false |
1173
|
|
|
*/ |
1174
|
|
View Code Duplication |
protected function checkBrowseriPod() |
|
|
|
|
1175
|
|
|
{ |
1176
|
|
|
if (stripos($this->_agent, 'iPod') !== false) { |
1177
|
|
|
$this->setVersion(self::VERSION_UNKNOWN); |
1178
|
|
|
$this->setBrowser(self::BROWSER_IPOD); |
1179
|
|
|
$this->getSafariVersionOnIos(); |
1180
|
|
|
$this->getChromeVersionOnIos(); |
1181
|
|
|
$this->checkForFacebookIos(); |
1182
|
|
|
$this->setMobile(true); |
1183
|
|
|
return true; |
1184
|
|
|
} |
1185
|
|
|
return false; |
1186
|
|
|
} |
1187
|
|
|
|
1188
|
|
|
/** |
1189
|
|
|
* Determine if the browser is Android or not (last updated 1.7) |
1190
|
|
|
* @return boolean True if the browser is Android otherwise false |
1191
|
|
|
*/ |
1192
|
|
|
protected function checkBrowserAndroid() |
1193
|
|
|
{ |
1194
|
|
|
if (stripos($this->_agent, 'Android') !== false) { |
1195
|
|
|
$aresult = explode(' ', stristr($this->_agent, 'Android')); |
1196
|
|
|
if (isset($aresult[1])) { |
1197
|
|
|
$aversion = explode(' ', $aresult[1]); |
1198
|
|
|
$this->setVersion($aversion[0]); |
1199
|
|
|
} else { |
1200
|
|
|
$this->setVersion(self::VERSION_UNKNOWN); |
1201
|
|
|
} |
1202
|
|
|
if (stripos($this->_agent, 'Mobile') !== false) { |
1203
|
|
|
$this->setMobile(true); |
1204
|
|
|
} else { |
1205
|
|
|
$this->setTablet(true); |
1206
|
|
|
} |
1207
|
|
|
$this->setBrowser(self::BROWSER_ANDROID); |
1208
|
|
|
return true; |
1209
|
|
|
} |
1210
|
|
|
return false; |
1211
|
|
|
} |
1212
|
|
|
|
1213
|
|
|
/** |
1214
|
|
|
* Determine the user's platform (last updated 1.7) |
1215
|
|
|
*/ |
1216
|
|
|
protected function checkPlatform() |
1217
|
|
|
{ |
1218
|
|
|
if (stripos($this->_agent, 'windows') !== false) { |
1219
|
|
|
$this->_platform = self::PLATFORM_WINDOWS; |
1220
|
|
|
} else if (stripos($this->_agent, 'iPad') !== false) { |
1221
|
|
|
$this->_platform = self::PLATFORM_IPAD; |
1222
|
|
|
} else if (stripos($this->_agent, 'iPod') !== false) { |
1223
|
|
|
$this->_platform = self::PLATFORM_IPOD; |
1224
|
|
|
} else if (stripos($this->_agent, 'iPhone') !== false) { |
1225
|
|
|
$this->_platform = self::PLATFORM_IPHONE; |
1226
|
|
|
} elseif (stripos($this->_agent, 'mac') !== false) { |
1227
|
|
|
$this->_platform = self::PLATFORM_APPLE; |
1228
|
|
|
} elseif (stripos($this->_agent, 'android') !== false) { |
1229
|
|
|
$this->_platform = self::PLATFORM_ANDROID; |
1230
|
|
|
} elseif (stripos($this->_agent, 'linux') !== false) { |
1231
|
|
|
$this->_platform = self::PLATFORM_LINUX; |
1232
|
|
|
} else if (stripos($this->_agent, 'Nokia') !== false) { |
1233
|
|
|
$this->_platform = self::PLATFORM_NOKIA; |
1234
|
|
|
} else if (stripos($this->_agent, 'BlackBerry') !== false) { |
1235
|
|
|
$this->_platform = self::PLATFORM_BLACKBERRY; |
1236
|
|
|
} elseif (stripos($this->_agent, 'FreeBSD') !== false) { |
1237
|
|
|
$this->_platform = self::PLATFORM_FREEBSD; |
1238
|
|
|
} elseif (stripos($this->_agent, 'OpenBSD') !== false) { |
1239
|
|
|
$this->_platform = self::PLATFORM_OPENBSD; |
1240
|
|
|
} elseif (stripos($this->_agent, 'NetBSD') !== false) { |
1241
|
|
|
$this->_platform = self::PLATFORM_NETBSD; |
1242
|
|
|
} elseif (stripos($this->_agent, 'OpenSolaris') !== false) { |
1243
|
|
|
$this->_platform = self::PLATFORM_OPENSOLARIS; |
1244
|
|
|
} elseif (stripos($this->_agent, 'SunOS') !== false) { |
1245
|
|
|
$this->_platform = self::PLATFORM_SUNOS; |
1246
|
|
|
} elseif (stripos($this->_agent, 'OS\/2') !== false) { |
1247
|
|
|
$this->_platform = self::PLATFORM_OS2; |
1248
|
|
|
} elseif (stripos($this->_agent, 'BeOS') !== false) { |
1249
|
|
|
$this->_platform = self::PLATFORM_BEOS; |
1250
|
|
|
} elseif (stripos($this->_agent, 'win') !== false) { |
1251
|
|
|
$this->_platform = self::PLATFORM_WINDOWS; |
1252
|
|
|
} |
1253
|
|
|
|
1254
|
|
|
} |
1255
|
|
|
} |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: