Skip to content

Commit 4e7d822

Browse files
committed
1.1.1
1 parent bcb1bbc commit 4e7d822

File tree

12 files changed

+109
-67
lines changed

12 files changed

+109
-67
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ env:
44
EXTNAME: lukewcs/togglectrl # Your extension vendor/package name
55
SNIFF: 1 # Run code sniffer on your code? 1 or 0
66
IMAGE_ICC: 1 # Run icc profile sniffer on your images? 1 or 0
7-
EPV: 1 # Run EPV (Extension Pre Validator) on your code? 1 or 0
7+
EPV: 0 # Run EPV (Extension Pre Validator) on your code? 1 or 0
88
EXECUTABLE_FILES: 1 # Run check for executable files? 1 or 0
99
PHPBB_BRANCH: 3.3.x # The phpBB branch to run tests on
1010

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ Extension for phpBB - Makes it possible to decide centrally for all extensions w
55

66
### Requirements
77
* phpBB 3.3.0 - 3.3.x
8-
* PHP 7.1.3 - 8.3.x
8+
* PHP 7.4.0 - 8.4.x

docs/version_check.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"stable": {
33
"3.3": {
4-
"current": "1.1.0",
4+
"current": "1.1.1",
55
"announcement": "https://github.com/LukeWCS/toggle-control/releases",
66
"eol": null,
77
"security": false

lukewcs/togglectrl/acp/acp_togglectrl_module.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class acp_togglectrl_module
1919
public $tpl_name;
2020
public $u_action;
2121

22-
public function main($id, $mode)
22+
public function main()
2323
{
2424
global $phpbb_container;
2525

lukewcs/togglectrl/adm/style/acp_togglectrl_settings.html

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<a id="maincontent"></a>
1818

1919
<h1>{{ lang('TOGGLECTRL_CONFIG_TITLE') }}</h1>
20-
<p>{{ lang('TOGGLECTRL_CONFIG_DESC', TOGGLECTRL_METADATA.EXT_NAME) }}</p>
20+
<p>{{ lang('TOGGLECTRL_CONFIG_DESC', TOGGLECTRL_METADATA.ext_name) }}</p>
2121

2222
{{ _self.notes(TOGGLECTRL_NOTES) }}
2323

@@ -77,7 +77,7 @@ <h1>{{ lang('TOGGLECTRL_CONFIG_TITLE') }}</h1>
7777
{% macro select(name, options, multiple = null, size = null) -%}
7878
<select name="{{ name }}{{ multiple ? '[]' }}"{{
7979
(size !== null ? ' size="' ~ size ~ '"') ~
80-
((multiple ?? false) ? ' multiple')
80+
(multiple ? ' multiple')
8181
}}>
8282
{% for opt in options %}
8383
<option value="{{ opt.value }}"{{
@@ -99,8 +99,11 @@ <h1>{{ lang('TOGGLECTRL_CONFIG_TITLE') }}</h1>
9999
{% endmacro %}
100100

101101
{% macro footer(metadata) %}
102-
<p class="{{ metadata.CLASS }}">
103-
{{ metadata.EXT_NAME }} {{ metadata.EXT_VER }} &copy; LukeWCS<br>
104-
{{ metadata.LANG_DESC|e('html') }} {{ metadata.LANG_VER|e('html') }} &bull; {{ metadata.LANG_AUTHOR|e('html') }}
102+
<p class="{{ metadata.class }}">
103+
{{ metadata.ext_name }} {{ metadata.ext_ver }} &copy; {{ metadata.ext_copyright }}
104+
{% if metadata.lang_ver is defined %}
105+
<br>
106+
{{ metadata.lang_desc|e('html') }} {{ metadata.lang_ver|e('html') }} &bull; {{ metadata.lang_author|e('html') }}
107+
{% endif %}
105108
</p>
106109
{% endmacro %}

lukewcs/togglectrl/adm/style/acp_togglectrl_settings.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*/
1212

13-
(function ($) { // IIFE start
13+
(function ($) {
1414

1515
'use strict';
1616

@@ -49,4 +49,4 @@ $(window).ready(function () {
4949
$('[name="togglectrl_enabled"]') .on('change' , setState);
5050
});
5151

52-
})(jQuery); // IIFE end
52+
})(jQuery);

lukewcs/togglectrl/composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"type": "phpbb-extension",
44
"description": "Makes it possible to decide centrally for all extensions which visual style should be used for yes/no switches, provided extensions support Toggle Control.",
55
"homepage": "https://github.com/LukeWCS/toggle-control",
6-
"version": "1.1.0",
7-
"time": "2024-03-31",
6+
"version": "1.1.1",
7+
"time": "2024-12-15",
88
"license": "GPL-2.0-only",
99
"authors": [
1010
{
@@ -14,7 +14,7 @@
1414
}
1515
],
1616
"require": {
17-
"php": ">=7.1.3,<8.4.0@dev",
17+
"php": ">=7.4.0,<8.5.0@dev",
1818
"composer/installers": "~1.0.0"
1919
},
2020
"extra": {

lukewcs/togglectrl/controller/acp_togglectrl_controller.php

Lines changed: 61 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515

1616
class acp_togglectrl_controller
1717
{
18-
protected $language;
19-
protected $template;
20-
protected $request;
21-
protected $config;
22-
protected $ext_manager;
23-
protected $metadata;
18+
protected object $language;
19+
protected object $template;
20+
protected object $request;
21+
protected object $config;
22+
protected object $ext_manager;
2423

25-
public $u_action;
24+
protected array $metadata;
25+
public string $u_action;
2626

2727
public function __construct(
2828
\phpbb\language\language $language,
@@ -46,7 +46,7 @@ public function module_settings(): void
4646
$notes = [];
4747

4848
$this->language->add_lang(['acp_togglectrl', 'acp_togglectrl_lang_author'], 'lukewcs/togglectrl');
49-
$this->set_meta_template_vars('TOGGLECTRL');
49+
$this->set_meta_template_vars('TOGGLECTRL', 'LukeWCS');
5050

5151
if ($this->request->is_set_post('submit'))
5252
{
@@ -67,20 +67,19 @@ public function module_settings(): void
6767
$notes[] = $lang_outdated_msg;
6868
}
6969

70-
$this->template->assign_vars([
70+
$template_vars = [
7171
'TOGGLECTRL_NOTES' => $notes,
72-
'TOGGLECTRL_ENABLED' => $this->config['togglectrl_enabled'],
73-
'TOGGLECTRL_TYPES' => $this->select_struct($this->config['togglectrl_type'], [
74-
['TOGGLECTRL_TYPE_TOGGLE' , 'toggle'],
75-
['TOGGLECTRL_TYPE_CHECKBOX' , 'checkbox'],
76-
['TOGGLECTRL_TYPE_RADIO' , 'radio'],
72+
'TOGGLECTRL_ENABLED' => (bool) $this->config['togglectrl_enabled'],
73+
'TOGGLECTRL_TYPES' => $this->select_struct((string) $this->config['togglectrl_type'], [
74+
'TOGGLECTRL_TYPE_TOGGLE' => 'toggle',
75+
'TOGGLECTRL_TYPE_CHECKBOX' => 'checkbox',
76+
'TOGGLECTRL_TYPE_RADIO' => 'radio',
7777
]),
78-
]);
79-
80-
if (!$this->config['togglectrl_enabled'])
81-
{
82-
$this->template->assign_var('TOGGLECTRL_TYPE', $this->config['togglectrl_type']);
83-
}
78+
];
79+
$template_vars += !$this->config['togglectrl_enabled'] ? [
80+
'TOGGLECTRL_TYPE' => (string) $this->config['togglectrl_type'],
81+
] : [];
82+
$this->template->assign_vars($template_vars);
8483

8584
add_form_key('togglectrl');
8685
}
@@ -90,43 +89,60 @@ public function set_page_url(string $u_action): void
9089
$this->u_action = $u_action;
9190
}
9291

93-
private function select_struct($value, array $options_params): array
92+
private function select_struct($cfg_value, array $options): array
9493
{
95-
$is_array_value = is_array($value);
96-
$options = [];
97-
foreach ($options_params as $params)
94+
$options_tpl = [];
95+
96+
foreach ($options as $opt_key => $opt_value)
9897
{
99-
$options[] = [
100-
'label' => $params[0],
101-
'value' => $params[1],
102-
'selected' => $is_array_value ? in_array($params[1], $value) : $params[1] == $value,
103-
'bold' => $params[2] ?? false,
98+
if (!is_array($opt_value))
99+
{
100+
$opt_value = [$opt_value];
101+
}
102+
$options_tpl[] = [
103+
'label' => $opt_key,
104+
'value' => $opt_value[0],
105+
'bold' => $opt_value[1] ?? false,
106+
'selected' => is_array($cfg_value) ? in_array($opt_value[0], $cfg_value) : $opt_value[0] == $cfg_value,
104107
];
105108
}
106109

107-
return $options;
110+
return $options_tpl;
111+
}
112+
113+
private function set_meta_template_vars(string $tpl_prefix, string $copyright): void
114+
{
115+
$template_vars = [
116+
'ext_name' => $this->metadata['extra']['display-name'],
117+
'ext_ver' => $this->language->lang($tpl_prefix . '_VERSION_STRING', $this->metadata['version']),
118+
'ext_copyright' => $copyright,
119+
'class' => strtolower($tpl_prefix) . '_footer',
120+
];
121+
$template_vars += $this->language->is_set($tpl_prefix . '_LANG_VER') ? [
122+
'lang_desc' => $this->language->lang($tpl_prefix . '_LANG_DESC'),
123+
'lang_ver' => $this->language->lang($tpl_prefix . '_VERSION_STRING', $this->language->lang($tpl_prefix . '_LANG_VER')),
124+
'lang_author' => $this->language->lang($tpl_prefix . '_LANG_AUTHOR'),
125+
] : [];
126+
127+
$this->template->assign_vars([$tpl_prefix . '_METADATA' => $template_vars]);
108128
}
109129

110-
private function set_meta_template_vars(string $tpl_prefix): void
130+
/*
131+
Determine the version of the language pack with fallback to 0.0.0
132+
*/
133+
private function get_lang_ver(string $lang_ext_ver): string
111134
{
112-
$this->template->assign_vars([
113-
$tpl_prefix . '_METADATA' => [
114-
'EXT_NAME' => $this->metadata['extra']['display-name'],
115-
'EXT_VER' => $this->language->lang($tpl_prefix . '_VERSION_STRING', $this->metadata['version']),
116-
'LANG_DESC' => $this->language->lang($tpl_prefix . '_LANG_DESC'),
117-
'LANG_VER' => $this->language->lang($tpl_prefix . '_VERSION_STRING', $this->language->lang($tpl_prefix . '_LANG_VER')),
118-
'LANG_AUTHOR' => $this->language->lang($tpl_prefix . '_LANG_AUTHOR'),
119-
'CLASS' => strtolower($tpl_prefix) . '_footer',
120-
],
121-
]);
135+
preg_match('/^([0-9]+\.[0-9]+\.[0-9]+.*)/', $this->language->lang($lang_ext_ver), $matches);
136+
return ($matches[1] ?? '0.0.0');
122137
}
123138

124-
// Check the language pack version for the minimum version and generate notice if outdated
139+
/*
140+
Check the language pack version for the minimum version and generate notice if outdated
141+
*/
125142
private function lang_ver_check_msg(string $lang_version_var, string $lang_outdated_var): string
126143
{
127144
$lang_outdated_msg = '';
128-
preg_match('/^([0-9]+\.[0-9]+\.[0-9]+)/', $this->language->lang($lang_version_var), $matches);
129-
$ext_lang_ver = $matches[1] ?? '0.0.0';
145+
$ext_lang_ver = $this->get_lang_ver($lang_version_var);
130146
$ext_lang_min_ver = $this->metadata['extra']['lang-min-ver'];
131147

132148
if (phpbb_version_compare($ext_lang_ver, $ext_lang_min_ver, '<'))
@@ -135,7 +151,7 @@ private function lang_ver_check_msg(string $lang_version_var, string $lang_outda
135151
{
136152
$lang_outdated_msg = $this->language->lang($lang_outdated_var);
137153
}
138-
else // Fallback if the current language package does not yet have the required variable.
154+
else /* Fallback if the current language package does not yet have the required variable. */
139155
{
140156
$lang_outdated_msg = 'Note: The language pack for the extension <strong>%1$s</strong> is no longer up-to-date. (installed: %2$s / needed: %3$s)';
141157
}

lukewcs/togglectrl/event/listener.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
class listener implements EventSubscriberInterface
1919
{
20-
protected $config;
21-
protected $template;
20+
protected object $config;
21+
protected object $template;
2222

2323
public function __construct(
2424
\phpbb\config\config $config,
@@ -29,7 +29,7 @@ public function __construct(
2929
$this->template = $template;
3030
}
3131

32-
public static function getSubscribedEvents()
32+
public static function getSubscribedEvents(): array
3333
{
3434
return [
3535
'core.adm_page_header' => 'generate_template_vars',
@@ -38,7 +38,7 @@ public static function getSubscribedEvents()
3838
];
3939
}
4040

41-
public function generate_template_vars()
41+
public function generate_template_vars(): void
4242
{
4343
if ($this->config['togglectrl_enabled'])
4444
{

lukewcs/togglectrl/ext.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class ext extends \phpbb\extension\base
1818
public function is_enableable()
1919
{
2020
$valid_phpbb = phpbb_version_compare(PHPBB_VERSION, '3.3.0', '>=') && phpbb_version_compare(PHPBB_VERSION, '3.4.0-dev', '<');
21-
$valid_php = phpbb_version_compare(PHP_VERSION, '7.1.3', '>=') && phpbb_version_compare(PHP_VERSION, '8.4.0-dev', '<');
21+
$valid_php = phpbb_version_compare(PHP_VERSION, '7.4.0', '>=') && phpbb_version_compare(PHP_VERSION, '8.5.0-dev', '<');
2222

2323
return $valid_phpbb && $valid_php;
2424
}

0 commit comments

Comments
 (0)