From 511e10e78bb0980929dfce3a286344bae31e2e7b Mon Sep 17 00:00:00 2001 From: slawkens Date: Sat, 27 Jan 2024 00:56:45 +0100 Subject: [PATCH] Same for themes + commands --- ma | 3 ++- system/src/Plugins.php | 37 ++++++++++++++++++++++++++++++++----- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/ma b/ma index 1db3f56602..a412bc7526 100644 --- a/ma +++ b/ma @@ -11,6 +11,7 @@ if(!IS_CLI) { require_once SYSTEM . 'functions.php'; require_once SYSTEM . 'init.php'; +use MyAAC\Plugins; use Symfony\Component\Console\Application; $application = new Application(); @@ -26,7 +27,7 @@ foreach ($commandsGlob as $item) { $application->add(new ($commandPre . $name)); } -$pluginCommands = glob(PLUGINS . '*/commands/*.php'); +$pluginCommands = Plugins::getCommands(); foreach ($pluginCommands as $item) { $application->add(require $item); } diff --git a/system/src/Plugins.php b/system/src/Plugins.php index a310739d3c..842665c51e 100644 --- a/system/src/Plugins.php +++ b/system/src/Plugins.php @@ -122,12 +122,14 @@ public static function getThemes() } $themes = []; - $pluginThemes = glob(PLUGINS . '*/themes/*', GLOB_ONLYDIR); - foreach ($pluginThemes as $path) { - $path = str_replace(PLUGINS, 'plugins/', $path); - $name = pathinfo($path, PATHINFO_FILENAME); + foreach(self::getAllPluginsJson() as $plugin) { + $pluginThemes = glob(PLUGINS . $plugin['filename'] . '/themes/*', GLOB_ONLYDIR); + foreach ($pluginThemes as $path) { + $path = str_replace(PLUGINS, 'plugins/', $path); + $name = pathinfo($path, PATHINFO_FILENAME); - $themes[$name] = $path; + $themes[$name] = $path; + } } if ($cache->enabled()) { @@ -137,6 +139,31 @@ public static function getThemes() return $themes; } + public static function getCommands() + { + $cache = Cache::getInstance(); + if ($cache->enabled()) { + $tmp = ''; + if ($cache->fetch('plugins_commands', $tmp)) { + return unserialize($tmp); + } + } + + $commands = []; + foreach(self::getAllPluginsJson() as $plugin) { + $pluginCommands = glob(PLUGINS . $plugin['filename'] . '/commands/*.php'); + foreach ($pluginCommands as $path) { + $commands[] = $path; + } + } + + if ($cache->enabled()) { + $cache->set('plugins_commands', serialize($commands), 600); + } + + return $commands; + } + public static function getHooks() { $cache = Cache::getInstance();