]> git.wh0rd.org - tt-rss.git/commitdiff
implement multiple rule/action filters
authorAndrew Dolgov <fox@fakecake.org>
Thu, 30 Aug 2012 14:50:56 +0000 (18:50 +0400)
committerAndrew Dolgov <fox@fakecake.org>
Fri, 31 Aug 2012 08:13:47 +0000 (12:13 +0400)
14 files changed:
classes/dlg.php
classes/opml.php
classes/pref/filters.php
classes/pref/labels.php
include/functions.php
include/rssfuncs.php
js/functions.js
js/prefs.js
schema/ttrss_schema_mysql.sql
schema/ttrss_schema_pgsql.sql
schema/versions/mysql/96.sql [new file with mode: 0644]
schema/versions/pgsql/96.sql [new file with mode: 0644]
tt-rss.css
update.php

index c540214a6ac163b0bd49aafcd5a763ca4e5da52f..0e5eef22430784bc0e8a9908f2f2c9e2d0f21a57 100644 (file)
@@ -444,132 +444,6 @@ class Dlg extends Handler_Protected {
                </div>";
        }
 
-       function quickAddFilter() {
-               $active_feed_id = (int) db_escape_string($_REQUEST["feed"]);
-               $cat_filter = db_escape_string($_REQUEST["is_cat"]) == "true";
-
-               print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-filters\">";
-               print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"quiet\" value=\"1\">";
-               print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"add\">";
-               print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"csrf_token\" value=\"".$_SESSION['csrf_token']."\">";
-
-               $result = db_query($this->link, "SELECT id,description
-                       FROM ttrss_filter_types ORDER BY description");
-
-               $filter_types = array();
-
-               while ($line = db_fetch_assoc($result)) {
-                       //array_push($filter_types, $line["description"]);
-                       $filter_types[$line["id"]] = __($line["description"]);
-               }
-
-               print "<div class=\"dlgSec\">".__("Match")."</div>";
-
-               print "<div class=\"dlgSecCont\">";
-
-               print "<span id=\"filterDlg_dateModBox\" style=\"display : none\">";
-
-               $filter_params = array(
-                       "before" => __("before"),
-                       "after" => __("after"));
-
-               print_select_hash("filter_date_modifier", "before",
-                       $filter_params, 'dojoType="dijit.form.Select"');
-
-               print "&nbsp;</span>";
-
-               print "<input dojoType=\"dijit.form.ValidationTextBox\"
-                        required=\"true\" id=\"filterDlg_regExp\"
-                        style=\"font-size : 16px\"
-                        name=\"reg_exp\" value=\"$reg_exp\"/>";
-
-               print "<span id=\"filterDlg_dateChkBox\" style=\"display : none\">";
-               print "&nbsp;<button dojoType=\"dijit.form.Button\"
-                       onclick=\"return filterDlgCheckDate()\">".
-                       __('Check it')."</button>";
-               print "</span>";
-
-               print "<hr/>" .  __("on field") . " ";
-               print_select_hash("filter_type", 1, $filter_types,
-                       'onchange="filterDlgCheckType(this)" dojoType="dijit.form.Select"');
-
-               print "<hr/>";
-
-               print __("in") . " ";
-
-               print "<span id='filterDlg_feeds'>";
-               print_feed_select($this->link, "feed_id",
-                       $cat_filter ? "CAT:$active_feed_id" : $active_feed_id,
-                       'dojoType="dijit.form.FilteringSelect"');
-               print "</span>";
-
-               print "<span id='filterDlg_cats' style='display : none'>";
-               print_feed_cat_select($this->link, "cat_id", $active_cat_id,
-                       'dojoType="dijit.form.FilteringSelect"');
-               print "</span>";
-
-               print "</div>";
-
-               print "<div class=\"dlgSec\">".__("Perform Action")."</div>";
-
-               print "<div class=\"dlgSecCont\">";
-
-               print "<select name=\"action_id\" dojoType=\"dijit.form.Select\"
-                       onchange=\"filterDlgCheckAction(this)\">";
-
-               $result = db_query($this->link, "SELECT id,description FROM ttrss_filter_actions
-                       ORDER BY name");
-
-               while ($line = db_fetch_assoc($result)) {
-                       printf("<option value='%d'>%s</option>", $line["id"], __($line["description"]));
-               }
-
-               print "</select>";
-
-               print "<span id=\"filterDlg_paramBox\" style=\"display : none\">";
-               print " " . __("with parameters:") . " ";
-               print "<input dojoType=\"dijit.form.TextBox\"
-                       id=\"filterDlg_actionParam\"
-                       name=\"action_param\">";
-
-               print_label_select($this->link, "action_param_label", $action_param,
-                'id="filterDlg_actionParamLabel" dojoType="dijit.form.Select"');
-
-               print "</span>";
-
-               print "&nbsp;"; // tiny layout hack
-
-               print "</div>";
-
-               print "<div class=\"dlgSec\">".__("Options")."</div>";
-               print "<div class=\"dlgSecCont\">";
-
-               print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"enabled\" id=\"enabled\" checked=\"1\">
-                               <label for=\"enabled\">".__('Enabled')."</label><hr/>";
-
-               print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"inverse\" id=\"inverse\">
-                       <label for=\"inverse\">".__('Inverse match')."</label><hr/>";
-
-#              print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"cat_filter\" id=\"cat_filter\" onchange=\"filterDlgCheckCat(this)\">
-#                              <label for=\"cat_filter\">".__('Apply to category')."</label><hr/>";
-
-
-               print "</div>";
-
-               print "<div class=\"dlgButtons\">";
-
-               print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').test()\">".
-                       __('Test')."</button> ";
-
-               print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').execute()\">".
-                       __('Create')."</button> ";
-
-               print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').hide()\">".
-                       __('Cancel')."</button>";
-
-               print "</div>";
-       }
-
        function inactiveFeeds() {
 
                if (DB_TYPE == "pgsql") {
index 8683fb73a33a86b7a70fb8c6681d781ae4480a6f..60d0d40e07fa129e5a597e9a62cd108d031fe3b5 100644 (file)
@@ -159,7 +159,7 @@ class Opml extends Handler_Protected {
 
                        $out .= "</outline>";
 
-                       $out .= "<outline title=\"tt-rss-filters\" schema-version=\"".SCHEMA_VERSION."\">";
+/*                     $out .= "<outline title=\"tt-rss-filters\" schema-version=\"".SCHEMA_VERSION."\">";
 
                        $result = db_query($this->link, "SELECT filter_type,
                                        reg_exp,
@@ -191,7 +191,7 @@ class Opml extends Handler_Protected {
                        }
 
 
-                       $out .= "</outline>";
+                       $out .= "</outline>"; */
                }
 
                $out .= "</body></opml>";
@@ -287,7 +287,7 @@ class Opml extends Handler_Protected {
                }
        }
 
-       private function opml_import_filter($doc, $node, $owner_uid) {
+       /* private function opml_import_filter($doc, $node, $owner_uid) {
                $attrs = $node->attributes;
 
                $filter_name = db_escape_string($attrs->getNamedItem('filter-name')->nodeValue);
@@ -355,7 +355,7 @@ class Opml extends Handler_Protected {
                                }
                        }
                }
-       }
+       } */
 
        private function opml_import_category($doc, $root_node, $owner_uid, $parent_id) {
                $body = $doc->getElementsByTagName('body');
@@ -413,7 +413,7 @@ class Opml extends Handler_Protected {
                                                $this->opml_import_label($doc, $node, $owner_uid);
                                                break;
                                        case "tt-rss-filters":
-                                               $this->opml_import_filter($doc, $node, $owner_uid);
+                                               //$this->opml_import_filter($doc, $node, $owner_uid);
                                                break;
                                        default:
                                                $this->opml_import_feed($doc, $node, $dst_cat_id, $owner_uid);
index 1a6c49071751086d845e7d3033f0343bef73016d..591d429eb346c88be2a982a747b695321409b6aa 100644 (file)
@@ -2,12 +2,13 @@
 class Pref_Filters extends Handler_Protected {
 
        function csrf_ignore($method) {
-               $csrf_ignored = array("index", "getfiltertree", "edit");
+               $csrf_ignored = array("index", "getfiltertree", "edit", "newfilter", "newrule",
+                       "newaction");
 
                return array_search($method, $csrf_ignored) !== false;
        }
 
-       function filter_test($filter_type, $reg_exp,
+/*     function filter_test($filter_type, $reg_exp,
                        $action_id, $action_param, $filter_param, $inverse, $feed_id, $cat_id,
                        $cat_filter) {
 
@@ -97,7 +98,7 @@ class Pref_Filters extends Handler_Protected {
                print "</table>";
                print "</div>";
 
-       }
+                       } */
 
        function getfiltertree() {
                $root = array();
@@ -105,106 +106,27 @@ class Pref_Filters extends Handler_Protected {
                $root['name'] = __('Filters');
                $root['items'] = array();
 
-               $search = $_SESSION["prefs_filter_search"];
-
-               if ($search) $search_qpart = " (LOWER(reg_exp) LIKE LOWER('%$search%')
-                       OR LOWER(ttrss_feeds.title) LIKE LOWER('%$search%')
-                       OR LOWER(COALESCE(ttrss_feed_categories.title, '".__('Uncategorized')."'))
-                               LIKE LOWER('%$search%') AND cat_filter = true) AND ";
-
-               $result = db_query($this->link, "SELECT
-                               ttrss_filters.id AS id,reg_exp,
-                               ttrss_filter_types.name AS filter_type_name,
-                               ttrss_filter_types.description AS filter_type_descr,
-                               enabled,
-                               inverse,
-                               cat_filter,
-                               feed_id,
-                               ttrss_filters.cat_id,
-                               action_id,
-                               filter_param,
-                               filter_type,
-                               ttrss_filter_actions.description AS action_description,
-                               ttrss_feeds.title AS feed_title,
-                               COALESCE(ttrss_feed_categories.title, '".__('Uncategorized')."') AS cat_title,
-                               ttrss_filter_actions.name AS action_name,
-                               ttrss_filters.action_param AS action_param
-                       FROM
-                               ttrss_filter_types,ttrss_filter_actions,ttrss_filters LEFT JOIN
-                                       ttrss_feeds ON (ttrss_filters.feed_id = ttrss_feeds.id) LEFT JOIN
-                                       ttrss_feed_categories ON (ttrss_filters.cat_id = ttrss_feed_categories.id)
-                       WHERE
-                               filter_type = ttrss_filter_types.id AND
-                               ttrss_filter_actions.id = action_id AND
-                               $search_qpart
-                               ttrss_filters.owner_uid = ".$_SESSION["uid"]."
-                       ORDER by action_description, reg_exp");
-
-               $cat = false;
-               $cur_action_description = "";
-
-               if (db_num_rows($result) > 0) {
-
-                       while ($line = db_fetch_assoc($result)) {
-                               if ($cur_action_description != $line['action_description']) {
-
-                                       if ($cat)
-                                               array_push($root['items'], $cat);
-
-                                       $cat = array();
-                                       $cat['id'] = 'ACTION:' . $line['action_id'];
-                                       $cat['name'] = $line['action_description'];
-                                       $cat['items'] = array();
-
-                                       $cur_action_description = $line['action_description'];
-                               }
-
-                               if (array_search($line["action_name"],
-                                       array("score", "tag", "label")) === false) {
-
-                                               $line["action_param"] = '';
-                               } else {
-                                       if ($line['action_name'] == 'label') {
-
-                                               $tmp_result = db_query($this->link, "SELECT fg_color, bg_color
-                                                       FROM ttrss_labels2 WHERE caption = '".
-                                                               db_escape_string($line["action_param"])."' AND
-                                                               owner_uid = " . $_SESSION["uid"]);
-
-                                               if (db_num_rows($tmp_result) != 0) {
-                                                       $fg_color = db_fetch_result($tmp_result, 0, "fg_color");
-                                                       $bg_color = db_fetch_result($tmp_result, 0, "bg_color");
+               $result = db_query($this->link, "SELECT *,
+                       (SELECT action_id FROM ttrss_filters2_actions
+                               WHERE filter_id = ttrss_filters2.id ORDER BY id LIMIT 1) AS action_id,
+                       (SELECT reg_exp FROM ttrss_filters2_rules
+                               WHERE filter_id = ttrss_filters2.id ORDER BY id LIMIT 1) AS reg_exp
+                       FROM ttrss_filters2 WHERE
+                       owner_uid = ".$_SESSION["uid"]." ORDER BY action_id,reg_exp");
 
-                                                       $tmp = "<span class=\"labelColorIndicator\" style='color : $fg_color; background-color : $bg_color'>&alpha;</span> " . $line['action_param'];
+               while ($line = db_fetch_assoc($result)) {
 
-                                                       $line['action_param'] = $tmp;
-                                               }
-                                       }
-                               }
+                       $name = $this->getFilterName($line["id"]);
 
-                               $filter = array();
-                               $filter['id'] = 'FILTER:' . $line['id'];
-                               $filter['bare_id'] = $line['id'];
-                               $filter['name'] = $line['reg_exp'];
-                               $filter['type'] = $line['filter_type'];
-                               $filter['enabled'] = sql_bool_to_bool($line['enabled']);
-                               $filter['param'] = $line['action_param'];
-                               $filter['inverse'] = sql_bool_to_bool($line['inverse']);
-                               $filter['checkbox'] = false;
-
-                               if (sql_bool_to_bool($line['cat_filter']))
-                                       if ($line['cat_id'] != 0) {
-                                               $filter['feed'] = $line['cat_title'];
-                                       } else {
-                                               $filter['feed'] = __('Uncategorized');
-                                       }
-                               else if ($line['feed_id'])
-                                       $filter['feed'] = $line['feed_title'];
+                       $filter = array();
+                       $filter['id'] = 'FILTER:' . $line['id'];
+                       $filter['bare_id'] = $line['id'];
+                       $filter['name'] = $name[0];
+                       $filter['param'] = $name[1];
+                       $filter['checkbox'] = false;
+                       $filter['enabled'] = $line["enabled"];
 
-                               array_push($cat['items'], $filter);
-                       }
-
-                       array_push($root['items'], $cat);
+                       array_push($root['items'], $filter);
                }
 
                $fl = array();
@@ -221,19 +143,10 @@ class Pref_Filters extends Handler_Protected {
                $filter_id = db_escape_string($_REQUEST["id"]);
 
                $result = db_query($this->link,
-                       "SELECT * FROM ttrss_filters WHERE id = '$filter_id' AND owner_uid = " . $_SESSION["uid"]);
-
-               $reg_exp = htmlspecialchars(db_fetch_result($result, 0, "reg_exp"));
-               $filter_type = db_fetch_result($result, 0, "filter_type");
-               $feed_id = (int) db_fetch_result($result, 0, "feed_id");
-               $cat_id = (int) db_fetch_result($result, 0, "cat_id");
-               $action_id = db_fetch_result($result, 0, "action_id");
-               $action_param = db_fetch_result($result, 0, "action_param");
-               $filter_param = db_fetch_result($result, 0, "filter_param");
+                       "SELECT * FROM ttrss_filters2 WHERE id = '$filter_id' AND owner_uid = " . $_SESSION["uid"]);
 
                $enabled = sql_bool_to_bool(db_fetch_result($result, 0, "enabled"));
-               $inverse = sql_bool_to_bool(db_fetch_result($result, 0, "inverse"));
-               $cat_filter = sql_bool_to_bool(db_fetch_result($result, 0, "cat_filter"));
+               $match_any_rule = sql_bool_to_bool(db_fetch_result($result, 0, "match_any_rule"));
 
                print "<form id=\"filter_edit_form\" onsubmit='return false'>";
 
@@ -242,105 +155,89 @@ class Pref_Filters extends Handler_Protected {
                print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"editSave\">";
                print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"csrf_token\" value=\"".$_SESSION['csrf_token']."\">";
 
-               $result = db_query($this->link, "SELECT id,description
-                       FROM ttrss_filter_types ORDER BY description");
-
-               $filter_types = array();
-
-               while ($line = db_fetch_assoc($result)) {
-                       //array_push($filter_types, $line["description"]);
-                       $filter_types[$line["id"]] = __($line["description"]);
-               }
-
                print "<div class=\"dlgSec\">".__("Match")."</div>";
 
-               print "<div class=\"dlgSecCont\">";
+               print "<div dojoType=\"dijit.Toolbar\">";
 
-               if ($filter_type != 5) {
-                       $date_ops_invisible = 'style="display : none"';
-               }
+               print "<div dojoType=\"dijit.form.DropDownButton\">".
+                               "<span>" . __('Select')."</span>";
+               print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
+               print "<div onclick=\"dijit.byId('filterEditDlg').selectRules(true)\"
+                       dojoType=\"dijit.MenuItem\">".__('All')."</div>";
+               print "<div onclick=\"dijit.byId('filterEditDlg').selectRules(false)\"
+                       dojoType=\"dijit.MenuItem\">".__('None')."</div>";
+               print "</div></div>";
 
-               print "<span id=\"filterDlg_dateModBox\" $date_ops_invisible>";
-               print __("Date") . " ";
+               print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').addRule()\">".
+                       __('Add')."</button> ";
 
-               $filter_params = array(
-                       "before" => __("before"),
-                       "after" => __("after"));
+               print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').deleteRule()\">".
+                       __('Delete')."</button> ";
 
-               print_select_hash("filter_date_modifier", $filter_param,
-                       $filter_params, 'dojoType="dijit.form.Select"');
+               print "</div>";
 
-               print "&nbsp;</span>";
+               print "<ul id='filterDlg_Matches'>";
 
-               print "<input dojoType=\"dijit.form.ValidationTextBox\"
-                                required=\"1\"
-                                name=\"reg_exp\" style=\"font-size : 16px;\" value=\"$reg_exp\">";
+               $rules_result = db_query($this->link, "SELECT * FROM ttrss_filters2_rules
+                       WHERE filter_id = '$filter_id' ORDER BY id");
 
-               print "<span id=\"filterDlg_dateChkBox\" $date_ops_invisible>";
-               print "&nbsp;<button dojoType=\"dijit.form.Button\" onclick=\"return filterDlgCheckDate()\">".
-                       __('Check it')."</button>";
-               print "</span>";
+               while ($line = db_fetch_assoc($rules_result)) {
+                       if ($line["cat_filter"]) {
+                               unset($line["cat_filter"]);
+                               $line["feed_id"] = "CAT:" . (int)$line["cat_id"];
+                               unset($line["cat_id"]);
+                       }
 
-               print "<hr/> " . __("on field") . " ";
-               print_select_hash("filter_type", $filter_type, $filter_types,
-                       'onchange="filterDlgCheckType(this)" dojoType="dijit.form.Select"');
+                       $data = htmlspecialchars(json_encode($line));
 
-               print "<hr/>";
-
-               print __("in") . " ";
+                       print "<li><input type='checkbox' onclick='toggleSelectListRow(this)'>".
+                               "<span onclick=\"dijit.byId('filterEditDlg').editRule(this)\">".$this->getRuleName($line)."</span>".
+                               "<input type='hidden' name='rule[]' value=\"$data\"/></li>";
+               }
 
-               print "<span id='filterDlg_feeds'>";
-               print_feed_select($this->link, "feed_id", ($cat_filter) ? "CAT:$cat_id" : $feed_id,
-                       'dojoType="dijit.form.FilteringSelect"');
-               print "</span>";
+               print "</ul>";
 
                print "</div>";
 
-               print "<div class=\"dlgSec\">".__("Perform Action")."</div>";
-
-               print "<div class=\"dlgSecCont\">";
+               print "<div class=\"dlgSec\">".__("Apply actions")."</div>";
 
-               print "<select name=\"action_id\" dojoType=\"dijit.form.Select\"
-                       onchange=\"filterDlgCheckAction(this)\">";
+               print "<div dojoType=\"dijit.Toolbar\">";
 
-               $result = db_query($this->link, "SELECT id,description FROM ttrss_filter_actions
-                       ORDER BY name");
-
-               while ($line = db_fetch_assoc($result)) {
-                       $is_sel = ($line["id"] == $action_id) ? "selected=\"1\"" : "";
-                       printf("<option value='%d' $is_sel>%s</option>", $line["id"], __($line["description"]));
-               }
-
-               print "</select>";
+               print "<div dojoType=\"dijit.form.DropDownButton\">".
+                               "<span>" . __('Select')."</span>";
+               print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
+               print "<div onclick=\"dijit.byId('filterEditDlg').selectActions(true)\"
+                       dojoType=\"dijit.MenuItem\">".__('All')."</div>";
+               print "<div onclick=\"dijit.byId('filterEditDlg').selectActions(false)\"
+                       dojoType=\"dijit.MenuItem\">".__('None')."</div>";
+               print "</div></div>";
 
-               $param_hidden = ($action_id == 4 || $action_id == 6 || $action_id == 7) ? "" : "display : none";
+               print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').addAction()\">".
+                       __('Add')."</button> ";
 
-               print "<span id=\"filterDlg_paramBox\" style=\"$param_hidden\">";
-               print " " . __("with parameters:") . " ";
+               print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').deleteAction()\">".
+                       __('Delete')."</button> ";
 
-               $param_int_hidden = ($action_id != 7) ? "" : "display : none";
+               print "</div>";
 
-               print "<input style=\"$param_int_hidden\"
-                               dojoType=\"dijit.form.TextBox\" id=\"filterDlg_actionParam\"
-                               name=\"action_param\" value=\"$action_param\">";
+               print "<ul id='filterDlg_Actions'>";
 
-               $param_int_hidden = ($action_id == 7) ? "" : "display : none";
+               $actions_result = db_query($this->link, "SELECT * FROM ttrss_filters2_actions
+                       WHERE filter_id = '$filter_id' ORDER BY id");
 
-               print_label_select($this->link, "action_param_label", $action_param,
-                "style=\"$param_int_hidden\"" .
-                'id="filterDlg_actionParamLabel" dojoType="dijit.form.Select"');
+               while ($line = db_fetch_assoc($actions_result)) {
+                       $line["action_param_label"] = $line["action_param"];
+                       $data = htmlspecialchars(json_encode($line));
 
-               print "</span>";
+                       print "<li><input type='checkbox' onclick='toggleSelectListRow(this)'>".
+                               "<span onclick=\"dijit.byId('filterEditDlg').editAction(this)\">".$this->getActionName($line)."</span>".
+                               "<input type='hidden' name='action[]' value=\"$data\"/></li>";
+               }
 
-               print "&nbsp;"; // tiny layout hack
+               print "</ul>";
 
                print "</div>";
 
-               print "<div class=\"dlgSec\">".__("Options")."</div>";
-               print "<div class=\"dlgSecCont\">";
-
-               print "<div style=\"line-height : 100%\">";
-
                if ($enabled) {
                        $checked = "checked=\"1\"";
                } else {
@@ -348,28 +245,18 @@ class Pref_Filters extends Handler_Protected {
                }
 
                print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"enabled\" id=\"enabled\" $checked>
-                               <label for=\"enabled\">".__('Enabled')."</label><hr/>";
+                               <label for=\"enabled\">".__('Enabled')."</label>";
 
-               if ($inverse) {
+               if ($match_any_rule) {
                        $checked = "checked=\"1\"";
                } else {
                        $checked = "";
                }
 
-               print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"inverse\" id=\"inverse\" $checked>
-                       <label for=\"inverse\">".__('Inverse match')."</label><hr/>";
-
-#              if ($cat_filter) {
-#                      $checked = "checked=\"1\"";
-#              } else {
-#                      $checked = "";
-#              }
-
-#              print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"cat_filter\" id=\"cat_filter\" onchange=\"filterDlgCheckCat(this)\" $checked>
-#                              <label for=\"cat_filter\">".__('Apply to category')."</label><hr/>";
+               print "<br/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"match_any_rule\" id=\"match_any_rule\" $checked>
+                               <label for=\"match_any_rule\">".__('Match any rule')."</label>";
 
-               print "</div>";
-               print "</div>";
+               print "<p/>";
 
                print "<div class=\"dlgButtons\">";
 
@@ -378,8 +265,8 @@ class Pref_Filters extends Handler_Protected {
                        __('Remove')."</button>";
                print "</div>";
 
-               print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').test()\">".
-                       __('Test')."</button> ";
+#              print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').test()\">".
+#                      __('Test')."</button> ";
 
                print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').execute()\">".
                        __('Save')."</button> ";
@@ -390,75 +277,66 @@ class Pref_Filters extends Handler_Protected {
                print "</div>";
        }
 
-       function editSave() {
+       private function getRuleName($rule) {
+               if (!$rule) $rule = json_decode($_REQUEST["rule"], true);
 
-               $savemode = db_escape_string($_REQUEST["savemode"]);
-               $reg_exp = db_escape_string(trim($_REQUEST["reg_exp"]));
-               $filter_type = db_escape_string(trim($_REQUEST["filter_type"]));
-               $filter_id = db_escape_string($_REQUEST["id"]);
-               $feed_id = db_escape_string($_REQUEST["feed_id"]);
-               $action_id = db_escape_string($_REQUEST["action_id"]);
-               $action_param = db_escape_string($_REQUEST["action_param"]);
-               $action_param_label = db_escape_string($_REQUEST["action_param_label"]);
-               $enabled = checkbox_to_sql_bool(db_escape_string($_REQUEST["enabled"]));
-               $inverse = checkbox_to_sql_bool(db_escape_string($_REQUEST["inverse"]));
-
-               # for the time being, no other filters use params anyway...
-               $filter_param = db_escape_string($_REQUEST["filter_date_modifier"]);
+               $feed_id = $rule["feed_id"];
 
                if (strpos($feed_id, "CAT:") === 0) {
-                       $cat_filter = true;
-                       $cat_id = (int) substr($feed_id, 4);
-                       $feed_id = "NULL";
+                       $feed_id = (int) substr($feed_id, 4);
+                       $feed = getCategoryTitle($this->link, $feed_id);
                } else {
-                       $cat_filter = false;
                        $feed_id = (int) $feed_id;
-                       $cat_id = "NULL";
+
+                       if ($rule["feed_id"])
+                               $feed = getFeedTitle($this->link, (int)$rule["feed_id"]);
+                       else
+                               $feed = __("All feeds");
                }
 
-               $raw_feed_id = (int) $feed_id;
-               $raw_cat_id = (int) $cat_id;
+               $result = db_query($this->link, "SELECT description FROM ttrss_filter_types
+                       WHERE id = ".(int)$rule["filter_type"]);
+               $match_on = db_fetch_result($result, 0, "description");
 
-               if (!$feed_id) $feed_id = "NULL";
-               if (!$cat_id) $feed_id = "NULL";
+               return T_sprintf("%s on %s in %s", $rule["reg_exp"], $match_on, $feed);
+       }
 
-               /* When processing 'assign label' filters, action_param_label dropbox
-                * overrides action_param */
+       function printRuleName() {
+               print $this->getRuleName(json_decode($_REQUEST["rule"], true));
+       }
 
-               if ($action_id == 7) {
-                       $action_param = $action_param_label;
-               }
+       private function getActionName($action) {
+               $result = db_query($this->link, "SELECT description FROM
+                       ttrss_filter_actions WHERE id = " .(int)$action["action_id"]);
 
-               if ($action_id == 6) {
-                       $action_param = (int) str_replace("+", "", $action_param);
-               }
+               $title = __(db_fetch_result($result, 0, "description"));
 
-               if ($savemode != "test") {
-                       $result = db_query($this->link, "UPDATE ttrss_filters SET
-                               reg_exp = '$reg_exp',
-                               feed_id = $feed_id,
-                               cat_id = $cat_id,
-                               action_id = '$action_id',
-                               filter_type = '$filter_type',
-                               enabled = $enabled,
-                               inverse = $inverse,
-                               cat_filter = ".bool_to_sql_bool($cat_filter).",
-                               action_param = '$action_param',
-                               filter_param = '$filter_param'
-                               WHERE id = '$filter_id' AND owner_uid = " . $_SESSION["uid"]);
-               } else {
+               if ($action["action_id"] == 4 || $action["action_id"] == 6 ||
+                       $action["action_id"] == 7)
+                               $title .= ": " . $action["action_param"];
 
-                       $this->filter_test($filter_type, $reg_exp,
-                               $action_id, $action_param, $filter_param, sql_bool_to_bool($inverse),
-                               $raw_feed_id, $raw_cat_id, $cat_filter);
+               return $title;
+       }
 
-                       print "<div align='center'>";
-                       print "<button dojoType=\"dijit.form.Button\"
-                               onclick=\"return dijit.byId('filterTestDlg').hide()\">".
-                               __('Close this window')."</button>";
-                       print "</div>";
+       function printActionName() {
+               print $this->getActionName(json_decode($_REQUEST["action"], true));
+       }
+
+       function editSave() {
+
+#              print_r($_REQUEST);
+
+               $filter_id = db_escape_string($_REQUEST["id"]);
+               $enabled = checkbox_to_sql_bool(db_escape_string($_REQUEST["enabled"]));
+               $match_any_rule = checkbox_to_sql_bool(db_escape_string($_REQUEST["match_any_rule"]));
+
+               $result = db_query($this->link, "UPDATE ttrss_filters2 SET enabled = $enabled,
+                       match_any_rule = $match_any_rule
+                       WHERE id = '$filter_id'
+                       AND owner_uid = ". $_SESSION["uid"]);
+
+               $this->saveRulesAndActions($filter_id);
 
-               }
        }
 
        function remove() {
@@ -466,82 +344,117 @@ class Pref_Filters extends Handler_Protected {
                $ids = split(",", db_escape_string($_REQUEST["ids"]));
 
                foreach ($ids as $id) {
-                       db_query($this->link, "DELETE FROM ttrss_filters WHERE id = '$id' AND owner_uid = ". $_SESSION["uid"]);
+                       db_query($this->link, "DELETE FROM ttrss_filters2 WHERE id = '$id' AND owner_uid = ". $_SESSION["uid"]);
                }
        }
 
-       function add() {
+       private function saveRulesAndActions($filter_id) {
 
-               $savemode = db_escape_string($_REQUEST["savemode"]);
-               $regexp = db_escape_string(trim($_REQUEST["reg_exp"]));
-               $filter_type = db_escape_string(trim($_REQUEST["filter_type"]));
-               $feed_id = db_escape_string($_REQUEST["feed_id"]);
-#              $cat_id = db_escape_string($_REQUEST["cat_id"]);
-               $action_id = db_escape_string($_REQUEST["action_id"]);
-               $action_param = db_escape_string($_REQUEST["action_param"]);
-               $action_param_label = db_escape_string($_REQUEST["action_param_label"]);
-               $inverse = checkbox_to_sql_bool(db_escape_string($_REQUEST["inverse"]));
-#              $cat_filter = checkbox_to_sql_bool(db_escape_string($_REQUEST["cat_filter"]));
+               db_query($this->link, "DELETE FROM ttrss_filters2_rules WHERE filter_id = '$filter_id'");
+               db_query($this->link, "DELETE FROM ttrss_filters2_actions WHERE filter_id = '$filter_id'");
 
-               # for the time being, no other filters use params anyway...
-               $filter_param = db_escape_string($_REQUEST["filter_date_modifier"]);
+               if ($filter_id) {
+                       /* create rules */
 
-               if (!$regexp) return;
+                       $rules = array();
+                       $actions = array();
 
-               if (strpos($feed_id, "CAT:") === 0) {
-                       $cat_filter = true;
-                       $cat_id = (int) substr($feed_id, 4);
-                       $feed_id = "NULL";
-               } else {
-                       $cat_filter = false;
-                       $feed_id = (int) $feed_id;
-                       $cat_id = "NULL";
-               }
+                       foreach ($_REQUEST["rule"] as $rule) {
+                               $rule = json_decode($rule, true);
+                               unset($rule["id"]);
 
-               $raw_feed_id = (int) $feed_id;
-               $raw_cat_id = (int) $cat_id;
+                               if (array_search($rule, $rules) === false) {
+                                       array_push($rules, $rule);
+                               }
+                       }
 
-               if (!$feed_id) $feed_id = "NULL";
-               if (!$cat_id) $feed_id = "NULL";
+                       foreach ($_REQUEST["action"] as $action) {
+                               $action = json_decode($action, true);
+                               unset($action["id"]);
 
-               /* When processing 'assign label' filters, action_param_label dropbox
-                * overrides action_param */
+                               if (array_search($action, $actions) === false) {
+                                       array_push($actions, $action);
+                               }
+                       }
 
-               if ($action_id == 7) {
-                       $action_param = $action_param_label;
-               }
+                       foreach ($rules as $rule) {
+                               if ($rule) {
 
-               if ($action_id == 6) {
-                       $action_param = (int) str_replace("+", "", $action_param);
-               }
+                                       $reg_exp = strip_tags(db_escape_string(trim($rule["reg_exp"])));
+                                       $filter_type = (int) db_escape_string(trim($rule["filter_type"]));
+                                       $feed_id = db_escape_string(trim($rule["feed_id"]));
+
+                                       if (strpos($feed_id, "CAT:") === 0) {
+                                               $cat_filter = bool_to_sql_bool(true);
+                                               $cat_id = (int) substr($feed_id, 4);
+                                               $feed_id = "NULL";
 
-               if ($savemode != "test") {
-                       $result = db_query($this->link,
-                               "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id,
-                                       action_id, action_param, inverse, filter_param, cat_id, cat_filter)
-                               VALUES
-                                       ('$regexp', '$filter_type','".$_SESSION["uid"]."',
-                                       $feed_id, '$action_id', '$action_param', $inverse,
-                                       '$filter_param', $cat_id, ".bool_to_sql_bool($cat_filter).")");
-
-                       if (db_affected_rows($this->link, $result) != 0) {
-                               print T_sprintf("Created filter <b>%s</b>", htmlspecialchars($regexp));
+                                               if (!$cat_id) $cat_id = "NULL"; // Uncategorized
+                                       } else {
+                                               $cat_filter = bool_to_sql_bool(false);
+                                               $feed_id = (int) $feed_id;
+                                               $cat_id = "NULL";
+
+                                               if (!$feed_id) $feed_id = "NULL"; // Uncategorized
+                                       }
+
+                                       $query = "INSERT INTO ttrss_filters2_rules
+                                               (filter_id, reg_exp,filter_type,feed_id,cat_id,cat_filter) VALUES
+                                               ('$filter_id', '$reg_exp', '$filter_type', $feed_id, $cat_id, $cat_filter)";
+
+                                       db_query($this->link, $query);
+                               }
                        }
 
-               } else {
+                       foreach ($actions as $action) {
+                               if ($action) {
+
+                                       $action_id = (int) db_escape_string($action["action_id"]);
+                                       $action_param = db_escape_string($action["action_param"]);
+                                       $action_param_label = db_escape_string($action["action_param_label"]);
+
+                                       if ($action_id == 7) {
+                                               $action_param = $action_param_label;
+                                       }
 
-                       $this->filter_test($filter_type, $regexp,
-                               $action_id, $action_param, $filter_param, sql_bool_to_bool($inverse),
-                               $raw_feed_id, $raw_cat_id,
-                               $cat_filter);
+                                       if ($action_id == 6) {
+                                               $action_param = (int) str_replace("+", "", $action_param);
+                                       }
 
-                       print "<div align='center'>";
-                       print "<button dojoType=\"dijit.form.Button\"
-                               onclick=\"return dijit.byId('filterTestDlg').hide()\">".
-                               __('Close this window')."</button>";
-                       print "</div>";
+                                       $query = "INSERT INTO ttrss_filters2_actions
+                                               (filter_id, action_id, action_param) VALUES
+                                               ('$filter_id', '$action_id', '$action_param')";
 
+                                       db_query($this->link, $query);
+                               }
+                       }
                }
+
+
+       }
+
+       function add() {
+#              print_r($_REQUEST);
+
+               $enabled = checkbox_to_sql_bool($_REQUEST["enabled"]);
+               $match_any_rule = checkbox_to_sql_bool($_REQUEST["match_any_rule"]);
+
+               db_query($this->link, "BEGIN");
+
+               /* create base filter */
+
+               $result = db_query($this->link, "INSERT INTO ttrss_filters2
+                       (owner_uid, match_any_rule, enabled) VALUES
+                       (".$_SESSION["uid"].",$match_any_rule,$enabled)");
+
+               $result = db_query($this->link, "SELECT MAX(id) AS id FROM ttrss_filters2
+                       WHERE owner_uid = ".$_SESSION["uid"]);
+
+               $filter_id = db_fetch_result($result, 0, "id");
+
+               $this->saveRulesAndActions($filter_id);
+
+               db_query($this->link, "COMMIT");
        }
 
        function index() {
@@ -602,6 +515,9 @@ class Pref_Filters extends Handler_Protected {
                print "<button dojoType=\"dijit.form.Button\" onclick=\"return quickAddFilter()\">".
                        __('Create filter')."</button> ";
 
+               print "<button dojoType=\"dijit.form.Button\" onclick=\"return joinSelectedFilters()\">".
+                       __('Combine')."</button> ";
+
                print "<button dojoType=\"dijit.form.Button\" onclick=\"return editSelectedFilter()\">".
                        __('Edit')."</button> ";
 
@@ -648,5 +564,354 @@ class Pref_Filters extends Handler_Protected {
                print "</div>"; #container
 
        }
+
+       function newfilter() {
+
+               print "<form name='filter_new_form' id='filter_new_form'>";
+
+               $active_feed_id = (int) db_escape_string($_REQUEST["feed"]);
+               $cat_filter = db_escape_string($_REQUEST["is_cat"]) == "true";
+
+               print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-filters\">";
+               print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"add\">";
+               print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"csrf_token\" value=\"".$_SESSION['csrf_token']."\">";
+
+               print "<div class=\"dlgSec\">".__("Match")."</div>";
+
+               print "<div dojoType=\"dijit.Toolbar\">";
+
+               print "<div dojoType=\"dijit.form.DropDownButton\">".
+                               "<span>" . __('Select')."</span>";
+               print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
+               print "<div onclick=\"dijit.byId('filterEditDlg').selectRules(true)\"
+                       dojoType=\"dijit.MenuItem\">".__('All')."</div>";
+               print "<div onclick=\"dijit.byId('filterEditDlg').selectRules(false)\"
+                       dojoType=\"dijit.MenuItem\">".__('None')."</div>";
+               print "</div></div>";
+
+               print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').addRule()\">".
+                       __('Add')."</button> ";
+
+               print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').deleteRule()\">".
+                       __('Delete')."</button> ";
+
+               print "</div>";
+
+               print "<ul id='filterDlg_Matches'>";
+#              print "<li>No rules</li>";
+               print "</ul>";
+
+               print "</div>";
+
+               print "<div class=\"dlgSec\">".__("Apply actions")."</div>";
+
+               print "<div dojoType=\"dijit.Toolbar\">";
+
+               print "<div dojoType=\"dijit.form.DropDownButton\">".
+                               "<span>" . __('Select')."</span>";
+               print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
+               print "<div onclick=\"dijit.byId('filterEditDlg').selectActions(true)\"
+                       dojoType=\"dijit.MenuItem\">".__('All')."</div>";
+               print "<div onclick=\"dijit.byId('filterEditDlg').selectActions(false)\"
+                       dojoType=\"dijit.MenuItem\">".__('None')."</div>";
+               print "</div></div>";
+
+               print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').addAction()\">".
+                       __('Add')."</button> ";
+
+               print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').deleteAction()\">".
+                       __('Delete')."</button> ";
+
+               print "</div>";
+
+               print "<ul id='filterDlg_Actions'>";
+#              print "<li>No actions</li>";
+               print "</ul>";
+
+/*             print "<div class=\"dlgSec\">".__("Options")."</div>";
+               print "<div class=\"dlgSecCont\">"; */
+
+               print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"enabled\" id=\"enabled\" checked=\"1\">
+                               <label for=\"enabled\">".__('Enabled')."</label>";
+
+               print "<br/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"match_any_rule\" id=\"match_any_rule\">
+                               <label for=\"match_any_rule\">".__('Match any rule')."</label>";
+
+               print "<p/>";
+
+/*             print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"inverse\" id=\"inverse\">
+       <label for=\"inverse\">".__('Inverse match')."</label><hr/>"; */
+
+//             print "</div>";
+
+               print "<div class=\"dlgButtons\">";
+
+#              print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').test()\">".
+#                      __('Test')."</button> ";
+
+               print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').execute()\">".
+                       __('Create')."</button> ";
+
+               print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').hide()\">".
+                       __('Cancel')."</button>";
+
+               print "</div>";
+
+       }
+
+       function newrule() {
+               $rule = json_decode($_REQUEST["rule"], true);
+
+               if ($rule) {
+                       $reg_exp = htmlspecialchars($rule["reg_exp"]);
+                       $filter_type = $rule["filter_type"];
+                       $feed_id = $rule["feed_id"];
+               } else {
+                       $reg_exp = "";
+                       $filter_type = 1;
+                       $feed_id = 0;
+               }
+
+               if (strpos($feed_id, "CAT:") === 0) {
+                       $feed_id = substr($feed_id, 4);
+                       $cat_filter = true;
+               } else {
+                       $cat_filter = false;
+               }
+
+
+               print "<form name='filter_new_rule_form' id='filter_new_rule_form'>";
+
+               $result = db_query($this->link, "SELECT id,description
+                       FROM ttrss_filter_types ORDER BY description");
+
+               $filter_types = array();
+
+               while ($line = db_fetch_assoc($result)) {
+                       $filter_types[$line["id"]] = __($line["description"]);
+               }
+
+               print "<div class=\"dlgSec\">".__("Match")."</div>";
+
+               print "<div class=\"dlgSecCont\">";
+
+               print "<input dojoType=\"dijit.form.ValidationTextBox\"
+                        required=\"true\" id=\"filterDlg_regExp\"
+                        style=\"font-size : 16px\"
+                        name=\"reg_exp\" value=\"$reg_exp\"/>";
+
+               print "<hr/>" .  __("on field") . " ";
+               print_select_hash("filter_type", $filter_type, $filter_types,
+                       'dojoType="dijit.form.Select"');
+
+               print "<hr/>";
+
+               print __("in") . " ";
+
+               print "<span id='filterDlg_feeds'>";
+               print_feed_select($this->link, "feed_id",
+                       $cat_filter ? "CAT:$feed_id" : $feed_id,
+                       'dojoType="dijit.form.FilteringSelect"');
+               print "</span>";
+
+               print "</div>";
+
+               print "<div class=\"dlgButtons\">";
+
+               print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterNewRuleDlg').execute()\">".
+                       ($rule ? __("Save rule") : __('Add rule'))."</button> ";
+
+               print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterNewRuleDlg').hide()\">".
+                       __('Cancel')."</button>";
+
+               print "</div>";
+
+               print "</form>";
+       }
+
+       function newaction() {
+               $action = json_decode($_REQUEST["action"], true);
+
+               if ($action) {
+                       $action_param = db_escape_string($action["action_param"]);
+                       $action_id = (int)$action["action_id"];
+               } else {
+                       $action_param = "";
+                       $action_id = 0;
+               }
+
+               print "<form name='filter_new_action_form' id='filter_new_action_form'>";
+
+               print "<div class=\"dlgSec\">".__("Perform Action")."</div>";
+
+               print "<div class=\"dlgSecCont\">";
+
+               print "<select name=\"action_id\" dojoType=\"dijit.form.Select\"
+                       onchange=\"filterDlgCheckAction(this)\">";
+
+               $result = db_query($this->link, "SELECT id,description FROM ttrss_filter_actions
+                       ORDER BY name");
+
+               while ($line = db_fetch_assoc($result)) {
+                       $is_selected = ($line["id"] == $action_id) ? "selected='1'" : "";
+                       printf("<option $is_selected value='%d'>%s</option>", $line["id"], __($line["description"]));
+               }
+
+               print "</select>";
+
+               $param_box_hidden = ($action_id == 7 || $action_id == 4 || $action_id == 6) ?
+                       "" : "display : none";
+
+               $param_hidden = ($action_id == 4 || $action_id == 6) ?
+                       "" : "display : none";
+
+               $label_param_hidden = ($action_id == 7) ?       "" : "display : none";
+
+               print "<span id=\"filterDlg_paramBox\" style=\"$param_box_hidden\">";
+               print " " . __("with parameters:") . " ";
+               print "<input dojoType=\"dijit.form.TextBox\"
+                       id=\"filterDlg_actionParam\" style=\"$param_hidden\"
+                       name=\"action_param\" value=\"$action_param\">";
+
+               print_label_select($this->link, "action_param_label", $action_param,
+                       "id=\"filterDlg_actionParamLabel\" style=\"$label_param_hidden\"
+                       dojoType=\"dijit.form.Select\"");
+
+               print "</span>";
+
+               print "&nbsp;"; // tiny layout hack
+
+               print "</div>";
+
+               print "<div class=\"dlgButtons\">";
+
+               print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterNewActionDlg').execute()\">".
+                       ($action ? __("Save action") : __('Add action'))."</button> ";
+
+               print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterNewActionDlg').hide()\">".
+                       __('Cancel')."</button>";
+
+               print "</div>";
+
+               print "</form>";
+       }
+
+       private function getFilterName($id) {
+               $result = db_query($this->link,
+                       "SELECT * FROM ttrss_filters2_rules WHERE filter_id = '$id' ORDER BY id
+                       LIMIT 3");
+
+               $titles = array();
+               $count = 0;
+
+               while ($line = db_fetch_assoc($result)) {
+
+                       if ($line["cat_filter"]) {
+                               unset($line["cat_filter"]);
+                               $line["feed_id"] = "CAT:" . (int)$line["cat_id"];
+                               unset($line["cat_id"]);
+                       }
+
+                       if ($count < 2) {
+                               array_push($titles, $this->getRuleName($line));
+                       } else {
+                               array_push($titles, "...");
+                               break;
+                       }
+                       ++$count;
+               }
+
+               $result = db_query($this->link,
+                       "SELECT * FROM ttrss_filters2_actions WHERE filter_id = '$id' ORDER BY id LIMIT 3");
+
+               $actions = array();
+               $count = 0;
+
+               while ($line = db_fetch_assoc($result)) {
+                       if ($count < 2) {
+                               array_push($actions, $this->getActionName($line));
+                       } else {
+                               array_push($actions, "...");
+                               break;
+                       }
+                       ++$count;
+               }
+
+               return array(join(", ", $titles), join(", ", $actions));
+       }
+
+       function join() {
+               $ids = explode(",", db_escape_string($_REQUEST["ids"]));
+
+               if (count($ids) > 1) {
+                       $base_id = array_shift($ids);
+                       $ids_str = join(",", $ids);
+
+                       db_query($this->link, "BEGIN");
+                       db_query($this->link, "UPDATE ttrss_filters2_rules
+                               SET filter_id = '$base_id' WHERE filter_id IN ($ids_str)");
+                       db_query($this->link, "UPDATE ttrss_filters2_actions
+                               SET filter_id = '$base_id' WHERE filter_id IN ($ids_str)");
+
+                       db_query($this->link, "DELETE FROM ttrss_filters2 WHERE id IN ($ids_str)");
+                       db_query($this->link, "UPDATE ttrss_filters2 SET match_any_rule = true WHERE id = '$base_id'");
+
+                       db_query($this->link, "COMMIT");
+
+                       $this->optimizeFilter($base_id);
+
+               }
+       }
+
+       private function optimizeFilter($id) {
+               db_query($this->link, "BEGIN");
+               $result = db_query($this->link, "SELECT * FROM ttrss_filters2_actions
+                       WHERE filter_id = '$id'");
+
+               $tmp = array();
+               $dupe_ids = array();
+
+               while ($line = db_fetch_assoc($result)) {
+                       $id = $line["id"];
+                       unset($line["id"]);
+
+                       if (array_search($line, $tmp) === false) {
+                               array_push($tmp, $line);
+                       } else {
+                               array_push($dupe_ids, $id);
+                       }
+               }
+
+               if (count($dupe_ids) > 0) {
+                       $ids_str = join(",", $dupe_ids);
+                       db_query($this->link, "DELETE FROM ttrss_filters2_actions
+                               WHERE id IN ($ids_str)");
+               }
+
+               $result = db_query($this->link, "SELECT * FROM ttrss_filters2_rules
+                       WHERE filter_id = '$id'");
+
+               $tmp = array();
+               $dupe_ids = array();
+
+               while ($line = db_fetch_assoc($result)) {
+                       $id = $line["id"];
+                       unset($line["id"]);
+
+                       if (array_search($line, $tmp) === false) {
+                               array_push($tmp, $line);
+                       } else {
+                               array_push($dupe_ids, $id);
+                       }
+               }
+
+               if (count($dupe_ids) > 0) {
+                       $ids_str = join(",", $dupe_ids);
+                       db_query($this->link, "DELETE FROM ttrss_filters2_rules
+                               WHERE id IN ($ids_str)");
+               }
+
+               db_query($this->link, "COMMIT");
+       }
 }
 ?>
index 317f92738ff481d3a91c978f7bb9d7553384df71..a7f79146a79611c8dd6d1812253e581baf0dc176 100644 (file)
@@ -192,10 +192,10 @@ class Pref_Labels extends Handler_Protected {
 
                                        $old_caption = db_escape_string($old_caption);
 
-                                       db_query($this->link, "UPDATE ttrss_filters SET
+                                       db_query($this->link, "UPDATE ttrss_filters2_actions SET
                                                action_param = '$caption' WHERE action_param = '$old_caption'
                                                AND action_id = 7
-                                               AND owner_uid = " . $_SESSION["uid"]);
+                                               AND filter_id IN (SELECT id FROM ttrss_filters2 WHERE owner_uid = ".$_SESSION["uid"].")");
 
                                        print $_REQUEST["value"];
                                } else {
index ddd166f3a24d6cfbff093845830bdecace683678..ac0276fc7607b180ece39b616d8d9d1af1d675ba 100644 (file)
@@ -1,6 +1,6 @@
 <?php
        define('EXPECTED_CONFIG_VERSION', 26);
-       define('SCHEMA_VERSION', 95);
+       define('SCHEMA_VERSION', 96);
 
        $fetch_last_error = false;
 
        function get_article_filters($filters, $title, $content, $link, $timestamp, $author, $tags) {
                $matches = array();
 
-               if ($filters["title"]) {
-                       foreach ($filters["title"] as $filter) {
-                               $reg_exp = $filter["reg_exp"];
-                               $inverse = $filter["inverse"];
-                               if ((!$inverse && @preg_match("/$reg_exp/i", $title)) ||
-                                               ($inverse && !@preg_match("/$reg_exp/i", $title))) {
+               foreach ($filters as $filter) {
+                       $match_any_rule = $filter["match_any_rule"];
+                       $filter_match = false;
 
-                                       array_push($matches, array($filter["action"], $filter["action_param"]));
-                               }
-                       }
-               }
+                       foreach ($filter["rules"] as $rule) {
+                               $match = false;
+                               $reg_exp = $rule["reg_exp"];
 
-               if ($filters["content"]) {
-                       foreach ($filters["content"] as $filter) {
-                               $reg_exp = $filter["reg_exp"];
-                               $inverse = $filter["inverse"];
+                               if (!$reg_exp)
+                                       continue;
 
-                               if ((!$inverse && @preg_match("/$reg_exp/i", $content)) ||
-                                               ($inverse && !@preg_match("/$reg_exp/i", $content))) {
-
-                                       array_push($matches, array($filter["action"], $filter["action_param"]));
+                               switch ($rule["type"]) {
+                               case "title":
+                                       $match = @preg_match("/$reg_exp/i", $title);
+                                       break;
+                               case "content":
+                                       $match = @preg_match("/$reg_exp/i", $content);
+                                       break;
+                               case "both":
+                                       $match = (@preg_match("/$reg_exp/i", $title) || @preg_match("/$reg_exp/i", $title));
+                                       break;
+                               case "link":
+                                       $match = @preg_match("/$reg_exp/i", $link);
+                                       break;
+                               case "author":
+                                       $match = @preg_match("/$reg_exp/i", $author);
+                                       break;
+                               case "tag":
+                                       $tag_string = join(",", $tags);
+                                       $match = @preg_match("/$reg_exp/i", $tag_string);
+                                       break;
                                }
-                       }
-               }
 
-               if ($filters["both"]) {
-                       foreach ($filters["both"] as $filter) {
-                               $reg_exp = $filter["reg_exp"];
-                               $inverse = $filter["inverse"];
-
-                               if ($inverse) {
-                                       if (!@preg_match("/$reg_exp/i", $title) && !preg_match("/$reg_exp/i", $content)) {
-                                               array_push($matches, array($filter["action"], $filter["action_param"]));
+                               if ($match_any_rule) {
+                                       if ($match) {
+                                               $filter_match = true;
+                                               break;
                                        }
                                } else {
-                                       if (@preg_match("/$reg_exp/i", $title) || preg_match("/$reg_exp/i", $content)) {
-                                               array_push($matches, array($filter["action"], $filter["action_param"]));
-                                       }
-                               }
-                       }
-               }
-
-               if ($filters["link"]) {
-                       $reg_exp = $filter["reg_exp"];
-                       foreach ($filters["link"] as $filter) {
-                               $reg_exp = $filter["reg_exp"];
-                               $inverse = $filter["inverse"];
-
-                               if ((!$inverse && @preg_match("/$reg_exp/i", $link)) ||
-                                               ($inverse && !@preg_match("/$reg_exp/i", $link))) {
-
-                                       array_push($matches, array($filter["action"], $filter["action_param"]));
-                               }
-                       }
-               }
-
-               if ($filters["date"]) {
-                       $reg_exp = $filter["reg_exp"];
-                       foreach ($filters["date"] as $filter) {
-                               $date_modifier = $filter["filter_param"];
-                               $inverse = $filter["inverse"];
-                               $check_timestamp = strtotime($filter["reg_exp"]);
-
-                               # no-op when timestamp doesn't parse to prevent misfires
-
-                               if ($check_timestamp) {
-                                       $match_ok = false;
-
-                                       if ($date_modifier == "before" && $timestamp < $check_timestamp ||
-                                               $date_modifier == "after" && $timestamp > $check_timestamp) {
-                                                       $match_ok = true;
-                                       }
-
-                                       if ($inverse) $match_ok = !$match_ok;
-
-                                       if ($match_ok) {
-                                               array_push($matches, array($filter["action"], $filter["action_param"]));
+                                       $filter_match = $match;
+                                       if (!$match) {
+                                               break;
                                        }
                                }
                        }
-               }
-
-               if ($filters["author"]) {
-                       foreach ($filters["author"] as $filter) {
-                               $reg_exp = $filter["reg_exp"];
-                               $inverse = $filter["inverse"];
-                               if ((!$inverse && @preg_match("/$reg_exp/i", $author)) ||
-                                               ($inverse && !@preg_match("/$reg_exp/i", $author))) {
 
-                                       array_push($matches, array($filter["action"], $filter["action_param"]));
+                       if ($filter_match) {
+                               foreach ($filter["actions"] AS $action) {
+                                       array_push($matches, $action);
                                }
                        }
                }
 
-               if ($filters["tag"]) {
-
-                       $tag_string = join(",", $tags);
-
-                       foreach ($filters["tag"] as $filter) {
-                               $reg_exp = $filter["reg_exp"];
-                               $inverse = $filter["inverse"];
-
-                               if ((!$inverse && @preg_match("/$reg_exp/i", $tag_string)) ||
-                                               ($inverse && !@preg_match("/$reg_exp/i", $tag_string))) {
-
-                                       array_push($matches, array($filter["action"], $filter["action_param"]));
-                               }
-                       }
-               }
-
-
                return $matches;
        }
 
        function find_article_filter($filters, $filter_name) {
                foreach ($filters as $f) {
-                       if ($f[0] == $filter_name) {
+                       if ($f["type"] == $filter_name) {
                                return $f;
                        };
                }
                return false;
        }
 
+       function find_article_filters($filters, $filter_name) {
+               $results = array();
+
+               foreach ($filters as $f) {
+                       if ($f["type"] == $filter_name) {
+                               array_push($results, $f);
+                       };
+               }
+               return $results;
+       }
+
        function calculate_article_score($filters) {
                $score = 0;
 
                foreach ($filters as $f) {
-                       if ($f[0] == "score") {
-                               $score += $f[1];
+                       if ($f["type"] == "score") {
+                               $score += $f["param"];
                        };
                }
                return $score;
 
        function assign_article_to_labels($link, $id, $filters, $owner_uid) {
                foreach ($filters as $f) {
-                       if ($f[0] == "label") {
-                               label_add_article($link, $id, $f[1], $owner_uid);
+                       if ($f["type"] == "label") {
+                               label_add_article($link, $id, $f["param"], $owner_uid);
                        };
                }
        }
                return $text;
        }
 
-       function load_filters($link, $feed, $owner_uid, $action_id = false) {
+       function load_filters($link, $feed_id, $owner_uid, $action_id = false) {
                $filters = array();
 
+               $cat_id = getFeedCategory($link, $feed_id);
 
-               if ($action_id) $ftype_query_part = "action_id = '$action_id' AND";
-
-               $result = db_query($link, "SELECT reg_exp,
-                       ttrss_filter_types.name AS name,
-                       ttrss_filter_actions.name AS action,
-                       inverse,
-                       action_param,
-                       filter_param
-                       FROM ttrss_filters
-                               LEFT JOIN ttrss_feeds ON (ttrss_feeds.id = '$feed'),
-                               ttrss_filter_types,ttrss_filter_actions
-                       WHERE
-                               enabled = true AND
-                               $ftype_query_part
-                               ttrss_filters.owner_uid = $owner_uid AND
-                               ttrss_filter_types.id = filter_type AND
-                               ttrss_filter_actions.id = action_id AND
-                               ((cat_filter = true AND ttrss_feeds.cat_id = ttrss_filters.cat_id) OR
-                               (cat_filter = true AND ttrss_feeds.cat_id IS NULL AND
-                                       ttrss_filters.cat_id IS NULL) OR
-                               (cat_filter = false AND (feed_id IS NULL OR feed_id = '$feed')))
-                       ORDER BY reg_exp");
+               $result = db_query($link, "SELECT * FROM ttrss_filters2 WHERE
+                       owner_uid = $owner_uid AND enabled = true");
 
                while ($line = db_fetch_assoc($result)) {
+                       $filter_id = $line["id"];
+
+                       $result2 = db_query($link, "SELECT
+                               r.reg_exp, r.feed_id, r.cat_id, r.cat_filter, t.name AS type_name
+                               FROM ttrss_filters2_rules AS r,
+                               ttrss_filter_types AS t
+                               WHERE
+                                       (cat_id IS NULL OR cat_id = '$cat_id') AND
+                                       (feed_id IS NULL OR feed_id = '$feed_id') AND
+                                       filter_type = t.id AND filter_id = '$filter_id'");
+
+                       $rules = array();
+                       $actions = array();
 
-                       if (!$filters[$line["name"]]) $filters[$line["name"]] = array();
-                               $filter["reg_exp"] = $line["reg_exp"];
-                               $filter["action"] = $line["action"];
-                               $filter["action_param"] = $line["action_param"];
-                               $filter["filter_param"] = $line["filter_param"];
-                               $filter["inverse"] = sql_bool_to_bool($line["inverse"]);
+                       while ($rule_line = db_fetch_assoc($result2)) {
+#                              print_r($rule_line);
 
-                               array_push($filters[$line["name"]], $filter);
+                               $rule = array();
+                               $rule["reg_exp"] = $rule_line["reg_exp"];
+                               $rule["type"] = $rule_line["type_name"];
+
+                               array_push($rules, $rule);
+                       }
+
+                       $result2 = db_query($link, "SELECT a.action_param,t.name AS type_name
+                               FROM ttrss_filters2_actions AS a,
+                               ttrss_filter_actions AS t
+                               WHERE
+                                       action_id = t.id AND filter_id = '$filter_id'");
+
+                       while ($action_line = db_fetch_assoc($result2)) {
+#                              print_r($action_line);
+
+                               $action = array();
+                               $action["type"] = $action_line["type_name"];
+                               $action["param"] = $action_line["action_param"];
+
+                               array_push($actions, $action);
                        }
 
 
+                       $filter = array();
+                       $filter["match_any_rule"] = sql_bool_to_bool($line["match_any_rule"]);
+                       $filter["rules"] = $rules;
+                       $filter["actions"] = $actions;
+
+                       if (count($rules) > 0 && count($actions) > 0) {
+                               array_push($filters, $filter);
+                       }
+               }
+
                return $filters;
        }
 
        return $tempname;
        }
 
+       function getFeedCategory($link, $feed) {
+               $result = db_query($link, "SELECT cat_id FROM ttrss_feeds
+                       WHERE id = '$feed'");
+
+               if (db_num_rows($result) > 0) {
+                       return db_fetch_result($result, 0, "cat_id");
+               } else {
+                       return false;
+               }
+
+       }
+
 ?>
index 241896f8bcb737ed749cea292e265efea9656441..47e0c68f32612c98f4261bf4c2a7e63175ad9ff1 100644 (file)
                                        $entry_tags[$i] = mb_strtolower($entry_tags[$i], 'utf-8');
 
                                if ($debug_enabled) {
-                                       _debug("update_rss_feed: unfiltered tags found:");
-                                       print_r($entry_tags);
+                                       //_debug("update_rss_feed: unfiltered tags found:");
+                                       //print_r($entry_tags);
                                }
 
                                # sanitize content
                                // check for manual tags (we have to do it here since they're loaded from filters)
 
                                foreach ($article_filters as $f) {
-                                       if ($f[0] == "tag") {
+                                       if ($f["type"] == "tag") {
 
-                                               $manual_tags = trim_array(explode(",", $f[1]));
+                                               $manual_tags = trim_array(explode(",", $f["param"]));
 
                                                foreach ($manual_tags as $tag) {
                                                        if (tag_is_valid($tag)) {
index 3aa73035908545232819beb04bd5ad7956949a59..f2c5e3bf5f9cd1c7902bc7e7a4860099479d443c 100644 (file)
@@ -545,7 +545,7 @@ function fatalError(code, msg, ext_info) {
        }
 }
 
-function filterDlgCheckType(sender) {
+/* function filterDlgCheckType(sender) {
 
        try {
 
@@ -565,7 +565,7 @@ function filterDlgCheckType(sender) {
                exception_error("filterDlgCheckType", e);
        }
 
-}
+} */
 
 function filterDlgCheckAction(sender) {
 
@@ -938,17 +938,163 @@ function quickAddFeed() {
        }
 }
 
+function createNewRuleElement(parentNode, replaceNode) {
+       try {
+               var form = document.forms["filter_new_rule_form"];
+
+               var query = "backend.php?op=pref-filters&method=printrulename&rule="+
+                       param_escape(dojo.formToJson(form));
+
+               console.log(query);
+
+               new Ajax.Request("backend.php", {
+                       parameters: query,
+                       onComplete: function (transport) {
+                               try {
+                                       var li = dojo.create("li");
+
+                                       dojo.create("input", { type: "checkbox",
+                                               onclick: function() { toggleSelectListRow(this) },
+                                       }, li);
+
+                                       dojo.create("input", { type: "hidden",
+                                               name: "rule[]",
+                                               value: dojo.formToJson(form) }, li);
+
+                                       dojo.create("span", {
+                                               onclick: function() {
+                                                       dijit.byId('filterEditDlg').editRule(this);
+                                               },
+                                               innerHTML: transport.responseText }, li);
+
+                                       if (replaceNode) {
+                                               parentNode.replaceChild(li, replaceNode);
+                                       } else {
+                                               parentNode.appendChild(li);
+                                       }
+                               } catch (e) {
+                                       exception_error("createNewRuleElement", e);
+                               }
+               } });
+       } catch (e) {
+               exception_error("createNewRuleElement", e);
+       }
+}
+
+function createNewActionElement(parentNode, replaceNode) {
+       try {
+               var form = document.forms["filter_new_action_form"];
+
+               if (form.action_id.value == 7) {
+                       form.action_param.value = form.action_param_label.value;
+               }
+
+               var query = "backend.php?op=pref-filters&method=printactionname&action="+
+                       param_escape(dojo.formToJson(form));
+
+               console.log(query);
+
+               new Ajax.Request("backend.php", {
+                       parameters: query,
+                       onComplete: function (transport) {
+                               try {
+                                       var li = dojo.create("li");
+
+                                       dojo.create("input", { type: "checkbox",
+                                               onclick: function() { toggleSelectListRow(this) },
+                                       }, li);
+
+                                       dojo.create("input", { type: "hidden",
+                                               name: "action[]",
+                                               value: dojo.formToJson(form) }, li);
+
+                                       dojo.create("span", {
+                                               onclick: function() {
+                                                       dijit.byId('filterEditDlg').editAction(this);
+                                               },
+                                               innerHTML: transport.responseText }, li);
+
+                                       if (replaceNode) {
+                                               parentNode.replaceChild(li, replaceNode);
+                                       } else {
+                                               parentNode.appendChild(li);
+                                       }
+
+                               } catch (e) {
+                                       exception_error("createNewActionElement", e);
+                               }
+                       } });
+       } catch (e) {
+               exception_error("createNewActionElement", e);
+       }
+}
+
+
+function addFilterRule(replaceNode, ruleStr) {
+       try {
+               if (dijit.byId("filterNewRuleDlg"))
+                       dijit.byId("filterNewRuleDlg").destroyRecursive();
+
+               var query = "backend.php?op=pref-filters&method=newrule&rule=" +
+                       param_escape(ruleStr);
+
+               var rule_dlg = new dijit.Dialog({
+                       id: "filterNewRuleDlg",
+                       title: ruleStr ? __("Edit rule") : __("Add rule"),
+                       style: "width: 600px",
+                       execute: function() {
+                               if (this.validate()) {
+                                       createNewRuleElement($("filterDlg_Matches"), replaceNode);
+                                       this.hide();
+                               }
+                       },
+                       href: query});
+
+               rule_dlg.show();
+       } catch (e) {
+               exception_error("addFilterRule", e);
+       }
+}
+
+function addFilterAction(replaceNode, actionStr) {
+       try {
+               if (dijit.byId("filterNewActionDlg"))
+                       dijit.byId("filterNewActionDlg").destroyRecursive();
+
+               var query = "backend.php?op=pref-filters&method=newaction&action=" +
+                       param_escape(actionStr);
+
+               var rule_dlg = new dijit.Dialog({
+                       id: "filterNewActionDlg",
+                       title: actionStr ? __("Edit action") : __("Add action"),
+                       style: "width: 600px",
+                       execute: function() {
+                               if (this.validate()) {
+                                       createNewActionElement($("filterDlg_Actions"), replaceNode);
+                                       this.hide();
+                               }
+                       },
+                       href: query});
+
+               rule_dlg.show();
+       } catch (e) {
+               exception_error("addFilterAction", e);
+       }
+}
+
 function quickAddFilter() {
        try {
                var query = "";
                if (!inPreferences()) {
-                       query = "backend.php?op=dlg&method=quickAddFilter&feed=" +
+                       query = "backend.php?op=pref-filters&method=newfilter&feed=" +
                                param_escape(getActiveFeedId()) + "&is_cat=" +
                                param_escape(activeFeedIsCat());
                } else {
-                       query = "backend.php?op=dlg&method=quickAddFilter";
+                       query = "backend.php?op=pref-filters&method=newfilter";
                }
 
+               console.log(query);
+
                if (dijit.byId("feedEditDlg"))
                        dijit.byId("feedEditDlg").destroyRecursive();
 
@@ -959,96 +1105,46 @@ function quickAddFilter() {
                        id: "filterEditDlg",
                        title: __("Create Filter"),
                        style: "width: 600px",
-                       test: function() {
-                               if (this.validate()) {
-
-                                       var query = "?op=rpc&method=verifyRegexp&reg_exp=" +
-                                               param_escape(dialog.attr('value').reg_exp);
-
-                                       notify_progress("Verifying regular expression...");
-
-                                       new Ajax.Request("backend.php", {
-                                               parameters: query,
-                                               onComplete: function(transport) {
-                                                       var reply = JSON.parse(transport.responseText);
-
-                                                       if (reply) {
-                                                               notify('');
-
-                                                               if (!reply['status']) {
-                                                                       alert("Invalid regular expression.");
-                                                                       return;
-                                                               } else {
-
-                                                                       if (dijit.byId("filterTestDlg"))
-                                                                               dijit.byId("filterTestDlg").destroyRecursive();
-
-                                                                       tdialog = new dijit.Dialog({
-                                                                               id: "filterTestDlg",
-                                                                               title: __("Filter Test Results"),
-                                                                               style: "width: 600px",
-                                                                               href: "backend.php?savemode=test&" +
-                                                                               dojo.objectToQuery(dialog.attr('value')),
-                                                                       });
-
-                                                                       tdialog.show();
-                                                               }
-                                                       }
-                                       }});
-                               }
+                       editRule: function(e) {
+                               var li = e.parentNode;
+                               var rule = li.getElementsByTagName("INPUT")[1].value;
+                               addFilterRule(li, rule);
+                       },
+                       editAction: function(e) {
+                               var li = e.parentNode;
+                               var action = li.getElementsByTagName("INPUT")[1].value;
+                               addFilterAction(li, action);
+                       },
+                       addAction: function() { addFilterAction(); },
+                       addRule: function() { addFilterRule(); },
+                       deleteAction: function() {
+                               $$("#filterDlg_Actions li.[class*=Selected]").each(function(e) { e.parentNode.removeChild(e) });
+                       },
+                       deleteRule: function() {
+                               $$("#filterDlg_Matches li.[class*=Selected]").each(function(e) { e.parentNode.removeChild(e) });
                        },
                        execute: function() {
                                if (this.validate()) {
 
-                                       var query = "?op=rpc&method=verifyRegexp&reg_exp=" +
-                                               param_escape(dialog.attr('value').reg_exp);
+                                       var query = dojo.formToQuery("filter_new_form");
 
-                                       notify_progress("Verifying regular expression...");
+                                       console.log(query);
 
-                                       new Ajax.Request("backend.php", {
+                                       new Ajax.Request("backend.php", {
                                                parameters: query,
-                                               onComplete: function(transport) {
-                                                       var reply = JSON.parse(transport.responseText);
-
-                                                       if (reply) {
-                                                               notify('');
-
-                                                               if (!reply['status']) {
-                                                                       alert("Invalid regular expression.");
-                                                                       return;
-                                                               } else {
-                                                                       notify_progress("Saving data...", true);
-
-                                                                       console.log(dojo.objectToQuery(dialog.attr('value')));
-
-                                                                       new Ajax.Request("backend.php", {
-                                                                               parameters: dojo.objectToQuery(dialog.attr('value')),
-                                                                               onComplete: function(transport) {
-                                                                                       dialog.hide();
-                                                                                       notify_info(transport.responseText);
-                                                                                       if (inPreferences()) {
-                                                                                               updateFilterList();
-                                                                                       }
-                                                                       }});
-                                                               }
+                                               onComplete: function (transport) {
+                                                       if (inPreferences()) {
+                                                               updateFilterList();
                                                        }
-                                       }});
+
+                                                       dialog.hide();
+                                       } });
                                }
                        },
                        href: query});
 
                dialog.show();
 
-               var lh = dojo.connect(dialog, "onLoad",
-                               function() {
-                                       dojo.disconnect(lh);
-                                       var title = $("PTITLE-FULL-" + active_post_id);
-
-                                       if (title) {
-                                               $("filterDlg_regExp").value = title.innerHTML;
-                                       }
-                       });
-
        } catch (e) {
                exception_error("quickAddFilter", e);
        }
index b308d011defc3fba3e1bd7bffa9cfe8536d23327..1fbbc55a58c8654a87d218e6a9dd0075fe145c60 100644 (file)
@@ -136,9 +136,18 @@ function editFilter(id) {
                        id: "filterEditDlg",
                        title: __("Edit Filter"),
                        style: "width: 600px",
+                       editRule: function(e) {
+                               var li = e.parentNode;
+                               var rule = li.getElementsByTagName("INPUT")[1].value;
+                               addFilterRule(li, rule);
+                       },
+                       editAction: function(e) {
+                               var li = e.parentNode;
+                               var action = li.getElementsByTagName("INPUT")[1].value;
+                               addFilterAction(li, action);
+                       },
                        removeFilter: function() {
-                               var title = this.attr('value').reg_exp;
-                               var msg = __("Remove filter %s?").replace("%s", title);
+                               var msg = __("Remove filter?");
 
                                if (confirm(msg)) {
                                        this.hide();
@@ -157,57 +166,29 @@ function editFilter(id) {
                                                } });
                                }
                        },
-                       test: function() {
-                               if (this.validate()) {
-
-                                       if (dijit.byId("filterTestDlg"))
-                                               dijit.byId("filterTestDlg").destroyRecursive();
-
-                                       tdialog = new dijit.Dialog({
-                                               id: "filterTestDlg",
-                                               title: __("Filter Test Results"),
-                                               style: "width: 600px",
-                                               href: "backend.php?savemode=test&" +
-                                                       dojo.objectToQuery(dialog.attr('value')),
-                                               });
-
-                                       tdialog.show();
-
-                               }
+                       addAction: function() { addFilterAction(); },
+                       addRule: function() { addFilterRule(); },
+                       deleteAction: function() {
+                               $$("#filterDlg_Actions li.[class*=Selected]").each(function(e) { e.parentNode.removeChild(e) });
+                       },
+                       deleteRule: function() {
+                               $$("#filterDlg_Matches li.[class*=Selected]").each(function(e) { e.parentNode.removeChild(e) });
                        },
                        execute: function() {
                                if (this.validate()) {
 
-                                       var query = "?op=rpc&method=verifyRegexp&reg_exp=" +
-                                               param_escape(dialog.attr('value').reg_exp);
+                                       notify_progress("Saving data...", true);
 
-                                       notify_progress("Verifying regular expression...");
+                                       var query = dojo.formToQuery("filter_edit_form");
 
-                                       new Ajax.Request("backend.php", {
+                                       console.log(query);
+
+                                       new Ajax.Request("backend.php", {
                                                parameters: query,
                                                onComplete: function(transport) {
-                                                       var reply = JSON.parse(transport.responseText);
-
-                                                       if (reply) {
-                                                               notify('');
-
-                                                               if (!reply['status']) {
-                                                                       alert("Match regular expression seems to be invalid.");
-                                                                       return;
-                                                               } else {
-                                                                       notify_progress("Saving data...", true);
-
-                                                                       console.log(dojo.objectToQuery(dialog.attr('value')));
-
-                                                                       new Ajax.Request("backend.php", {
-                                                                               parameters: dojo.objectToQuery(dialog.attr('value')),
-                                                                               onComplete: function(transport) {
-                                                                                       dialog.hide();
-                                                                                       updateFilterList();
-                                                                       }});
-                                                               }
-                                                       }
-                                       }});
+                                                       dialog.hide();
+                                                       updateFilterList();
+                                               }});
                                }
                        },
                        href: query});
@@ -605,6 +586,31 @@ function editSelectedFilter() {
 
 }
 
+function joinSelectedFilters() {
+       var rows = getSelectedFilters();
+
+       if (rows.length == 0) {
+               alert(__("No filters are selected."));
+               return;
+       }
+
+       var ok = confirm(__("Combine selected filters?"));
+
+       if (ok) {
+               notify_progress("Joining filters...");
+
+               var query = "?op=pref-filters&method=join&ids="+
+                       param_escape(rows.toString());
+
+               console.log(query);
+
+               new Ajax.Request("backend.php", {
+                       parameters: query,
+                       onComplete: function(transport) {
+                                       updateFilterList();
+                       } });
+       }
+}
 
 function editSelectedFeed() {
        var rows = getSelectedFeeds();
index e5109de27e6791235125f2fb1f64329f1d1afacf..9a160f2aa72c92f43e9673fa2459662f616c5429 100644 (file)
@@ -9,6 +9,9 @@ drop table if exists ttrss_labels2;
 drop table if exists ttrss_feedbrowser_cache;
 drop table if exists ttrss_version;
 drop table if exists ttrss_labels;
+drop table if exists ttrss_filters2_actions;
+drop table if exists ttrss_filters2_rules;
+drop table if exists ttrss_filters2;
 drop table if exists ttrss_filters;
 drop table if exists ttrss_filter_types;
 drop table if exists ttrss_filter_actions;
@@ -259,6 +262,38 @@ create table ttrss_filters (id integer not null primary key auto_increment,
        index (action_id),
        foreign key (action_id) references ttrss_filter_actions(id) ON DELETE CASCADE) ENGINE=InnoDB DEFAULT CHARSET=UTF8;
 
+create table ttrss_filters2(id integer primary key auto_increment,
+       owner_uid integer not null,
+       match_any_rule boolean not null default false,
+       enabled boolean not null default true,
+       index(owner_uid),
+       foreign key (owner_uid) references ttrss_users(id) ON DELETE CASCADE) ENGINE=InnoDB DEFAULT CHARSET=UTF8;
+       
+create table ttrss_filters2_rules(id integer primary key auto_increment,
+       filter_id integer not null references ttrss_filters2(id) on delete cascade,
+       reg_exp varchar(250) not null,
+       filter_type integer not null,
+       feed_id integer default null,
+       cat_id integer default null,
+       cat_filter boolean not null default false,
+       index (filter_id),
+       foreign key (filter_id) references ttrss_filters2(id) on delete cascade,
+       index (filter_type),
+       foreign key (filter_type) references ttrss_filter_types(id) ON DELETE CASCADE,
+       index (feed_id),
+       foreign key (feed_id) references ttrss_feeds(id) ON DELETE CASCADE,
+       index (cat_id),
+       foreign key (cat_id) references ttrss_feed_categories(id) ON DELETE CASCADE) ENGINE=InnoDB DEFAULT CHARSET=UTF8;
+
+create table ttrss_filters2_actions(id integer primary key auto_increment,
+       filter_id integer not null,
+       action_id integer not null default 1 references ttrss_filter_actions(id) on delete cascade,
+       action_param varchar(250) not null default '',
+       index (filter_id),
+       foreign key (filter_id) references ttrss_filters2(id) on delete cascade,
+       index (action_id),
+       foreign key (action_id) references ttrss_filter_actions(id) ON DELETE CASCADE) ENGINE=InnoDB DEFAULT CHARSET=UTF8;
+
 create table ttrss_tags (id integer primary key auto_increment,
        owner_uid integer not null,
        tag_name varchar(250) not null,
@@ -270,7 +305,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 (95);
+insert into ttrss_version values (96);
 
 create table ttrss_enclosures (id integer primary key auto_increment,
        content_url text not null,
index 778e2111a2ced97081abb963315931e5f246cc18..600714e6e17ca766455ae1e655d97b75c54c801f 100644 (file)
@@ -6,6 +6,9 @@ drop table if exists ttrss_labels2;
 drop table if exists ttrss_feedbrowser_cache;
 drop table if exists ttrss_version;
 drop table if exists ttrss_labels;
+drop table if exists ttrss_filters2_rules;
+drop table if exists ttrss_filters2_actions;
+drop table if exists ttrss_filters2;
 drop table if exists ttrss_filters;
 drop table if exists ttrss_filter_types;
 drop table if exists ttrss_filter_actions;
@@ -222,6 +225,24 @@ create table ttrss_filters (id serial not null primary key,
        action_id integer not null default 1 references ttrss_filter_actions(id) on delete cascade,
        action_param varchar(250) not null default '');
 
+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,
+       enabled boolean not null default true);
+       
+create table ttrss_filters2_rules(id serial not null primary key,
+       filter_id integer not null references ttrss_filters2(id) on delete cascade,
+       reg_exp varchar(250) not null,
+       filter_type integer not null references ttrss_filter_types(id),
+       feed_id integer references ttrss_feeds(id) on delete cascade default null,
+       cat_id integer references ttrss_feed_categories(id) on delete cascade default null,
+       cat_filter boolean not null default false);
+
+create table ttrss_filters2_actions(id serial not null primary key,
+       filter_id integer not null references ttrss_filters2(id) on delete cascade,
+       action_id integer not null default 1 references ttrss_filter_actions(id) on delete cascade,
+       action_param varchar(250) not null default '');
+
 create table ttrss_tags (id serial not null primary key,
        tag_name varchar(250) not null,
        owner_uid integer not null references ttrss_users(id) on delete cascade,
@@ -232,7 +253,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 (95);
+insert into ttrss_version values (96);
 
 create table ttrss_enclosures (id serial not null primary key,
        content_url text not null,
diff --git a/schema/versions/mysql/96.sql b/schema/versions/mysql/96.sql
new file mode 100644 (file)
index 0000000..4d4e244
--- /dev/null
@@ -0,0 +1,38 @@
+begin;
+
+create table ttrss_filters2(id integer primary key auto_increment,
+       owner_uid integer not null,
+       match_any_rule boolean not null default false,
+       enabled boolean not null default true,
+       index(owner_uid),
+       foreign key (owner_uid) references ttrss_users(id) ON DELETE CASCADE) ENGINE=InnoDB DEFAULT CHARSET=UTF8;
+       
+create table ttrss_filters2_rules(id integer primary key auto_increment,
+       filter_id integer not null references ttrss_filters2(id) on delete cascade,
+       reg_exp varchar(250) not null,
+       filter_type integer not null,
+       feed_id integer default null,
+       cat_id integer default null,
+       cat_filter boolean not null default false,
+       index (filter_id),
+       foreign key (filter_id) references ttrss_filters2(id) on delete cascade,
+       index (filter_type),
+       foreign key (filter_type) references ttrss_filter_types(id) ON DELETE CASCADE,
+       index (feed_id),
+       foreign key (feed_id) references ttrss_feeds(id) ON DELETE CASCADE,
+       index (cat_id),
+       foreign key (cat_id) references ttrss_feed_categories(id) ON DELETE CASCADE) ENGINE=InnoDB DEFAULT CHARSET=UTF8;
+
+create table ttrss_filters2_actions(id integer primary key auto_increment,
+       filter_id integer not null,
+       action_id integer not null default 1 references ttrss_filter_actions(id) on delete cascade,
+       action_param varchar(250) not null default '',
+       index (filter_id),
+       foreign key (filter_id) references ttrss_filters2(id) on delete cascade,
+       index (action_id),
+       foreign key (action_id) references ttrss_filter_actions(id) ON DELETE CASCADE) ENGINE=InnoDB DEFAULT CHARSET=UTF8;
+
+update ttrss_version set schema_version = 96;
+
+commit;
+
diff --git a/schema/versions/pgsql/96.sql b/schema/versions/pgsql/96.sql
new file mode 100644 (file)
index 0000000..86895e5
--- /dev/null
@@ -0,0 +1,23 @@
+begin;
+
+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,
+       enabled boolean not null default true);
+       
+create table ttrss_filters2_rules(id serial not null primary key,
+       filter_id integer not null references ttrss_filters2(id) on delete cascade,
+       reg_exp varchar(250) not null,
+       filter_type integer not null references ttrss_filter_types(id),
+       feed_id integer references ttrss_feeds(id) on delete cascade default null,
+       cat_id integer references ttrss_feed_categories(id) on delete cascade default null,
+       cat_filter boolean not null default false);
+
+create table ttrss_filters2_actions(id serial not null primary key,
+       filter_id integer not null references ttrss_filters2(id) on delete cascade,
+       action_id integer not null default 1 references ttrss_filter_actions(id) on delete cascade,
+       action_param varchar(250) not null default '');
+
+update ttrss_version set schema_version = 95;
+
+commit;
index 421e6f153a2fde033f0e97acdf77ad65fd81398b..801a96ac946c14ddec2389e603efde912f192e3c 100644 (file)
@@ -1426,3 +1426,19 @@ div.dialogNotice {
        margin-bottom : 5px;
        color : gray;
 }
+
+ul#filterDlg_Matches, ul#filterDlg_Actions {
+       max-height : 100px;
+       overflow : auto;
+       list-style-type : none;
+       border-style : solid;
+       border-color : #c0c0c0;
+       border-width : 0px 1px 1px 1px;
+       background-color : #ecf4ff;
+       margin : 0px 0px 5px 0px;
+       padding : 0px;
+}
+
+ul#filterDlg_Matches li, ul#filterDlg_Actions li {
+       cursor : pointer;
+}
index e28729293a2ba1756ca9944819cca5aabad935e7..51930beab03c50efefdbb359362c1f7d0d0290ce 100755 (executable)
@@ -51,6 +51,7 @@
                print "  -update-self        - update tt-rss installation to latest version\n";
                print "  -quiet              - don't show messages\n";
                print "  -indexes            - recreate missing schema indexes\n";
+               print "  -convert-filters    - convert type1 filters to type2\n";
                print "  -help               - show this help\n";
                return;
        }
                update_self($link, in_array("-force", $op));
        }
 
+       if (in_array("-convert-filters", $op)) {
+               _debug("WARNING: this will remove all existing type2 filters.");
+               _debug("Type 'yes' to continue.");
+
+               if (read_stdin() != 'yes')
+                       exit;
+
+               _debug("converting filters...");
+
+               db_query($link, "DELETE FROM ttrss_filters2");
+
+               $result = db_query($link, "SELECT * FROM ttrss_filters ORDER BY id");
+
+               while ($line = db_fetch_assoc($result)) {
+                       $owner_uid = $line["owner_uid"];
+
+                       $filter = array();
+
+                       if (sql_bool_to_bool($line["cat_filter"])) {
+                               $feed_id = "CAT:" . (int)$line["cat_id"];
+                       } else {
+                               $feed_id = (int)$line["feed_id"];
+                       }
+
+                       $filter["enabled"] = $line["enabled"] ? "on" : "off";
+                       $filter["rule"] = array(
+                               json_encode(array(
+                                       "reg_exp" => $line["reg_exp"],
+                                       "feed_id" => $feed_id,
+                                       "filter_type" => $line["filter_type"])));
+
+                       $filter["action"] = array(
+                               json_encode(array(
+                                       "action_id" => $line["action_id"],
+                                       "action_param_label" => $line["action_param"],
+                                       "action_param" => $line["action_param"])));
+
+                       // Oh god it's full of hacks
+
+                       $_REQUEST = $filter;
+                       $_SESSION["uid"] = $owner_uid;
+
+                       $filters = new Pref_Filters($link, $_REQUEST);
+                       $filters->add();
+               }
+
+       }
+
        db_close($link);
 
        if ($lock_handle != false) {