plugin.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. $plugin_general_debug = false;
  18. // This function adds a plugin
  19. function use_plugin ($name) {
  20. global $plugin_general_debug;
  21. if (file_exists('../plugins/'.$name.'/setup.php')) {
  22. if ($plugin_general_debug)
  23. echo "plugin: -- Loading $name/setup.php<br>\n";
  24. include ('../plugins/'.$name.'/setup.php');
  25. $function = 'squirrelmail_plugin_init_'.$name;
  26. if (function_exists($function))
  27. {
  28. if ($plugin_general_debug)
  29. echo "plugin: ---- Executing $function to init plugin<br>\n";
  30. $function($plugin_general_debug);
  31. }
  32. elseif ($plugin_general_debug)
  33. echo "plugin: -- Init function $function doesn't exist.<br>\n";
  34. }
  35. elseif ($plugin_general_debug)
  36. echo "plugin: Couldn't find $name/setup.php<br>\n";
  37. }
  38. // This function executes a hook
  39. function do_hook ($name) {
  40. global $squirrelmail_plugin_hooks;
  41. $Data = func_get_args();
  42. if (isset($squirrelmail_plugin_hooks[$name]) &&
  43. is_array($squirrelmail_plugin_hooks[$name])) {
  44. foreach ($squirrelmail_plugin_hooks[$name] as $id => $function) {
  45. // Add something to set correct gettext domain for plugin
  46. if (function_exists($function)) {
  47. $function($Data);
  48. }
  49. }
  50. }
  51. // Variable-length argument lists have a slight problem when
  52. // passing values by reference. Pity. This is a workaround.
  53. return $Data;
  54. }
  55. // On startup, register all plugins configured for use
  56. if (isset($plugins) && is_array($plugins))
  57. foreach ($plugins as $id => $name)
  58. {
  59. if ($plugin_general_debug)
  60. echo "plugin: Attempting load of plugin $name<br>\n";
  61. use_plugin($name);
  62. }
  63. ?>