From: <gi...@ma...> - 2010-01-01 19:41:27
|
The branch, master has been updated via 7dd4e281b1ae0e60813cbdcef89f0afb0d113988 (commit) via fe5a72105f2811e29479f75f2bf89d0733bf4529 (commit) via 2e2598a8c5cb1ee7c8a1f0e53a8dea8ba492e1fe (commit) via 927ba6168dac68d60dcfdc02c5c974403db5dc7a (commit) from ce604f90211fdbdcb3d62cdae5cfbcc610eca1b0 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 7dd4e281b1ae0e60813cbdcef89f0afb0d113988 Author: John Reese <jr...@le...> Date: Fri Jan 1 13:36:40 2010 -0500 Documented example plugin source code commit fe5a72105f2811e29479f75f2bf89d0733bf4529 Author: John Reese <jr...@le...> Date: Fri Jan 1 13:36:33 2010 -0500 Minor plugin doc fix commit 2e2598a8c5cb1ee7c8a1f0e53a8dea8ba492e1fe Author: John Reese <jr...@le...> Date: Fri Jan 1 13:13:36 2010 -0500 Documented plugin localizations commit 927ba6168dac68d60dcfdc02c5c974403db5dc7a Author: John Reese <jr...@le...> Date: Fri Jan 1 13:13:15 2010 -0500 Updated plugin config documentation ----------------------------------------------------------------------- Summary of changes: docbook/developers/en/plugins-building-source.sgml | 168 +++++++++++++++++++- docbook/developers/en/plugins-building.sgml | 114 ++++++++++++-- 2 files changed, 266 insertions(+), 16 deletions(-) ----------------------------------------------------------------------- commit 7dd4e281b1ae0e60813cbdcef89f0afb0d113988 Author: John Reese <jr...@le...> Date: Fri Jan 1 13:36:40 2010 -0500 Documented example plugin source code diff --git a/docbook/developers/en/plugins-building-source.sgml b/docbook/developers/en/plugins-building-source.sgml index 6f1f749..7239b75 100644 --- a/docbook/developers/en/plugins-building-source.sgml +++ b/docbook/developers/en/plugins-building-source.sgml @@ -7,10 +7,176 @@ warranty or implied warranties. You may use this code however you want. </para> + <programlisting> +Example/ + Example.php + files/ + foo.css + lang/ + strings_english.txt + pages/ + config_page.php + config_update.php + foo.php + </programlisting> + <sect2 id="dev.plugins.building.source.Example.php"> <title>Example/Example.php</title> - <programlisting> + <programlisting><filename>Example/Example.php</filename> +<?php +class ExamplePlugin extends MantisPlugin { + function register() { + $this->name = 'Example'; # Proper name of plugin + $this->description = ''; # Short description of the plugin + $this->page = ''; # Default plugin page + + $this->version = '1.0'; # Plugin version string + $this->requires = array( # Plugin dependencies, array of basename => version pairs + 'MantisCore' => '1.2', # Should always depend on an appropriate version of MantisBT + ); + + $this->author = ''; # Author/team name + $this->contact = ''; # Author/team e-mail address + $this->url = ''; # Support webpage + } + + function events() { + return array( + 'EVENT_EXAMPLE_FOO' => EVENT_TYPE_EXECUTE, + 'EVENT_EXAMPLE_BAR' => EVENT_TYPE_CHAIN, + ); + } + + function hooks() { + return array( + 'EVENT_EXAMPLE_FOO' => 'foo', + 'EVENT_EXAMPLE_BAR' => 'bar', + ); + } + + function config() { + return array( + 'foo_or_bar' => 'foo', + ); + } + + function foo( $p_event ) { + echo 'In method foo(). '; + } + + function bar( $p_event, $p_chained_param ) { + return str_replace( 'foo', 'bar', $p_chained_param ); + } + +} + </programlisting> + </sect2> + + <sect2 id="dev.plugins.building.source.foo.css"> + <title>Example/files/foo.css</title> + + <programlisting><filename>Example/files/foo.css</filename> +p.foo { + color: red; +} + </programlisting> + </sect2> + + <sect2 id="dev.plugins.building.source.stringsenglish.txt"> + <title>Example/lang/strings_english.txt</title> + + <programlisting><filename>Example/lang/strings_english.txt</filename> +<?php + +$s_plugin_Example_configuration = "Configuration"; +$s_plugin_Example_foo_or_bar = "Foo or Bar?"; +$s_plugin_Example_reset = "Reset Value"; + </programlisting> + </sect2> + + <sect2 id="dev.plugins.building.source.configpage.php"> + <title>Example/page/config_page.php</title> + + <programlisting><filename>Example/pages/config_page.php</filename> +<?php + +html_page_top( plugin_lang_get( 'configuration' ) ); +$t_foo_or_bar = plugin_config_get( 'foo_or_bar' ); + +?> + +<br/> + +<form action="<?php echo plugin_page( 'config_update' ) ?>" method="post"> +<?php echo form_security_field( 'plugin_Example_config_update' ) ?> +<table class="width60" align="center"> + +<tr> + <td class="form-title" rowspan="2"><?php echo plugin_lang_get( 'configuration' ) ?></td> +</tr> + +<tr <?php echo helper_alternate_class() ?>> + <td class="category"><php echo plugin_lang_get( 'foo_or_bar' ) ?></td> + <td><input name="foo_or_bar" value="<?php echo string_attribute( $t_foo_or_bar ) ?>"/></td> +</tr> + +<tr <?php echo helper_alternate_class() ?>> + <td class="category"><php echo plugin_lang_get( 'reset' ) ?></td> + <td><input type="checkbox" name="reset"/></td> +</tr> + +<tr> + <td class="center" rowspan="2"><input type="submit"/></td> +</tr> + +</table> +</form> + +<?php + +html_page_bottom(); + </programlisting> + </sect2> + + <sect2 id="dev.plugins.building.source.configupdate.php"> + <title>Example/pages/config_update.php</title> + + <programlisting><filename>Example/pages/config_update.php</filename> +<?php +form_security_validate( 'plugin_Example_config_update' ); + +$f_foo_or_bar = gpc_get_string( 'foo_or_bar' ); +$f_reset = gpc_get_bool( 'reset', false ); + +if ( $f_reset ) { + plugin_config_delete( 'foo_or_bar' ); +} else { + if ( $f_foo_or_bar == 'foo' || $f_foo_or_bar == 'bar' ) { + plugin_config_set( 'foo_or_bar', $f_foo_or_bar ); + } +} + +form_security_purge( 'plugin_Example_config_update' ); +print_successful_redirect( plugin_page( 'foo', true ) ); + </programlisting> + </sect2> + + <sect2 id="dev.plugins.building.source.foo.php"> + <title>Example/page/foo.php</title> + + <programlisting><filename>Example/pages/foo.php</filename> +<?php +echo '<p>Here is a link to <a href="', plugin_page( 'foo' ), '">page foo</a>.</p>'; + '<link rel="stylesheet" type="text/css" href="', plugin_file( 'foo.css' ), '"/>', + '<p class="foo">'; + +event_signal( 'EVENT_EXAMPLE_FOO' ); + +$t_string = 'A sentence with the word "foo" in it.'; +$t_new_string = event_signal( 'EVENT_EXAMPLE_BAR', array( $t_string ) ); + +echo $t_new_string, '</p>'; </programlisting> </sect2> </sect1> commit fe5a72105f2811e29479f75f2bf89d0733bf4529 Author: John Reese <jr...@le...> Date: Fri Jan 1 13:36:33 2010 -0500 Minor plugin doc fix diff --git a/docbook/developers/en/plugins-building.sgml b/docbook/developers/en/plugins-building.sgml index eb560af..676d722 100644 --- a/docbook/developers/en/plugins-building.sgml +++ b/docbook/developers/en/plugins-building.sgml @@ -283,7 +283,7 @@ class ExamplePlugin extends MantisPlugin { <?php echo '<p>Here is a link to <a href="', plugin_page( 'foo' ), '">page foo</a>.</p>'; -echo '<link rel="stylesheet" type="text/css" href="', plugin_file( 'foo.css' ), '"/>', + '<link rel="stylesheet" type="text/css" href="', plugin_file( 'foo.css' ), '"/>', '<p class="foo">'; event_signal( 'EVENT_EXAMPLE_FOO' ); commit 2e2598a8c5cb1ee7c8a1f0e53a8dea8ba492e1fe Author: John Reese <jr...@le...> Date: Fri Jan 1 13:13:36 2010 -0500 Documented plugin localizations diff --git a/docbook/developers/en/plugins-building.sgml b/docbook/developers/en/plugins-building.sgml index 76077dd..eb560af 100644 --- a/docbook/developers/en/plugins-building.sgml +++ b/docbook/developers/en/plugins-building.sgml @@ -392,6 +392,88 @@ print_successful_redirect( plugin_page( 'foo', true ) ); <title>Language and Localization</title> <para> + MantisBT has a very advanced set of localization tools, which allow all parts of of + the application to be localized to the user's preferred language. This feature has + been extended for use by plugins as well, so that a plugin can be localized in much + the same method as used for the core system. Localizing a plugin involves creating + a language file for each localization available, and using a special API call to + retrieve the appropriate string for the user's language. + </para> + + <para> + All language files for plugins follow the same format used in the core of MantisBT, + should be placed in the plugin's <filename>lang/</filename> directory, and named + the same as the core language files. Strings specific to the plugin should be + "namespaced" in a way that will minimize any risk of collision. Translating the + plugin to other languages already supported by MantisBT is then as simple as + creating a new strings file with the localized content; the MantisBT core will find + and use the new language strings automatically. + </para> + + <para> + We'll use the "configuration" pages from the previous examples, and dress them up + with localized language strings, and add a few more flourishes to make the page act + like a standard MantisBT page. First we need to create a language file for English, + the default language of MantisBT and the default fallback language in the case that + some strings have not yet been localized to the user's language: + </para> + + <programlisting><filename>Example/lang/strings_english.txt</filename> + +<?php + +$s_plugin_Example_configuration = "Configuration"; +$s_plugin_Example_foo_or_bar = "Foo or Bar?"; +$s_plugin_Example_reset = "Reset Value"; + </programlisting> + + <programlisting><filename>Example/pages/config_page.php</filename> +<?php + +html_page_top( plugin_lang_get( 'configuration' ) ); +$t_foo_or_bar = plugin_config_get( 'foo_or_bar' ); + +?> + +<br/> + +<form action="<?php echo plugin_page( 'config_update' ) ?>" method="post"> +<?php echo form_security_field( 'plugin_Example_config_update' ) ?> +<table class="width60" align="center"> + +<tr> + <td class="form-title" rowspan="2"><?php echo plugin_lang_get( 'configuration' ) ?></td> +</tr> + +<tr <?php echo helper_alternate_class() ?>> + <td class="category"><php echo plugin_lang_get( 'foo_or_bar' ) ?></td> + <td><input name="foo_or_bar" value="<?php echo string_attribute( $t_foo_or_bar ) ?>"/></td> +</tr> + +<tr <?php echo helper_alternate_class() ?>> + <td class="category"><php echo plugin_lang_get( 'reset' ) ?></td> + <td><input type="checkbox" name="reset"/></td> +</tr> + +<tr> + <td class="center" rowspan="2"><input type="submit"/></td> +</tr> + +</table> +</form> + +<?php + +html_page_bottom(); + </programlisting> + + <para> + The two calls to <function>html_page_top()</function> and + <function>html_page_bottom()</function> trigger the standard MantisBT header and + footer portions, respectively, which also displays things such as the menus and + triggers other layout-related events. <function>helper_alternate_class()</function> + generates the CSS classes for alternating row colors in the table. The rest of the + HTML and CSS follows the "standard" MantisBT markup styles for content and layout. </para> </sect2> commit 927ba6168dac68d60dcfdc02c5c974403db5dc7a Author: John Reese <jr...@le...> Date: Fri Jan 1 13:13:15 2010 -0500 Updated plugin config documentation diff --git a/docbook/developers/en/plugins-building.sgml b/docbook/developers/en/plugins-building.sgml index faed2c1..76077dd 100644 --- a/docbook/developers/en/plugins-building.sgml +++ b/docbook/developers/en/plugins-building.sgml @@ -343,27 +343,29 @@ class ExamplePlugin extends MantisPlugin { <function>plugin_config_set()</function>. With these functions, the config option is prefixed with the plugin's name, in attempt to automatically avoid conflicts in naming. Our Example plugin will demonstrate this by adding a secure form to the - "foo" page, and handling the form on a separate page "bar" that will modify the - value in the database, and redirect back to page "foo", just like any other form - and action page in MantisBT: + "config_page", and handling the form on a separate page "config_update" that will + modify the value in the database, and redirect back to page "config_page", just + like any other form and action page in MantisBT: </para> - <programlisting><filename>Example/pages/foo.php</filename> + <programlisting><filename>Example/pages/config_page.php</filename> -<?php -... +<form action="<?php echo plugin_page( 'config_update' ) ?>" method="post"> +<?php echo form_security_field( 'plugin_Example_config_update' ) ?> -echo '<form action="', plugin_page( 'bar' ), '" method="post">', - form_security_field( 'plugin_Example_bar' ), - '<input name="foo_or_bar" value="', string_attribute( plugin_config_get( 'foo_or_bar' ) ), '"/>', - '<label><input type="checkbox" name="reset"/> Reset</label>', - '<input type="submit"/>'; +<label>Foo or Bar?<br/><input name="foo_or_bar" value="<?php echo string_attribute( $t_foo_or_bar ) ?>"/></label> +<br/> +<label><input type="checkbox" name="reset"/> Reset</label> +<br/> +<input type="submit"/> + +</form> </programlisting> - <programlisting><filename>Example/pages/foo.php</filename> + <programlisting><filename>Example/pages/config_update.php</filename> <?php -form_security_validate( 'plugin_Example_bar' ); +form_security_validate( 'plugin_Example_config_update' ); $f_foo_or_bar = gpc_get_string( 'foo_or_bar' ); $f_reset = gpc_get_bool( 'reset', false ); @@ -376,7 +378,7 @@ if ( $f_reset ) { } } -form_security_purge( 'plugin_Example_bar' ); +form_security_purge( 'plugin_Example_config_update' ); print_successful_redirect( plugin_page( 'foo', true ) ); </programlisting> ----------------------------------------------------------------------- -- Mantis Bug Tracker |