]> git.wh0rd.org Git - tt-rss.git/commitdiff
more work on user-selectable plugins; properly process system and user plugins
authorAndrew Dolgov <fox@fakecake.org>
Tue, 25 Dec 2012 06:02:08 +0000 (10:02 +0400)
committerAndrew Dolgov <fox@fakecake.org>
Tue, 25 Dec 2012 06:02:08 +0000 (10:02 +0400)
23 files changed:
classes/plugin.php
classes/pluginhost.php
classes/pref/prefs.php
config.php-dist
include/functions.php
include/rssfuncs.php
plugins/digest/digest.php
plugins/example/example.php
plugins/example_feed/example_feed.php
plugins/example_routing/example_routing.php
plugins/flattr/flattr.php
plugins/googleplus/googleplus.php
plugins/identica/identica.php
plugins/import_export/import_export.php
plugins/instances/instances.php
plugins/mail/mail.php
plugins/note/note.php
plugins/pinterest/pinterest.php
plugins/pocket/pocket.php
plugins/redditimgur/redditimgur.php
plugins/share/share.php
plugins/updater/updater.php
update.php

index 59cb64f53380ca56182565b64b308e58a455e567..e655a2062ef998726ef148a3ed25fbac999f536a 100644 (file)
@@ -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 "";
+       }
 }
 ?>
index d8df6db49a50addaedeae1759344141d55207064..ee56886f48ea4b336708e309d9b61577059da923 100644 (file)
@@ -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) {
index bb1b44ece899795bcb2660f7a3f0f5779eaab80b..ce17af27857d733bb7d99e365290ed4d9ac91796 100644 (file)
@@ -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]) {
 
index 2828379449219a7782d01bbba5c34b7b52a36a7b..52afdea1d4bbafd8020d19fd5901211fc729eef7 100644 (file)
        // after login, or content encoding errors, disable it.
 
        define('PLUGINS', 'note');
-       // Plugins to load. Check plugins/ directory for additional information.
+       // Comma-separated list of plugins to load for all users. System plugins have to be specified
+       // here, user plugins may be loaded per-user using Preferences/Plugins.
 
        define('FEEDBACK_URL', '');
        // Displays an URL for users to provide feedback or comments regarding
index 6848f14b9d90d52636f6e11f691dbd8f7b047eb1..cd39789ab542afbfc22505f6fe5f6f93bf271e96 100644 (file)
                        $plugins = get_pref($link, "_ENABLED_PLUGINS", $owner_uid);
 
                        global $pluginhost;
-                       $pluginhost->load($plugins);
+                       $pluginhost->load($plugins, $pluginhost::KIND_USER);
                }
        }
 
                        global $pluginhost;
 
                        $pluginhost = new PluginHost($link);
