diff --git a/NEWS b/NEWS index 4c474824..df57fa3f 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,6 @@ - - html_options passthru all unknown paramters now + - html_checkboxes and html_radios passthru all unknown paramters now + additionally their output is now XHTML compliant (messju) + - html_options passthru all unknown paramters now (messju) - fix link functionality of html_image, also make output XHTML compatible (Hinrich Donner, Monte) - append "@" to default modifier vars/args diff --git a/libs/plugins/function.html_checkboxes.php b/libs/plugins/function.html_checkboxes.php index 0c06ef5e..cb18d173 100644 --- a/libs/plugins/function.html_checkboxes.php +++ b/libs/plugins/function.html_checkboxes.php @@ -24,41 +24,75 @@ */ function smarty_function_html_checkboxes($params, &$smarty) { - require_once $smarty->_get_plugin_filepath('shared','escape_special_chars'); + require_once $smarty->_get_plugin_filepath('shared','escape_special_chars'); + + $name = 'checkbox'; + $values = null; + $checkboxes = null; + $checked = null; + $separator = ''; + $output = null; + + $extra = ''; + + foreach($params as $_key => $_val) { + switch($_key) { + case 'name': + case 'separator': + $$_key = $_val; + break; - extract($params); + case 'checkboxes': + $$_key = (array)$_val; + break; - $_html_result = ''; - if(!isset($name)){ - $name = 'checkbox'; - } - settype($checked, 'array'); - if (isset($checkboxes)) { - settype($checkboxes, 'array'); - foreach ($checkboxes as $_key => $_val) { - $_html_result .= smarty_function_html_checkboxes_output($name, $_key, $_val, $checked, $separator); - } - } else { - settype($output, 'array'); - settype($values, 'array'); - for ($_i = 0, $_for_max = count($output); $_i < $_for_max; $_i++) { - $_html_result .= smarty_function_html_checkboxes_output($name, $values[$_i], $output[$_i], $checked, $separator); - } - } + case 'values': + case 'output': + case 'checked': + $$_key = array_values((array)$_val); + break; - return $_html_result; + default: + $extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"'; + break; + } + } + + if (!isset($checkboxes) && !isset($values)) + return ''; /* raise error here? */ + + settype($checked, 'array'); + $_html_result = ''; + + if (is_array($checkboxes)) { + + foreach ($checkboxes as $_key=>$_val) + $_html_result .= smarty_function_html_checkboxes_output($name, $_key, $_val, $checked, $extra, $separator); + + + } else { + foreach ($values as $_i=>$_key) { + $_val = isset($output[$_i]) ? $output[$_i] : ''; + $_html_result .= smarty_function_html_checkboxes_output($name, $_key, $_val, $checked, $extra, $separator); + } + + } + + return $_html_result; + } -function smarty_function_html_checkboxes_output($name, $value, $output, $checked, $separator) { - $_output = '' . $output . $separator . "\n"; + + return $_output; } - ?> diff --git a/libs/plugins/function.html_options.php b/libs/plugins/function.html_options.php index 30477e21..1b3cd509 100644 --- a/libs/plugins/function.html_options.php +++ b/libs/plugins/function.html_options.php @@ -5,71 +5,96 @@ * ------------------------------------------------------------- * Type: function * Name: html_options + * Input: name (optional) - string default "select" + * values (required if no options supplied) - array + * options (required if no values supplied) - associative array + * selected (optional) - string default not set + * output (required if not options supplied) - array * Purpose: Prints the list of ' . "\n"; - foreach ($values as $key => $value) { - $optgroup_html .= smarty_function_html_options_optoutput($key, $value, $selected); - } - $optgroup_html .= "\n"; - return $optgroup_html; + $optgroup_html = '' . "\n"; + foreach ($values as $key => $value) { + $optgroup_html .= smarty_function_html_options_optoutput($key, $value, $selected); + } + $optgroup_html .= "\n"; + return $optgroup_html; } /* vim: set expandtab: */ diff --git a/libs/plugins/function.html_radios.php b/libs/plugins/function.html_radios.php index ae3e8a6e..88b48830 100644 --- a/libs/plugins/function.html_radios.php +++ b/libs/plugins/function.html_radios.php @@ -22,42 +22,75 @@ * {html_radios values=$ids checked=$checked separator='
' output=$names} * ------------------------------------------------------------- */ -require_once $this->_get_plugin_filepath('shared','escape_special_chars'); function smarty_function_html_radios($params, &$smarty) { - extract($params); + require_once $smarty->_get_plugin_filepath('shared','escape_special_chars'); - $_html_result = ''; - if(!isset($name)){ - $name = 'radio'; - } - settype($checked, 'array'); - if (isset($radios)) { - settype($radios, 'array'); - foreach ($radios as $_key => $_val) { - $_html_result .= smarty_function_html_radios_output($name, $_key, $_val, $checked, $separator); - } - } else { - settype($output, 'array'); - settype($values, 'array'); - for ($_i = 0, $_for_max = count($output); $_i < $_for_max; $_i++) { - $_html_result .= smarty_function_html_radios_output($name, $values[$_i], $output[$_i], $checked, $separator); - } - } + $name = 'radio'; + $values = null; + $radios = null; + $checked = null; + $separator = ''; + $output = null; + $extra = ''; + + foreach($params as $_key => $_val) { + switch($_key) { + case 'name': + case 'separator': + case 'checked': + $$_key = (string)$_val; + break; - return $_html_result; + case 'radios': + $$_key = (array)$_val; + break; + + case 'values': + case 'output': + $$_key = array_values((array)$_val); + break; + + default: + $extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"'; + break; + } + } + + if (!isset($radios) && !isset($values)) + return ''; /* raise error here? */ + + $_html_result = ''; + + if (isset($radios) && is_array($radios)) { + + foreach ((array)$radios as $_key=>$_val) + $_html_result .= smarty_function_html_radios_output($name, $_key, $_val, $checked, $extra, $separator); + + } else { + + foreach ((array)$values as $_i=>$_key) { + $_val = isset($output[$_i]) ? $output[$_i] : ''; + $_html_result .= smarty_function_html_radios_output($name, $_key, $_val, $checked, $extra, $separator); + } + + } + + return $_html_result; + } -function smarty_function_html_radios_output($name, $value, $output, $checked, $separator) { - $_output = '' . $output . $separator . "\n"; + + return $_output; } - ?>