1
0
mirror of https://git.tt-rss.org/git/tt-rss.git synced 2025-12-13 19:05:55 +00:00

add support for plugins adding API methods

This commit is contained in:
Andrew Dolgov
2013-04-12 08:18:43 +04:00
parent 5e725f9c8c
commit 79f9bef767
3 changed files with 54 additions and 2 deletions

View File

@@ -464,8 +464,19 @@ class API extends Handler {
}
function index() {
print $this->wrap(self::STATUS_ERR, array("error" => 'UNKNOWN_METHOD'));
function index($method) {
global $pluginhost;
$plugin = $pluginhost->get_api_method(strtolower($method));
if ($plugin && method_exists($plugin, $method)) {
$reply = $plugin->$method();
print $this->wrap($reply[0], $reply[1]);
} else {
print $this->wrap(self::STATUS_ERR, array("error" => 'UNKNOWN_METHOD', "method" => $method));
}
}
function shareToPublished() {

View File

@@ -7,6 +7,7 @@ class PluginHost {
private $commands = array();
private $storage = array();
private $feeds = array();
private $api_methods = array();
private $owner_uid;
private $debug;
@@ -347,5 +348,14 @@ class PluginHost {
return PLUGIN_FEED_BASE_INDEX - 1 + abs($feed);
}
function add_api_method($name, $sender) {
if ($this->is_system($sender)) {
$this->api_methods[strtolower($name)] = $sender;
}
}
function get_api_method($name) {
return $this->api_methods[$name];
}
}
?>