mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-07 20:08:53 +00:00
[ticket/17100] Move date format select HTML to HTML files
PHPBB3-17100
This commit is contained in:
parent
dda8766471
commit
9ee130fc59
4 changed files with 55 additions and 19 deletions
|
@ -1116,44 +1116,71 @@ class acp_board
|
|||
}
|
||||
|
||||
/**
|
||||
* Select default dateformat
|
||||
*/
|
||||
function dateformat_select($value, $key)
|
||||
* Create select for default date format
|
||||
*
|
||||
* @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
|
||||
$old_tz = $user->timezone;
|
||||
$old_tz = $this->user->timezone;
|
||||
try
|
||||
{
|
||||
$user->timezone = new DateTimeZone($config['board_timezone']);
|
||||
$this->user->timezone = new DateTimeZone($this->config['board_timezone']);
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
// 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"' : '') . '>';
|
||||
$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>';
|
||||
$dateformats = [];
|
||||
}
|
||||
|
||||
$dateformat_options .= '<option value="custom"';
|
||||
if (!isset($user->lang['dateformats'][$value]))
|
||||
foreach ($dateformats as $format => $null)
|
||||
{
|
||||
$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
|
||||
$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>
|
||||
<input type=\"text\" name=\"config[$key]\" id=\"$key\" value=\"$value\" maxlength=\"64\" />";
|
||||
return [
|
||||
[
|
||||
'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,
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -129,6 +129,7 @@ class forms extends AbstractExtension
|
|||
'CHECKED' => (bool) ($form_data['checked'] ?? false),
|
||||
'CLASS' => (string) ($form_data['class'] ?? ''),
|
||||
'VALUE' => (string) ($form_data['value']),
|
||||
'DATA' => $form_data['data'] ?? [],
|
||||
]);
|
||||
}
|
||||
catch (\Twig\Error\Error $e)
|
||||
|
@ -181,6 +182,8 @@ class forms extends AbstractExtension
|
|||
'TOGGLEABLE' => (bool) ($form_data['toggleable'] ?? false),
|
||||
'OPTIONS' => $form_data['options'] ?? [],
|
||||
'GROUP_ONLY' => (bool) ($form_data['group_only'] ?? false),
|
||||
'DATA' => $form_data['data'] ?? [],
|
||||
'SIZE' => (int) ($form_data['size'] ?? 0),
|
||||
]);
|
||||
}
|
||||
catch (\Twig\Error\Error $e)
|
||||
|
|
|
@ -11,5 +11,8 @@
|
|||
{% if TYPE == 'password' %}autocomplete="off" {% endif %}
|
||||
{% if CHECKED %}checked="checked" {% endif %}
|
||||
{% if CLASS %}class="{{ CLASS }}" {% endif %}
|
||||
{% for attribute, attribute_value in DATA %}
|
||||
data-{{ attribute|e }}="{{ attribute_value|e('html_attr') }}"
|
||||
{% endfor %}
|
||||
value="{{ VALUE }}">
|
||||
{% endapply %}
|
||||
|
|
|
@ -4,6 +4,9 @@
|
|||
{% if CLASS %}class="{{ CLASS }}" {% endif %}
|
||||
name="{{ NAME }}"
|
||||
{% 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 %}>
|
||||
{% endapply %}
|
||||
{% for element in OPTIONS %}
|
||||
|
|
Loading…
Add table
Reference in a new issue