source: branches/2.4/phpgwapi/inc/class.browser.inc.php @ 6731

Revision 6731, 8.5 KB checked in by eduardow, 12 years ago (diff)

Ticket #2607 - Acesso via Windows phone não redireciona página automaticamente.

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