Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 3 commits
  • 7 files changed
  • 0 comments
  • 1 contributor
May 24, 2011
Leonardo Sapiras Updated code in the PluginManager constructor
-Merged $lang['strpluginnotfound'] with $lang['strpluginnotfoundcomplem'].
-Regenated translations.
-Exit the code when a given plugin doen't exist.
c717532
Leonardo Sapiras Dealing with Plugin
-Moved the code from PluginManager->get_translation() to Exemple's contruct, with some changes.
-Dropped PluginManager->get_translation().
2e18ebd
May 26, 2011
Leonardo Sapiras Code refactor
-Removed some useless code.
-Moved some code from Example/plugin.php to PluginManager.php.
e727129
2  classes/Misc.php
@@ -1089,7 +1089,7 @@ function printTopbar() {
1089 1089
 				$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>";
1090 1090
 				/* TOPLINK HOOK'S PLACE */
1091 1091
 				$plugin_functions_parameters = array(
1092  
-					'toplinks' => &$toplinks, //the array of toplinks is passed by reference.
  1092
+					'toplinks' => &$toplinks,
1093 1093
 					'href' => $this->href
1094 1094
 				);
1095 1095
 				/* * */
28  classes/PluginManager.php
@@ -30,10 +30,8 @@ function __construct($language) {
30 30
 				include_once($plugin_file);
31 31
 				$plugin = new $activated_plugin($this, $language);
32 32
 			} else {
33  
-				//TODO: create a HTML.
34 33
 				printf($lang['strpluginnotfound']."\t\n", $activated_plugin);
35  
-				printf($lang['strpluginnotfoundcomplem']);
36  
-				// TODO: exit??
  34
+				exit;
37 35
 			}
38 36
 		}
39 37
 	}
