Add support for 'tabs' hooks in the plugin architecture.
authorLeonardo Sapiras <l.sapiras@gmail.com>
Tue, 6 Dec 2011 00:30:00 +0000 (01:30 +0100)
committerJehan-Guillaume (ioguix) de Rorthais <ioguix@free.fr>
Wed, 22 Aug 2012 10:23:50 +0000 (12:23 +0200)
By Leonardo Sapiras during the GSoC 2011, reviewed, patched,
integrated and commited by ioguix.

classes/Misc.php
classes/PluginManager.php

index 96534c527d19fd6b07f4e3b3b9bb3b39688a049b..4664dee197e830e99e213a974ba4f85c2c5be101 100644 (file)
 
                /**
                 * Display navigation tabs
-                * @param $tabs An associative array of tabs definitions, see printNav() for an example.
+                * @param $tabs The name of current section (Ex: intro, server, ...), or an array with tabs (Ex: sqledit.php doFind function)
                 * @param $activetab The name of the tab to be highlighted.
                 */
                function printTabs($tabs, $activetab) {
                 * @param $section The name of the tab bar.
                 */
                function getNavTabs($section) {
-                       global $data, $lang, $conf;
+                       global $data, $lang, $conf, $plugin_manager;
 
                        $hide_advanced = ($conf['show_advanced'] === false);
+                       $tabs = array();
 
                        switch ($section) {
                                case 'root':
-                                       return array (
+                                       $tabs = array (
                                                'intro' => array (
                                                        'title' => $lang['strintroduction'],
                                                        'url'   => "intro.php",
                                                        'icon'  => 'Servers',
                                                ),
                                        );
+                                       break;
 
                                case 'server':
                                case 'report':
                                        $hide_users = !$data->isSuperUser();
-                                       $tmp = array (
+                                       $tabs = array (
                                                'databases' => array (
                                                        'title' => $lang['strdatabases'],
                                                        'url'   => 'all_db.php',
                                                )
                                        );
                                        if ($data->hasRoles()) {
-                                               $tmp = array_merge($tmp, array(
+                                               $tabs = array_merge($tabs, array(
                                                        'roles' => array (
                                                                'title' => $lang['strroles'],
                                                                'url'   => 'roles.php',
                                                ));
                                        }
                                        else {
-                                               $tmp = array_merge($tmp, array(
+                                               $tabs = array_merge($tabs, array(
                                                        'users' => array (
                                                                'title' => $lang['strusers'],
                                                                'url'   => 'users.php',
                                                ));
                                        }
 
-                                       $tmp = array_merge($tmp, array(
+                                       $tabs = array_merge($tabs, array(
                                                'account' => array (
                                                        'title' => $lang['straccount'],
                                                        'url'   => $data->hasRoles() ? 'roles.php' : 'users.php',
                                                        'icon' => 'Reports',
                                                ),
                                        ));
-                                       return $tmp;
                                        break;
                                case 'database':
                                        $tabs = array (
                                                        'icon'  => 'Export',
                                                ),
                                        );
-                                       return $tabs;
+                                       break;
 
                                case 'schema':
                                        $tabs = array (
                                                ),
                                        );
                                        if (!$data->hasFTS()) unset($tabs['fulltext']);
-                                       return $tabs;
+                                       break;
 
                                case 'table':
-                                       return array (
+                                       $tabs = array (
                                                'columns' => array (
                                                        'title' => $lang['strcolumns'],
                                                        'url'   => 'tblproperties.php',
                                                        'hide'  => false,
                                                ),
                                        );
+                                       break;
 
                                case 'view':
-                                       return array (
+                                       $tabs = array (
                                                'columns' => array (
                                                        'title' => $lang['strcolumns'],
                                                        'url'   => 'viewproperties.php',
                                                        'hide'  => false,
                                                ),
                                        );
+                                       break;
 
                                case 'function':
-                                       return array (
+                                       $tabs = array (
                                                'definition' => array (
                                                        'title' => $lang['strdefinition'],
                                                        'url'   => 'functions.php',
                                                        'icon'  => 'Privileges',
                                                ),
                                        );
+                                       break;
 
                                case 'aggregate':
-                                       return array (
+                                       $tabs = array (
                                                'definition' => array (
                                                        'title' => $lang['strdefinition'],
                                                        'url'   => 'aggregates.php',
                                                        'icon'  => 'Definition',
                                                ),
                                        );
+                                       break;
 
                                case 'role':
-                                       return array (
+                                       $tabs = array (
                                                'definition' => array (
                                                        'title' => $lang['strdefinition'],
                                                        'url'   => 'roles.php',
                                                        'icon'  => 'Definition',
                                                ),
                                        );
+                                       break;
 
                                case 'popup':
-                                       return array (
+                                       $tabs = array (
                                                'sql' => array (
                                                        'title' => $lang['strsql'],
                                                        'url'   => 'sqledit.php',
                                                        'icon'  => 'Search',
                                                ),
                                        );
+                                       break;
 
                                case 'column':
-                                       return array(
+                                       $tabs = array(
                                                'properties' => array (
                                                        'title'         => $lang['strcolprop'],
                                                        'url'           => 'colproperties.php',
                                                        'icon'  => 'Privileges',
                                                )
                                        );
+                                       break;
 
                 case 'fulltext':
-                    return array (
+                    $tabs = array (
                         'ftsconfigs' => array (
                             'title' => $lang['strftstabconfigs'],
                             'url'   => 'fulltext.php',
                             'icon'  => 'FtsParser',
                         ),
                     );
-
-                               default:
-                                       return array();
+                    break;
                        }
+
+                       // Tabs hook's place
+                       $plugin_functions_parameters = array(
+                               'tabs' => &$tabs,
+                               'section' => $section
+                       );
+                       $plugin_manager->do_hook('tabs', $plugin_functions_parameters);
+
+                       return $tabs;
                }
 
                /**
                }
 
                function icon($icon) {
-                       global $conf;
-                       $path = "images/themes/{$conf['theme']}/{$icon}";
-                       if (file_exists($path.'.png')) return $path.'.png';
-                       if (file_exists($path.'.gif')) return $path.'.gif';
-                       $path = "images/themes/default/{$icon}";
-                       if (file_exists($path.'.png')) return $path.'.png';
-                       if (file_exists($path.'.gif')) return $path.'.gif';
+                       if (is_string($icon)) {
+                               global $conf;
+                               $path = "images/themes/{$conf['theme']}/{$icon}";
+                               if (file_exists($path.'.png')) return $path.'.png';
+                               if (file_exists($path.'.gif')) return $path.'.gif';
+                               $path = "images/themes/default/{$icon}";
+                               if (file_exists($path.'.png')) return $path.'.png';
+                               if (file_exists($path.'.gif')) return $path.'.gif';
+                       }
+                       else {
+                               // Icon from plugins
+                               $path = "plugins/{$icon[0]}/images/{$icon[1]}";
+                               if (file_exists($path.'.png')) return $path.'.png';
+                               if (file_exists($path.'.gif')) return $path.'.gif';
+                       }
                        return '';
                }
 
index 5ef37faa197e9fd76474545f1c32573a395bf513..ce26d21919d5344eeba60bd6ec8d359b0708f107 100644 (file)
@@ -10,7 +10,7 @@ class PluginManager {
         * Attributes
         */
        private $plugins_list = array();
-       private $available_hooks = array('toplinks' /* wip, more hooks to come in next commits */);
+       private $available_hooks = array('toplinks', 'tabs' /* wip, more hooks to come in next commits */);
        private $actions = array();
        private $hooks = array();