source: contrib/Dms/ccBrowserInfo.php @ 3526

Revision 3526, 8.0 KB checked in by afernandes, 13 years ago (diff)

Ticket #1416 - Disponibilizado modulos Timesheet e DMS para a comunidade.

  • Property svn:executable set to *
Line 
1<?php
2  // ccBrowserInfo.php -- A PHP class for HTTP client user agent detection.
3  // by Chip Chapin <cchapin@chipchapin.com>
4  // Visit my home page at http://www.chipchapin.com
5  // Visit the ccBrowserInfo home page:
6  //     http://www.chipchapin.com/WebTools/OtherTools/ccBrowserInfo/
7 
8  // ccBrowserInfo.php was inspired by browser.php in SourceForge 2.5.
9  // Other important influences:
10  //   sniffer.js from Netscape and
11  //   phpSniff (http://phpsniff.sourceforge.net/), which offers more
12  //   functions and greater control, but is too elaborate for my taste.
13
14  // ccBrowserInfo does NOT try to be rigorous.  Our primary goal is to distinguish
15  // between older NN and IE, and between Windows and Mac (and Unix).
16  // A useful list of older browser strings is here:
17  //   http://www.browserlist.browser.org/browser_mappings_list_big.html
18  // See also the built-in pull-down list in the phpSniff example:
19  //   http://phpsniff.sourceforge.net/
20 
21  // Revision History 
22  // 2002-01-01  cchapin  Creation
23  // 2002-11-02  cchapin  Initial Public release (v1.0)
24 
25// +-----------------------------------------------------------------------+
26// | Copyright (c) 2002 Chip Chapin <cchapin@chipchapin.com>               |
27// |                    http://www.chipchapin.com                          |
28// | All rights reserved.                                                  |
29// |                                                                       |
30// | Redistribution and use in source and binary forms, with or without    |
31// | modification, are permitted provided that the following conditions    |
32// | are met:                                                              |
33// |                                                                       |
34// | o Redistributions of source code must retain the above copyright      |
35// |   notice, this list of conditions and the following disclaimer.       |
36// | o Redistributions in binary form must reproduce the above copyright   |
37// |   notice, this list of conditions and the following disclaimer in the |
38// |   documentation and/or other materials provided with the distribution.|
39// | o The names of the authors may not be used to endorse or promote      |
40// |   products derived from this software without specific prior written  |
41// |   permission.                                                         |
42// |                                                                       |
43// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS   |
44// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT     |
45// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
46// | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT  |
47// | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
48// | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT      |
49// | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
50// | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
51// | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT   |
52// | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
53// | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  |
54// |                                                                       |
55// +-----------------------------------------------------------------------+
56// | Author: Chip Chapin <cchapin@chipchapin.com>                          |
57// +-----------------------------------------------------------------------+
58
59class ccBrowserInfo
60{
61  var $agent='unknown';
62  var $ver=0;
63  var $majorver=0;
64  var $minorver=0;
65  var $platform='unknown';
66  var $debug=false;
67
68  function get_agent()    { return $this->agent; }
69  function get_version()  { return $this->ver; }       
70  function get_platform() { return $this->platform; }
71  function is_mac()       { return $this->platform == 'Mac'; }
72  // function is_windows()   { return $this->platform == 'Win'; }
73  function is_win()       { return $this->platform == 'Win'; }
74  function is_ie()        { return $this->agent == 'IE'; }
75  function is_ie3()       { return $this->is_ie() && $this->majorver < 4; }
76  function is_ie4()       { return $this->is_ie() && $this->majorver == 4; }
77  function is_ie5up()     { return $this->is_ie() && $this->majorver >= 5; }
78  // function is_netscape()  { return $this->agent == 'MOZILLA'; }
79  function is_moz()       { return $this->agent == 'MOZILLA'; }
80  // function is_netscape4() { return $this->agent == 'MOZILLA' && $this->majorver <= 4; }
81  function is_moz4dn()    { return $this->agent == 'MOZILLA' && $this->majorver <= 4; }
82  function is_moz5()      { return $this->agent == 'MOZILLA' && $this->majorver == 5; }
83  function is_moz5up()    { return $this->agent == 'MOZILLA' && $this->majorver >= 5; }
84  // function is_winNN()     { return ($this->is_windows() && $this->is_netscape());}
85  function is_winNN()     { return ($this->is_win() && $this->is_moz4dn());}
86  function is_macNN()     { return ($this->is_mac() && $this->is_moz4dn());}
87       
88  // This item relates to browser functionality, not identification. 
89  // It really belongs elsewhere.
90  function transparentFlashOK() {
91    return $this->is_ie5up() && $this->is_windows();
92  }
93
94  // Constructor
95  // Determine client browser type, version and platform using
96  // heuristic examination of user agent string.
97  // @param $ua allows override of user agent string for testing.
98  function ccBrowserInfo( $ua=0 )
99  {
100    if (empty($ua)) $ua = $_SERVER['HTTP_USER_AGENT'];
101    $useragent = strtolower($ua);
102
103    // Determine browser and version
104    // The order in which we test the agents patterns is important
105    // Intentionally ignore Konquerer.  It should show up as Mozilla.
106    // post-Netscape Mozilla versions using Gecko show up as Mozilla 5.0
107    if (preg_match( '/(opera |opera\/)([0-9]*).([0-9]{1,2})/', $useragent, $matches)) ;
108    elseif (preg_match( '/(msie )([0-9]*).([0-9]{1,2})/', $useragent, $matches)) ;
109    elseif (preg_match( '/(mozilla\/)([0-9]*).([0-9]{1,2})/', $useragent, $matches)) ;
110    else {
111      $matches[1] = 'unknown'; $matches[2]=0; $matches[3]=0;
112    }
113    switch ($matches[1]) {
114      case 'opera/':
115      case 'opera ': $this->agent='OPERA'; break;
116      case 'msie ': $this->agent='IE'; break;
117      case 'mozilla/': $this->agent='MOZILLA'; break;
118      case 'unknown': $this->agent='OTHER'; break;
119      default: $this->agent='Oops!';
120    }                   
121    $this->majorver=$matches[2];
122    $this->minorver=$matches[3];
123    $this->ver=$matches[2].'.'.$matches[3];
124   
125    // Determine platform
126    // This is very incomplete for platforms other than Win/Mac
127    if (preg_match( '/(win|mac|linux|unix)/', $useragent, $matches)) ;
128    else $matches[1] = 'unknown';
129    switch ($matches[1]) {
130      case 'win': $this->platform='Win'; break;
131      case 'mac': $this->platform='Mac'; break;
132      case 'linux': $this->platform='Linux'; break;
133      case 'unix': $this->platform='Unix'; break;
134      case 'unknown': $this->platform='Other'; break;
135      default: $this->platform='Oops!';
136    }
137   
138    if ($this->debug) $this-showme();
139  } // ccBrowserInfo constructor
140
141
142  function showme()
143  {
144    echo "\n\nAgent String: " . $_SERVER['HTTP_USER_AGENT'] . "<br>\n";
145    echo "\nis Windows: " . ($this->is_win()?'true':'false') . "<br>\n";
146    echo "\nis Mac: " . ($this->is_mac()?'true':'false') . "<br>\n";
147    echo "\nis IE: " . ($this->is_ie()?'true':'false') . "<br>\n";
148    echo "\nis IE5up: " . ($this->is_ie5up()?'true':'false') . "<br>\n";
149    echo "\nis NN: " . ($this->is_moz4dn()?'true':'false') . "<br>\n";
150    echo "\nis Moz5up: " . ($this->is_moz5up()?'true':'false') . "<br>\n";
151    echo "\nPlatform: " . $this->get_platform() . "<br>\n";
152    echo "\nVersion: " . $this->get_version() . "<br>\n";
153    echo "\nAgent: " . $this->get_agent() . "<br>\n";
154  } // showme
155 
156} // class ccBrowserInfo
157
158?>
Note: See TracBrowser for help on using the repository browser.