Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Review 4

-Move some code from plugin.php to Example's actions.
-Dropped unuseless comments.
-Replaced some comments.
-Fixed code in Misc->getNavTabs.
-Created a class to plugin's inherit from.
-Refactored Example's methods to use the parent class.
-Created a constant to have the ppa's class dir.
  • Loading branch information...
commit f702c9ee74ea05e1250b4402dee684554653c17d 1 parent aafea03
@leonardosapiras authored
View
94 classes/Misc.php
@@ -503,7 +503,7 @@ function getNavTabs($section) {
switch ($section) {
case 'root':
- return array (
+ $tabs = array (
'intro' => array (
'title' => $lang['strintroduction'],
'url' => "intro.php",
@@ -515,6 +515,7 @@ function getNavTabs($section) {
'icon' => 'Servers',
),
);
+ break;
case 'server':
case 'report':
@@ -683,7 +684,7 @@ function getNavTabs($section) {
'icon' => 'Export',
),
);
- return $tabs;
+ break;
case 'schema':
$tabs = array (
@@ -788,7 +789,7 @@ function getNavTabs($section) {
),
);
if (!$data->hasFTS()) unset($tabs['fulltext']);
- return $tabs;
+ break;
case 'table':
$tabs = array (
@@ -865,6 +866,7 @@ function getNavTabs($section) {
'hide' => false,
),
);
+ break;
case 'view':
$tabs = array (
@@ -904,6 +906,7 @@ function getNavTabs($section) {
'hide' => false,
),
);
+ break;
case 'function':
$tabs = array (
@@ -929,6 +932,7 @@ function getNavTabs($section) {
'icon' => 'Privileges',
),
);
+ break;
case 'aggregate':
$tabs = array (
@@ -944,9 +948,10 @@ function getNavTabs($section) {
'icon' => 'Definition',
),
);
+ break;
case 'role':
- return array (
+ $tabs = array (
'definition' => array (
'title' => $lang['strdefinition'],
'url' => 'roles.php',
@@ -958,6 +963,7 @@ function getNavTabs($section) {
'icon' => 'Definition',
),
);
+ break;
case 'popup':
$tabs = array (
@@ -975,6 +981,7 @@ function getNavTabs($section) {
'icon' => 'Search',
),
);
+ break;
case 'column':
$tabs = array(
@@ -1000,6 +1007,7 @@ function getNavTabs($section) {
'icon' => 'Privileges',
)
);
+ break;
case 'fulltext':
$tabs = array (
@@ -1031,15 +1039,15 @@ function getNavTabs($section) {
'icon' => 'FtsParser',
)
);
+ break;
}
- /* TABS HOOK'S PLACE */
+ // Tabs hook's place
$plugin_functions_parameters = array(
'tabs' => &$tabs,
'section' => $section
);
$plugin_manager->do_hook('tabs', $plugin_functions_parameters);
- /* * */
return $tabs;
}
@@ -1085,15 +1093,12 @@ function printTopbar() {
echo "<td style=\"text-align: right\">";
echo "<ul class=\"toplink\">\n";
foreach ($toplinks as $link) {
- $tag = "\t<li><a class=\"toplink\"";
- $tag.=" href=\"{$link['href']}\"";
-
- if (isset($link['target'])) $tag.=" target=\"{$link['target']}\"";
- if (isset($link['onclick'])) $tag.=" onclick=\"{$link['onclick']}\"";
-
+ $tag = "\t<li><a";
+ foreach ($link['attr'] as $attr => $value) {
+ $tag.= " ".$attr."=\"".htmlentities($value)."\"";
+ }
$tag.=">";
-
- if (isset($link['text'])) $tag.= $link['text'];
+ $tag.= htmlentities($link['content']);
$tag.="</a></li>\n";
echo $tag;
@@ -1129,43 +1134,50 @@ function getTopLinks() {
$server_info = $this->getServerInfo();
- $sql_url = "sqledit.php?{$this->href}&amp;action=";
+ $sql_url = "sqledit.php?{$this->href}&action=";
$sql_window_id = htmlspecialchars('sqledit:'.$_REQUEST['server']);
- $history_url = "history.php?{$this->href}&amp;action=pophistory";
+ $history_url = "history.php?{$this->href}&action=pophistory";
$history_window_id = htmlspecialchars('history:'.$_REQUEST['server']);
$logout_shared = isset($_SESSION['sharedUsername']) ? "return confirm('{$lang['strconfdropcred']})" : "";
- $toplinks = array(
- array(
- 'href' => "{$sql_url}sql",
- 'target' => "sqledit",
- 'onclick' => "window.open('{$sql_url}sql','{$sql_window_id}','toolbar=no,width=700,height=500,resizable=yes,scrollbars=yes').focus(); return false;",
- 'text' => $lang['strsql']
+ $toplinks = array (
+ array (
+ 'attr' => array (
+ 'href' => "{$sql_url}sql",
+ 'target' => "sqledit",
+ 'onclick' => "window.open('{$sql_url}sql','{$sql_window_id}','toolbar=no,width=700,height=500,resizable=yes,scrollbars=yes').focus(); return false;",
+ ),
+ 'content' => $lang['strsql']
),
- 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;",
- 'text' => $lang['strhistory']
+ 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' => $lang['strhistory']
),
- array(
- 'href' => "{$sql_url}find",
- 'target' => "sqledit",
- 'onclick' => "window.open('{$sql_url}find','{$sql_window_id}','toolbar=no,width=700,height=500,resizable=yes,scrollbars=yes').focus(); return false;",
- 'text' => $lang['strfind']
+ array (
+ 'attr' => array (
+ 'href' => "{$sql_url}find",
+ 'target' => "sqledit",
+ 'onclick' => "window.open('{$sql_url}find','{$sql_window_id}','toolbar=no,width=700,height=500,resizable=yes,scrollbars=yes').focus(); return false;",
+ ),
+ 'content' => $lang['strfind']
),
array(
- 'href' => "servers.php?action=logout&amp;logoutServer=".htmlspecialchars($server_info['host']).":".htmlspecialchars($server_info['port']).":".htmlspecialchars($server_info['sslmode']).$logout_shared,
- 'text' => $lang['strlogout'],
- 'onclick' => $logout_shared
+ 'attr' => array (
+ 'href' => "servers.php?action=logout&logoutServer=".htmlspecialchars($server_info['host']).":".htmlspecialchars($server_info['port']).":".htmlspecialchars($server_info['sslmode']).$logout_shared,
+ 'onclick' => $logout_shared,
+ ),
+ 'content' => $lang['strlogout']
)
);
- /* TOPLINK HOOK'S PLACE */
+ // Toplink hook's place
$plugin_functions_parameters = array(
'toplinks' => &$toplinks
);
$plugin_manager->do_hook('toplinks', $plugin_functions_parameters);
- /* * */
return $toplinks;
}
@@ -1375,12 +1387,13 @@ function getTrail($subject = null) {
}
}
- /* TRAIL HOOKS PLACE */
+ // Trail hook's place
$plugin_functions_parameters = array(
- 'trail' => &$trail
+ 'trail' => &$trail,
+ 'subject' => $subject
);
$plugin_manager->do_hook('trail', $plugin_functions_parameters);
- /* * */
+
return $trail;
}
@@ -1862,11 +1875,10 @@ function icon($icon) {
if (file_exists($path.'.png')) return $path.'.png';
if (file_exists($path.'.gif')) return $path.'.gif';
} else {
- /* ICON HOOK'S PLACE */
+ // Icon hook's place
$path = "plugins/{$icon['plugin']}/images/{$icon['image']}";
if (file_exists($path.'.png')) return $path.'.png';
if (file_exists($path.'.gif')) return $path.'.gif';
- /* * */
}
return '';
}
View
25 classes/Plugin.php
@@ -0,0 +1,25 @@
+<?php
+abstract class Plugin {
+
+ /**
+ * Constructor
+ * Register the plugin's functions in hooks of PPA.
+ * @param $language Current phpPgAdmin language.
+ * @param $plugin_directory Plugin's path.
+ */
+ function __construct($language, $plugin_directory) {
+ // Set the plugin's language
+ require_once("{$plugin_directory}/lang/recoded/english.php");
+ if (file_exists("{$plugin_directory}/lang/recoded/{$language}.php")) {
+ include_once("{$plugin_directory}/lang/recoded/{$language}.php");
+ }
+ $this->lang = $plugin_lang;
+ }
+
+ abstract function get_hooks();
+
+ abstract function get_actions();
+
+ abstract function get_name();
+}
+?>
View
9 classes/PluginManager.php
@@ -77,8 +77,8 @@ function add_plugin($plugin) {
function do_hook($hook, &$function_args) {
if (isset($this->hooks[$hook])) {
foreach ($this->hooks[$hook] as $plugin_name => $functions) {
+ $plugin = $this->plugins_list[$plugin_name];
foreach ($functions as $function) {
- $plugin = $this->plugins_list[$plugin_name];
if (method_exists($plugin, $function)) {
call_user_func(array($plugin, $function), $function_args);
}
@@ -95,13 +95,12 @@ function do_hook($hook, &$function_args) {
function do_action($plugin_name, $action) {
global $lang;
- if (isset($this->plugins_list[$plugin_name])) {
- $plugin = $this->plugins_list[$plugin_name];
- } else {
+ if (!isset($this->plugins_list[$plugin_name])) {
// Show an error and stop the application
printf($lang['strpluginnotfound']."\t\n", $name);
exit;
- }
+ }
+ $plugin = $this->plugins_list[$plugin_name];
// Check if the plugin's method exists and if this method is an declareted action.
// The actions are declared in the plugins' constructors.
View
3  libraries/lib.inc.php
@@ -22,6 +22,9 @@
$postgresqlMinVer = '7.4';
$phpMinVer = '5.0';
+ // Constants
+ define('PPA_CLASS_PATH', dirname(__FILE__).'/../classes');
+
// Check the version of PHP
if (version_compare(phpversion(), $phpMinVer, '<'))
exit(sprintf('Version of PHP not supported. Please upgrade to version %s or later.', $phpMinVer));
View
7 plugin.php
@@ -1,10 +1,5 @@
<?php
require_once('./libraries/lib.inc.php');
-//
-$misc->printHeader($lang['strdatabase']);
-$misc->printBody();
-$misc->printTrail($_REQUEST['subject']);
-//
+
$plugin_manager->do_action($_REQUEST['plugin'], $_REQUEST['action']);
-$misc->printFooter();
?>
View
58 plugins/Example/plugin.php
@@ -1,25 +1,22 @@
<?php
-class Example {
+require_once(PPA_CLASS_PATH.'/Plugin.php');
+
+class Example extends Plugin {
/**
* Attributes
*/
private $name = 'Example';
- private $lang;
+ protected $lang;
/**
* Constructor
- * Register the plugin's functions in hooks of PPA.
+ * Call parent constructor, passing the language that will be used.
* @param $language Current phpPgAdmin language. If it was not found in the plugin, English will be used.
*/
function __construct($language) {
- // Set the plugin's language
- $lang_directory = dirname(__FILE__)."/lang/recoded";
- require_once("$lang_directory/english.php");
- if (file_exists("$lang_directory/$language.php")) {
- include_once("$lang_directory/$language.php");
- }
- $this->lang = $plugin_lang;
+ $plugin_directory = dirname(__FILE__);
+ parent::__construct($language, $plugin_directory);
}
/**
@@ -82,13 +79,16 @@ function add_plugin_toplinks(&$plugin_functions_parameters) {
global $misc;
$href = "plugin.php?".$misc->href;
- $href.= "&amp;plugin=".urlencode($this->name);
- $href.= "&amp;subject=server";
- $href.= "&amp;action=show_page";
-
- $toplink = array(
- 'href' => $href,
- 'text' => $this->lang['strdescription']
+ $href.= "&plugin=".urlencode($this->name);
+ $href.= "&subject=server";
+ $href.= "&action=show_page";
+
+ $toplink = array (
+ 'attr' => array (
+ 'href' => $href,
+ 'class' => 'toplink'
+ ),
+ 'content' => $this->lang['strdescription']
);
//Add the link in the toplinks array
@@ -177,6 +177,10 @@ function add_plugin_trail(&$plugin_functions_parameters) {
function show_page() {
global $lang, $misc;
+ $misc->printHeader($lang['strdatabase']);
+ $misc->printBody();
+ $misc->printTrail($_REQUEST['subject']);
+
echo "<div>{$this->lang['strdescription']}</div>\n";
echo "<br/>\n";
@@ -196,6 +200,8 @@ function show_page() {
$back_link.= $lang['strback'];
$back_link.= "</a>\n";
echo $back_link;
+
+ $misc->printFooter();
}
/**
@@ -204,6 +210,10 @@ function show_page() {
function show_level_2() {
global $lang, $misc;
+ $misc->printHeader($lang['strdatabase']);
+ $misc->printBody();
+ $misc->printTrail($_REQUEST['subject']);
+
echo "<div>{$this->lang['strdesclevel2']}</div>\n";
echo "<br/>\n";
@@ -226,6 +236,8 @@ function show_level_2() {
$back_link.= $lang['strback'];
$back_link.= "</a>\n";
echo $back_link;
+
+ $misc->printFooter();
}
/**
@@ -234,6 +246,10 @@ function show_level_2() {
function show_level_3() {
global $lang, $misc;
+ $misc->printHeader($lang['strdatabase']);
+ $misc->printBody();
+ $misc->printTrail($_REQUEST['subject']);
+
echo "<div>{$this->lang['strdesclevel3']}</div>";
echo "<br/>\n";
@@ -256,6 +272,8 @@ function show_level_3() {
$back_link.= $lang['strback'];
$back_link.= "</a>\n";
echo $back_link;
+
+ $misc->printFooter();
}
/**
@@ -264,6 +282,10 @@ function show_level_3() {
function show_level_4() {
global $lang, $misc;
+ $misc->printHeader($lang['strdatabase']);
+ $misc->printBody();
+ $misc->printTrail($_REQUEST['subject']);
+
echo "<div>{$this->lang['strdesclevel4']}</div>\n";
echo "<br/>\n";
@@ -274,6 +296,8 @@ function show_level_4() {
$back_link.= $lang['strback'];
$back_link.= "</a>\n";
echo $back_link;
+
+ $misc->printFooter();
}
}
?>
Please sign in to comment.
Something went wrong with that request. Please try again.