]>
git.wh0rd.org - tt-rss.git/blob - classes/pluginhost.php
46415bd214874b18de66ebf37e9c153f9070d85d
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;
12 const HOOK_PREFS_TABS
= 5;
14 function __construct($link) {
18 private function register_plugin($name, $plugin) {
19 //array_push($this->plugins, $plugin);
20 $this->plugins
[$name] = $plugin;
27 function get_plugins() {
28 return $this->plugins
;
31 function get_plugin($name) {
32 return $this->plugins
[$name];
35 function run_hooks($type, $method, $args) {
36 foreach ($this->get_hooks($type) as $hook) {
37 $hook->$method($args);
41 function add_hook($type, $sender) {
42 if (!is_array($this->hooks
[$type])) {
43 $this->hooks
[$type] = array();
46 array_push($this->hooks
[$type], $sender);
49 function del_hook($type, $sender) {
50 if (is_array($this->hooks
[$type])) {
51 $key = array_Search($this->hooks
[$type], $sender);
53 unset($this->hooks
[$type][$key]);
58 function get_hooks($type) {
59 return $this->hooks
[$type];
62 function load($classlist) {
63 $plugins = explode(",", $classlist);
65 foreach ($plugins as $class) {
66 $class = trim($class);
67 $class_file = strtolower(basename($class));
68 $file = dirname(__FILE__
)."/../plugins/$class_file/$class_file.php";
70 if (file_exists($file)) require_once $file;
72 if (class_exists($class) && is_subclass_of($class, "Plugin")) {
73 $plugin = new $class($this);
75 $this->register_plugin($class, $plugin);
80 function add_handler($handler, $method, $sender) {
81 $handler = str_replace("-", "_", strtolower($handler));
82 $method = strtolower($method);
84 if (!is_array($this->handlers
[$handler])) {
85 $this->handlers
[$handler] = array();
88 $this->handlers
[$handler][$method] = $sender;
91 function del_handler($handler, $method) {
92 $handler = str_replace("-", "_", strtolower($handler));
93 $method = strtolower($method);
95 unset($this->handlers
[$handler][$method]);
98 function lookup_handler($handler, $method) {
99 $handler = str_replace("-", "_", strtolower($handler));
100 $method = strtolower($method);
102 if (is_array($this->handlers
[$handler])) {
103 if (isset($this->handlers
[$handler]["*"])) {
104 return $this->handlers
[$handler]["*"];
106 return $this->handlers
[$handler][$method];