Use third party library to detect user's browser

This commit is contained in:
Dmitriy Simushev 2014-12-29 15:04:24 +00:00
parent efbf92b012
commit 9cd082b878
2 changed files with 16 additions and 26 deletions

View File

@ -28,12 +28,22 @@
"tedivm/stash": "0.12.*",
"canteen/html5": "1.1.*",
"vierbergenlars/php-semver": "3.0.*",
"swiftmailer/swiftmailer": "5.3.*"
"swiftmailer/swiftmailer": "5.3.*",
"ua-parser/ua-parser": "dev-master#c95b59bc18e5f0a2a44ae145b6f32561c7e4fc25"
},
"require-dev": {
"squizlabs/php_codesniffer": "1.*"
},
"config": {
"vendor-dir": "mibew/vendor"
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/ua-parser/uap-php"
}
],
"scripts": {
"post-install-cmd": "php mibew/vendor/bin/uaparser.php ua-parser:update"
}
}

View File

@ -17,38 +17,18 @@
* limitations under the License.
*/
// Import namespaces and classes of the core
use Mibew\Settings;
use UAParser\Parser as UAParser;
function get_user_agent_version($user_agent)
{
$known_agents = get_known_user_agents();
if (is_array($known_agents)) {
$user_agent = strtolower($user_agent);
foreach ($known_agents as $agent) {
if (strstr($user_agent, $agent)) {
if (preg_match("/" . $agent . "[\\s\/]?(\\d+(\\.\\d+(\\.\\d+(\\.\\d+)?)?)?)/", $user_agent, $matches)) {
$ver = $matches[1];
if ($agent == 'safari') {
if (preg_match("/version\/(\\d+(\\.\\d+(\\.\\d+)?)?)/", $user_agent, $matches)) {
$ver = $matches[1];
} else {
$ver = "1 or 2 (build " . $ver . ")";
}
if (preg_match("/mobile\/(\\d+(\\.\\d+(\\.\\d+)?)?)/", $user_agent, $matches)) {
$user_agent = "iPhone " . $matches[1] . " ($agent $ver)";
break;
}
}
static $parser = null;
$user_agent = ucfirst($agent) . " " . $ver;
break;
}
}
}
if (is_null($parser)) {
$parser = UAParser::create();
}
return $user_agent;
return $parser->parse($user_agent)->ua->toString();
}
function get_user_addr($addr)