disable regexp compilation error
[squirrelmail.git] / doc / Development / plugin.txt
index 64ca8f0a40af6d3f7f6a8e333dadd7510731b5af..3fa3834456e8666b56d9b4c1ca6120f774dc5c59 100644 (file)
@@ -5,9 +5,9 @@ development FAQ for more information.  Also, help writing plugins
 is easily obtained by posting to the squirrelmail-plugins mailing
 list.  (See details about mailing lists on the website)
 
-FAQ -> http://www.squirrelmail.org/wiki/wiki.php?DeveloperFAQ
+FAQ -> http://www.squirrelmail.org/wiki/DeveloperFAQ
 Plugin Development ->
-       http://www.squirrelmail.org/wiki/wiki.php?DevelopingPlugins
+       http://www.squirrelmail.org/wiki/DevelopingPlugins
 
 
 A FEW NOTES ON THE PLUGIN ARCHITECTURE
@@ -163,36 +163,59 @@ version is not listed, files are included from v.1.3.2.):
       1.7. class/mime/Language.class.php
       1.8. class/mime/ContentType.class.php
    2. functions/global.php
+      * fixes differences between php 4.0.x and 4.1+ globals (only in 1.4.x).  
+      * undoes magic_quotes_gpc=on sanitizing
+      * sets $PHP_SELF (since 1.5.1)
+      * starts session
    3. functions/strings.php
+      3.1. functions/global.php
+      3.2. plugins/compatibility/functions.php (compatibility v.2.0.4+, requires
+           code patching)
+      * sets squirrelmail version variable and constant.
+      * sets $PHP_SELF (before 1.5.1)
    4. config/config.php
       4.1. config/config_local.php (from 1.4.0rc1)
    5. functions/i18n.php
       5.1. functions/global.php (from 1.4.0)
+      * reads 'squirrelmail_language' cookie
+      * loads $languages (since 1.5.1 $languages array is built from
+        locale/*/setup.php files)
+      * loads own gettext functions, if php gettext is unavailable
    6. functions/auth.php
    7. include/load_prefs.php
       7.1. include/validate.php
       7.2. functions/prefs.php
+         7.2.1. functions/global.php (sqgetGlobalVar() function)
+         7.2.2. functions/plugin.php (do_hook_function() function,, 
+                since 1.4.4 and 1.5.1, see 7.3)
+         7.2.3. $prefs_backend (only in 1.4.3 and 1.5.0)
+                do_hook_function('prefs_backend') (since 1.4.4 and 1.5.1)
+                functions/db_prefs.php
+                functions/file_prefs.php
+           7.2.3.1. functions/display_messages.php
+                    (loaded only by file_prefs.php)
+           7.2.3.2. files loaded by plugin that uses 'prefs_backend' hook
       7.3. functions/plugin.php
          7.3.1. functions/global.php (from 1.4.0 and 1.5.0)
          7.3.2. functions/prefs.php (from 1.5.1)
+         7.3.3. plugins/*/setup.php files for enabled plugins. 
+         * starts all squirrelmail_plugin_init_pluginname functions
       7.4. functions/constants.php
       7.5. do_hook('loading_prefs')
-         7.5.1. files loaded by plugins that use 'loading_prefs'
+         7.5.1. files loaded by plugins that use 'loading_prefs' hook
    8. functions/page_header.php
       8.1. functions/strings.php
       8.2. functions/html.php
       8.3. functions/imap_mailbox.php
          8.3.1. functions/imap_utf7_local.php
       8.4. functions/global.php
-   9. functions/prefs.php
-      9.1. functions/global.php
-      9.2. $prefs_backend (only in 1.4.3 and 1.5.0)
-           do_hook_function('prefs_backend') (since 1.4.4 and 1.5.1)
-           functions/db_prefs.php
-           functions/file_prefs.php
-         9.2.1. functions/display_messages.php
-                (loaded only by file_prefs.php)
-         9.2.2. files loaded by plugin that uses 'prefs_backend'
+   9. functions/prefs.php (already loaded. see 7.2)
+
+Since SquirrelMail 1.5.1 functions/global.php file must be loaded before 
+setting any own global variables. If variables are set before loading 
+functions/global.php library, they can be corrupted in PHP register_globals=On 
+setups.
+
 
 Hook Types:  Parameters and Return Values
 -----------------------------------------
@@ -282,6 +305,8 @@ but may be out of date soon thereafter.  You never know.  ;-)
   error_box                      functions/display_messages.php  concat_hook
   get_pref_override              functions/file_prefs.php        hook_func
   get_pref                       functions/file_prefs.php        hook_func
