diff --git a/NEWS b/NEWS
index dfe49508..3c915ebb 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,7 @@
+ - added YYYY-MM-DD format support to html_select_date
+ (Jan Rosier, Monte)
+ - fixed cache_lifetime logic bug,
+ also made -1 = never expire (Monte)
- fixed directory separator issue for Windows. (Andrei)
- added ability to use simple variables as array indices or
object properties. (Andrei)
diff --git a/libs/plugins/function.html_select_date.php b/libs/plugins/function.html_select_date.php
index b86e9a25..3b2fd01b 100644
--- a/libs/plugins/function.html_select_date.php
+++ b/libs/plugins/function.html_select_date.php
@@ -1,17 +1,18 @@
plugins_dir . '/shared.make_timestamp.php';
@@ -20,7 +21,6 @@ function smarty_function_html_select_date($params, &$smarty)
{
/* Default values. */
$prefix = "Date_";
- $time = time();
$start_year = strftime("%Y");
$end_year = $start_year;
$display_days = true;
@@ -55,6 +55,16 @@ function smarty_function_html_select_date($params, &$smarty)
extract($params);
+ // If $time is not in format yyyy-mm-dd
+ if (!preg_match('/\d{4}-\d{2}-\d{2}/', $time)) {
+ // then $time is empty or unix timestamp or mysql timestamp
+ // using smarty_make_timestamp to get an unix timestamp and
+ // strftime to make yyyy-mm-dd
+ $time = strftime('%Y-%m-%d', smarty_make_timestamp($time));
+ }
+ // Now split this in pieces, which later can be used to set the select
+ $time = explode("-", $time);
+
// make syntax "+N" or "-N" work with start_year and end_year
if (preg_match('!^(\+|\-)\s*(\d+)$!', $end_year, $match)) {
if ($match[1] == '+') {
@@ -70,8 +80,7 @@ function smarty_function_html_select_date($params, &$smarty)
$start_year = strftime('%Y') - $match[2];
}
}
-
- $time = smarty_make_timestamp($time);
+
$field_order = strtoupper($field_order);
$html_result = $month_result = $day_result = $year_result = "";
@@ -100,16 +109,16 @@ function smarty_function_html_select_date($params, &$smarty)
$month_result .= '>'."\n";
$month_result .= smarty_function_html_options(array('output' => $month_names,
'values' => range(1, 12),
- 'selected' => strftime("%m", $time),
+ 'selected' => $time[1],
'print_result' => false),
$smarty);
$month_result .= '';
}
if ($display_days) {
- $days = range(1, 31);
- for ($i = 0; $i < count($days); $i++)
- $days[$i] = sprintf($day_format, $days[$i]);
+ $days = array();
+ for ($i = 1; $i <= 31; $i++)
+ $days[] = sprintf($day_format, $i);
$day_result .= '';
@@ -142,7 +151,7 @@ function smarty_function_html_select_date($params, &$smarty)
$year_name = $prefix . 'Year';
}
if ($year_as_text) {
- $year_result .= ' $years,
'values' => $years,
- 'selected' => strftime("%Y", $time),
+ 'selected' => $time[0],
'print_result' => false),
$smarty);
$year_result .= '';
diff --git a/plugins/function.html_select_date.php b/plugins/function.html_select_date.php
index b86e9a25..3b2fd01b 100644
--- a/plugins/function.html_select_date.php
+++ b/plugins/function.html_select_date.php
@@ -1,17 +1,18 @@
plugins_dir . '/shared.make_timestamp.php';
@@ -20,7 +21,6 @@ function smarty_function_html_select_date($params, &$smarty)
{
/* Default values. */
$prefix = "Date_";
- $time = time();
$start_year = strftime("%Y");
$end_year = $start_year;
$display_days = true;
@@ -55,6 +55,16 @@ function smarty_function_html_select_date($params, &$smarty)
extract($params);
+ // If $time is not in format yyyy-mm-dd
+ if (!preg_match('/\d{4}-\d{2}-\d{2}/', $time)) {
+ // then $time is empty or unix timestamp or mysql timestamp
+ // using smarty_make_timestamp to get an unix timestamp and
+ // strftime to make yyyy-mm-dd
+ $time = strftime('%Y-%m-%d', smarty_make_timestamp($time));
+ }
+ // Now split this in pieces, which later can be used to set the select
+ $time = explode("-", $time);
+
// make syntax "+N" or "-N" work with start_year and end_year
if (preg_match('!^(\+|\-)\s*(\d+)$!', $end_year, $match)) {
if ($match[1] == '+') {
@@ -70,8 +80,7 @@ function smarty_function_html_select_date($params, &$smarty)
$start_year = strftime('%Y') - $match[2];
}
}
-
- $time = smarty_make_timestamp($time);
+
$field_order = strtoupper($field_order);
$html_result = $month_result = $day_result = $year_result = "";
@@ -100,16 +109,16 @@ function smarty_function_html_select_date($params, &$smarty)
$month_result .= '>'."\n";
$month_result .= smarty_function_html_options(array('output' => $month_names,
'values' => range(1, 12),
- 'selected' => strftime("%m", $time),
+ 'selected' => $time[1],
'print_result' => false),
$smarty);
$month_result .= '';
}
if ($display_days) {
- $days = range(1, 31);
- for ($i = 0; $i < count($days); $i++)
- $days[$i] = sprintf($day_format, $days[$i]);
+ $days = array();
+ for ($i = 1; $i <= 31; $i++)
+ $days[] = sprintf($day_format, $i);
$day_result .= '';
@@ -142,7 +151,7 @@ function smarty_function_html_select_date($params, &$smarty)
$year_name = $prefix . 'Year';
}
if ($year_as_text) {
- $year_result .= ' $years,
'values' => $years,
- 'selected' => strftime("%Y", $time),
+ 'selected' => $time[0],
'print_result' => false),
$smarty);
$year_result .= '';