- reworked old browser class to use have only static methods

--> recogniced it's so old and dusty, it does not make sense any more
--> moved content_header() method to html class
- fixed calls of browser->content_header to use html::content_header
  instead
This commit is contained in:
Ralf Becker 2009-10-11 11:37:46 +00:00
parent cdd9450504
commit 4e21b766b9
5 changed files with 270 additions and 315 deletions

View File

@ -45,7 +45,7 @@
$this->bo =& CreateObject('calendar.boholiday');
$this->bo->check_admin();
$this->base_url = $this->bo->base_url;
$this->template_dir = $GLOBALS['egw']->common->get_tpl_dir('calendar');
$this->template_dir = common::get_tpl_dir('calendar');
$this->sb =& CreateObject('calendar.sbox');
// calendar does not work with hidden sidebox atm.
@ -71,7 +71,7 @@
unset($GLOBALS['egw_info']['flags']['noheader']);
unset($GLOBALS['egw_info']['flags']['nonavbar']);
$GLOBALS['egw_info']['flags']['noappfooter'] = True;
$GLOBALS['egw']->common->egw_header();
common::egw_header();
$p = &$GLOBALS['egw']->template;
$p->set_file(Array('locales'=>'locales.tpl'));
@ -157,7 +157,7 @@
unset($GLOBALS['egw_info']['flags']['noheader']);
unset($GLOBALS['egw_info']['flags']['nonavbar']);
$GLOBALS['egw_info']['flags']['noappfooter'] = True;
$GLOBALS['egw']->common->egw_header();
common::egw_header();
$p =& $GLOBALS['egw']->template;
$p->set_file(Array('locale'=>'locales.tpl'));
$p->set_block('locale','list','list');
@ -268,7 +268,7 @@
unset($GLOBALS['egw_info']['flags']['nonavbar']);
$GLOBALS['egw_info']['flags']['noappfooter'] = True;
$GLOBALS['egw_info']['flags']['app_header'] = $GLOBALS['egw_info']['apps']['calendar']['title'].' - '.($this->bo->id ? lang('Edit') : lang('Add')).' '.lang('Holiday');
$GLOBALS['egw']->common->egw_header();
common::egw_header();
$t = &$GLOBALS['egw']->template;
$t->set_file(Array('holiday'=>'holiday.tpl','form_button'=>'form_button_script.tpl'));
@ -277,7 +277,7 @@
if (@count($error))
{
$message = $GLOBALS['egw']->common->error_list($error);
$message = common::error_list($error);
}
else
{
@ -300,7 +300,7 @@
$this->display_item($t,lang('title'),'<input name="holiday[name]" size="60" maxlength="50" value="'.$holiday['name'].'">');
// Date
$this->display_item($t,lang('Date'),$GLOBALS['egw']->common->dateformatorder($this->sb->getYears('holiday[year]',$holiday['occurence']>1900?$holiday['occurence']:0),$this->sb->getMonthText('holiday[month_num]',$holiday['month']),$this->sb->getDays('holiday[mday]',$holiday['day'])).
$this->display_item($t,lang('Date'),common::dateformatorder($this->sb->getYears('holiday[year]',$holiday['occurence']>1900?$holiday['occurence']:0),$this->sb->getMonthText('holiday[month_num]',$holiday['month']),$this->sb->getDays('holiday[mday]',$holiday['day'])).
'&nbsp;'.lang('Set a Year only for one-time / non-regular holidays.'));
// Occurence
@ -432,7 +432,7 @@
unset($GLOBALS['egw_info']['flags']['noheader']);
unset($GLOBALS['egw_info']['flags']['nonavbar']);
$GLOBALS['egw_info']['flags']['noappfooter'] = True;
$GLOBALS['egw']->common->egw_header();
common::egw_header();
$p =& CreateObject('phpgwapi.Template',$this->template_dir);
$p->set_file(Array('form'=>'delete_common.tpl','form_button'=>'form_button_script.tpl'));
@ -479,11 +479,9 @@
if (isset($_GET['download']))
{
$locale = $this->bo->locales[0];
$browser =& CreateObject('phpgwapi.browser');
$browser->content_header("holidays.$locale.csv",'text/text');
unset($browser);
html::content_header("holidays.$locale.csv",'text/text');
echo "charset\t".$GLOBALS['egw']->translation->charset()."\n";
echo "charset\t".translation::charset()."\n";
$last_year = -1;
foreach($holidays as $holiday)
{
@ -495,7 +493,7 @@
}
echo "$locale\t$holiday[name]\t$holiday[day]\t$holiday[month]\t$holiday[occurence]\t$holiday[dow]\t$holiday[observance_rule]\n";
}
$GLOBALS['egw']->common->egw_exit();
common::egw_exit();
}
if($this->debug)
{
@ -508,13 +506,13 @@
$GLOBALS['egw_info']['flags']['noappheader'] = True;
$GLOBALS['egw_info']['flags']['noappfooter'] = True;
$GLOBALS['egw_info']['flags']['nofooter'] = True;
$GLOBALS['egw']->common->egw_header();
common::egw_header();
echo '<body onLoad="document.submitform.submit()">'."\n";
echo '<form action="'.$action.'" method="post" name="submitform">'."\n";
echo '<input type="hidden" name="locale" value="'.$this->bo->locales[0].'">'."\n";
echo '<input type="hidden" name="charset" value="'.$GLOBALS['egw']->translation->charset().'">'."\n";
echo '<input type="hidden" name="charset" value="'.translation::charset().'">'."\n";
foreach($holidays as $holiday)
{
echo '<input type="hidden" name="name[]" value="'.htmlspecialchars($holiday['name']).'">'."\n"

View File

@ -524,7 +524,7 @@ abstract class bo_merge
{
exec('/usr/bin/zip -F '.escapeshellarg($archive));
}
ExecMethod2('phpgwapi.browser.content_header',basename($document),$mimetype);
html::content_header(basename($document),$mimetype,filesize($archive));
readfile($archive,'r');
}
else

View File

@ -1,39 +1,36 @@
<?php
/**************************************************************************\
* eGroupWare API - Browser detect functions *
* This file written by Miles Lott <milosch@groupwhere.org> *
* Majority of code borrowed from Sourceforge 2.5 *
* Copyright 1999-2000 (c) The SourceForge Crew - http://sourceforge.net *
* Browser detection functions for eGroupWare developers *
* -------------------------------------------------------------------------*
* This library is part of the eGroupWare API *
* http://www.egroupware.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 *
\**************************************************************************/
/**
* eGroupWare API - Browser detect functions
*
* This file written by Miles Lott <milosch@groupwhere.org>
* Majority of code borrowed from Sourceforge 2.5
* Copyright 1999-2000 (c) The SourceForge Crew - http://sourceforge.net
*
* @link http://www.egroupware.org
* @author Miles Lott <milosch@groupwhere.org>
* @license http://opensource.org/licenses/lgpl-license.php LGPL - GNU Lesser General Public License
* @package api
* @subpackage html
* @version $Id$
*/
/* $Id$ */
/**
* Dusty old browser detection functions (all static now)
*
* @deprecated use html::content_header(), html::$user_agent and html::$ua_version
*/
class browser
{
public static $agent;
public static $version;
public static $platform;
public static $br;
public static $p;
class browser
{
var $BROWSER_AGENT;
var $BROWSER_VER;
var $BROWSER_PLATFORM;
var $br;
var $p;
var $data;
function browser()
/**
* Init our static properties
*/
public static function init_static()
{
$HTTP_USER_AGENT = $_SERVER['HTTP_USER_AGENT'];
/*
@ -41,36 +38,36 @@
*/
if(preg_match('/MSIE ([0-9].[0-9]{1,2})/',$HTTP_USER_AGENT,$log_version))
{
$this->BROWSER_VER = $log_version[1];
$this->BROWSER_AGENT = 'IE';
self::$version = $log_version[1];
self::$agent = 'IE';
}
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))
{
$this->BROWSER_VER = $log_version[1];
$this->BROWSER_AGENT = 'OPERA';
self::$version = $log_version[1];
self::$agent = 'OPERA';
}
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))
{
$this->BROWSER_VER = $log_version[1];
$this->BROWSER_AGENT = 'iCab';
self::$version = $log_version[1];
self::$agent = 'iCab';
}
elseif(strpos($HTTP_USER_AGENT,'Gecko') !== false)
{
$this->BROWSER_VER = $log_version[1];
$this->BROWSER_AGENT = 'MOZILLA';
self::$version = $log_version[1];
self::$agent = 'MOZILLA';
}
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))
{
$this->BROWSER_VER=$log_version[1];
$this->BROWSER_AGENT='Konqueror';
self::$version=$log_version[1];
self::$agent='Konqueror';
}
else
{
$this->BROWSER_VER=0;
$this->BROWSER_AGENT='OTHER';
self::$version=0;
self::$agent='OTHER';
}
/*
@ -78,27 +75,27 @@
*/
if(strpos($HTTP_USER_AGENT,'Win') !== false)
{
$this->BROWSER_PLATFORM='Win';
self::$platform='Win';
}
elseif(strpos($HTTP_USER_AGENT,'Mac') !== false)
{
$this->BROWSER_PLATFORM='Mac';
self::$platform='Mac';
}
elseif(strpos($HTTP_USER_AGENT,'Linux') !== false)
{
$this->BROWSER_PLATFORM='Linux';
self::$platform='Linux';
}
elseif(strpos($HTTP_USER_AGENT,'Unix') !== false)
{
$this->BROWSER_PLATFORM='Unix';
self::$platform='Unix';
}
elseif(strpos($HTTP_USER_AGENT,'Beos') !== false)
{
$this->BROWSER_PLATFORM='Beos';
self::$platform='Beos';
}
else
{
$this->BROWSER_PLATFORM='Other';
self::$platform='Other';
}
/*
@ -115,177 +112,95 @@
// 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')
if(self::$agent == 'IE')
{
$this->br = '<br/>';
$this->p = '<p/>';
self::$br = '<br/>';
self::$p = '<p/>';
}
else
{
$this->br = '<br>';
$this->p = '<p>';
self::$br = '<br>';
self::$p = '<p>';
}
error_log(__METHOD__."() $_SERVER[HTTP_USER_AGENT] --> agent=".self::$agent.', version='.self::$version.', platform='.self::$platform);
}
function return_array()
public static function return_array()
{
$this->data = array(
'agent' => $this->get_agent(),
'version' => $this->get_version(),
'platform' => $this->get_platform()
return array(
'agent' => self::$agent,
'version' => self::$version,
'platform' => self::$platform,
);
return $this->data;
}
function get_agent()
public static function get_agent()
{
return $this->BROWSER_AGENT;
return self::$agent;
}
function get_version()
public static function get_version()
{
return $this->BROWSER_VER;
return self::$version;
}
function get_platform()
public static function get_platform()
{
return $this->BROWSER_PLATFORM;
return self::$platform;
}
function is_linux()
public static function is_linux()
{
if($this->get_platform()=='Linux')
{
return true;
}
else
{
return false;
}
return $platform == 'Linux';
}
function is_unix()
public static function is_unix()
{
if($this->get_platform()=='Unix')
{
return true;
}
else
{
return false;
}
return $platform() == 'Unix';
}
function is_beos()
public static function is_beos()
{
if($this->get_platform()=='Beos')
{
return true;
}
else
{
return false;
}
return $platform == 'Beos';
}
function is_mac()
public static function is_mac()
{
if($this->get_platform()=='Mac')
{
return true;
}
else
{
return false;
}
return $platform == 'Mac';
}
function is_windows()
public static function is_windows()
{
if($this->get_platform()=='Win')
{
return true;
}
else
{
return false;
}
return $platform == 'Win';
}
function is_ie()
public static function is_ie()
{
if($this->get_agent()=='IE')
{
return true;
}
else
{
return false;
}
return $agent == 'IE';
}
function is_netscape()
public static function is_netscape()
{
if($this->get_agent()=='MOZILLA')
{
return true;
}
else
{
return false;
}
return $agent == 'MOZILLA';
}
function is_opera()
public static function is_opera()
{
if($this->get_agent()=='OPERA')
{
return true;
}
else
{
return false;
}
return $agent == 'OPERA';
}
// Echo content headers for file downloads
function content_header($fn='',$mime='',$length='',$nocache=True)
/**
* Output content headers for file downloads
*
* @param string $fn filename
* @param string $mime='' mimetype or '' (default) to detect it from filename, using mime_magic::filename2mime()
* @param int $length=0 content length, default 0 = skip that header
* @param boolean $nocache=true send headers to disallow browser/proxies to cache the download
* @deprecated use html::content_header() direct
*/
public static function content_header($fn,$mime='',$length=0,$nocache=True)
{
// if no mime-type is given or it's the default binary-type, guess it from the extension
if(empty($mime) || $mime == 'application/octet-stream')
{
$mime_magic = createObject('phpgwapi.mime_magic');
$mime = $mime_magic->filename2mime($fn);
html::content_header($fn,$mime,$length,$nocache);
}
if($fn)
{
if($this->get_agent() == 'IE') // && browser_get_version() == "5.5")
{
$attachment = '';
}
else
{
$attachment = ' attachment;';
}
// Show this for all
header('Content-disposition:'.$attachment.' filename="'.$fn.'"');
header('Content-type: '.$mime);
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');
}
}
}
}
?>
}
browser::init_static();

