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