From 207d6bc69120aba1af2b51808f17e0059b571fed Mon Sep 17 00:00:00 2001 From: slawkens Date: Tue, 3 Jun 2025 08:52:33 +0200 Subject: [PATCH] feat: AutoLoad plugins init.php, by default disabled --- system/init.php | 6 ++++++ system/src/Plugins.php | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/system/init.php b/system/init.php index 44634265..821ac440 100644 --- a/system/init.php +++ b/system/init.php @@ -12,6 +12,7 @@ use DebugBar\StandardDebugBar; use MyAAC\Cache\Cache; use MyAAC\CsrfToken; use MyAAC\Hooks; +use MyAAC\Plugins; use MyAAC\Models\Town; use MyAAC\Settings; @@ -46,6 +47,11 @@ if(isset($config['gzip_output']) && $config['gzip_output'] && isset($_SERVER['HT global $cache; $cache = Cache::getInstance(); +// load plugins init.php +foreach (Plugins::getInits() as $init) { + require $init; +} + // event system global $hooks; $hooks = new Hooks(); diff --git a/system/src/Plugins.php b/system/src/Plugins.php index 438fe32e..85f0a2ba 100644 --- a/system/src/Plugins.php +++ b/system/src/Plugins.php @@ -11,6 +11,25 @@ class Plugins { private static $error = null; private static $plugin_json = []; + public static function getInits() + { + return Cache::remember('plugins_inits', 10 * 60, function () { + $inits = []; + foreach(self::getAllPluginsJson() as $plugin) { + if (!self::getAutoLoadOption($plugin, 'init', false)) { + continue; + } + + $pluginInits = glob(PLUGINS . $plugin['filename'] . '/init.php'); + foreach ($pluginInits as $path) { + $inits[] = $path; + } + } + + return $inits; + }); + } + public static function getAdminPages() { return Cache::remember('plugins_admin_pages', 10 * 60, function () {