1.4.7 cleans globals too
[squirrelmail.git] / doc / Development / plugin.txt
index 3fa3834456e8666b56d9b4c1ca6120f774dc5c59..ed09f7dcfaa13ed8cccb03d6d40218f6f8ca2869 100644 (file)
@@ -125,34 +125,77 @@ the main SquirrelMail directory.  This constant is always available
 for you to use when including other files from the SquirrelMail core,
 your own plugin, or other plugins, should the need arise.  If any of
 your plugin files are requested directly from the client browser,
-you will need to define this constant before you do anything else:
+you will need to include the SquirrelMail initialization file which is present
+since SquirrelMail 1.5.2.
 
-  define('SM_PATH', '../../');
+The SquirrelMail initialization file which is located in include/init.php does
+take care of setting up the session, defining the constants like SM_PATH and
+it take care of including a minimum set of required files.
 
-Files are included like this:
+The files which are included depends on which file the hook operates on.
+For all hook locations the following files are included:
 
-  include_once(SM_PATH . 'include/validate.php');
+    require(SM_PATH . 'functions/global.php');
+    require(SM_PATH . 'config/config.php');
+    require(SM_PATH . 'functions/plugin.php');
+    require(SM_PATH . 'include/constants.php');
+    require(SM_PATH . 'include/languages.php');
+    require(SM_PATH . 'functions/display_messages.php' );
+    require(SM_PATH . 'functions/page_header.php');
+    require(SM_PATH . 'functions/html.php');
+
+Except login.php also the following files are included:
+    require(SM_PATH . 'functions/prefs.php');
+
+    require(SM_PATH . 'functions/db_prefs.php');
+OR
+    require(SM_PATH . 'functions/file_prefs.php');
+(dependent of the configured preference backend)
+
+For all files except login.php and redirect.php also the following files are
+included:
+    require(SM_PATH . 'functions/strings.php');
+    require(SM_PATH . 'functions/auth.php');
+
+Because the use of "require" in include/init.php your plugin will fail if it
+tries to include the file in the plugin as well.
+Be aware of that.
+
+To include the init.php file add the following in your plugin:
+
+    /**
+     * Include the SquirrelMail initialization file.
+     */
+    require('../../include/init.php');
+
+Other files then the files mentioned above can be included by your plugin
+like this:
+
+    include_once(SM_PATH . 'functions/imap_general.php');
 
 When including files, please make sure to use the include_once() function
-and NOT include(), require(), or require_once(), since these all are much
-less efficient than include_once() and can have a cumulative effect on
-SquirrelMail performance.
+and NOT include(), require() because they can cause fatal errors when other
+plugins or SquirrelMail files include the same file.
+If you use require_once() instead of include_once() then if something cause
+wrong with the include then php will raise a fatal error. That's the reason
+plugins MUST use include_once() instead of require_once().
 
 The files that you may need to include in a plugin will vary greatly
 depending upon what the plugin is designed to do.  For files that are
-requested directly by the client browser, we strongly recommend that
-you include the file include/validate.php, since it will set up the
-SquirrelMail environment automatically.  It will ensure the the user
-has been authenticated and is currently logged in, load all user
-preferences, include internationalization support, call stripslashes()
-on all incoming data (if magic_quotes_gpc is on), and initialize and
-include all other basic SquirrelMail resources and functions.  You may
-see other plugins that directly include other SquirrelMail files, but
+requested directly by the client browser, you MUST includey the file
+    include/init.php
+, since it will set up the SquirrelMail environment automatically.
+It will ensure the the user has been authenticated and is currently logged in,
+load all user preferences, include internationalization support,
+call stripslashes() on all incoming data (if magic_quotes_gpc is on), and
+initialize and include all other basic SquirrelMail resources and functions.
+You may see other plugins that directly include other SquirrelMail files, but
 that is no longer necessary and is a hold-over from older SquirrelMail
 versions.
 
 List of files, that are included by include/validate.php (If SquirrelMail
-version is not listed, files are included from v.1.3.2.):
+version is not listed, files are included from v.1.3.2.). This table is
+specific to SquirrelMail 1.3.2 - 1.5.1. Script layout was changed in 1.5.2.
    1. class/mime.class.php
       1.1. class/mime/Rfc822Header.class.php
       1.2. class/mime/MessageHeader.class.php
@@ -163,7 +206,7 @@ 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).  
+      * 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
@@ -186,7 +229,7 @@ version is not listed, files are included from v.1.3.2.):
       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,, 
+         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)
@@ -198,7 +241,7 @@ version is not listed, files are included from v.1.3.2.):
       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. 
+         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')
@@ -211,9 +254,9 @@ version is not listed, files are included from v.1.3.2.):
       8.4. functions/global.php
    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 
+In SquirrelMail 1.4.7+ and 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.
 
 
@@ -309,6 +352,8 @@ but may be out of date soon thereafter.  You never know.  ;-)
 &% 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
+  folder_status (since 1.5.1)    functions/imap_mailbox.php      hook_func
+                                 functions/imap_general.php      hook_func
   mailbox_index_before           functions/mailbox_display.php   do_hook
   mailbox_form_before            functions/mailbox_display.php   do_hook
   mailbox_index_after            functions/mailbox_display.php   do_hook
@@ -331,6 +376,7 @@ but may be out of date soon thereafter.  You never know.  ;-)
   compose_button_row             src/compose.php                 do_hook
   compose_send                   src/compose.php                 do_hook
   compose_send_after             src/compose.php                 do_hook
