added html_radios to distribution

This commit is contained in:
mohrt
2003-02-24 15:36:34 +00:00
parent ea0e560e90
commit 878d8ab5c5
2 changed files with 69 additions and 0 deletions

1
NEWS
View File

@@ -1,3 +1,4 @@
- added html_radios to distribution (Christopher Kvarme, Monte)
- fixed string_format modifier args (wrong order) (Paul - fixed string_format modifier args (wrong order) (Paul
Lockaby, Monte) Lockaby, Monte)
- use tmp file for file writes, avoid file lock race (Monte) - use tmp file for file writes, avoid file lock race (Monte)

View File

@@ -0,0 +1,68 @@
<?php
/*
* Smarty plugin
* ---------------------------------------------------------------------------------------------
* Type: function
* Name: html_radios
* Purpose: Prints the list of <input type="radio" tags generated from the passed parameters
* Parameters: name [required]- string
* checked [optional]- string
* values [required] - array
* separator[optional] - ie <br> or &nbsp;
* output[optional] -without this one the buttons don't have names
* Author: Christopher Kvarme <christopher.kvarme@flashjab.com>
* ---------------------------------------------------------------------------------------------
*/
function smarty_function_html_radios($params, &$smarty)
{
extract($params);
$html_result = '';
settype($checked, 'array');
if (isset($radios)) {
settype($radios, 'array');
foreach ($radios as $key => $value) {
$html_result .= smarty_function_html_radios_optoutput($key, $value, $checked);
}
} else {
settype($output, 'array');
settype($values, 'array');
for ($i = 0, $for_max = count($output); $i < $for_max; $i++) {
if ($i < count($values)) {
$html_result .= smarty_function_html_radios_optoutput($values[$i], $output[$i], $checked, $name, $separator);
} else {
$html_result .= smarty_function_html_radios_optoutput($output[$i], $output[$i], $checked, $name, $separator);
}
}
}
return $html_result;
}
function smarty_function_html_radios_optoutput($key, $value, $checked, $name, $separator) {
if(!is_array($value)) {
$html_result = '<input type="radio" name="' . htmlspecialchars($name) . '" value="' .
htmlspecialchars($key) . '"';
if (in_array($key, $checked))
$html_result .= " checked";
$html_result .= '>' . htmlspecialchars($value) . $separator . "\n";
} else {
$html_result = smarty_function_html_radios_optgroup($key, $value, $checked, $name, $separator);
}
return $html_result;
}
function smarty_function_html_radios_optgroup($key, $values, $checked) {
$optgroup_html = '<optgroup label="' . htmlspecialchars($value) . '">' . "\n";
foreach ($values as $key => $value) {
$optgroup_html .= smarty_function_html_radios_optoutput($key, $value, $checked);
}
$optgroup_html .= "</optgroup>\n";
return $optgroup_html;
}
/* vim: set expandtab: */
?>