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