plugin.php 2.6 KB

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