| [ Index ] |
PHP Cross Reference of MantisBT |
[Summary view] [Print] [Text view]
1 <?xml version='1.0' encoding='utf-8' ?> 2 <!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [ 3 <!ENTITY % BOOK_ENTITIES SYSTEM "Developers_Guide.ent"> 4 %BOOK_ENTITIES; 5 ]> 6 <sect1 id="dev.plugins.building.source"> 7 <title>Example Plugin Source Listing</title> 8 9 <para> 10 The code in this section, for the Example plugin, is available for use, 11 modification, and redistribution without any restrictions and without any 12 warranty or implied warranties. You may use this code however you want. 13 </para> 14 15 <programlisting> 16 Example/ 17 Example.php 18 files/ 19 foo.css 20 lang/ 21 strings_english.txt 22 pages/ 23 config_page.php 24 config_update.php 25 foo.php 26 </programlisting> 27 28 <sect2 id="dev.plugins.building.source.Example.php"> 29 <title>Example/Example.php</title> 30 31 <programlisting><filename>Example/Example.php</filename> 32 <?php 33 class ExamplePlugin extends MantisPlugin { 34 function register() { 35 $this->name = 'Example'; # Proper name of plugin 36 $this->description = ''; # Short description of the plugin 37 $this->page = ''; # Default plugin page 38 39 $this->version = '1.0'; # Plugin version string 40 $this->requires = array( # Plugin dependencies, array of basename => version pairs 41 'MantisCore' => '1.2.0, <= 1.2.0', # Should always depend on an appropriate version of MantisBT 42 ); 43 44 $this->author = ''; # Author/team name 45 $this->contact = ''; # Author/team e-mail address 46 $this->url = ''; # Support webpage 47 } 48 49 function events() { 50 return array( 51 'EVENT_EXAMPLE_FOO' => EVENT_TYPE_EXECUTE, 52 'EVENT_EXAMPLE_BAR' => EVENT_TYPE_CHAIN, 53 ); 54 } 55 56 function hooks() { 57 return array( 58 'EVENT_EXAMPLE_FOO' => 'foo', 59 'EVENT_EXAMPLE_BAR' => 'bar', 60 ); 61 } 62 63 function config() { 64 return array( 65 'foo_or_bar' => 'foo', 66 ); 67 } 68 69 function foo( $p_event ) { 70 echo 'In method foo(). '; 71 } 72 73 function bar( $p_event, $p_chained_param ) { 74 return str_replace( 'foo', 'bar', $p_chained_param ); 75 } 76 77 } 78 </programlisting> 79 </sect2> 80 81 <sect2 id="dev.plugins.building.source.foo.css"> 82 <title>Example/files/foo.css</title> 83 84 <programlisting><filename>Example/files/foo.css</filename> 85 p.foo { 86 color: red; 87 } 88 </programlisting> 89 </sect2> 90 91 <sect2 id="dev.plugins.building.source.stringsenglish.txt"> 92 <title>Example/lang/strings_english.txt</title> 93 94 <programlisting><filename>Example/lang/strings_english.txt</filename> 95 <?php 96 97 $s_plugin_Example_configuration = "Configuration"; 98 $s_plugin_Example_foo_or_bar = "Foo or Bar?"; 99 $s_plugin_Example_reset = "Reset Value"; 100 </programlisting> 101 </sect2> 102 103 <sect2 id="dev.plugins.building.source.configpage.php"> 104 <title>Example/page/config_page.php</title> 105 106 <programlisting><filename>Example/pages/config_page.php</filename> 107 <?php 108 109 html_page_top( plugin_lang_get( 'configuration' ) ); 110 $t_foo_or_bar = plugin_config_get( 'foo_or_bar' ); 111 112 ?> 113 114 <br/> 115 116 <form action="<?php echo plugin_page( 'config_update' ) ?>" method="post"> 117 <?php echo form_security_field( 'plugin_Example_config_update' ) ?> 118 <table class="width60"> 119 120 <tr> 121 <td class="form-title" rowspan="2"><?php echo plugin_lang_get( 'configuration' ) ?></td> 122 </tr> 123 124 <tr <?php echo helper_alternate_class() ?>> 125 <td class="category"><php echo plugin_lang_get( 'foo_or_bar' ) ?></td> 126 <td><input name="foo_or_bar" value="<?php echo string_attribute( $t_foo_or_bar ) ?>"/></td> 127 </tr> 128 129 <tr <?php echo helper_alternate_class() ?>> 130 <td class="category"><php echo plugin_lang_get( 'reset' ) ?></td> 131 <td><input type="checkbox" name="reset"/></td> 132 </tr> 133 134 <tr> 135 <td class="center" rowspan="2"><input type="submit"/></td> 136 </tr> 137 138 </table> 139 </form> 140 141 <?php 142 143 html_page_bottom(); 144 </programlisting> 145 </sect2> 146 147 <sect2 id="dev.plugins.building.source.configupdate.php"> 148 <title>Example/pages/config_update.php</title> 149 150 <programlisting><filename>Example/pages/config_update.php</filename> 151 <?php 152 form_security_validate( 'plugin_Example_config_update' ); 153 154 $f_foo_or_bar = gpc_get_string( 'foo_or_bar' ); 155 $f_reset = gpc_get_bool( 'reset', false ); 156 157 if ( $f_reset ) { 158 plugin_config_delete( 'foo_or_bar' ); 159 } else { 160 if ( $f_foo_or_bar == 'foo' || $f_foo_or_bar == 'bar' ) { 161 plugin_config_set( 'foo_or_bar', $f_foo_or_bar ); 162 } 163 } 164 165 form_security_purge( 'plugin_Example_config_update' ); 166 print_successful_redirect( plugin_page( 'foo', true ) ); 167 </programlisting> 168 </sect2> 169 170 <sect2 id="dev.plugins.building.source.foo.php"> 171 <title>Example/page/foo.php</title> 172 173 <programlisting><filename>Example/pages/foo.php</filename> 174 <?php 175 echo '<p>Here is a link to <a href="', plugin_page( 'foo' ), '">page foo</a>.</p>'; 176 '<link rel="stylesheet" type="text/css" href="', plugin_file( 'foo.css' ), '"/>', 177 '<p class="foo">'; 178 179 event_signal( 'EVENT_EXAMPLE_FOO' ); 180 181 $t_string = 'A sentence with the word "foo" in it.'; 182 $t_new_string = event_signal( 'EVENT_EXAMPLE_BAR', array( $t_string ) ); 183 184 echo $t_new_string, '</p>'; 185 </programlisting> 186 </sect2> 187 </sect1>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Jul 28 15:48:31 2011 | Cross-referenced by PHPXref 0.7 |