Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 6 files changed
  • 0 commit comments
  • 1 contributor
Commits on May 23, 2011
@asleonardo Action's validation
-Created a way to validate plugins' and their actions.
-Add new parameter (actions) in the PluginManager's method add_plugin.
bc32a60
@asleonardo Cleanup and refactor code and comments
-Updated comments.
-Updated Example's back link to servers page.
-Fixed english mistake in the english translation.
fe24a2d
View
38 classes/PluginManager.php
@@ -41,9 +41,10 @@ function __construct($language) {
/**
* Add a plugin in the list of plugins to manage
* @param $plugin - Instance from plugin
- * @param $hooks - Array with functions and the places where they will hook.
+ * @param $hooks - Array with functions and the places where they will hook. The default value is an empty array.
+ * @param $actions - Array with functions that the plugin will use as actions. The default value is an empty array.
*/
- function add_plugin($plugin, $hooks) {
+ function add_plugin($plugin, $hooks = array(), $actions = array()) {
//The $name is the identification of the plugin.
//Example: PluginExample is the identification for PluginExample
//It will be used to get a specific plugin from the plugins_list.
@@ -52,18 +53,28 @@ function add_plugin($plugin, $hooks) {
//Register the plugin's functions
foreach ($hooks as $hook => $functions) {
- $this->functions_list[$hook][$plugin_name] = $functions;
+ $this->functions_list['hooks'][$hook][$plugin_name] = $functions;
}
+
+ //Register the plugin's actions
+ $this->functions_list['actions'][$plugin_name] = $actions;
}
/**
* Get a plugin from the $plugins_list by the plugin's identification.
* @param $name - the plugin's name as identification. Exemple: PluginExample.
- *
- * TODO: show an error when a given plugin doesn't exist
*/
function get_plugin($name) {
- return $this->plugins_list[$name];
+ global $lang;
+
+ if (isset($this->plugins_list[$name])) {
+ return $this->plugins_list[$name];
+ } else {
+ // Show an error and stop the application
+ printf($lang['strpluginnotfound']."\t\n", $name);
+ printf($lang['strpluginnotfoundcomplem']);
+ exit;
+ }
}
/**
@@ -74,8 +85,8 @@ function get_plugin($name) {
* TODO: check the supported entries (browser tree, tabs, trailer, navigation links, action buttons, top links)
*/
function execute_plugin_funtions($hook, &$function_args) {
- if (isset($this->functions_list[$hook])) {
- foreach ($this->functions_list[$hook] as $plugin_name => $functions) {
+ if (isset($this->functions_list['hooks'][$hook])) {
+ foreach ($this->functions_list['hooks'][$hook] as $plugin_name => $functions) {
foreach ($functions as $function) {
$plugin = $this->get_plugin($plugin_name);
if (method_exists($plugin, $function)) {
@@ -104,15 +115,20 @@ function get_transalation($name, $language) {
/**
* Execute a plugin's action
* @param $action - action that will be executed. The action is the name of a plugin's function.
- *
- * TODO: show erro when an action cannot be executed.
*/
function do_action($plugin_name, $action) {
+ global $lang;
$plugin = $this->get_plugin($plugin_name);
- if (method_exists($plugin, $action)) {
+ // Check if the plugin's method exists and if this method is an declareted action.
+ // The actions are declared in the plugins' constructors.
+ if (method_exists($plugin, $action) and in_array($action, $this->functions_list['actions'][$plugin_name])) {
call_user_func(array($plugin, $action));
+ } else {
+ // Show an error and stop the application
+ printf($lang['stractionnotfound']."\t\n", $action, $plugin_name);
+ exit;
}
}
}
View
3  lang/english.php
@@ -912,6 +912,7 @@
$lang['strftscantparsercopy'] = 'Can\'t specify both parser and template during text search configuration creation.';
//Plugins
- $lang['strpluginnotfound'] = 'Erro: plugin \'%s\' not found. Check if this plugin exists in the plugins/ directory, or if this plugins has a plugin.php file.';
+ $lang['strpluginnotfound'] = 'Error: plugin \'%s\' not found. Check if this plugin exists in the plugins/ directory, or if this plugins has a plugin.php file.';
$lang['strpluginnotfoundcomplem'] = 'Plugin\'s names are case sensitive';
+ $lang['stractionnotfound'] = 'Error: action \'%s\' not found in the \'%s\' plugin, or it was not specified as an action.';
?>
View
1  lang/portuguese-br.php
@@ -914,4 +914,5 @@
//Plugins
$lang['strpluginnotfound'] = 'Erro: plugin \'%s\' não encontrado. Verifique se esse plugin existe no diretório plugins/, ou se esse plugin contém um arquivo plugin.php';
$lang['strpluginnotfoundcomplem'] = 'Os nomes dos plugins são case sensitive';
+ $lang['stractionnotfound'] = 'Erro: ação \'%s\' não encontrada no plugin \'%s\'.';
?>
View
3  lang/recoded/english.php
@@ -912,6 +912,7 @@
$lang['strftscantparsercopy'] = 'Can\'t specify both parser and template during text search configuration creation.';
//Plugins
- $lang['strpluginnotfound'] = 'Erro: plugin \'%s\' not found. Check if this plugin exists in the plugins/ directory, or if this plugins has a plugin.php file.';
+ $lang['strpluginnotfound'] = 'Error: plugin \'%s\' not found. Check if this plugin exists in the plugins/ directory, or if this plugins has a plugin.php file.';
$lang['strpluginnotfoundcomplem'] = 'Plugin\'s names are case sensitive';
+ $lang['stractionnotfound'] = 'Error: action \'%s\' not found in the \'%s\' plugin, or it was not specified as an action.';
?>
View
1  lang/recoded/portuguese-br.php
@@ -914,4 +914,5 @@
//Plugins
$lang['strpluginnotfound'] = 'Erro: plugin \'%s\' não encontrado. Verifique se esse plugin existe no diretório plugins/, ou se esse plugin contém um arquivo plugin.php';
$lang['strpluginnotfoundcomplem'] = 'Os nomes dos plugins são case sensitive';
+ $lang['stractionnotfound'] = 'Erro: ação \'%s\' não encontrada no plugin \'%s\'.';
?>
View
30 plugins/Example/plugin.php
@@ -15,16 +15,16 @@ class Example {
*/
function __construct($plugin_manager, $language) {
$this->lang = $plugin_manager->get_transalation($this->name, $language);
- $plugin_manager->add_plugin($this, $this->get_hooks());
+ $plugin_manager->add_plugin($this, $this->get_hooks(), $this->get_actions());
}
/**
* This method returns the functions that will hook in the phpPgAdmin core.
- * To do include a function just put in the $functions array the follwing code:
+ * To do include a function just put in the $hooks array the follwing code:
* 'hook' => array('function1', 'function2').
*
* Example:
- * $functions = array(
+ * $hooks = array(
* 'toplinks' => array('add_plugin_toplinks'),
* 'tabs' => array('add_tab_entry'),
* 'action_buttons' => array('add_more_an_entry')
@@ -36,11 +36,28 @@ function get_hooks() {
$hooks = array(
'toplinks' => array('add_plugin_toplinks')
);
-
return $hooks;
}
/**
+ * This method returns the functions that will be used as actions.
+ * To do include a function that will be used as action, just put in the $actions array the follwing code:
+ *
+ * $actions = array(
+ * 'show_page',
+ * 'show_error',
+ * );
+ *
+ * @return $actions
+ */
+ function get_actions() {
+ $actions = array(
+ 'show_page'
+ );
+ return $actions;
+ }
+
+ /**
* Get the plugin name, that will be used as identification
* @return $plugin_name
*/
@@ -58,8 +75,6 @@ function add_plugin_toplinks(&$plugin_functions_parameters) {
$href = "plugin.php?".$plugin_functions_parameters['href'];
$href.= "&plugin=".urlencode($this->name);
$href.= "&action=show_page";
- //NOTE: What is the best way to return? $_SERVER['HTTP_REFERER'] cannot be trusted.
- $href.= "&return_url=".urlencode($_SERVER['PHP_SELF']."?".$misc->getHREF());
$link = "<a class=\"toplink\" href=\"$href\">";
$link.= $this->lang['strdescription'];
@@ -71,6 +86,7 @@ function add_plugin_toplinks(&$plugin_functions_parameters) {
/**
* Show a simple page
+ * This function will be used as an action
*
* TODO: make a style for this plugin, as an example of use of own css style.
*/
@@ -80,7 +96,7 @@ function show_page() {
echo "<div>{$this->lang['strdescription']}</div>";
echo "<br>";
- $url = "<a href=\"{$_REQUEST['return_url']}\">";
+ $url = "<a href=\"servers.php\">";
$url.= $lang['strback'];
$url.= "</a>";
echo $url;

No commit comments for this range

Something went wrong with that request. Please try again.