66 * @package Plugin Loader
77 * @link https://github.com/dragomano/Plugin-Loader
88 * @author Bugo <bugo@dragomano.ru>
9- * @copyright 2023 Bugo
9+ * @copyright 2023-2024 Bugo
1010 * @license https://opensource.org/licenses/BSD-3-Clause The 3-Clause BSD License
1111 *
12- * @version 0.5
12+ * @version 0.6
1313 */
1414
1515namespace Bugo \PluginLoader ;
1616
1717use SimpleXMLElement ;
1818use ZipArchive ;
1919
20- if (!defined ('SMF ' ))
20+ if (! defined ('SMF ' ))
2121 die ('No direct access... ' );
2222
2323/**
2424 * Generated by Simple Mod Maker
2525 */
26- class Integration
26+ final class Integration
2727{
28- public function hooks (): void
29- {
30- add_integration_function ('integrate_update_settings_file ' , __CLASS__ . '::updateSettingsFile# ' , false , __FILE__ );
31- add_integration_function ('integrate_admin_areas ' , __CLASS__ . '::adminAreas# ' , false , __FILE__ );
32- }
28+ use HasInvoke;
3329
30+ #[Hook('integrate_update_settings_file ' , self ::class . '::updateSettingsFile# ' , __FILE__ )]
3431 public function updateSettingsFile (array &$ settings_defs ): void
3532 {
3633 $ settings_defs ['plugins ' ] = [
@@ -46,6 +43,7 @@ public function updateSettingsFile(array &$settings_defs): void
4643 ];
4744 }
4845
46+ #[Hook('integrate_admin_areas ' , self ::class . '::adminAreas# ' , __FILE__ )]
4947 public function adminAreas (array &$ admin_areas ): void
5048 {
5149 global $ txt ;
@@ -109,9 +107,7 @@ public function browseList(): void
109107 $ context ['sub_template ' ] = 'main ' ;
110108
111109 $ this ->handleSave ();
112-
113110 $ this ->handleToggle ();
114-
115111 $ this ->handleRemove ();
116112 }
117113
@@ -167,7 +163,7 @@ private function handleSave(): void
167163 {
168164 global $ context ;
169165
170- if (!isset ($ _REQUEST ['save ' ]) || empty ($ _REQUEST ['plugin_name ' ]))
166+ if (! isset ($ _REQUEST ['save ' ]) || empty ($ _REQUEST ['plugin_name ' ]))
171167 return ;
172168
173169 checkSession ();
@@ -194,21 +190,22 @@ private function handleToggle(): void
194190 {
195191 global $ context , $ sourcedir ;
196192
197- if (!isset ($ _REQUEST ['toggle ' ]))
193+ if (! isset ($ _REQUEST ['toggle ' ]))
198194 return ;
199195
200196 $ input = file_get_contents ('php://input ' );
201197 $ data = smf_json_decode ($ input , true ) ?? [];
202198
203- if (empty ($ data ) || empty ($ data ['status ' ]) || empty ($ data ['plugin ' ]))
199+ if (empty ($ data ) || empty ($ data ['status ' ]) || empty ($ data ['plugin ' ])) {
204200 redirectexit ('action=admin;area=plugins ' );
201+ }
205202
206203 if ($ data ['status ' ] === 'on ' ) {
207204 $ context ['pl_enabled_plugins ' ] = array_filter ($ context ['pl_enabled_plugins ' ], function ($ item ) use ($ data ) {
208205 return $ item !== $ data ['plugin ' ];
209206 });
210207 } else {
211- if (!empty ($ context ['pl_plugins ' ][$ data ['plugin ' ]]['database ' ])) {
208+ if (! empty ($ context ['pl_plugins ' ][$ data ['plugin ' ]]['database ' ])) {
212209 db_extend ('packages ' );
213210
214211 require PLUGINS_DIR . DIRECTORY_SEPARATOR . $ data ['plugin ' ] . DIRECTORY_SEPARATOR . $ context ['pl_plugins ' ][$ data ['plugin ' ]]['database ' ];
@@ -228,14 +225,15 @@ private function handleRemove(): void
228225 {
229226 global $ sourcedir ;
230227
231- if (!isset ($ _REQUEST ['remove ' ]))
228+ if (! isset ($ _REQUEST ['remove ' ]))
232229 return ;
233230
234231 $ input = file_get_contents ('php://input ' );
235232 $ data = smf_json_decode ($ input , true ) ?? [];
236233
237- if (empty ( $ data) || empty ($ data ['plugin ' ]))
234+ if ($ data === [] || empty ($ data ['plugin ' ])) {
238235 redirectexit ('action=admin;area=plugins ' );
236+ }
239237
240238 require_once $ sourcedir . '/Subs-Package.php ' ;
241239
@@ -246,41 +244,43 @@ private function prepareSettings(string $id): void
246244 {
247245 global $ context , $ txt ;
248246
249- if (!empty ($ context ['pl_plugins ' ][$ id ]['settings ' ])) {
250- $ settings = $ this ->getSettings (PLUGINS_DIR . DIRECTORY_SEPARATOR . $ id );
251- $ languages = $ this ->getLanguages ($ id );
247+ if (empty ($ context ['pl_plugins ' ][$ id ]['settings ' ]))
248+ return ;
249+
250+ $ settings = $ this ->getSettings (PLUGINS_DIR . DIRECTORY_SEPARATOR . $ id );
251+ $ languages = $ this ->getLanguages ($ id );
252252
253- $ options = [];
254- if (isset ($ context ['pl_plugins ' ][$ id ]['settings ' ]['setting ' ]['@attributes ' ])) {
255- $ option = $ context ['pl_plugins ' ][$ id ]['settings ' ]['setting ' ]['@attributes ' ];
253+ $ options = [];
254+ if (isset ($ context ['pl_plugins ' ][$ id ]['settings ' ]['setting ' ]['@attributes ' ])) {
255+ $ option = $ context ['pl_plugins ' ][$ id ]['settings ' ]['setting ' ]['@attributes ' ];
256+ $ options [$ option ['name ' ]] = [
257+ 'name ' => $ languages [$ option ['name ' ]] ?? $ txt ['not_applicable ' ],
258+ 'type ' => $ option ['type ' ],
259+ 'value ' => $ settings [$ option ['name ' ]] ?? $ option ['default ' ],
260+ ];
261+ } else {
262+ foreach ($ context ['pl_plugins ' ][$ id ]['settings ' ]['setting ' ] as $ setting ) {
263+ $ option = $ setting ['@attributes ' ];
256264 $ options [$ option ['name ' ]] = [
257265 'name ' => $ languages [$ option ['name ' ]] ?? $ txt ['not_applicable ' ],
258266 'type ' => $ option ['type ' ],
259267 'value ' => $ settings [$ option ['name ' ]] ?? $ option ['default ' ],
260268 ];
261- } else {
262- foreach ($ context ['pl_plugins ' ][$ id ]['settings ' ]['setting ' ] as $ setting ) {
263- $ option = $ setting ['@attributes ' ];
264- $ options [$ option ['name ' ]] = [
265- 'name ' => $ languages [$ option ['name ' ]] ?? $ txt ['not_applicable ' ],
266- 'type ' => $ option ['type ' ],
267- 'value ' => $ settings [$ option ['name ' ]] ?? $ option ['default ' ],
268- ];
269- }
270269 }
271-
272- $ context ['pl_plugins ' ][$ id ]['settings ' ] = $ options ;
273270 }
271+
272+ $ context ['pl_plugins ' ][$ id ]['settings ' ] = $ options ;
274273 }
275274
276275 private function getSettings (string $ path ): array
277276 {
278277 return is_file ($ path . '/settings.ini ' ) ? parse_ini_file ($ path . '/settings.ini ' ) : [];
279278 }
280279
281- private function saveSettings (string $ plugin , array $ settings ): void
280+ private function saveSettings (string $ plugin , array $ settings = [] ): void
282281 {
283- if (empty ($ settings )) return ;
282+ if ($ settings === [])
283+ return ;
284284
285285 $ iniString = '' ;
286286 foreach ($ settings as $ key => $ value ) {
@@ -356,7 +356,7 @@ private function extractPackage(): bool
356356 {
357357 global $ txt , $ context ;
358358
359- if (!isset ($ _REQUEST ['get ' ]))
359+ if (! isset ($ _REQUEST ['get ' ]))
360360 return false ;
361361
362362 $ package = $ _FILES ['package ' ];
0 commit comments