]>
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 return $this->hooks
[$type];
63 function load($classlist) {
64 $plugins = explode(",", $classlist);
66 foreach ($plugins as $class) {
67 $class = trim($class);
68 $class_file = strtolower(basename($class));
69 $file = dirname(__FILE__
)."/../plugins/$class_file/$class_file.php";
71 if (file_exists($file)) require_once $file;
73 if (class_exists($class) && is_subclass_of($class, "Plugin")) {
74 $plugin = new $class($this);
76 $this->register_plugin($class, $plugin);
81 function add_handler($handler, $method, $sender) {
82 $handler = str_replace("-", "_", strtolower($handler));
83 $method = strtolower($method);
85 if (!is_array($this->handlers
[$handler])) {
86 $this->handlers
[$handler] = array();
89 $this->handlers
[$handler][$method] = $sender;
92 function del_handler($handler, $method) {
93 $handler = str_replace("-", "_", strtolower($handler));
94 $method = strtolower($method);
96 unset($this->handlers
[$handler][$method]);
99 function lookup_handler($handler, $method) {
100 $handler = str_replace("-", "_", strtolower($handler));
101 $method = strtolower($method);
103 if (is_array($this->handlers
[$handler])) {
104 if (isset($this->handlers
[$handler]["*"])) {
105 return $this->handlers
[$handler]["*"];
107 return $this->handlers
[$handler][$method];
114 function add_command($command, $description, $sender) {
115 $command = "-" . str_replace("-", "_", strtolower($command));
117 $this->commands
[$command] = array("description" => $description,
121 function del_command($command) {
122 $command = "-" . strtolower($command);
124 unset($this->commands
[$command]);
127 function lookup_command($command) {
128 $command = "-" . strtolower($command);
130 if (is_array($this->commands
[$command])) {
131 return $this->commands
[$command]["class"];
139 function get_commands() {
140 return $this->commands
;
143 function run_commands($args) {
144 foreach ($this->get_commands() as $command => $data) {
145 if (in_array($command, $args)) {
146 $command = str_replace("-", "", $command);
147 $data["class"]->$command($args);