mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-23 16:33:17 +01:00
295 lines
6.6 KiB
PHP
295 lines
6.6 KiB
PHP
<?php
|
|
/**************************************************************************\
|
|
* phpGroupWare API - Browser detect functions *
|
|
* This file written by Miles Lott <milosch@phpgroupware.org> *
|
|
* Majority of code borrowed from Sourceforge 2.5 *
|
|
* Copyright 1999-2000 (c) The SourceForge Crew - http://sourceforge.net *
|
|
* Browser detection functions for phpGroupWare developers *
|
|
* -------------------------------------------------------------------------*
|
|
* This library is part of the phpGroupWare API *
|
|
* http://www.phpgroupware.org/api *
|
|
* ------------------------------------------------------------------------ *
|
|
* This library is free software; you can redistribute it and/or modify it *
|
|
* under the terms of the GNU Lesser General Public License as published by *
|
|
* the Free Software Foundation; either version 2.1 of the License, *
|
|
* or any later version. *
|
|
* This library is distributed in the hope that it will be useful, but *
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
|
* See the GNU Lesser General Public License for more details. *
|
|
* You should have received a copy of the GNU Lesser General Public License *
|
|
* along with this library; if not, write to the Free Software Foundation, *
|
|
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
|
|
\**************************************************************************/
|
|
|
|
/* $Id$ */
|
|
|
|
class browser
|
|
{
|
|
var $BROWSER_AGENT;
|
|
var $BROWSER_VER;
|
|
var $BROWSER_PLATFORM;
|
|
var $br;
|
|
var $p;
|
|
var $data;
|
|
|
|
function browser ()
|
|
{
|
|
$HTTP_USER_AGENT = $GLOBALS['HTTP_USER_AGENT'];
|
|
/*
|
|
Determine browser and version
|
|
*/
|
|
if(ereg('MSIE ([0-9].[0-9]{1,2})',$HTTP_USER_AGENT,$log_version))
|
|
{
|
|
$this->BROWSER_VER = $log_version[1];
|
|
$this->BROWSER_AGENT = 'IE';
|
|
}
|
|
elseif(ereg('Opera ([0-9].[0-9]{1,2})',$HTTP_USER_AGENT,$log_version) ||
|
|
ereg('Opera/([0-9].[0-9]{1,2})',$HTTP_USER_AGENT,$log_version))
|
|
{
|
|
$this->BROWSER_VER = $log_version[1];
|
|
$this->BROWSER_AGENT = 'OPERA';
|
|
}
|
|
elseif(eregi('iCab ([0-9].[0-9a-zA-Z]{1,4})',$HTTP_USER_AGENT,$log_version) ||
|
|
eregi('iCab/([0-9].[0-9a-zA-Z]{1,4})',$HTTP_USER_AGENT,$log_version))
|
|
{
|
|
$this->BROWSER_VER = $log_version[1];
|
|
$this->BROWSER_AGENT = 'iCab';
|
|
}
|
|
elseif(eregi('Netscape6/([0-9].[0-9a-zA-Z]{1,4})',$HTTP_USER_AGENT,$log_version))
|
|
{
|
|
$this->BROWSER_VER = $log_version[1];
|
|
$this->BROWSER_AGENT = 'Netscape';
|
|
}
|
|
elseif(ereg('Konqueror/([0-9].[0-9].[0-9]{1,2})',$HTTP_USER_AGENT,$log_version) ||
|
|
ereg( 'Konqueror/([0-9].[0-9]{1,2})',$HTTP_USER_AGENT,$log_version))
|
|
{
|
|
$this->BROWSER_VER = $log_version[1];
|
|
$this->BROWSER_AGENT = 'Konqueror';
|
|
}
|
|
elseif(ereg('Mozilla/([0-9].[0-9]{1,2})',$HTTP_USER_AGENT,$log_version))
|
|
{
|
|
$this->BROWSER_VER = $log_version[1];
|
|
$this->BROWSER_AGENT = 'MOZILLA';
|
|
}
|
|
else
|
|
{
|
|
$this->BROWSER_VER = 0;
|
|
$this->BROWSER_AGENT = 'OTHER';
|
|
}
|
|
|
|
/*
|
|
Determine platform
|
|
*/
|
|
if(strstr($HTTP_USER_AGENT,'Win'))
|
|
{
|
|
$this->BROWSER_PLATFORM='Win';
|
|
}
|
|
elseif(strstr($HTTP_USER_AGENT,'Mac'))
|
|
{
|
|
$this->BROWSER_PLATFORM='Mac';
|
|
}
|
|
elseif(strstr($HTTP_USER_AGENT,'Linux'))
|
|
{
|
|
$this->BROWSER_PLATFORM='Linux';
|
|
}
|
|
elseif(strstr($HTTP_USER_AGENT,'Unix'))
|
|
{
|
|
$this->BROWSER_PLATFORM='Unix';
|
|
}
|
|
elseif(strstr($HTTP_USER_AGENT,'Beos'))
|
|
{
|
|
$this->BROWSER_PLATFORM='Beos';
|
|
}
|
|
else
|
|
{
|
|
$this->BROWSER_PLATFORM='Other';
|
|
}
|
|
|
|
/*
|
|
echo "\n\nAgent: $HTTP_USER_AGENT";
|
|
echo "\nIE: " . $this->is_ie();
|
|
echo "\nMac: " . $this->is_mac();
|
|
echo "\nWindows: " . $this->is_windows();
|
|
echo "\nPlatform: " . $this->get_platform();
|
|
echo "\nVersion: " . $this->get_version();
|
|
echo "\nAgent: " . $this->get_agent();
|
|
*/
|
|
|
|
// The br and p vars are supposed to return the correct
|
|
// value for tags that do not need to be closed. This is
|
|
// per the xhmtl spec, so we need to fix this to include
|
|
// all compliant browsers we know of.
|
|
if($this->BROWSER_AGENT == 'IE')
|
|
{
|
|
$this->br = '<br/>';
|
|
$this->p = '<p/>';
|
|
}
|
|
else
|
|
{
|
|
$this->br = '<br>';
|
|
$this->p = '<p>';
|
|
}
|
|
}
|
|
|
|
function return_array()
|
|
{
|
|
$this->data = array(
|
|
'agent' => $this->get_agent(),
|
|
'version' => $this->get_version(),
|
|
'platform' => $this->get_platform()
|
|
);
|
|
|
|
return $this->data;
|
|
}
|
|
|
|
function get_agent()
|
|
{
|
|
return $this->BROWSER_AGENT;
|
|
}
|
|
|
|
function get_version()
|
|
{
|
|
return $this->BROWSER_VER;
|
|
}
|
|
|
|
function get_platform()
|
|
{
|
|
return $this->BROWSER_PLATFORM;
|
|
}
|
|
|
|
function is_linux()
|
|
{
|
|
if($this->get_platform()=='Linux')
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
function is_unix()
|
|
{
|
|
if($this->get_platform()=='Unix')
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
function is_beos()
|
|
{
|
|
if($this->get_platform()=='Beos')
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
function is_mac()
|
|
{
|
|
if($this->get_platform()=='Mac')
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
function is_windows()
|
|
{
|
|
if($this->get_platform()=='Win')
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
function is_ie()
|
|
{
|
|
if($this->get_agent()=='IE')
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
function is_netscape()
|
|
{
|
|
if($this->get_agent()=='MOZILLA')
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
function is_opera()
|
|
{
|
|
if($this->get_agent()=='OPERA')
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// Echo content headers for file downloads
|
|
function content_header($fn='',$mime='',$length='',$nocache=True)
|
|
{
|
|
if(!$mime)
|
|
{
|
|
$mime='application/octet-stream';
|
|
}
|
|
if($fn)
|
|
{
|
|
if($this->get_agent() == 'IE')
|
|
{
|
|
$attachment = '';
|
|
header('Cache-control: private');
|
|
}
|
|
else
|
|
{
|
|
$attachment = ' attachment;';
|
|
}
|
|
|
|
header('Content-type: ' . $mime);
|
|
header('Content-disposition:' . $attachment . ' filename="' . $fn . '"');
|
|
|
|
if($length)
|
|
{
|
|
header('Content-length: '.$length);
|
|
}
|
|
|
|
if($nocache)
|
|
{
|
|
header('Pragma: no-cache');
|
|
header('Pragma: public');
|
|
header('Expires: 0');
|
|
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
?>
|