/
Plugins_Building_Source.xml
189 lines (149 loc) · 5.42 KB
/
Plugins_Building_Source.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<?xml version='1.0' encoding='utf-8' ?>
<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
<!ENTITY % BOOK_ENTITIES SYSTEM "Developers_Guide.ent">
%BOOK_ENTITIES;
]>
<section id="dev.plugins.building.source">
<title>Example Plugin Source Listing</title>
<para>
The code in this section, for the Example plugin, is available for use,
modification, and redistribution without any restrictions and without any
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>
<section id="dev.plugins.building.source.Example.php">
<title>Example/Example.php</title>
<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
'MantisCore' => '2.0', # 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>
</section>
<section 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>
</section>
<section 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>
</section>
<section id="dev.plugins.building.source.configpage.php">
<title>Example/page/config_page.php</title>
<programlisting><filename>Example/pages/config_page.php</filename>
<?php
layout_page_header( plugin_lang_get( 'configuration' ) );
layout_page_begin();
$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">
<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
layout_page_end();
</programlisting>
</section>
<section 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>
</section>
<section 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>
</section>
</section>