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

Revision 5141, 8.2 KB checked in by wmerlotto, 12 years ago (diff)

Ticket #2305 - Enviando alteracoes, desenvolvidas internamente na Prognus, modulo phpgwapi.

  • 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                const PLATFORM_WINDOWS = 'Win';
36                const PLATFORM_MAC = 'Mac';
37                const PLATFORM_LINUX = 'Linux';
38                const PLATFORM_BEOS = 'Beos';
39                const PLATFORM_IPHONE = 'iPhone';
40                const PLATFORM_IPOD = 'iPod';
41                const PLATFORM_IPAD = 'iPad';
42                const PLATFORM_BLACKBERRY = 'BlackBerry';
43                const PLATFORM_NOKIA = 'Nokia';
44                const PLATFORM_ANDROID = 'Android';
45                const PLATFORM_UNIX = 'Unix';
46
47                function browser()
48                {
49                        $HTTP_USER_AGENT = $_SERVER['HTTP_USER_AGENT'];
50                        /*
51                                Determine browser and version
52                        */
53                        if(ereg('MSIE ([0-9].[0-9]{1,2})',$HTTP_USER_AGENT,$log_version))
54                        {
55                                $this->BROWSER_VER = $log_version[1];
56                                $this->BROWSER_AGENT = 'IE';
57                        }
58                        elseif(ereg('Opera ([0-9].[0-9]{1,2})',$HTTP_USER_AGENT,$log_version) ||
59                                ereg('Opera/([0-9].[0-9]{1,2})',$HTTP_USER_AGENT,$log_version))
60                        {
61                                $this->BROWSER_VER   = $log_version[1];
62                                $this->BROWSER_AGENT = 'OPERA';
63                        }
64                        elseif(eregi('iCab ([0-9].[0-9a-zA-Z]{1,4})',$HTTP_USER_AGENT,$log_version) ||
65                                eregi('iCab/([0-9].[0-9a-zA-Z]{1,4})',$HTTP_USER_AGENT,$log_version))
66                        {
67                                $this->BROWSER_VER   = $log_version[1];
68                                $this->BROWSER_AGENT = 'iCab';
69                        }
70                        elseif(ereg('Gecko',$HTTP_USER_AGENT,$log_version))
71                        {
72                                if(isset($log_version[1]))
73                                $this->BROWSER_VER   = $log_version[1];
74                                $this->BROWSER_AGENT = 'MOZILLA';
75                        }
76                        elseif(ereg('Konqueror/([0-9].[0-9].[0-9]{1,2})',$HTTP_USER_AGENT,$log_version) ||
77                                ereg('Konqueror/([0-9].[0-9]{1,2})',$HTTP_USER_AGENT,$log_version))
78                        {
79                                $this->BROWSER_VER=$log_version[1];
80                                $this->BROWSER_AGENT='Konqueror';
81                        }
82                        else
83                        {
84                                $this->BROWSER_VER=0;
85                                $this->BROWSER_AGENT='OTHER';
86                        }
87
88                        /*
89                                Determine platform
90                        */
91                        if(strstr($HTTP_USER_AGENT,'iPad'))
92                        {
93                                $this->BROWSER_PLATFORM = self::PLATFORM_IPAD;
94                        }
95                        elseif(strstr($HTTP_USER_AGENT,'iPod'))
96                        {
97                                $this->BROWSER_PLATFORM = self::PLATFORM_IPOD;
98                        }
99                        elseif(strstr($HTTP_USER_AGENT,'iPhone'))
100                        {
101                                $this->BROWSER_PLATFORM = self::PLATFORM_IPHONE;
102                        }
103                        elseif(strstr($HTTP_USER_AGENT,'BlackBerry'))
104                        {
105                                $this->BROWSER_PLATFORM = self::PLATFORM_BLACKBERRY;
106                        }
107                        elseif(strstr($HTTP_USER_AGENT,'Android'))
108                        {
109                                $this->BROWSER_PLATFORM = self::PLATFORM_ANDROID;
110                        }
111                        elseif(strstr($HTTP_USER_AGENT,'Nokia'))
112                        {
113                                $this->BROWSER_PLATFORM = self::PLATFORM_NOKIA;
114                        }                       
115                        elseif(strstr($HTTP_USER_AGENT,'Mac'))
116                        {
117                                $this->BROWSER_PLATFORM = self::PLATFORM_MAC;
118                        }
119                        elseif(strstr($HTTP_USER_AGENT,'Win'))
120                        {
121                                $this->BROWSER_PLATFORM = self::PLATFORM_WINDOWS;
122                        }                       
123                        elseif(strstr($HTTP_USER_AGENT,'Linux'))
124                        {
125                                $this->BROWSER_PLATFORM = self::PLATFORM_LINUX;
126                        }
127                        elseif(strstr($HTTP_USER_AGENT,'Unix'))
128                        {
129                                $this->BROWSER_PLATFORM = self::PLATFORM_UNIX;
130                        }
131                        elseif(strstr($HTTP_USER_AGENT,'Beos'))
132                        {
133                                $this->BROWSER_PLATFORM = self::PLATFORM_BEOS;
134                        }
135                        else
136                        {
137                                $this->BROWSER_PLATFORM='Other';
138                        }
139
140                        /*
141                        echo "\n\nAgent: $HTTP_USER_AGENT";
142                        echo "\nIE: ".browser_is_ie();
143                        echo "\nMac: ".browser_is_mac();
144                        echo "\nWindows: ".browser_is_windows();
145                        echo "\nPlatform: ".browser_get_platform();
146                        echo "\nVersion: ".browser_get_version();
147                        echo "\nAgent: ".browser_get_agent();
148                        */
149
150                        // The br and p functions are supposed to return the correct
151                        // value for tags that do not need to be closed.  This is
152                        // per the xhmtl spec, so we need to fix this to include
153                        // all compliant browsers we know of.
154                        if($this->BROWSER_AGENT == 'IE')
155                        {
156                                $this->br = '<br/>';
157                                $this->p = '<p/>';
158                        }
159                        else
160                        {
161                                $this->br = '<br>';
162                                $this->p = '<p>';
163                        }
164                }
165
166                function return_array()
167                {
168                        $this->data = array(
169                                'agent'    => $this->get_agent(),
170                                'version'  => $this->get_version(),
171                                'platform' => $this->get_platform()
172                        );
173
174                        return $this->data;
175                }
176
177                function get_agent()
178                {
179                        return $this->BROWSER_AGENT;
180                }
181
182                function get_version()
183                {
184                        return $this->BROWSER_VER;
185                }
186
187                function get_platform()
188                {
189                        return $this->BROWSER_PLATFORM;
190                }
191
192                function is_linux()
193                {
194                        return ($this->get_platform()==self::PLATFORM_LINUX);
195                }
196
197                function is_unix()
198                {
199                        return ($this->get_platform()==self::PLATFORM_UNIX);
200                }
201
202        function isMobile( )
203                {
204                        return $this -> is_ipad( )
205                                || $this -> is_iphone( )
206                                || $this -> is_nokia( )
207                                || $this -> is_ipod( )
208                                || $this -> is_blackberry( )
209                                || $this -> is_android( );
210                }
211
212                function is_beos()
213                {
214                        return ($this->get_platform()==self::PLATFORM_BEOS);
215                }
216
217                function is_mac()
218                {
219                        return ($this->get_platform()==self::PLATFORM_MAC);
220                }
221
222                function is_windows()
223                {
224                        return ($this->get_platform()==self::PLATFORM_WINDOWS);
225                }
226               
227                function is_ipad()
228                {
229                        return ($this->get_platform()==self::PLATFORM_IPAD);
230                }
231               
232                function is_iphone()
233                {
234                        return ($this->get_platform()==self::PLATFORM_IPHONE);
235                }
236               
237                function is_nokia()
238                {
239                        return ($this->get_platform()==self::PLATFORM_NOKIA);
240                }
241               
242                function is_ipod()
243                {
244                        return ($this->get_platform()==self::PLATFORM_IPOD);
245                }
246               
247                function is_blackberry()
248                {
249                        return ($this->get_platform()==self::PLATFORM_BLACKBERRY);
250                }
251               
252                function is_android()
253                {
254                        return ($this->get_platform()==self::PLATFORM_ANDROID);
255                }
256
257                function is_ie()
258                {
259                        if($this->get_agent()=='IE')
260                        {
261                                return true;
262                        }
263                        else
264                        {
265                                return false;
266                        }
267                }
268
269                function is_netscape()
270                {
271                        if($this->get_agent()=='MOZILLA')
272                        {
273                                return true;
274                        }
275                        else
276                        {
277                                return false;
278                        }
279                }
280
281                function is_opera()
282                {
283                        if($this->get_agent()=='OPERA')
284                        {
285                                return true;
286                        }
287                        else
288                        {
289                                return false;
290                        }
291                }
292
293                // Echo content headers for file downloads
294                function content_header($fn='',$mime='',$length='',$nocache=True)
295                {
296                        // if no mime-type is given or it's the default binary-type, guess it from the extension
297                        if(empty($mime) || $mime == 'application/octet-stream')
298                        {
299                                $mime_magic = createObject('phpgwapi.mime_magic');
300                                $mime = $mime_magic->filename2mime($fn);
301                        }
302                        if($fn)
303                        {
304                                if($this->get_agent() == 'IE') // && browser_get_version() == "5.5")
305                                {
306                                        $attachment = '';
307                                }
308                                else
309                                {
310                                        $attachment = ' attachment;';
311                                }
312
313                                // Show this for all
314                                header('Content-disposition:'.$attachment.' filename="'.$fn.'"');
315                                header('Content-type: '.$mime);
316
317                                if($length)
318                                {
319                                        header('Content-length: '.$length);
320                                }
321
322                                if($nocache)
323                                {
324                                        header('Pragma: no-cache');
325                                        header('Pragma: public');
326                                        header('Expires: 0');
327                                        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
328                                }
329                        }
330                }
331        }
332?>
Note: See TracBrowser for help on using the repository browser.