@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | - defined('ROOT_PATH') || exit('Access denied'); |
|
| 2 | + defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | 3 | /** |
| 4 | 4 | * File: Browser.php |
| 5 | 5 | * Author: Chris Schuld (http://chrisschuld.com/) |
@@ -21,68 +21,68 @@ discard block |
||
| 21 | 21 | * http://www.gnu.org/copyleft/gpl.html |
| 22 | 22 | * |
| 23 | 23 | */ |
| 24 | - class Browser { |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * List of know platforms |
|
| 28 | - * @var array |
|
| 29 | - */ |
|
| 30 | - private $_platforms = array( |
|
| 31 | - '/windows nt 10/i' => 'Windows 10', |
|
| 32 | - '/windows phone 10/i' => 'Windows Phone 10', |
|
| 33 | - '/windows phone 8.1/i' => 'Windows Phone 8.1', |
|
| 34 | - '/windows phone 8/i' => 'Windows Phone 8', |
|
| 35 | - '/windows nt 6.3/i' => 'Windows 8.1', |
|
| 36 | - '/windows nt 6.2/i' => 'Windows 8', |
|
| 37 | - '/windows nt 6.1/i' => 'Windows 7', |
|
| 38 | - '/windows nt 6.0/i' => 'Windows Vista', |
|
| 39 | - '/windows nt 5.2/i' => 'Windows Server 2003/XP x64', |
|
| 40 | - '/windows nt 5.1/i' => 'Windows XP', |
|
| 41 | - '/windows xp/i' => 'Windows XP', |
|
| 42 | - '/windows nt 5.0/i' => 'Windows 2000', |
|
| 43 | - '/windows me/i' => 'Windows ME', |
|
| 44 | - '/win98/i' => 'Windows 98', |
|
| 45 | - '/win95/i' => 'Windows 95', |
|
| 46 | - '/win16/i' => 'Windows 3.11', |
|
| 47 | - '/macintosh|mac os x/i' => 'Mac OS X', |
|
| 48 | - '/mac_powerpc/i' => 'Mac OS 9', |
|
| 49 | - '/iphone/i' => 'iPhone', |
|
| 50 | - '/ipod/i' => 'iPod', |
|
| 51 | - '/ipad/i' => 'iPad', |
|
| 52 | - '/android/i' => 'Android', |
|
| 53 | - '/ubuntu/i' => 'Ubuntu', |
|
| 54 | - '/linux/i' => 'Linux', |
|
| 55 | - '/blackberry/i' => 'BlackBerry', |
|
| 56 | - '/webos/i' => 'Mobile' |
|
| 57 | - ); |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * List of know browsers |
|
| 61 | - * @var array |
|
| 62 | - */ |
|
| 63 | - private $_browsers = array( |
|
| 64 | - '/mobile/i' => 'Handheld Browser', |
|
| 65 | - '/msie/i' => 'Internet Explorer', |
|
| 66 | - '/firefox/i' => 'Firefox', |
|
| 67 | - '/chrome/i' => 'Chrome', |
|
| 68 | - '/safari/i' => 'Safari', |
|
| 69 | - '/edge/i' => 'Edge', |
|
| 70 | - '/opera/i' => 'Opera', |
|
| 71 | - '/netscape/i' => 'Netscape', |
|
| 72 | - '/maxthon/i' => 'Maxthon', |
|
| 73 | - '/konqueror/i' => 'Konqueror' |
|
| 74 | - ); |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * Agent string |
|
| 78 | - * @var string |
|
| 79 | - */ |
|
| 80 | - private $_agent = ''; |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * Browser name |
|
| 84 | - * @var string |
|
| 85 | - */ |
|
| 24 | + class Browser { |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * List of know platforms |
|
| 28 | + * @var array |
|
| 29 | + */ |
|
| 30 | + private $_platforms = array( |
|
| 31 | + '/windows nt 10/i' => 'Windows 10', |
|
| 32 | + '/windows phone 10/i' => 'Windows Phone 10', |
|
| 33 | + '/windows phone 8.1/i' => 'Windows Phone 8.1', |
|
| 34 | + '/windows phone 8/i' => 'Windows Phone 8', |
|
| 35 | + '/windows nt 6.3/i' => 'Windows 8.1', |
|
| 36 | + '/windows nt 6.2/i' => 'Windows 8', |
|
| 37 | + '/windows nt 6.1/i' => 'Windows 7', |
|
| 38 | + '/windows nt 6.0/i' => 'Windows Vista', |
|
| 39 | + '/windows nt 5.2/i' => 'Windows Server 2003/XP x64', |
|
| 40 | + '/windows nt 5.1/i' => 'Windows XP', |
|
| 41 | + '/windows xp/i' => 'Windows XP', |
|
| 42 | + '/windows nt 5.0/i' => 'Windows 2000', |
|
| 43 | + '/windows me/i' => 'Windows ME', |
|
| 44 | + '/win98/i' => 'Windows 98', |
|
| 45 | + '/win95/i' => 'Windows 95', |
|
| 46 | + '/win16/i' => 'Windows 3.11', |
|
| 47 | + '/macintosh|mac os x/i' => 'Mac OS X', |
|
| 48 | + '/mac_powerpc/i' => 'Mac OS 9', |
|
| 49 | + '/iphone/i' => 'iPhone', |
|
| 50 | + '/ipod/i' => 'iPod', |
|
| 51 | + '/ipad/i' => 'iPad', |
|
| 52 | + '/android/i' => 'Android', |
|
| 53 | + '/ubuntu/i' => 'Ubuntu', |
|
| 54 | + '/linux/i' => 'Linux', |
|
| 55 | + '/blackberry/i' => 'BlackBerry', |
|
| 56 | + '/webos/i' => 'Mobile' |
|
| 57 | + ); |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * List of know browsers |
|
| 61 | + * @var array |
|
| 62 | + */ |
|
| 63 | + private $_browsers = array( |
|
| 64 | + '/mobile/i' => 'Handheld Browser', |
|
| 65 | + '/msie/i' => 'Internet Explorer', |
|
| 66 | + '/firefox/i' => 'Firefox', |
|
| 67 | + '/chrome/i' => 'Chrome', |
|
| 68 | + '/safari/i' => 'Safari', |
|
| 69 | + '/edge/i' => 'Edge', |
|
| 70 | + '/opera/i' => 'Opera', |
|
| 71 | + '/netscape/i' => 'Netscape', |
|
| 72 | + '/maxthon/i' => 'Maxthon', |
|
| 73 | + '/konqueror/i' => 'Konqueror' |
|
| 74 | + ); |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * Agent string |
|
| 78 | + * @var string |
|
| 79 | + */ |
|
| 80 | + private $_agent = ''; |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * Browser name |
|
| 84 | + * @var string |
|
| 85 | + */ |
|
| 86 | 86 | private $_browser_name = ''; |
| 87 | 87 | |
| 88 | 88 | /** |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | */ |
| 122 | 122 | private $_is_facebook = false; |
| 123 | 123 | |
| 124 | - /** |
|
| 124 | + /** |
|
| 125 | 125 | * Class constructor |
| 126 | 126 | */ |
| 127 | 127 | public function __construct($userAgent = '') { |
@@ -248,10 +248,10 @@ discard block |
||
| 248 | 248 | return $this->_is_facebook; |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | - /** |
|
| 252 | - * Returns a formatted string with a summary of the details of the browser. |
|
| 253 | - * @return string formatted string with a summary of the browser |
|
| 254 | - */ |
|
| 251 | + /** |
|
| 252 | + * Returns a formatted string with a summary of the details of the browser. |
|
| 253 | + * @return string formatted string with a summary of the browser |
|
| 254 | + */ |
|
| 255 | 255 | public function __toString() { |
| 256 | 256 | return "<strong>Browser Name:</strong> {$this->getBrowser()}<br/>\n" . |
| 257 | 257 | "<strong>Browser Version:</strong> {$this->getVersion()}<br/>\n" . |
@@ -295,69 +295,69 @@ discard block |
||
| 295 | 295 | /** |
| 296 | 296 | * Determine the user's platform |
| 297 | 297 | */ |
| 298 | - protected function checkPlatform() { |
|
| 299 | - foreach ($this->_platforms as $regex => $value) { |
|
| 300 | - if (preg_match($regex, $this->_agent) ) { |
|
| 301 | - $this->setPlatform($value); |
|
| 302 | - break; |
|
| 303 | - } |
|
| 304 | - } |
|
| 305 | - } |
|
| 298 | + protected function checkPlatform() { |
|
| 299 | + foreach ($this->_platforms as $regex => $value) { |
|
| 300 | + if (preg_match($regex, $this->_agent) ) { |
|
| 301 | + $this->setPlatform($value); |
|
| 302 | + break; |
|
| 303 | + } |
|
| 304 | + } |
|
| 305 | + } |
|
| 306 | 306 | |
| 307 | - /** |
|
| 307 | + /** |
|
| 308 | 308 | * Routine to determine the browser type |
| 309 | 309 | */ |
| 310 | - protected function checkBrowser() { |
|
| 311 | - foreach ($this->_browsers as $regex => $value) { |
|
| 312 | - if (preg_match($regex, $this->_agent ) ) { |
|
| 313 | - $this->setBrowser($value); |
|
| 314 | - break; |
|
| 315 | - } |
|
| 316 | - } |
|
| 317 | - } |
|
| 310 | + protected function checkBrowser() { |
|
| 311 | + foreach ($this->_browsers as $regex => $value) { |
|
| 312 | + if (preg_match($regex, $this->_agent ) ) { |
|
| 313 | + $this->setBrowser($value); |
|
| 314 | + break; |
|
| 315 | + } |
|
| 316 | + } |
|
| 317 | + } |
|
| 318 | 318 | |
| 319 | - /** |
|
| 319 | + /** |
|
| 320 | 320 | * Routine to determine the browser version |
| 321 | 321 | */ |
| 322 | - protected function checkBrowserVersion(){ |
|
| 323 | - $detected = $this->getBrowser(); |
|
| 324 | - $d = array_search($detected, $this->_browsers); |
|
| 325 | - $browser = str_replace(array("/i","/"), "", $d); |
|
| 326 | - $regex = "/(?<browser>version|{$browser})[\/]+(?<version>[0-9.|a-zA-Z.]*)/i"; |
|
| 327 | - if (preg_match_all($regex, $this->_agent, $matches)) { |
|
| 328 | - $found = array_search($browser, $matches["browser"]); |
|
| 329 | - $this->setVersion($matches["version"][$found]); |
|
| 330 | - } |
|
| 331 | - } |
|
| 332 | - |
|
| 333 | - /** |
|
| 322 | + protected function checkBrowserVersion(){ |
|
| 323 | + $detected = $this->getBrowser(); |
|
| 324 | + $d = array_search($detected, $this->_browsers); |
|
| 325 | + $browser = str_replace(array("/i","/"), "", $d); |
|
| 326 | + $regex = "/(?<browser>version|{$browser})[\/]+(?<version>[0-9.|a-zA-Z.]*)/i"; |
|
| 327 | + if (preg_match_all($regex, $this->_agent, $matches)) { |
|
| 328 | + $found = array_search($browser, $matches["browser"]); |
|
| 329 | + $this->setVersion($matches["version"][$found]); |
|
| 330 | + } |
|
| 331 | + } |
|
| 332 | + |
|
| 333 | + /** |
|
| 334 | 334 | * Determine if the browser is Mobile or not |
| 335 | 335 | */ |
| 336 | - protected function checkMobile() { |
|
| 337 | - if (preg_match('/mobile|phone|ipod/i', $this->_agent) ) { |
|
| 338 | - $this->setMobile(true); |
|
| 339 | - } |
|
| 340 | - } |
|
| 336 | + protected function checkMobile() { |
|
| 337 | + if (preg_match('/mobile|phone|ipod/i', $this->_agent) ) { |
|
| 338 | + $this->setMobile(true); |
|
| 339 | + } |
|
| 340 | + } |
|
| 341 | 341 | |
| 342 | - /** |
|
| 342 | + /** |
|
| 343 | 343 | * Determine if the browser is Tablet or not |
| 344 | 344 | */ |
| 345 | - protected function checkTablet() { |
|
| 346 | - if (preg_match('/tablet|ipad/i', $this->_agent) ) { |
|
| 347 | - $this->setTablet(true); |
|
| 348 | - } |
|
| 349 | - } |
|
| 345 | + protected function checkTablet() { |
|
| 346 | + if (preg_match('/tablet|ipad/i', $this->_agent) ) { |
|
| 347 | + $this->setTablet(true); |
|
| 348 | + } |
|
| 349 | + } |
|
| 350 | 350 | |
| 351 | - /** |
|
| 351 | + /** |
|
| 352 | 352 | * Determine if the browser is Robot or not |
| 353 | 353 | */ |
| 354 | - protected function checkBot() { |
|
| 355 | - if (preg_match('/bot/i', $this->_agent) ) { |
|
| 356 | - $this->setTablet(true); |
|
| 357 | - } |
|
| 358 | - } |
|
| 354 | + protected function checkBot() { |
|
| 355 | + if (preg_match('/bot/i', $this->_agent) ) { |
|
| 356 | + $this->setTablet(true); |
|
| 357 | + } |
|
| 358 | + } |
|
| 359 | 359 | |
| 360 | - /** |
|
| 360 | + /** |
|
| 361 | 361 | * Detect if URL is loaded from FacebookExternalHit |
| 362 | 362 | */ |
| 363 | 363 | protected function checkFacebook() { |
@@ -370,10 +370,10 @@ discard block |
||
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | |
| 373 | - /** |
|
| 374 | - * Protected routine to calculate and determine what |
|
| 375 | - * the browser is in use (including platform) |
|
| 376 | - */ |
|
| 373 | + /** |
|
| 374 | + * Protected routine to calculate and determine what |
|
| 375 | + * the browser is in use (including platform) |
|
| 376 | + */ |
|
| 377 | 377 | protected function determine() { |
| 378 | 378 | $this->checkPlatform(); |
| 379 | 379 | $this->checkBrowser(); |
@@ -384,4 +384,4 @@ discard block |
||
| 384 | 384 | $this->checkFacebook(); |
| 385 | 385 | } |
| 386 | 386 | |
| 387 | - } |
|
| 387 | + } |
|