PostgreSQL should now work as a db prefs backend (and fix alterable field names)
[squirrelmail.git] / doc / plugin.txt
CommitLineData
99098885 1$Id$
2
3It is best if you check out the SquirrelMail development FAQ for more
4information. This document may be obsoleted at some point in the future (or
5maybe we'll write a script to get the wiki contents and dump them in here
6automatically).
7
8FAQ -> http://www.squirrelmail.org/wiki/wiki.php?DeveloperFAQ
9Plugin Hooks -> http://www.squirrelmail.org/wiki/wiki.php?DevelopingPlugins
10
11
1aaef171 12A FEW NOTES ON THE PLUGIN ARCHITECTURE
13======================================
14
97ca984f 15The plugin architecture of SquirrelMail is designed to make it possible to
16add new features without having to patch SquirrelMail itself. Functionality
17like password changing, displaying ads and calendars should be possible to
18add as plugins.
1aaef171 19
20
21The idea
22--------
23
24The idea is to be able to run random code at given places in the
25SquirrelMail code. This random code should then be able to do whatever
26needed to enhance the functionality of SquirrelMail. The places where
27code can be executed are called "hooks".
28
29There are some limitations in what these hooks can do. It is difficult
30to use them to change the layout and to change functionality that
31already is in SquirrelMail.
32
33Some way for the plugins to interact with the help subsystem and
34translations will be provided.
35
36
37The implementation
38------------------
39
40In the main SquirrelMail files the file functions/plugin.php. In
41places where hooks are made available they are executed by calling the
97ca984f 42function do_hook('hookname').
1aaef171 43
97ca984f 44The do_hook traverses the array $squirrelmail_plugin_hooks['hookname']
1aaef171 45and executes all the functions that are named in that array.
46
47A plugin must reside in a subdirectory in the plugins/ directory. The
48name of the subdirectory is considered the name of the plugin.
49
50To start using a plugin, its name must be added to the $plugins array
51in config.php like this:
52
97ca984f 53 $plugins[0] = 'plugin_name';
1aaef171 54
55When a plugin is registered the file plugins/plugin_name/setup.php is
56included and the function squirrelmail_plugin_init_plugin_name is
57called with no parameters.
58
59
60Writing plugins
61---------------
62
63A plugin must consist of at least a file called setup.php. All other
64files the plugin consist of should also be in the plugin directory.
65
66The function squirrelmail_plugin_init_plugin_name is called to
67initalize a plugin. This function could look something like this:
68
69function squirrelmail_plugin_init_demo () {
70 global $squirrelmail_plugin_hooks;
71
97ca984f 72 $squirrelmail_plugin_hooks['generic_header']['demo'] = 'plugin_demo_header';
73 $squirrelmail_plugin_hooks['menuline']['demo'] = 'plugin_demo_menuline';
1aaef171 74}
75
76Note that the SquirrelMail files assume that all other SquirrelMail
77files are available as ../directory/file. This means that if some file
97ca984f 78in the plugin directory is requested, it must do a chdir('..') before
1aaef171 79including any of the standard SquirrelMail files.
6b638171 80
81
a3a95e4a 82Hook Data Passed
83----------------
84Hooks, when executed, are called with one parameter, an array of data
85that is passed to the hook. The first element in the array is the name
86of the hook that is being called. Any other elements in the array are
87dependant on the type of hook that is being called.
88
89Some of the information in the array may be changed. By default, the
90plugins should never change data unless it is documented otherwise.
91
92
6b638171 93List of hooks
94-------------
ef3c69f0 95 generic_header functions/page_header.php
96 menuline functions/page_header.php
97 compose_button_row src/compose.php
98 compose_bottom src/compose.php
b3911477 99 compose_form src/compose.php
0e8c1c9a 100 compose_send src/compose.php
ef3c69f0 101 left_main_before src/left_main.php
102 left_main_after src/left_main.php
103 * options_save src/options.php (see note on options)
104 * options_link_and_description src/options.php (see note on options)
105 * options_highlight_bottom src/options_highlight.php
106 * options_personal_bottom src/options_personal.php
107 * options_personal_inside src/options_personal.php
108 * options_personal_save src/options_personal.php
109 * options_display_bottom src/options_display.php
110 * options_display_inside src/options_display.php
3751dc7f 111 * options_display_save src/options_display.php
ef3c69f0 112 * options_folders_bottom src/options_folders.php
113 * options_folders_inside src/options_folders.php
114 * options_folders_save src/options_folders.php
0f101579 115 & options_identities_process src/options_identities.php
116 & options_identities_top src/options_identities.php
117 & options_identities_renumber src/options_identities.php (multiple places)
118 & options_identities_table src/options_identities.php
119 & options_identities_buttons src/options_identities.php
ef3c69f0 120 logout src/signout.php
cf6df86f 121 logout_above_text src/signout.php
ef3c69f0 122 login_before src/webmail.php
123 login_verified src/webmail.php
124 loading_prefs src/load_prefs.php
125 mailbox_index_before functions/mailbox_display.php
126 mailbox_index_after functions/mailbox_display.php
3751dc7f 127 mailbox_form_before functions/mailbox_display.php
1ffd5e31 128 subject_link functions/mailbox_display.php
99098885 129 motd src/right_main.php
ef3c69f0 130 right_main_after_header src/right_main.php
131 right_main_bottom src/right_main.php
132 login_top src/login.php
133 login_bottom src/login.php
441f2d33 134 html_top src/read_body.php
ef3c69f0 135 read_body_top src/read_body.php
136 read_body_bottom src/read_body.php
441f2d33 137 html_bottom src/read_body.php
7137f80f 138 read_body_header src/read_body.php
9736fafe 139 read_body_header_right src/read_body.php
ef3c69f0 140 search_before_form src/search.php
141 search_after_form src/search.php
142 search_bottom src/search.php
143 help_top src/help.php
144 help_bottom src/help.php
145 help_chapter src/help.php
3937dc89 146 addrbook_html_search_below src/addrbook_search_html.php
ef3c69f0 147 addressbook_bottom src/addressbook.php
a3a95e4a 148 ^ attachment $type0/$type1 functions/mime.php (see note on attachments)
149
ef3c69f0 150(*) Options
151-----------
152There are two ways to do options for your plugin. First, you can incorporate it
153into an existing section of the preferences (Display, Personal, or Folders).
154The second way, you create your own section that they can choose from and it
155displays its own range of options.
156
157
158First: Integrating into existing options
159-----------------------------------------
160There are two hooks you need to use for this one:
161
1621. options_YOUCHOOSE_inside
163 This is the code that goes inside the table for the section you choose. Since
164 it is going inside an existing table, it must be in this form:
165 ------cut here-------
166 <tr>
167 <td>
168 OPTION_NAME
169 </td>
170 <td>
171 OPTION_INPUT
172 </td>
173 </tr>
174 ------cut here-------
175
1762. options_YOUCHOOSE_save
177 This is the code that saves your preferences into the users' preference
178 file. For an example of how to do this, see src/options.php.
179
180
181Second: Create your own section
182-------------------------------
6b638171 183It is possible to create your own options sections with plugins. There are
184three hooks you will need to use.
185
1861. options_link_and_description
1e63b430 187 This creates the link and has a description that is shown on the options
57945c53 188 page. This should output HTML that looks like this. Make sure to read
1e63b430 189 the section on outputing your own pages.
6b638171 190
191 -----cut here-----
57945c53 192 function my_plugin_name_my_function() {
6b638171 193 global $color
194 ?>
195 <table width=50% cellpadding=3 cellspacing=0 border=0 align=center>
196 <tr>
97ca984f 197 <td bgcolor="<?php echo $color[9] ?>">
6b638171 198 <a href="../plugins/YOUR_PLUGIN/YOUR_OPTIONS.php">YOUR OPTIONS NAME</a>
199 </td>
200 </tr>
201 <tr>
97ca984f 202 <td bgcolor="<?php echo $color[0] ?>">
6b638171 203 YOUR DESCRIPTION
204 </td>
205 </tr>
206 </table>
207 <?php
208 }
209 -----cut here-----
210
2112. options_save
212 Here is the code that you need to do to save your options in the
213 preference files or manipulate whatever data you are trying to change
214 through the options section. You can look at options.php for details
215 on how this is to be done.
216
2173. loading_prefs (optional)
218 If you are wanting to save preferences to the preference files, then
219 you need to do this step as well. Otherwise if you are manipulating
220 other data, ignore this step.
221
222 You should put the code in here that loads your preferences back
223 into usable variables. Examples of this can be found in the file
224 src/load_prefs.php
a3a95e4a 225
226
0f101579 227(&) Identity Hooks
228------------------
229Some hooks are passed special information in the array of arguments. See
230the SpamCop plugin for how to use them.
231
232options_identities_process
233 [0] = Hook's name
234 [1] = Should I run the SaveUpdateFunction() (alterable)
235
236options_identities_renumber
237 [0] = Hook's name
238 [1] = Renumber it from ('default' or 1 through # idents - 1)
239 [2] = Renumber it to (same thing)
240
241options_identities_table
242 [0] = Hook's name
243 [1] = Color of table (use it like <tr<?PHP echo $Info[1]?>> in your
244 plugin)
245 [2] = Is this an empty section?
246 [3] = What is the 'post' value?
247
248options_identities_buttons
249 [0] = Hook's name
250 [1] = Is this an empty section (the one at the end of the list)?
251 [2] = What is the 'post' value?
252
253
a3a95e4a 254(^) Attachment Hooks
255--------------------
256When a message has attachments, this hook is called with the MIME types. For
257instance, a .zip file hook is "attachment application/x-zip". The hook should
258probably show a link to do a specific action, such as "Verify" or "View" for a
259.zip file.
260
261This is a breakdown of the data passed in the array to the hook that is called:
262
263 [0] = Hook's name ('attachment text/plain')
264 [1] = Array of links of actions (more below) (Alterable)
265 [2] = Used for returning to mail message (startMessage)
266 [3] = Used for finding message to display (id)
267 [4] = Mailbox name, urlencode()'d (urlMailbox)
268 [5] = Entity ID inside mail message (ent)
269 [6] = Default URL to go to when filename is clicked on (Alterable)
ef30bf50 270 [7] = Filename that is displayed for the attachment
271 [8] = Sent if message was found from a search (where)
272 [9] = Sent if message was found from a search (what)
a3a95e4a 273
274To set up links for actions, you assign them like this:
275
276 $Args[1]['your_plugin_name']['href'] = 'URL to link to';
277 $Args[1]['your_plugin_name']['text'] = 'What to display';
441f2d33 278
ae2f65a9 279It's also possible to specify a hook as "attachment type0/*",
280for example "attachment text/*". This hook will be executed whenever there's
281no more specific rule available for that type.
282
57945c53 283
284Outputting Your Own Pages
285-------------------------
286
287Often, when you want to provide your own customized options screen or create
288another web page instead of just using standard hooks, you will be creating
289your own .php files. An example of this is the attachment_common plugin's
290image.php file.
291
292To make sure that security is maintained and standards are followed, the top
293of your PHP script should look very similar to this:
294
295 <?PHP
296 /* This is my php file.
297 * description goes here.
298 */
299
300 chdir('..');
301 include('../src/validate.php');
302
303The validate.php script will include internationalization support,
304config.php variables, strings.php functions, and also authenticate that the
1e63b430 305user is truly logged in. validate.php also calls stripslashes() on incoming
57945c53 306data (if gpc_magic_quotes() is on). You should never need to worry about
307that stuff again. As a warning, this has only really been ironed out in
3081.1.1. If you create/modify a plugin to follow these rules, you must
309mention that it requires SquirrelMail 1.1.1 or later.
310
311After that, if you need further functions, just use
312
313 include('../functions/filename.php');
314
315in your script. Since 1.0.5, it was no longer necessary (nor recommended)
316to use the "if (! isset($filename_php))" syntax.