plugin.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. ** plugin.php
  4. **
  5. ** This file provides the framework for a plugin architecture.
  6. **
  7. ** Plugins will eventually be a way to provide added functionality
  8. ** without having to patch the SquirrelMail source code. Have some
  9. ** patience, though, as the these funtions might change in the near
  10. ** future.
  11. **
  12. ** Documentation on how to write plugins might show up some time.
  13. **
  14. ** $Id$
  15. **/
  16. $plugin_php = true;
  17. // This function adds a plugin
  18. function use_plugin ($name) {
  19. if (file_exists('../plugins/'.$name.'/setup.php')) {
  20. include ('../plugins/'.$name.'/setup.php');
  21. $function = 'squirrelmail_plugin_init_'.$name;
  22. if (function_exists($function))
  23. $function();
  24. }
  25. }
  26. // This function executes a hook
  27. function do_hook ($name) {
  28. global $squirrelmail_plugin_hooks;
  29. $Data = func_get_args();
  30. if (isset($squirrelmail_plugin_hooks[$name]) &&
  31. is_array($squirrelmail_plugin_hooks[$name])) {
  32. foreach ($squirrelmail_plugin_hooks[$name] as $id => $function) {
  33. // Add something to set correct gettext domain for plugin
  34. if (function_exists($function)) {
  35. $function($Data);
  36. }
  37. }
  38. }
  39. // Variable-length argument lists have a slight problem when
  40. // passing values by reference. Pity. This is a workaround.
  41. return $Data;
  42. }
  43. // On startup, register all plugins configured for use
  44. if (isset($plugins) && is_array($plugins))
  45. foreach ($plugins as $id => $name)
  46. use_plugin($name);
  47. ?>