Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

-Created branch ppa_new_plugin_arch for the new plugin architecture;

-Included index 'plugins' in the $conf var;
-Included index 'PluginExample' in the $conf['plugins'] var;
-Created PluginManager class (classes/plugins/PluginManager.php) to manage the plugins;
-Created plugins directory;
-Created basic structure of a plugin, PluginExample, with some example functions;
-Updated file libraries/lib.inc.php, with the code to manager the plugins;
-Updated code that write the toplinks at classes/Misc.php;
-Created a hook example for the toplinks;
-Created default transalation for the PluginExample (English);
-Created default transalation for the PluginExample (Portuguese-BR);
  • Loading branch information...
commit 8ccfe9f14bf83a26fb2c9abd2828b5473f3f9897 1 parent ed943b3
Leonardo Sapiras authored May 11, 2011
18  classes/Misc.php
@@ -1142,11 +1142,21 @@ function printTopbar() {
1142 1142
 					' onclick="return confirm(\''. $lang['strconfdropcred']. '\')"':
1143 1143
 					'';
1144 1144
 
  1145
+				global $plugin_manager;
  1146
+				$toplinks = array();
  1147
+				$toplinks[] = "<a class=\"toplink\" 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;\">{$lang['strsql']}</a>";
  1148
+				$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>";
  1149
+				$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>";
  1150
+				/* TOPLINK HOOK'S PLACE */
  1151
+				$plugin_manager->execute_plugin_funtions('toplinks', $toplinks);
  1152
+				$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>";
  1153
+				
  1154
+				
1145 1155
 				echo "<td style=\"text-align: right\">";
1146  
-				echo "<ul class=\"toplink\">\n\t<li><a class=\"toplink\" 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;\">{$lang['strsql']}</a></li>\n";
1147  
-				echo "\t<li><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></li>\n";
1148  
-				echo "\t<li><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></li>\n";
1149  
- 				echo "\t<li><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></li>\n";
  1156
+				echo "<ul class=\"toplink\">\n";
  1157
+				foreach ($toplinks as $link) {
  1158
+					echo "\t<li>$link</li>\n";
  1159
+				}
1150 1160
  				echo "</ul>\n";
1151 1161
 				echo "</td>";
1152 1162
 			}
65  classes/plugins/PluginManager.php
... ...
@@ -0,0 +1,65 @@
  1
+<?php
  2
+
  3
+/**
  4
+ * A class that implements the plugin's system
  5
+ *
  6
+ * $Id:
  7
+ */
  8
+
  9
+class PluginManager {
  10
+
  11
+	/**
  12
+	 * Attributes
  13
+	 */
  14
+	public $plugins_list = array();
  15
+	public $functions_list = array();
  16
+
  17
+	/**
  18
+	 * Add a plugin in the manager 
  19
+	 * @param $plugin
  20
+	 */
  21
+	function add_plugin($plugin) {
  22
+		$this->plugins_list[$plugin->get_plugin_index()] = $plugin;
  23
+	}
  24
+
  25
+	/**
  26
+	 * Get a plugin from the $plugins_list by the plugin's name.
  27
+	 * @param $plugin_index
  28
+	 */
  29
+	function get_plugin($plugin_index) {
  30
+		return $this->plugins_list[$plugin_index];
  31
+	}
  32
+
  33
+	/**
  34
+	 * Add a function in the $functions_list list, with the information when this function will be used by the 
  35
+	 * phppgadmin core.
  36
+	 * @param $plugin_index - Index that identify the plugin. Example the plugin_example's index is plugin_example :-)
  37
+	 * @param $when - This identify when the added function will be called
  38
+	 * @param $function - The name of the function. It will be called by callback;
  39
+	 */
  40
+	function add_plugin_functions($plugin_index, $when, $function) {
  41
+		$this->functions_list[$when][] = array('plugin_index' => $plugin_index, 'function' => $function);
  42
+	}
  43
+
  44
+	/**
  45
+	 * Execute the plugins functions according some moment.
  46
+	 * @param $when - When the function will be called
  47
+	 * @param $function_args - The reference to arguments of the called function
  48
+	 *
  49
+	 * TODO: check the supported entries (browser tree, tabs, trailer, navigation links, action buttons, top links)
  50
+	 */
  51
+	function execute_plugin_funtions($when, &$function_args) {
  52
+		if (isset($this->functions_list[$when])) {
  53
+			foreach ($this->functions_list[$when] as $node) {
  54
+				$plugin_index = $node['plugin_index'];
  55
+				$function = $node['function'];
  56
+				$plugin = $this->get_plugin($plugin_index); 
  57
+				//
  58
+				if (method_exists($plugin, $function)) {
  59
+					call_user_func_array(array($plugin, $function), array(&$function_args));
  60
+				}
  61
+			}
  62
+		}
  63
+	}
  64
+}
  65
