diff options
author | Andrew Dolgov <[email protected]> | 2012-12-25 00:45:10 +0400 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2012-12-25 00:45:10 +0400 |
commit | de612e7a3850d3053c7038e94098c0681d46983b (patch) | |
tree | 3e983cc930f18bd3d18d6536801929c733f7bf6c /classes/pluginhost.php | |
parent | 57e97294259f8d14806764d7a65083c2b84f1ea7 (diff) |
experimental support for per-user plugins (bump schema)
Diffstat (limited to 'classes/pluginhost.php')
-rw-r--r-- | classes/pluginhost.php | 42 |
1 files changed, 30 insertions, 12 deletions
diff --git a/classes/pluginhost.php b/classes/pluginhost.php index a637a5216..d8df6db49 100644 --- a/classes/pluginhost.php +++ b/classes/pluginhost.php @@ -78,32 +78,45 @@ class PluginHost { $class_file = strtolower(basename($class)); $file = dirname(__FILE__)."/../plugins/$class_file/$class_file.php"; - if (file_exists($file)) require_once $file; + if (!isset($this->plugins[$class])) { + if (file_exists($file)) require_once $file; - if (class_exists($class) && is_subclass_of($class, "Plugin")) { - $plugin = new $class($this); + if (class_exists($class) && is_subclass_of($class, "Plugin")) { + $plugin = new $class($this); - $this->register_plugin($class, $plugin); + $this->register_plugin($class, $plugin); + } } } } + function is_system($plugin) { + $about = $plugin->_about(); + + return @$about[3]; + } + + // only system plugins are allowed to modify routing function add_handler($handler, $method, $sender) { $handler = str_replace("-", "_", strtolower($handler)); $method = strtolower($method); - if (!is_array($this->handlers[$handler])) { - $this->handlers[$handler] = array(); - } + if ($this->is_system($sender)) { + if (!is_array($this->handlers[$handler])) { + $this->handlers[$handler] = array(); + } - $this->handlers[$handler][$method] = $sender; + $this->handlers[$handler][$method] = $sender; + } } function del_handler($handler, $method) { $handler = str_replace("-", "_", strtolower($handler)); $method = strtolower($method); - unset($this->handlers[$handler][$method]); + if ($this->is_system($sender)) { + unset($this->handlers[$handler][$method]); + } } function lookup_handler($handler, $method) { @@ -121,17 +134,22 @@ class PluginHost { return false; } + // only system plugins are allowed to modify commands function add_command($command, $description, $sender) { $command = "-" . str_replace("-", "_", strtolower($command)); - $this->commands[$command] = array("description" => $description, - "class" => $sender); + if ($this->is_system($sender)) { + $this->commands[$command] = array("description" => $description, + "class" => $sender); + } } function del_command($command) { $command = "-" . strtolower($command); - unset($this->commands[$command]); + if ($this->is_system($sender)) { + unset($this->commands[$command]); + } } function lookup_command($command) { |