ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilBrowser.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4  //**************************************************************************\
5  //* Browser detect functions *
6  // This file written by Miles Lott <milosch@phpgroupware.org> *
7  // Majority of code borrowed from Sourceforge 2.5 *
8  // Copyright 1999-2000 (c) The SourceForge Crew - http://sourceforge.net *
9  // Browser detection functions for phpGroupWare developers *
10  // -------------------------------------------------------------------------*
11  // This library is borrowed from the phpGroupWare API *
12  // http://www.phpgroupware.org/api *
13  // Modifications made by Sascha Hofmann <sascha.hofmann@uni-koeln.de> *
14  // *
15  //**************************************************************************/
16 
22 class ilBrowser
23 {
27  var $br;
28  var $p;
29  var $data;
30 
31  function ilBrowser()
32  {
33  $HTTP_USER_AGENT = $_SERVER['HTTP_USER_AGENT'];
34  /*
35  Determine browser and version
36  */
37  if(ereg('MSIE ([0-9].[0-9]{1,2})',$HTTP_USER_AGENT,$log_version))
38  {
39  $this->BROWSER_VER = $log_version[1];
40  $this->BROWSER_AGENT = 'IE';
41  }
42  elseif(ereg('Opera ([0-9].[0-9]{1,2})',$HTTP_USER_AGENT,$log_version) ||
43  ereg('Opera/([0-9].[0-9]{1,2})',$HTTP_USER_AGENT,$log_version))
44  {
45  $this->BROWSER_VER = $log_version[1];
46  $this->BROWSER_AGENT = 'OPERA';
47  }
48  elseif(ereg('Safari ([0-9/.]*)',$HTTP_USER_AGENT,$log_version) ||
49  ereg('Safari/([0-9/.]*)',$HTTP_USER_AGENT,$log_version))
50  {
51  $this->BROWSER_VER = $log_version[1];
52  $this->BROWSER_AGENT = 'Safari';
53  }
54  elseif(ereg('Firefox ([0-9/.]*)',$HTTP_USER_AGENT,$log_version) ||
55  ereg('Firefox/([0-9/.]*)',$HTTP_USER_AGENT,$log_version))
56  {
57  $this->BROWSER_VER = $log_version[1];
58  $this->BROWSER_AGENT = 'Firefox';
59  }
60  elseif(eregi('iCab ([0-9].[0-9a-zA-Z]{1,4})',$HTTP_USER_AGENT,$log_version) ||
61  eregi('iCab/([0-9].[0-9a-zA-Z]{1,4})',$HTTP_USER_AGENT,$log_version))
62  {
63  $this->BROWSER_VER = $log_version[1];
64  $this->BROWSER_AGENT = 'iCab';
65  }
66  elseif(eregi('Mozilla ([0-9].[0-9a-zA-Z]{1,4})',$HTTP_USER_AGENT,$log_version) ||
67  eregi('Mozilla/([0-9].[0-9a-zA-Z]{1,4})',$HTTP_USER_AGENT,$log_version))
68  {
69  $this->BROWSER_VER = $log_version[1];
70  if (ereg('Gecko',$HTTP_USER_AGENT,$log_version))
71  {
72  $this->BROWSER_AGENT = 'Mozilla';
73  }
74  else
75  {
76  $this->BROWSER_AGENT = 'Netscape';
77  }
78  }
79  elseif(ereg('Konqueror/([0-9].[0-9].[0-9]{1,2})',$HTTP_USER_AGENT,$log_version) ||
80  ereg('Konqueror/([0-9].[0-9]{1,2})',$HTTP_USER_AGENT,$log_version))
81  {
82  $this->BROWSER_VER=$log_version[1];
83  $this->BROWSER_AGENT='Konqueror';
84  }
85  else
86  {
87  $this->BROWSER_VER=0;
88  $this->BROWSER_AGENT='OTHER';
89  }
90 
91  /*
92  Determine platform
93  */
94  if(strstr($HTTP_USER_AGENT,'Win'))
95  {
96  $this->BROWSER_PLATFORM='Win';
97  }
98  elseif(strstr($HTTP_USER_AGENT,'Mac'))
99  {
100  $this->BROWSER_PLATFORM='Mac';
101  }
102  elseif(strstr($HTTP_USER_AGENT,'Linux'))
103  {
104  $this->BROWSER_PLATFORM='Linux';
105  }
106  elseif(strstr($HTTP_USER_AGENT,'Unix'))
107  {
108  $this->BROWSER_PLATFORM='Unix';
109  }
110  elseif(strstr($HTTP_USER_AGENT,'Beos'))
111  {
112  $this->BROWSER_PLATFORM='Beos';
113  }
114  else
115  {
116  $this->BROWSER_PLATFORM='Other';
117  }
118 
119 /*
120  echo "<br>Agent: $HTTP_USER_AGENT";
121  echo "<br><b>Browser</b>";
122  echo "<br>IE: ".$this->isIE();
123  echo "<br>Netscape: ".$this->isNetscape();
124  echo "<br>Mozilla: ".$this->isMozilla();
125  echo "<br>Firefox: ".$this->isFirefox();
126  echo "<br>Safari: ".$this->isSafari();
127  echo "<br>Opera: ".$this->isOpera();
128  echo "<br><b>OS</b>";
129  echo "<br>Mac: ".$this->isMac();
130  echo "<br>Windows: ".$this->isWindows();
131  echo "<br>Linux: ".$this->isLinux();
132  echo "<br>Unix: ".$this->isUnix();
133  echo "<br>Beos: ".$this->isBeos();
134  echo "<br><b>Summary</b>";
135  echo "<br>OS: ".$this->getPlatform();
136  echo "<br>Version: ".$this->getVersion(false);
137  echo "<br>Agent: ".$this->getAgent();
138 */
139 
140  // The br and p functions are supposed to return the correct
141  // value for tags that do not need to be closed. This is
142  // per the xhmtl spec, so we need to fix this to include
143  // all compliant browsers we know of.
144  if($this->BROWSER_AGENT == 'IE')
145  {
146  $this->br = '<br/>';
147  $this->p = '<p/>';
148  }
149  else
150  {
151  $this->br = '<br>';
152  $this->p = '<p>';
153  }
154  }
155 
156  function returnArray()
157  {
158  $this->data = array(
159  'agent' => $this->getAgent(),
160  'version' => $this->getVersion(false),
161  'platform' => $this->getPlatform()
162  );
163 
164  return $this->data;
165  }
166 
167  function getAgent()
168  {
169  return $this->BROWSER_AGENT;
170  }
171 
172  function getVersion($a_as_array = true)
173  {
174  return explode(".", $this->BROWSER_VER);
175  }
176 
177  function getPlatform()
178  {
180  }
181 
182  function isLinux()
183  {
184  if($this->getPlatform()=='Linux')
185  {
186  return true;
187  }
188  else
189  {
190  return false;
191  }
192  }
193 
194  function isUnix()
195  {
196  if($this->getPlatform()=='Unix')
197  {
198  return true;
199  }
200  else
201  {
202  return false;
203  }
204  }
205 
206  function isBeos()
207  {
208  if($this->getPlatform()=='Beos')
209  {
210  return true;
211  }
212  else
213  {
214  return false;
215  }
216  }
217 
218  function isMac()
219  {
220  if($this->getPlatform()=='Mac')
221  {
222  return true;
223  }
224  else
225  {
226  return false;
227  }
228  }
229 
230  function isWindows()
231  {
232  if($this->getPlatform()=='Win')
233  {
234  return true;
235  }
236  else
237  {
238  return false;
239  }
240  }
241 
242  function isIE()
243  {
244  if($this->getAgent()=='IE')
245  {
246  return true;
247  }
248  else
249  {
250  return false;
251  }
252  }
253 
257  function isNetscape()
258  {
259  if($this->getAgent()=='Netscape')
260  {
261  return true;
262  }
263  else
264  {
265  return false;
266  }
267  }
268 
272  function isMozilla()
273  {
274  if($this->getAgent()=='Mozilla')
275  {
276  return true;
277  }
278  else
279  {
280  return false;
281  }
282  }
283 
284  function isOpera()
285  {
286  if($this->getAgent()=='OPERA')
287  {
288  return true;
289  }
290  else
291  {
292  return false;
293  }
294  }
295 
296  function isSafari()
297  {
298  if($this->getAgent()=='Safari')
299  {
300  return true;
301  }
302  else
303  {
304  return false;
305  }
306  }
307 
308  function isFirefox()
309  {
310  if($this->getAgent()=='Firefox')
311  {
312  return true;
313  }
314  else
315  {
316  return false;
317  }
318  }
319 
320 }
321 
322 ?>