plugin.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. require_once(SM_PATH . 'functions/global.php');
  15. global $squirrelmail_plugin_hooks;
  16. $squirrelmail_plugin_hooks = array();
  17. /* This function adds a plugin. */
  18. function use_plugin ($name) {
  19. if (file_exists(SM_PATH . "plugins/$name/setup.php")) {
  20. include_once(SM_PATH . "plugins/$name/setup.php");
  21. $function = "squirrelmail_plugin_init_$name";
  22. if (function_exists($function)) {
  23. $function();
  24. }
  25. }
  26. }
  27. /* This function executes a hook. */
  28. function do_hook ($name) {
  29. global $squirrelmail_plugin_hooks;
  30. $data = func_get_args();
  31. $ret = '';
  32. if (isset($squirrelmail_plugin_hooks[$name])
  33. && is_array($squirrelmail_plugin_hooks[$name])) {
  34. foreach ($squirrelmail_plugin_hooks[$name] as $function) {
  35. /* Add something to set correct gettext domain for plugin. */
  36. if (function_exists($function)) {
  37. $function($data);
  38. }
  39. }
  40. }
  41. /* Variable-length argument lists have a slight problem when */
  42. /* passing values by reference. Pity. This is a workaround. */
  43. return $data;
  44. }
  45. /* This function executes a hook. */
  46. function do_hook_function($name,$parm=NULL) {
  47. global $squirrelmail_plugin_hooks;
  48. $ret = '';
  49. if (isset($squirrelmail_plugin_hooks[$name])
  50. && is_array($squirrelmail_plugin_hooks[$name])) {
  51. foreach ($squirrelmail_plugin_hooks[$name] as $function) {
  52. /* Add something to set correct gettext domain for plugin. */
  53. if (function_exists($function)) {
  54. $ret = $function($parm);
  55. }
  56. }
  57. }
  58. /* Variable-length argument lists have a slight problem when */
  59. /* passing values by reference. Pity. This is a workaround. */
  60. return $ret;
  61. }
  62. /* This function executes a hook. */
  63. function concat_hook_function($name,$parm=NULL) {
  64. global $squirrelmail_plugin_hooks;
  65. $ret = '';
  66. if (isset($squirrelmail_plugin_hooks[$name])
  67. && is_array($squirrelmail_plugin_hooks[$name])) {
  68. foreach ($squirrelmail_plugin_hooks[$name] as $function) {
  69. /* Concatenate results from hook. */
  70. if (function_exists($function)) {
  71. $ret .= $function($parm);
  72. }
  73. }
  74. }
  75. /* Variable-length argument lists have a slight problem when */
  76. /* passing values by reference. Pity. This is a workaround. */
  77. return $ret;
  78. }
  79. /**
  80. * This function checks whether the user's USER_AGENT is known to
  81. * be broken. If so, returns true and the plugin is invisible to the
  82. * offending browser.
  83. */
  84. function soupNazi(){
  85. $soup_menu = array('Mozilla/3','Mozilla/2','Mozilla/1', 'Opera 4',
  86. 'Opera/4', 'OmniWeb', 'Lynx');
  87. sqgetGlobalVar('HTTP_USER_AGENT', $user_agent, SQ_SERVER);
  88. foreach($soup_menu as $browser) {
  89. if(stristr($user_agent, $browser)) {
  90. return 1;
  91. }
  92. }
  93. return 0;
  94. }
  95. /*************************************/
  96. /*** MAIN PLUGIN LOADING CODE HERE ***/
  97. /*************************************/
  98. /* On startup, register all plugins configured for use. */
  99. if (isset($plugins) && is_array($plugins)) {
  100. foreach ($plugins as $name) {
  101. use_plugin($name);
  102. }
  103. }
  104. ?>