[ticket/17100] Move date format select HTML to HTML files

PHPBB3-17100
This commit is contained in:
Marc Alexander 2023-04-10 10:53:58 +02:00
parent dda8766471
commit 9ee130fc59
No known key found for this signature in database
GPG key ID: 50E0D2423696F995
4 changed files with 55 additions and 19 deletions

View file

@ -1116,44 +1116,71 @@ class acp_board
} }
/** /**
* Select default dateformat * Create select for default date format
*/ *
function dateformat_select($value, $key) * @param string $value Current date format value
* @param string $key Date format key
*/
public function dateformat_select(string $value, string $key): array
{ {
global $user, $config;
// Let the format_date function operate with the acp values // Let the format_date function operate with the acp values
$old_tz = $user->timezone; $old_tz = $this->user->timezone;
try try
{ {
$user->timezone = new DateTimeZone($config['board_timezone']); $this->user->timezone = new DateTimeZone($this->config['board_timezone']);
} }
catch (\Exception $e) catch (\Exception $e)
{ {
// If the board timezone is invalid, we just use the users timezone. // If the board timezone is invalid, we just use the users timezone.
} }
$dateformat_options = ''; $dateformat_options = [];
foreach ($user->lang['dateformats'] as $format => $null) $dateformats = $this->language->lang_raw('dateformats');
if (!is_array($dateformats))
{ {
$dateformat_options .= '<option value="' . $format . '"' . (($format == $value) ? ' selected="selected"' : '') . '>'; $dateformats = [];
$dateformat_options .= $user->format_date(time(), $format, false) . ((strpos($format, '|') !== false) ? $user->lang['VARIANT_DATE_SEPARATOR'] . $user->format_date(time(), $format, true) : '');
$dateformat_options .= '</option>';
} }
$dateformat_options .= '<option value="custom"'; foreach ($dateformats as $format => $null)
if (!isset($user->lang['dateformats'][$value]))
{ {
$dateformat_options .= ' selected="selected"'; $dateformat_options[] = [
'value' => $format,
'selected' => $format == $value,
'label' => $this->user->format_date(time(), $format, false) . ((strpos($format, '|') !== false) ? $this->language->lang('VARIANT_DATE_SEPARATOR') . $this->user->format_date(time(), $format, true) : '')
];
} }
$dateformat_options .= '>' . $user->lang['CUSTOM_DATEFORMAT'] . '</option>';
// Add custom entry
$dateformat_options[] = [
'value' => 'custom',
'selected' => !isset($dateformats[$value]),
'label' => $this->language->lang('CUSTOM_DATEFORMAT'),
];
// Reset users date options // Reset users date options
$user->timezone = $old_tz; $this->user->timezone = $old_tz;
return "<select name=\"dateoptions\" id=\"dateoptions\" onchange=\"if (this.value == 'custom') { document.getElementById('" . addslashes($key) . "').value = '" . addslashes($value) . "'; } else { document.getElementById('" . addslashes($key) . "').value = this.value; }\">$dateformat_options</select> return [
<input type=\"text\" name=\"config[$key]\" id=\"$key\" value=\"$value\" maxlength=\"64\" />"; [
'tag' => 'select',
'name' => 'dateoptions',
'id' => 'dateoptions',
'options' => $dateformat_options,
'data' => [
'dateoption' => $key,
'dateoption-default' => $value,
]
],
[
'tag' => 'input',
'type' => 'text',
'name' => "config[$key]",
'id' => $key,
'value' => $value,
'maxlength' => 64,
]
];
} }
/** /**

View file

@ -129,6 +129,7 @@ class forms extends AbstractExtension
'CHECKED' => (bool) ($form_data['checked'] ?? false), 'CHECKED' => (bool) ($form_data['checked'] ?? false),
'CLASS' => (string) ($form_data['class'] ?? ''), 'CLASS' => (string) ($form_data['class'] ?? ''),
'VALUE' => (string) ($form_data['value']), 'VALUE' => (string) ($form_data['value']),
'DATA' => $form_data['data'] ?? [],
]); ]);
} }
catch (\Twig\Error\Error $e) catch (\Twig\Error\Error $e)
@ -181,6 +182,8 @@ class forms extends AbstractExtension
'TOGGLEABLE' => (bool) ($form_data['toggleable'] ?? false), 'TOGGLEABLE' => (bool) ($form_data['toggleable'] ?? false),
'OPTIONS' => $form_data['options'] ?? [], 'OPTIONS' => $form_data['options'] ?? [],
'GROUP_ONLY' => (bool) ($form_data['group_only'] ?? false), 'GROUP_ONLY' => (bool) ($form_data['group_only'] ?? false),
'DATA' => $form_data['data'] ?? [],
'SIZE' => (int) ($form_data['size'] ?? 0),
]); ]);
} }
catch (\Twig\Error\Error $e) catch (\Twig\Error\Error $e)

View file

@ -11,5 +11,8 @@
{% if TYPE == 'password' %}autocomplete="off" {% endif %} {% if TYPE == 'password' %}autocomplete="off" {% endif %}
{% if CHECKED %}checked="checked" {% endif %} {% if CHECKED %}checked="checked" {% endif %}
{% if CLASS %}class="{{ CLASS }}" {% endif %} {% if CLASS %}class="{{ CLASS }}" {% endif %}
{% for attribute, attribute_value in DATA %}
data-{{ attribute|e }}="{{ attribute_value|e('html_attr') }}"
{% endfor %}
value="{{ VALUE }}"> value="{{ VALUE }}">
{% endapply %} {% endapply %}

View file

@ -4,6 +4,9 @@
{% if CLASS %}class="{{ CLASS }}" {% endif %} {% if CLASS %}class="{{ CLASS }}" {% endif %}
name="{{ NAME }}" name="{{ NAME }}"
{% if TOGGLEABLE %}data-togglable-settings="true" {% endif %} {% if TOGGLEABLE %}data-togglable-settings="true" {% endif %}
{% for attribute, attribute_value in DATA %}
data-{{ attribute|e }}="{{ attribute_value|e('html_attr') }}"
{% endfor %}
{% if SIZE %}size="{{ SIZE }}" {% endif %}> {% if SIZE %}size="{{ SIZE }}" {% endif %}>
{% endapply %} {% endapply %}
{% for element in OPTIONS %} {% for element in OPTIONS %}