[ Index ]

PHP Cross Reference of MantisBT

title

Body

[close]

/docbook/Developers_Guide/en-US/ -> Plugins_Building_Source.xml (source)

   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  &lt;?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, &lt;= 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  &lt;?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  &lt;?php
 108  
 109  html_page_top( plugin_lang_get( 'configuration' ) );
 110  $t_foo_or_bar = plugin_config_get( 'foo_or_bar' );
 111  
 112  ?&gt;
 113  
 114  &lt;br/&gt;
 115  
 116  &lt;form action="&lt;?php echo plugin_page( 'config_update' ) ?&gt;" method="post"&gt;
 117  &lt;?php echo form_security_field( 'plugin_Example_config_update' ) ?&gt;
 118  &lt;table class="width60"&gt;
 119  
 120  &lt;tr&gt;
 121      &lt;td class="form-title" rowspan="2"&gt;&lt;?php echo plugin_lang_get( 'configuration' ) ?&gt;&lt;/td&gt;
 122  &lt;/tr&gt;
 123  
 124  &lt;tr &lt;?php echo helper_alternate_class() ?&gt;&gt;
 125      &lt;td class="category"&gt;&lt;php echo plugin_lang_get( 'foo_or_bar' ) ?&gt;&lt;/td&gt;
 126      &lt;td&gt;&lt;input name="foo_or_bar" value="&lt;?php echo string_attribute( $t_foo_or_bar ) ?&gt;"/&gt;&lt;/td&gt;
 127  &lt;/tr&gt;
 128  
 129  &lt;tr &lt;?php echo helper_alternate_class() ?&gt;&gt;
 130      &lt;td class="category"&gt;&lt;php echo plugin_lang_get( 'reset' ) ?&gt;&lt;/td&gt;
 131      &lt;td&gt;&lt;input type="checkbox" name="reset"/&gt;&lt;/td&gt;
 132  &lt;/tr&gt;
 133  
 134  &lt;tr&gt;
 135      &lt;td class="center" rowspan="2"&gt;&lt;input type="submit"/&gt;&lt;/td&gt;
 136  &lt;/tr&gt;
 137  
 138  &lt;/table&gt;
 139  &lt;/form&gt;
 140  
 141  &lt;?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  &lt;?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  &lt;?php
 175  echo '&lt;p&gt;Here is a link to &lt;a href="', plugin_page( 'foo' ), '">page foo&lt;/a&gt;.&lt;/p&gt;';
 176       '&lt;link rel="stylesheet" type="text/css" href="', plugin_file( 'foo.css' ), '"/&gt;',
 177       '&lt;p class="foo"&gt;';
 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, '&lt;/p&gt;';
 185          </programlisting>
 186      </sect2>
 187  </sect1>


Generated: Thu Jul 28 15:48:31 2011 Cross-referenced by PHPXref 0.7