[ Index ]
 

Code source de eGroupWare 1.2.106-2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/phpgwapi/inc/ -> class.browser.inc.php (source)

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


Généré le : Sun Feb 25 17:20:01 2007 par Balluche grâce à PHPXref 0.7