1515
1616class acp_limitreplies_controller
1717{
18- protected $ language ;
19- protected $ template ;
20- protected $ config ;
21- protected $ request ;
22- protected $ ext_manager ;
18+ protected object $ language ;
19+ protected object $ template ;
20+ protected object $ config ;
21+ protected object $ request ;
22+ protected object $ ext_manager ;
2323
24- protected $ u_action ;
25-
26- private $ metadata ;
24+ protected string $ u_action ;
25+ private array $ metadata ;
2726
2827 public function __construct (
2928 \phpbb \language \language $ language ,
@@ -51,7 +50,10 @@ public function module_settings(): void
5150
5251 if ($ this ->request ->is_set_post ('submit ' ))
5352 {
54- $ this ->check_form_key_error ('lukewcs_limitreplies ' );
53+ if (!check_form_key ('lukewcs_limitreplies ' ))
54+ {
55+ trigger_error ($ this ->language ->lang ('FORM_INVALID ' ) . adm_back_link ($ this ->u_action ), E_USER_WARNING );
56+ }
5557
5658 $ this ->config ->set ('limitreplies_switch_enable ' , $ this ->request ->variable ('limitreplies_switch_enable ' , 0 ));
5759 $ this ->config ->set ('limitreplies_number_wait_time ' , $ this ->request ->variable ('limitreplies_number_wait_time ' , 60 ));
@@ -71,9 +73,9 @@ public function module_settings(): void
7173
7274 'LIMITREPLIES_SWITCH_ENABLE ' => (bool ) $ this ->config ['limitreplies_switch_enable ' ],
7375 'LIMITREPLIES_NUMBER_WAIT_TIME ' => (int ) $ this ->config ['limitreplies_number_wait_time ' ],
74- 'LIMITREPLIES_SELECT_HINT_MODE_OPTS ' => $ this ->select_struct ($ this ->config ['limitreplies_select_hint_mode ' ], [
75- [ 'LIMITREPLIES_HINT_MODE_ONCLICK ' , 1 ] ,
76- [ 'LIMITREPLIES_HINT_MODE_ALWAYS ' , 2 ] ,
76+ 'LIMITREPLIES_SELECT_HINT_MODE_OPTS ' => $ this ->select_struct (( int ) $ this ->config ['limitreplies_select_hint_mode ' ], [
77+ 'LIMITREPLIES_HINT_MODE_ONCLICK ' => 1 ,
78+ 'LIMITREPLIES_HINT_MODE_ALWAYS ' => 2 ,
7779 ]),
7880 ]);
7981
@@ -85,14 +87,6 @@ public function set_page_url($u_action): void
8587 $ this ->u_action = $ u_action ;
8688 }
8789
88- private function check_form_key_error (string $ key ): void
89- {
90- if (!check_form_key ($ key ))
91- {
92- trigger_error ($ this ->language ->lang ('FORM_INVALID ' ) . adm_back_link ($ this ->u_action ), E_USER_WARNING );
93- }
94- }
95-
9690 private function set_meta_template_vars (string $ tpl_prefix , string $ copyright ): void
9791 {
9892 $ template_vars = [
@@ -110,12 +104,22 @@ private function set_meta_template_vars(string $tpl_prefix, string $copyright):
110104 $ this ->template ->assign_vars ([$ tpl_prefix . '_METADATA ' => $ template_vars ]);
111105 }
112106
113- // Check the language pack version for the minimum version and generate notice if outdated
107+ /*
108+ Determine the version of the language pack with fallback to 0.0.0
109+ */
110+ private function get_lang_ver (string $ lang_ext_ver ): string
111+ {
112+ preg_match ('/^([0-9]+\.[0-9]+\.[0-9]+.*)/ ' , $ this ->language ->lang ($ lang_ext_ver ), $ matches );
113+ return ($ matches [1 ] ?? '0.0.0 ' );
114+ }
115+
116+ /*
117+ Check the language pack version for the minimum version and generate notice if outdated
118+ */
114119 private function lang_ver_check_msg (string $ lang_version_var , string $ lang_outdated_var ): string
115120 {
116121 $ lang_outdated_msg = '' ;
117- preg_match ('/^([0-9]+\.[0-9]+\.[0-9]+)/ ' , $ this ->language ->lang ($ lang_version_var ), $ matches );
118- $ ext_lang_ver = $ matches [1 ] ?? '0.0.0 ' ;
122+ $ ext_lang_ver = $ this ->get_lang_ver ($ lang_version_var );
119123 $ ext_lang_min_ver = $ this ->metadata ['extra ' ]['lang-min-ver ' ];
120124
121125 if (phpbb_version_compare ($ ext_lang_ver , $ ext_lang_min_ver , '< ' ))
@@ -124,8 +128,7 @@ private function lang_ver_check_msg(string $lang_version_var, string $lang_outda
124128 {
125129 $ lang_outdated_msg = $ this ->language ->lang ($ lang_outdated_var );
126130 }
127- // Fallback if the current language package does not yet have the required variable.
128- else
131+ else /* Fallback if the current language package does not yet have the required variable. */
129132 {
130133 $ 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) ' ;
131134 }
@@ -135,20 +138,24 @@ private function lang_ver_check_msg(string $lang_version_var, string $lang_outda
135138 return $ lang_outdated_msg ;
136139 }
137140
138- private function select_struct ($ value , array $ options_params ): array
141+ private function select_struct ($ cfg_value , array $ options ): array
139142 {
140- $ is_array_value = is_array ( $ value ) ;
141- $ options = [];
142- foreach ($ options_params as $ params )
143+ $ options_tpl = [] ;
144+
145+ foreach ($ options as $ opt_key => $ opt_value )
143146 {
144- $ options [] = [
145- 'label ' => $ params [0 ],
146- 'value ' => $ params [1 ],
147- 'bold ' => $ params [2 ] ?? false ,
148- 'selected ' => $ is_array_value ? in_array ($ params [1 ], $ value ) : $ params [1 ] == $ value ,
147+ if (!is_array ($ opt_value ))
148+ {
149+ $ opt_value = [$ opt_value ];
150+ }
151+ $ options_tpl [] = [
152+ 'label ' => $ opt_key ,
153+ 'value ' => $ opt_value [0 ],
154+ 'bold ' => $ opt_value [1 ] ?? false ,
155+ 'selected ' => is_array ($ cfg_value ) ? in_array ($ opt_value [0 ], $ cfg_value ) : $ opt_value [0 ] == $ cfg_value ,
149156 ];
150157 }
151158
152- return $ options ;
159+ return $ options_tpl ;
153160 }
154161}
0 commit comments