2001-04-07 16:19:28 +02:00
|
|
|
<?php
|
|
|
|
/**************************************************************************\
|
2004-05-05 14:06:13 +02:00
|
|
|
* eGroupWare API - Browser detect functions *
|
|
|
|
* This file written by Miles Lott <milosch@groupwhere.org> *
|
2001-04-07 16:19:28 +02:00
|
|
|
* Majority of code borrowed from Sourceforge 2.5 *
|
|
|
|
* Copyright 1999-2000 (c) The SourceForge Crew - http://sourceforge.net *
|
2004-05-05 14:06:13 +02:00
|
|
|
* Browser detection functions for eGroupWare developers *
|
2001-04-07 16:19:28 +02:00
|
|
|
* -------------------------------------------------------------------------*
|
2004-05-05 14:06:13 +02:00
|
|
|
* This library is part of the eGroupWare API *
|
|
|
|
* http://www.egroupware.org/api *
|
2001-04-07 16:19:28 +02:00
|
|
|
* ------------------------------------------------------------------------ *
|
|
|
|
* 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;
|
2001-05-11 23:35:34 +02:00
|
|
|
var $br;
|
|
|
|
var $p;
|
2001-04-07 16:59:00 +02:00
|
|
|
var $data;
|
2001-04-07 16:19:28 +02:00
|
|
|
|
2003-08-28 16:31:11 +02:00
|
|
|
function browser()
|
2001-04-07 16:19:28 +02:00
|
|
|
{
|
2003-09-28 14:31:16 +02:00
|
|
|
$HTTP_USER_AGENT = $_SERVER['HTTP_USER_AGENT'];
|
2001-04-07 16:19:28 +02:00
|
|
|
/*
|
|
|
|
Determine browser and version
|
|
|
|
*/
|
2009-06-08 18:21:14 +02:00
|
|
|
if(preg_match('/MSIE ([0-9].[0-9]{1,2})/',$HTTP_USER_AGENT,$log_version))
|
2001-04-07 16:19:28 +02:00
|
|
|
{
|
2001-04-13 07:03:18 +02:00
|
|
|
$this->BROWSER_VER = $log_version[1];
|
|
|
|
$this->BROWSER_AGENT = 'IE';
|
2001-04-07 16:19:28 +02:00
|
|
|
}
|
2009-06-08 18:21:14 +02:00
|
|
|
elseif(preg_match('/Opera ([0-9].[0-9]{1,2})/',$HTTP_USER_AGENT,$log_version) ||
|
|
|
|
preg_match('/Opera\\/([0-9].[0-9]{1,2})/',$HTTP_USER_AGENT,$log_version))
|
2001-04-07 16:19:28 +02:00
|
|
|
{
|
2001-04-13 07:03:18 +02:00
|
|
|
$this->BROWSER_VER = $log_version[1];
|
|
|
|
$this->BROWSER_AGENT = 'OPERA';
|
|
|
|
}
|
2009-06-08 18:21:14 +02:00
|
|
|
elseif(preg_match('/iCab ([0-9].[0-9a-zA-Z]{1,4})/i',$HTTP_USER_AGENT,$log_version) ||
|
|
|
|
preg_match('/iCab\\/([0-9].[0-9a-zA-Z]{1,4})/i',$HTTP_USER_AGENT,$log_version))
|
2001-04-13 07:03:18 +02:00
|
|
|
{
|
|
|
|
$this->BROWSER_VER = $log_version[1];
|
|
|
|
$this->BROWSER_AGENT = 'iCab';
|
|
|
|
}
|
2009-06-08 18:21:14 +02:00
|
|
|
elseif(strpos($HTTP_USER_AGENT,'Gecko') !== false)
|
2001-04-13 07:03:18 +02:00
|
|
|
{
|
|
|
|
$this->BROWSER_VER = $log_version[1];
|
2003-09-28 14:31:16 +02:00
|
|
|
$this->BROWSER_AGENT = 'MOZILLA';
|
2001-04-07 16:19:28 +02:00
|
|
|
}
|
2009-06-08 18:21:14 +02:00
|
|
|
elseif(preg_match('/Konqueror\\/([0-9].[0-9].[0-9]{1,2})/',$HTTP_USER_AGENT,$log_version) ||
|
|
|
|
preg_match('/Konqueror\\/([0-9].[0-9]{1,2})/',$HTTP_USER_AGENT,$log_version))
|
2001-05-31 07:06:16 +02:00
|
|
|
{
|
2003-08-28 16:31:11 +02:00
|
|
|
$this->BROWSER_VER=$log_version[1];
|
|
|
|
$this->BROWSER_AGENT='Konqueror';
|
2001-05-31 07:06:16 +02:00
|
|
|
}
|
2001-04-07 16:19:28 +02:00
|
|
|
else
|
|
|
|
{
|
2003-08-28 16:31:11 +02:00
|
|
|
$this->BROWSER_VER=0;
|
|
|
|
$this->BROWSER_AGENT='OTHER';
|
2001-04-07 16:19:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Determine platform
|
|
|
|
*/
|
2007-04-30 07:42:05 +02:00
|
|
|
if(strpos($HTTP_USER_AGENT,'Win') !== false)
|
2001-04-07 16:19:28 +02:00
|
|
|
{
|
|
|
|
$this->BROWSER_PLATFORM='Win';
|
|
|
|
}
|
2007-04-30 07:42:05 +02:00
|
|
|
elseif(strpos($HTTP_USER_AGENT,'Mac') !== false)
|
2001-04-07 16:19:28 +02:00
|
|
|
{
|
|
|
|
$this->BROWSER_PLATFORM='Mac';
|
|
|
|
}
|
2007-04-30 07:42:05 +02:00
|
|
|
elseif(strpos($HTTP_USER_AGENT,'Linux') !== false)
|
2001-04-07 16:19:28 +02:00
|
|
|
{
|
|
|
|
$this->BROWSER_PLATFORM='Linux';
|
|
|
|
}
|
2007-04-30 07:42:05 +02:00
|
|
|
elseif(strpos($HTTP_USER_AGENT,'Unix') !== false)
|
2001-04-07 16:19:28 +02:00
|
|
|
{
|
|
|
|
$this->BROWSER_PLATFORM='Unix';
|
|
|
|
}
|
2007-04-30 07:42:05 +02:00
|
|
|
elseif(strpos($HTTP_USER_AGENT,'Beos') !== false)
|
2001-04-07 16:34:37 +02:00
|
|
|
{
|
|
|
|
$this->BROWSER_PLATFORM='Beos';
|
|
|
|
}
|
2001-04-07 16:19:28 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
$this->BROWSER_PLATFORM='Other';
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
echo "\n\nAgent: $HTTP_USER_AGENT";
|
2003-08-28 16:31:11 +02:00
|
|
|
echo "\nIE: ".browser_is_ie();
|
|
|
|
echo "\nMac: ".browser_is_mac();
|
|
|
|
echo "\nWindows: ".browser_is_windows();
|
|
|
|
echo "\nPlatform: ".browser_get_platform();
|
|
|
|
echo "\nVersion: ".browser_get_version();
|
|
|
|
echo "\nAgent: ".browser_get_agent();
|
2001-04-07 16:19:28 +02:00
|
|
|
*/
|
2001-05-11 23:35:34 +02:00
|
|
|
|
2003-08-28 16:31:11 +02:00
|
|
|
// The br and p functions are supposed to return the correct
|
2001-05-11 23:35:34 +02:00
|
|
|
// 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.
|
2002-04-13 23:38:34 +02:00
|
|
|
if($this->BROWSER_AGENT == 'IE')
|
2001-05-11 23:35:34 +02:00
|
|
|
{
|
|
|
|
$this->br = '<br/>';
|
2003-08-28 16:31:11 +02:00
|
|
|
$this->p = '<p/>';
|
2001-05-11 23:35:34 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$this->br = '<br>';
|
2003-08-28 16:31:11 +02:00
|
|
|
$this->p = '<p>';
|
2001-05-11 23:35:34 +02:00
|
|
|
}
|
2001-04-07 16:19:28 +02:00
|
|
|
}
|
|
|
|
|
2001-04-07 16:59:00 +02:00
|
|
|
function return_array()
|
|
|
|
{
|
|
|
|
$this->data = array(
|
2001-04-07 17:22:57 +02:00
|
|
|
'agent' => $this->get_agent(),
|
|
|
|
'version' => $this->get_version(),
|
|
|
|
'platform' => $this->get_platform()
|
2001-04-07 16:59:00 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
return $this->data;
|
|
|
|
}
|
|
|
|
|
2001-04-07 17:22:57 +02:00
|
|
|
function get_agent()
|
2001-04-07 16:19:28 +02:00
|
|
|
{
|
|
|
|
return $this->BROWSER_AGENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_version()
|
|
|
|
{
|
|
|
|
return $this->BROWSER_VER;
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_platform()
|
|
|
|
{
|
|
|
|
return $this->BROWSER_PLATFORM;
|
|
|
|
}
|
|
|
|
|
2001-04-07 16:34:37 +02:00
|
|
|
function is_linux()
|
|
|
|
{
|
2002-04-13 23:38:34 +02:00
|
|
|
if($this->get_platform()=='Linux')
|
2001-04-07 16:34:37 +02:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function is_unix()
|
|
|
|
{
|
2002-04-13 23:38:34 +02:00
|
|
|
if($this->get_platform()=='Unix')
|
2001-04-07 16:34:37 +02:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function is_beos()
|
|
|
|
{
|
2002-04-13 23:38:34 +02:00
|
|
|
if($this->get_platform()=='Beos')
|
2001-04-07 16:34:37 +02:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-04-07 16:19:28 +02:00
|
|
|
function is_mac()
|
|
|
|
{
|
2002-04-13 23:38:34 +02:00
|
|
|
if($this->get_platform()=='Mac')
|
2001-04-07 16:19:28 +02:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function is_windows()
|
|
|
|
{
|
2002-04-13 23:38:34 +02:00
|
|
|
if($this->get_platform()=='Win')
|
2001-04-07 16:19:28 +02:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function is_ie()
|
|
|
|
{
|
2002-04-13 23:38:34 +02:00
|
|
|
if($this->get_agent()=='IE')
|
2001-04-07 16:19:28 +02:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function is_netscape()
|
|
|
|
{
|
2002-04-13 23:38:34 +02:00
|
|
|
if($this->get_agent()=='MOZILLA')
|
2001-04-07 16:19:28 +02:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2001-04-13 07:03:18 +02:00
|
|
|
|
2001-04-13 15:32:16 +02:00
|
|
|
function is_opera()
|
|
|
|
{
|
2002-04-13 23:38:34 +02:00
|
|
|
if($this->get_agent()=='OPERA')
|
2001-04-13 15:32:16 +02:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-04-13 07:03:18 +02:00
|
|
|
// Echo content headers for file downloads
|
2001-07-09 17:58:05 +02:00
|
|
|
function content_header($fn='',$mime='',$length='',$nocache=True)
|
2001-04-13 07:03:18 +02:00
|
|
|
{
|
2003-12-28 15:54:17 +01:00
|
|
|
// if no mime-type is given or it's the default binary-type, guess it from the extension
|
2003-12-28 15:51:24 +01:00
|
|
|
if(empty($mime) || $mime == 'application/octet-stream')
|
2001-07-09 17:58:05 +02:00
|
|
|
{
|
2003-09-28 14:31:16 +02:00
|
|
|
$mime_magic = createObject('phpgwapi.mime_magic');
|
2003-12-28 15:54:17 +01:00
|
|
|
$mime = $mime_magic->filename2mime($fn);
|
2001-07-09 17:58:05 +02:00
|
|
|
}
|
2002-04-13 23:38:34 +02:00
|
|
|
if($fn)
|
2001-04-13 07:03:18 +02:00
|
|
|
{
|
2003-08-28 16:31:11 +02:00
|
|
|
if($this->get_agent() == 'IE') // && browser_get_version() == "5.5")
|
2001-04-13 07:03:18 +02:00
|
|
|
{
|
2001-05-31 06:45:51 +02:00
|
|
|
$attachment = '';
|
2001-04-13 07:03:18 +02:00
|
|
|
}
|
2001-05-31 06:45:51 +02:00
|
|
|
else
|
2001-04-13 07:03:18 +02:00
|
|
|
{
|
2001-05-31 06:45:51 +02:00
|
|
|
$attachment = ' attachment;';
|
2001-04-13 07:03:18 +02:00
|
|
|
}
|
2001-04-13 07:21:20 +02:00
|
|
|
|
2003-08-28 16:31:11 +02:00
|
|
|
// Show this for all
|
|
|
|
header('Content-disposition:'.$attachment.' filename="'.$fn.'"');
|
|
|
|
header('Content-type: '.$mime);
|
2001-04-13 07:21:20 +02:00
|
|
|
|
2002-04-13 23:38:34 +02:00
|
|
|
if($length)
|
2001-04-13 07:34:46 +02:00
|
|
|
{
|
2001-12-27 16:17:29 +01:00
|
|
|
header('Content-length: '.$length);
|
2001-04-13 07:34:46 +02:00
|
|
|
}
|
|
|
|
|
2002-04-13 23:38:34 +02:00
|
|
|
if($nocache)
|
2001-04-13 07:21:20 +02:00
|
|
|
{
|
|
|
|
header('Pragma: no-cache');
|
2002-04-24 15:27:46 +02:00
|
|
|
header('Pragma: public');
|
2001-04-13 07:21:20 +02:00
|
|
|
header('Expires: 0');
|
2002-04-24 15:27:46 +02:00
|
|
|
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
|
2001-04-13 07:21:20 +02:00
|
|
|
}
|
2001-04-13 07:03:18 +02:00
|
|
|
}
|
|
|
|
}
|
2001-04-07 16:19:28 +02:00
|
|
|
}
|
|
|
|
?>
|