diff --git a/classes/handler/public.php b/classes/handler/public.php index 1bf0887011d0248ce8fcaa4da0334b0cdde1bf22..632cece81c9ab10bcf59a00a4f5ecf52f84e0f9e 100644 --- a/classes/handler/public.php +++ b/classes/handler/public.php @@ -1004,10 +1004,10 @@ class Handler_Public extends Handler { print "<h2>Database update required</h2>"; - print "<h3>"; - printf("Your Tiny Tiny RSS database needs update to the latest version: %d to %d.", - $updater->getSchemaVersion(), SCHEMA_VERSION); - print "</h3>"; + print_notice("<h4>". + sprintf("Your Tiny Tiny RSS database needs update to the latest version: %d to %d.", + $updater->getSchemaVersion(), SCHEMA_VERSION). + "</h4>"); print_warning("Please backup your database before proceeding."); diff --git a/classes/pluginhost.php b/classes/pluginhost.php index c4ec1871d3b0775b6f7445103ad087928f0a47e6..75620a191e704c77ca911efbb548a5e8a33cc578 100644 --- a/classes/pluginhost.php +++ b/classes/pluginhost.php @@ -8,6 +8,7 @@ class PluginHost { private $storage = array(); private $feeds = array(); private $api_methods = array(); + private $plugin_actions = array(); private $owner_uid; private $debug; private $last_registered; @@ -47,6 +48,7 @@ class PluginHost { const HOOK_SUBSCRIBE_FEED = 27; const HOOK_HEADLINES_BEFORE = 28; const HOOK_RENDER_ENCLOSURE = 29; + const HOOK_ARTICLE_FILTER_ACTION = 30; const KIND_ALL = 1; const KIND_SYSTEM = 2; @@ -98,7 +100,7 @@ class PluginHost { } function get_plugin($name) { - return $this->plugins[$name]; + return $this->plugins[strtolower($name)]; } function run_hooks($type, $method, $args) { @@ -415,5 +417,19 @@ class PluginHost { function get_api_method($name) { return $this->api_methods[$name]; } + + function add_filter_action($sender, $action_name, $action_desc) { + $sender_class = get_class($sender); + + if (!isset($this->plugin_actions[$sender_class])) + $this->plugin_actions[$sender_class] = array(); + + array_push($this->plugin_actions[$sender_class], + array("action" => $action_name, "description" => $action_desc, "sender" => $sender)); + } + + function get_filter_actions() { + return $this->plugin_actions; + } } ?> diff --git a/classes/pref/filters.php b/classes/pref/filters.php index a84340877e24b7dbf44c4fe8d72f89664486ecf2..a2a2d0928861be2122983494d0a8b53b3ec383c2 100644 --- a/classes/pref/filters.php +++ b/classes/pref/filters.php @@ -519,6 +519,21 @@ class Pref_Filters extends Handler_Protected { $action["action_id"] == 7) $title .= ": " . $action["action_param"]; + if ($action["action_id"] == 9) { + list ($pfclass, $pfaction) = explode(":", $action["action_param"]); + + $filter_actions = PluginHost::getInstance()->get_filter_actions(); + + foreach ($filter_actions as $fclass => $factions) { + foreach ($factions as $faction) { + if ($pfaction == $faction["action"] && $pfclass == $fclass) { + $title .= ": " . $fclass . ": " . $faction["description"]; + break; + } + } + } + } + return $title; } @@ -989,16 +1004,18 @@ class Pref_Filters extends Handler_Protected { print "</select>"; - $param_box_hidden = ($action_id == 7 || $action_id == 4 || $action_id == 6) ? + $param_box_hidden = ($action_id == 7 || $action_id == 4 || $action_id == 6 || $action_id == 9) ? "" : "display : none"; $param_hidden = ($action_id == 4 || $action_id == 6) ? "" : "display : none"; $label_param_hidden = ($action_id == 7) ? "" : "display : none"; + $plugin_param_hidden = ($action_id == 9) ? "" : "display : none"; print "<span id=\"filterDlg_paramBox\" style=\"$param_box_hidden\">"; - print " " . __("with parameters:") . " "; + print " "; + //print " " . __("with parameters:") . " "; print "<input dojoType=\"dijit.form.TextBox\" id=\"filterDlg_actionParam\" style=\"$param_hidden\" name=\"action_param\" value=\"$action_param\">"; @@ -1007,6 +1024,22 @@ class Pref_Filters extends Handler_Protected { "id=\"filterDlg_actionParamLabel\" style=\"$label_param_hidden\" dojoType=\"dijit.form.Select\""); + $filter_actions = PluginHost::getInstance()->get_filter_actions(); + $filter_action_hash = array(); + + foreach ($filter_actions as $fclass => $factions) { + foreach ($factions as $faction) { + + $filter_action_hash[$fclass . ":" . $faction["action"]] = + $fclass . ": " . $faction["description"]; + } + + } + + print_select_hash("filterDlg_actionParamPlugin", $action_param, $filter_action_hash, + "style=\"$plugin_param_hidden\" dojoType=\"dijit.form.Select\"", + "action_param_plugin"); + print "</span>"; print " "; // tiny layout hack diff --git a/classes/pref/prefs.php b/classes/pref/prefs.php index fe88218ba5bc5b45d4f984c85f4b062553116695..41dc536f500e1a903853720fee45ed30d40b3ecf 100644 --- a/classes/pref/prefs.php +++ b/classes/pref/prefs.php @@ -752,7 +752,7 @@ class Pref_Prefs extends Handler_Protected { foreach ($tmppluginhost->get_plugins() as $name => $plugin) { $about = $plugin->about(); - if ($about[3] && strpos($name, "example") === FALSE) { + if ($about[3]) { if (in_array($name, $system_enabled)) { $checked = "checked='1'"; } else { @@ -802,7 +802,7 @@ class Pref_Prefs extends Handler_Protected { foreach ($tmppluginhost->get_plugins() as $name => $plugin) { $about = $plugin->about(); - if (!$about[3] && strpos($name, "example") === FALSE) { + if (!$about[3]) { if (in_array($name, $system_enabled)) { $checked = "checked='1'"; diff --git a/include/functions.php b/include/functions.php index d90855ea6bd275acd90e8a0427ece00233e2a674..6d183abaa9420ea03684bc2c553ad692c2f6cdbf 100644 --- a/include/functions.php +++ b/include/functions.php @@ -1,6 +1,6 @@ <?php define('EXPECTED_CONFIG_VERSION', 26); - define('SCHEMA_VERSION', 128); + define('SCHEMA_VERSION', 129); define('LABEL_BASE_INDEX', -1024); define('PLUGIN_FEED_BASE_INDEX', -128); @@ -580,8 +580,10 @@ } } - function print_select($id, $default, $values, $attributes = "") { - print "<select name=\"$id\" id=\"$id\" $attributes>"; + function print_select($id, $default, $values, $attributes = "", $name = "") { + if (!$name) $name = $id; + + print "<select name=\"$name\" id=\"$id\" $attributes>"; foreach ($values as $v) { if ($v == $default) $sel = "selected=\"1\""; @@ -595,8 +597,10 @@ print "</select>"; } - function print_select_hash($id, $default, $values, $attributes = "") { - print "<select name=\"$id\" id='$id' $attributes>"; + function print_select_hash($id, $default, $values, $attributes = "", $name = "") { + if (!$name) $name = $id; + + print "<select name=\"$name\" id='$id' $attributes>"; foreach (array_keys($values) as $v) { if ($v == $default) $sel = 'selected="selected"'; diff --git a/include/rssfuncs.php b/include/rssfuncs.php index 6532fb270e6f385c9d3506a1cb29df6a667ba9d3..a922516cd71b71633f4cc24b086b84a71d2fb5c7 100644 --- a/include/rssfuncs.php +++ b/include/rssfuncs.php @@ -773,6 +773,47 @@ } } + /* Collect article tags here so we could filter by them: */ + + $article_filters = get_article_filters($filters, $article["title"], + $article["content"], $article["link"], 0, $article["author"], + $article["tags"]); + + if ($debug_enabled) { + _debug("article filters: ", $debug_enabled); + if (count($article_filters) != 0) { + print_r($article_filters); + } + } + + $plugin_filter_names = find_article_filters($article_filters, "plugin"); + $plugin_filter_actions = $pluginhost->get_filter_actions(); + + if (count($plugin_filter_names) > 0) { + _debug("applying plugin filter actions...", $debug_enabled); + + foreach ($plugin_filter_names as $pfn) { + list($pfclass,$pfaction) = explode(":", $pfn["param"]); + + if (isset($plugin_filter_actions[$pfclass])) { + $plugin = $pluginhost->get_plugin($pfclass); + + _debug("... $pfclass: $pfaction", $debug_enabled); + + if ($plugin) { + $start = microtime(true); + $article = $plugin->hook_article_filter_action($article, $pfaction); + + _debug("=== " . sprintf("%.4f (sec)", microtime(true) - $start), $debug_enabled); + } else { + _debug("??? $pfclass: plugin object not found."); + } + } else { + _debug("??? $pfclass: filter plugin not registered."); + } + } + } + $entry_tags = $article["tags"]; $entry_guid = db_escape_string($entry_guid); $entry_title = db_escape_string($article["title"]); @@ -875,19 +916,6 @@ $dupcheck_qpart = ""; } - /* Collect article tags here so we could filter by them: */ - - $article_filters = get_article_filters($filters, $entry_title, - $entry_content, $entry_link, $entry_timestamp, $entry_author, - $entry_tags); - - if ($debug_enabled) { - _debug("article filters: ", $debug_enabled); - if (count($article_filters) != 0) { - print_r($article_filters); - } - } - if (find_article_filter($article_filters, "filter")) { //db_query("COMMIT"); // close transaction in progress continue; diff --git a/js/functions.js b/js/functions.js index 98a531851683b241f26a88db56880cef2b45bf92..a0f954e075206c3ad5bd2924c0c25dfb8d039e17 100644 --- a/js/functions.js +++ b/js/functions.js @@ -591,15 +591,21 @@ function filterDlgCheckAction(sender) { } // if selected action supports parameters, enable params field - if (action == 4 || action == 6 || action == 7) { + if (action == 4 || action == 6 || action == 7 || action == 9) { new Effect.Appear(action_param, {duration : 0.5}); - if (action != 7) { - Element.show(dijit.byId("filterDlg_actionParam").domNode); - Element.hide(dijit.byId("filterDlg_actionParamLabel").domNode); - } else { + + Element.hide(dijit.byId("filterDlg_actionParam").domNode); + Element.hide(dijit.byId("filterDlg_actionParamLabel").domNode); + Element.hide(dijit.byId("filterDlg_actionParamPlugin").domNode); + + if (action == 7) { Element.show(dijit.byId("filterDlg_actionParamLabel").domNode); - Element.hide(dijit.byId("filterDlg_actionParam").domNode); + } else if (action == 9) { + Element.show(dijit.byId("filterDlg_actionParamPlugin").domNode); + } else { + Element.show(dijit.byId("filterDlg_actionParam").domNode); } + } else { Element.hide(action_param); } @@ -966,6 +972,8 @@ function createNewActionElement(parentNode, replaceNode) { if (form.action_id.value == 7) { form.action_param.value = form.action_param_label.value; + } else if (form.action_id.value == 9) { + form.action_param.value = form.action_param_plugin.value; } var query = "backend.php?op=pref-filters&method=printactionname&action="+ diff --git a/schema/ttrss_schema_mysql.sql b/schema/ttrss_schema_mysql.sql index 8a6f7d681a375d934640ee979b52b9039928526d..296049083fd42436e26244adf242fad58088c120 100644 --- a/schema/ttrss_schema_mysql.sql +++ b/schema/ttrss_schema_mysql.sql @@ -232,6 +232,9 @@ insert into ttrss_filter_actions (id,name,description) values (7, 'label', insert into ttrss_filter_actions (id,name,description) values (8, 'stop', 'Stop / Do nothing'); +insert into ttrss_filter_actions (id,name,description) values (9, 'plugin', + 'Invoke plugin'); + create table ttrss_filters2(id integer primary key auto_increment, owner_uid integer not null, match_any_rule boolean not null default false, @@ -278,7 +281,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 (127); +insert into ttrss_version values (129); create table ttrss_enclosures (id integer primary key auto_increment, content_url text not null, diff --git a/schema/ttrss_schema_pgsql.sql b/schema/ttrss_schema_pgsql.sql index 9dafa693e11c409f9170fb789c0099c0cd75081b..b53d375cc6d30e90f93281080d30ed826e60b919 100644 --- a/schema/ttrss_schema_pgsql.sql +++ b/schema/ttrss_schema_pgsql.sql @@ -228,6 +228,9 @@ insert into ttrss_filter_actions (id,name,description) values (7, 'label', insert into ttrss_filter_actions (id,name,description) values (8, 'stop', 'Stop / Do nothing'); +insert into ttrss_filter_actions (id,name,description) values (9, 'plugin', + 'Invoke plugin'); + create table ttrss_filters2(id serial not null primary key, owner_uid integer not null references ttrss_users(id) on delete cascade, match_any_rule boolean not null default false, @@ -260,7 +263,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 (127); +insert into ttrss_version values (129); create table ttrss_enclosures (id serial not null primary key, content_url text not null, diff --git a/schema/versions/mysql/129.sql b/schema/versions/mysql/129.sql new file mode 100644 index 0000000000000000000000000000000000000000..2ebec0dc9d7e8da9818113d80da8e6bf501b6266 --- /dev/null +++ b/schema/versions/mysql/129.sql @@ -0,0 +1,8 @@ +BEGIN; + +insert into ttrss_filter_actions (id,name,description) values (9, 'plugin', + 'Invoke plugin'); + +UPDATE ttrss_version SET schema_version = 129; + +COMMIT; diff --git a/schema/versions/pgsql/129.sql b/schema/versions/pgsql/129.sql new file mode 100644 index 0000000000000000000000000000000000000000..2ebec0dc9d7e8da9818113d80da8e6bf501b6266 --- /dev/null +++ b/schema/versions/pgsql/129.sql @@ -0,0 +1,8 @@ +BEGIN; + +insert into ttrss_filter_actions (id,name,description) values (9, 'plugin', + 'Invoke plugin'); + +UPDATE ttrss_version SET schema_version = 129; + +COMMIT;