plugin.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * plugin.php
  4. *
  5. * Copyright (c) 1999-2001 The SquirrelMail Development Team
  6. * Licensed under the GNU GPL. For full terms see the file COPYING.
  7. *
  8. * This file provides the framework for a plugin architecture.
  9. *
  10. * Documentation on how to write plugins might show up some time.
  11. *
  12. * $Id$
  13. */
  14. /*****************************************************************/
  15. /*** THIS FILE NEEDS TO HAVE ITS FORMATTING FIXED!!! ***/
  16. /*** PLEASE DO SO AND REMOVE THIS COMMENT SECTION. ***/
  17. /*** + Base level indent should begin at left margin, as ***/
  18. /*** the first line of the function definition below. ***/
  19. /*** + All identation should consist of four space blocks ***/
  20. /*** + Tab characters are evil. ***/
  21. /*** + all comments should use "slash-star ... star-slash" ***/
  22. /*** style -- no pound characters, no slash-slash style ***/
  23. /*** + FLOW CONTROL STATEMENTS (if, while, etc) SHOULD ***/
  24. /*** ALWAYS USE { AND } CHARACTERS!!! ***/
  25. /*** + Please use ' instead of ", when possible. Note " ***/
  26. /*** should always be used in _( ) function calls. ***/
  27. /*** Thank you for your help making the SM code more readable. ***/
  28. /*****************************************************************/
  29. global $squirrelmail_plugin_hooks;
  30. $squirrelmail_plugin_hooks = array();
  31. // This function adds a plugin
  32. function use_plugin ($name) {
  33. if (file_exists('../plugins/'.$name.'/setup.php')) {
  34. include_once('../plugins/'.$name.'/setup.php');
  35. $function = 'squirrelmail_plugin_init_'.$name;
  36. if (function_exists($function)) {
  37. $function();
  38. }
  39. }
  40. }
  41. // This function executes a hook
  42. function do_hook ($name) {
  43. global $squirrelmail_plugin_hooks;
  44. $Data = func_get_args();
  45. if (isset($squirrelmail_plugin_hooks[$name]) &&
  46. is_array($squirrelmail_plugin_hooks[$name])) {
  47. foreach ($squirrelmail_plugin_hooks[$name] as $function) {
  48. // Add something to set correct gettext domain for plugin
  49. if (function_exists($function)) {
  50. $function($Data);
  51. }
  52. }
  53. }
  54. // Variable-length argument lists have a slight problem when
  55. // passing values by reference. Pity. This is a workaround.
  56. return $Data;
  57. }
  58. /* -------------------- MAIN --------------------- */
  59. // On startup, register all plugins configured for use
  60. if (isset($plugins) && is_array($plugins)) {
  61. foreach ($plugins as $name) {
  62. use_plugin($name);
  63. }
  64. }
  65. ?>