thomascube
2012-05-04 5b04ddd6bc9e0af5f73694371cd3988b1d5be7e8
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
638fb8 21  $Id$
47124c 22
T 23 */
24
25 /** 
26  * rcube_browser
27  * 
28  * Provide details about the client's browser based on the User-Agent header
29  *
30  * @package Core
31  */
32 class rcube_browser
33 {
34     function __construct()
35     {
2aa2b3 36         $HTTP_USER_AGENT = strtolower($_SERVER['HTTP_USER_AGENT']);
47124c 37
T 38         $this->ver = 0;
6e0fde 39         $this->win = strpos($HTTP_USER_AGENT, 'win') != false;
A 40         $this->mac = strpos($HTTP_USER_AGENT, 'mac') != false;
41         $this->linux = strpos($HTTP_USER_AGENT, 'linux') != false;
42         $this->unix  = strpos($HTTP_USER_AGENT, 'unix') != false;
47124c 43
6e0fde 44         $this->opera = strpos($HTTP_USER_AGENT, 'opera') !== false;
A 45         $this->ns4 = strpos($HTTP_USER_AGENT, 'mozilla/4') !== false && strpos($HTTP_USER_AGENT, 'msie') === false;
46         $this->ns  = ($this->ns4 || strpos($HTTP_USER_AGENT, 'netscape') !== false);
47         $this->ie  = !$this->opera && strpos($HTTP_USER_AGENT, 'compatible; msie') !== false;
48         $this->mz  = !$this->ie && strpos($HTTP_USER_AGENT, 'mozilla/5') !== false;
49         $this->chrome = strpos($HTTP_USER_AGENT, 'chrome') !== false;
50         $this->khtml = strpos($HTTP_USER_AGENT, 'khtml') !== false;
51         $this->safari = !$this->chrome && ($this->khtml || strpos($HTTP_USER_AGENT, 'safari') !== false);
47124c 52
c2e697 53         if ($this->ns || $this->chrome) {
2aa2b3 54             $test = preg_match('/(mozilla|chrome)\/([0-9.]+)/', $HTTP_USER_AGENT, $regs);
c2e697 55             $this->ver = $test ? (float)$regs[2] : 0;
47124c 56         }
c2e697 57         else if ($this->mz) {
23a2ee 58             $test = preg_match('/rv:([0-9.]+)/', $HTTP_USER_AGENT, $regs);
47124c 59             $this->ver = $test ? (float)$regs[1] : 0;
T 60         }
c2e697 61         else if ($this->ie || $this->opera) {
2aa2b3 62             $test = preg_match('/(msie|opera) ([0-9.]+)/', $HTTP_USER_AGENT, $regs);
c2e697 63             $this->ver = $test ? (float)$regs[2] : 0;
47124c 64         }
T 65
2aa2b3 66         if (preg_match('/ ([a-z]{2})-([a-z]{2})/', $HTTP_USER_AGENT, $regs))
47124c 67             $this->lang =  $regs[1];
T 68         else
69             $this->lang =  'en';
70
71         $this->dom = ($this->mz || $this->safari || ($this->ie && $this->ver>=5) || ($this->opera && $this->ver>=7));
72         $this->pngalpha = $this->mz || $this->safari || ($this->ie && $this->ver>=5.5) ||
73             ($this->ie && $this->ver>=5 && $this->mac) || ($this->opera && $this->ver>=7) ? true : false;
0501b6 74         $this->imgdata = !$this->ie;
47124c 75     }
b25dfd 76 }
47124c 77