]>
Commit | Line | Data |
---|---|---|
19c73507 AD |
1 | <?php |
2 | class PluginHost { | |
3 | private $link; | |
4 | private $hooks = array(); | |
5 | private $plugins = array(); | |
6 | ||
7 | const HOOK_ARTICLE_BUTTON = 1; | |
8 | const HOOK_ARTICLE_FILTER = 2; | |
9 | ||
10 | function __construct($link) { | |
11 | $this->link = $link; | |
12 | } | |
13 | ||
14 | private function register_plugin($name, $plugin) { | |
15 | //array_push($this->plugins, $plugin); | |
16 | $this->plugins[$name] = $plugin; | |
17 | } | |
18 | ||
19 | function get_link() { | |
20 | return $this->link; | |
21 | } | |
22 | ||
23 | function get_plugins() { | |
24 | return $this->plugins; | |
25 | } | |
26 | ||
27 | function get_plugin($name) { | |
28 | return $this->plugins[$name]; | |
29 | } | |
30 | ||
31 | function add_hook($type, $sender) { | |
32 | if (!is_array($this->hooks[$type])) { | |
33 | $this->hooks[$type] = array(); | |
34 | } | |
35 | ||
36 | array_push($this->hooks[$type], $sender); | |
37 | } | |
38 | ||
39 | function del_hook($type, $sender) { | |
40 | if (is_array($this->hooks[$type])) { | |
41 | $key = array_Search($this->hooks[$type], $sender); | |
42 | if ($key !== FALSE) { | |
43 | unset($this->hooks[$type][$key]); | |
44 | } | |
45 | } | |
46 | } | |
47 | ||
48 | function get_hooks($type) { | |
49 | return $this->hooks[$type]; | |
50 | } | |
51 | ||
52 | function load($classlist) { | |
53 | $plugins = explode(",", $classlist); | |
54 | ||
55 | foreach ($plugins as $class) { | |
56 | $class = trim($class); | |
57 | $class_file = str_replace("_", "/", strtolower(basename($class))); | |
58 | $file = dirname(__FILE__)."/../plugins/$class_file/$class_file.php"; | |
59 | ||
60 | if (file_exists($file)) require_once $file; | |
61 | ||
62 | if (class_exists($class)) { | |
63 | $plugin = new $class($this); | |
64 | ||
65 | $this->register_plugin($class, $plugin); | |
66 | } | |
67 | } | |
68 | } | |
69 | ||
70 | } | |
71 | ?> |