source: branches/2.2.0.1/phpgwapi/inc/class.browser.inc.php @ 4252

Revision 4252, 8.2 KB checked in by rafaelraymundo, 13 years ago (diff)

Ticket #1726 - Permitindo o envio de mail em texto puro. r4202

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