From 39a8a58f38d969d99420b56f9d09ebf2f06d4e83 Mon Sep 17 00:00:00 2001 From: billz Date: Thu, 7 Nov 2024 10:23:10 -0800 Subject: [PATCH] Fix handlePageAction for multiple plugin instances, move renderTemplate to plugins --- src/RaspAP/Plugins/PluginManager.php | 39 ++++------------------------ 1 file changed, 5 insertions(+), 34 deletions(-) diff --git a/src/RaspAP/Plugins/PluginManager.php b/src/RaspAP/Plugins/PluginManager.php index e2453932..65cb42b4 100644 --- a/src/RaspAP/Plugins/PluginManager.php +++ b/src/RaspAP/Plugins/PluginManager.php @@ -3,7 +3,7 @@ /** * Plugin Manager class * - * @description Architecture to support user plugins for RaspAP + * @description Class supporting user plugins to extend RaspAP * @author Bill Zimmerman * Special thanks to GitHub user @assachs * @license https://github.com/raspap/raspap-webgui/blob/master/LICENSE @@ -66,32 +66,6 @@ class PluginManager $this->plugins[] = $plugin; // store the plugin instance } - /** - * Renders a template from inside a plugin directory - * @param string $pluginName - * @param string $templateName - * @param array $__data - */ - public function renderTemplate(string $pluginName, string $templateName, array $__data = []): string - { - // Construct the file path for the template - $templateFile = "{$this->pluginPath}/{$pluginName}/templates/{$templateName}.php"; - - if (!file_exists($templateFile)) { - return "Template file {$templateFile} not found."; - } - - // Extract the data for use in the template - if (!empty($__data)) { - extract($__data); - } - - // Start output buffering to capture the template output - ob_start(); - include $templateFile; - return ob_get_clean(); // return the output - } - // Returns the sidebar public function getSidebar(): Sidebar { @@ -106,13 +80,10 @@ class PluginManager { foreach ($this->getInstalledPlugins() as $pluginClass) { $plugin = new $pluginClass($this->pluginPath, $pluginClass); - - if ($plugin instanceof PluginInterface) { - if ($plugin->handlePageAction($page, $this)) { - return true; - } else { - return false; - } + if ($plugin instanceof PluginInterface && $plugin->handlePageAction($page)) { + return true; + } else { + continue; } } }