From 36b3e5000604089315f9a739d5558c7469006083 Mon Sep 17 00:00:00 2001 From: azett Date: Sun, 9 Oct 2022 14:18:34 +0200 Subject: [PATCH] fixed Smarty code: Replaced strftime() with strftime_replacement(); original Smarty file kept --- .../plugins/function.html_select_date.php | 6 +- .../function.html_select_date_ORIG_v4.2.1.php | 395 ++++++++++++++++++ 2 files changed, 399 insertions(+), 2 deletions(-) create mode 100644 fp-includes/smarty-4.2.1/libs/plugins/function.html_select_date_ORIG_v4.2.1.php diff --git a/fp-includes/smarty-4.2.1/libs/plugins/function.html_select_date.php b/fp-includes/smarty-4.2.1/libs/plugins/function.html_select_date.php index a396046..f9e6e2b 100644 --- a/fp-includes/smarty-4.2.1/libs/plugins/function.html_select_date.php +++ b/fp-includes/smarty-4.2.1/libs/plugins/function.html_select_date.php @@ -315,9 +315,11 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem } for ($i = 1; $i <= 12; $i++) { $_val = sprintf('%02d', $i); + // FlatPress: replaces strftime() with strftime_replacement in order to be PHP 8.1 compatible $_text = isset($month_names) ? smarty_function_escape_special_chars($month_names[ $i ]) : - ($month_format === '%m' ? $_val : strftime($month_format, $_month_timestamps[ $i ])); - $_value = $month_value_format === '%m' ? $_val : strftime($month_value_format, $_month_timestamps[ $i ]); + ($month_format === '%m' ? $_val : strftime_replacement($month_format, $_month_timestamps[ $i ])); + $_value = $month_value_format === '%m' ? $_val : strftime_replacement($month_value_format, $_month_timestamps[ $i ]); + // /FlatPress $_html_months .= '' . $option_separator; } diff --git a/fp-includes/smarty-4.2.1/libs/plugins/function.html_select_date_ORIG_v4.2.1.php b/fp-includes/smarty-4.2.1/libs/plugins/function.html_select_date_ORIG_v4.2.1.php new file mode 100644 index 0000000..a396046 --- /dev/null +++ b/fp-includes/smarty-4.2.1/libs/plugins/function.html_select_date_ORIG_v4.2.1.php @@ -0,0 +1,395 @@ + + * @author Rodney Rehm + * + * @param array $params parameters + * + * @param \Smarty_Internal_Template $template + * + * @return string + * @throws \SmartyException + */ +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; + if ($_month_timestamps === null) { + $_current_year = date('Y'); + $_month_timestamps = array(); + for ($i = 1; $i <= 12; $i++) { + $_month_timestamps[ $i ] = mktime(0, 0, 0, $i, 1, 2000); + } + } + /* Default values. */ + $prefix = 'Date_'; + $start_year = null; + $end_year = null; + $display_days = true; + $display_months = true; + $display_years = true; + $month_format = '%B'; + /* Write months as numbers by default GL */ + $month_value_format = '%m'; + $day_format = '%02d'; + /* Write day values using this format MB */ + $day_value_format = '%d'; + $year_as_text = false; + /* Display years in reverse order? Ie. 2000,1999,.... */ + $reverse_years = false; + /* Should the select boxes be part of an array when returned from PHP? + e.g. setting it to "birthday", would create "birthday[Day]", + "birthday[Month]" & "birthday[Year]". Can be combined with prefix */ + $field_array = null; + /* tags. + If not set, uses default dropdown. */ + $day_size = null; + $month_size = null; + $year_size = null; + /* Unparsed attributes common to *ALL* the tags. + An example might be in the template: all_extra ='class ="foo"'. */ + $all_extra = null; + /* Separate attributes for the tags. */ + $day_extra = null; + $month_extra = null; + $year_extra = null; + /* Order in which to display the fields. + "D" -> day, "M" -> month, "Y" -> year. */ + $field_order = 'MDY'; + /* String printed between the different fields. */ + $field_separator = "\n"; + $option_separator = "\n"; + $time = null; + + // $all_empty = null; + // $day_empty = null; + // $month_empty = null; + // $year_empty = null; + $extra_attrs = ''; + $all_id = null; + $day_id = null; + $month_id = null; + $year_id = null; + foreach ($params as $_key => $_value) { + switch ($_key) { + case 'time': + $$_key = $_value; // we'll handle conversion below + break; + case 'month_names': + 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); + } + break; + case 'prefix': + case 'field_array': + case 'start_year': + case 'end_year': + case 'day_format': + case 'day_value_format': + case 'month_format': + case 'month_value_format': + case 'day_size': + case 'month_size': + case 'year_size': + case 'all_extra': + case 'day_extra': + case 'month_extra': + case 'year_extra': + case 'field_order': + case 'field_separator': + case 'option_separator': + case 'all_empty': + case 'month_empty': + case 'day_empty': + case 'year_empty': + case 'all_id': + case 'month_id': + case 'day_id': + case 'year_id': + $$_key = (string)$_value; + break; + case 'display_days': + case 'display_months': + case 'display_years': + case 'year_as_text': + 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); + } + break; + } + } + // Note: date() is faster than strftime() + // Note: explode(date()) is faster than date() date() date() + + if (isset($time) && is_array($time)) { + if (isset($time[$prefix . 'Year'])) { + // $_REQUEST[$field_array] given + foreach ([ + 'Y' => 'Year', + 'm' => 'Month', + 'd' => 'Day' + ] as $_elementKey => $_elementName) { + $_variableName = '_' . strtolower($_elementName); + $$_variableName = + isset($time[$prefix . $_elementName]) ? $time[$prefix . $_elementName] : + date($_elementKey); + } + } elseif (isset($time[$field_array][$prefix . 'Year'])) { + // $_REQUEST given + foreach ([ + 'Y' => 'Year', + 'm' => 'Month', + 'd' => 'Day' + ] as $_elementKey => $_elementName) { + $_variableName = '_' . strtolower($_elementName); + $$_variableName = isset($time[$field_array][$prefix . $_elementName]) ? + $time[$field_array][$prefix . $_elementName] : date($_elementKey); + } + } else { + // no date found, use NOW + [$_year, $_month, $_day] = explode('-', date('Y-m-d')); + } + } elseif (isset($time) && preg_match("/(\d*)-(\d*)-(\d*)/", $time, $matches)) { + $_year = $_month = $_day = null; + if ($matches[1] > '') $_year = (int) $matches[1]; + if ($matches[2] > '') $_month = (int) $matches[2]; + if ($matches[3] > '') $_day = (int) $matches[3]; + } elseif ($time === null) { + if (array_key_exists('time', $params)) { + $_year = $_month = $_day = null; + } else { + [$_year, $_month, $_day] = explode('-', date('Y-m-d')); + } + } else { + $template->_checkPlugins( + array( + array( + 'function' => 'smarty_make_timestamp', + 'file' => SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php' + ) + ) + ); + $time = smarty_make_timestamp($time); + [$_year, $_month, $_day] = 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) { + $key .= '_year'; + $t = $$key; + if ($t === null) { + $$key = (int)$_current_year; + } 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) { + $_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 = + ''; + } else { + $_html_years = ''; + } + } + // generate month + if ($display_months) { + $_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) { + $_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 ]) { + case 'Y': + case 'y': + if (isset($_html_years)) { + if ($_html) { + $_html .= $field_separator; + } + $_html .= $_html_years; + } + break; + case 'm': + case 'M': + if (isset($_html_months)) { + if ($_html) { + $_html .= $field_separator; + } + $_html .= $_html_months; + } + break; + case 'd': + case 'D': + if (isset($_html_days)) { + if ($_html) { + $_html .= $field_separator; + } + $_html .= $_html_days; + } + break; + } + } + return $_html; +}