source: trunk/phpgwapi/inc/class.browser.inc.php @ 2

Revision 2, 6.6 KB checked in by niltonneto, 17 years ago (diff)

Removida todas as tags usadas pelo CVS ($Id, $Source).
Primeira versão no CVS externo.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<?php
2  /**************************************************************************\
3  * eGroupWare API - Browser detect functions                                *
4  * This file written by Miles Lott <milosch@groupwhere.org>                 *
5  * Majority of code borrowed from Sourceforge 2.5                           *
6  * Copyright 1999-2000 (c) The SourceForge Crew - http://sourceforge.net    *
7  * Browser detection functions for eGroupWare developers                    *
8  * -------------------------------------------------------------------------*
9  * This library is part of the eGroupWare API                               *
10  * http://www.egroupware.org/api                                            *
11  * ------------------------------------------------------------------------ *
12  * This library is free software; you can redistribute it and/or modify it  *
13  * under the terms of the GNU Lesser General Public License as published by *
14  * the Free Software Foundation; either version 2.1 of the License,         *
15  * or any later version.                                                    *
16  * This library is distributed in the hope that it will be useful, but      *
17  * WITHOUT ANY WARRANTY; without even the implied warranty of               *
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                     *
19  * See the GNU Lesser General Public License for more details.              *
20  * You should have received a copy of the GNU Lesser General Public License *
21  * along with this library; if not, write to the Free Software Foundation,  *
22  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA            *
23  \**************************************************************************/
24
25
26        class browser
27        {
28                var $BROWSER_AGENT;
29                var $BROWSER_VER;
30                var $BROWSER_PLATFORM;
31                var $br;
32                var $p;
33                var $data;
34
35                function browser()
36                {
37                        $HTTP_USER_AGENT = $_SERVER['HTTP_USER_AGENT'];
38                        /*
39                                Determine browser and version
40                        */
41                        if(ereg('MSIE ([0-9].[0-9]{1,2})',$HTTP_USER_AGENT,$log_version))
42                        {
43                                $this->BROWSER_VER = $log_version[1];
44                                $this->BROWSER_AGENT = 'IE';
45                        }
46                        elseif(ereg('Opera ([0-9].[0-9]{1,2})',$HTTP_USER_AGENT,$log_version) ||
47                                ereg('Opera/([0-9].[0-9]{1,2})',$HTTP_USER_AGENT,$log_version))
48                        {
49                                $this->BROWSER_VER   = $log_version[1];
50                                $this->BROWSER_AGENT = 'OPERA';
51                        }
52                        elseif(eregi('iCab ([0-9].[0-9a-zA-Z]{1,4})',$HTTP_USER_AGENT,$log_version) ||
53                                eregi('iCab/([0-9].[0-9a-zA-Z]{1,4})',$HTTP_USER_AGENT,$log_version))
54                        {
55                                $this->BROWSER_VER   = $log_version[1];
56                                $this->BROWSER_AGENT = 'iCab';
57                        }
58                        elseif(ereg('Gecko',$HTTP_USER_AGENT,$log_version))
59                        {
60                                $this->BROWSER_VER   = $log_version[1];
61                                $this->BROWSER_AGENT = 'MOZILLA';
62                        }
63                        elseif(ereg('Konqueror/([0-9].[0-9].[0-9]{1,2})',$HTTP_USER_AGENT,$log_version) ||
64                                ereg('Konqueror/([0-9].[0-9]{1,2})',$HTTP_USER_AGENT,$log_version))
65                        {
66                                $this->BROWSER_VER=$log_version[1];
67                                $this->BROWSER_AGENT='Konqueror';
68                        }
69                        else
70                        {
71                                $this->BROWSER_VER=0;
72                                $this->BROWSER_AGENT='OTHER';
73                        }
74
75                        /*
76                                Determine platform
77                        */
78                        if(strstr($HTTP_USER_AGENT,'Win'))
79                        {
80                                $this->BROWSER_PLATFORM='Win';
81                        }
82                        elseif(strstr($HTTP_USER_AGENT,'Mac'))
83                        {
84                                $this->BROWSER_PLATFORM='Mac';
85                        }
86                        elseif(strstr($HTTP_USER_AGENT,'Linux'))
87                        {
88                                $this->BROWSER_PLATFORM='Linux';
89                        }
90                        elseif(strstr($HTTP_USER_AGENT,'Unix'))
91                        {
92                                $this->BROWSER_PLATFORM='Unix';
93                        }
94                        elseif(strstr($HTTP_USER_AGENT,'Beos'))
95                        {
96                                $this->BROWSER_PLATFORM='Beos';
97                        }
98                        else
99                        {
100                                $this->BROWSER_PLATFORM='Other';
101                        }
102
103                        /*
104                        echo "\n\nAgent: $HTTP_USER_AGENT";
105                        echo "\nIE: ".browser_is_ie();
106                        echo "\nMac: ".browser_is_mac();
107                        echo "\nWindows: ".browser_is_windows();
108                        echo "\nPlatform: ".browser_get_platform();
109                        echo "\nVersion: ".browser_get_version();
110                        echo "\nAgent: ".browser_get_agent();
111                        */
112
113                        // The br and p functions are supposed to return the correct
114                        // value for tags that do not need to be closed.  This is
115                        // per the xhmtl spec, so we need to fix this to include
116                        // all compliant browsers we know of.
117                        if($this->BROWSER_AGENT == 'IE')
118                        {
119                                $this->br = '<br/>';
120                                $this->p = '<p/>';
121                        }
122                        else
123                        {
124                                $this->br = '<br>';
125                                $this->p = '<p>';
126                        }
127                }
128
129                function return_array()
130                {
131                        $this->data = array(
132                                'agent'    => $this->get_agent(),
133                                'version'  => $this->get_version(),
134                                'platform' => $this->get_platform()
135                        );
136
137                        return $this->data;
138                }
139
140                function get_agent()
141                {
142                        return $this->BROWSER_AGENT;
143                }
144
145                function get_version()
146                {
147                        return $this->BROWSER_VER;
148                }
149
150                function get_platform()
151                {
152                        return $this->BROWSER_PLATFORM;
153                }
154
155                function is_linux()
156                {
157                        if($this->get_platform()=='Linux')
158                        {
159                                return true;
160                        }
161                        else
162                        {
163                                return false;
164                        }
165                }
166
167                function is_unix()
168                {
169                        if($this->get_platform()=='Unix')
170                        {
171                                return true;
172                        }
173                        else
174                        {
175                                return false;
176                        }
177                }
178
179                function is_beos()
180                {
181                        if($this->get_platform()=='Beos')
182                        {
183                                return true;
184                        }
185                        else
186                        {
187                                return false;
188                        }
189                }
190
191                function is_mac()
192                {
193                        if($this->get_platform()=='Mac')
194                        {
195                                return true;
196                        }
197                        else
198                        {
199                                return false;
200                        }
201                }
202
203                function is_windows()
204                {
205                        if($this->get_platform()=='Win')
206                        {
207                                return true;
208                        }
209                        else
210                        {
211                                return false;
212                        }
213                }
214
215                function is_ie()
216                {
217                        if($this->get_agent()=='IE')
218                        {
219                                return true;
220                        }
221                        else
222                        {
223                                return false;
224                        }
225                }
226
227                function is_netscape()
228                {
229                        if($this->get_agent()=='MOZILLA')
230                        {
231                                return true;
232                        }
233                        else
234                        {
235                                return false;
236                        }
237                }
238
239                function is_opera()
240                {
241                        if($this->get_agent()=='OPERA')
242                        {
243                                return true;
244                        }
245                        else
246                        {
247                                return false;
248                        }
249                }
250
251                // Echo content headers for file downloads
252                function content_header($fn='',$mime='',$length='',$nocache=True)
253                {
254                        // if no mime-type is given or it's the default binary-type, guess it from the extension
255                        if(empty($mime) || $mime == 'application/octet-stream')
256                        {
257                                $mime_magic = createObject('phpgwapi.mime_magic');
258                                $mime = $mime_magic->filename2mime($fn);
259                        }
260                        if($fn)
261                        {
262                                if($this->get_agent() == 'IE') // && browser_get_version() == "5.5")
263                                {
264                                        $attachment = '';
265                                }
266                                else
267                                {
268                                        $attachment = ' attachment;';
269                                }
270
271                                // Show this for all
272                                header('Content-disposition:'.$attachment.' filename="'.$fn.'"');
273                                header('Content-type: '.$mime);
274
275                                if($length)
276                                {
277                                        header('Content-length: '.$length);
278                                }
279
280                                if($nocache)
281                                {
282                                        header('Pragma: no-cache');
283                                        header('Pragma: public');
284                                        header('Expires: 0');
285                                        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
286                                }
287                        }
288                }
289        }
290?>
Note: See TracBrowser for help on using the repository browser.