Thomas Bruederli
2012-11-17 6ddb16d181e285d4f0ef0ef55bdd0ba787f1b583
commit | author | age
47124c 1 <?php
T 2
3 /*
4  +-----------------------------------------------------------------------+
5  | program/include/rcube_browser.php                                     |
6  |                                                                       |
e019f2 7  | This file is part of the Roundcube Webmail client                     |
f5e7b3 8  | Copyright (C) 2007-2009, The Roundcube Dev Team                       |
7fe381 9  |                                                                       |
T 10  | Licensed under the GNU General Public License version 3 or            |
11  | any later version with exceptions for skins & plugins.                |
12  | See the README file for a full license statement.                     |
47124c 13  |                                                                       |
T 14  | PURPOSE:                                                              |
15  |   Class representing the client browser's properties                  |
16  |                                                                       |
17  +-----------------------------------------------------------------------+
18  | Author: Thomas Bruederli <roundcube@gmail.com>                        |
19  +-----------------------------------------------------------------------+
20 */
21
041c93 22 /**
47124c 23  * Provide details about the client's browser based on the User-Agent header
T 24  *
9ab346 25  * @package    Framework
AM 26  * @subpackage Core
47124c 27  */
T 28 class rcube_browser
29 {
30     function __construct()
31     {
2aa2b3 32         $HTTP_USER_AGENT = strtolower($_SERVER['HTTP_USER_AGENT']);
47124c 33
T 34         $this->ver = 0;
6e0fde 35         $this->win = strpos($HTTP_USER_AGENT, 'win') != false;
A 36         $this->mac = strpos($HTTP_USER_AGENT, 'mac') != false;
37         $this->linux = strpos($HTTP_USER_AGENT, 'linux') != false;
38         $this->unix  = strpos($HTTP_USER_AGENT, 'unix') != false;
47124c 39
6e0fde 40         $this->opera = strpos($HTTP_USER_AGENT, 'opera') !== false;
A 41         $this->ns4 = strpos($HTTP_USER_AGENT, 'mozilla/4') !== false && strpos($HTTP_USER_AGENT, 'msie') === false;
42         $this->ns  = ($this->ns4 || strpos($HTTP_USER_AGENT, 'netscape') !== false);
43         $this->ie  = !$this->opera && strpos($HTTP_USER_AGENT, 'compatible; msie') !== false;
44         $this->khtml = strpos($HTTP_USER_AGENT, 'khtml') !== false;
2698d7 45         $this->mz  = !$this->ie && !$this->khtml && strpos($HTTP_USER_AGENT, 'mozilla/5') !== false;
AM 46         $this->chrome = strpos($HTTP_USER_AGENT, 'chrome') !== false;
6e0fde 47         $this->safari = !$this->chrome && ($this->khtml || strpos($HTTP_USER_AGENT, 'safari') !== false);
47124c 48
c2e697 49         if ($this->ns || $this->chrome) {
2aa2b3 50             $test = preg_match('/(mozilla|chrome)\/([0-9.]+)/', $HTTP_USER_AGENT, $regs);
c2e697 51             $this->ver = $test ? (float)$regs[2] : 0;
47124c 52         }
c2e697 53         else if ($this->mz) {
23a2ee 54             $test = preg_match('/rv:([0-9.]+)/', $HTTP_USER_AGENT, $regs);
47124c 55             $this->ver = $test ? (float)$regs[1] : 0;
T 56         }
c2e697 57         else if ($this->ie || $this->opera) {
2aa2b3 58             $test = preg_match('/(msie|opera) ([0-9.]+)/', $HTTP_USER_AGENT, $regs);
c2e697 59             $this->ver = $test ? (float)$regs[2] : 0;
47124c 60         }
T 61
2aa2b3 62         if (preg_match('/ ([a-z]{2})-([a-z]{2})/', $HTTP_USER_AGENT, $regs))
47124c 63             $this->lang =  $regs[1];
T 64         else
65             $this->lang =  'en';
66
67         $this->dom = ($this->mz || $this->safari || ($this->ie && $this->ver>=5) || ($this->opera && $this->ver>=7));
68         $this->pngalpha = $this->mz || $this->safari || ($this->ie && $this->ver>=5.5) ||
69             ($this->ie && $this->ver>=5 && $this->mac) || ($this->opera && $this->ver>=7) ? true : false;
0501b6 70         $this->imgdata = !$this->ie;
47124c 71     }
b25dfd 72 }
47124c 73