Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

...
  • 6 commits
  • 20 files changed
  • 0 commit comments
  • 1 contributor
Commits on May 19, 2011
Leonardo Sapiras Refactored PluginManager and PluginExample
-Moved PluginManager.php from classes/plugins/ to classes/
-Removed classes/plugins
-Updated plugin comment in the conf/config.inc.php
-Removed prefix plugin_ from PluginExample attributes and inside PluginManager
-Renamed plugin_index to name
-Renamed plugin_name to description
-Renamed get_plugin_index to get_name
-Changed attributes from public to private
-Moved plugin's instanciation from lib.inc.php to PluginManager contructor
-Validation if the plugins in the $conf['plugins'] exist
-Created $lang['strpluginnotfound'] and $lang['strpluginnotfoundcomplem'] in English and Portuguese-BR translation, to show an error when a plugin doesn't exist.
-Created get_functions method to get the plugins' functions
-Removed add_plugin_functions method
-Replaced $when to $hook in the execute_plugin_funtions code and comments
-Changes in the execute_plugin_funtions method
fb4c200
Commits on May 20, 2011
Leonardo Sapiras Create a simple page
-Created do_action in the plugin_manager, to deal with plugins actions.
-Put some TODOs in the comments.
-Created a method show_page, that will show a simple PluginExamples page.
-Created plugin.php file to deal with plugins requests.
-Made some English corrections.
ca62603
Leonardo Sapiras Plugin refactor
-Changed plugin_name in the lang files to strdescription
-Removed $description
-Remored $plugin_lang['plugin_toplink'] from translation files
9b9b561
Leonardo Sapiras Moved PluginExample to Example
-Changed config.inc.php
-Moved plugins/PluginExample to Example
-Refatored Example
-Fixed a bug in the Example plugin
22824fa
Leonardo Sapiras Dropped plugins/lang/translations.php 8bc2b70
Leonardo Sapiras Small change in the plugin Example page. 725a760
7 classes/Misc.php
View
@@ -1088,7 +1088,12 @@ function printTopbar() {
$toplinks[] = "<a class=\"toplink\" href=\"{$history_url}\" onclick=\"window.open('{$history_url}','{$history_window_id}','toolbar=no,width=800,height=600,resizable=yes,scrollbars=yes').focus(); return false;\">{$lang['strhistory']}</a>";
$toplinks[] = "<a class=\"toplink\" 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;\">{$lang['strfind']}</a>";
/* TOPLINK HOOK'S PLACE */
- $plugin_manager->execute_plugin_funtions('toplinks', $toplinks);
+ $plugin_functions_parameters = array(
+ 'toplinks' => &$toplinks, //the array of toplinks is passed by reference.
+ 'href' => $this->href
+ );
+ /* * */
+ $plugin_manager->execute_plugin_funtions('toplinks', $plugin_functions_parameters);
$toplinks[] = "<a class=\"toplink\" href=\"servers.php?action=logout&amp;logoutServer=".htmlspecialchars($server_info['host']).":".htmlspecialchars($server_info['port']).":".htmlspecialchars($server_info['sslmode'])."\"{$logout_shared}>{$lang['strlogout']}</a>";
119 classes/PluginManager.php
View
@@ -0,0 +1,119 @@
+<?php
+
+/**
+ * A class that implements the plugin's system
+ */
+
+class PluginManager {
+
+ /**
+ * Attributes
+ */
+ private $plugins_list = array();
+ private $functions_list = array();
+
+ /**
+ * Register the plugins
+ * @param $language - Language that have been used.
+ */
+ function __construct($language) {
+ global $conf, $lang;
+
+ // Get the activated plugins
+ $plugins = $conf['plugins'];
+
+ foreach ($plugins as $activated_plugin) {
+ $plugin_file = './plugins/'.$activated_plugin.'/plugin.php';
+
+ // Verify is the activated plugin exists
+ if (file_exists($plugin_file)) {
+ include_once($plugin_file);
+ $plugin = new $activated_plugin($this, $language);
+ } else {
+ //TODO: create a HTML.
+ printf($lang['strpluginnotfound']."\t\n", $activated_plugin);
+ printf($lang['strpluginnotfoundcomplem']);
+ // TODO: exit??
+ }
+ }
+ }
+
+ /**
+ * 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.
+ */
+ function add_plugin($plugin, $hooks) {
+ //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.
+ $plugin_name = $plugin->get_name();
+ $this->plugins_list[$plugin_name] = $plugin;
+
+ //Register the plugin's functions
+ foreach ($hooks as $hook => $functions) {
+ $this->functions_list[$hook][$plugin_name] = $functions;
+ }
+ }
+
+ /**
+ * 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];
+ }
+
+ /**
+ * Execute the plugins functions according some moment.
+ * @param $hook - The place where the function will be called
+ * @param $function_args - The reference to arguments of the called function
+ *
+ * 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) {
+ foreach ($functions as $function) {
+ $plugin = $this->get_plugin($plugin_name);
+ if (method_exists($plugin, $function)) {
+ call_user_func_array(array($plugin, $function), array(&$function_args));
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Get the plugin translations
+ * @param $name - Plugin's name. Example: PluginExample, Crud, etc...
+ * @param $language - Current phpPgAdmin language. If it was not found in the plugin, English will be used.
+ *
+ * TODO: check if an english translation file exists. If not, to think a way to alert about it.
+ */
+ function get_transalation($name, $language) {
+ require_once("./plugins/{$name}/lang/recoded/english.php");
+ if (file_exists("./plugins/{$name}/lang/recoded/{$language}.php")) {
+ include_once("./plugins/{$name}/lang/recoded/{$language}.php");
+ }
+ return $plugin_lang;
+ }
+
+ /**
+ * 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) {
+
+ $plugin = $this->get_plugin($plugin_name);
+
+ if (method_exists($plugin, $action)) {
+ call_user_func(array($plugin, $action));
+ }
+ }
+}
+?>
83 classes/plugins/PluginManager.php
View
@@ -1,83 +0,0 @@
-<?php
-
-/**
- * A class that implements the plugin's system
- */
-
-class PluginManager {
-
- /**
- * Attributes
- */
- public $plugins_list = array();
- public $functions_list = array();
-
- /**
- * Add a plugin in the list of plugins to manage
- * @param $plugin - Instance from plugin
- */
- function add_plugin($plugin) {
- //The plugin index 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.
- $plugin_index = $plugin->get_plugin_index();
- $this->plugins_list[$plugin_index] = $plugin;
- }
-
- /**
- * Get a plugin from the $plugins_list by the plugin's identification.
- * @param $plugin_index - plugin identification. Exemple: PluginExample.
- */
- function get_plugin($plugin_index) {
- return $this->plugins_list[$plugin_index];
- }
-
- /**
- * Add a function in the $functions_list list, with the information when this function will be used by the
- * phppgadmin core.
- * @param $plugin_index - Index that identify the plugin. Example the plugin_example's index is plugin_example :-)
- * @param $when - This identify when the added function will be called
- * @param $function - The name of the function. It will be called by callback;
- */
- function add_plugin_functions($plugin_index, $when, $function) {
- $this->functions_list[$when][] = array('plugin_index' => $plugin_index, 'function' => $function);
- }
-
- /**
- * Execute the plugins functions according some moment.
- * @param $when - When the function will be called
- * @param $function_args - The reference to arguments of the called function
- *
- * TODO: check the supported entries (browser tree, tabs, trailer, navigation links, action buttons, top links)
- */
- function execute_plugin_funtions($when, &$function_args) {
- if (isset($this->functions_list[$when])) {
- foreach ($this->functions_list[$when] as $node) {
- $plugin_index = $node['plugin_index'];
- $function = $node['function'];
- $plugin = $this->get_plugin($plugin_index);
- //
- if (method_exists($plugin, $function)) {
- call_user_func_array(array($plugin, $function), array(&$function_args));
- }
- }
- }
- }
-
- /**
- * Get the plugin translations
- * @param $plugin_index - Name of the plugin index. Example: PluginExample, Crud, etc...
- * @param $language - Current phpPgAdmin language. If it was not found in the plugin, English will be used.
- *
- * TODO: check if an english translation file exists. If not, to think a way to alert about it.
- */
- function get_transalation($plugin_index, $language) {
- require_once("./plugins/{$plugin_index}/lang/recoded/english.php");
- require_once("./plugins/{$plugin_index}/lang/translations.php");
- if (isset($pluginLangFiles[$language])) {
- include_once("./plugins/{$plugin_index}/lang/recoded/{$language}.php");
- }
- return $plugin_lang;
- }
-}
-?>
7 conf/config.inc.php-dist
View
@@ -142,9 +142,10 @@
// Time in seconds. If set to 0, refreshing data using ajax will be disabled (locks and activity pages)
$conf['ajax_refresh'] = 3;
- // Plugins
- // Add index to plugins that will be activated.
- // Example: array('PluginExample', 'Slony', ...)
+ /** Plugins management
+ * Add plugin names to the following array to activate them
+ * Example: $conf['plugins'] = array('Example', 'Slony');
+ */
$conf['plugins'] = array();
/*****************************************
4 lang/english.php
View
@@ -910,4 +910,8 @@
$lang['strftstabdicts'] = 'Dictionaries';
$lang['strftstabparsers'] = 'Parsers';
$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['strpluginnotfoundcomplem'] = 'Plugin\'s names are case sensitive';
?>
4 lang/portuguese-br.php
View
@@ -910,4 +910,8 @@
$lang['strftstabdicts'] = 'Dicionários';
$lang['strftstabparsers'] = 'Parsers';
$lang['strftscantparsercopy'] = 'Não é possível especificar ambos parser e modelo durante a criação da configuração de busca de texto.';
+
+ //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';
?>
4 lang/recoded/english.php
View
@@ -910,4 +910,8 @@
$lang['strftstabdicts'] = 'Dictionaries';
$lang['strftstabparsers'] = 'Parsers';
$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['strpluginnotfoundcomplem'] = 'Plugin\'s names are case sensitive';
?>
4 lang/recoded/portuguese-br.php
View
@@ -910,4 +910,8 @@
$lang['strftstabdicts'] = 'Dicion&#225;rios';
$lang['strftstabparsers'] = 'Parsers';
$lang['strftscantparsercopy'] = 'N&#227;o &#233; poss&#237;vel especificar ambos parser e modelo durante a cria&#231;&#227;o da configura&#231;&#227;o de busca de texto.';
+
+ //Plugins
+ $lang['strpluginnotfound'] = 'Erro: plugin \'%s\' n&#227;o encontrado. Verifique se esse plugin existe no diret&#243;rio plugins/, ou se esse plugin cont&#233;m um arquivo plugin.php';
+ $lang['strpluginnotfoundcomplem'] = 'Os nomes dos plugins s&#227;o case sensitive';
?>
13 libraries/lib.inc.php
View
@@ -179,16 +179,9 @@
exit;
}
- // Check if there are activated plugins
- $plugins = $conf['plugins'];
- require_once('./classes/plugins/PluginManager.php');
- $plugin_manager = new PluginManager();
- //register the plugins and their functions
- foreach ($plugins as $activated_plugin) {
- include_once('./plugins/'.$activated_plugin.'/plugin.php');
- $plugin = new $activated_plugin($plugin_manager, $_language);
- $plugin_manager->add_plugin($plugin);
- }
+ // Manage the plugins
+ require_once('./classes/PluginManager.php');
+ $plugin_manager = new PluginManager($_language);
// Create data accessor object, if necessary
if (!isset($_no_db_connection)) {
10 plugin.php
View
@@ -0,0 +1,10 @@
+<?php
+require_once('./libraries/lib.inc.php');
+//
+$misc->printHeader($lang['strdatabase']);
+$misc->printBody();
+$misc->printTopbar();
+//
+$plugin_manager->do_action($_REQUEST['plugin'], $_REQUEST['action']);
+$misc->printFooter();
+?>
0  plugins/PluginExample/README.txt → plugins/Example/README.txt
View
File renamed without changes
0  plugins/PluginExample/lang/Makefile → plugins/Example/lang/Makefile
View
File renamed without changes
0  plugins/PluginExample/lang/convert.awk → plugins/Example/lang/convert.awk
View
File renamed without changes
7 plugins/PluginExample/lang/recoded/english.php → plugins/Example/lang/english.php
View
@@ -6,9 +6,6 @@
*/
//Plugin data
- $plugin_lang['plugin_name'] = 'Plugin Example';
+ $plugin_lang['strdescription'] = 'Plugin Example';
- //Test
- $plugin_lang['plugin_toplink'] = 'Example extra toplink';
-
-?>
+ ?>
5 plugins/PluginExample/lang/recoded/portuguese-br.php → plugins/Example/lang/portuguese-br.php
View
@@ -6,9 +6,6 @@
*/
//Plugin data
- $plugin_lang['plugin_name'] = 'Plugin Exemplo';
-
- //Test
- $plugin_lang['plugin_toplink'] = 'Exemplo de toplink extra';
+ $plugin_lang['strdescription'] = 'Plugin Exemplo';
?>
5 plugins/PluginExample/lang/english.php → plugins/Example/lang/recoded/english.php
View
@@ -6,9 +6,6 @@
*/
//Plugin data
- $plugin_lang['plugin_name'] = 'Plugin Example';
-
- //Test
- $plugin_lang['plugin_toplink'] = 'Example extra toplink';
+ $plugin_lang['strdescription'] = 'Plugin Example';
?>
5 plugins/PluginExample/lang/portuguese-br.php → plugins/Example/lang/recoded/portuguese-br.php
View
@@ -6,9 +6,6 @@
*/
//Plugin data
- $plugin_lang['plugin_name'] = 'Plugin Exemplo';
-
- //Test
- $plugin_lang['plugin_toplink'] = 'Exemplo de toplink extra';
+ $plugin_lang['strdescription'] = 'Plugin Exemplo';
?>
89 plugins/Example/plugin.php
View
@@ -0,0 +1,89 @@
+<?php
+class Example {
+
+ /**
+ * Attributes
+ */
+ private $name = 'Example';
+ private $lang;
+
+ /**
+ * Constructor
+ * Register the plugin's functions in hooks of PPA.
+ * @param $plugin_manager - Instance of plugin manager
+ * @param $language Current phpPgAdmin language. If it was not found in the plugin, English will be used.
+ */
+ function __construct($plugin_manager, $language) {
+ $this->lang = $plugin_manager->get_transalation($this->name, $language);
+ $plugin_manager->add_plugin($this, $this->get_hooks());
+ }
+
+ /**
+ * 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:
+ * 'hook' => array('function1', 'function2').
+ *
+ * Example:
+ * $functions = array(
+ * 'toplinks' => array('add_plugin_toplinks'),
+ * 'tabs' => array('add_tab_entry'),
+ * 'action_buttons' => array('add_more_an_entry')
+ * );
+ *
+ * @return $hooks
+ */
+ function get_hooks() {
+ $hooks = array(
+ 'toplinks' => array('add_plugin_toplinks')
+ );
+
+ return $hooks;
+ }
+
+ /**
+ * Get the plugin name, that will be used as identification
+ * @return $plugin_name
+ */
+ function get_name() {
+ return $this->name;
+ }
+
+ /**
+ * Add plugin in the top links
+ * @param $toplinks_operations
+ */
+ function add_plugin_toplinks(&$plugin_functions_parameters) {
+ global $misc;
+
+ $href = "plugin.php?".$plugin_functions_parameters['href'];
+ $href.= "&amp;plugin=".urlencode($this->name);
+ $href.= "&amp;action=show_page";
+ //NOTE: What is the best way to return? $_SERVER['HTTP_REFERER'] cannot be trusted.
+ $href.= "&amp;return_url=".urlencode($_SERVER['PHP_SELF']."?".$misc->getHREF());
+
+ $link = "<a class=\"toplink\" href=\"$href\">";
+ $link.= $this->lang['strdescription'];
+ $link.= "</a>";
+
+ //Add the link in the toplinks array
+ $plugin_functions_parameters['toplinks'][] = $link;
+ }
+
+ /**
+ * Show a simple page
+ *
+ * TODO: make a style for this plugin, as an example of use of own css style.
+ */
+ function show_page() {
+ global $lang;
+
+ echo "<div>{$this->lang['strdescription']}</div>";
+ echo "<br>";
+
+ $url = "<a href=\"{$_REQUEST['return_url']}\">";
+ $url.= $lang['strback'];
+ $url.= "</a>";
+ echo $url;
+ }
+}
+?>
26 plugins/PluginExample/lang/translations.php
View
@@ -1,26 +0,0 @@
-<?php
- /**
- * Supported Translations for PluginExample
- */
-
-
- // List of language files, and encoded language name.
-
- $pluginLangFiles = array(
- 'english' => 'English',
- 'portuguese-br' => 'Portugu&ecirc;s-Brasileiro'
- );
-
- // ISO639 language code to language file mapping.
- // See http://www.w3.org/WAI/ER/IG/ert/iso639.htm for language codes
-
- // If it's available 'language-country', but not general
- // 'language' translation (eg. 'portuguese-br', but not 'portuguese')
- // specify both 'la' => 'language-country' and 'la-co' => 'language-country'.
-
- $availableLanguages = array(
- 'en' => 'english',
- 'pt' => 'portuguese-br',
- 'pt-br' => 'portuguese-br'
- );
-?>
40 plugins/PluginExample/plugin.php
View
@@ -1,40 +0,0 @@
-<?php
-class PluginExample {
-
- /**
- * Attributes
- */
- public $plugin_name = 'Plugin example';
- public $plugin_index = __CLASS__;
- public $plugin_lang;
-
- /**
- * Constructor
- * Register the plugin's functions in hooks of PPA.
- * @param $plugin_manager - Instance of plugin manager
- * @param $language Current phpPgAdmin language. If it was not found in the plugin, English will be used.
- */
- function __construct($plugin_manager, $language) {
- $this->plugin_lang = $plugin_manager->get_transalation($this->plugin_index, $language);
- $plugin_manager->add_plugin_functions($this->plugin_index, 'toplinks', 'add_plugin_toplinks');
-
- /* Register more functions here */
- }
-
- /**
- * Get the plugin identification
- * @return $plugin_index
- */
- function get_plugin_index() {
- return $this->plugin_index;
- }
-
- /**
- * Add plugin in the top links
- * @param $toplinks_operations
- */
- function add_plugin_toplinks(&$toplinks_operations) {
- $toplinks_operations[$this->plugin_index] = "<a class=\"toplink\" href=\"#\">{$this->plugin_lang['plugin_toplink']}</a>";
- }
-}
-?>

No commit comments for this range

Something went wrong with that request. Please try again.