Tweak the LSUB INBOX regexp to allow for only 1 space between LSUB and
[squirrelmail.git] / doc / plugin.txt
CommitLineData
99098885 1$Id$
2
9cd2ae7d 3In addition to this document, please check out the SquirrelMail
4development FAQ for more information. Also, help writing plugins
5is easily obtained by posting to the squirrelmail-plugins mailing
b2978b37 6list. (See details about mailing lists on the website)
99098885 7
8FAQ -> http://www.squirrelmail.org/wiki/wiki.php?DeveloperFAQ
9cd2ae7d 9Plugin Development ->
10 http://www.squirrelmail.org/wiki/wiki.php?DevelopingPlugins
99098885 11
12
1aaef171 13A FEW NOTES ON THE PLUGIN ARCHITECTURE
14======================================
15
9cd2ae7d 16The plugin architecture of SquirrelMail is designed to make it possible
17to add new features without having to patch SquirrelMail itself.
18Functionality like password changing, displaying ads and calendars should
19be possible to add as plugins.
1aaef171 20
21
9cd2ae7d 22The Idea
1aaef171 23--------
24
25The idea is to be able to run random code at given places in the
26SquirrelMail code. This random code should then be able to do whatever
27needed to enhance the functionality of SquirrelMail. The places where
28code can be executed are called "hooks".
29
30There are some limitations in what these hooks can do. It is difficult
31to use them to change the layout and to change functionality that
32already is in SquirrelMail.
33
34Some way for the plugins to interact with the help subsystem and
35translations will be provided.
36
37
9cd2ae7d 38The Implementation
1aaef171 39------------------
40
9cd2ae7d 41The plugin jumping off point in the main SquirrelMail code is in the
42file functions/plugin.php. In places where hooks are made available,
43they are executed by calling the function do_hook('hookname'). The
44do_hook function then traverses the array
45$squirrelmail_plugin_hooks['hookname'] and executes all the functions
46that are named in that array. Those functions are placed there when
47plugins register themselves with SquirrelMail as discussed below. A
48plugin may add its own internal functions to this array under any
49hook name provided by the SquirrelMail developers.
1aaef171 50
51A plugin must reside in a subdirectory in the plugins/ directory. The
9cd2ae7d 52name of the subdirectory is considered to be the name of the plugin.
53(The plugin will not function correctly if this is not the case.)
1aaef171 54
55To start using a plugin, its name must be added to the $plugins array
56in config.php like this:
57
9cd2ae7d 58 $plugins[0] = 'plugin_name';
1aaef171 59
9cd2ae7d 60When a plugin is registered, the file plugins/plugin_name/setup.php is
61included and the function squirrelmail_plugin_init_plugin_name() is
62called with no parameters. That function is where the plugin may
63register itself against any hooks it wishes to take advantage of.
1aaef171 64
65
9cd2ae7d 66WRITING PLUGINS
67===============
68
69All plugins must contain a file called setup.php and must include a
70function called squirrelmail_plugin_init_plugin_name() therein. Since
71including numerous plugins can slow SquirrelMail performance
72considerably, the setup.php file should contain little else. Any
73functions that are registered against plugin hooks should do little
74more than call another function in a different file.
75
76Any other files used by the plugin should also be placed in the
77plugin directory (or subdirectory thereof) and should contain the
78bulk of the plugin logic.
1aaef171 79
9cd2ae7d 80The function squirrelmail_plugin_init_plugin_name() is called to
81initalize a plugin. This function could look something like this (if
82the plugin was named "demo" and resided in the directory plugins/demo/):
1aaef171 83
9cd2ae7d 84function squirrelmail_plugin_init_demo ()
85{
86 global $squirrelmail_plugin_hooks;
1aaef171 87
9cd2ae7d 88 $squirrelmail_plugin_hooks['generic_header']['demo'] = 'plugin_demo_header';
89 $squirrelmail_plugin_hooks['menuline']['demo'] = 'plugin_demo_menuline';
90}
91
92Please note that as of SquirrelMail 1.5.0, this function will no longer
93be called at run time and will instead be called only once at configure-
94time. Thus, the inclusion of any dynamic code (anything except hook
95registration) here is strongly discouraged.
1aaef171 96
9cd2ae7d 97In this example, the "demo" plugin should also have two other functions
98in its setup.php file called plugin_demo_header() and plugin_demo_menuline().
99The first of these might look something like this:
100
101function plugin_demo_header()
102{
103 include_once(SM_PATH . 'plugins/demo/functions.php');
104 plugin_demo_header_do();
1aaef171 105}
106
9cd2ae7d 107The function called plugin_demo_header_do() would be in the file called
108functions.php in the demo plugin directory and would contain the plugin's
109core logic for the "generic_header" hook.
110
111
112Including Other Files
113---------------------
114
115A plugin may need to reference functionality provided in other
116files, and therefore need to include those files. Most of the
117core SquirrelMail functions are already available to your plugin
118unless it has any files that are requested directly by the client
119browser (custom options page, etc.). In this case, you'll need
120to make sure you include the files you need (see below).
121
122Note that as of SquirrelMail 1.4.0, all files are accessed using a
123constant called SM_PATH that always contains the relative path to
124the main SquirrelMail directory. This constant is always available
125for you to use when including other files from the SquirrelMail core,
126your own plugin, or other plugins, should the need arise. If any of
127your plugin files are requested directly from the client browser,
128you will need to define this constant before you do anything else:
129
130 define('SM_PATH', '../../');
131
132Files are included like this:
133
134 include_once(SM_PATH . 'include/validate.php');
135
136When including files, please make sure to use the include_once() function
137and NOT include(), require(), or require_once(), since these all are much
138less efficient than include_once() and can have a cumulative effect on
139SquirrelMail performance.
140
141The files that you may need to include in a plugin will vary greatly
142depending upon what the plugin is designed to do. For files that are
143requested directly by the client browser, we strongly recommend that
144you include the file include/validate.php, since it will set up the
145SquirrelMail environment automatically. It will ensure the the user
146has been authenticated and is currently logged in, load all user
147preferences, include internationalization support, call stripslashes()
148on all incoming data (if magic_quotes_gpc is on), and initialize and
149include all other basic SquirrelMail resources and functions. You may
150see other plugins that directly include other SquirrelMail files, but
151that is no longer necessary and is a hold-over from older SquirrelMail
152versions.
6b638171 153
154
9cd2ae7d 155Hook Types: Parameters and Return Values
156-----------------------------------------
157
f4fd89e0 158Hooks, when executed, are called with differing parameters and may or may
159not take return values, all depending on the type of hook being called and
160the context in which it is being used. On the source side (where the hook
161call originates), all hooks have at least one parameter, which is the
162name of the hook. After that, things get complicated.
163
164 do_hook
165 -------
166 Most hook calls don't pass any data and don't ask for anything back.
167 These always use the do_hook call. A limited number of do_hook calls do
168 pass some extra parameters, in which case your plugin may modify the
169 given data if you do so by reference. It is not necessary to return
170 anything from your function in such a case; modifying the parameter
171 data by reference is what does the job (although the hook call itself
172 (in the source) must grab the return value for this to work). Note
173 that in this case, the parameter to your hook function will be an array,
174 the first element simply being the hook name, followed by any other
175 parameters that may have been included in the actual hook call in the
176 source. Modify parameters with care!
177
178 do_hook_function
179 ----------------
180 This hook type was intended to be the main hook type used when the
181 source needs to get something back from your plugin. It is somewhat
182 limited in that it will only use the value returned from the LAST
183 plugin registered against the hook. The source for this hook might
184 use the return value for internal purposes, or might expect you to
185 provide text or HTML to be sent to the client browser (you'll have to
186 look at its use in context to understand how you should return values
187 here). The parameters that your hook function gets will be anything
188 you see AFTER the hook name in the actual hook call in the source.
189 These cannot be changed in the same way that the do_hook parameters
190 can be.
191
192 concat_hook_function
193 --------------------
194 This is a newer hook type meant to address the shortcomings of
195 do_hook_function; specifically in that it uses the return values of
196 all plugins registered against the hook. In order to do so, the
197 return value is assumed to be a string, which is just piled on top
198 of whatever it got from the other plugins working on the same hook.
199 Again, you'll have to inspect the source code to see how such data
200 is put to use, but most of the time, it is used to create a string
201 of HTML to be inserted into the output page. The parameters that
202 your hook function will get are the same as for the do_hook_function;
203 they are anything AFTER the hook name in the actual hook call in the
204 source.
205
efea59ed 206 boolean_hook_function
207 ---------------------
f4fd89e0 208 The newest of the SquirrelMail hooks, this type is used to let all
209 plugins registered against the hook to "vote" for some action. What
210 that action is is entirely dependent on how the hook is used in the
211 source (look for yourself). Plugins make their "vote" by returning
212 TRUE or FALSE. This hook may be configured to "tally votes" in one
213 of three ways. This configuration is done with the third parameter
214 in the hook call in the source:
215 > 0 -- Any one or more TRUEs will override any FALSEs
216 < 0 -- Any one or more FALSEs will override any TRUEs
217 = 0 -- Majority wins. Ties are broken in this case with
218 the last parameter in the hook call in the source.
219 Your hook function will get the second paramter in the hook call in
220 the source as its parameter (this might be an array if multiple values
221 need to be passed).
a3a95e4a 222
f4fd89e0 223See below for further discussion of special hook types and the values
a3a95e4a 224
225
9cd2ae7d 226List of Hooks
6b638171 227-------------
ef3c69f0 228
9cd2ae7d 229This is a list of all hooks currently available in SquirrelMail, ordered
230by file. Note that this list is accurate as of June 17, 2003 (should be
231close to what is contained in release 1.4.1, plus or minus a hook or two),
232but may be out of date soon thereafter. You never know. ;-)
6b638171 233
9cd2ae7d 234 Hook Name Found In Called With(#)
235 --------- -------- --------------
236 loading_constants functions/constants.php do_hook
54067ccd 237 logout_error functions/display_messages.php do_hook
238 error_box functions/display_messages.php concat_hook
9cd2ae7d 239 get_pref_override functions/file_prefs.php hook_func
240 get_pref functions/file_prefs.php hook_func
241 special_mailbox functions/imap_mailbox.php hook_func
242 % rename_or_delete_folder functions/imap_mailbox.php hook_func
9cd2ae7d 243 mailbox_index_before functions/mailbox_display.php do_hook
244 mailbox_form_before functions/mailbox_display.php do_hook
245 mailbox_index_after functions/mailbox_display.php do_hook
246 check_handleAsSent_result functions/mailbox_display.php do_hook
247 subject_link functions/mailbox_display.php concat_hook
c5aaf57f 248 mailbox_display_buttons functions/mailbox_display.php do_hook
9cd2ae7d 249 message_body functions/mime.php do_hook
250 ^ attachment $type0/$type1 functions/mime.php do_hook
9ad17edb 251 attachments_bottom functions/mime.php hook_func
c4115032 252 decode_body functions/mime.php hook_func
9cd2ae7d 253 generic_header functions/page_header.php do_hook
254 menuline functions/page_header.php do_hook
c5aaf57f 255 internal_link functions/page_header.php hook_func
9cd2ae7d 256 loading_prefs include/load_prefs.php do_hook
257 addrbook_html_search_below src/addrbook_search_html.php do_hook
258 addressbook_bottom src/addressbook.php do_hook
259 compose_form src/compose.php do_hook
260 compose_bottom src/compose.php do_hook
261 compose_button_row src/compose.php do_hook
262 compose_send src/compose.php do_hook
263 folders_bottom src/folders.php do_hook
264 help_top src/help.php do_hook
265 help_chapter src/help.php do_hook
266 help_bottom src/help.php do_hook
7022cc97 267 left_main_after_each_folder src/left_main.php concat_hook
9cd2ae7d 268 left_main_before src/left_main.php do_hook
269 left_main_after src/left_main.php do_hook
270 login_cookie src/login.php do_hook
271 login_top src/login.php do_hook
272 login_form src/login.php do_hook
273 login_bottom src/login.php do_hook
274 move_before_move src/move_messages.php do_hook
c5aaf57f 275 move_messages_button_action src/move_messages.php concat_hook
9cd2ae7d 276 * optpage_set_loadinfo src/options.php do_hook
277 * optpage_loadhook_personal src/options.php do_hook
278 * optpage_loadhook_display src/options.php do_hook
279 * optpage_loadhook_highlight src/options.php do_hook
280 * optpage_loadhook_folder src/options.php do_hook
281 * optpage_loadhook_order src/options.php do_hook
282 * options_personal_save src/options.php do_hook
283 * options_display_save src/options.php do_hook
284 * options_folder_save src/options.php do_hook
285 * options_save src/options.php do_hook
286 * optpage_register_block src/options.php do_hook
287 * options_link_and_description src/options.php do_hook
288 * options_personal_inside src/options.php do_hook
289 * options_display_inside src/options.php do_hook
290 * options_highlight_inside src/options.php do_hook
291 * options_folder_inside src/options.php do_hook
292 * options_order_inside src/options.php do_hook
293 * options_personal_bottom src/options.php do_hook
294 * options_display_bottom src/options.php do_hook
295 * options_highlight_bottom src/options.php do_hook
296 * options_folder_bottom src/options.php do_hook
297 * options_order_bottom src/options.php do_hook
298 * options_highlight_bottom src/options_highlight.php do_hook
299 & options_identities_process src/options_identities.php do_hook
300 & options_identities_top src/options_identities.php do_hook
301 &% options_identities_renumber src/options_identities.php do_hook
302 & options_identities_table src/options_identities.php concat_hook
303 & options_identities_buttons src/options_identities.php concat_hook
304 message_body src/printer_friendly_bottom.php do_hook
305 read_body_header src/read_body.php do_hook
306 read_body_menu_top src/read_body.php do_hook
307 read_body_menu_bottom src/read_body.php do_hook
308 read_body_header_right src/read_body.php do_hook
309 html_top src/read_body.php do_hook
310 read_body_top src/read_body.php do_hook
311 read_body_bottom src/read_body.php do_hook
312 html_bottom src/read_body.php do_hook
313 login_before src/redirect.php do_hook
314 login_verified src/redirect.php do_hook
315 generic_header src/right_main.php do_hook
316 right_main_after_header src/right_main.php do_hook
317 right_main_bottom src/right_main.php do_hook
318 search_before_form src/search.php do_hook
319 search_after_form src/search.php do_hook
320 search_bottom src/search.php do_hook
321 logout src/signout.php do_hook
322 webmail_top src/webmail.php do_hook
323 webmail_bottom src/webmail.php do_hook
324 logout_above_text src/signout.php concat_hook
325
326% = This hook is used in multiple places in the given file
327# = Called with hook type (see below)
328& = Special identity hooks (see below)
329^ = Special attachments hook (see below)
330* = Special options hooks (see below)
6b638171 331
6b638171 332
9cd2ae7d 333(#) Called With
334---------------
335Each hook is called using the hook type specified in the list above:
336 do_hook do_hook()
337 hook_func do_hook_function()
338 concat_hook concat_hook_function()
a3a95e4a 339
340
0f101579 341(&) Identity Hooks
342------------------
9cd2ae7d 343This set of hooks is passed special information in the array of arguments:
0f101579 344
345options_identities_process
9cd2ae7d 346
347 This hook is called at the top of the Identities page, which is
348 most useful when the user has changed any identity settings - this
349 is where you'll want to save any custom information you are keeping
350 for each identity or catch any custom submit buttons that you may
351 have added to the identities page. The arguments to this hook are:
352
353 [0] = hook name (always "options_identities_process")
354 [1] = should I run the SaveUpdateFunction() (alterable)
355
356 Obviously, set the second array element to 1/true if you want to
357 trigger SaveUpdateFunction() after the hook is finished - by default,
358 it will not be called.
0f101579 359
360options_identities_renumber
9cd2ae7d 361
362 This hook is called when one of the identities is being renumbered,
363 such as if the user had three identities and deletes the second -
364 this hook would be called with an array that looks like this:
365 ('options_identities_renumber', 2, 1). The arguments to this hook
366 are:
367
368 [0] = hook name (always "options_identities_renumber")
369 [1] = being renumbered from ('default' or 1 through (# idents) - 1)
370 [2] = being renumbered to ('default' or 1 through (# idents) - 1)
0f101579 371
372options_identities_table
9cd2ae7d 373
374 This hook allows you to insert additional rows into the table that
375 holds each identity. The arguments to this hook are:
376
377 [0] = color of table (use it like this in your plugin:
378 <tr bgcolor="<?PHP echo $info[1]?>">
379 [1] = is this an empty section (the one at the end of the list)?
380 [2] = what is the 'post' value? (ident # or empty string if default)
381
382 You need to return any HTML you would like to add to the table.
383 You could add a table row with code similar to this:
384
385 function demo_identities_table(&$args)
386 {
387 return '<tr bgcolor="' . $args[0] . '"><td>&nbsp;</td><td>'
388 . 'YOUR CODE HERE' . '</td></tr>' . "\n";
389 }
0f101579 390
391options_identities_buttons
9cd2ae7d 392
393 This hook allows you to add a button (or other HTML) to the row of
394 buttons under each identity. The arguments to this hook are:
395
396 [0] = is this an empty section (the one at the end of the list)?
397 [1] = what is the 'post' value? (ident # or empty string if default)
398
399 You need to return any HTML you would like to add here. You could add
400 a button with code similar to this:
401
402 function demo_identities_button(&$args)
403 {
404 return '<input type="submit" name="demo_button_' . $args[1]
405 . '" value="Press Me">';
406 }
0f101579 407
408
a3a95e4a 409(^) Attachment Hooks
410--------------------
411When a message has attachments, this hook is called with the MIME types. For
412instance, a .zip file hook is "attachment application/x-zip". The hook should
413probably show a link to do a specific action, such as "Verify" or "View" for a
9cd2ae7d 414.zip file. Thus, to register your plugin for .zip attachments, you'd do this
415in setup.php (assuming your plugin is called "demo"):
416
417 $squirrelmail_plugin_hooks['attachment application/x-zip']['demo']
418 = 'demo_handle_zip_attachment';
a3a95e4a 419
420This is a breakdown of the data passed in the array to the hook that is called:
421
422 [0] = Hook's name ('attachment text/plain')
9cd2ae7d 423 [1] = Array of links of actions (see below) (alterable)
a3a95e4a 424 [2] = Used for returning to mail message (startMessage)
425 [3] = Used for finding message to display (id)
426 [4] = Mailbox name, urlencode()'d (urlMailbox)
427 [5] = Entity ID inside mail message (ent)
9cd2ae7d 428 [6] = Default URL to go to when filename is clicked on (alterable)
ef30bf50 429 [7] = Filename that is displayed for the attachment
430 [8] = Sent if message was found from a search (where)
431 [9] = Sent if message was found from a search (what)
a3a95e4a 432
433To set up links for actions, you assign them like this:
434
9cd2ae7d 435 $Args[1]['<plugin_name>']['href'] = 'URL to link to';
436 $Args[1]['<plugin_name>']['text'] = 'What to display';
441f2d33 437
ae2f65a9 438It's also possible to specify a hook as "attachment type0/*",
439for example "attachment text/*". This hook will be executed whenever there's
440no more specific rule available for that type.
441
9cd2ae7d 442Putting all this together, the demo_handle_zip_attachment() function should
443look like this (note the argument being passed):
57945c53 444
9cd2ae7d 445 function demo_handle_zip_attachment(&$Args)
446 {
447 include_once(SM_PATH . 'plugins/demo/functions.php');
448 demo_handle_zip_attachment_do($Args);
449 }
57945c53 450
9cd2ae7d 451And the demo_handle_zip_attachment_do() function in the
452plugins/demo/functions.php file would typically (but not necessarily)
453display a custom link:
454
455 function demo_handle_zip_attachment_do(&$Args)
456 {
457 $Args[1]['demo']['href'] = SM_PATH . 'plugins/demo/zip_handler.php?'
458 . 'passed_id=' . $Args[3] . '&mailbox=' . $Args[4]
459 . '&passed_ent_id=' . $Args[5];
460 $Args[1]['demo']['text'] = 'show zip contents';
461 }
462
463The file plugins/demo/zip_handler.php can now do whatever it needs with the
464attachment (note that this will hand information about how to retrieve the
465source message from the IMAP server as GET varibles).
466
467
468(*) Options
469-----------
470Before you start adding user preferences to your plugin, please take a moment
471to think about it: in some cases, more options may not be a good thing.
472Having too many options can be confusing. Thinking from the user's
473perspective, will the proposed options actually be used? Will users
474understand what these options are for?
475
476There are two ways to add options for your plugin. When you only have a few
477options that don't merit an entirely new preferences page, you can incorporate
478them into an existing section of SquirrelMail preferences (Personal
479Information, Display Preferences, Message Highlighting, Folder Preferences or
480Index Order). Or, if you have an extensive number of settings or for some
481reason need a separate page for the user to interact with, you can create your
482own preferences page.
483
484
485Integrating Your Options Into Existing SquirrelMail Preferences Pages
486---------------------------------------------------------------------
487
488There are two ways to accomplish the integration of your plugin's settings
489into another preferences page. The first method is to add the HTML code
490for your options directly to the preferences page of your choice. Although
491currently very popular, this method will soon be deprecated, so avoid it
492if you can. That said, here is how it works. :) Look for any of the hooks
493named as "options_<pref page>_inside", where <pref page> is "display",
494"personal", etc. For this example, we'll use "options_display_inside" and,
495as above, "demo" as our plugin name:
496
497 1. In setup.php in the squirrelmail_plugin_init_demo() function:
498
499 $squirrelmail_plugin_hooks['options_display_inside']['demo']
500 = 'demo_show_options';
501
502 Note that there are also hooks such as "options_display_bottom",
503 however, they place your options at the bottom of the preferences
504 page, which is usually not desirable (mostly because they also
505 come AFTER the HTML FORM tag is already closed). It is possible
506 to use these hooks if you want to create your own FORM with custom
507 submission logic.
508
509 2. Assuming the function demo_show_options() calls another function
510 elsewhere called demo_show_options_do(), that function should have
511 output similar to this (note that you will be inserting code into
512 a table that is already defined with two columns, so please be sure
513 to keep this framework in your plugin):
514
515 ------cut here-------
516 <tr>
517 <td>
518 OPTION_NAME
519 </td>
520 <td>
521 OPTION_INPUT
522 </td>
523 </tr>
524 ------cut here-------
525
526 Of course, you can place any text where OPTION_NAME is and any input
527 tags where OPTION_INPUT is.
528
529 3. You will want to use the "options_<pref page>_save" hook (in this case,
530 "options_display_save") to save the user's settings after they have
531 pressed the "Submit" button. Again, back in setup.php in the
532 squirrelmail_plugin_init_demo() function:
57945c53 533
9cd2ae7d 534 $squirrelmail_plugin_hooks['options_display_save']['demo']
535 = 'demo_save_options';
57945c53 536
9cd2ae7d 537 4. Assuming the function demo_save_options() calls another function
538 elsewhere called demo_save_options_do(), that function should put
539 the user's settings into permanent storage (see the preferences
540 section below for more information). This example assumes that
541 in the preferences page, the INPUT tag's NAME attribute was set
542 to "demo_option":
543
544 global $data_dir, $username;
545 sqgetGlobalVar('demo_option', $demo_option);
546 setPref($data_dir, $username, 'demo_option', $demo_option);
547
548
549The second way to add options to one of the SquirrelMail preferences page is
550to use one of the "optpage_loadhook_<pref page>" hooks. The sent_subfolders
551plugin is an excellent example of this method. Briefly, this way of adding
552options consists of adding some plugin-specific information to a predefined
553data structure which SquirrelMail then uses to build the HTML input forms
554for you. This is the preferred method of building options lists going forward.
555
556 1. We'll use the "optpage_loadhook_display" hook to add a new group of
557 options to the display preferences page. In setup.php in the
558 squirrelmail_plugin_init_demo() function:
559
560 $squirrelmail_plugin_hooks['optpage_loadhook_display']['demo']
561 = 'demo_options';
562
563 2. Assuming the function demo_options() calls another function elsewhere
564 called demo_options_do(), that function needs to add a new key to two
565 arrays, $optpage_data['grps'] and $optpage_data['vals']. The value
566 associated with that key should simply be a section heading for your
567 plugin on the preferences page for the $optpage_data['grps'] array,
568 and yet another array with all of your plugin's options for the
569 $optpage_data['vals'] array. The options are built as arrays (yes,
570 that's four levels of nested arrays) that specify attributes that are
571 used by SquirrelMail to build your HTML input tags automatically.
572 This example includes just one input element, a SELECT (drop-down)
573 list:
574
575 global $optpage_data;
576 $optpage_data['grps']['DEMO_PLUGIN'] = 'Demo Options';
577 $optionValues = array();
578 $optionValues[] = array(
579 'name' => 'plugin_demo_favorite_color',
580 'caption' => 'Please Choose Your Favorite Color',
581 'type' => SMOPT_TYPE_STRLIST,
582 'refresh' => SMOPT_REFRESH_ALL,
583 'posvals' => array(0 => 'red',
584 1 => 'blue',
585 2 => 'green',
586 3 => 'orange'),
587 'save' => 'save_plugin_demo_favorite_color'
588 );
589 $optpage_data['vals']['DEMO_PLUGIN'] = $optionValues;
590
591 The array that you use to specify each plugin option has the following
592 possible attributes:
593
6976aad7 594 name The name of this setting, which is used not only for
595 the INPUT tag name, but also for the name of this
596 setting in the user's preferences
597 caption The text that prefaces this setting on the preferences
598 page
599 type The type of INPUT element, which should be one of:
600 SMOPT_TYPE_STRING String/text input
601 SMOPT_TYPE_STRLIST Select list input
602 SMOPT_TYPE_TEXTAREA Text area input
603 SMOPT_TYPE_INTEGER Integer input
604 SMOPT_TYPE_FLOAT Floating point number input
605 SMOPT_TYPE_BOOLEAN Boolean (yes/no radio buttons)
606 input
607 SMOPT_TYPE_HIDDEN Hidden input (not actually
608 shown on preferences page)
609 SMOPT_TYPE_COMMENT Text is shown (specified by the
610 'comment' attribute), but no
611 user input is needed
612 SMOPT_TYPE_FLDRLIST Select list of IMAP folders
613 refresh Indicates if a link should be shown to refresh part or
614 all of the window (optional). Possible values are:
615 SMOPT_REFRESH_NONE No refresh link is shown
616 SMOPT_REFRESH_FOLDERLIST Link is shown to refresh
617 only the folder list
618 SMOPT_REFRESH_ALL Link is shown to refresh
619 the entire window
620 initial_value The value that should initially be placed in this
621 INPUT element
622 posvals For select lists, this should be an associative array,
623 where each key is an actual input value and the
624 corresponding value is what is displayed to the user
625 for that list item in the drop-down list
626 value Specify the default/preselected value for this option
627 input
628 save You may indicate that special functionality needs to be
629 used instead of just saving this setting by giving the
630 name of a function to call when this value would
631 otherwise just be saved in the user's preferences
632 size Specifies the size of certain input items (typically
633 textual inputs). Possible values are:
634 SMOPT_SIZE_TINY
635 SMOPT_SIZE_SMALL
636 SMOPT_SIZE_MEDIUM
637 SMOPT_SIZE_LARGE
638 SMOPT_SIZE_HUGE
639 SMOPT_SIZE_NORMAL
640 comment For SMOPT_TYPE_COMMENT type options, this is the text
641 displayed to the user
642 script This is where you may add any additional javascript
643 or other code to the user input
644 post_script You may specify some script (usually Javascript) that
645 will be placed after (outside of) the INPUT tag.
9cd2ae7d 646
647 3. If you indicated a 'save' attribute for any of your options, you must
648 create that function (you'll only need to do this if you need to do
649 some special processing for one of your settings). The function gets
650 one parameter, which is an object with mostly the same attributes you
651 defined when you made the option above... the 'new_value' (and possibly
652 'value', which is the current value for this setting) is the most useful
653 attribute in this context:
654
655 function save_plugin_demo_favorite_color($option)
656 {
657 // if user chose orange, make note that they are really dumb
658 if ($option->new_value == 3)
659 {
660 // more code here as needed
661 }
662
663 // don't even save this setting if user chose green (old
664 // setting will remain)
665 if ($option->new_value == 2)
666 return;
667
668 // for all other colors, save as normal
669 save_option($option);
670 }
671
672
673Creating Your Own Preferences Page
674----------------------------------
675
676It is also possible to create your own preferences page for a plugin. This
677is particularly useful when your plugin has numerous options or needs to
678offer special interaction with the user (for things such as changing password,
679etc.). Here is an outline of how to do so (again, using the "demo" plugin
680name):
681
682 1. Add a new listing to the main Options page. Older versions of
683 SquirrelMail offered a hook called "options_link_and_description"
684 although its use is deprecated (and it is harder to use in that
685 it requires you to write your own HTML to add the option). Instead,
686 you should always use the "optpage_register_block" hook where you
687 create a simple array that lets SquirrelMail build the HTML
688 to add the plugin options entry automatically. In setup.php in the
689 squirrelmail_plugin_init_demo() function:
690
691 $squirrelmail_plugin_hooks['optpage_register_block']['demo']
692 = 'demo_options_block';
693
694 2. Assuming the function demo_options_block() calls another function
695 elsewhere called demo_options_block_do(), that function only needs
696 to create a simple array and add it to the $optpage_blocks array:
697
698 global $optpage_blocks;
699 $optpage_blocks[] = array(
700 'name' => 'Favorite Color Settings',
701 'url' => SM_PATH . 'plugins/demo/options.php',
702 'desc' => 'Change your favorite color & find new exciting colors',
703 'js' => FALSE
704 );
705
706 The array should have four elements:
707 name The title of the plugin's options as it will be displayed on
708 the Options page
709 url The URI that points to your plugin's custom preferences page
710 desc A description of what the preferences page offers the user,
711 displayed on the Options page below the title
712 js Indicates if this option page requires the client browser
713 to be Javascript-capable. Should be TRUE or FALSE.
714
715 3. There are two different ways to create the actual preferences page
716 itself. One is to simply write all of your own HTML and other
717 interactive functionality, while the other is to define some data
718 structures that allow SquirrelMail to build your user inputs and save
719 your data automatically.
720
721 Building your own page is wide open, and for ideas, you should look at
722 any of the plugins that currently have their own preferences pages. If
723 you do this, make sure to read step number 4 below for information on
724 saving settings. In order to maintain security, consistant look and
725 feel, internationalization support and overall integrity, there are just
726 a few things you should always do in this case: define the SM_PATH
727 constant, include the file include/validate.php (see the section about
728 including other files above) and make a call to place the standard page
729 heading at the top of your preferences page. The top of your PHP file
730 might look something like this:
731
732 define('SM_PATH', '../../');
733 include_once(SM_PATH . 'include/validate.php');
734 global $color;
735 displayPageHeader($color, 'None');
736
737 From here you are on your own, although you are encouraged to do things
738 such as use the $color array to keep your HTML correctly themed, etc.
739
740 If you want SquirrelMail to build your preferences page for you,
741 creating input forms and automatically saving users' settings, then
742 you should change the 'url' attribute in the options block you created
743 in step number 2 above to read as follows:
744
745 'url' => SM_PATH . 'src/options.php?optpage=plugin_demo',
746
747 Now, you will need to use the "optpage_set_loadinfo" hook to tell
748 SquirrelMail about your new preferences page. In setup.php in the
749 squirrelmail_plugin_init_demo() function:
57945c53 750
9cd2ae7d 751 $squirrelmail_plugin_hooks['optpage_set_loadinfo']['demo']
752 = 'demo_optpage_loadinfo';
753
754 Assuming the function demo_optpage_loadinfo() calls another function
755 elsewhere called demo_optpage_loadinfo_do(), that function needs to
756 define values for four variables (make sure you test to see that it
757 is your plugin that is being called by checking the GET variable you
758 added to the url just above):
759
760 global $optpage, $optpage_name, $optpage_file,
761 $optpage_loader, $optpage_loadhook;
762 if ($optpage == 'plugin_demo')
763 {
764 $optpage_name = "Favorite Color Preferences";
765 $optpage_file = SM_PATH . 'plugins/demo/options.php';
766 $optpage_loader = 'load_optpage_data_demo';
767 $optpage_loadhook = 'optpage_loadhook_demo';
768 }
769
770 Now you are ready to build all of your options. In the file you
771 indicated for the variable $optpage_file above, you'll need to create
772 a function named the same as the value you used for $optpage_loader
773 above. In this example, the file plugins/demo/options.php should
774 have at least this function in it:
775
776 function load_optpage_data_demo()
777 {
778 $optpage_data = array();
779 $optpage_data['grps']['DEMO_PLUGIN'] = 'Demo Options';
780 $optionValues = array();
781 $optionValues[] = array(
782 'name' => 'plugin_demo_favorite_color',
783 'caption' => 'Please Choose Your Favorite Color',
784 'type' => SMOPT_TYPE_STRLIST,
785 'refresh' => SMOPT_REFRESH_ALL,
786 'posvals' => array(0 => 'red',
787 1 => 'blue',
788 2 => 'green',
789 3 => 'orange'),
790 'save' => 'save_plugin_demo_favorite_color'
791 );
792 $optpage_data['vals']['DEMO_PLUGIN'] = $optionValues;
793 return $optpage_data;
794 }
795
796 For a detailed description of how you build these options, please read
797 step number 2 for the second method of adding options to an existing
798 preferences page above. Notice that the only difference here is in the
799 very first and last lines of this function where you are actually
800 creating and returning the options array instead of just adding onto it.
801
802 That's all there is to it - SquirrelMail will create a preferences page
803 titled as you indicated for $optpage_name above, and other plugins
804 can even add extra options to this new preferences page. To do so,
805 they should use the hook name you specified for $optpage_loadhook above
806 and use the second method for adding option settings to existing
807 preferences pages described above.
808
809 4. Saving your options settings: if you used the second method in step
810 number 3 above, your settings will be saved automatically (or you can
811 define special functions to save special settings such as the
812 save_plugin_demo_favorite_color() function in the example described
813 above) and there is probably no need to follow this step. If you
814 created your own preferences page from scratch, you'll need to follow
815 this step. First, you need to register your plugin against the
816 "options_save" hook. In setup.php in the squirrelmail_plugin_init_demo()
817 function:
818
819 $squirrelmail_plugin_hooks['options_save']['demo']
820 = 'demo_save_options';
821
822 Assuming the function demo_save_options() calls another function
823 elsewhere called demo_save_options_do(), that function needs to grab
824 all of your POST and/or GET settings values and save them in the user's
825 preferences (for more about preferences, see that section below). Since
826 this is a generic hook called for all custom preferences pages, you
827 should always set "optpage" as a POST or GET variable with a string that
828 uniquely identifies your plugin:
829
830 <input type="hidden" name="optpage" value="plugin_demo">
831
832 Now in your demo_save_options_do() function, do something like this:
833
834 global $username, $data_dir, $optpage, $favorite_color;
835 if ($optpage == 'plugin_demo')
836 {
837 sqgetGlobalVar('favorite_color', $favorite_color, SQ_FORM);
838 setPref($data_dir, $username, 'favorite_color', $favorite_color);
839 }
840
841 Note that $favorite_color may not need to be globalized, although
842 experience has shown that some versions of PHP don't behave as expected
843 unless you do so. Even when you use SquirrelMail's built-in preferences
844 page generation functionality, you may still use this hook, although
845 there should be no need to do so. If you need to do some complex
846 validation routines, note that it might be better to do so in the file
847 you specified as the "$optpage_file" (in our example, that was the
848 plugins/demo/options.php file), since at this point, you can still
849 redisplay your preferences page. You could put code similar to this
850 in the plugins/demp/options.php file (note that there is no function;
851 this code needs to be executed at include time):
852
853 global $optmode;
854 if ($optmode == 'submit')
855 {
856 // do something here such as validation, etc
857 if (you want to redisplay your preferences page)
858 $optmode = '';
859 }
860
861
862Preferences
863-----------
864
865Saving and retrieving user preferences is very easy in SquirrelMail.
866SquirrelMail supports preference storage in files or in a database
867backend, however, the code you need to write to manipulate preferences
868is the same in both cases.
869
870Setting preferences:
871
872 Setting preferences is done for you if you use the built-in facilities
873 for automatic options construction and presentation (see above). If
874 you need to manually set preferences, however, all you need to do is:
875
876 global $data_dir, $username;
877 setPref($data_dir, $username, 'pref_name', $pref_value);
878
879 Where "pref_name" is the key under which the value will be stored
880 and "pref_value" is a variable that should contain the actual
881 preference value to be stored.
882
883Loading preferences:
884
885 There are two approaches to retrieving plugin (or any other) preferences.
886 You can grab individual preferences one at a time or you can add your
887 plugin's preferences to the routine that loads up user preferences at
888 the beginning of each page request. If you do the latter, making sure
889 to place your preference variables into the global scope, they will be
890 immediately available in all other plugin code. To retrieve a single
891 preference value at any time, do this:
892
893 global $data_dir, $username;
894 $pref_value = getPref($data_dir, $username, 'pref_name', 'default value');
895
896 Where "pref_name" is the preference you are retrieving, "default_value"
897 is what will be returned if the preference is not found for this user,
898 and, of course, "pref_value" is the variable that will get the actual
899 preference value.
900
901 To have all your preferences loaded at once when each page request is
902 made, you'll need to register a function against the "loading_prefs" hook.
903 For our "demo" plugin, in setup.php in the squirrelmail_plugin_init_demo()
904 function:
905
906 $squirrelmail_plugin_hooks['loading_prefs']['demo']
907 = 'demo_load_prefs';
908
909 Assuming the function demo_load_prefs() calls another function
910 elsewhere called demo_load_prefs_do(), that function just needs to
911 pull out any all all preferences you'll be needing elsewhere:
912
913 global $data_dir, $username, $pref_value;
914 $pref_value = getPref($data_dir, $username, 'pref_name', 'default value');
915
916 Remember to globalize each preference, or this code is useless.
917
918
919Internationalization
920--------------------
921
922Although this document may only be available in English, we sure hope that you
923are thinking about making your plugin useful to the thousands of non-English
924speaking SquirrelMail users out there! It is almost rude not to do so, and
925it isn't much trouble, either. This document will only describe how you can
926accomplish the internationalization of a plugin. For more general information
927about PHP and SquirrelMail translation facilities, see:
928
929http://www.squirrelmail.org/wiki/wiki.php?LanguageTranslation
930
931The unofficial way to internationalize a plugin is to put all plugin output
932into the proper format but to rely on the SquirrelMail translation facilities
933for all the rest. If the plugin were really to get translated, you'd need
934to make sure that all output strings for your plugin are either added to or
935already exist in the main SquirrelMail locale files.
936
937The better way to make sure your plugin is translated is to create your own
938locale files and what is called a "gettext domain" (see the link above for
939more information).
940
941There are three basic steps to getting your plugins internationalized: put
942all output into the proper format, switch gettext domains and create locale
943files.
944
945 1. Putting plugin output into the correct format is quite easy. The hard
946 part is making sure you catch every last echo statement. You need to
947 echo text like this:
948
949 echo _("Hello");
950
951 So, even in the HTML segments of your plugin files, you need to do this:
952
953 <input type="submit" value="<?php echo _("Submit") ?>">
954
955 You can put any text you want inside of the quotes (you MUST use double
956 quotes!), including HTML tags, etc. What you should think carefully
957 about is that some languages may use different word ordering, so this
958 might be problematic:
959
960 echo _("I want to eat a ") . $fruitName . _(" before noon");
961
962 Because some languages (Japanese, for instance) would need to translate
963 such a sentence to "Before noon " . $fruitName . " I want to eat", but
964 with the format above, they are stuck having to translate each piece
965 separately. You might want to reword your original sentence:
966
967 echo _("This is what I want to eat before noon: ") . $fruitName;
968
969 2. By default, the SquirrelMail gettext domain is always in use. That
970 means that any text in the format described above will be translated
971 using the locale files found in the main SquirrelMail locale directory.
972 Unless your plugin produces no output or only output that is in fact
973 translated under the default SquirrelMail domain, you need to create
974 your own gettext domain. The PHP for doing so is very simple. At
975 the top of any file that produces any output, place the following code
976 (again, using "demo" as the plugin name):
977
978 bindtextdomain('demo', SM_PATH . 'plugins/demo/locale');
979 textdomain('demo');
980
981 Now all output will be translated using your own custom locale files.
982 Please be sure to switch back to the SquirrelMail domain at the end
983 of the file, or many of the other SquirrelMail files may misbehave:
984
985 bindtextdomain('squirrelmail', SM_PATH . 'locale');
986 textdomain('squirrelmail');
987
988 Note that if, in the middle of your plugin file, you use any
989 SquirrelMail functions that send output to the browser, you'll need
990 to temporarily switch back to the SquirrelMail domain:
991
992 bindtextdomain('squirrelmail', SM_PATH . 'locale');
993 textdomain('squirrelmail');
994 displayPageHeader($color, 'None');
995 bindtextdomain('demo', SM_PATH . 'plugins/demo/locale');
996 textdomain('demo');
997
998 Note that technically speaking, you only need to have one bindtextdomain
999 call per file, you should always use it before every textdomain call,
1000 since PHP installations without gettext compiled into them will not
1001 function properly if you do not.
1002
1003 3. Finally, you just need to create your own locale. You should create
1004 a directory structure like this in the plugin directory:
1005
1006 demo
1007 |
1008 ------locale
1009 |
1010 ------de_DE
1011 | |
1012 | ------LC_MESSAGES
1013 |
1014 ------ja_JP
1015 |
1016 ------LC_MESSAGES
1017
1018 Create a directories such as de_DE for each language (de_DE is German,
1019 ja_JP is Japanese, etc. - check the SquirrelMail locale directory for
1020 a fairly comprehensive listing). Inside of each LC_MESSAGES directory
1021 you should place two files, one with your translations in it, called
1022 <plugin name>.po (in this case, "demo.po"), and one that is a compiled
1023 version of the ".po" file, called <plugin name>.mo (in this case,
1024 "demo.mo"). On most linux systems, there is a tool you can use to pull
1025 out most of the strings that you need to have translated from your PHP
1026 files into a sample .po file:
1027
1028 xgettext --keyword=_ -d <plugin name> -s -C *.php
1029
1030 --keyword option tells xgettext what your strings are enclosed in
1031 -d is the domain of your plugin which should be the plugin's name
1032 -s tells xgettext to sort the results and remove duplicate strings
1033 -C means you are translating a file with C/C++ type syntax (ie. PHP)
1034 *.php is all the files you want translations for
1035
1036 Note, however, that this will not always pick up all strings, so you
1037 should double-check manually. Of course, it's easiest if you just keep
1038 track of all your strings as you are coding your plugin. Your .po file
1039 will now look something like:
1040
1041 # SOME DESCRIPTIVE TITLE.
1042 # Copyright (C) YEAR Free Software Foundation, Inc.
1043 # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
1044 #
1045 #, fuzzy
1046 msgid ""
1047 msgstr ""
1048 "Project-Id-Version: PACKAGE VERSION\n"
1049 "POT-Creation-Date: 2003-06-18 11:22-0600\n"
1050 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1051 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1052 "Language-Team: LANGUAGE <LL@li.org>\n"
1053 "MIME-Version: 1.0\n"
1054 "Content-Type: text/plain; charset=CHARSET\n"
1055 "Content-Transfer-Encoding: ENCODING\n"
1056
1057 #: functions.php:45
1058 msgid "Hello"
1059 msgstr ""
1060
1061 #: functions.php:87
1062 msgid "Favorite Color"
1063 msgstr ""
1064
1065 You should change the header to look something more like:
1066
1067 # Copyright (c) 1999-2003 The Squirrelmail Development Team
1068 # Roland Bauerschmidt <rb@debian.org>, 1999.
1069 msgid ""
1070 msgstr ""
1071 "Project-Id-Version: $Id: squirrelmail.po,v 1.10 2003/06/04 15:01:59
1072 philippe_mingo Exp $\n"
1073 "POT-Creation-Date: 2003-01-21 19:21+0100\n"
1074 "PO-Revision-Date: 2003-01-21 21:01+0100\n"
1075 "Last-Translator: Juergen Edner <juergen.edner@epost.de>\n"
1076 "Language-Team: German <squirrelmail-i18n@lists.squirrelmail.net>\n"
1077 "MIME-Version: 1.0\n"
1078 "Content-Type: text/plain; charset=ISO-8859-1\n"
1079 "Content-Transfer-Encoding: 8bit\n"
1080
1081 The most important thing to change here is the charset on the next to
1082 last line. You'll want to keep a master copy of the .po file and make
1083 a copy for each language you have a translation for. You'll need to
1084 translate each string in the .po file:
1085
1086 msgid "Hello"
1087 msgstr "Guten Tag"
1088
1089 After you're done translating, you can create the .mo file very simply
1090 by running the following command (available on most linux systems):
1091
d2b351d7 1092 msgfmt -o <plugin name>.mo <plugin name>.po
9cd2ae7d 1093
1094 In the case of the "demo" plugin:
1095
d2b351d7 1096 msgfmt -o demo.mo demo.po
9cd2ae7d 1097
1098 Please be sure that the .po and .mo files both are named exactly the
1099 same as the domain you bound in step 2 above and everything else works
1100 automatically. In SquirrelMail, go to Options -> Display Preferences
1101 and change your Language setting to see the translations in action!
1102
1103
a7532db9 1104
1105Documenting the Code (Optional)
1106-------------------------------
1107
1108If you wish, you can use phpdoc (Javadoc-style) comments, when documenting your
1109code.
1110
1111If you follow the standards that are followed between Squirrelmail core &
1112plugin developers, the resulted documentation can be included with the rest of
1113the Squirrelmail code & API documentation. Specifically, in the page-level
1114docblock, declare the package to be 'plugins', and the subpackage to be the
1115name of your plugin. For instance:
1116
1117/**
1118 * demo.php
1119 *
1120 * Copyright (c) 2003 My Name <my-email-address>
1121 * Licensed under the GNU GPL. For full terms see the file COPYING.
1122 *
1123 * @package plugins
1124 * @subpackage demo
1125 */
1126
1127The rest is up to you. Try to follow some common sense and document what is
1128really needed. Documenting the code properly can be a big help not only to
1129yourself, but to those who will take a look at your code, fix the bugs and even
1130improve it, in the true open-source spirit that Squirrelmail was built upon.
1131
1132For more information about phpdocumentor and how to write proper-tagged
1133comments, you are directed at:
1134
1135http://phpdocu.sourceforge.net/
1136
1137
1138
9cd2ae7d 1139PLUGIN STANDARDS AND REQUIREMENTS
1140=================================
1141
1142The SquirrelMail project has some important goals, such as avoiding the
1143use of JavaScript, avoiding non-standard HTML tags, keeping file sizes
1144small and providing the fastest webmail client on the Internet. As such,
1145we'd like it if plugin authors coded with the same goals in mind that the
1146core developers do. Common sense is always a good tool to have in your
1147programming repertoire, but below is an outline of some standards that we
1148ask you as a plugin developer to meet. Depending upon how far you bend
1149these rules, we may not want to post your plugin on the SquirrelMail
1150website... and of course, no one really wants your efforts to go to waste
1151and for the SquirrelMail community to miss out on a potentially useful
1152plugin, so please try to follow these guidelines as closely as possible.
1153
1154
1155Small setup.php
1156---------------
1157
1158In order for SquirrelMail to remain fast and lean, we are now asking
1159that all plugin authors remove all unnecessary functionality from setup.php
d2b351d7 1160and refactor it into another file. There are a few ways to accomplish
9cd2ae7d 1161this, none of which are difficult. At a minimum, you'll want to have the
1162squirrelmail_plugin_init_<plugin name>() function in setup.php, and naturally,
1163you'll need functions that are merely stubs for each hook that you are using.
1164One (but not the only) way to do it is:
1165
1166 function squirrelmail_plugin_init_demo()
1167 {
1168 global $squirrelmail_plugin_hooks;
1169 $squirrelmail_plugin_hooks['generic_header']['demo'] = 'plugin_demo_header';
1170 }
1171 function plugin_demo_header()
1172 {
1173 include_once(SM_PATH . 'plugins/demo/functions.php');
1174 plugin_demo_header_do();
1175 }
1176
1177
1178Internationalization
1179--------------------
1180
1181Q: What is more disappointing to users in France who would make good
1182 use of your plugin than learning that it is written entirely in English?
1183A: Learning that they cannot send you a French translation file for your
1184 plugin.
1185
1186There are thousands of users out there whose native tongue is not English,
1187and when you develop your plugin without going through the three simple steps
1188needed to internationalize it, you are effectively writing them all off.
1189PLEASE consider internationalizing your plugin!
1190
1191
1192Developing with E_ALL
1193---------------------
1194
1195When you are developing your plugin, you should always have error reporting
1196turned all the way up. You can do this by changing two settings in your
1197php.ini and restarting your web server:
1198
799c2046 1199 display_errors = On
9cd2ae7d 1200 error_reporting = E_ALL
1201
1202This way, you'll be sure to see all Notices, Warnings and Errors that your
1203code generates (it's OK, really, it happens to the best of us... except me!).
1204Please make sure to fix them all before you release the plugin.
1205
1206
1b6b1526 1207Compatibility with register_globals=Off
1208---------------------------------------
1209
1210Most sensible systems administrators now run their PHP systems with the
1211setting "register_globals" as OFF. This is a prudent security setting,
1212and as the SquirrelMail core code has long since been upgraded to work
1213in such an environment, we are now requiring that all plugins do the same.
1214Compatibility with this setting amounts to little more than explicitly
1215gathering any and all variables you sent from a <form> tag as GET or POST
1216values instead of just assuming that they will be placed in the global
1217scope automatically. There is nothing more to do than this:
1218
1219 global $favorite_color;
1220 sqgetGlobalVar('favorite_color', $favorite_color, SQ_FORM);
1221
1222
9cd2ae7d 1223Extra Blank Lines
1224-----------------
1225
1226It may seem innocuous, but if you have any blank lines either before the
1227first <?php tag or after the last ?> tag in any of your plugin files, you
1228you will break SquirrelMail in ways that may seem entirely unrelated. For
1229instance, this will often cause a line feed character to be included with
1230email attachments when they are viewed or downloaded, rendering them useless!
1231
1232
1233include_once
1234------------
1235
1236When including files, please make sure to use the include_once() function
1237and NOT include(), require(), or require_once(), since these all are much
1238less efficient than include_once() and can have a cumulative effect on
1239SquirrelMail performance.
1240
1241
1242Version Reporting
1243-----------------
1244
1245In order for systems administrators to keep better track of your plugin and
1246get upgrades more efficiently, you are requested to make version information
1247available to SquirrelMail in a format that it understands. There are two
1248ways to do this. Presently, we are asking that you do both, since we are
1249still in a transition period between the two. This is painless, so please
1250be sure to include it:
1251
1252 1. Create a file called "version" in the plugin directory. That file
1253 should have only two lines: the first line should have the name of
1254 the plugin as named on the SquirrelMail web site (this is often a
1255 prettified version of the plugin directory name), the second line
1256 must have the version and nothing more. So for our "demo" plugin,
1257 whose name on the web site might be something like "Demo Favorite
1258 Colors", the file plugins/demo/version should have these two lines:
1259
1260 Demo Favorite Colors
1261 1.0
1262
1263 2. In setup.php, you should have a function called <plugin name>_version().
1264 That function should return the version of your plugin. For the "demo"
1265 plugin, that should look like this:
1266
1267 function demo_version()
1268 {
1269 return '1.0';
1270 }
1271
1272
1273Configuration Files
1274-------------------
1275
1276It is common to need a configuration file that holds some variables that
1277are set up at install time. For ease of installation and maintenance, you
1278should place all behavioral settings in a config file, isolated from the
1279rest of your plugin code. A typical file name to use is "config.php". If
1280you are using such a file, you should NOT include a file called "config.php"
1281in your plugin distribution, but instead a copy of that file called
1282"config.php.sample". This helps systems administrators avoid overwriting
1283the "config.php" files and losing all of their setup information when they
1284upgrade your plugin.
1285
1286
1287Session Variables
1288-----------------
1289
1290In the past, there have been some rather serious issues with PHP sessions
1291and SquirrelMail, and certain people have worked long and hard to ensure
1292that these problems no longer occur in an extremely wide variety of OS/PHP/
1293web server environments. Thus, if you need to place any values into the
1294user's session, there are some built-in SquirrelMail functions that you are
1295strongly encouraged to make use of. Using them also makes your job easier.
1296
1297 1. To place a variable into the session:
1298
1299 global $favorite_color;
1300 $favoriteColor = 'green';
1301 sqsession_register($favorite_color, 'favorite_color');
1302
1303 Strictly speaking, globalizing the variable shouldn't be necessary,
1304 but certain versions of PHP seem to behave more predictably if you do.
1305
1306 2. To retrieve a variable from the session:
1307
1308 global $favorite_color;
1309 sqgetGlobalVar('favorite_color', $favorite_color, SQ_SESSION);
1310
1311 3. You can also check for the presence of a variable in the session:
1312
1313 if (sqsession_is_registered('favorite_color'))
1314 // do something important
1315
1316 4. To remove a variable from the session:
1317
ea26c996 1318 global $favorite_color;
9cd2ae7d 1319 sqsession_unregister('favorite_color');
1320
ea26c996 1321 Strictly speaking, globalizing the variable shouldn't be necessary,
1322 but certain versions of PHP seem to behave more predictably if you do.
1323
9cd2ae7d 1324
1325Form Variables
1326--------------
1327
1328You are also encouraged to use SquirrelMail's built-in facilities to
1329retrieve variables from POST and GET submissions. This is also much
1330easier on you and makes sure that all PHP installations are accounted
1331for (such as those that don't make the $_POST array automatically
1332global, etc.):
1333
1334 global $favorite_color;
1335 sqgetGlobalVar('favorite_color', $favorite_color, SQ_FORM);
1336
1337
1338Files In Plugin Directory
1339-------------------------
1340
1341There are a few files that you should make sure to include when you build
1342your final plugin distribution:
1343
1344 1. A copy of the file index.php from the main plugins directory. When
1345 working in your plugin directory, just copy it in like this:
1346
1347 $ cp ../index.php .
1348
1349 This will redirect anyone who tries to browse to your plugin directory
1350 to somewhere more appropriate. If you create other directories under
1351 your plugin directory, you may copy the file there as well to be extra
1352 safe. If you are storing sensitive configuration files or other data
1353 in such a directory, you could even include a .htaccess file with the
1354 contents "Deny From All" that will disallow access to that directory
1355 entirely (when the target system is running the Apache web server).
1356 Keep in mind that not all web servers will honor an .htaccess file, so
1357 don't depend on it for security. Make sure not to put such a file in
1358 your main plugin directory!
1359
1360 2. A file that describes your plugin and offers detailed instructions for
1361 configuration or help with troubleshooting, etc. This file is usually
1362 entitled "README". Some useful sections to include might be:
1363
1364 Plugin Name and Author
1365 Current Version
1366 Plugin Features
1367 Detailed Plugin Description
1368 How-to for Plugin Configuration
1369 Change Log
1370 Future Ideas/Enhancements/To Do List
1371
1372 3. A file that explains how to install your plugin. This file is typically
1373 called "INSTALL". If you do not require any special installation
1374 actions, you can probably copy one from another plugin or use this as
1375 a template:
1376
1377 Installing the Demo Plugin
1378 ==========================
1379
1380 1) Start with untaring the file into the plugins directory.
1381 Here is a example for the 1.0 version of the Demo plugin.
1382
1383 $ cd plugins
1384 $ tar -zxvf demo-1.0-1.4.0.tar.gz
1385
1386 2) Change into the demo directory, copy config.php.sample
1387 to config.php and edit config.php, making adjustments as
1388 you deem necessary. For more detailed explanations about
1389 each of these parameters, consult the README file.
1390
1391 $ cd demo
1392 $ cp config.php.sample config.php
1393 $ vi config.php
1394
1395
1396 3) Then go to your config directory and run conf.pl. Choose
1397 option 8 and move the plugin from the "Available Plugins"
1398 category to the "Installed Plugins" category. Save and exit.
1399
1400 $ cd ../../config/
1401 $ ./conf.pl
1402
1403
1404 Upgrading the Demo Plugin
1405 =========================
1406
1407 1) Start with untaring the file into the plugins directory.
1408 Here is a example for the 3.1 version of the demo plugin.
1409
1410 $ cd plugins
1411 $ tar -zxvf demo-3.1-1.4.0.tar.gz
1412
1413
1414 2) Change into the demo directory, check your config.php
1415 file against the new version, to see if there are any new
1416 settings that you must add to your config.php file.
1417
1418 $ diff -Nau config.php config.php.sample
1419
1420 Or simply replace your config.php file with the provided sample
1421 and reconfigure the plugin from scratch (see step 2 under the
1422 installation procedure above).
1423
1424
1425COMPATIBILITY WITH OLDER VERSIONS OF SQUIRRELMAIL
1426=================================================
1427
1428Whenever new versions of SquirrelMail are released, there is always a
1429considerable lag time before it is widely adopted. During that transitional
1430time, especially when the new SquirrelMail version contains any architectural
1431and/or functional changes, plugin developers are put in a unique and very
1432difficult position. That is, there will be people running both the old and
1433new versions of SquirrelMail who want to use your plugin, and you will
1434probably want to accomodate them both.
1435
1436The easiest way to keep both sides happy is to keep two different versions
1437of your pluign up to date, one that runs under the older SquirrelMail, and
1438one that requires the newest SquirrelMail. This is inconvenient, however,
1439especially if you are continuing to develop the plugin. Depending on the
1440changes the SquirrelMail has implemented in the new version, you may be able
1441to include code that can auto-sense SquirrelMail version and make adjustments
1442on the fly. There is a function available to you for determining the
1443SquirrelMail version called check_sm_version() and it can be used as such:
1444
1445 check_sm_version(1, 4, 0)
1446
1447This will return TRUE if the SquirrelMail being used is at least 1.4.0, and
1448FALSE otherwise.
1449
1450As this document is written, we are in a transition period between versions
14511.2.11 and 1.4.0. There is a plugin called "Compatibilty" that is intended
1452for use by plugin authors so they can develop one version of their plugin
1453and seamlessly support both 1.2.x and 1.4.x SquirrelMail installations. For
1454more information about how to use the "Compatibility" plugin, download it and
1455read its README file or see:
1456
1457 http://www.squirrelmail.org/wiki/wiki.php?PluginUpgrading
1458
1459
1460REQUESTING NEW HOOKS
1461====================
1462
1463It's impossible to foresee all of the places where hooks might be useful
1464(it's also impossible to put in hooks everywhere!), so you might need to
1465negotiate the insertion of a new hook to make your plugin work. In order
1466to do so, you should post such a request to the squirrelmail-devel mailing
1467list.
1468
1469
1470HOW TO RELEASE YOUR PLUGIN
1471==========================
1472
1473As long as you've consulted the list of plugin standards and done your
1474best to follow them, there's little standing in the way of great fame as an
1475official SquirrelMail plugin developer.
1476
1477 1. Make a distribution file. There is a convenient Perl script in
1478 the plugins directory that will help you do this:
1479
1480 make_archive.pl -v demo 1.0 1.4.0
1481
1482 -v is optional and indicates that the script should run in verbose mode
1483 demo is the name of your plugin
1484 1.0 is the version of your plugin
1485 1.4.0 is the version of SquirrelMail that is required to run your plugin
1486
1487 You can also create the distribution file manually in most *nix
1488 environments by running this command from the plugins directory (NOT
1489 your plugin directory):
1490
1491 $ tar czvf demo-1.0-1.4.0.tar.gz demo
1492
1493 Where "demo" is the name of your plugin, "1.0" is the version of
1494 your plugin, and "1.4.0" is the version of SquirrelMail required
1495 to use your plugin.
1496
1497 2. Consult the SquirrelMail web site for contact information for the
1498 Plugins Team Leaders, to whom you should make your request. If they
1499 do not respond, you should feel free to ask for help contacting them
1500 on the squirrelmail-plugins mailing list.
1501
1502 http://www.squirrelmail.org/wiki/wiki.php?SquirrelMailLeadership
1503