ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilBrowser.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 
25 
26  //**************************************************************************\
27  //* Browser detect functions *
28  // This file written by Miles Lott <milosch@phpgroupware.org> *
29  // Majority of code borrowed from Sourceforge 2.5 *
30  // Copyright 1999-2000 (c) The SourceForge Crew - http://sourceforge.net *
31  // Browser detection functions for phpGroupWare developers *
32  // -------------------------------------------------------------------------*
33  // This library is borrowed from the phpGroupWare API *
34  // http://www.phpgroupware.org/api *
35  // Modifications made by Sascha Hofmann <sascha.hofmann@uni-koeln.de> *
36  // *
37  //**************************************************************************/
38 
44 class ilBrowser
45 {
49  var $br;
50  var $p;
51  var $data;
52 
53  function ilBrowser()
54  {
55  $HTTP_USER_AGENT = $_SERVER['HTTP_USER_AGENT'];
56  /*
57  Determine browser and version
58  */
59  if(ereg('MSIE ([0-9].[0-9]{1,2})',$HTTP_USER_AGENT,$log_version))
60  {
61  $this->BROWSER_VER = $log_version[1];
62  $this->BROWSER_AGENT = 'IE';
63  }
64  elseif(ereg('Opera ([0-9].[0-9]{1,2})',$HTTP_USER_AGENT,$log_version) ||
65  ereg('Opera/([0-9].[0-9]{1,2})',$HTTP_USER_AGENT,$log_version))
66  {
67  $this->BROWSER_VER = $log_version[1];
68  $this->BROWSER_AGENT = 'OPERA';
69  }
70  elseif(ereg('Safari ([0-9/.]*)',$HTTP_USER_AGENT,$log_version) ||
71  ereg('Safari/([0-9/.]*)',$HTTP_USER_AGENT,$log_version))
72  {
73  $this->BROWSER_VER = $log_version[1];
74  $this->BROWSER_AGENT = 'Safari';
75  }
76  elseif(ereg('Firefox ([0-9/.]*)',$HTTP_USER_AGENT,$log_version) ||
77  ereg('Firefox/([0-9/.]*)',$HTTP_USER_AGENT,$log_version))
78  {
79  $this->BROWSER_VER = $log_version[1];
80  $this->BROWSER_AGENT = 'Firefox';
81  }
82  elseif(eregi('iCab ([0-9].[0-9a-zA-Z]{1,4})',$HTTP_USER_AGENT,$log_version) ||
83  eregi('iCab/([0-9].[0-9a-zA-Z]{1,4})',$HTTP_USER_AGENT,$log_version))
84  {
85  $this->BROWSER_VER = $log_version[1];
86  $this->BROWSER_AGENT = 'iCab';
87  }
88  elseif(eregi('Mozilla ([0-9].[0-9a-zA-Z]{1,4})',$HTTP_USER_AGENT,$log_version) ||
89  eregi('Mozilla/([0-9].[0-9a-zA-Z]{1,4})',$HTTP_USER_AGENT,$log_version))
90  {
91  $this->BROWSER_VER = $log_version[1];
92  if (ereg('Gecko',$HTTP_USER_AGENT,$log_version))
93  {
94  $this->BROWSER_AGENT = 'Mozilla';
95  }
96  else
97  {
98  $this->BROWSER_AGENT = 'Netscape';
99  }
100  }
101  elseif(ereg('Konqueror/([0-9].[0-9].[0-9]{1,2})',$HTTP_USER_AGENT,$log_version) ||
102  ereg('Konqueror/([0-9].[0-9]{1,2})',$HTTP_USER_AGENT,$log_version))
103  {
104  $this->BROWSER_VER=$log_version[1];
105  $this->BROWSER_AGENT='Konqueror';
106  }
107  else
108  {
109  $this->BROWSER_VER=0;
110  $this->BROWSER_AGENT='OTHER';
111  }
112 
113  /*
114  Determine platform
115  */
116  if(strstr($HTTP_USER_AGENT,'Win'))
117  {
118  $this->BROWSER_PLATFORM='Win';
119  }
120  elseif(strstr($HTTP_USER_AGENT,'Mac'))
121  {
122  $this->BROWSER_PLATFORM='Mac';
123  }
124  elseif(strstr($HTTP_USER_AGENT,'Linux'))
125  {
126  $this->BROWSER_PLATFORM='Linux';
127  }
128  elseif(strstr($HTTP_USER_AGENT,'Unix'))
129  {
130  $this->BROWSER_PLATFORM='Unix';
131  }
132  elseif(strstr($HTTP_USER_AGENT,'Beos'))
133  {
134  $this->BROWSER_PLATFORM='Beos';
135  }
136  else
137  {
138  $this->BROWSER_PLATFORM='Other';
139  }
140 
141 /*
142  echo "<br>Agent: $HTTP_USER_AGENT";
143  echo "<br><b>Browser</b>";
144  echo "<br>IE: ".$this->isIE();
145  echo "<br>Netscape: ".$this->isNetscape();
146  echo "<br>Mozilla: ".$this->isMozilla();
147  echo "<br>Firefox: ".$this->isFirefox();
148  echo "<br>Safari: ".$this->isSafari();
149  echo "<br>Opera: ".$this->isOpera();
150  echo "<br><b>OS</b>";
151  echo "<br>Mac: ".$this->isMac();
152  echo "<br>Windows: ".$this->isWindows();
153  echo "<br>Linux: ".$this->isLinux();
154  echo "<br>Unix: ".$this->isUnix();
155  echo "<br>Beos: ".$this->isBeos();
156  echo "<br><b>Summary</b>";
157  echo "<br>OS: ".$this->getPlatform();
158  echo "<br>Version: ".$this->getVersion(false);
159  echo "<br>Agent: ".$this->getAgent();
160 */
161 
162  // The br and p functions are supposed to return the correct
163  // value for tags that do not need to be closed. This is
164  // per the xhmtl spec, so we need to fix this to include
165  // all compliant browsers we know of.
166  if($this->BROWSER_AGENT == 'IE')
167  {
168  $this->br = '<br/>';
169  $this->p = '<p/>';
170  }
171  else
172  {
173  $this->br = '<br>';
174  $this->p = '<p>';
175  }
176  }
177 
178  function returnArray()
179  {
180  $this->data = array(
181  'agent' => $this->getAgent(),
182  'version' => $this->getVersion(false),
183  'platform' => $this->getPlatform()
184  );
185 
186  return $this->data;
187  }
188 
189  function getAgent()
190  {
191  return $this->BROWSER_AGENT;
192  }
193 
194  function getVersion($a_as_array = true)
195  {
196  return explode(".", $this->BROWSER_VER);
197  }
198 
199  function getPlatform()
200  {
202  }
203 
204  function isLinux()
205  {
206  if($this->getPlatform()=='Linux')
207  {
208  return true;
209  }
210  else
211  {
212  return false;
213  }
214  }
215 
216  function isUnix()
217  {
218  if($this->getPlatform()=='Unix')
219  {
220  return true;
221  }
222  else
223  {
224  return false;
225  }
226  }
227 
228  function isBeos()
229  {
230  if($this->getPlatform()=='Beos')
231  {
232  return true;
233  }
234  else
235  {
236  return false;
237  }
238  }
239 
240  function isMac()
241  {
242  if($this->getPlatform()=='Mac')
243  {
244  return true;
245  }
246  else
247  {
248  return false;
249  }
250  }
251 
252  function isWindows()
253  {
254  if($this->getPlatform()=='Win')
255  {
256  return true;
257  }
258  else
259  {
260  return false;
261  }
262  }
263 
264  function isIE()
265  {
266  if($this->getAgent()=='IE')
267  {
268  return true;
269  }
270  else
271  {
272  return false;
273  }
274  }
275 
279  function isNetscape()
280  {
281  if($this->getAgent()=='Netscape')
282  {
283  return true;
284  }
285  else
286  {
287  return false;
288  }
289  }
290 
294  function isMozilla()
295  {
296  if($this->getAgent()=='Mozilla')
297  {
298  return true;
299  }
300  else
301  {
302  return false;
303  }
304  }
305 
306  function isOpera()
307  {
308  if($this->getAgent()=='OPERA')
309  {
310  return true;
311  }
312  else
313  {
314  return false;
315  }
316  }
317 
318  function isSafari()
319  {
320  if($this->getAgent()=='Safari')
321  {
322  return true;
323  }
324  else
325  {
326  return false;
327  }
328  }
329 
330  function isFirefox()
331  {
332  if($this->getAgent()=='Firefox')
333  {
334  return true;
335  }
336  else
337  {
338  return false;
339  }
340  }
341 
342 }
343 
344 ?>