summaryrefslogtreecommitdiff
path: root/include/addons.php
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2019-11-17 20:57:39 +0100
committerAndreas Baumann <mail@andreasbaumann.cc>2019-11-17 20:57:39 +0100
commit3b06ee0d381dc1be5f40ca98ad4278046d869d21 (patch)
treed31e79fc57d882b8267f40c3434480bb58a3ca73 /include/addons.php
downloadfluxbb-master.tar.xz
checked in initial customized verison for Archlinux32HEADmaster
Diffstat (limited to 'include/addons.php')
-rw-r--r--include/addons.php84
1 files changed, 84 insertions, 0 deletions
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 @@
+<?php
+
+/**
+ * Copyright (C) 2008-2012 FluxBB
+ * based on code by Rickard Andersson copyright (C) 2002-2008 PunBB
+ * License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
+ */
+
+// Make sure no one attempts to run this script "directly"
+if (!defined('PUN'))
+ exit;
+
+
+/**
+ * Class flux_addon_manager
+ *
+ * This class is responsible for loading the addons and storing their hook listeners.
+ */
+class flux_addon_manager
+{
+ var $hooks = array();
+
+ var $loaded = false;
+
+ function load()
+ {
+ $this->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)
+ { }
+}