+?>
6  conf/config.inc.php-dist
@@ -149,7 +149,11 @@
149 149
 	// Configuration for ajax scripts
150 150
 	// Time in seconds. If set to 0, refreshing data using ajax will be disabled (locks and activity pages)
151 151
 	$conf['ajax_refresh'] = 3;
152  
-	
  152
+
  153
+	// Plugins
  154
+	$conf['plugins'] = array();
  155
+	$conf['plugins'][] = 'PluginExample';
  156
+
153 157
 	/*****************************************
154 158
 	 * Don't modify anything below this line *
155 159
 	 *****************************************/
11  libraries/lib.inc.php
@@ -179,6 +179,17 @@
179 179
 		exit;
180 180
 	}
181 181
 
  182
+	// Check if there are activated plugins
  183
+	$plugins = $conf['plugins'];//xdebug_var_dump($lang, $_language);
  184
+	require_once('./classes/plugins/PluginManager.php');
  185
+	$plugin_manager = new PluginManager();
  186
+	//register the plugins and their functions
  187
+	foreach ($plugins as $activated_plugin) {
  188
+		include_once('./plugins/'.$activated_plugin.'/plugin.php');
  189
+		$plugin = new $activated_plugin($plugin_manager, $_language);
  190
+		$plugin_manager->add_plugin($plugin);
  191
+	}
  192
+
182 193
 	// Create data accessor object, if necessary
