Even more flexible ... (was: Re: More flexible html_select_date)
| From: | Alexander Skwar | Date: | Sat, 25 Aug 2001 15:48:05 +0000 |
| Subject: | Even more flexible ... (was: Re: More flexible html_select_date) | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-1389@lists.php.net to get a copy of this message | ||
So sprach »Alexander 'Digital Projects' Skwar« am 2001-08-24 um 19:37:59 +0200 :
> Hi!
>
> I've modified the {html_select_date} function quite a bit. I've
> introduced a number of new options which may be passed.
And I modified it again. Since I needed the years to be displayed in
reverse order (2000, 1999, ....), I introduced yet another new option:
year_reverse
Setting it to TRUE returns the years as above (2000, 1999, ....). Not
specifying it, or setting it to FALSE gives the old behaviour: 1999,
2000.
Attached are diffs my already modified version of Smarty.addons.php
(Smarty.addons.php.mod.diff) and to the original one, as shipped with
Smarty 1.4.4 (Smarty.addons.php.original.diff).
I've also added to the docs. Attached is the diff to my modified
version (docs.sgm.mod.diff) and to the 1.4.4's docs.sgm
(docs.sgm.original.diff).
Alexander Skwar
--
How to quote: http://learn.to/quote (german) http://quote.6x.to (english)
Homepage: http://www.digitalprojects.com | http://www.iso-top.de
iso-top.de - Die günstige Art an Linux Distributionen zu kommen
Uptime: 7 hours 12 minutes
--- Smarty.addons.php.Meins Sat Aug 25 17:34:13 2001 +++ Smarty.addons.php Sat Aug 25 17:37:05 2001 @@ -304,6 +304,8 @@ $month_format = "%B"; $day_format = "%02d"; $year_as_text = false; + /* Display years in reverse order? Ie. 2000,1999,.... */ + $year_reverse = FALSE; /* <select size>'s of the different <select> tags */ /* If not set, no size is printed */ $day_size = NULL; @@ -388,6 +390,9 @@ $year_result .= 'name="'.$prefix.'Year" value="'.strftime('%Y', $time).'" size="4" maxlength="4">'; } else { $years = range($start_year, $end_year); + if ($year_reverse){ + rsort($years, SORT_NUMERIC); + } $year_result .= '<select name="'.$prefix.'Year"'; if (NULL !== $all_args){ --- Smarty.addons.php.Original Fri Aug 24 18:15:08 2001 +++ Smarty.addons.php Sat Aug 25 17:37:05 2001 @@ -304,12 +304,32 @@ $month_format = "%B"; $day_format = "%02d"; $year_as_text = false; + /* Display years in reverse order? Ie. 2000,1999,.... */ + $year_reverse = FALSE; + /* <select size>'s of the different <select> tags */ + /* If not set, no size is printed */ + $day_size = NULL; + $month_size = NULL; + $year_size = NULL; + /* Unparsed arguments common to *ALL* the <select>/<input> tags */ + /* An example might be in the template: all_args='class="foo"' */ + $all_args = NULL; + /* Seperate arguments for the tags */ + $day_args = NULL; + $month_args = NULL; + $year_args = NULL; + /* Order in which to display the fields */ + /* "D" -> day, "M" -> month, "Y" -> year */ + $date_order = 'MDY'; + /* String printed between the different fields */ + $field_sep = "\n"; extract(func_get_arg(0)); $time = smarty_make_timestamp($time); + $date_order = strtoupper($date_order); - $html_result = ""; + $html_result = $month_result = $day_result = $year_result = ""; if ($display_months) { $month_names = array(); @@ -317,12 +337,22 @@ for ($i = 1; $i <= 12; $i++) $month_names[] = strftime($month_format, mktime(0, 0, 0, $i, 1, 2000)); - $html_result .= '<select name="'.$prefix.'Month">'."\n"; - $html_result .= smarty_func_html_options(array('output' => $month_names, - 'values' => range(1, 12), - 'selected' => strftime("%m", $time), - 'print_result' => false)); - $html_result .= "</select>\n"; + $month_result .= '<select name="'.$prefix.'Month"'; + if (NULL !== $all_args){ + $month_result .= ' ' . $all_args; + } + if (NULL !== $month_args){ + $month_result .= ' ' . $month_args; + } + if (NULL !== $month_size){ + $month_result .= ' size="' . $month_size . '"'; + } + $month_result .= '>'."\n"; + $month_result .= smarty_func_html_options(array('output' => $month_names, + 'values' => range(1, 12), + 'selected' => strftime("%m", $time), + 'print_result' => false)); + $month_result .= '</select>'; } if ($display_days) { @@ -330,27 +360,75 @@ for ($i = 0; $i < count($days); $i++) $days[$i] = sprintf($day_format, $days[$i]); - $html_result .= '<select name="'.$prefix.'Day">'."\n"; - $html_result .= smarty_func_html_options(array('output' => $days, - 'values' => range(1, 31), - 'selected' => strftime("%d", $time), - 'print_result' => false)); - $html_result .= "</select>\n"; + $day_result .= '<select name="'.$prefix.'Day"'; + if (NULL !== $all_args){ + $day_result .= ' ' . $all_args; + } + if (NULL !== $day_args){ + $day_result .= ' ' . $day_args; + } + if (NULL !== $day_size){ + $day_result .= ' size="' . $day_size . '"'; + } + $day_result .= '>'."\n"; + $day_result .= smarty_func_html_options(array('output' => $days, + 'values' => range(1, 31), + 'selected' => strftime("%d", $time), + 'print_result' => false)); + $day_result .= '</select>'; } if ($display_years) { if ($year_as_text) { - $html_result .= '<input type="text" name="'.$prefix.'Year" value="'.strftime('%Y', $time).'" size="4" maxlength="4">'; + $year_result .= '<input type="text" '; + if (NULL !== $all_args){ + $year_result .= ' ' . $all_args; + } + if (NULL !== $year_args){ + $year_result .= ' ' . $year_args; + } + $year_result .= 'name="'.$prefix.'Year" value="'.strftime('%Y', $time).'" size="4" maxlength="4">'; } else { $years = range($start_year, $end_year); - - $html_result .= '<select name="'.$prefix.'Year">'."\n"; - $html_result .= smarty_func_html_options(array('output' => $years, + if ($year_reverse){ + rsort($years, SORT_NUMERIC); + } + + $year_result .= '<select name="'.$prefix.'Year"'; + if (NULL !== $all_args){ + $year_result .= ' ' . $all_args; + } + if (NULL !== $year_args){ + $year_result .= ' ' . $year_args; + } + if (NULL !== $year_size){ + $year_result .= ' size="' . $year_size . '"'; + } + $year_result .= '>'."\n"; + $year_result .= smarty_func_html_options(array('output' => $years, 'values' => $years, 'selected' => strftime("%Y", $time), 'print_result' => false)); - $html_result .= "</select>\n"; + $year_result .= '</select>'; } + } + + // Loop thru the date_order field + for ($i = 0; $i <= 2; $i++){ + $c = substr($date_order, $i, 1); + switch ($c){ + case 'D': + $html_result .= $day_result; + break; + case 'M': + $html_result .= $month_result; + break; + case 'Y': + $html_result .= $year_result; + break; + } + // Add the field seperator + $html_result .= $field_sep; } print $html_result; --- docs.sgm.Meins Sat Aug 25 17:39:33 2001 +++ docs.sgm Sat Aug 25 17:41:53 2001 @@ -3262,6 +3262,13 @@ <entry>\n</entry> <entry>String which is to be printed between all the fields. The default is a line break.</entry> </row> + <row> + <entry>year_reverse</entry> + <entry>boolean</entry> + <entry>No</entry> + <entry>FALSE</entry> + <entry>Should the years be displayed in reverse order? Specifying TRUE would return 2000, 1999, 1998...., while the default would be to return 1998, 1999, 2000</entr> + </row> </tbody> </tgroup> </informaltable> --- docs.sgm.Original Fri Aug 24 21:12:56 2001 +++ docs.sgm Sat Aug 25 17:41:53 2001 @@ -3199,6 +3199,76 @@ <entry>false</entry> <entry>whether or not to display the year as text</entry> </row> + <row> + <entry>day_size</entry> + <entry>string</entry> + <entry>No</entry> + <entry>Unset</entry> + <entry>Size to display the day select box in. If unset, no size="" parameter is printed</entry> + </row> + <row> + <entry>month_size</entry> + <entry>string</entry> + <entry>No</entry> + <entry>Unset</entry> + <entry>Size to display the month select box in. If unset, no size="" parameter is printed</entry> + </row> + <row> + <entry>year_size</entry> + <entry>string</entry> + <entry>No</entry> + <entry>Unset</entry> + <entry>Size to display the year select box in. If unset, no size="" parameter is printed</entry> + </row> + <row> + <entry>all_args</entry> + <entry>string</entry> + <entry>No</entry> + <entry>Unset</entry> + <entry>Additional arguments to all the >select</>input< tags. These arguments are printed as-is. Eg. in the template might be all_args='class="foo" id="yo"', which would then assign 'class="foo" id="yo"' to all the tags.</entry> + </row> + <row> + <entry>day_args</entry> + <entry>string</entry> + <entry>No</entry> + <entry>Unset</entry> + <entry>Additional arguments to the day select box</entry> + </row> + <row> + <entry>month_args</entry> + <entry>string</entry> + <entry>No</entry> + <entry>Unset</entry> + <entry>Additional arguments to the month select box</entry> + </row> + <row> + <entry>year_args</entry> + <entry>string</entry> + <entry>No</entry> + <entry>Unset</entry> + <entry>Additional arguments to the year select box</entry> + </row> + <row> + <entry>date_order</entry> + <entry>string</entry> + <entry>No</entry> + <entry>MDY</entry> + <entry>Order in which the fields are to be displayed. Possible values are all combinations of the letters D, M, Y. The letters stand for day (D), month (M) and year (Y)</entry> + </row> + <row> + <entry>field_sep</entry> + <entry>string</entry> + <entry>No</entry> + <entry>\n</entry> + <entry>String which is to be printed between all the fields. The default is a line break.</entry> + </row> + <row> + <entry>year_reverse</entry> + <entry>boolean</entry> + <entry>No</entry> + <entry>FALSE</entry> + <entry>Should the years be displayed in reverse order? Specifying TRUE would return 2000, 1999, 1998...., while the default would be to return 1998, 1999, 2000</entr> + </row> </tbody> </tgroup> </informaltable>
--- Smarty.addons.php.Meins Sat Aug 25 17:34:13 2001 +++ Smarty.addons.php Sat Aug 25 17:37:05 2001 @@ -304,6 +304,8 @@ $month_format = "%B"; $day_format = "%02d"; $year_as_text = false; + /* Display years in reverse order? Ie. 2000,1999,.... */ + $year_reverse = FALSE; /* <select size>'s of the different <select> tags */ /* If not set, no size is printed */ $day_size = NULL; @@ -388,6 +390,9 @@ $year_result .= 'name="'.$prefix.'Year" value="'.strftime('%Y', $time).'" size="4" maxlength="4">'; } else { $years = range($start_year, $end_year); + if ($year_reverse){ + rsort($years, SORT_NUMERIC); + } $year_result .= '<select name="'.$prefix.'Year"'; if (NULL !== $all_args){ --- Smarty.addons.php.Original Fri Aug 24 18:15:08 2001 +++ Smarty.addons.php Sat Aug 25 17:37:05 2001 @@ -304,12 +304,32 @@ $month_format = "%B"; $day_format = "%02d"; $year_as_text = false; + /* Display years in reverse order? Ie. 2000,1999,.... */ + $year_reverse = FALSE; + /* <select size>'s of the different <select> tags */ + /* If not set, no size is printed */ + $day_size = NULL; + $month_size = NULL; + $year_size = NULL; + /* Unparsed arguments common to *ALL* the <select>/<input> tags */ + /* An example might be in the template: all_args='class="foo"' */ + $all_args = NULL; + /* Seperate arguments for the tags */ + $day_args = NULL; + $month_args = NULL; + $year_args = NULL; + /* Order in which to display the fields */ + /* "D" -> day, "M" -> month, "Y" -> year */ + $date_order = 'MDY'; + /* String printed between the different fields */ + $field_sep = "\n"; extract(func_get_arg(0)); $time = smarty_make_timestamp($time); + $date_order = strtoupper($date_order); - $html_result = ""; + $html_result = $month_result = $day_result = $year_result = ""; if ($display_months) { $month_names = array(); @@ -317,12 +337,22 @@ for ($i = 1; $i <= 12; $i++) $month_names[] = strftime($month_format, mktime(0, 0, 0, $i, 1, 2000)); - $html_result .= '<select name="'.$prefix.'Month">'."\n"; - $html_result .= smarty_func_html_options(array('output' => $month_names, - 'values' => range(1, 12), - 'selected' => strftime("%m", $time), - 'print_result' => false)); - $html_result .= "</select>\n"; + $month_result .= '<select name="'.$prefix.'Month"'; + if (NULL !== $all_args){ + $month_result .= ' ' . $all_args; + } + if (NULL !== $month_args){ + $month_result .= ' ' . $month_args; + } + if (NULL !== $month_size){ + $month_result .= ' size="' . $month_size . '"'; + } + $month_result .= '>'."\n"; + $month_result .= smarty_func_html_options(array('output' => $month_names, + 'values' => range(1, 12), + 'selected' => strftime("%m", $time), + 'print_result' => false)); + $month_result .= '</select>'; } if ($display_days) { @@ -330,27 +360,75 @@ for ($i = 0; $i < count($days); $i++) $days[$i] = sprintf($day_format, $days[$i]); - $html_result .= '<select name="'.$prefix.'Day">'."\n"; - $html_result .= smarty_func_html_options(array('output' => $days, - 'values' => range(1, 31), - 'selected' => strftime("%d", $time), - 'print_result' => false)); - $html_result .= "</select>\n"; + $day_result .= '<select name="'.$prefix.'Day"'; + if (NULL !== $all_args){ + $day_result .= ' ' . $all_args; + } + if (NULL !== $day_args){ + $day_result .= ' ' . $day_args; + } + if (NULL !== $day_size){ + $day_result .= ' size="' . $day_size . '"'; + } + $day_result .= '>'."\n"; + $day_result .= smarty_func_html_options(array('output' => $days, + 'values' => range(1, 31), + 'selected' => strftime("%d", $time), + 'print_result' => false)); + $day_result .= '</select>'; } if ($display_years) { if ($year_as_text) { - $html_result .= '<input type="text" name="'.$prefix.'Year" value="'.strftime('%Y', $time).'" size="4" maxlength="4">'; + $year_result .= '<input type="text" '; + if (NULL !== $all_args){ + $year_result .= ' ' . $all_args; + } + if (NULL !== $year_args){ + $year_result .= ' ' . $year_args; + } + $year_result .= 'name="'.$prefix.'Year" value="'.strftime('%Y', $time).'" size="4" maxlength="4">'; } else { $years = range($start_year, $end_year); - - $html_result .= '<select name="'.$prefix.'Year">'."\n"; - $html_result .= smarty_func_html_options(array('output' => $years, + if ($year_reverse){ + rsort($years, SORT_NUMERIC); + } + + $year_result .= '<select name="'.$prefix.'Year"'; + if (NULL !== $all_args){ + $year_result .= ' ' . $all_args; + } + if (NULL !== $year_args){ + $year_result .= ' ' . $year_args; + } + if (NULL !== $year_size){ + $year_result .= ' size="' . $year_size . '"'; + } + $year_result .= '>'."\n"; + $year_result .= smarty_func_html_options(array('output' => $years, 'values' => $years, 'selected' => strftime("%Y", $time), 'print_result' => false)); - $html_result .= "</select>\n"; + $year_result .= '</select>'; } + } + + // Loop thru the date_order field + for ($i = 0; $i <= 2; $i++){ + $c = substr($date_order, $i, 1); + switch ($c){ + case 'D': + $html_result .= $day_result; + break; + case 'M': + $html_result .= $month_result; + break; + case 'Y': + $html_result .= $year_result; + break; + } + // Add the field seperator + $html_result .= $field_sep; } print $html_result; --- docs.sgm.Meins Sat Aug 25 17:39:33 2001 +++ docs.sgm Sat Aug 25 17:41:53 2001 @@ -3262,6 +3262,13 @@ <entry>\n</entry> <entry>String which is to be printed between all the fields. The default is a line break.</entry> </row> + <row> + <entry>year_reverse</entry> + <entry>boolean</entry> + <entry>No</entry> + <entry>FALSE</entry> + <entry>Should the years be displayed in reverse order? Specifying TRUE would return 2000, 1999, 1998...., while the default would be to return 1998, 1999, 2000</entr> + </row> </tbody> </tgroup> </informaltable> --- docs.sgm.Original Fri Aug 24 21:12:56 2001 +++ docs.sgm Sat Aug 25 17:41:53 2001 @@ -3199,6 +3199,76 @@ <entry>false</entry> <entry>whether or not to display the year as text</entry> </row> + <row> + <entry>day_size</entry> + <entry>string</entry> + <entry>No</entry> + <entry>Unset</entry> + <entry>Size to display the day select box in. If unset, no size="" parameter is printed</entry> + </row> + <row> + <entry>month_size</entry> + <entry>string</entry> + <entry>No</entry> + <entry>Unset</entry> + <entry>Size to display the month select box in. If unset, no size="" parameter is printed</entry> + </row> + <row> + <entry>year_size</entry> + <entry>string</entry> + <entry>No</entry> + <entry>Unset</entry> + <entry>Size to display the year select box in. If unset, no size="" parameter is printed</entry> + </row> + <row> + <entry>all_args</entry> + <entry>string</entry> + <entry>No</entry> + <entry>Unset</entry> + <entry>Additional arguments to all the >select</>input< tags. These arguments are printed as-is. Eg. in the template might be all_args='class="foo" id="yo"', which would then assign 'class="foo" id="yo"' to all the tags.</entry> + </row> + <row> + <entry>day_args</entry> + <entry>string</entry> + <entry>No</entry> + <entry>Unset</entry> + <entry>Additional arguments to the day select box</entry> + </row> + <row> + <entry>month_args</entry> + <entry>string</entry> + <entry>No</entry> + <entry>Unset</entry> + <entry>Additional arguments to the month select box</entry> + </row> + <row> + <entry>year_args</entry> + <entry>string</entry> + <entry>No</entry> + <entry>Unset</entry> + <entry>Additional arguments to the year select box</entry> + </row> + <row> + <entry>date_order</entry> + <entry>string</entry> + <entry>No</entry> + <entry>MDY</entry> + <entry>Order in which the fields are to be displayed. Possible values are all combinations of the letters D, M, Y. The letters stand for day (D), month (M) and year (Y)</entry> + </row> + <row> + <entry>field_sep</entry> + <entry>string</entry> + <entry>No</entry> + <entry>\n</entry> + <entry>String which is to be printed between all the fields. The default is a line break.</entry> + </row> + <row> + <entry>year_reverse</entry> + <entry>boolean</entry> + <entry>No</entry> + <entry>FALSE</entry> + <entry>Should the years be displayed in reverse order? Specifying TRUE would return 2000, 1999, 1998...., while the default would be to return 1998, 1999, 2000</entr> + </row> </tbody> </tgroup> </informaltable>