From 4c00f8ae0a7758110ee5f4ef19bf1f623efe585a Mon Sep 17 00:00:00 2001 From: Leonardo Sapiras Date: Tue, 6 Dec 2011 00:19:08 +0100 Subject: [PATCH] Add support for 'toplinks' hooks in the plugin architecture. By Leonardo Sapiras during the GSoC 2011, reviewed, patched, integrated and commited by ioguix. --- classes/Misc.php | 103 ++++++++++++++++++++++++++++++++------ classes/PluginManager.php | 2 +- 2 files changed, 88 insertions(+), 17 deletions(-) diff --git a/classes/Misc.php b/classes/Misc.php index 46e0b88d..96534c52 100644 --- a/classes/Misc.php +++ b/classes/Misc.php @@ -606,6 +606,37 @@ echo "\n"; } + /** + * Display a list of links + * @param $links An associative array of links to print + * links = array( + * 'attr' => array( // list of A tag attribute + * ... + * ), + * 'content' => The link text + * 'fields' => the data from which content and attr's values are obtained + * ); + * @param $class An optional class or list of classes seprated by a space + * WARNING: This field is NOT escaped! No user should be able to inject something here, use with care. + */ + function printLinksList($links, $class='') { + echo "\n"; + } + /** * Display navigation tabs * @param $tabs An associative array of tabs definitions, see printNav() for an example. @@ -1217,41 +1248,81 @@ } function printTopbar() { - global $lang, $conf, $appName, $appVersion, $appLangFiles; + global $lang, $conf, $plugin_manager, $appName, $appVersion, $appLangFiles; $server_info = $this->getServerInfo(); echo "
"; + echo ""; + + /* top right informations when connected */ - if (isset($_REQUEST['server'])) { $sql_url = "sqledit.php?{$this->href}&action="; - $sql_window_id = htmlspecialchars('sqledit:'.$_REQUEST['server']); + $sql_window_id = htmlentities('sqledit:'.$_REQUEST['server']); $history_url = "history.php?{$this->href}&action=pophistory"; - $history_window_id = htmlspecialchars('history:'.$_REQUEST['server']); - $logout_shared = isset($_SESSION['sharedUsername']) ? - ' onclick="return confirm(\''. $lang['strconfdropcred']. '\')"': - ''; + $history_window_id = htmlentities('history:'.$_REQUEST['server']); + $logout_shared = isset($_SESSION['sharedUsername']) ? "return confirm('{$lang['strconfdropcred']})" : ''; + + $toplinks = array ( + array ( + 'attr' => array ( + 'href' => "{$sql_url}&action=sql", + 'target' => "sqledit", + 'onclick' => "window.open('{$sql_url}&action=sql','{$sql_window_id}','toolbar=no,width=700,height=500,resizable=yes,scrollbars=yes').focus(); return false;" + ), + 'content' => noEscape(field('strsql')), + 'fields' => $lang + ), + array ( + 'attr' => array ( + 'href' => $history_url, + 'onclick' => "window.open('{$history_url}','{$history_window_id}','toolbar=no,width=800,height=600,resizable=yes,scrollbars=yes').focus(); return false;", + ), + 'content' => noEscape(field('strhistory')), + 'fields' => $lang + ), + array ( + 'attr' => array ( + 'href' => "{$sql_url}&action=find", + 'target' => "sqledit", + 'onclick' => "window.open('{$sql_url}&action=find','{$sql_window_id}','toolbar=no,width=700,height=500,resizable=yes,scrollbars=yes').focus(); return false;", + ), + 'content' => noEscape(field('strfind')), + 'fields' => $lang + ), + array( + 'attr' => array ( + 'href' => "servers.php?action=logout&logoutServer=".htmlentities($server_info['host']).":".htmlentities($server_info['port']).":".htmlentities($server_info['sslmode']), + 'onclick' => $logout_shared, + ), + 'content' => noEscape(field('strlogout')), + 'fields' => $lang + ) + ); + + // Toplink hook's place + $plugin_functions_parameters = array( + 'toplinks' => &$toplinks + ); + + $plugin_manager->do_hook('toplinks', $plugin_functions_parameters); echo ""; } + else { + echo "{$appName}{$appVersion}"; + } /* echo "
"; if ($server_info && isset($server_info['platform']) && isset($server_info['username'])) { + /* top left informations when connected */ echo sprintf($lang['strtopbar'], ''.htmlspecialchars($server_info['platform']).'', ''.htmlspecialchars((empty($server_info['host'])) ? 'localhost':$server_info['host']).'', ''.htmlspecialchars($server_info['port']).'', ''.htmlspecialchars($server_info['username']).''); - } else { - echo "$appName $appVersion"; - } - echo ""; - echo "\n"; + $this->printLinksList($toplinks, 'toplink'); echo " "; diff --git a/classes/PluginManager.php b/classes/PluginManager.php index c4279a02..5ef37faa 100644 --- a/classes/PluginManager.php +++ b/classes/PluginManager.php @@ -10,7 +10,7 @@ class PluginManager { * Attributes */ private $plugins_list = array(); - private $available_hooks = array(/* wip, will be added in next commits */); + private $available_hooks = array('toplinks' /* wip, more hooks to come in next commits */); private $actions = array(); private $hooks = array(); -- 2.39.5