+& options_identities_process     functions/identity.php          do_hook
+&% options_identities_renumber   functions/identity.php          do_hook
   special_mailbox                functions/imap_mailbox.php      hook_func
 % rename_or_delete_folder        functions/imap_mailbox.php      hook_func
   mailbox_index_before           functions/mailbox_display.php   do_hook
@@ -301,10 +326,11 @@ but may be out of date soon thereafter.  You never know.  ;-)
   loading_prefs                  include/load_prefs.php          do_hook
   addrbook_html_search_below     src/addrbook_search_html.php    do_hook
   addressbook_bottom             src/addressbook.php             do_hook
-  compose_form                   src/compose.php                 do_hook
+! compose_form                   src/compose.php                 do_hook
   compose_bottom                 src/compose.php                 do_hook
   compose_button_row             src/compose.php                 do_hook
   compose_send                   src/compose.php                 do_hook
+  compose_send_after             src/compose.php                 do_hook
   folders_bottom                 src/folders.php                 do_hook
   help_top                       src/help.php                    do_hook
   help_chapter                   src/help.php                    do_hook
@@ -314,7 +340,8 @@ but may be out of date soon thereafter.  You never know.  ;-)
   left_main_after                src/left_main.php               do_hook
   login_cookie                   src/login.php                   do_hook
   login_top                      src/login.php                   do_hook
-  login_form                     src/login.php                   do_hook
+  login_form                     src/login.php                   concat_hook
+    (was do_hook before 1.5.1)
   login_bottom                   src/login.php                   do_hook
 * optpage_set_loadinfo           src/options.php                 do_hook
 * optpage_loadhook_personal      src/options.php                 do_hook
@@ -339,9 +366,7 @@ but may be out of date soon thereafter.  You never know.  ;-)
 * options_folder_bottom          src/options.php                 do_hook
 * options_order_bottom           src/options.php                 do_hook
 * options_highlight_bottom       src/options_highlight.php       do_hook
-& options_identities_process     src/options_identities.php      do_hook
 & options_identities_top         src/options_identities.php      do_hook
-&% options_identities_renumber   src/options_identities.php      do_hook
 & options_identities_table       src/options_identities.php      concat_hook
 & options_identities_buttons     src/options_identities.php      concat_hook
   message_body                   src/printer_friendly_bottom.php do_hook
@@ -353,7 +378,6 @@ but may be out of date soon thereafter.  You never know.  ;-)
   read_body_bottom               src/read_body.php               do_hook
   login_before                   src/redirect.php                do_hook
   login_verified                 src/redirect.php                do_hook
-  generic_header                 src/right_main.php              do_hook
   right_main_after_header        src/right_main.php              do_hook
   right_main_bottom              src/right_main.php              do_hook
   search_before_form             src/search.php                  do_hook
@@ -371,6 +395,7 @@ O info_bottom                    plugins/info/options.php        do_hook
 ^ = Special attachments hook (see below)
 * = Special options hooks (see below)
 O = Optional hook provided by a particular plugin
