summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJehan-Guillaume (ioguix) de Rorthais2012-08-17 18:49:28 +0000
committerJehan-Guillaume (ioguix) de Rorthais2012-08-22 10:39:41 +0000
commit0a3fdfecfb9c52654b351cc9f08c470149840ca5 (patch)
treeec64cd063e6344c8cf394bfbbca1954b962d9004
parentfd8eebfc005ab3b3346985da9939977cffc2f18a (diff)
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.
-rw-r--r--classes/Misc.php24
-rw-r--r--classes/Plugin.php21
-rw-r--r--classes/PluginManager.php7
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
@@ -33,6 +33,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