]> git.wh0rd.org - tt-rss.git/blobdiff - classes/pluginhost.php
add HOOK_UPDATE_TASK
[tt-rss.git] / classes / pluginhost.php
index b28d2511d7423c391d2d649e77fba41bce0a2295..c55667e1268345f73efa00c01f11080d2a4c9e11 100644 (file)
@@ -4,11 +4,15 @@ class PluginHost {
        private $hooks = array();
        private $plugins = array();
        private $handlers = array();
+       private $commands = array();
 
        const HOOK_ARTICLE_BUTTON = 1;
        const HOOK_ARTICLE_FILTER = 2;
        const HOOK_PREFS_TAB = 3;
        const HOOK_PREFS_SECTION = 4;
+       const HOOK_PREFS_TABS = 5;
+       const HOOK_FEED_PARSED = 6;
+       const HOOK_UPDATE_TASK = 7;
 
        function __construct($link) {
                $this->link = $link;
@@ -55,7 +59,11 @@ class PluginHost {
        }
 
        function get_hooks($type) {
-               return $this->hooks[$type];
+               if (isset($this->hooks[$type])) {
+                       return $this->hooks[$type];
+               } else {
+                       return array();
+               }
        }
 
        function load($classlist) {
@@ -77,7 +85,7 @@ class PluginHost {
        }
 
        function add_handler($handler, $method, $sender) {
-               $handler = strtolower($handler);
+               $handler = str_replace("-", "_", strtolower($handler));
                $method = strtolower($method);
 
                if (!is_array($this->handlers[$handler])) {
@@ -88,21 +96,64 @@ class PluginHost {
        }
 
        function del_handler($handler, $method) {
-               $handler = strtolower($handler);
+               $handler = str_replace("-", "_", strtolower($handler));
                $method = strtolower($method);
 
                unset($this->handlers[$handler][$method]);
        }
 
        function lookup_handler($handler, $method) {
-               $handler = strtolower($handler);
+               $handler = str_replace("-", "_", strtolower($handler));
                $method = strtolower($method);
 
                if (is_array($this->handlers[$handler])) {
-                       return $this->handlers[$handler][$method];
+                       if (isset($this->handlers[$handler]["*"])) {
+                               return $this->handlers[$handler]["*"];
+                       } else {
+                               return $this->handlers[$handler][$method];
+                       }
                }
 
                return false;
        }
+
+       function add_command($command, $description, $sender) {
+               $command = "-" . str_replace("-", "_", strtolower($command));
+
+               $this->commands[$command] = array("description" => $description,
+                       "class" => $sender);
+       }
+
+       function del_command($command) {
+               $command = "-" . strtolower($command);
+
+               unset($this->commands[$command]);
+       }
+
+       function lookup_command($command) {
+               $command = "-" . strtolower($command);
+
+               if (is_array($this->commands[$command])) {
+                       return $this->commands[$command]["class"];
+               } else {
+                       return false;
+               }
+
+               return false;
+       }
+
+       function get_commands() {
+               return $this->commands;
+       }
+
+       function run_commands($args) {
+               foreach ($this->get_commands() as $command => $data) {
+                       if (in_array($command, $args)) {
+                               $command = str_replace("-", "", $command);
+                               $data["class"]->$command($args);
+                       }
+               }
+       }
+
 }
 ?>