+! = See below for notes about working with the compose page's <form> tag
 
 
 (#) Called With
@@ -381,6 +406,35 @@ Each hook is called using the hook type specified in the list above:
    concat_hook   concat_hook_function()
 
 
+(!) Compose Form
+----------------
+The compose_form hook allows plugins to insert their own code into 
+the form tag for the main message composition HTML form.  Usually
+plugins will want to insert some kind of code in an onsubmit event
+handler.  In order to allow more than one plugin to do so, all plugins
+using this hook to add some onsubmit code need to add that code (without
+the enclosing attribute name and quotes) as a new array entry to the 
+global $compose_onsubmit array.  The code should use "return false"
+if the plugin has found a reason to stop form submission, otherwise,
+it should DO NOTHING (that is, please do not use "return true", as that
+will prevent other plugins from using the onsubmit handler).  SquirrelMail
+itself will insert a final "return true".  All onsubmit code will be
+enclosed in double quotes by SquirrelMail, so plugins need to quote 
+accordingly if needed.  For example:
+
+   global $compose_onsubmit;
+   $compose_onsubmit[] = ' if (somevar == \'no\') return false; ';
+
+Note the escaped single quotes.  If you use double quotes, they would have
+to be escaped as such:
+
+   global $compose_onsubmit;
+   $compose_onsubmit[] = ' if (somevar == \'no\') { alert(\\"Sorry\\"); return false; }';
+
+Any other form tag additions by a plugin (beside onsubmit event code) can 
+currently be echoed directly to the browser.
+
+
 (&) Identity Hooks
 ------------------
 This set of hooks is passed special information in the array of arguments:
@@ -393,6 +447,7 @@ options_identities_process
    for each identity or catch any custom submit buttons that you may
    have added to the identities page.  The arguments to this hook are:
 
+    (SquirrelMail 1.4.4 or older and 1.5.0)
       [0] = hook name (always "options_identities_process")
       [1] = should I run the SaveUpdateFunction() (alterable)
 
@@ -400,6 +455,15 @@ options_identities_process
    trigger SaveUpdateFunction() after the hook is finished - by default,
    it will not be called.
 
+    (SquirrelMail 1.4.6+ or 1.5.1+)
+      [0] = hook name (always "options_identities_process")
+      [1] = action (hook is used only in 'update' action and any custom 
+            action added to form with option_identities_table and 
+            option_identities_buttons hooks)
+      [2] = processed identity number
+
+   Hook is not available in SquirrelMail 1.4.5.
+
 options_identities_renumber
 
    This hook is called when one of the identities is being renumbered,
@@ -412,6 +476,9 @@ options_identities_renumber
       [1] = being renumbered from ('default' or 1 through (# idents) - 1)
       [2] = being renumbered to ('default' or 1 through (# idents) - 1)
 
+   Hook is not available in SquirrelMail 1.4.5. Renumbering order differs
+   in 1.4.5+ and 1.5.1+.
+
 options_identities_table
 
    This hook allows you to insert additional rows into the table that
@@ -453,6 +520,16 @@ options_identities_buttons
               . '" value="Press Me" />';
       }
 
+   Input element should use 'smaction[action_name][identity_no]' value in 
+   'name' attribute, if you want to process your button actions in
+   SquirrelMail 1.4.6+ and 1.5.1+ options_identity_process hook.
+
+
+See sample implementation of identity hooks in SquirrelMail demo plugin.
+
+  cvs -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/squirrelmail \
+    co plugins/demo
+
 
 (^) Attachment Hooks
 --------------------
@@ -705,6 +782,9 @@ for you.  This is the preferred method of building options lists going forward.
          htmlencoded    disables html sanitizing. WARNING - don't use it, if user
                         input is possible in option or use own sanitizing functions.
                         Currently works only with SMOPT_TYPE_STRLIST.
+         folder_filter  Controls folder list limits in SMOPT_TYPE_FLDRLIST widget.
+                        See $flag argument in sqimap_mailbox_option_list()
+                        function. Available since 1.5.1.
 
       Note that you do not have to create a whole new section on the options
       page if you merely want to add a simple input item or two to an options
@@ -1014,7 +1094,7 @@ it isn't much trouble, either.  This document will only describe how you can
 accomplish the internationalization of a plugin.  For more general information
 about PHP and SquirrelMail translation facilities, see:
 
-http://www.squirrelmail.org/wiki/wiki.php?LanguageTranslation
+http://www.squirrelmail.org/wiki/LanguageTranslation
 
 The unofficial way to internationalize a plugin is to put all plugin output
 into the proper format but to rely on the SquirrelMail translation facilities
@@ -1320,6 +1400,10 @@ scope automatically.  There is nothing more to do than this:
    global $favorite_color;
    sqgetGlobalVar('favorite_color', $favorite_color, SQ_FORM);
 
+SquirrelMail 1.5.1+ cleans globals in functions/global.php library. If 
+plugin depends on PHP register_globals=On and loads this library, it will 
+be broken.
+
 
 Security considerations
 -----------------------
@@ -1583,7 +1667,7 @@ and seamlessly support both 1.2.x and 1.4.x SquirrelMail installations.  For
 more information about how to use the "Compatibility" plugin, download it and
 read its README file or see:
 
-   http://www.squirrelmail.org/wiki/wiki.php?PluginUpgrading
+   http://www.squirrelmail.org/wiki/PluginUpgrading
 
 
 REQUESTING NEW HOOKS
@@ -1628,5 +1712,5 @@ official SquirrelMail plugin developer.
       do not respond, you should feel free to ask for help contacting them
       on the squirrelmail-plugins mailing list.
 
-         http://www.squirrelmail.org/wiki/wiki.php?SquirrelMailLeadership
+         http://www.squirrelmail.org/wiki/SquirrelMailLeadership