plugin.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. **/
  15. $plugin_php = true;
  16. // This function adds a plugin
  17. function use_plugin ($name) {
  18. if (file_exists('../plugins/'.$name.'/setup.php')) {
  19. include ('../plugins/'.$name.'/setup.php');
  20. $function = 'squirrelmail_plugin_init_'.$name;
  21. if (function_exists($function))
  22. $function();
  23. }
  24. }
  25. // This function executes a hook
  26. function do_hook ($name) {
  27. global $squirrelmail_plugin_hooks;
  28. $Data = func_get_args();
  29. if (is_array($squirrelmail_plugin_hooks[$name])) {
  30. foreach ($squirrelmail_plugin_hooks[$name] as $id => $function) {
  31. // Add something to set correct gettext domain for plugin
  32. if (function_exists($function)) {
  33. $function(&$Data);
  34. }
  35. }
  36. }
  37. // Variable-length argument lists have a slight problem when
  38. // passing values by reference. Pity. This is a workaround.
  39. return $Data;
  40. }
  41. // On startup, register all plugins configured for use
  42. if (is_array($plugins))
  43. foreach ($plugins as $id => $name)
  44. use_plugin($name);
  45. ?>