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;
15 const HOOK_UPDATE_TASK = 7;
17 function __construct($link) {
21 private function register_plugin($name, $plugin) {
22 //array_push($this->plugins, $plugin);
23 $this->plugins[$name] = $plugin;
30 function get_plugins() {
31 return $this->plugins;
34 function get_plugin($name) {
35 return $this->plugins[$name];
38 function run_hooks($type, $method, $args) {
39 foreach ($this->get_hooks($type) as $hook) {
40 $hook->$method($args);
44 function add_hook($type, $sender) {
45 if (!is_array($this->hooks[$type])) {
46 $this->hooks[$type] = array();
49 array_push($this->hooks[$type], $sender);
52 function del_hook($type, $sender) {
53 if (is_array($this->hooks[$type])) {
54 $key = array_Search($this->hooks[$type], $sender);
56 unset($this->hooks[$type][$key]);
61 function get_hooks($type) {
62 if (isset($this->hooks[$type])) {
63 return $this->hooks[$type];
69 function load($classlist) {
70 $plugins = explode(",", $classlist);
72 foreach ($plugins as $class) {
73 $class = trim($class);
74 $class_file = strtolower(basename($class));
75 $file = dirname(__FILE__)."/../plugins/$class_file/$class_file.php";
77 if (file_exists($file)) require_once $file;
79 if (class_exists($class) && is_subclass_of($class, "Plugin")) {
80 $plugin = new $class($this);
82 $this->register_plugin($class, $plugin);
87 function add_handler($handler, $method, $sender) {
88 $handler = str_replace("-", "_", strtolower($handler));
89 $method = strtolower($method);
91 if (!is_array($this->handlers[$handler])) {
92 $this->handlers[$handler] = array();
95 $this->handlers[$handler][$method] = $sender;
98 function del_handler($handler, $method) {
99 $handler = str_replace("-", "_", strtolower($handler));
100 $method = strtolower($method);
102 unset($this->handlers[$handler][$method]);
105 function lookup_handler($handler, $method) {
106 $handler = str_replace("-", "_", strtolower($handler));
107 $method = strtolower($method);
109 if (is_array($this->handlers[$handler])) {
110 if (isset($this->handlers[$handler]["*"])) {
111 return $this->handlers[$handler]["*"];
113 return $this->handlers[$handler][$method];
120 function add_command($command, $description, $sender) {
121 $command = "-" . str_replace("-", "_", strtolower($command));
123 $this->commands[$command] = array("description" => $description,
127 function del_command($command) {
128 $command = "-" . strtolower($command);
130 unset($this->commands[$command]);
133 function lookup_command($command) {
134 $command = "-" . strtolower($command);
136 if (is_array($this->commands[$command])) {
137 return $this->commands[$command]["class"];
145 function get_commands() {
146 return $this->commands;
149 function run_commands($args) {
150 foreach ($this->get_commands() as $command => $data) {
151 if (in_array($command, $args)) {
152 $command = str_replace("-", "", $command);
153 $data["class"]->$command($args);