From ab5d8d4e07bb3c8230d0285ef8902ef1979fce51 Mon Sep 17 00:00:00 2001 From: emkael Date: Thu, 18 Oct 2018 02:39:34 +0200 Subject: Updating Smarty --- lib/smarty/plugins/function.html_select_date.php | 250 +++++++++++------------ 1 file changed, 122 insertions(+), 128 deletions(-) (limited to 'lib/smarty/plugins/function.html_select_date.php') diff --git a/lib/smarty/plugins/function.html_select_date.php b/lib/smarty/plugins/function.html_select_date.php index 13c5003..86403e3 100644 --- a/lib/smarty/plugins/function.html_select_date.php +++ b/lib/smarty/plugins/function.html_select_date.php @@ -1,29 +1,17 @@ - * Name: html_select_date
+ * Type: function + * Name: html_select_date * Purpose: Prints the dropdowns for date selection. - * * ChangeLog: - *
+ *
  *            - 1.0 initial release
  *            - 1.1 added support for +/- N syntax for begin
  *              and end year values. (Monte)
@@ -37,22 +25,33 @@ require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php');
  *              dropdown to include given date unless explicitly set (Monte)
  *            - 1.3.4 fix behaviour of 0000-00-00 00:00:00 dates to match that
  *              of 0000-00-00 dates (cybot, boots)
- *            - 2.0 complete rewrite for performance,  
+ *            - 2.0 complete rewrite for performance,
  *              added attributes month_names, *_id
