diff --git a/src/composer.json b/src/composer.json index f36a1c5a..9ad65cbf 100644 --- a/src/composer.json +++ b/src/composer.json @@ -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" } } \ No newline at end of file diff --git a/src/mibew/libs/userinfo.php b/src/mibew/libs/userinfo.php index 2b3e7d05..f9e552e0 100644 --- a/src/mibew/libs/userinfo.php +++ b/src/mibew/libs/userinfo.php @@ -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)