summaryrefslogtreecommitdiff
path: root/classes/plugins.php
blob: 6f3720ca9a61932b8b15d863a8733a43fd229d43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
class Plugins {
	protected $link;
	protected $plugins;
	protected $listeners;

	function __construct($link) {
		$this->link = $link;
		$this->listeners = array();
		$this->load_plugins();
	}

	function load_plugins() {
		if (defined('_ENABLE_PLUGINS')) {
			$plugins = explode(",", _ENABLE_PLUGINS);

			foreach ($plugins as $p) {
				$plugin_class = "plugin_$p";
				if (class_exists($plugin_class)) {
					$plugin = new $plugin_class($this->link, $this);
				}
			}
		}
	}

	function add_listener($hook_name, $plugin) {
		if (!is_array($this->listeners[$hook_name]))
			$this->listeners[$hook_name] = array();

		array_push($this->listeners[$hook_name], $plugin);
	}

	function hook($hook_name, &$params) {
		if (is_array($this->listeners[$hook_name])) {
			foreach ($this->listeners[$hook_name] as $p) {
				if (method_exists($p, $hook_name)) {
					$p->$hook_name($params);
				}
			}
		}
	}

}
?>