2003-09-14 12:19:42 +02:00
|
|
|
<?php
|
2006-08-30 16:47:56 +02:00
|
|
|
/**
|
2016-03-13 12:22:44 +01:00
|
|
|
* EGroupware API: generates html with methods representing html-tags or higher widgets
|
2006-08-30 16:47:56 +02:00
|
|
|
*
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @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
|
2008-03-09 15:35:48 +01:00
|
|
|
* @author RalfBecker-AT-outdoor-training.de
|
2016-03-13 12:22:44 +01:00
|
|
|
* @copyright 2001-2016 by RalfBecker@outdoor-training.de
|
2008-03-09 15:35:48 +01:00
|
|
|
* @package api
|
|
|
|
* @subpackage html
|
2006-08-30 16:47:56 +02:00
|
|
|
* @version $Id$
|
|
|
|
*/
|
2004-11-19 07:32:10 +01:00
|
|
|
|
2016-03-13 12:22:44 +01:00
|
|
|
use EGroupware\Api;
|
|
|
|
|
2005-02-16 14:04:14 +01:00
|
|
|
/**
|
2008-03-09 15:35:48 +01:00
|
|
|
* Generates html with methods representing html-tags or higher widgets
|
|
|
|
*
|
2016-03-14 11:48:03 +01:00
|
|
|
* @deprecated use methods of Api\Html, Api\Header\Content or Api\Header\UserAgent classes
|
2005-02-16 14:04:14 +01:00
|
|
|
*/
|
2016-03-13 12:22:44 +01:00
|
|
|
class html extends Api\Html
|
2004-11-19 07:32:10 +01:00
|
|
|
{
|
2005-02-16 14:04:14 +01:00
|
|
|
/**
|
2016-03-14 11:48:03 +01:00
|
|
|
* @deprecated use Api\Header\UserAgent::type()
|
2005-02-16 14:04:14 +01:00
|
|
|
*/
|
2008-03-09 15:35:48 +01:00
|
|
|
static $user_agent;
|
2011-06-03 09:47:11 +02:00
|
|
|
/**
|
2016-03-14 11:48:03 +01:00
|
|
|
* @deprecated use Api\Header\UserAgent::mobile()
|
2011-06-03 09:47:11 +02:00
|
|
|
*/
|
|
|
|
static $ua_mobile;
|
2005-02-16 14:04:14 +01:00
|
|
|
/**
|
2016-03-14 11:48:03 +01:00
|
|
|
* @deprecated use Api\Header\UserAgent::version()
|
2005-02-16 14:04:14 +01:00
|
|
|
*/
|
2008-03-09 15:35:48 +01:00
|
|
|
static $ua_version;
|
2005-02-16 14:04:14 +01:00
|
|
|
/**
|
2016-03-13 12:22:44 +01:00
|
|
|
* @deprecated seriously Netscape4 ;-)
|
2005-02-16 14:04:14 +01:00
|
|
|
*/
|
2008-03-09 15:35:48 +01:00
|
|
|
static $netscape4;
|
2005-02-16 14:04:14 +01:00
|
|
|
/**
|
2016-03-13 12:22:44 +01:00
|
|
|
* @deprecated seriously Netscape4 ;-)
|
|
|
|
*/
|
|
|
|
static private $prefered_img_title = 'title';
|
|
|
|
/**
|
|
|
|
* @deprecated use Api\Translation::charset()
|
2005-02-16 14:04:14 +01:00
|
|
|
*/
|
2008-03-09 15:35:48 +01:00
|
|
|
static $charset;
|
2016-03-13 12:22:44 +01:00
|
|
|
|
2005-02-16 14:04:14 +01:00
|
|
|
/**
|
2016-03-13 12:22:44 +01:00
|
|
|
* Output content headers for user-content, mitigating risk of javascript or html
|
|
|
|
*
|
|
|
|
* Mitigate risk of serving javascript or css from our domain,
|
|
|
|
* which will get around same origin policy and CSP!
|
|
|
|
*
|
|
|
|
* Mitigate risk of html downloads by using CSP or force download for IE
|
|
|
|
*
|
|
|
|
* @param resource|string &$content content might be changed by this call
|
|
|
|
* @param string $path filename or path for content-disposition header
|
|
|
|
* @param string &$mime ='' mimetype or '' (default) to detect it from filename, using mime_magic::filename2mime()
|
|
|
|
* on return used, maybe changed, mime-type
|
|
|
|
* @param int $length =0 content length, default 0 = skip that header
|
|
|
|
* on return changed size
|
|
|
|
* @param boolean $nocache =true send headers to disallow browser/proxies to cache the download
|
|
|
|
* @param boolean $force_download =true send content-disposition attachment header
|
|
|
|
* @param boolean $no_content_type =false do not send actual content-type and content-length header, just content-disposition
|
2016-03-14 11:48:03 +01:00
|
|
|
* @deprecated use Api\Header\Content::safe()
|
2005-02-16 14:04:14 +01:00
|
|
|
*/
|
2016-03-13 12:22:44 +01:00
|
|
|
public static function safe_content_header(&$content, $path, &$mime='', &$length=0, $nocache=true, $force_download=true, $no_content_type=false)
|
|
|
|
{
|
2016-03-14 11:48:03 +01:00
|
|
|
Api\Header\Content::safe($content, $path, $mime, $length, $nocache, $force_download, $no_content_type);
|
2016-03-13 12:22:44 +01:00
|
|
|
}
|
2005-06-30 11:10:15 +02:00
|
|
|
|
2012-11-13 23:14:00 +01:00
|
|
|
/**
|
2016-03-13 12:22:44 +01:00
|
|
|
* Output content-type headers for file downloads
|
|
|
|
*
|
|
|
|
* This function should only be used for non-user supplied content!
|
|
|
|
* For uploaded files, mail attachmentes, etc, you have to use safe_content_header!
|
|
|
|
*
|
|
|
|
* @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
|
|
|
|
* @param boolean $forceDownload =true send headers to handle as attachment/download
|
2016-03-14 11:48:03 +01:00
|
|
|
* @deprecated use Api\Header\Content::type()
|
2012-11-13 23:14:00 +01:00
|
|
|
*/
|
2016-03-13 12:22:44 +01:00
|
|
|
public static function content_header($fn,$mime='',$length=0,$nocache=True,$forceDownload=true)
|
|
|
|
{
|
2016-03-14 11:48:03 +01:00
|
|
|
Api\Header\Content::type($fn, $mime, $length, $nocache, $forceDownload);
|
2016-03-13 12:22:44 +01:00
|
|
|
}
|
2012-11-13 23:14:00 +01:00
|
|
|
|
2005-02-16 14:04:14 +01:00
|
|
|
/**
|
2016-03-13 12:22:44 +01:00
|
|
|
* Output content-disposition header for file downloads
|
|
|
|
*
|
|
|
|
* @param string $fn filename
|
|
|
|
* @param boolean $forceDownload =true send headers to handle as attachment/download
|
2016-03-14 11:48:03 +01:00
|
|
|
* @deprecated use Api\Header\Content::disposition()
|
2005-02-16 14:04:14 +01:00
|
|
|
*/
|
2016-03-13 12:22:44 +01:00
|
|
|
public static function content_disposition_header($fn,$forceDownload=true)
|
2004-11-19 07:32:10 +01:00
|
|
|
{
|
2016-03-14 11:48:03 +01:00
|
|
|
Api\Header\Content::disposition($fn, $forceDownload);
|
2016-03-13 12:22:44 +01:00
|
|
|
}
|
2005-11-26 15:25:39 +01:00
|
|
|
|
2016-03-13 12:22:44 +01:00
|
|
|
/**
|
|
|
|
* Created an input-field with an attached color-picker
|
|
|
|
*
|
|
|
|
* @param string $name the name of the input-field
|
|
|
|
* @param string $value ='' the actual value for the input-field, default ''
|
|
|
|
* @param string $title ='' tooltip/title for the picker-activation-icon
|
|
|
|
* @param string $options ='' options for input
|
|
|
|
* @deprecated use html5 input type="color"
|
|
|
|
* @return string the html
|
|
|
|
*/
|
|
|
|
static function inputColor($name,$value='',$title='',$options='')
|
|
|
|
{
|
|
|
|
return self::input($name, $value, 'color', $options.' size="7" maxsize="7"').
|
|
|
|
($title ? ' title="'.self::htmlspecialchars($title).'"' : '');
|
|
|
|
}
|
2005-11-26 15:25:39 +01:00
|
|
|
|
2016-03-13 12:22:44 +01:00
|
|
|
/**
|
|
|
|
* representates a b tab (bold)
|
|
|
|
*
|
|
|
|
* @param string $content of the link, if '' only the opening tag gets returned
|
|
|
|
* @deprecated use css
|
|
|
|
* @return string the html
|
|
|
|
*/
|
|
|
|
static function bold($content)
|
|
|
|
{
|
|
|
|
return '<b>'.$content.'</b>';
|
2004-11-19 07:32:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-03-13 12:22:44 +01:00
|
|
|
* representates a i tab (bold)
|
|
|
|
*
|
|
|
|
* @param string $content of the link, if '' only the opening tag gets returned
|
|
|
|
* @deprecated use css
|
|
|
|
* @return string the html
|
|
|
|
*/
|
|
|
|
static function italic($content)
|
2004-11-19 07:32:10 +01:00
|
|
|
{
|
2016-03-13 12:22:44 +01:00
|
|
|
return '<i>'.$content.'</i>';
|
2004-11-19 07:32:10 +01:00
|
|
|
}
|
2005-11-26 15:25:39 +01:00
|
|
|
|
2004-11-19 07:32:10 +01:00
|
|
|
/**
|
|
|
|
* Handles tooltips via the wz_tooltip class from Walter Zorn
|
|
|
|
*
|
2010-01-17 04:20:45 +01:00
|
|
|
* @param string $text text or html for the tooltip, all chars allowed, they will be quoted approperiate
|
2005-02-16 14:04:14 +01:00
|
|
|
* @param boolean $do_lang (default False) should the text be run though lang()
|
|
|
|
* @param array $options param/value pairs, eg. 'TITLE' => 'I am the title'. Some common parameters:
|
2004-11-19 07:32:10 +01:00
|
|
|
* title (string) gives extra title-row, width (int,'auto') , padding (int), above (bool), bgcolor (color), bgimg (URL)
|
|
|
|
* For a complete list and description see http://www.walterzorn.com/tooltip/tooltip_e.htm
|
2012-06-01 15:13:06 +02:00
|
|
|
* @param boolean $return_as_attributes true to return array(onmouseover, onmouseout) attributes
|
2016-03-13 12:22:44 +01:00
|
|
|
* @deprecated use something else ;-)
|
2012-06-01 15:13:06 +02:00
|
|
|
* @return string|array to be included in any tag, like '<p'.html::tooltip('Hello <b>Ralf</b>').'>Text with tooltip</p>'
|
2004-11-19 07:32:10 +01:00
|
|
|
*/
|
2012-06-01 15:13:06 +02:00
|
|
|
static function tooltip($text,$do_lang=False,$options=False, $return_as_attributes=false)
|
2004-11-19 07:32:10 +01:00
|
|
|
{
|
2012-04-04 15:05:58 +02:00
|
|
|
// tell egw_framework to include wz_tooltip.js
|
|
|
|
$GLOBALS['egw_info']['flags']['include_wz_tooltip'] = true;
|
|
|
|
|
2004-11-19 07:32:10 +01:00
|
|
|
if ($do_lang) $text = lang($text);
|
2005-11-26 15:25:39 +01:00
|
|
|
|
2012-06-01 15:13:06 +02:00
|
|
|
$ttip = 'Tip(\''.str_replace(array("\n","\r","'",'"'),array('','',"\\'",'"'),$text).'\'';
|
2010-04-13 17:12:09 +02:00
|
|
|
|
2010-01-24 04:15:12 +01:00
|
|
|
$sticky = false;
|
2004-11-19 07:32:10 +01:00
|
|
|
if (is_array($options))
|
|
|
|
{
|
2004-05-08 23:09:44 +02:00
|
|
|
foreach($options as $option => $value)
|
|
|
|
{
|
2010-01-24 04:15:12 +01:00
|
|
|
$option = strtoupper($option);
|
|
|
|
if ($option == 'STICKY') $sticky = (bool)$value;
|
|
|
|
|
|
|
|
switch(gettype($value))
|
|
|
|
{
|
|
|
|
case 'boolean':
|
|
|
|
$value = $value ? 'true' : 'false';
|
|
|
|
break;
|
|
|
|
case 'string':
|
2010-02-02 12:23:11 +01:00
|
|
|
if (stripos($value,"'")===false) $value = "'$value'";
|
2010-01-24 04:15:12 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
$ttip .= ','.$option.','.$value;
|
2004-05-08 23:09:44 +02:00
|
|
|
}
|
2004-11-19 07:32:10 +01:00
|
|
|
}
|
2012-06-01 15:13:06 +02:00
|
|
|
$ttip .= ')';
|
2010-01-24 04:15:12 +01:00
|
|
|
|
2012-06-01 15:13:06 +02:00
|
|
|
$untip = 'UnTip()';
|
2010-01-24 04:15:12 +01:00
|
|
|
|
2012-06-01 15:13:06 +02:00
|
|
|
return $return_as_attributes ? array($ttip, $untip) :
|
|
|
|
' onmouseover="'.self::htmlspecialchars($ttip).'" onmouseout="'.$untip.'"';
|
2004-11-19 07:32:10 +01:00
|
|
|
}
|
2005-11-26 15:25:39 +01:00
|
|
|
|
2005-02-16 14:04:14 +01:00
|
|
|
/**
|
2016-03-13 12:22:44 +01:00
|
|
|
* returns simple stylesheet (incl. <STYLE> tags) for nextmatch row-colors
|
2005-02-16 14:04:14 +01:00
|
|
|
*
|
2016-03-13 12:22:44 +01:00
|
|
|
* @deprecated included now always by the framework
|
|
|
|
* @return string classes 'th' = nextmatch header, 'row_on'+'row_off' = alternating rows
|
2005-02-16 14:04:14 +01:00
|
|
|
*/
|
2016-03-13 12:22:44 +01:00
|
|
|
static function themeStyles()
|
2004-11-19 07:32:10 +01:00
|
|
|
{
|
2016-03-13 12:22:44 +01:00
|
|
|
return self::style(self::theme2css());
|
2004-11-19 07:32:10 +01:00
|
|
|
}
|
2005-11-26 15:25:39 +01:00
|
|
|
|
2004-11-19 07:32:10 +01:00
|
|
|
/**
|
2016-03-13 12:22:44 +01:00
|
|
|
* returns simple stylesheet for nextmatch row-colors
|
2005-02-16 14:04:14 +01:00
|
|
|
*
|
2016-03-13 12:22:44 +01:00
|
|
|
* @deprecated included now always by the framework
|
|
|
|
* @return string classes 'th' = nextmatch header, 'row_on'+'row_off' = alternating rows
|
2007-01-19 07:58:38 +01:00
|
|
|
*/
|
2016-03-13 12:22:44 +01:00
|
|
|
static function theme2css()
|
2004-11-19 07:32:10 +01:00
|
|
|
{
|
2016-03-13 12:22:44 +01:00
|
|
|
return ".th { background: ".$GLOBALS['egw_info']['theme']['th_bg']."; }\n".
|
|
|
|
".row_on,.th_bright { background: ".$GLOBALS['egw_info']['theme']['row_on']."; }\n".
|
|
|
|
".row_off { background: ".$GLOBALS['egw_info']['theme']['row_off']."; }\n";
|
2007-01-19 07:58:38 +01:00
|
|
|
}
|
2005-11-26 15:25:39 +01:00
|
|
|
|
2004-11-19 07:32:10 +01:00
|
|
|
/**
|
2016-03-13 12:22:44 +01:00
|
|
|
* initialise our static vars
|
2005-02-16 14:04:14 +01:00
|
|
|
*/
|
2016-03-13 12:22:44 +01:00
|
|
|
static function _init_static()
|
2007-04-14 18:57:57 +02:00
|
|
|
{
|
2016-03-13 12:22:44 +01:00
|
|
|
self::$user_agent = Api\Header\UserAgent::type();
|
|
|
|
self::$ua_version = Api\Header\UserAgent::version();
|
|
|
|
self::$ua_mobile = Api\Header\UserAgent::mobile();
|
|
|
|
self::$netscape4 = self::$user_agent == 'mozilla' && self::$ua_version < 5;
|
|
|
|
self::$prefered_img_title = self::$netscape4 ? 'alt' : 'title';
|
|
|
|
//error_log("HTTP_USER_AGENT='$_SERVER[HTTP_USER_AGENT]', UserAgent: '".self::$user_agent."', Version: '".self::$ua_version."', isMobile=".array2string(self::$ua_mobile).", img_title: '".self::$prefered_img_title."'");
|
2014-01-18 18:02:29 +01:00
|
|
|
|
2016-03-13 12:22:44 +01:00
|
|
|
self::$charset = Api\Translation::charset();
|
2014-01-18 18:02:29 +01:00
|
|
|
}
|
2005-02-09 14:53:16 +01:00
|
|
|
}
|
2008-03-09 15:35:48 +01:00
|
|
|
html::_init_static();
|