]>
git.wh0rd.org - tt-rss.git/blob - classes/pluginhost.php
4 private $hooks = array();
5 private $plugins = array();
6 private $handlers = array();
7 private $commands = array();
9 const HOOK_ARTICLE_BUTTON
= 1;
10 const HOOK_ARTICLE_FILTER
= 2;
11 const HOOK_PREFS_TAB
= 3;
12 const HOOK_PREFS_SECTION
= 4;
13 const HOOK_PREFS_TABS
= 5;
15 function __construct($link) {
19 private function register_plugin($name, $plugin) {
20 //array_push($this->plugins, $plugin);
21 $this->plugins
[$name] = $plugin;
28 function get_plugins() {
29 return $this->plugins
;
32 function get_plugin($name) {
33 return $this->plugins
[$name];
36 function run_hooks($type, $method, $args) {
37 foreach ($this->get_hooks($type) as $hook) {
38 $hook->$method($args);
42 function add_hook($type, $sender) {
43 if (!is_array($this->hooks
[$type])) {
44 $this->hooks
[$type] = array();
47 array_push($this->hooks
[$type], $sender);
50 function del_hook($type, $sender) {
51 if (is_array($this->hooks
[$type])) {
52 $key = array_Search($this->hooks
[$type], $sender);
54 unset($this->hooks
[$type][$key]);
59 function get_hooks($type) {
60 if (isset($this->hooks
[$type])) {
61 return $this->hooks
[$type];
67 function load($classlist) {
68 $plugins = explode(",", $classlist);
70 foreach ($plugins as $class) {
71 $class = trim($class);
72 $class_file = strtolower(basename($class));
73 $file = dirname(__FILE__
)."/../plugins/$class_file/$class_file.php";
75 if (file_exists($file)) require_once $file;
77 if (class_exists($class) && is_subclass_of($class, "Plugin")) {
78 $plugin = new $class($this);
80 $this->register_plugin($class, $plugin);
85 function add_handler($handler, $method, $sender) {
86 $handler = str_replace("-", "_", strtolower($handler));
87 $method = strtolower($method);
89 if (!is_array($this->handlers
[$handler])) {
90 $this->handlers
[$handler] = array();
93 $this->handlers
[$handler][$method] = $sender;
96 function del_handler($handler, $method) {
97 $handler = str_replace("-", "_", strtolower($handler));
98 $method = strtolower($method);
100 unset($this->handlers
[$handler][$method]);
103 function lookup_handler($handler, $method) {
104 $handler = str_replace("-", "_", strtolower($handler));
105 $method = strtolower($method);
107 if (is_array($this->handlers
[$handler])) {
108 if (isset($this->handlers
[$handler]["*"])) {
109 return $this->handlers
[$handler]["*"];
111 return $this->handlers
[$handler][$method];
118 function add_command($command, $description, $sender) {
119 $command = "-" . str_replace("-", "_", strtolower($command));
121 $this->commands
[$command] = array("description" => $description,
125 function del_command($command) {
126 $command = "-" . strtolower($command);
128 unset($this->commands
[$command]);
131 function lookup_command($command) {
132 $command = "-" . strtolower($command);
134 if (is_array($this->commands
[$command])) {
135 return $this->commands
[$command]["class"];
143 function get_commands() {
144 return $this->commands
;
147 function run_commands($args) {
148 foreach ($this->get_commands() as $command => $data) {
149 if (in_array($command, $args)) {
150 $command = str_replace("-", "", $command);
151 $data["class"]->$command($args);