diff --git a/backend.php b/backend.php index 66afb06c..cc45b6a8 100644 --- a/backend.php +++ b/backend.php @@ -63,6 +63,10 @@ authenticate_user($link, "admin", null); } + if ($_SESSION["uid"]) { + load_user_plugins($link, $_SESSION["uid"]); + } + $purge_intervals = array( 0 => __("Use default"), -1 => __("Never purge"), diff --git a/classes/pluginhost.php b/classes/pluginhost.php index a637a521..d8df6db4 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) { diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php index 447aa894..b28bd549 100644 --- a/classes/pref/feeds.php +++ b/classes/pref/feeds.php @@ -1480,11 +1480,11 @@ class Pref_Feeds extends Handler_Protected { print ""; #pane global $pluginhost; + $pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB, "hook_prefs_tab", "prefFeeds"); print ""; #container - } private function feedlist_init_cat($cat_id, $hidden = false) { diff --git a/classes/pref/prefs.php b/classes/pref/prefs.php index db7a3e04..bb1b44ec 100644 --- a/classes/pref/prefs.php +++ b/classes/pref/prefs.php @@ -621,8 +621,133 @@ class Pref_Prefs extends Handler_Protected { "; + print ""; print ''; # inner pane print ''; # border container + + print ""; #pane + + print "
"; + + print "

".__("Plugins")."

"; + + print_notice("You will need to reload Tiny Tiny RSS for plugin changes to take effect."); + + print "
"; + + print ""; + + print ""; + print ""; + + print ""; + + print ""; + + print " + + + + + "; + + $system_enabled = array_map("trim", explode(",", PLUGINS)); + $user_enabled = array_map("trim", explode(",", get_pref($this->link, "_ENABLED_PLUGINS"))); + + $tmppluginhost = new PluginHost($link); + $tmppluginhost->load_all(); + + foreach ($tmppluginhost->get_plugins() as $name => $plugin) { + $about = $plugin->_about(); + + if ($about[3]) { + if (in_array($name, $system_enabled)) { + $checked = "checked='1'"; + } else { + $checked = ""; + } + + print ""; + + print ""; + + print ""; + print ""; + print ""; + print ""; + + print ""; + + } + } + + print ""; + + print " + + + + + "; + + + foreach ($tmppluginhost->get_plugins() as $name => $plugin) { + $about = $plugin->_about(); + + if (!$about[3]) { + + if (in_array($name, $system_enabled)) { + $checked = "checked='1'"; + $disabled = "disabled='1'"; + } else if (in_array($name, $user_enabled)) { + $checked = "checked='1'"; + $disabled = ""; + } else { + $checked = ""; + $disabled = ""; + } + + print ""; + + print ""; + + print ""; + print ""; + print ""; + print ""; + + print ""; + + + + } + + } + + print "

".__("System plugins")."

 ".__('Plugin')."".__('Description')."".__('Version')."".__('Author')."
$name" . htmlspecialchars($about[1]) . "" . htmlspecialchars(sprintf("%.2f", $about[0])) . "" . htmlspecialchars($about[2]) . "

".__("User plugins")."

 ".__('Plugin')."".__('Description')."".__('Version')."".__('Author')."
$name" . htmlspecialchars($about[1]) . "" . htmlspecialchars(sprintf("%.2f", $about[0])) . "" . htmlspecialchars($about[2]) . "
"; + + print "

"; + print "
"; print "
"; #pane @@ -698,5 +823,11 @@ class Pref_Prefs extends Handler_Protected { } } + + function setplugins() { + $plugins = join(",", $_REQUEST["plugins"]); + + set_pref($this->link, "_ENABLED_PLUGINS", $plugins); + } } ?> diff --git a/include/functions.php b/include/functions.php index 14b3af51..6848f14b 100644 --- a/include/functions.php +++ b/include/functions.php @@ -1,6 +1,6 @@ load($plugins); + } + } + function login_sequence($link, $login_form = 0) { if (SINGLE_USER_MODE) { - return authenticate_user($link, "admin", null); + authenticate_user($link, "admin", null); + load_user_plugins($link, $_SESSION["uid"]); } else { if (!$_SESSION["uid"] || !validate_session($link)) { @@ -735,6 +745,10 @@ setcookie("ttrss_lang", $_SESSION["language"], time() + SESSION_COOKIE_LIFETIME); } + + if ($_SESSION["uid"]) { + load_user_plugins($link, $_SESSION["uid"]); + } } } diff --git a/plugins/digest/digest.php b/plugins/digest/digest.php index d0cbd5b0..cb906e3c 100644 --- a/plugins/digest/digest.php +++ b/plugins/digest/digest.php @@ -7,7 +7,8 @@ class Digest extends Plugin implements IHandler { function _about() { return array(1.0, "Digest mode for tt-rss (tablet friendly UI)", - "fox"); + "fox", + true); } function __construct($host) { diff --git a/plugins/example/example.php b/plugins/example/example.php index 42550b17..be6a4855 100644 --- a/plugins/example/example.php +++ b/plugins/example/example.php @@ -9,7 +9,8 @@ class Example extends Plugin { function _about() { return array(1.0, "Example plugin #1", - "fox"); + "fox", + true); } function __construct($host) { diff --git a/plugins/example_feed/example_feed.php b/plugins/example_feed/example_feed.php index 205594ed..a0d6d19c 100644 --- a/plugins/example_feed/example_feed.php +++ b/plugins/example_feed/example_feed.php @@ -10,7 +10,8 @@ class Example_Feed extends Plugin { function _about() { return array(1.0, "Example feed plugin", - "fox"); + "fox", + true); } function __construct($host) { diff --git a/plugins/example_routing/example_routing.php b/plugins/example_routing/example_routing.php index 024bf5b2..f15951e0 100644 --- a/plugins/example_routing/example_routing.php +++ b/plugins/example_routing/example_routing.php @@ -18,7 +18,8 @@ class Example_Routing extends Plugin implements IHandler { function _about() { return array(1.0, "Example routing plugin", - "fox"); + "fox", + true); } function __construct($host) { diff --git a/plugins/instances/instances.php b/plugins/instances/instances.php index fd80ee44..2836bce5 100644 --- a/plugins/instances/instances.php +++ b/plugins/instances/instances.php @@ -13,7 +13,8 @@ class Instances extends Plugin implements IHandler { function _about() { return array(1.0, "Support for linking tt-rss instances together and sharing popular feeds.", - "fox"); + "fox", + true); } function __construct($host) { diff --git a/plugins/updater/updater.php b/plugins/updater/updater.php index c85ef328..2148e3c0 100644 --- a/plugins/updater/updater.php +++ b/plugins/updater/updater.php @@ -7,7 +7,8 @@ class Updater extends Plugin { function _about() { return array(1.0, "Updates tt-rss installation to latest version.", - "fox"); + "fox", + true); } function __construct($host) { diff --git a/prefs.php b/prefs.php index 8b554167..e20ac9ba 100644 --- a/prefs.php +++ b/prefs.php @@ -20,7 +20,6 @@ no_cache_incantation(); header('Content-Type: text/html; charset=utf-8'); - ?> diff --git a/schema/ttrss_schema_mysql.sql b/schema/ttrss_schema_mysql.sql index 28778942..bb8bd102 100644 --- a/schema/ttrss_schema_mysql.sql +++ b/schema/ttrss_schema_mysql.sql @@ -308,7 +308,7 @@ create table ttrss_tags (id integer primary key auto_increment, create table ttrss_version (schema_version int not null) ENGINE=InnoDB DEFAULT CHARSET=UTF8; -insert into ttrss_version values (99); +insert into ttrss_version values (100); create table ttrss_enclosures (id integer primary key auto_increment, content_url text not null, @@ -452,6 +452,8 @@ insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) valu insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('AUTO_ASSIGN_LABELS', 1, 'true', 'Assign articles to labels automatically', 3); +insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('_ENABLED_PLUGINS', 2, '', '', 1); + update ttrss_prefs set access_level = 1 where pref_name in ('ON_CATCHUP_SHOW_NEXT_FEED', 'SORT_HEADLINES_BY_FEED_DATE', 'VFEED_GROUP_BY_FEED', diff --git a/schema/ttrss_schema_pgsql.sql b/schema/ttrss_schema_pgsql.sql index 432ebf88..3c508bb3 100644 --- a/schema/ttrss_schema_pgsql.sql +++ b/schema/ttrss_schema_pgsql.sql @@ -256,7 +256,7 @@ create index ttrss_tags_post_int_id_idx on ttrss_tags(post_int_id); create table ttrss_version (schema_version int not null); -insert into ttrss_version values (99); +insert into ttrss_version values (100); create table ttrss_enclosures (id serial not null primary key, content_url text not null, @@ -392,6 +392,8 @@ insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) valu insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('AUTO_ASSIGN_LABELS', 1, 'true', 'Assign articles to labels automatically', 3); +insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('_ENABLED_PLUGINS', 2, '', '', 1); + update ttrss_prefs set access_level = 1 where pref_name in ('ON_CATCHUP_SHOW_NEXT_FEED', 'SORT_HEADLINES_BY_FEED_DATE', 'VFEED_GROUP_BY_FEED', diff --git a/schema/versions/mysql/100.sql b/schema/versions/mysql/100.sql new file mode 100644 index 00000000..a360dab6 --- /dev/null +++ b/schema/versions/mysql/100.sql @@ -0,0 +1,7 @@ +begin; + +insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('_ENABLED_PLUGINS', 2, '', '', 1); + +update ttrss_version set schema_version = 100; + +commit; diff --git a/schema/versions/pgsql/100.sql b/schema/versions/pgsql/100.sql new file mode 100644 index 00000000..a360dab6 --- /dev/null +++ b/schema/versions/pgsql/100.sql @@ -0,0 +1,7 @@ +begin; + +insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('_ENABLED_PLUGINS', 2, '', '', 1); + +update ttrss_version set schema_version = 100; + +commit;