]>
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;
14 const HOOK_FEED_PARSED
= 6;
16 function __construct($link) {
20 private function register_plugin($name, $plugin) {
21 //array_push($this->plugins, $plugin);
22 $this->plugins
[$name] = $plugin;
29 function get_plugins() {
30 return $this->plugins
;
33 function get_plugin($name) {
34 return $this->plugins
[$name];
37 function run_hooks($type, $method, $args) {
38 foreach ($this->get_hooks($type) as $hook) {
39 $hook->$method($args);
43 function add_hook($type, $sender) {
44 if (!is_array($this->hooks
[$type])) {
45 $this->hooks
[$type] = array();
48 array_push($this->hooks
[$type], $sender);
51 function del_hook($type, $sender) {
52 if (is_array($this->hooks
[$type])) {
53 $key = array_Search($this->hooks
[$type], $sender);
55 unset($this->hooks
[$type][$key]);
60 function get_hooks($type) {
61 if (isset($this->hooks
[$type])) {
62 return $this->hooks
[$type];
68 function load($classlist) {
69 $plugins = explode(",", $classlist);
71 foreach ($plugins as $class) {
72 $class = trim($class);
73 $class_file = strtolower(basename($class));
74 $file = dirname(__FILE__
)."/../plugins/$class_file/$class_file.php";
76 if (file_exists($file)) require_once $file;
78 if (class_exists($class) && is_subclass_of($class, "Plugin")) {
79 $plugin = new $class($this);
81 $this->register_plugin($class, $plugin);
86 function add_handler($handler, $method, $sender) {
87 $handler = str_replace("-", "_", strtolower($handler));
88 $method = strtolower($method);
90 if (!is_array($this->handlers
[$handler])) {
91 $this->handlers
[$handler] = array();
94 $this->handlers
[$handler][$method] = $sender;
97 function del_handler($handler, $method) {
98 $handler = str_replace("-", "_", strtolower($handler));
99 $method = strtolower($method);
101 unset($this->handlers
[$handler][$method]);
104 function lookup_handler($handler, $method) {
105 $handler = str_replace("-", "_", strtolower($handler));
106 $method = strtolower($method);
108 if (is_array($this->handlers
[$handler])) {
109 if (isset($this->handlers
[$handler]["*"])) {
110 return $this->handlers
[$handler]["*"];
112 return $this->handlers
[$handler][$method];
119 function add_command($command, $description, $sender) {
120 $command = "-" . str_replace("-", "_", strtolower($command));
122 $this->commands
[$command] = array("description" => $description,
126 function del_command($command) {
127 $command = "-" . strtolower($command);
129 unset($this->commands
[$command]);
132 function lookup_command($command) {
133 $command = "-" . strtolower($command);
135 if (is_array($this->commands
[$command])) {
136 return $this->commands
[$command]["class"];
144 function get_commands() {
145 return $this->commands
;
148 function run_commands($args) {
149 foreach ($this->get_commands() as $command => $data) {
150 if (in_array($command, $args)) {
151 $command = str_replace("-", "", $command);
152 $data["class"]->$command($args);