+  configtest (since 1.5.2)       src/configtest.php              boolean_hook
   folders_bottom                 src/folders.php                 do_hook
   help_top                       src/help.php                    do_hook
   help_chapter                   src/help.php                    do_hook
@@ -384,6 +430,8 @@ but may be out of date soon thereafter.  You never know.  ;-)
   search_after_form              src/search.php                  do_hook
   search_bottom                  src/search.php                  do_hook
   logout                         src/signout.php                 do_hook
+  message_body (since 1.5.2)     src/view_html.php               do_hook
+  message_body (since 1.5.2)     src/view_text.php               do_hook
   webmail_top                    src/webmail.php                 do_hook
   webmail_bottom                 src/webmail.php                 concat_hook
   logout_above_text              src/signout.php                 concat_hook
@@ -408,18 +456,18 @@ Each hook is called using the hook type specified in the list above:
 
 (!) Compose Form
 ----------------
-The compose_form hook allows plugins to insert their own code into 
+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 
+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 
+enclosed in double quotes by SquirrelMail, so plugins need to quote
 accordingly if needed.  For example:
 
    global $compose_onsubmit;
@@ -431,7 +479,7 @@ 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 
+Any other form tag additions by a plugin (beside onsubmit event code) can
 currently be echoed directly to the browser.
 
 
@@ -457,8 +505,8 @@ options_identities_process
 
     (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 
+      [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
 
@@ -499,8 +547,8 @@ options_identities_table
               . 'YOUR CODE HERE' . '</td></tr>' . "\n";
       }
 
-   First hook argument was modified in 1.4.5/1.5.1. In SquirrelMail 1.4.1-1.4.4 
-   and 1.5.0 argument contains only background color. You should use 
+   First hook argument was modified in 1.4.5/1.5.1. In SquirrelMail 1.4.1-1.4.4
+   and 1.5.0 argument contains only background color. You should use
    <tr bgcolor="<?php echo $args[0]; ?>"> in these SquirrelMail versions.
 
 options_identities_buttons
@@ -520,7 +568,7 @@ options_identities_buttons
               . '" value="Press Me" />';
       }
 
-   Input element should use 'smaction[action_name][identity_no]' value in 
+   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.
 
@@ -1156,7 +1204,7 @@ files.
       the top of any file that produces any output, place the following code
       (again, using "demo" as the plugin name):
 
-         bindtextdomain('demo', SM_PATH . 'plugins/demo/locale');
+         bindtextdomain('demo', SM_PATH . 'locale');
          textdomain('demo');
 
       Now all output will be translated using your own custom locale files.
@@ -1173,7 +1221,7 @@ files.
          bindtextdomain('squirrelmail', SM_PATH . 'locale');
          textdomain('squirrelmail');
          displayPageHeader($color, 'None');
-         bindtextdomain('demo', SM_PATH . 'plugins/demo/locale');
+         bindtextdomain('demo', SM_PATH . 'locale');
          textdomain('demo');
 
       Note that technically speaking, you only need to have one bindtextdomain
@@ -1181,30 +1229,26 @@ files.
       since PHP installations without gettext compiled into them will not
       function properly if you do not.
 
-  3.  Finally, you just need to create your own locale.  You should create
-      a directory structure like this in the plugin directory:
+  3.  Finally, you just need to create your own locale.  There is a directory
+      structure like this in the locale directory:
 
-         demo
-           |
-           ------locale
-                    |
-                    ------de_DE
-                    |       |
-                    |       ------LC_MESSAGES
+         locale
+            |
+            ------de_DE
+            |       |
+            |       ------LC_MESSAGES
+            |
+            ------ja_JP
                     |
-                    ------ja_JP
-                            |
-                            ------LC_MESSAGES
-
-      Create a directories such as de_DE for each language (de_DE is German,
-      ja_JP is Japanese, etc. - check the SquirrelMail locale directory for
-      a fairly comprehensive listing).  Inside of each LC_MESSAGES directory
-      you should place two files, one with your translations in it, called
-      <plugin name>.po (in this case, "demo.po"), and one that is a compiled
-      version of the ".po" file, called <plugin name>.mo (in this case,
-      "demo.mo").  On most linux systems, there is a tool you can use to pull
-      out most of the strings that you need to have translated from your PHP
-      files into a sample .po file:
+                    ------LC_MESSAGES
+
+      There is a directory such as de_DE for each language (de_DE is German,
+      ja_JP is Japanese, etc.).  Inside of each LC_MESSAGES directory you should
+      place two files; one with your translations in it, called <plugin name>.po
+      (in this case, "demo.po"), and one that is a compiled version of the ".po"
+      file, called <plugin name>.mo (in this case, "demo.mo").  On most linux
+      systems, there is a tool you can use to pull out most of the strings that
+      you need to have translated from your PHP files into a sample .po file:
 
          xgettext --keyword=_ -d <plugin name> -s -C *.php
 
@@ -1245,7 +1289,7 @@ files.
 
       You should change the header to look something more like:
 
-         # Copyright (c) 1999-2005 The SquirrelMail Project Team
+         # Copyright (c) 1999-2006 The SquirrelMail Project Team
          # Roland Bauerschmidt <rb@debian.org>, 1999.
          # $Id$
          msgid ""
@@ -1400,8 +1444,8 @@ 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 
+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.