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