View File

@ -797,12 +797,9 @@ class db_backup
}
else
{
if (!is_object($this->browser))
{
$this->browser = new browser();
}
$this->browser->content_header('schema-backup-'.date('YmdHi').'.inc.php','text/plain',bytes($def));
echo "<?php\n\t/* eGroupWare schema-backup from ".date('Y-m-d H:i:s')." */\n\n".$def;
$def = "<?php\n\t/* eGroupWare schema-backup from ".date('Y-m-d H:i:s')." */\n\n".$def;
html::content_header('schema-backup-'.date('YmdHi').'.inc.php','text/plain',bytes($def));
echo $def;
}
}

View File

@ -6,7 +6,7 @@
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de> complete rewrite in 6/2006 and earlier modifications
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @author RalfBecker-AT-outdoor-training.de
* @copyright 2001-2008 by RalfBecker@outdoor-training.de
* @copyright 2001-2009 by RalfBecker@outdoor-training.de
* @package api
* @subpackage html
* @version $Id$
@ -15,13 +15,12 @@
/**
* Generates html with methods representing html-tags or higher widgets
*
* The class has only static methods now, so there's no need to instanciate the object anymore!
*
* The class has only static methods now, so there's no need to instanciate as object anymore!
*/
class html
{
/**
* user-agent: 'mozilla','msie','konqueror', 'safari', 'opera'
* user-agent: 'firefox', 'msie', 'safari' (incl. iPhone, Chrome), 'opera', 'konqueror', 'mozilla'
* @var string
*/
static $user_agent;
@ -58,17 +57,17 @@ class html
static function _init_static()
{
// should be Ok for all HTML 4 compatible browsers
if (!preg_match('/(Safari)\/([0-9.]+)/i',$_SERVER['HTTP_USER_AGENT'],$parts) &&
!preg_match('/compatible; ([a-z_]+)[\/ ]+([0-9.]+)/i',$_SERVER['HTTP_USER_AGENT'],$parts))
if(!preg_match('/compatible; ([a-z]+)[\/ ]+([0-9.]+)/i',$_SERVER['HTTP_USER_AGENT'],$parts))
{
preg_match('/^([a-z_]+)\/([0-9.]+)/i',$_SERVER['HTTP_USER_AGENT'],$parts);
preg_match_all('/([a-z]+)\/([0-9.]+)/i',$_SERVER['HTTP_USER_AGENT'],$parts,PREG_SET_ORDER);
$parts = array_pop($parts);
}
list(,self::$user_agent,self::$ua_version) = $parts;
self::$user_agent = strtolower(self::$user_agent);
if ((self::$user_agent = strtolower(self::$user_agent)) == 'version') self::$user_agent = 'opera';
self::$netscape4 = self::$user_agent == 'mozilla' && self::$ua_version < 5;
self::$prefered_img_title = self::$netscape4 ? 'alt' : 'title';
//echo "<p>HTTP_USER_AGENT='$_SERVER[HTTP_USER_AGENT]', UserAgent: 'self::$user_agent', Version: 'self::$ua_version', img_title: 'self::$prefered_img_title'</p>\n";
//echo "<p>HTTP_USER_AGENT='$_SERVER[HTTP_USER_AGENT]', UserAgent: '".self::$user_agent."', Version: '".self::$ua_version."', img_title: '".self::$prefered_img_title."'</p>\n";
if ($GLOBALS['egw']->translation)
{
@ -1281,5 +1280,51 @@ class html
}
return $purifier->purify( $html );
}
/**
* Output content headers for file downloads
*
* @author Miles Lott originally in browser class
* @param string $fn filename
* @param string $mime='' mimetype or '' (default) to detect it from filename, using mime_magic::filename2mime()
* @param int $length=0 content length, default 0 = skip that header
* @param boolean $nocache=true send headers to disallow browser/proxies to cache the download
*/
public static function content_header($fn,$mime='',$length=0,$nocache=True)
{
// if no mime-type is given or it's the default binary-type, guess it from the extension
if(empty($mime) || $mime == 'application/octet-stream')
{
$mime = mime_magic::filename2mime($fn);
}
if($fn)
{
if(self::$user_agent == 'msie') // && self::$ua_version == '5.5')
{
$attachment = '';
}
else
{
$attachment = ' attachment;';
}
// Show this for all
header('Content-disposition:'.$attachment.' filename="'.$fn.'"');
header('Content-type: '.$mime);
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');
}
}
}
}
html::_init_static();