@@ -41,10 +39,8 @@ function __construct($language) {
41 39
 	/**
42 40
 	 * Add a plugin in the list of plugins to manage
43 41
 	 * @param $plugin - Instance from plugin
44  
-	 * @param $hooks - Array with functions and the places where they will hook. The default value is an empty array.
45  
-	 * @param $actions - Array with functions that the plugin will use as actions. The default value is an empty array.
46 42
 	 */
47  
-	function add_plugin($plugin, $hooks = array(), $actions = array()) {
  43
+	function add_plugin($plugin) {
48 44
 		//The $name is the identification of the plugin.
49 45
 		//Example: PluginExample is the identification for PluginExample
50 46
 		//It will be used to get a specific plugin from the plugins_list.
@@ -52,11 +48,13 @@ function add_plugin($plugin, $hooks = array(), $actions = array()) {
52 48
 		$this->plugins_list[$plugin_name] = $plugin;
53 49
 
54 50
 		//Register the plugin's functions
  51
+		$hooks = $plugin->get_hooks();   //TODO: validate if the plugin has the get_hooks method?
55 52
 		foreach ($hooks as $hook => $functions) {
56 53
 			$this->functions_list['hooks'][$hook][$plugin_name] = $functions;
57 54
 		}
58 55
 
59 56
 		//Register the plugin's actions
  57
+		$actions = $plugin->get_actions();
60 58
 		$this->functions_list['actions'][$plugin_name] = $actions;
61 59
 	}
62 60
 
@@ -72,7 +70,6 @@ function get_plugin($name) {
72 70
 		} else {
73 71
 			// Show an error and stop the application
74 72
 			printf($lang['strpluginnotfound']."\t\n", $name);
75  
-			printf($lang['strpluginnotfoundcomplem']);
76 73
 			exit;
77 74
 		}
78 75
 	}
@@ -88,7 +85,7 @@ function execute_plugin_funtions($hook, &$function_args) {
88 85
 		if (isset($this->functions_list['hooks'][$hook])) {
89 86
 			foreach ($this->functions_list['hooks'][$hook] as $plugin_name => $functions) {
90 87
 				foreach ($functions as $function) {
91  
-					$plugin = $this->get_plugin($plugin_name);
  88
+					$plugin = $this->plugins_list[$plugin_name];
92 89
 					if (method_exists($plugin, $function)) {
93 90
 						call_user_func_array(array($plugin, $function), array(&$function_args));
94 91
 					}
@@ -98,21 +95,6 @@ function execute_plugin_funtions($hook, &$function_args) {
98 95
 	}
99 96
 
100 97
 	/**
101  
-	 * Get the plugin translations
102  
-	 * @param $name - Plugin's name. Example: PluginExample, Crud, etc...
103  
-	 * @param $language - Current phpPgAdmin language. If it was not found in the plugin, English will be used.
104  
-	 *
105  
-	 * TODO: check if an english translation file exists. If not, to think a way to alert about it.
106  
-	 */
107  
-	function get_transalation($name, $language) {
108  
-		require_once("./plugins/{$name}/lang/recoded/english.php");
109  
-		if (file_exists("./plugins/{$name}/lang/recoded/{$language}.php")) {
110  
-			include_once("./plugins/{$name}/lang/recoded/{$language}.php");
111  
-		}
112  
-		return $plugin_lang;
113  
-	}
114  
-
115  
-	/**
116 98
 	 * Execute a plugin's action
117 99
 	 * @param $action - action that will be executed. The action is the name of a plugin's function.
118 100
 	 */
3  lang/english.php
@@ -912,7 +912,6 @@
912 912
 	$lang['strftscantparsercopy'] = 'Can\'t specify both parser and template during text search configuration creation.';
913 913
 
914 914
 	//Plugins
915  
-	$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.';
916  
-	$lang['strpluginnotfoundcomplem'] = 'Plugin\'s names are case sensitive';
  915
+	$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. Plugin\'s names are case sensitive';
917 916
 	$lang['stractionnotfound'] = 'Error: action \'%s\' not found in the \'%s\' plugin, or it was not specified as an action.';
918 917
 ?>
3  lang/portuguese-br.php
@@ -912,7 +912,6 @@
912 912
 	$lang['strftscantparsercopy'] = 'Não é possível especificar ambos parser e modelo durante a criação da configuração de busca de texto.';
913 913
 
914 914
 	//Plugins
915  
-	$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';
916  
-	$lang['strpluginnotfoundcomplem'] = 'Os nomes dos plugins são case sensitive';
  915
+	$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. Os nomes dos plugins são case sensitive.';
917 916
 	$lang['stractionnotfound'] = 'Erro: ação \'%s\' não encontrada no plugin \'%s\'.';
918 917
 ?>
3  lang/recoded/english.php
@@ -912,7 +912,6 @@
912 912
 	$lang['strftscantparsercopy'] = 'Can\'t specify both parser and template during text search configuration creation.';
913 913
 
914 914
 	//Plugins
915  
-	$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.';
916  
-	$lang['strpluginnotfoundcomplem'] = 'Plugin\'s names are case sensitive';
  915
+	$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. Plugin\'s names are case sensitive';
917 916
 	$lang['stractionnotfound'] = 'Error: action \'%s\' not found in the \'%s\' plugin, or it was not specified as an action.';
918 917
 ?>
3  lang/recoded/portuguese-br.php
@@ -912,7 +912,6 @@
912 912
 	$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.';
913 913
 
914 914
 	//Plugins
915  
-	$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';
916  
-	$lang['strpluginnotfoundcomplem'] = 'Os nomes dos plugins s&#227;o case sensitive';
  915
+	$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. Os nomes dos plugins s&#227;o case sensitive.';
917 916
 	$lang['stractionnotfound'] = 'Erro: a&#231;&#227;o \'%s\' n&#227;o encontrada no plugin \'%s\'.';
918 917
 ?>
11  plugins/Example/plugin.php
@@ -14,8 +14,15 @@ class Example {
14 14
 	 * @param $language Current phpPgAdmin language. If it was not found in the plugin, English will be used.
15 15
 	 */
16 16
 	function __construct($plugin_manager, $language) {
17  
-		$this->lang = $plugin_manager->get_transalation($this->name, $language);
18  
-		$plugin_manager->add_plugin($this, $this->get_hooks(), $this->get_actions());
  17
+		// Set the plugin's language
  18
+		$lang_directory = dirname(__FILE__)."/lang/recoded";
  19
+		require_once("$lang_directory/english.php");
  20
+		if (file_exists("$lang_directory/$language.php")) {
  21
+			include_once("$lang_directory/$language.php");
  22
+		}
  23
+		$this->lang = $plugin_lang;
  24
+
  25
+		$plugin_manager->add_plugin($this);
19 26
 	}
20 27
 
21 28
 	/**

No commit comments for this range

Something went wrong with that request. Please try again.