183 194
 	if (!isset($_no_db_connection)) {
184 195
 		if (!isset($_REQUEST['server'])) {
12  plugins/PluginExample/README.txt
... ...
@@ -0,0 +1,12 @@
  1
+It is a plugin example, that will be usefull to create other plugins.
  2
+
  3
+This plugin is able to:
  4
+
  5
+* Add an entry in the browser tree in any level
  6
+* Add an entry in the tabs
  7
+* Add an entry in the trailer
  8
+* Add an entry in the navigation links
  9
+* Add an entry in the action buttons
  10
+* Add an entry in the top links
  11
+
  12
+The example plugin is default disable in the central config.inc.php file. 
257  plugins/PluginExample/lang/Makefile
... ...
@@ -0,0 +1,257 @@
  1
+# This Makefile recodes source lang files into XML Unicode.
  2
+# You should add your encodings to this file.  You need to have GNU Recode
  3
+# installed.
  4
+# 
  5
+# It is important to:
  6
+# - fix the delimiters of php code: <?php and ?>
  7
+# - convert CRLF -> LF
  8
+# - remove all text before first <?php
  9
+# - remove all text after last ?>
  10
+# - convert "&apos;" -> "'"
  11
+# using 'convert.awk'
  12
+#
  13
+# Modifications by Dave Smith, 2003-11-10:
  14
+#	Added TARGETS variable for easy listing of all lang files.
  15
+#	Added 'prepare' target to check that 'recode' is installed.
  16
+#	Added 'clean' target to nuke recoded files. 
  17
+#	Surpressed verbose command line dumpage with '@'.
  18
+#	Added dependency checking for incremental recoding.
  19
+#	Added pretty "Recoding ..." messages.
  20
+#	Added 'chmod 644' to 'all' target for correct file permissions.
  21
+# Modifications by Rafal Slubowski, 2003-12-12:
  22
+#       All conversions of recoded text moved to convert.awk script
  23
+# 
  24
+# $Id: Makefile,v 1.48 2007/02/10 03:48:35 xzilla Exp $
  25
+
  26
+DESTDIR=./recoded
  27
+TARGETS=polish \
  28
+	english \
  29
+	chinese-sim \
  30
+	chinese-tr \
  31
+	chinese-utf8-zh_TW \
  32
+	chinese-utf8-zh_CN \
  33
+	danish \
  34
+	dutch \
  35
+	german \
  36
+	spanish \
  37
+	italian \
  38
+	french \
  39
+	russian \
  40
+	russian-utf8 \
  41
+	japanese \
  42
+	slovak \
  43
+	turkish \
  44
+	czech \
  45
+	portuguese-br \
  46
+	portuguese-pt \
  47
+	swedish \
  48
+	afrikaans \
  49
+	arabic \
  50
+	mongol \
  51
+	ukrainian \
  52
+	hungarian \
  53
+	hebrew \
  54
+	catalan \
  55
+	romanian \
  56
+	greek \
  57
+	galician
  58
+
  59
+all:	prepare ${TARGETS}
  60
+	@for p in ${TARGETS} ; do chmod 644 ${DESTDIR}/$$p.php ; done
  61
+
  62
+prepare:
  63
+	@which recode >/dev/null 2>&1 || ( echo "You must have GNU 'recode' installed to use this Makefile,\
  64
+						but I could not find it in your path!" && exit 1 )
  65
+	@which sed >/dev/null 2>&1 || ( echo "You must have sed installed to use this Makefile,\
  66
+						but I could not find it in your path!" && exit 1 )
  67
+	@which awk >/dev/null 2>&1 || ( echo "You must have awk installed to use this Makefile,\
  68
+						but I could not find it in your path!" && exit 1 )
  69
+
  70
+clean:
  71
+	@echo "Nuking recoded lang files..."
  72
+	@for p in ${TARGETS} ; do rm -fv ${DESTDIR}/$$p.php ; done
  73
+
  74
+catalan:	catalan.php
  75
+	@echo "Recoding catalan..."
  76
+	@cat catalan.php | recode utf-8..xml | ./convert.awk \
  77
+		> ${DESTDIR}/catalan.php
  78
+	@chmod 644 catalan.php ${DESTDIR}/catalan.php
  79
+
  80
+polish:	polish.php
  81
+	@echo "Recoding polish..."
  82
+	@cat polish.php | recode utf-8..xml | ./convert.awk \
  83
+		> ${DESTDIR}/polish.php
  84
+	@chmod 644 polish.php ${DESTDIR}/polish.php
  85
+
  86
+english:	english.php
  87
+	@echo "Recoding english..."
  88
+	@cat english.php | recode latin1..xml | ./convert.awk \
  89
+		> ${DESTDIR}/english.php
  90
+	@chmod 644 english.php ${DESTDIR}/english.php
  91
+
  92
+dutch:	dutch.php
  93
+	@echo "Recoding dutch..."
  94
+	@cat dutch.php | recode latin1..xml | ./convert.awk \
  95
+		> ${DESTDIR}/dutch.php
  96
+	@chmod 644 dutch.php ${DESTDIR}/dutch.php
  97
+
  98
+danish:	danish.php
  99
+	@echo "Recoding danish..."
  100
+	@cat danish.php | recode latin1..xml | ./convert.awk \
  101
+		> ${DESTDIR}/danish.php
  102
+	@chmod 644 danish.php ${DESTDIR}/danish.php
  103
+
  104
+german:	german.php
  105
+	@echo "Recoding german..."
  106
+	@cat german.php | recode utf-8..xml | ./convert.awk \
  107
+		> ${DESTDIR}/german.php
  108
+	@chmod 644 german.php ${DESTDIR}/german.php
  109
+
  110
+spanish:	spanish.php
  111
+	@echo "Recoding spanish..."
  112
+	@cat spanish.php | recode iso-8859-1..xml | ./convert.awk \
  113
+		> ${DESTDIR}/spanish.php
  114
+	@chmod 644 spanish.php ${DESTDIR}/spanish.php
  115
+
  116
+italian:	italian.php
  117
+	@echo "Recoding italian..."
  118
+	@cat italian.php | recode iso-8859-1..xml | ./convert.awk \
  119
+		> ${DESTDIR}/italian.php
  120
+	@chmod 644 italian.php ${DESTDIR}/italian.php
  121
+
  122
+chinese-sim:	chinese-sim.php
  123
+	@echo "Recoding chinese-sim..."
  124
+	@cat chinese-sim.php | recode gb2312..xml | ./convert.awk \
  125
+		> ${DESTDIR}/chinese-sim.php
  126
+	@chmod 644 chinese-sim.php ${DESTDIR}/chinese-sim.php
  127
+
  128
+chinese-tr:	chinese-tr.php
  129
+	@echo "Recoding chinese-tr..."
  130
+	@cat chinese-tr.php | recode big5..xml | ./convert.awk \
  131
+		> ${DESTDIR}/chinese-tr.php
  132
+	@chmod 644 chinese-tr.php ${DESTDIR}/chinese-tr.php
  133
+
  134
+chinese-utf8-zh_CN:	chinese-utf8-zh_CN.php
  135
+	@echo "Recoding chinese-utf8-zh_CN..."
  136
+	@cat chinese-utf8-zh_CN.php | recode utf-8..xml | ./convert.awk \
  137
+		> ${DESTDIR}/chinese-utf8-zh_CN.php
  138
+	@chmod 644 chinese-utf8-zh_CN.php ${DESTDIR}/chinese-utf8-zh_CN.php
  139
+
  140
+chinese-utf8-zh_TW:	chinese-utf8-zh_TW.php
  141
+	@echo "Recoding chinese-utf8-zh_TW..."
  142
+	@cat chinese-utf8-zh_TW.php | recode utf-8..xml | ./convert.awk \
  143
+		> ${DESTDIR}/chinese-utf8-zh_TW.php
  144
+	@chmod 644 chinese-utf8-zh_TW.php ${DESTDIR}/chinese-utf8-zh_TW.php
  145
+
  146
+french:	french.php
  147
+	@echo "Recoding french..."
  148
+	@cat french.php | recode latin1..xml | ./convert.awk \
  149
+		> ${DESTDIR}/french.php
  150
+	@chmod 644 french.php ${DESTDIR}/french.php
  151
+
  152
+japanese:	japanese.php
  153
+	@echo "Recoding japanese..."
  154
+	@cat japanese.php | recode euc-jp..xml | ./convert.awk \
  155
+		> ${DESTDIR}/japanese.php
  156
+	@chmod 644 japanese.php ${DESTDIR}/japanese.php
  157
+
  158
+russian:	russian.php
  159
+	@echo "Recoding russian..."
  160
+	@cat russian.php | recode koi8..xml | ./convert.awk \
  161
+		> ${DESTDIR}/russian.php
  162
+	@chmod 644 russian.php ${DESTDIR}/russian.php
  163
+russian-utf8:	russian-utf8.php
  164
+	@echo "Recoding russian-utf8..."
  165
+	@cat russian-utf8.php | recode utf-8..xml | ./convert.awk \
  166
+		> ${DESTDIR}/russian-utf8.php
  167
+	@chmod 644 russian-utf8.php ${DESTDIR}/russian-utf8.php
  168
+
  169
+slovak:	slovak.php
  170
+	@echo "Recoding slovak..."
  171
+	@cat slovak.php | recode utf-8..xml | ./convert.awk \
  172
+		> ${DESTDIR}/slovak.php
  173
+	@chmod 644 slovak.php ${DESTDIR}/slovak.php
  174
+
  175
+czech:	czech.php
  176
+	@echo "Recoding czech..."
  177
+	@cat czech.php | recode utf-8..xml | ./convert.awk \
  178
+		> ${DESTDIR}/czech.php
  179
+	@chmod 644 czech.php ${DESTDIR}/czech.php
  180
+
  181
+turkish:	turkish.php
  182
+	@echo "Recoding turkish..."
  183
+	@cat turkish.php | recode iso-8859-9..xml | ./convert.awk \
  184
+		> ${DESTDIR}/turkish.php
  185
+	@chmod 644 turkish.php ${DESTDIR}/turkish.php
  186
+
  187
+portuguese-br:	portuguese-br.php
  188
+	@echo "Recoding portuguese-br..."
  189
+	@cat portuguese-br.php | recode iso-8859-1..xml | ./convert.awk \
  190
+		> ${DESTDIR}/portuguese-br.php
  191
+	@chmod 644 portuguese-br.php ${DESTDIR}/portuguese-br.php
  192
+
  193
+portuguese-pt:	portuguese-pt.php
  194
+	@echo "Recoding portuguese-pt..."
  195
+	@cat portuguese-pt.php | recode iso-8859-15..xml | ./convert.awk \
  196
+		> ${DESTDIR}/portuguese-pt.php
  197
+	@chmod 644 portuguese-pt.php ${DESTDIR}/portuguese-pt.php
  198
+
  199
+swedish:	swedish.php
  200
+	@echo "Recoding swedish..."
  201
+	@cat swedish.php | recode iso-8859-1..xml | ./convert.awk \
  202
+		> ${DESTDIR}/swedish.php
  203
+	@chmod 644 swedish.php ${DESTDIR}/swedish.php
  204
+
  205
+afrikaans:	afrikaans.php
  206
+	@echo "Recoding afrikaans..."
  207
+	@cat afrikaans.php | recode iso-8859-1..xml | ./convert.awk \
  208
+		> ${DESTDIR}/afrikaans.php
  209
+	@chmod 644 afrikaans.php ${DESTDIR}/afrikaans.php
  210
+
  211
+hungarian:	hungarian.php
  212
+	@echo "Recoding hungarian..."
  213
+	@cat hungarian.php | recode utf-8..xml | ./convert.awk \
  214
+		> ${DESTDIR}/hungarian.php
  215
+	@chmod 644 hungarian.php ${DESTDIR}/hungarian.php
  216
+
  217
+arabic:		arabic.php
  218
+	@echo "Recoding arabic..."
  219
+	@cat arabic.php | recode utf-8..xml | ./convert.awk \
  220
+		> ${DESTDIR}/arabic.php
  221
+	@chmod 644 arabic.php ${DESTDIR}/arabic.php
  222
+
  223
+mongol:		mongol.php
  224
+	@echo "Recoding mongol..."
  225
+	@cat mongol.php | recode iso-8859-5..xml | ./convert.awk \
  226
+		> ${DESTDIR}/mongol.php
  227
+	@chmod 644 mongol.php ${DESTDIR}/mongol.php
  228
+
  229
+ukrainian:	ukrainian.php
  230
+	@echo "Recoding ukrainian..."
  231
+	@cat ukrainian.php | recode koi8-r..xml | ./convert.awk \
  232
+		> ${DESTDIR}/ukrainian.php
  233
+	@chmod 644 ukrainian.php ${DESTDIR}/ukrainian.php
  234
+
  235
+hebrew:	hebrew.php
  236
+	@echo "Recoding hebrew..."
  237
+	@cat hebrew.php | recode utf-8..xml | ./convert.awk \
  238
+		> ${DESTDIR}/hebrew.php
  239
+	@chmod 644 hebrew.php ${DESTDIR}/hebrew.php
  240
+
  241
+romanian:		romanian.php
  242
+	@echo "Recoding romanian..."
  243
+	@cat romanian.php | recode utf-8..xml | ./convert.awk \
  244
+		> ${DESTDIR}/romanian.php
  245
+	@chmod 644 romanian.php ${DESTDIR}/romanian.php
  246
+
  247
+greek:                greek.php
  248
+	@echo "Recoding greek..."
  249
+	@cat greek.php | recode iso-8859-7..xml | ./convert.awk \
  250
+		> ${DESTDIR}/greek.php
  251
+	@chmod 644 greek.php ${DESTDIR}/greek.php
  252
+
  253
+galician: galician.php
  254
+	@echo "Recoding galician..."
  255
+	@cat galician.php | recode utf-8..xml | ./convert.awk \
  256
+		> ${DESTDIR}/galician.php
  257
+	@chmod 644 galician.php ${DESTDIR}/galician.php
18  plugins/PluginExample/lang/convert.awk
... ...
@@ -0,0 +1,18 @@
  1
+#!/usr/bin/awk -f
  2
+#
  3
+# Script contains all needed conversions of recoded text
  4
+#
  5
+# Remove everything before first "<?php"
  6
+BEGIN	{ while (index($0,"&lt;?php")==0) { getline; continue } 
  7
+	  print "<?php";
  8
+	}
  9
+# Remove everything after first "?>"
  10
+# (as there should be only one occurance, thats no problem)
  11
+/\?\&gt;/ { print "?>"; exit }
  12
+
  13
+	{ 
  14
+	  # Convert CRLF -> LF (== "remove CR" ) ;-)
  15
+	  gsub("&#13;","");
  16
+	  gsub("&apos;","'");
  17
+	  print $0
  18
+	}
16  plugins/PluginExample/lang/english.php
... ...
@@ -0,0 +1,16 @@
  1
+<?php
  2
+
  3
+	/**
  4
+	 * English language file for plugin Example.  Use this as a basis
  5
+	 * for new translations.
  6
+	 *
  7
+	 * $Id: 
  8
+	 */
  9
+
  10
+	//Plugin data
  11
+	$plugin_lang['plugin_name'] = 'Plugin Example';
  12
+
  13
+	//Test
  14
+	$plugin_lang['plugin_toplink'] = 'Example extra toplink';
  15
+
  16
+?>
16  plugins/PluginExample/lang/portuguese-br.php
... ...
@@ -0,0 +1,16 @@
  1
+<?php
  2
+
  3
+	/**
  4
+	 * Brazilian Portuguese language file for plugin Example. Use this as a basis
  5
+	 * for new translations.
  6
+	 *
  7
+	 * $Id: 
  8
+	 */
  9
+
  10
+	//Plugin data
  11
+	$plugin_lang['plugin_name'] = 'Plugin Exemplo';
  12
+
  13
+	//Test
  14
+	$plugin_lang['plugin_toplink'] = 'Exemplo de toplink extra';
  15
+
  16
+?>
16  plugins/PluginExample/lang/recoded/english.php
... ...
@@ -0,0 +1,16 @@
  1
+<?php
  2
+
  3
+	/**
  4
+	 * English language file for plugin Example.  Use this as a basis
  5
+	 * for new translations.
  6
+	 *
  7
+	 * $Id: 
  8
+	 */
  9
+
  10
+	//Plugin data
  11
+	$plugin_lang['plugin_name'] = 'PluginExample';
  12
+
  13
+	//Test
  14
+	$plugin_lang['plugin_toplink'] = 'Example extra toplink';
  15
+
  16
+?>
16  plugins/PluginExample/lang/recoded/portuguese-br.php
... ...
@@ -0,0 +1,16 @@
  1
+<?php
  2
+
  3
+	/**
  4
+	 * Brazilian Portuguese language file for plugin Example. Use this as a basis
  5
+	 * for new translations.
  6
+	 *
  7
+	 * $Id: 
  8
+	 */
  9
+
  10
+	//Plugin data
  11
+	$plugin_lang['plugin_name'] = 'Plugin Exemplo';
  12
+
  13
+	//Test
  14
+	$plugin_lang['plugin_toplink'] = 'Exemplo de toplink extra';
  15
+
  16
+?>
27  plugins/PluginExample/lang/translations.php
... ...
@@ -0,0 +1,27 @@
  1
+<?php
  2
+	/**
  3
+	 * Supported Translations for PluginExample
  4
+	 *
  5
+	 * $Id: 
  6
+	 */
  7
+	
  8
+	
  9
+	// List of language files, and encoded language name.
  10
+	
  11
+	$pluginLangFiles = array(
  12
+		'english' => 'English',
  13
+		'portuguese-br' => 'Portugu&ecirc;s-Brasileiro'
  14
+	);
  15
+
  16
+	// ISO639 language code to language file mapping.
  17
+	// See http://www.w3.org/WAI/ER/IG/ert/iso639.htm for language codes
  18
+
  19
+	// If it's available 'language-country', but not general
  20
+	// 'language' translation (eg. 'portuguese-br', but not 'portuguese')
  21
+	// specify both 'la' => 'language-country' and 'la-co' => 'language-country'.
  22
+
  23
+	$availableLanguages = array(
  24
+		'en' => 'english',
  25
+		'pt-br' => 'portuguese-br'
  26
+	);
  27
+?>
51  plugins/PluginExample/plugin.php
... ...
@@ -0,0 +1,51 @@
  1
+<?php
  2
+class PluginExample {
  3
+
  4
+	/**
  5
+	 * Attributes
  6
+	 */
  7
+	public $plugin_name = 'Plugin example';
  8
+	public $plugin_index = __CLASS__;
  9
+	public $plugin_lang = '';
  10
+
  11
+	/**
  12
+	 * Constructor
  13
+	 * Register the plugin's functions in hooks of PPA.
  14
+	 * @param $plugin_manager - Instance of plugin manager
  15
+	 */
  16
+	function __construct($plugin_manager, $language) {
  17
+		$this->manage_transalation($language);
  18
+		$plugin_manager->add_plugin_functions($this->plugin_index, 'toplinks', 'add_plugin_toplinks');
  19
+		/* Register more functions here */
  20
+	}
  21
+
  22
+	/**
  23
+	 * Get the $plugin_index
  24
+	 * @return $plugin_index
  25
+	 */
  26
+	 function get_plugin_index() {
  27
+	 	 return $this->plugin_index;
  28
+	 }
  29
+
  30
+	/**
  31
+	 * Add plugin in the top links
  32
+	 * @param $toplinks_operations
  33
+	 */
  34
+	function add_plugin_toplinks(&$toplinks_operations) {
  35
+		$toplinks_operations[$this->plugin_index] = "<a class=\"toplink\" href=\"#\">{$this->plugin_lang['plugin_toplink']}</a>";
  36
+	}
  37
+
  38
+	/**
  39
+	 * Manage the plugins translations
  40
+	 * TODO: to put this function in the PluginManager class
  41
+	 */
  42
+	function manage_transalation($language) {
  43
+		require_once("./plugins/{$this->plugin_index}/lang/recoded/english.php");
  44
+		include_once("./plugins/{$this->plugin_index}/lang/translations.php");
  45
+		if (isset($pluginLangFiles[$language])) {
  46
+			include_once("./plugins/{$this->plugin_index}/lang/recoded/{$language}.php");
  47
+		}
  48
+		$this->plugin_lang = $plugin_lang;
  49
+	}
  50
+}
  51
+?>

0 notes on commit 8ccfe9f

Robert Treat

According to the above comment, shouldn't you have both a portuguese mapping and portuguese-br mapping? I only see the -br one. It might be that the above comment is wrong, but they don't seem to match.

Robert Treat

Would it be possible to combine the above into a single config variable.... like $conf['plugins'] = array('PluginExample','Slony');

Leonardo Sapiras

Yup, I don't see problem. I will also write an comment with an example. Thanks

Leonardo Sapiras

Yes, you are right, is missing the 'pt' => 'portuguese-br'.
About the comment. I copy it from the original lang/translations.php, and I forgot to follow what is written.

Leonardo Sapiras

Write a comment that this files is a copy from lang/Makefile. And remove unnecessaries comments and languages that this plugin doesn't have translation.

Leonardo Sapiras

The $Id was used by cvs. I can be dropped from here, and the other files.

Please sign in to comment.
Something went wrong with that request. Please try again.