plugin.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. /**
  3. * plugin.php
  4. *
  5. * Copyright (c) 1999-2003 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(SM_PATH . "plugins/$name/setup.php")) {
  19. include_once(SM_PATH . "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. $ret = '';
  31. if (isset($squirrelmail_plugin_hooks[$name])
  32. && is_array($squirrelmail_plugin_hooks[$name])) {
  33. foreach ($squirrelmail_plugin_hooks[$name] as $function) {
  34. /* Add something to set correct gettext domain for plugin. */
  35. if (function_exists($function)) {
  36. $function($data);
  37. }
  38. }
  39. }
  40. /* Variable-length argument lists have a slight problem when */
  41. /* passing values by reference. Pity. This is a workaround. */
  42. return $data;
  43. }
  44. /* This function executes a hook. */
  45. function do_hook_function($name,$parm=NULL) {
  46. global $squirrelmail_plugin_hooks;
  47. $ret = '';
  48. if (isset($squirrelmail_plugin_hooks[$name])
  49. && is_array($squirrelmail_plugin_hooks[$name])) {
  50. foreach ($squirrelmail_plugin_hooks[$name] as $function) {
  51. /* Add something to set correct gettext domain for plugin. */
  52. if (function_exists($function)) {
  53. $ret = $function($parm);
  54. }
  55. }
  56. }
  57. /* Variable-length argument lists have a slight problem when */
  58. /* passing values by reference. Pity. This is a workaround. */
  59. return $ret;
  60. }
  61. /**
  62. * This function checks whether the user's USER_AGENT is known to
  63. * be broken. If so, returns true and the plugin is invisible to the
  64. * offending browser.
  65. */
  66. function soupNazi(){
  67. $soup_menu = array('Mozilla/3','Mozilla/2','Mozilla/1', 'Opera 4',
  68. 'Opera/4', 'OmniWeb', 'Lynx');
  69. foreach($soup_menu as $browser) {
  70. if(stristr($_SERVER['HTTP_USER_AGENT'], $browser)) {
  71. return 1;
  72. }
  73. }
  74. return 0;
  75. }
  76. /*************************************/
  77. /*** MAIN PLUGIN LOADING CODE HERE ***/
  78. /*************************************/
  79. /* On startup, register all plugins configured for use. */
  80. if (isset($plugins) && is_array($plugins)) {
  81. foreach ($plugins as $name) {
  82. use_plugin($name);
  83. }
  84. }
  85. ?>