- 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,14 +45,14 @@
$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.
unset($GLOBALS['egw_info']['user']['preferences']['common']['auto_hide_sidebox']);
$GLOBALS['egw_info']['flags']['app_header'] = $GLOBALS['egw_info']['apps']['calendar']['title'].' - '.lang('Holiday Management');
$GLOBALS['egw']->template->set_var('help_msg',lang('<b>Please note</b>: The calendar use the holidays of your country, which is set to %1. You can change it in your %2.<br />Holidays are %3 automatic installed from %4. You can changed it in %5.',
'<b>'.$GLOBALS['egw_info']['user']['preferences']['common']['country'].'</b>','<a href="'.$GLOBALS['egw']->link('/index.php',array(
'menuaction' => 'preferences.uisettings.index',
@ -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');
@ -210,7 +210,7 @@
{
$holidays[$i]['name'] = '&nbsp;';
}
$var = Array(
'tr_color' => $tr_color,
'header_delete'=> lang('Delete'),
@ -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,13 +277,13 @@
if (@count($error))
{
$message = $GLOBALS['egw']->common->error_list($error);
$message = common::error_list($error);
}
else
{
$message = '';
}
$var = Array(
'title_holiday' => ($this->bo->id ? lang('Edit') : lang('Add')).' '.lang('Holiday'),
'message' => $message,
@ -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
@ -357,7 +357,7 @@
'menuaction' => 'calendar.uiholiday.admin'
);
}
$t->set_var(Array(
'action_url_button' => $GLOBALS['egw']->link($this->base_url,$link_params),
'action_text_button' => lang('Cancel'),
@ -365,7 +365,7 @@
'action_extra_field' => ''
));
$t->parse('cancel_button','form_button');
if ($this->bo->id)
{
$link_params = Array(
@ -396,7 +396,7 @@
$p =& CreateObject('phpgwapi.Template',$this->template_dir);
$p->set_file(Array('form'=>'delete_common.tpl','form_button'=>'form_button_script.tpl'));
$p->set_var('messages',lang('Are you sure you want to delete this Country ?')."<br>".$this->bo->locales[0]);
$var = Array(
@ -428,15 +428,15 @@
{
return $this->edit_locale();
}
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'));
$p->set_var('messages',lang('Are you sure you want to delete this holiday ?')."<br>".$holiday['name'].' ('.$this->bo->locales[0].') '.$this->bo->rule_string($holiday));
$var = Array(
@ -468,7 +468,7 @@
}
$this->bo->year = 0; // for a complete list with all years
$holidays = $this->bo->get_holiday_list();
if (!is_array($holidays) || !count($holidays))
{
$this->admin();
@ -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,291 +1,206 @@
<?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
/**
* Init our static properties
*/
public static function init_static()
{
var $BROWSER_AGENT;
var $BROWSER_VER;
var $BROWSER_PLATFORM;
var $br;
var $p;
var $data;
function browser()
$HTTP_USER_AGENT = $_SERVER['HTTP_USER_AGENT'];
/*
Determine browser and version
*/
if(preg_match('/MSIE ([0-9].[0-9]{1,2})/',$HTTP_USER_AGENT,$log_version))
{
$HTTP_USER_AGENT = $_SERVER['HTTP_USER_AGENT'];
/*
Determine browser and version
*/
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';
}
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';
}
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';
}
elseif(strpos($HTTP_USER_AGENT,'Gecko') !== false)
{
$this->BROWSER_VER = $log_version[1];
$this->BROWSER_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';
}
else
{
$this->BROWSER_VER=0;
$this->BROWSER_AGENT='OTHER';
}
/*
Determine platform
*/
if(strpos($HTTP_USER_AGENT,'Win') !== false)
{
$this->BROWSER_PLATFORM='Win';
}
elseif(strpos($HTTP_USER_AGENT,'Mac') !== false)
{
$this->BROWSER_PLATFORM='Mac';
}
elseif(strpos($HTTP_USER_AGENT,'Linux') !== false)
{
$this->BROWSER_PLATFORM='Linux';
}
elseif(strpos($HTTP_USER_AGENT,'Unix') !== false)
{
$this->BROWSER_PLATFORM='Unix';
}
elseif(strpos($HTTP_USER_AGENT,'Beos') !== false)
{
$this->BROWSER_PLATFORM='Beos';
}
else
{
$this->BROWSER_PLATFORM='Other';
}
/*
echo "\n\nAgent: $HTTP_USER_AGENT";
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();
*/
// The br and p functions 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>';
}
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))
{
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))
{
self::$version = $log_version[1];
self::$agent = 'iCab';
}
elseif(strpos($HTTP_USER_AGENT,'Gecko') !== false)
{
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))
{
self::$version=$log_version[1];
self::$agent='Konqueror';
}
else
{
self::$version=0;
self::$agent='OTHER';
}
function return_array()
/*
Determine platform
*/
if(strpos($HTTP_USER_AGENT,'Win') !== false)
{
$this->data = array(
'agent' => $this->get_agent(),
'version' => $this->get_version(),
'platform' => $this->get_platform()
);
return $this->data;
self::$platform='Win';
}
elseif(strpos($HTTP_USER_AGENT,'Mac') !== false)
{
self::$platform='Mac';
}
elseif(strpos($HTTP_USER_AGENT,'Linux') !== false)
{
self::$platform='Linux';
}
elseif(strpos($HTTP_USER_AGENT,'Unix') !== false)
{
self::$platform='Unix';
}
elseif(strpos($HTTP_USER_AGENT,'Beos') !== false)
{
self::$platform='Beos';
}
else
{
self::$platform='Other';
}
function get_agent()
/*
echo "\n\nAgent: $HTTP_USER_AGENT";
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();
*/
// The br and p functions 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(self::$agent == 'IE')
{
return $this->BROWSER_AGENT;
self::$br = '<br/>';
self::$p = '<p/>';
}
function get_version()
else
{
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 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);
}
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');
}
}
self::$br = '<br>';
self::$p = '<p>';
}
error_log(__METHOD__."() $_SERVER[HTTP_USER_AGENT] --> agent=".self::$agent.', version='.self::$version.', platform='.self::$platform);
}
?>
public static function return_array()
{
return array(
'agent' => self::$agent,
'version' => self::$version,
'platform' => self::$platform,
);
}
public static function get_agent()
{
return self::$agent;
}
public static function get_version()
{
return self::$version;
}
public static function get_platform()
{
return self::$platform;
}
public static function is_linux()
{
return $platform == 'Linux';
}
public static function is_unix()
{
return $platform() == 'Unix';
}
public static function is_beos()
{
return $platform == 'Beos';
}
public static function is_mac()
{
return $platform == 'Mac';
}
public static function is_windows()
{
return $platform == 'Win';
}
public static function is_ie()
{
return $agent == 'IE';
}
public static function is_netscape()
{
return $agent == 'MOZILLA';
}
public static function is_opera()
{
return $agent == 'OPERA';
}
/**
* 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)
{
html::content_header($fn,$mime,$length,$nocache);
}
}
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();