plugin.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * plugin.php
  4. *
  5. * Copyright (c) 1999-2002 The SquirrelMail Project 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. global $squirrelmail_plugin_hooks;
  15. $squirrelmail_plugin_hooks = array();
  16. /* This function adds a plugin. */
  17. function use_plugin ($name) {
  18. if (file_exists("../plugins/$name/setup.php")) {
  19. include_once("../plugins/$name/setup.php");
  20. $function = "squirrelmail_plugin_init_$name";
  21. if (function_exists($function)) {
  22. $function();
  23. }
  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 $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. /*************************************/
  44. /*** MAIN PLUGIN LOADING CODE HERE ***/
  45. /*************************************/
  46. /* On startup, register all plugins configured for use. */
  47. if (isset($plugins) && is_array($plugins)) {
  48. foreach ($plugins as $name) {
  49. use_plugin($name);
  50. }
  51. }
  52. /**
  53. * This function checks whether the user's USER_AGENT is known to
  54. * be broken. If so, returns true and the plugin is invisible to the
  55. * offending browser.
  56. */
  57. function soupNazi(){
  58. global $HTTP_USER_AGENT, $SQSPELL_SOUP_NAZI;
  59. require_once('../plugins/squirrelspell/sqspell_config.php');
  60. $soup_menu = explode( ',', $SQSPELL_SOUP_NAZI );
  61. return( in_array( trim( $HTTP_USER_AGENT ), $soup_menu ) );
  62. }
  63. ?>