From 3b06ee0d381dc1be5f40ca98ad4278046d869d21 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sun, 17 Nov 2019 20:57:39 +0100 Subject: checked in initial customized verison for Archlinux32 --- include/addons.php | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 include/addons.php (limited to 'include/addons.php') diff --git a/include/addons.php b/include/addons.php new file mode 100644 index 0000000..8a0ff48 --- /dev/null +++ b/include/addons.php @@ -0,0 +1,84 @@ +loaded = true; + + $d = dir(PUN_ROOT.'addons'); + if (!$d) return; + + while (($addon_file = $d->read()) !== false) + { + if (!is_dir(PUN_ROOT.'addons/'.$addon_file) && preg_match('%(\w+)\.php$%', $addon_file)) + { + $addon_name = 'addon_'.substr($addon_file, 0, -4); + + include PUN_ROOT.'addons/'.$addon_file; + $addon = new $addon_name; + + $addon->register($this); + } + } + $d->close(); + } + + function bind($hook, $callback) + { + if (!isset($this->hooks[$hook])) + $this->hooks[$hook] = array(); + + if (is_callable($callback)) + $this->hooks[$hook][] = $callback; + } + + function hook($name) + { + if (!$this->loaded) + $this->load(); + + $callbacks = isset($this->hooks[$name]) ? $this->hooks[$name] : array(); + + // Execute every registered callback for this hook + foreach ($callbacks as $callback) + { + list($addon, $method) = $callback; + $addon->$method(); + } + } +} + + +/** + * Class flux_addon + * + * This class can be extended to provide addon functionality. + * Subclasses should implement the register method which will be called so that they have a chance to register possible + * listeners for all hooks. + */ +class flux_addon +{ + function register($manager) + { } +} -- cgit v1.2.3-54-g00ecf