This repository was archived by the owner on Jan 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 106
Expand file tree
/
Copy pathBrowser.php
More file actions
398 lines (358 loc) · 9.62 KB
/
Browser.php
File metadata and controls
398 lines (358 loc) · 9.62 KB
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
<?php
namespace Sinergi\BrowserDetector;
class Browser
{
const UNKNOWN = 'unknown';
const VIVALDI = 'Vivaldi';
const OPERA = 'Opera';
const OPERA_MINI = 'Opera Mini';
const WEBTV = 'WebTV';
const IE = 'Internet Explorer';
const POCKET_IE = 'Pocket Internet Explorer';
const KONQUEROR = 'Konqueror';
const ICAB = 'iCab';
const OMNIWEB = 'OmniWeb';
const FIREBIRD = 'Firebird';
const FIREFOX = 'Firefox';
const SEAMONKEY = 'SeaMonkey';
const ICEWEASEL = 'Iceweasel';
const SHIRETOKO = 'Shiretoko';
const MOZILLA = 'Mozilla';
const AMAYA = 'Amaya';
const LYNX = 'Lynx';
const SAFARI = 'Safari';
const SAMSUNG_BROWSER = 'SamsungBrowser';
const CHROME = 'Chrome';
const NAVIGATOR = 'Android Navigator';
const BLACKBERRY = 'BlackBerry';
const ICECAT = 'IceCat';
const NOKIA_S60 = 'Nokia S60 OSS Browser';
const NOKIA = 'Nokia Browser';
const MSN = 'MSN Browser';
const NETSCAPE_NAVIGATOR = 'Netscape Navigator';
const GALEON = 'Galeon';
const NETPOSITIVE = 'NetPositive';
const PHOENIX = 'Phoenix';
const GSA = 'Google Search Appliance';
const YANDEX = 'Yandex';
const EDGE = 'Edge';
const EDGE_HTML = 'EdgeHTML';
const DRAGON = 'Dragon';
const NSPLAYER = 'Windows Media Player';
const UCBROWSER = 'UC Browser';
const MICROSOFT_OFFICE = 'Microsoft Office';
const APPLE_NEWS = 'Apple News';
const DALVIK = 'Android';
const VERSION_UNKNOWN = 'unknown';
/**
* @var UserAgent
*/
private $userAgent;
/**
* @var string
*/
private $name;
/**
* @var string
*/
private $version;
/**
* @var bool
*/
private $isChromeFrame = false;
/**
* @var bool
*/
private $isWebkit = false;
/**
* @var bool
*/
private $isFacebookWebView = false;
/**
* @var bool
*/
private $isTwitterWebView = false;
/**
* @var bool
*/
private $isCompatibilityMode = false;
/**
* @param null|string|UserAgent $userAgent
* @throws \Sinergi\BrowserDetector\InvalidArgumentException
*/
public function __construct($userAgent = null)
{
if ($userAgent instanceof UserAgent) {
$this->setUserAgent($userAgent);
} elseif (null === $userAgent || is_string($userAgent)) {
$this->setUserAgent(new UserAgent($userAgent));
} else {
throw new InvalidArgumentException();
}
}
/**
* Set the name of the Browser.
*
* @param string $name
* @return $this
*/
public function setName($name)
{
$this->name = (string)$name;
return $this;
}
/**
* Return the name of the Browser.
*
* @return string
*/
public function getName()
{
if (!isset($this->name)) {
BrowserDetector::detect($this, $this->getUserAgent());
}
return $this->name;
}
/**
* Check to see if the specific browser is valid.
*
* @param string $name
* @return bool
*/
public function isBrowser($name)
{
return (0 == strcasecmp($this->getName(), trim($name)));
}
/**
* Set the version of the browser.
*
* @param string $version
* @return $this
*/
public function setVersion($version)
{
$this->version = (string)$version;
return $this;
}
/**
* The version of the browser.
*
* @return string
*/
public function getVersion()
{
if (!isset($this->name)) {
BrowserDetector::detect($this, $this->getUserAgent());
}
return (string) $this->version;
}
/**
* Detects scripted agents (robots / bots)
* Returns a resolved ScriptedAgent object if detected.
* Otherwise returns false.
*
* @return ScriptedAgent|bool
*/
public function detectScriptedAgent()
{
$ua = $this->getUserAgent()->getUserAgentString();
if (stripos($ua, 'bot') !== false ||
stripos($ua, 'spider') !== false ||
stripos($ua, 'crawler') !== false ||
stripos($ua, 'preview') !== false ||
stripos($ua, 'slurp') !== false ||
stripos($ua, 'facebookexternalhit') !== false ||
stripos($ua, 'mediapartners') !== false ||
stripos($ua, 'google-adwords') !== false ||
stripos($ua, 'adxvastfetcher') !== false ||
stripos($ua, 'adbeat') !== false ||
stripos($ua, 'google favicon') !== false ||
stripos($ua, 'webdav client') !== false ||
stripos($ua, 'metauri api') !== false ||
stripos($ua, 'tlsprobe') !== false ||
stripos($ua, 'wpif') !== false ||
stripos($ua, 'imgsizer') !== false ||
stripos($ua, 'netcraft ssl server survey') !== false ||
stripos($ua, 'curl/') !== false ||
stripos($ua, 'go-http-client/') !== false ||
stripos($ua, 'python') !== false ||
stripos($ua, 'libwww') !== false ||
stripos($ua, 'wget/') !== false ||
stripos($ua, 'zgrab/') !== false ||
stripos($ua, 'Java/') !== false ||
stripos($ua, '() { :;}; /bin/bash -c') !== false ||
stripos($ua, 'browsershots') !== false ||
stripos($ua, 'magereport') !== false ||
stripos($ua, 'ubermetrics-technologies') !== false ||
stripos($ua, 'W3C') !== false ||
stripos($ua, 'Validator') !== false ||
stripos($ua, 'Jigsaw/') !== false ||
stripos($ua, 'bing') !== false ||
stripos($ua, 'msn') !== false ||
stripos($ua, 'Google Web Preview') !== false ||
stripos($ua, 'ips-agent') !== false ||
(stripos($ua, 'Chrome/51.0.2704.103') !== false && !isset($_SERVER['HTTP_UPGRADE_INSECURE_REQUESTS']) && stristr($_SERVER['HTTP_ACCEPT_LANGUAGE'], "ru-RU") !== false) //ICQ Preview
) {
$scriptedAgent = new ScriptedAgent($ua);
if ($scriptedAgent->getName()==ScriptedAgent::UNKNOWN) {
return false;
} else {
return $scriptedAgent;
}
} else {
return false;
}
}
/**
* @param bool $isChromeFrame
* @return $this
*/
public function setIsChromeFrame($isChromeFrame)
{
$this->isChromeFrame = (bool)$isChromeFrame;
return $this;
}
/**
* Used to determine if the browser is actually "chromeframe".
*
* @return bool
*/
public function getIsChromeFrame()
{
if (!isset($this->name)) {
BrowserDetector::detect($this, $this->getUserAgent());
}
return $this->isChromeFrame;
}
/**
* @return bool
*/
public function isChromeFrame()
{
return $this->getIsChromeFrame();
}
/**
* @param bool $isWebkit
* @return $this
*/
public function setIsWebkit($isWebkit)
{
$this->isWebkit = (bool)$isWebkit;
return $this;
}
/**
* Used to determine if the browser is actually "chromeframe".
*
* @return bool
*/
public function getIsWebkit()
{
if (!isset($this->name)) {
BrowserDetector::detect($this, $this->getUserAgent());
}
return $this->isWebkit;
}
/**
* @return bool
*/
public function isWebkit()
{
return $this->getIsWebkit();
}
/**
* @param bool $isFacebookWebView
* @return $this
*/
public function setIsFacebookWebView($isFacebookWebView)
{
$this->isFacebookWebView = (bool) $isFacebookWebView;
return $this;
}
/**
* Used to determine if the browser is actually "facebook".
*
* @return bool
*/
public function getIsFacebookWebView()
{
if (!isset($this->name)) {
BrowserDetector::detect($this, $this->getUserAgent());
}
return $this->isFacebookWebView;
}
/**
* @return bool
*/
public function isFacebookWebView()
{
return $this->getIsFacebookWebView();
}
/**
* @param bool $isTwitterWebView
* @return $this
*/
public function setIsTwitterWebView($isTwitterWebView)
{
$this->isTwitterWebView = (bool) $isTwitterWebView;
return $this;
}
/**
* Used to determine if the browser is actually "Twitter".
*
* @return bool
*/
public function getIsTwitterWebView()
{
if (!isset($this->name)) {
BrowserDetector::detect($this, $this->getUserAgent());
}
return $this->isTwitterWebView;
}
/**
* @return bool
*/
public function isTwitterWebView()
{
return $this->getIsTwitterWebView();
}
/**
* @param UserAgent $userAgent
* @return $this
*/
public function setUserAgent(UserAgent $userAgent)
{
$this->userAgent = $userAgent;
return $this;
}
/**
* @return UserAgent
*/
public function getUserAgent()
{
return $this->userAgent;
}
/**
* @param bool
*
* @return $this
*/
public function setIsCompatibilityMode($isCompatibilityMode)
{
$this->isCompatibilityMode = $isCompatibilityMode;
return $this;
}
/**
* @return bool
*/
public function isCompatibilityMode()
{
return $this->isCompatibilityMode;
}
/**
* Render pages outside of IE's compatibility mode.
*/
public function endCompatibilityMode()
{
header('X-UA-Compatible: IE=edge');
}
}