Skip to content

Commit edac59b

Browse files
Update functionality cbschuld#61
Co-Authored-By: Ivijan-Stefan Stipic <creativform@gmail.com>
1 parent 5a59c4c commit edac59b

File tree

1 file changed

+67
-2
lines changed

1 file changed

+67
-2
lines changed

lib/Browser.php

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ class Browser
7474
const BROWSER_CHROME = 'Chrome'; // http://www.google.com/chrome
7575
const BROWSER_ANDROID = 'Android'; // http://www.android.com/
7676
const BROWSER_GOOGLEBOT = 'GoogleBot'; // http://en.wikipedia.org/wiki/Googlebot
77-
77+
const BROWSER_TWITTER = 'Twitter';
78+
const BROWSER_APACHE_CLIENT = 'Apache Client';
79+
7880
const BROWSER_YANDEXBOT = 'YandexBot'; // http://yandex.com/bots
7981
const BROWSER_YANDEXIMAGERESIZER_BOT = 'YandexImageResizer'; // http://yandex.com/bots
8082
const BROWSER_YANDEXIMAGES_BOT = 'YandexImages'; // http://yandex.com/bots
@@ -138,6 +140,10 @@ class Browser
138140
const PLATFORM_JAVA_ANDROID = "Java/Android";
139141
const PLATFORM_POSTMAN = "Postman";
140142
const PLATFORM_I_FRAME = "Iframely";
143+
const PLATFORM_FACEBOOK = 'Facebook Platform';
144+
const PLATFORM_GOOGLE_API = 'Google API';
145+
const PLATFORM_TWITTERBOOT = 'Twitter Boot';
146+
const PLATFORM_APACHE = 'Apache';
141147

142148
const OPERATING_SYSTEM_UNKNOWN = 'unknown';
143149

@@ -385,6 +391,20 @@ public function __toString()
385391
"<strong>Browser User Agent String:</strong> {$this->getUserAgent()}<br/>\n" .
386392
"<strong>Platform:</strong> {$this->getPlatform()}<br/>";
387393
}
394+
395+
/**
396+
* UPDATE: Ivijan-Stefan Stipic
397+
* Returns a formatted array with a all informations of the browser.
398+
* @return array with a all informations of the browser
399+
*/
400+
public function __toArray() {
401+
return array(
402+
'browser' => $this->getBrowser(),
403+
'version' => $this->getVersion(),
404+
'user_agent' => $this->getUserAgent(),
405+
'platform' => $this->getPlatform()
406+
);
407+
}
388408

389409
/**
390410
* Protected routine to calculate and determine what the browser is in use (including platform)
@@ -969,6 +989,45 @@ protected function checkBrowserInternetExplorer()
969989
return true;
970990
}
971991
}
992+
/*
993+
* UPDATE: Ivijan-Stefan Stipic
994+
* -Test versions for IE8,9,10,11...
995+
* -Facebook, Google, Twitter platforms
996+
*/
997+
else if( stripos($this->_agent,'trident') !== false && stripos($this->_agent,'windows') !== false && stripos($this->_agent,'rv') !== false ) {
998+
$aversion = explode(' ',stristr($this->_agent,'rv:'));
999+
$this->setVersion(str_replace('rv:','',$aversion[0]));
1000+
$this->setBrowser(self::BROWSER_IE);
1001+
return true;
1002+
}
1003+
else if( stripos($this->_agent,'facebook') !== false && stripos($this->_agent,'externalhit') !== false) {
1004+
$aversion = explode(' ',stristr($this->_agent,'facebookexternalhit/'));
1005+
$this->setPlatform(self::PLATFORM_FACEBOOK);
1006+
$this->setVersion(str_replace('facebookexternalhit/','',$aversion[0]));
1007+
$this->setBrowser(self::BROWSER_FACEBOOK);
1008+
return true;
1009+
}
1010+
else if( stripos($this->_agent,'Google-HTTP-Java-Client') !== false) {
1011+
$aversion = explode(' ',stristr($this->_agent,'Google-HTTP-Java-Client/'));
1012+
$this->setPlatform(self::PLATFORM_GOOGLE_API);
1013+
$this->setVersion(str_replace('Google-HTTP-Java-Client/','',$aversion[0]));
1014+
$this->setBrowser(self::BROWSER_GOOGLEBOT);
1015+
return true;
1016+
}
1017+
else if( stripos($this->_agent,'Twitterbot') !== false) {
1018+
$aversion = explode('/',$this->_agent);
1019+
$this->setPlatform(self::PLATFORM_TWITTERBOOT);
1020+
$this->setVersion($aversion[1]);
1021+
$this->setBrowser(self::BROWSER_TWITTER);
1022+
return true;
1023+
}
1024+
else if( stripos($this->_agent,'Jakarta') !== false && stripos($this->_agent,'HttpClient') !== false ) {
1025+
$aversion = explode('/',$this->_agent);
1026+
$this->setPlatform(self::PLATFORM_APACHE);
1027+
$this->setVersion($aversion[1]);
1028+
$this->setBrowser(self::BROWSER_APACHE_CLIENT);
1029+
return true;
1030+
}
9721031
return false;
9731032
}
9741033

@@ -1016,7 +1075,10 @@ protected function checkBrowserOpera()
10161075
return true;
10171076
} else if (stripos($this->_agent, 'OPR') !== false) {
10181077
$resultant = stristr($this->_agent, 'OPR');
1019-
if (preg_match('/\//', $resultant)) {
1078+
if( preg_match('/Version\/(10.*)$/',$resultant,$matches) ) {
1079+
$this->setVersion($matches[1]);
1080+
}
1081+
else if (preg_match('/\//', $resultant)) {
10201082
$aresult = explode('/', str_replace("(", " ", $resultant));
10211083
if (isset($aresult[1])) {
10221084
$aversion = explode(' ', $aresult[1]);
@@ -1724,6 +1786,9 @@ protected function checkPlatform()
17241786
$this->_platform = self::PLATFORM_POSTMAN;
17251787
} elseif (stripos($this->_agent, 'Iframely') !== false) {
17261788
$this->_platform = self::PLATFORM_I_FRAME;
1789+
} else {
1790+
$this->_platform = self::PLATFORM_UNKNOWN;
17271791
}
1792+
17281793
}
17291794
}

0 commit comments

Comments
 (0)