mirror of
https://git.tt-rss.org/git/tt-rss.git
synced 2026-01-03 13:39:14 +00:00
more work on user-selectable plugins; properly process system and user plugins
This commit is contained in:
@@ -3,9 +3,22 @@ class Plugin {
|
||||
private $link;
|
||||
private $host;
|
||||
|
||||
function __construct($host) {
|
||||
function init($host) {
|
||||
$this->link = $host->get_link();
|
||||
$this->host = $host;
|
||||
}
|
||||
|
||||
function about() {
|
||||
// version, name, description, author, is_system
|
||||
return array(1.0, "plugin", "No description", "No author", false);
|
||||
}
|
||||
|
||||
function get_js() {
|
||||
return "";
|
||||
}
|
||||
|
||||
function get_prefs_js() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -14,6 +14,10 @@ class PluginHost {
|
||||
const HOOK_FEED_PARSED = 6;
|
||||
const HOOK_UPDATE_TASK = 7;
|
||||
|
||||
const KIND_ALL = 1;
|
||||
const KIND_SYSTEM = 2;
|
||||
const KIND_USER = 3;
|
||||
|
||||
function __construct($link) {
|
||||
$this->link = $link;
|
||||
}
|
||||
@@ -65,12 +69,12 @@ class PluginHost {
|
||||
return array();
|
||||
}
|
||||
}
|
||||
function load_all() {
|
||||
function load_all($kind) {
|
||||
$plugins = array_map("basename", glob("plugins/*"));
|
||||
$this->load(join(",", $plugins));
|
||||
$this->load(join(",", $plugins), $kind);
|
||||
}
|
||||
|
||||
function load($classlist) {
|
||||
function load($classlist, $kind) {
|
||||
$plugins = explode(",", $classlist);
|
||||
|
||||
foreach ($plugins as $class) {
|
||||
@@ -84,14 +88,31 @@ class PluginHost {
|
||||
if (class_exists($class) && is_subclass_of($class, "Plugin")) {
|
||||
$plugin = new $class($this);
|
||||
|
||||
$this->register_plugin($class, $plugin);
|
||||
switch ($kind) {
|
||||
case $this::KIND_SYSTEM:
|
||||
if ($this->is_system($plugin)) {
|
||||
$plugin->init($this);
|
||||
$this->register_plugin($class, $plugin);
|
||||
}
|
||||
break;
|
||||
case $this::KIND_USER:
|
||||
if (!$this->is_system($plugin)) {
|
||||
$plugin->init($this);
|
||||
$this->register_plugin($class, $plugin);
|
||||
}
|
||||
break;
|
||||
case $this::KIND_ALL:
|
||||
$plugin->init($this);
|
||||
$this->register_plugin($class, $plugin);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function is_system($plugin) {
|
||||
$about = $plugin->_about();
|
||||
$about = $plugin->about();
|
||||
|
||||
return @$about[3];
|
||||
}
|
||||
@@ -134,22 +155,17 @@ class PluginHost {
|
||||
return false;
|
||||
}
|
||||
|
||||
// only system plugins are allowed to modify commands
|
||||
function add_command($command, $description, $sender) {
|
||||
$command = "-" . str_replace("-", "_", strtolower($command));
|
||||
|
||||
if ($this->is_system($sender)) {
|
||||
$this->commands[$command] = array("description" => $description,
|
||||
"class" => $sender);
|
||||
}
|
||||
$this->commands[$command] = array("description" => $description,
|
||||
"class" => $sender);
|
||||
}
|
||||
|
||||
function del_command($command) {
|
||||
$command = "-" . strtolower($command);
|
||||
|
||||
if ($this->is_system($sender)) {
|
||||
unset($this->commands[$command]);
|
||||
}
|
||||
unset($this->commands[$command]);
|
||||
}
|
||||
|
||||
function lookup_command($command) {
|
||||
|
||||
@@ -670,10 +670,10 @@ class Pref_Prefs extends Handler_Protected {
|
||||
$user_enabled = array_map("trim", explode(",", get_pref($this->link, "_ENABLED_PLUGINS")));
|
||||
|
||||
$tmppluginhost = new PluginHost($link);
|
||||
$tmppluginhost->load_all();
|
||||
$tmppluginhost->load_all($tmppluginhost::KIND_ALL);
|
||||
|
||||
foreach ($tmppluginhost->get_plugins() as $name => $plugin) {
|
||||
$about = $plugin->_about();
|
||||
$about = $plugin->about();
|
||||
|
||||
if ($about[3]) {
|
||||
if (in_array($name, $system_enabled)) {
|
||||
@@ -709,7 +709,7 @@ class Pref_Prefs extends Handler_Protected {
|
||||
|
||||
|
||||
foreach ($tmppluginhost->get_plugins() as $name => $plugin) {
|
||||
$about = $plugin->_about();
|
||||
$about = $plugin->about();
|
||||
|
||||
if (!$about[3]) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user