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