]> git.donarmstrong.com Git - roundcube.git/blob - program/include/rcube_browser.php
Imported Upstream version 0.7
[roundcube.git] / program / include / rcube_browser.php
1 <?php
2
3 /*
4  +-----------------------------------------------------------------------+
5  | program/include/rcube_browser.php                                     |
6  |                                                                       |
7  | This file is part of the Roundcube Webmail client                     |
8  | Copyright (C) 2007-2009, The Roundcube Dev Team                       |
9  | Licensed under the GNU GPL                                            |
10  |                                                                       |
11  | PURPOSE:                                                              |
12  |   Class representing the client browser's properties                  |
13  |                                                                       |
14  +-----------------------------------------------------------------------+
15  | Author: Thomas Bruederli <roundcube@gmail.com>                        |
16  +-----------------------------------------------------------------------+
17
18  $Id: rcube_browser.php 5499 2011-11-28 09:03:27Z alec $
19
20 */
21
22 /** 
23  * rcube_browser
24  * 
25  * Provide details about the client's browser based on the User-Agent header
26  *
27  * @package Core
28  */
29 class rcube_browser
30 {
31     function __construct()
32     {
33         $HTTP_USER_AGENT = strtolower($_SERVER['HTTP_USER_AGENT']);
34
35         $this->ver = 0;
36         $this->win = strpos($HTTP_USER_AGENT, 'win') != false;
37         $this->mac = strpos($HTTP_USER_AGENT, 'mac') != false;
38         $this->linux = strpos($HTTP_USER_AGENT, 'linux') != false;
39         $this->unix  = strpos($HTTP_USER_AGENT, 'unix') != false;
40
41         $this->opera = strpos($HTTP_USER_AGENT, 'opera') !== false;
42         $this->ns4 = strpos($HTTP_USER_AGENT, 'mozilla/4') !== false && strpos($HTTP_USER_AGENT, 'msie') === false;
43         $this->ns  = ($this->ns4 || strpos($HTTP_USER_AGENT, 'netscape') !== false);
44         $this->ie  = !$this->opera && strpos($HTTP_USER_AGENT, 'compatible; msie') !== false;
45         $this->mz  = !$this->ie && strpos($HTTP_USER_AGENT, 'mozilla/5') !== false;
46         $this->chrome = strpos($HTTP_USER_AGENT, 'chrome') !== false;
47         $this->khtml = strpos($HTTP_USER_AGENT, 'khtml') !== false;
48         $this->safari = !$this->chrome && ($this->khtml || strpos($HTTP_USER_AGENT, 'safari') !== false);
49
50         if ($this->ns || $this->chrome) {
51             $test = preg_match('/(mozilla|chrome)\/([0-9.]+)/', $HTTP_USER_AGENT, $regs);
52             $this->ver = $test ? (float)$regs[2] : 0;
53         }
54         else if ($this->mz) {
55             $test = preg_match('/rv:([0-9.]+)/', $HTTP_USER_AGENT, $regs);
56             $this->ver = $test ? (float)$regs[1] : 0;
57         }
58         else if ($this->ie || $this->opera) {
59             $test = preg_match('/(msie|opera) ([0-9.]+)/', $HTTP_USER_AGENT, $regs);
60             $this->ver = $test ? (float)$regs[2] : 0;
61         }
62
63         if (preg_match('/ ([a-z]{2})-([a-z]{2})/', $HTTP_USER_AGENT, $regs))
64             $this->lang =  $regs[1];
65         else
66             $this->lang =  'en';
67
68         $this->dom = ($this->mz || $this->safari || ($this->ie && $this->ver>=5) || ($this->opera && $this->ver>=7));
69         $this->pngalpha = $this->mz || $this->safari || ($this->ie && $this->ver>=5.5) ||
70             ($this->ie && $this->ver>=5 && $this->mac) || ($this->opera && $this->ver>=7) ? true : false;
71         $this->imgdata = !$this->ie;
72     }
73 }
74