plugin.txt 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. $Id$
  2. It is best if you check out the SquirrelMail development FAQ for more
  3. information. This document may be obsoleted at some point in the future (or
  4. maybe we'll write a script to get the wiki contents and dump them in here
  5. automatically).
  6. FAQ -> http://www.squirrelmail.org/wiki/wiki.php?DeveloperFAQ
  7. Plugin Hooks -> http://www.squirrelmail.org/wiki/wiki.php?DevelopingPlugins
  8. A FEW NOTES ON THE PLUGIN ARCHITECTURE
  9. ======================================
  10. The plugin architecture of SquirrelMail is designed to make it possible to
  11. add new features without having to patch SquirrelMail itself. Functionality
  12. like password changing, displaying ads and calendars should be possible to
  13. add as plugins.
  14. The idea
  15. --------
  16. The idea is to be able to run random code at given places in the
  17. SquirrelMail code. This random code should then be able to do whatever
  18. needed to enhance the functionality of SquirrelMail. The places where
  19. code can be executed are called "hooks".
  20. There are some limitations in what these hooks can do. It is difficult
  21. to use them to change the layout and to change functionality that
  22. already is in SquirrelMail.
  23. Some way for the plugins to interact with the help subsystem and
  24. translations will be provided.
  25. The implementation
  26. ------------------
  27. In the main SquirrelMail files the file functions/plugin.php. In
  28. places where hooks are made available they are executed by calling the
  29. function do_hook('hookname').
  30. The do_hook traverses the array $squirrelmail_plugin_hooks['hookname']
  31. and executes all the functions that are named in that array.
  32. A plugin must reside in a subdirectory in the plugins/ directory. The
  33. name of the subdirectory is considered the name of the plugin.
  34. To start using a plugin, its name must be added to the $plugins array
  35. in config.php like this:
  36. $plugins[0] = 'plugin_name';
  37. When a plugin is registered the file plugins/plugin_name/setup.php is
  38. included and the function squirrelmail_plugin_init_plugin_name is
  39. called with no parameters.
  40. Writing plugins
  41. ---------------
  42. A plugin must consist of at least a file called setup.php. All other
  43. files the plugin consist of should also be in the plugin directory.
  44. The function squirrelmail_plugin_init_plugin_name is called to
  45. initalize a plugin. This function could look something like this:
  46. function squirrelmail_plugin_init_demo () {
  47. global $squirrelmail_plugin_hooks;
  48. $squirrelmail_plugin_hooks['generic_header']['demo'] = 'plugin_demo_header';
  49. $squirrelmail_plugin_hooks['menuline']['demo'] = 'plugin_demo_menuline';
  50. }
  51. Note that the SquirrelMail files assume that all other SquirrelMail
  52. files are available as ../directory/file. This means that if some file
  53. in the plugin directory is requested, it must do a chdir('..') before
  54. including any of the standard SquirrelMail files.
  55. Hook Data Passed
  56. ----------------
  57. Hooks, when executed, are called with one parameter, an array of data
  58. that is passed to the hook. The first element in the array is the name
  59. of the hook that is being called. Any other elements in the array are
  60. dependant on the type of hook that is being called.
  61. Some of the information in the array may be changed. By default, the
  62. plugins should never change data unless it is documented otherwise.
  63. List of hooks
  64. -------------
  65. generic_header functions/page_header.php
  66. menuline functions/page_header.php
  67. compose_button_row src/compose.php
  68. compose_bottom src/compose.php
  69. compose_form src/compose.php
  70. compose_send src/compose.php
  71. left_main_before src/left_main.php
  72. left_main_after src/left_main.php
  73. * options_save src/options.php (see note on options)
  74. * options_link_and_description src/options.php (see note on options)
  75. * options_highlight_bottom src/options_highlight.php
  76. * options_personal_bottom src/options_personal.php
  77. * options_personal_inside src/options_personal.php
  78. * options_personal_save src/options_personal.php
  79. * options_display_bottom src/options_display.php
  80. * options_display_inside src/options_display.php
  81. * options_display_save src/options_display.php
  82. * options_folders_bottom src/options_folders.php
  83. * options_folders_inside src/options_folders.php
  84. * options_folders_save src/options_folders.php
  85. & options_identities_process src/options_identities.php
  86. & options_identities_top src/options_identities.php
  87. & options_identities_renumber src/options_identities.php (multiple places)
  88. & options_identities_table src/options_identities.php
  89. & options_identities_buttons src/options_identities.php
  90. logout src/signout.php
  91. logout_above_text src/signout.php
  92. login_before src/webmail.php
  93. login_verified src/webmail.php
  94. loading_prefs src/load_prefs.php
  95. mailbox_index_before functions/mailbox_display.php
  96. mailbox_index_after functions/mailbox_display.php
  97. mailbox_form_before functions/mailbox_display.php
  98. subject_link functions/mailbox_display.php
  99. motd src/right_main.php
  100. right_main_after_header src/right_main.php
  101. right_main_bottom src/right_main.php
  102. login_top src/login.php
  103. login_bottom src/login.php
  104. html_top src/read_body.php
  105. read_body_top src/read_body.php
  106. read_body_bottom src/read_body.php
  107. html_bottom src/read_body.php
  108. read_body_header src/read_body.php
  109. read_body_header_right src/read_body.php
  110. read_body_after_from src/read_body.php
  111. search_before_form src/search.php
  112. search_after_form src/search.php
  113. search_bottom src/search.php
  114. help_top src/help.php
  115. help_bottom src/help.php
  116. help_chapter src/help.php
  117. addrbook_html_search_below src/addrbook_search_html.php
  118. addressbook_bottom src/addressbook.php
  119. ^ attachment $type0/$type1 functions/mime.php (see note on attachments)
  120. (*) Options
  121. -----------
  122. There are two ways to do options for your plugin. First, you can incorporate it
  123. into an existing section of the preferences (Display, Personal, or Folders).
  124. The second way, you create your own section that they can choose from and it
  125. displays its own range of options.
  126. First: Integrating into existing options
  127. -----------------------------------------
  128. There are two hooks you need to use for this one:
  129. 1. options_YOUCHOOSE_inside
  130. This is the code that goes inside the table for the section you choose. Since
  131. it is going inside an existing table, it must be in this form:
  132. ------cut here-------
  133. <tr>
  134. <td>
  135. OPTION_NAME
  136. </td>
  137. <td>
  138. OPTION_INPUT
  139. </td>
  140. </tr>
  141. ------cut here-------
  142. 2. options_YOUCHOOSE_save
  143. This is the code that saves your preferences into the users' preference
  144. file. For an example of how to do this, see src/options.php.
  145. Second: Create your own section
  146. -------------------------------
  147. It is possible to create your own options sections with plugins. There are
  148. three hooks you will need to use.
  149. 1. options_link_and_description
  150. This creates the link and has a description that is shown on the options
  151. page. This should output HTML that looks like this. Make sure to read
  152. the section on outputing your own pages.
  153. -----cut here-----
  154. function my_plugin_name_my_function() {
  155. global $color
  156. ?>
  157. <table width=50% cellpadding=3 cellspacing=0 border=0 align=center>
  158. <tr>
  159. <td bgcolor="<?php echo $color[9] ?>">
  160. <a href="../plugins/YOUR_PLUGIN/YOUR_OPTIONS.php">YOUR OPTIONS NAME</a>
  161. </td>
  162. </tr>
  163. <tr>
  164. <td bgcolor="<?php echo $color[0] ?>">
  165. YOUR DESCRIPTION
  166. </td>
  167. </tr>
  168. </table>
  169. <?php
  170. }
  171. -----cut here-----
  172. 2. options_save
  173. Here is the code that you need to do to save your options in the
  174. preference files or manipulate whatever data you are trying to change
  175. through the options section. You can look at options.php for details
  176. on how this is to be done.
  177. 3. loading_prefs (optional)
  178. If you are wanting to save preferences to the preference files, then
  179. you need to do this step as well. Otherwise if you are manipulating
  180. other data, ignore this step.
  181. You should put the code in here that loads your preferences back
  182. into usable variables. Examples of this can be found in the file
  183. src/load_prefs.php
  184. (&) Identity Hooks
  185. ------------------
  186. Some hooks are passed special information in the array of arguments. See
  187. the SpamCop plugin for how to use them.
  188. options_identities_process
  189. [0] = Hook's name
  190. [1] = Should I run the SaveUpdateFunction() (alterable)
  191. options_identities_renumber
  192. [0] = Hook's name
  193. [1] = Renumber it from ('default' or 1 through # idents - 1)
  194. [2] = Renumber it to (same thing)
  195. options_identities_table
  196. [0] = Hook's name
  197. [1] = Color of table (use it like <tr<?PHP echo $Info[1]?>> in your
  198. plugin)
  199. [2] = Is this an empty section?
  200. [3] = What is the 'post' value?
  201. options_identities_buttons
  202. [0] = Hook's name
  203. [1] = Is this an empty section (the one at the end of the list)?
  204. [2] = What is the 'post' value?
  205. (^) Attachment Hooks
  206. --------------------
  207. When a message has attachments, this hook is called with the MIME types. For
  208. instance, a .zip file hook is "attachment application/x-zip". The hook should
  209. probably show a link to do a specific action, such as "Verify" or "View" for a
  210. .zip file.
  211. This is a breakdown of the data passed in the array to the hook that is called:
  212. [0] = Hook's name ('attachment text/plain')
  213. [1] = Array of links of actions (more below) (Alterable)
  214. [2] = Used for returning to mail message (startMessage)
  215. [3] = Used for finding message to display (id)
  216. [4] = Mailbox name, urlencode()'d (urlMailbox)
  217. [5] = Entity ID inside mail message (ent)
  218. [6] = Default URL to go to when filename is clicked on (Alterable)
  219. [7] = Filename that is displayed for the attachment
  220. [8] = Sent if message was found from a search (where)
  221. [9] = Sent if message was found from a search (what)
  222. To set up links for actions, you assign them like this:
  223. $Args[1]['your_plugin_name']['href'] = 'URL to link to';
  224. $Args[1]['your_plugin_name']['text'] = 'What to display';
  225. It's also possible to specify a hook as "attachment type0/*",
  226. for example "attachment text/*". This hook will be executed whenever there's
  227. no more specific rule available for that type.
  228. Outputting Your Own Pages
  229. -------------------------
  230. Often, when you want to provide your own customized options screen or create
  231. another web page instead of just using standard hooks, you will be creating
  232. your own .php files. An example of this is the attachment_common plugin's
  233. image.php file.
  234. To make sure that security is maintained and standards are followed, the top
  235. of your PHP script should look very similar to this:
  236. <?PHP
  237. /* This is my php file.
  238. * description goes here.
  239. */
  240. chdir('..');
  241. include('../src/validate.php');
  242. The validate.php script will include internationalization support,
  243. config.php variables, strings.php functions, and also authenticate that the
  244. user is truly logged in. validate.php also calls stripslashes() on incoming
  245. data (if gpc_magic_quotes() is on). You should never need to worry about
  246. that stuff again. As a warning, this has only really been ironed out in
  247. 1.1.1. If you create/modify a plugin to follow these rules, you must
  248. mention that it requires SquirrelMail 1.1.1 or later.
  249. After that, if you need further functions, just use
  250. include('../functions/filename.php');
  251. in your script. Since 1.0.5, it was no longer necessary (nor recommended)
  252. to use the "if (! isset($filename_php))" syntax.