Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

plugin.inc.php 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /* Poweradmin, a friendly web-based admin tool for PowerDNS.
  3. * See <http://www.poweradmin.org> for more details.
  4. *
  5. * Copyright 2007-2009 Rejo Zenger <rejo@zenger.nl>
  6. * Copyright 2010-2017 Poweradmin Development Team
  7. * <http://www.poweradmin.org/credits.html>
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * Plugin API
  24. *
  25. * Dynamically add behavior by putting code in the plugins directory
  26. * of the application root. For the loader to include a plugin,
  27. * there must be a file named:
  28. *
  29. * plugins/[name]/[name].plugin.php
  30. *
  31. * Further imports, functions, or definitions can be done from
  32. * that top-level script.
  33. */
  34. $hook_listeners = array();
  35. /**
  36. * Register function to be executed for the given hook
  37. *
  38. * @param string $hook
  39. * @param mixed $function
  40. */
  41. function add_listener($hook, $function) {
  42. if (!$hook || !$function) {
  43. trigger_error('add_listener requires both a hook name and a function', E_USER_ERROR);
  44. }
  45. global $hook_listeners;
  46. $hook_listeners [$hook] [] = $function;
  47. }
  48. /**
  49. * Removes all listeners from the given hook
  50. *
  51. * @param string $hook
  52. */
  53. function clear_listeners($hook) {
  54. if (!$hook) {
  55. trigger_error('clear_listeners requires a hook name', E_USER_ERROR);
  56. }
  57. global $hook_listeners;
  58. $hook_listeners [$hook] = array();
  59. }
  60. /**
  61. * Execute a hook, call registered listener functions
  62. */
  63. function do_hook() {
  64. global $hook_listeners;
  65. $argc = func_num_args();
  66. $argv = func_get_args();
  67. if ($argc < 1) {
  68. trigger_error('Missing argument in do_hook', E_USER_ERROR);
  69. }
  70. $hook_name = array_shift($argv);
  71. if (!isset($hook_listeners [$hook_name])) {
  72. return;
  73. }
  74. foreach ($hook_listeners [$hook_name] as $func) {
  75. $response = call_user_func_array($func, (array) $argv);
  76. return $response;
  77. }
  78. }
  79. /**
  80. * Look for plugins and perform imports
  81. */
  82. function import_plugins() {
  83. $plugins_dir = 'inc/plugins';
  84. $contents = scandir($plugins_dir);
  85. foreach ($contents as $dir) {
  86. if ($dir == '.' || $dir == '..') {
  87. continue;
  88. }
  89. $plugin_file = $plugins_dir . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR . $dir . '.plugin.php';
  90. if (file_exists($plugin_file)) {
  91. require_once $plugin_file;
  92. }
  93. }
  94. }
  95. import_plugins();