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