And yet more flexible (was: Re: Even more flexible ...)
| From: | Alexander Skwar | Date: | Sat, 25 Aug 2001 17:56:07 +0000 |
| Subject: | And yet more flexible (was: Re: Even more flexible ...) | ||
| References: | 1 2 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-1390@lists.php.net to get a copy of this message | ||
So sprach »Alexander 'Digital Projects' Skwar« am 2001-08-25 um 17:48:05 +0200 :
> And I modified it again. Since I needed the years to be displayed in
And again :)
This time, I needed the fields to be part of an array. So I created the
option "in_array". For example, setting it to "birthday", would create
the fields "birthday[Day]", "birthday[Month]", and "birthday[Year]".
As usual, I attach diffs to the Smarty.addons.php file and the docs.sgm
file. The diffs are against the plain files from the 1.4.4
distribution.
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: 9 hours 22 minutes
--- Smarty.addons.php.Original Fri Aug 24 18:15:08 2001 +++ Smarty.addons.php Sat Aug 25 19:48:42 2001 @@ -304,12 +304,36 @@ $month_format = "%B"; $day_format = "%02d"; $year_as_text = false; + /* Display years in reverse order? Ie. 2000,1999,.... */ + $year_reverse = FALSE; + /* Should the select boxes be part of an array when returned from PHP? */ + /* Eg. setting it to "birthday", would create "birthday[Day]", "birthday[Month]" & "birthday[Year]" */ + /* Can be combined with prefix */ + $in_array = NULL; + /* <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 +341,27 @@ 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='; + if (NULL !== $in_array){ + $month_result .= '"' . $in_array . '[' . $prefix . 'Month]"'; + } else { + $month_result .= '"' . $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 +369,85 @@ 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='; + if (NULL !== $in_array){ + $day_result .= '"' . $in_array . '[' . $prefix . 'Day]"'; + } else { + $day_result .= '"' . $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 (NULL !== $in_array){ + $year_name = $in_array . '[' . $prefix . 'Year]'; + } else { + $year_name = $prefix . 'Year'; + } 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="' . $year_name . '" 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="' . $year_name . '"'; + 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.Original Fri Aug 24 21:12:56 2001 +++ docs.sgm Sat Aug 25 19:54:50 2001 @@ -3199,6 +3199,83 @@ <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</entry> + </row> + <row> + <entry>in_array</entry> + <entry>String</entry> + <entry>No</entry> + <entry>Unset</entry> + <entry>Should the returned fields be part of an array? Specifying a value makes the Day/Month/Year values part of this array. Eg. if in_array is set to "birthday", the fields birthday[Day], birthday[Month], and birthday[Year] would be created. Can be combined with prefix.</entry> + </row> </tbody> </tgroup> </informaltable>
--- Smarty.addons.php.Original Fri Aug 24 18:15:08 2001 +++ Smarty.addons.php Sat Aug 25 19:48:42 2001 @@ -304,12 +304,36 @@ $month_format = "%B"; $day_format = "%02d"; $year_as_text = false; + /* Display years in reverse order? Ie. 2000,1999,.... */ + $year_reverse = FALSE; + /* Should the select boxes be part of an array when returned from PHP? */ + /* Eg. setting it to "birthday", would create "birthday[Day]", "birthday[Month]" & "birthday[Year]" */ + /* Can be combined with prefix */ + $in_array = NULL; + /* <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 +341,27 @@ 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='; + if (NULL !== $in_array){ + $month_result .= '"' . $in_array . '[' . $prefix . 'Month]"'; + } else { + $month_result .= '"' . $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 +369,85 @@ 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='; + if (NULL !== $in_array){ + $day_result .= '"' . $in_array . '[' . $prefix . 'Day]"'; + } else { + $day_result .= '"' . $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 (NULL !== $in_array){ + $year_name = $in_array . '[' . $prefix . 'Year]'; + } else { + $year_name = $prefix . 'Year'; + } 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="' . $year_name . '" 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="' . $year_name . '"'; + 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.Original Fri Aug 24 21:12:56 2001 +++ docs.sgm Sat Aug 25 19:54:50 2001 @@ -3199,6 +3199,83 @@ <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</entry> + </row> + <row> + <entry>in_array</entry> + <entry>String</entry> + <entry>No</entry> + <entry>Unset</entry> + <entry>Should the returned fields be part of an array? Specifying a value makes the Day/Month/Year values part of this array. Eg. if in_array is set to "birthday", the fields birthday[Day], birthday[Month], and birthday[Year] would be created. Can be combined with prefix.</entry> + </row> </tbody> </tgroup> </informaltable>