- * 
- * - * @link http://www.smarty.net/manual/en/language.function.html.select.date.php {html_select_date} - * (Smarty online manual) + * + * @link http://www.smarty.net/manual/en/language.function.html.select.date.php {html_select_date} + * (Smarty online manual) * @version 2.0 - * @author Andrei Zmievski - * @author Monte Ohrt - * @author Rodney Rehm - * @param array $params parameters - * @param Smarty_Internal_Template $template template object - * @return string + * @author Andrei Zmievski + * @author Monte Ohrt + * @author Rodney Rehm + * + * @param array $params parameters + * + * @param \Smarty_Internal_Template $template + * + * @return string + * @throws \SmartyException */ -function smarty_function_html_select_date($params, $template) +function smarty_function_html_select_date($params, Smarty_Internal_Template $template) { + $template->_checkPlugins( + array( + array( + 'function' => 'smarty_function_escape_special_chars', + 'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php' + ) + ) + ); // generate timestamps used for month names only static $_month_timestamps = null; static $_current_year = null; @@ -60,23 +59,22 @@ function smarty_function_html_select_date($params, $template) $_current_year = date('Y'); $_month_timestamps = array(); for ($i = 1; $i <= 12; $i++) { - $_month_timestamps[$i] = mktime(0, 0, 0, $i, 1, 2000); + $_month_timestamps[ $i ] = mktime(0, 0, 0, $i, 1, 2000); } } - /* Default values. */ - $prefix = "Date_"; + $prefix = 'Date_'; $start_year = null; $end_year = null; $display_days = true; $display_months = true; $display_years = true; - $month_format = "%B"; + $month_format = '%B'; /* Write months as numbers by default GL */ - $month_value_format = "%m"; - $day_format = "%02d"; + $month_value_format = '%m'; + $day_format = '%02d'; /* Write day values using this format MB */ - $day_value_format = "%d"; + $day_value_format = '%d'; $year_as_text = false; /* Display years in reverse order? Ie. 2000,1999,.... */ $reverse_years = false; @@ -112,23 +110,28 @@ function smarty_function_html_select_date($params, $template) $day_id = null; $month_id = null; $year_id = null; - foreach ($params as $_key => $_value) { switch ($_key) { case 'time': if (!is_array($_value) && $_value !== null) { + $template->_checkPlugins( + array( + array( + 'function' => 'smarty_make_timestamp', + 'file' => SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php' + ) + ) + ); $time = smarty_make_timestamp($_value); } break; - case 'month_names': - if (is_array($_value) && count($_value) == 12) { + if (is_array($_value) && count($_value) === 12) { $$_key = $_value; } else { - trigger_error("html_select_date: month_names must be an array of 12 strings", E_USER_NOTICE); + trigger_error('html_select_date: month_names must be an array of 12 strings', E_USER_NOTICE); } break; - case 'prefix': case 'field_array': case 'start_year': @@ -157,7 +160,6 @@ function smarty_function_html_select_date($params, $template) case 'year_id': $$_key = (string)$_value; break; - case 'display_days': case 'display_months': case 'display_years': @@ -165,38 +167,41 @@ function smarty_function_html_select_date($params, $template) case 'reverse_years': $$_key = (bool)$_value; break; - default: if (!is_array($_value)) { $extra_attrs .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_value) . '"'; } else { - trigger_error("html_select_date: extra attribute '$_key' cannot be an array", E_USER_NOTICE); - } + trigger_error("html_select_date: extra attribute '{$_key}' cannot be an array", E_USER_NOTICE); + } break; - } + } } - // Note: date() is faster than strftime() // Note: explode(date()) is faster than date() date() date() - if (isset($params['time']) && is_array($params['time'])) { - if (isset($params['time'][$prefix . 'Year'])) { + if (isset($params[ 'time' ]) && is_array($params[ 'time' ])) { + if (isset($params[ 'time' ][ $prefix . 'Year' ])) { // $_REQUEST[$field_array] given - foreach (array('Y' => 'Year', 'm' => 'Month', 'd' => 'Day') as $_elementKey => $_elementName) { + foreach (array( + 'Y' => 'Year', + 'm' => 'Month', + 'd' => 'Day' + ) as $_elementKey => $_elementName) { $_variableName = '_' . strtolower($_elementName); - $$_variableName = isset($params['time'][$prefix . $_elementName]) - ? $params['time'][$prefix . $_elementName] - : date($_elementKey); + $$_variableName = + isset($params[ 'time' ][ $prefix . $_elementName ]) ? $params[ 'time' ][ $prefix . $_elementName ] : + date($_elementKey); } - $time = mktime(0, 0, 0, $_month, $_day, $_year); - } elseif (isset($params['time'][$field_array][$prefix . 'Year'])) { + } elseif (isset($params[ 'time' ][ $field_array ][ $prefix . 'Year' ])) { // $_REQUEST given - foreach (array('Y' => 'Year', 'm' => 'Month', 'd' => 'Day') as $_elementKey => $_elementName) { + foreach (array( + 'Y' => 'Year', + 'm' => 'Month', + 'd' => 'Day' + ) as $_elementKey => $_elementName) { $_variableName = '_' . strtolower($_elementName); - $$_variableName = isset($params['time'][$field_array][$prefix . $_elementName]) - ? $params['time'][$field_array][$prefix . $_elementName] - : date($_elementKey); + $$_variableName = isset($params[ 'time' ][ $field_array ][ $prefix . $_elementName ]) ? + $params[ 'time' ][ $field_array ][ $prefix . $_elementName ] : date($_elementKey); } - $time = mktime(0, 0, 0, $_month, $_day, $_year); } else { // no date found, use NOW list($_year, $_month, $_day) = $time = explode('-', date('Y-m-d')); @@ -210,153 +215,146 @@ function smarty_function_html_select_date($params, $template) } else { list($_year, $_month, $_day) = $time = explode('-', date('Y-m-d', $time)); } - // make syntax "+N" or "-N" work with $start_year and $end_year // Note preg_match('!^(\+|\-)\s*(\d+)$!', $end_year, $match) is slower than trim+substr - foreach (array('start', 'end') as $key) { + foreach (array( + 'start', + 'end' + ) as $key) { $key .= '_year'; $t = $$key; if ($t === null) { $$key = (int)$_current_year; - } else if ($t[0] == '+') { - $$key = (int)($_current_year + trim(substr($t, 1))); - } else if ($t[0] == '-') { - $$key = (int)($_current_year - trim(substr($t, 1))); + } elseif ($t[ 0 ] === '+') { + $$key = (int)($_current_year + (int)trim(substr($t, 1))); + } elseif ($t[ 0 ] === '-') { + $$key = (int)($_current_year - (int)trim(substr($t, 1))); } else { $$key = (int)$$key; } } - // flip for ascending or descending if (($start_year > $end_year && !$reverse_years) || ($start_year < $end_year && $reverse_years)) { $t = $end_year; $end_year = $start_year; $start_year = $t; } - // generate year if ($display_years) { - $_html_years = ''; $_extra = ''; $_name = $field_array ? ($field_array . '[' . $prefix . 'Year]') : ($prefix . 'Year'); if ($all_extra) { $_extra .= ' ' . $all_extra; - } + } if ($year_extra) { $_extra .= ' ' . $year_extra; } - if ($year_as_text) { - $_html_years = ''; + $_html_years = + ''; } else { $_html_years = ''; } } - // generate month if ($display_months) { - $_html_month = ''; $_extra = ''; $_name = $field_array ? ($field_array . '[' . $prefix . 'Month]') : ($prefix . 'Month'); if ($all_extra) { $_extra .= ' ' . $all_extra; - } + } if ($month_extra) { $_extra .= ' ' . $month_extra; } - $_html_months = ''; } - // generate day if ($display_days) { - $_html_day = ''; $_extra = ''; $_name = $field_array ? ($field_array . '[' . $prefix . 'Day]') : ($prefix . 'Day'); if ($all_extra) { $_extra .= ' ' . $all_extra; - } + } if ($day_extra) { $_extra .= ' ' . $day_extra; } - $_html_days = ''; } - // order the fields for output $_html = ''; - for ($i=0; $i <= 2; $i++) { - switch ($field_order[$i]) { + for ($i = 0; $i <= 2; $i++) { + switch ($field_order[ $i ]) { case 'Y': case 'y': if (isset($_html_years)) { @@ -365,8 +363,7 @@ function smarty_function_html_select_date($params, $template) } $_html .= $_html_years; } - break; - + break; case 'm': case 'M': if (isset($_html_months)) { @@ -375,8 +372,7 @@ function smarty_function_html_select_date($params, $template) } $_html .= $_html_months; } - break; - + break; case 'd': case 'D': if (isset($_html_days)) { @@ -385,10 +381,8 @@ function smarty_function_html_select_date($params, $template) } $_html .= $_html_days; } - break; + break; } } return $_html; } - -?> \ No newline at end of file -- cgit v1.2.3