From 0a3fdfecfb9c52654b351cc9f08c470149840ca5 Mon Sep 17 00:00:00 2001 From: "Jehan-Guillaume (ioguix) de Rorthais" Date: Fri, 17 Aug 2012 20:49:28 +0200 Subject: [PATCH] Allows plugin to set a return link in navlinks In some page (display, sql, ...), a "return" link will show up if $_GET['return'] = 'plugin' is given. The "get_subject_params" method of the plugin designated by $_GET['plugin'] is then called to add needed parameters in the href URL. --- classes/Misc.php | 24 ++++++++++++++---------- classes/Plugin.php | 21 +++++++++++++++++++++ classes/PluginManager.php | 7 +++++++ 3 files changed, 42 insertions(+), 10 deletions(-) diff --git a/classes/Misc.php b/classes/Misc.php index af77676e..d26a45eb 100644 --- a/classes/Misc.php +++ b/classes/Misc.php @@ -50,6 +50,8 @@ } function getSubjectParams($subject) { + global $plugin_manager; + $vars = array(); switch($subject) { @@ -171,16 +173,18 @@ 'column' => $_REQUEST['column'] )); break; - // case 'plugin': - // $vars = array('params' => array( - // 'server' => $_REQUEST['server'], - // 'subject' => 'plugin', - // 'plugin' => $_REQUEST['plugin'], - // 'database' => $_REQUEST['database'], - // 'schema' => $_REQUEST['schema'], - // 'action' => $_REQUEST['action'] - // )); - // break; + case 'plugin': + $vars = array( + 'url' => 'plugin.php', + 'params' => array( + 'server' => $_REQUEST['server'], + 'subject' => 'plugin', + 'plugin' => $_REQUEST['plugin'], + )); + + if (!is_null($plugin_manager->getPlugin($_REQUEST['plugin']))) + $vars['params'] = array_merge($vars['params'], $plugin_manager->getPlugin($_REQUEST['plugin'])->get_subject_params()); + break; default: return false; } diff --git a/classes/Plugin.php b/classes/Plugin.php index 5806d311..e3bea046 100644 --- a/classes/Plugin.php +++ b/classes/Plugin.php @@ -32,6 +32,21 @@ abstract class Plugin { abstract function get_actions(); + /** + * In some page (display, sql, ...), a "return" link will show up if + * $_GET['return'] = 'plugin' is given. The "get_subject_params" method + * of the plugin designated by $_GET['plugin'] is then called to add needed + * parameters in the href URL. + * This method can returns parameters based on context from $_REQUEST. See + * plugin Report as example. + * + * @returns an associative of parameter_name => value + */ + function get_subject_params() { + $vars = array(); + return $vars; + } + /** * Get the plugin name, that will be used as identification * @return $name @@ -40,6 +55,12 @@ abstract class Plugin { return $this->name; } + /** + * Returns the structure suitable for the method $misc->icon() to print + * the given icon. + * @param $img - The icon name + * @return the information suitable for the method $misc->icon() + */ function icon($img) { return array($this->name, $img); } diff --git a/classes/PluginManager.php b/classes/PluginManager.php index 1f01390f..3bc1eb39 100644 --- a/classes/PluginManager.php +++ b/classes/PluginManager.php @@ -74,6 +74,13 @@ class PluginManager { $this->actions[$plugin_name] = $actions; } + function getPlugin($plugin) { + if (isset($this->plugins_list[$plugin])) + return $this->plugins_list[$plugin]; + + return null; + } + /** * Execute the plugins hook functions when needed. * @param $hook - The place where the function will be called -- 2.39.5