source: subversion/trunk/roundcubemail/program/include/rcube_browser.php

Last change on this file was 5787, checked in by thomasb, 17 months ago

Changed license to GNU GPLv3+ with exceptions for skins and plugins

  • Property svn:keywords set to Id
File size: 3.4 KB
Line 
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 |                                                                       |
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.                     |
13 |                                                                       |
14 | PURPOSE:                                                              |
15 |   Class representing the client browser's properties                  |
16 |                                                                       |
17 +-----------------------------------------------------------------------+
18 | Author: Thomas Bruederli <roundcube@gmail.com>                        |
19 +-----------------------------------------------------------------------+
20
21 $Id$
22
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 */
32class rcube_browser
33{
34    function __construct()
35    {
36        $HTTP_USER_AGENT = strtolower($_SERVER['HTTP_USER_AGENT']);
37
38        $this->ver = 0;
39        $this->win = strpos($HTTP_USER_AGENT, 'win') != false;
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;
43
44        $this->opera = strpos($HTTP_USER_AGENT, 'opera') !== false;
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);
52
53        if ($this->ns || $this->chrome) {
54            $test = preg_match('/(mozilla|chrome)\/([0-9.]+)/', $HTTP_USER_AGENT, $regs);
55            $this->ver = $test ? (float)$regs[2] : 0;
56        }
57        else if ($this->mz) {
58            $test = preg_match('/rv:([0-9.]+)/', $HTTP_USER_AGENT, $regs);
59            $this->ver = $test ? (float)$regs[1] : 0;
60        }
61        else if ($this->ie || $this->opera) {
62            $test = preg_match('/(msie|opera) ([0-9.]+)/', $HTTP_USER_AGENT, $regs);
63            $this->ver = $test ? (float)$regs[2] : 0;
64        }
65
66        if (preg_match('/ ([a-z]{2})-([a-z]{2})/', $HTTP_USER_AGENT, $regs))
67            $this->lang =  $regs[1];
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;
74        $this->imgdata = !$this->ie;
75    }
76}
77
Note: See TracBrowser for help on using the repository browser.