-                       $pluginhost->load(PLUGINS);
+                       $pluginhost->load(PLUGINS, $pluginhost::KIND_ALL);
 
                        return true;
                } else {
index 2105de3301441b195e2bdc863f4fc121a450d531..d3286a538c7126ea41ce551408437336c349473c 100644 (file)
 
                if (!$rss->error()) {
 
-                       global $pluginhost;
+                       // We use local pluginhost here because we need to load different per-user feed plugins
+                       $user_plugins = get_pref($link, "_ENABLED_PLUGINS", $owner_uid);
+
+                       $pluginhost = new PluginHost($link);
+
+                       $pluginhost->load(PLUGINS, $pluginhost::KIND_ALL);
+                       $pluginhost->load($plugins, $pluginhost::KIND_USER);
+
                        $pluginhost->run_hooks($pluginhost::HOOK_FEED_PARSED, "hook_feed_parsed", $rss);
 
                        if ($debug_enabled) {
                                        "tags" => $entry_tags,
                                        "author" => $entry_author);
 
-                               global $pluginhost;
                                foreach ($pluginhost->get_hooks($pluginhost::HOOK_ARTICLE_FILTER) as $plugin) {
                                        $article = $plugin->hook_article_filter($article);
                                }
index cb906e3c1c4533a835c0698ad2a76879445b6e74..621e4258acd44d76c0c72306475e4681e67b6dcd 100644 (file)
@@ -4,22 +4,18 @@ class Digest extends Plugin implements IHandler {
        private $link;
        private $host;
 
-       function _about() {
+       function about() {
                return array(1.0,
                        "Digest mode for tt-rss (tablet friendly UI)",
                        "fox",
                        true);
        }
 
-       function __construct($host) {
+       function init($host) {
                $this->link = $host->get_link();
                $this->host = $host;
 
                $host->add_handler("digest", "*", $this);
-
-               //$host->add_handler("rpc", "digestinit", $this);
-               //$host->add_handler("rpc", "digestupdate", $this);
-               //$host->add_handler("rpc", "digestgetcontents", $this);
        }
 
        function index() {
index be6a48551cb650d419774e6c733c9042a7eb46ce..eef604b4f599631a3e057a3d9e62be02c642fecc 100644 (file)
@@ -6,14 +6,14 @@ class Example extends Plugin {
        private $link;
        private $host;
 
-       function _about() {
+       function about() {
                return array(1.0,
                        "Example plugin #1",
                        "fox",
                        true);
        }
 
-       function __construct($host) {
+       function init($host) {
                $this->link = $host->get_link();
                $this->host = $host;
 
index a0d6d19c740bdbcef0c0912a9770592dd0061a30..af14d3ff3fc9936b6b5a9d87a24877979c24b38c 100644 (file)
@@ -7,14 +7,14 @@ class Example_Feed extends Plugin {
        private $link;
        private $host;
 
-       function _about() {
+       function about() {
                return array(1.0,
                        "Example feed plugin",
                        "fox",
                        true);
        }
 
-       function __construct($host) {
+       function init($host) {
                $this->link = $host->get_link();
                $this->host = $host;
 
index f15951e088514e2c5f2f7c32ea91a9ac5101b0c3..31c5b6f284f67a1a7e29681bd400b4054df1d9f9 100644 (file)
@@ -15,14 +15,14 @@ class Example_Routing extends Plugin implements IHandler {
        private $link;
        private $host;
 
-       function _about() {
+       function about() {
                return array(1.0,
                        "Example routing plugin",
                        "fox",
                        true);
        }
 
-       function __construct($host) {
+       function init($host) {
                $this->link = $host->get_link();
                $this->host = $host;
 
index e5042632c6481c20e10ea775dd0f2c3f26521a34..3ab7ebd8575b455b76160ed746596f2581ff4c5b 100644 (file)
@@ -3,14 +3,14 @@ class Flattr extends Plugin {
        private $link;
        private $host;
 
-       function __construct($host) {
+       function init($host) {
                $this->link = $host->get_link();
                $this->host = $host;
 
                $host->add_hook($host::HOOK_ARTICLE_BUTTON, $this);
        }
 
-       function _about() {
+       function about() {
                return array(1.0,
                        "Share on Flattr plugin",
                        "Nic Honing");
index a100573de1fc4694685194e2f6a0853cf2a414c4..11e58de2ed35afe477de38a448f6b3d07582e0e8 100644 (file)
@@ -3,14 +3,14 @@ class GooglePlus extends Plugin {
        private $link;
        private $host;
 
-       function __construct($host) {
+       function init($host) {
                $this->link = $host->get_link();
                $this->host = $host;
 
                $host->add_hook($host::HOOK_ARTICLE_BUTTON, $this);
        }
 
-       function _about() {
+       function about() {
                return array(1.0,
                        "Share on Google+ plugin",
                        "homolibere");
index 67ca6ae2c61394e0a6a6d69917ee56a5a3b7a851..7d5e71310aa536645cf360e5eb1062cad2988a4b 100644 (file)
@@ -3,14 +3,14 @@ class Identica extends Plugin {
        private $link;
        private $host;
 
-       function __construct($host) {
+       function init($host) {
                $this->link = $host->get_link();
                $this->host = $host;
 
                $host->add_hook($host::HOOK_ARTICLE_BUTTON, $this);
        }
 
-       function _about() {
+       function about() {
                return array(1.0,
                        "Share on Identi.ca",
                        "fox");
index 68597978b1fd648cfda1e82bf91cd34bfd5b2098..823976565333af043b8504aff5d78b173cf3e78a 100644 (file)
@@ -4,7 +4,7 @@ class Import_Export extends Plugin implements IHandler {
        private $link;
        private $host;
 
-       function __construct($host) {
+       function init($host) {
                $this->link = $host->get_link();
                $this->host = $host;
 
@@ -12,7 +12,7 @@ class Import_Export extends Plugin implements IHandler {
                $host->add_command("xml-import", "USER FILE: import articles from XML", $this);
        }
 
-       function _about() {
+       function about() {
                return array(1.0,
                        "Imports and exports user data using a neutral XML format",
                        "fox");
index 2836bce5a46a6d1c0054445d1d71fc21aecb055e..3acb163cc8d46cdc5b265f58891517bc5f115e08 100644 (file)
@@ -10,14 +10,14 @@ class Instances extends Plugin implements IHandler {
                2       => "Invalid object received",
                16      => "Access denied" );
 
-       function _about() {
+       function about() {
                return array(1.0,
                        "Support for linking tt-rss instances together and sharing popular feeds.",
                        "fox",
                        true);
        }
 
-       function __construct($host) {
+       function init($host) {
                $this->link = $host->get_link();
                $this->host = $host;
 
index 648148cd3f28c3a52b28b2482f1ed7ff6c684ea4..ed65ca021f4f8e5dd0b84f100c9e7e363a81a5d7 100644 (file)
@@ -4,13 +4,13 @@ class Mail extends Plugin {
        private $link;
        private $host;
 
-       function _about() {
+       function about() {
                return array(1.0,
                        "Adds a share article via email button",
                        "fox");
        }
 
-       function __construct($host) {
+       function init($host) {
                $this->link = $host->get_link();
                $this->host = $host;
 
index c6c1ef903fac1596e855b493e906ff809dcdf8a7..560796a692267244c679dbc093e992a734e326b3 100644 (file)
@@ -3,13 +3,13 @@ class Note extends Plugin {
        private $link;
        private $host;
 
-       function _about() {
+       function about() {
                return array(1.0,
                        "Adds support for setting article notes",
                        "fox");
        }
 
-       function __construct($host) {
+       function init($host) {
                $this->link = $host->get_link();
                $this->host = $host;
 
index c4254917023dde20cb6c4c9471ce42f3d30b88e7..f93b62ff9a92dcdb6ed5c74c2a8671d92b369a1e 100644 (file)
@@ -3,13 +3,13 @@ class Pinterest extends Plugin {
        private $link;
        private $host;
 
-       function _about() {
+       function about() {
                return array(1.0,
                        "Share article via Pinterest",
                        "?");
        }
 
-       function __construct($host) {
+       function init($host) {
                $this->link = $host->get_link();
                $this->host = $host;
 
index 6b5ccddecf05bdf7724895f2595548ff5cfd9cae..b17597568535f20c5b446ffa2743ae8ad2bae235 100644 (file)
@@ -4,13 +4,13 @@ class Pocket extends Plugin {
        private $link;
        private $host;
 
-       function _about() {
+       function about() {
                return array(1.0,
                        "Share article via Pocket (formerly Read It Later)",
                        "?");
        }
 
-       function __construct($host) {
+       function init($host) {
                $this->link = $host->get_link();
                $this->host = $host;
 
index 1776475383681a66a941c16f1d1d5f4bcefe35a5..ca6554a75ef7aa7aef806dffa860820ea0794e91 100644 (file)
@@ -4,13 +4,13 @@ class RedditImgur extends Plugin {
        private $link;
        private $host;
 
-       function _about() {
+       function about() {
                return array(1.0,
                        "Inline image links in Reddit RSS feeds",
                        "fox");
        }
 
-       function __construct($host) {
+       function init($host) {
                $this->link = $host->get_link();
                $this->host = $host;
 
index 254b68bca61a71399212db87a450efe5a752420b..e1151849b8ebc26c85c65112d3f5f51e937e79b1 100644 (file)
@@ -3,13 +3,13 @@ class Share extends Plugin {
        private $link;
        private $host;
 
-       function _about() {
+       function about() {
                return array(1.0,
                        "Share article by unique URL",
                        "fox");
        }
 
-       function __construct($host) {
+       function init($host) {
                $this->link = $host->get_link();
                $this->host = $host;
 
index 2148e3c0125064b6a271214ea5025507718349de..1dbd5ab6641054a96c0224dd7c26234c8c4403a7 100644 (file)
@@ -4,14 +4,14 @@ class Updater extends Plugin {
        private $link;
        private $host;
 
-       function _about() {
+       function about() {
                return array(1.0,
                        "Updates tt-rss installation to latest version.",
                        "fox",
                        true);
        }
 
-       function __construct($host) {
+       function init($host) {
                $this->link = $host->get_link();
                $this->host = $host;
 
index 7bf6807ffb4b2145a59a32d3c92125e8d96f4b46..2e06565a42773bd6efa4442f079c43a64cb7e54b 100755 (executable)
 
        if (in_array("-list-plugins", $op)) {
                $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();
 
                        printf("%-60s - v%.2f (by %s)\n%s\n\n",
                                $name, $about[0], $about[2], $about[1]);