diff --git a/phpgwapi/inc/class.html.inc.php b/phpgwapi/inc/class.html.inc.php index dfc502703d..f3549f1f96 100644 --- a/phpgwapi/inc/class.html.inc.php +++ b/phpgwapi/inc/class.html.inc.php @@ -12,13 +12,50 @@ /* $Id$ */ +/** + * generates html with methods representing html-tags or higher widgets + * + * @package api + * @subpackage html + * @author RalfBecker-AT-outdoor-training.de + * @license GPL + */ class html { - var $user_agent,$ua_version; // 'mozilla','msie','konqueror' + /** + * user-agent: 'mozilla','msie','konqueror', 'safari', 'opera' + * @var string + */ + var $user_agent; + /** + * version of user-agent as specified by browser + * @var string + */ + var $ua_version; + /** + * what attribute to use for the title of an image: 'title' for everything but netscape4='alt' + * @var string + */ var $prefered_img_title; - var $charset,$phpgwapi_js_url; - var $need_footer = False; // do we need to be called at the end of the page + /** + * charset used by the page, as returned by $GLOBALS['phpgw']->translation->charset() + * @var string + */ + var $charset; + /** + * URL (NOT path) of the js directory in the api + * @var string + */ + var $phpgwapi_js_url; + /** + * do we need to set the wz_tooltip class, to be included at the end of the page + * @var boolean + */ + var $wz_tooltips_included = False; + /** + * Constructor: initialised the class-vars + */ function html() { // should be Ok for all HTML 4 compatible browsers @@ -42,13 +79,14 @@ class html } /** - * Created an input-field with an attached tigra color-picker + * Created an input-field with an attached color-picker * * Please note: it need to be called before the call to phpgw_header() !!! * - * @param $name string the name of the input-field - * @param $value string the actual value for the input-field, default '' - * @param $title string tooltip/title for the picker-activation-icon + * @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 + * @return string the html */ function inputColor($name,$value='',$title='') { @@ -64,10 +102,10 @@ class html * * Note: The wz_tooltip.js file gets automaticaly loaded at the end of the page * - * @param $text string/boolean text or html for the tooltip, all chars allowed, they will be quoted approperiate + * @param string/boolean $text text or html for the tooltip, all chars allowed, they will be quoted approperiate * Or if False the content (innerHTML) of the element itself is used. - * @param $do_lang boolean (default False) should the text be run though lang() - * @param $options array param/value pairs, eg. 'TITLE' => 'I am the title'. Some common parameters: + * @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: * 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 * @return string to be included in any tag, like '
tooltip('Hello Ralf').'>Text with tooltip
' @@ -97,6 +135,12 @@ class html return ' onmouseover="'.$opt_out.'return escape(\''.str_replace(array("\n","\r","'",'"'),array('','',"\\'",'"'),$text).'\')"'; } + /** + * activates URLs in a text, URLs get replaced by html-links + * + * @param string $content text containing URLs + * @return string html with activated links + */ function activate_links($content) { // Exclude everything which is already a link @@ -124,6 +168,17 @@ class html return preg_replace( $Expr, "$0", $result ); } + /** + * escapes chars with special meaning in html as entities + * + * Allows to use and char in the html-output and prefents XSS attacks. + * Some entities are allowed and get NOT escaped: + * - some translations (AFAIK the arabic ones) need this + * - < > for convinience + * + * @param string $str string to escape + * @return string + */ function htmlspecialchars($str) { // add @ by lkneschke to supress warning about unknown charset @@ -141,12 +196,12 @@ class html * @param string $name string with name of the submitted var which holds the key of the selected item form array * @param string/array $key key(s) of already selected item(s) from $arr, eg. '1' or '1,2' or array with keys * @param array $arr array with items to select, eg. $arr = array ( 'y' => 'yes','n' => 'no','m' => 'maybe'); - * @param boolean $no_lang if !$no_lang send items through lang() + * @param boolean $no_lang NOT run the labels of the options through lang(), default false=use lang() * @param string $options additional options (e.g. 'width') * @param int $multiple number of lines for a multiselect, default 0 = no multiselect * @return string to set for a template or to echo into html page */ - function select($name, $key, $arr=0,$no_lang=0,$options='',$multiple=0) + function select($name, $key, $arr=0,$no_lang=false,$options='',$multiple=0) { if (!is_array($arr)) { @@ -167,21 +222,53 @@ class html // explode on ',' only if multiple values expected and the key contains just numbers and commas $key = $multiple && preg_match('/^[,0-9]+$/',$key) ? explode(',',$key) : array($key); } - foreach($arr as $k => $text) + foreach($arr as $k => $data) { - $out .= '\n"; } - $out .= ">" . $this->htmlspecialchars($no_lang || $text == '' ? $text : lang($text)) . "\n"; } $out .= "\n"; return $out; } + /** + * generates an option-tag for a selectbox + * + * @param string $value value + * @param string $label label + * @param mixed $selected value or array of values of options to mark as selected + * @param boolean $no_lang NOT running the label through lang(), default false=use lang() + * @return string html + */ + function select_option($value,$label,$selected,$no_lang=0) + { + return '\n"; + } + + /** + * generates a div-tag + * + * @param string $content of a div, or '' to generate only the opening tag + * @param string $options to include in the tag, default ''=none + * @param string $class css-class attribute, default ''=none + * @param string $style css-styles attribute, default ''=none + * @return string html + */ function div($content,$options='',$class='',$style='') { if ($class) $options .= ' class="'.$class.'"'; @@ -190,6 +277,14 @@ class html return "html::link(url='$url',vars='"; print_r($vars); echo "')
\n"; @@ -465,11 +591,31 @@ htmlareaConfig_'.$id.'.editorURL = '."'$this->phpgwapi_js_url/htmlarea/';"; return $GLOBALS['phpgw']->link($url,$vars); } - function checkbox($name,$value='') + /** + * represents html checkbox + * + * @param string $name name + * @param boolean $checked box checked on display + * @param string $value value the var should be set to, default 'True' + * @return string html + */ + function checkbox($name,$checked=false,$value='True') { - return "\n"; + return '\n"; } + /** + * represents a html form + * + * @param string $content of the form, if '' only the opening tag gets returned + * @param array $hidden_vars array with name-value pairs for hidden input fields + * @param string $url eGW relative URL, will be run through the link function + * @param string/array $url_vars parameters for the URL, send to link function too + * @param string $name name of the form, defaul ''=none + * @param string $options attributes for the tag, default ''=none + * @param string $method method of the form, default 'POST' + * @return string html + */ function form($content,$hidden_vars,$url,$url_vars='',$name='',$options='',$method='POST') { $html = "