48 require_once(SMARTY_PLUGINS_DIR .
'shared.escape_special_chars.php');
61 foreach ($params as $_key => $_val) {
65 $$_key = (string) $_val;
70 if (is_array($_val)) {
71 trigger_error(
'html_radios: the "' . $_key .
'" attribute cannot be an array', E_USER_WARNING);
72 } elseif (is_object($_val)) {
73 if (method_exists($_val,
"__toString")) {
74 $selected = smarty_function_escape_special_chars((
string) $_val->__toString());
76 trigger_error(
"html_radios: selected attribute is an object of class '" . get_class($_val) .
"' without __toString() method", E_USER_NOTICE);
79 $selected = (string) $_val;
86 $$_key = (bool) $_val;
90 $$_key = (array) $_val;
95 $$_key = array_values((array) $_val);
99 trigger_error(
'html_radios: the use of the "radios" attribute is deprecated, use "options" instead', E_USER_WARNING);
100 $options = (array) $_val;
111 if (!empty($params[
'strict'])) {
112 if (!is_scalar($_val)) {
113 trigger_error(
"html_options: $_key attribute must be a scalar, only boolean true or string '$_key' will actually add the attribute", E_USER_NOTICE);
116 if ($_val ===
true || $_val === $_key) {
117 $extra .=
' ' . $_key .
'="' . smarty_function_escape_special_chars($_key) .
'"';
125 if (!is_array($_val)) {
126 $extra .=
' ' . $_key .
'="' . smarty_function_escape_special_chars($_val) .
'"';
128 trigger_error(
"html_radios: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
134 if (!isset($options) && !isset($values)) {
140 $_html_result = array();
142 if (isset($options)) {
143 foreach ($options as $_key => $_val) {
147 foreach ($values as $_i => $_key) {
148 $_val = isset($output[$_i]) ? $output[$_i] :
'';
153 if (!empty($params[
'assign'])) {
154 $template->assign($params[
'assign'], $_html_result);
156 return implode(
"\n", $_html_result);
164 if (is_object($value)) {
165 if (method_exists($value,
"__toString")) {
166 $value = (string) $value->__toString();
168 trigger_error(
"html_options: value is an object of class '" . get_class($value) .
"' without __toString() method", E_USER_NOTICE);
173 $value = (string) $value;
176 if (is_object($output)) {
177 if (method_exists($output,
"__toString")) {
178 $output = (string) $output->__toString();
180 trigger_error(
"html_options: output is an object of class '" . get_class($output) .
"' without __toString() method", E_USER_NOTICE);
185 $output = (string) $output;
190 $_id = smarty_function_escape_special_chars(preg_replace(
'![^\w\-\.]!' .
Smarty::$_UTF8_MODIFIER,
'_', $name .
'_' . $value));
191 $_output .=
'<label for="' . $_id .
'">';
193 $_output .=
'<label>';
197 $name = smarty_function_escape_special_chars($name);
198 $value = smarty_function_escape_special_chars($value);
200 $output = smarty_function_escape_special_chars($output);
203 $_output .=
'<input type="radio" name="' . $name .
'" value="' . $value .
'"';
205 if ($labels && $label_ids) {
206 $_output .=
' id="' . $_id .
'"';
209 if ($value === $selected) {
210 $_output .=
' checked="checked"';
213 $_output .= $extra .
' />' . $output;
215 $_output .=
'</label>';
218 $_output .= $separator;