]> git.wh0rd.org - tt-rss.git/blob - classes/plugins.php
expand error messages in subscribeToFeed(), provide proper error message
[tt-rss.git] / classes / plugins.php
1 <?php
2 class Plugins {
3 protected $link;
4 protected $plugins;
5 protected $listeners;
6
7 function __construct($link) {
8 $this->link = $link;
9 $this->listeners = array();
10 $this->load_plugins();
11 }
12
13 function load_plugins() {
14 if (defined('_ENABLE_PLUGINS')) {
15 $plugins = explode(",", _ENABLE_PLUGINS);
16
17 foreach ($plugins as $p) {
18 $plugin_class = "plugin_$p";
19 if (class_exists($plugin_class)) {
20 $plugin = new $plugin_class($this->link, $this);
21 }
22 }
23 }
24 }
25
26 function add_listener($hook_name, $plugin) {
27 if (!is_array($this->listeners[$hook_name]))
28 $this->listeners[$hook_name] = array();
29
30 array_push($this->listeners[$hook_name], $plugin);
31 }
32
33 function hook($hook_name, &$params) {
34 if (is_array($this->listeners[$hook_name])) {
35 foreach ($this->listeners[$hook_name] as $p) {
36 if (method_exists($p, $hook_name)) {
37 $p->$hook_name($params);
38 }
39 }
40 }
41 }
42
43 }
44 ?>