]>
git.wh0rd.org - tt-rss.git/blob - classes/pluginhost.php
4 private $hooks = array();
5 private $plugins = array();
6 private $handlers = array();
8 const HOOK_ARTICLE_BUTTON
= 1;
9 const HOOK_ARTICLE_FILTER
= 2;
10 const HOOK_PREFS_TAB
= 3;
11 const HOOK_PREFS_SECTION
= 4;
13 function __construct($link) {
17 private function register_plugin($name, $plugin) {
18 //array_push($this->plugins, $plugin);
19 $this->plugins
[$name] = $plugin;
26 function get_plugins() {
27 return $this->plugins
;
30 function get_plugin($name) {
31 return $this->plugins
[$name];
34 function run_hooks($type, $method, $args) {
35 foreach ($this->get_hooks($type) as $hook) {
36 $hook->$method($args);
40 function add_hook($type, $sender) {
41 if (!is_array($this->hooks
[$type])) {
42 $this->hooks
[$type] = array();
45 array_push($this->hooks
[$type], $sender);
48 function del_hook($type, $sender) {
49 if (is_array($this->hooks
[$type])) {
50 $key = array_Search($this->hooks
[$type], $sender);
52 unset($this->hooks
[$type][$key]);
57 function get_hooks($type) {
58 return $this->hooks
[$type];
61 function load($classlist) {
62 $plugins = explode(",", $classlist);
64 foreach ($plugins as $class) {
65 $class = trim($class);
66 $class_file = strtolower(basename($class));
67 $file = dirname(__FILE__
)."/../plugins/$class_file/$class_file.php";
69 if (file_exists($file)) require_once $file;
71 if (class_exists($class) && is_subclass_of($class, "Plugin")) {
72 $plugin = new $class($this);
74 $this->register_plugin($class, $plugin);
79 function add_handler($handler, $method, $sender) {
80 $handler = strtolower($handler);
81 $method = strtolower($method);
83 if (!is_array($this->handlers
[$handler])) {
84 $this->handlers
[$handler] = array();
87 $this->handlers
[$handler][$method] = $sender;
90 function del_handler($handler, $method) {
91 $handler = strtolower($handler);
92 $method = strtolower($method);
94 unset($this->handlers
[$handler][$method]);
97 function lookup_handler($handler, $method) {
98 $handler = strtolower($handler);
99 $method = strtolower($method);
101 if (is_array($this->handlers
[$handler])) {
102 return $this->handlers
[$handler][$method];