Allows plugin to set a return link in navlinks
authorJehan-Guillaume (ioguix) de Rorthais <ioguix@free.fr>
Fri, 17 Aug 2012 18:49:28 +0000 (20:49 +0200)
committerJehan-Guillaume (ioguix) de Rorthais <ioguix@free.fr>
Wed, 22 Aug 2012 10:39:41 +0000 (12:39 +0200)
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
classes/Plugin.php
classes/PluginManager.php

index af77676ec777dd9c4713b8f455f4df29b6dbf4bd..d26a45eb38d9edeb2fdc87fc3f69383e200a3099 100644 (file)
@@ -50,6 +50,8 @@
                }
 
                function getSubjectParams($subject) {
+                       global $plugin_manager;
+
                        $vars = array();
 
                        switch($subject) {
                                                        '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;
                        }
index 5806d3111269783461a6ab91b714ff42be773e8e..e3bea0469c7b060015e5244e1bc931f2d8356138 100644 (file)
@@ -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);
        }
index 1f01390fd9d7db2ed217f28c360d09db3de8741a..3bc1eb3996541b0717195980db6f24f4f1531541 100644 (file)
@@ -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