- bugfix {html_select_date} and {html_select_time} did not properly handle empty time arguments (Forum Topic 20190)

see http://www.smarty.net/forums/viewtopic.php?t=20190
This commit is contained in:
rodneyrehm
2011-10-20 13:31:25 +00:00
parent b71323ca24
commit 922017c7fa
3 changed files with 13 additions and 12 deletions

View File

@@ -2,6 +2,7 @@
20.10.2011 20.10.2011
- @silenced unlink() in Smarty_Internal_Write_File since debuggers go haywire without it. - @silenced unlink() in Smarty_Internal_Write_File since debuggers go haywire without it.
- bugfix Smarty::clearCompiledTemplate() threw an Exception if $cache_id was not present in $compile_dir when $use_sub_dirs = true. - bugfix Smarty::clearCompiledTemplate() threw an Exception if $cache_id was not present in $compile_dir when $use_sub_dirs = true.
- bugfix {html_select_date} and {html_select_time} did not properly handle empty time arguments (Forum Topic 20190)
19.10.2011 19.10.2011
- revert PHP4 constructor message - revert PHP4 constructor message

View File

@@ -116,7 +116,7 @@ function smarty_function_html_select_date($params, $template)
foreach ($params as $_key => $_value) { foreach ($params as $_key => $_value) {
switch ($_key) { switch ($_key) {
case 'time': case 'time':
if (!is_array($_value)) { if (!is_array($_value) && $_value !== null) {
$time = smarty_make_timestamp($_value); $time = smarty_make_timestamp($_value);
} }
break; break;
@@ -202,7 +202,8 @@ function smarty_function_html_select_date($params, $template)
list($_year, $_month, $_day) = $time = explode('-', date('Y-m-d')); list($_year, $_month, $_day) = $time = explode('-', date('Y-m-d'));
} }
} elseif ($time === null) { } elseif ($time === null) {
list($_year, $_month, $_day) = $time = explode('-', date('Y-m-d')); //list($_year, $_month, $_day) = $time = explode('-', date('Y-m-d'));
$_year = $_month = $_day = $time = null;
} else { } else {
list($_year, $_month, $_day) = $time = explode('-', date('Y-m-d', $time)); list($_year, $_month, $_day) = $time = explode('-', date('Y-m-d', $time));
} }

View File

@@ -82,7 +82,7 @@ function smarty_function_html_select_time($params, $template)
foreach ($params as $_key => $_value) { foreach ($params as $_key => $_value) {
switch ($_key) { switch ($_key) {
case 'time': case 'time':
if (!is_array($_value)) { if (!is_array($_value) && $_value !== null) {
$time = smarty_make_timestamp($_value); $time = smarty_make_timestamp($_value);
} }
break; break;
@@ -180,7 +180,8 @@ function smarty_function_html_select_time($params, $template)
list($_year, $_month, $_day) = $time = explode('-', date('Y-m-d')); list($_year, $_month, $_day) = $time = explode('-', date('Y-m-d'));
} }
} elseif ($time === null) { } elseif ($time === null) {
list($_hour, $_minute, $_second) = $time = explode('-', date('H-i-s')); //list($_hour, $_minute, $_second) = $time = explode('-', date('H-i-s'));
$_hour = $_minute = $_second = $time = null;
} else { } else {
list($_hour, $_minute, $_second) = $time = explode('-', date('H-i-s', $time)); list($_hour, $_minute, $_second) = $time = explode('-', date('H-i-s', $time));
} }
@@ -219,15 +220,13 @@ function smarty_function_html_select_time($params, $template)
$_text = $hour_format == '%02d' ? $_val : sprintf($hour_format, $i); $_text = $hour_format == '%02d' ? $_val : sprintf($hour_format, $i);
$_value = $hour_value_format == '%02d' ? $_val : sprintf($hour_value_format, $i); $_value = $hour_value_format == '%02d' ? $_val : sprintf($hour_value_format, $i);
if ($use_24_hours) { if (!$use_24_hours) {
$selected = $_hour == $_val;
} else {
$_hour12 = $_hour == 0 $_hour12 = $_hour == 0
? 12 ? 12
: ($_hour <= 12 ? $_hour : $_hour -12); : ($_hour <= 12 ? $_hour : $_hour -12);
} }
$selected = $use_24_hours ? $_hour == $_val : $_hour12 == $_val; $selected = $_hour !== null ? ($use_24_hours ? $_hour == $_val : $_hour12 == $_val) : null;
$_html_hours .= '<option value="' . $_value . '"' $_html_hours .= '<option value="' . $_value . '"'
. ($selected ? ' selected="selected"' : '') . ($selected ? ' selected="selected"' : '')
. '>' . $_text . '</option>' . $option_separator; . '>' . $_text . '</option>' . $option_separator;
@@ -263,13 +262,13 @@ function smarty_function_html_select_time($params, $template)
$_html_minutes .= '<option value="">' . ( isset($minute_empty) ? $minute_empty : $all_empty ) . '</option>' . $option_separator; $_html_minutes .= '<option value="">' . ( isset($minute_empty) ? $minute_empty : $all_empty ) . '</option>' . $option_separator;
} }
$selected = $_minute - $_minute % $minute_interval; $selected = $_minute !== null ? ($_minute - $_minute % $minute_interval) : null;
for ($i=0; $i <= 59; $i += $minute_interval) { for ($i=0; $i <= 59; $i += $minute_interval) {
$_val = sprintf('%02d', $i); $_val = sprintf('%02d', $i);
$_text = $minute_format == '%02d' ? $_val : sprintf($minute_format, $i); $_text = $minute_format == '%02d' ? $_val : sprintf($minute_format, $i);
$_value = $minute_value_format == '%02d' ? $_val : sprintf($minute_value_format, $i); $_value = $minute_value_format == '%02d' ? $_val : sprintf($minute_value_format, $i);
$_html_minutes .= '<option value="' . $_value . '"' $_html_minutes .= '<option value="' . $_value . '"'
. ($selected == $i ? ' selected="selected"' : '') . ($selected === $i ? ' selected="selected"' : '')
. '>' . $_text . '</option>' . $option_separator; . '>' . $_text . '</option>' . $option_separator;
} }
@@ -303,13 +302,13 @@ function smarty_function_html_select_time($params, $template)
$_html_seconds .= '<option value="">' . ( isset($second_empty) ? $second_empty : $all_empty ) . '</option>' . $option_separator; $_html_seconds .= '<option value="">' . ( isset($second_empty) ? $second_empty : $all_empty ) . '</option>' . $option_separator;
} }
$selected = $_second - $_second % $second_interval; $selected = $_second !== null ? ($_second - $_second % $second_interval) : null;
for ($i=0; $i <= 59; $i += $second_interval) { for ($i=0; $i <= 59; $i += $second_interval) {
$_val = sprintf('%02d', $i); $_val = sprintf('%02d', $i);
$_text = $second_format == '%02d' ? $_val : sprintf($second_format, $i); $_text = $second_format == '%02d' ? $_val : sprintf($second_format, $i);
$_value = $second_value_format == '%02d' ? $_val : sprintf($second_value_format, $i); $_value = $second_value_format == '%02d' ? $_val : sprintf($second_value_format, $i);
$_html_seconds .= '<option value="' . $_value . '"' $_html_seconds .= '<option value="' . $_value . '"'
. ($selected == $i ? ' selected="selected"' : '') . ($selected === $i ? ' selected="selected"' : '')
. '>' . $_text . '</option>' . $option_separator; . '>' . $_text . '</option>' . $option_separator;
} }