diff --git a/classes/dlg.php b/classes/dlg.php index c540214a6..0e5eef224 100644 --- a/classes/dlg.php +++ b/classes/dlg.php @@ -444,132 +444,6 @@ class Dlg extends Handler_Protected { "; } - function quickAddFilter() { - $active_feed_id = (int) db_escape_string($_REQUEST["feed"]); - $cat_filter = db_escape_string($_REQUEST["is_cat"]) == "true"; - - print ""; - print ""; - print ""; - print ""; - - $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 "
".__("Match")."
"; - - print "
"; - - print ""; - - $filter_params = array( - "before" => __("before"), - "after" => __("after")); - - print_select_hash("filter_date_modifier", "before", - $filter_params, 'dojoType="dijit.form.Select"'); - - print " "; - - print ""; - - print ""; - print " "; - print ""; - - print "
" . __("on field") . " "; - print_select_hash("filter_type", 1, $filter_types, - 'onchange="filterDlgCheckType(this)" dojoType="dijit.form.Select"'); - - print "
"; - - print __("in") . " "; - - print ""; - print_feed_select($this->link, "feed_id", - $cat_filter ? "CAT:$active_feed_id" : $active_feed_id, - 'dojoType="dijit.form.FilteringSelect"'); - print ""; - - print ""; - - print "
"; - - print "
".__("Perform Action")."
"; - - print "
"; - - print ""; - - print ""; - print " " . __("with parameters:") . " "; - print ""; - - print_label_select($this->link, "action_param_label", $action_param, - 'id="filterDlg_actionParamLabel" dojoType="dijit.form.Select"'); - - print ""; - - print " "; // tiny layout hack - - print "
"; - - print "
".__("Options")."
"; - print "
"; - - print " -
"; - - print " -
"; - -# print " -#
"; - - - print "
"; - - print "
"; - - print " "; - - print " "; - - print ""; - - print "
"; - } - function inactiveFeeds() { if (DB_TYPE == "pgsql") { diff --git a/classes/opml.php b/classes/opml.php index 8683fb73a..60d0d40e0 100644 --- a/classes/opml.php +++ b/classes/opml.php @@ -159,7 +159,7 @@ class Opml extends Handler_Protected { $out .= ""; - $out .= ""; +/* $out .= ""; $result = db_query($this->link, "SELECT filter_type, reg_exp, @@ -191,7 +191,7 @@ class Opml extends Handler_Protected { } - $out .= ""; + $out .= ""; */ } $out .= ""; @@ -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); diff --git a/classes/pref/filters.php b/classes/pref/filters.php index 1a6c49071..591d429eb 100644 --- a/classes/pref/filters.php +++ b/classes/pref/filters.php @@ -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 ""; print ""; - } + } */ 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"]; + $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"); - 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 "; + while ($line = db_fetch_assoc($result)) { - $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"); + $name = $this->getFilterName($line["id"]); - $cat = false; - $cur_action_description = ""; + $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"]; - 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"); - - $tmp = "α " . $line['action_param']; - - $line['action_param'] = $tmp; - } - } - } - - $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']; - - 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 "
"; @@ -242,104 +155,88 @@ class Pref_Filters extends Handler_Protected { print ""; print ""; - $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 "
".__("Match")."
"; - print "
"; + print "
"; - if ($filter_type != 5) { - $date_ops_invisible = 'style="display : none"'; - } + print "
". + "" . __('Select').""; + print "
"; + print "
".__('All')."
"; + print "
".__('None')."
"; + print "
"; - print ""; - print __("Date") . " "; + print " "; - $filter_params = array( - "before" => __("before"), - "after" => __("after")); - - print_select_hash("filter_date_modifier", $filter_param, - $filter_params, 'dojoType="dijit.form.Select"'); - - print " "; - - print ""; - - print ""; - print " "; - print ""; - - print "
" . __("on field") . " "; - print_select_hash("filter_type", $filter_type, $filter_types, - 'onchange="filterDlgCheckType(this)" dojoType="dijit.form.Select"'); - - print "
"; - - print __("in") . " "; - - print ""; - print_feed_select($this->link, "feed_id", ($cat_filter) ? "CAT:$cat_id" : $feed_id, - 'dojoType="dijit.form.FilteringSelect"'); - print ""; + print " "; print "
"; - print "
".__("Perform Action")."
"; + print ""; print "
"; - print "
".__("Options")."
"; - print "
"; + print "
".__("Apply actions")."
"; - print "
"; + print "
"; + + print "
". + "" . __('Select').""; + print "
"; + print "
".__('All')."
"; + print "
".__('None')."
"; + print "
"; + + print " "; + + print " "; + + print "
"; + + print "
    "; + + $actions_result = db_query($this->link, "SELECT * FROM ttrss_filters2_actions + WHERE filter_id = '$filter_id' ORDER BY id"); + + while ($line = db_fetch_assoc($actions_result)) { + $line["action_param_label"] = $line["action_param"]; + $data = htmlspecialchars(json_encode($line)); + + print "
  • ". + "".$this->getActionName($line)."". + "
  • "; + } + + print "
"; + + print "
"; if ($enabled) { $checked = "checked=\"1\""; @@ -348,28 +245,18 @@ class Pref_Filters extends Handler_Protected { } print " -
"; + "; - if ($inverse) { + if ($match_any_rule) { $checked = "checked=\"1\""; } else { $checked = ""; } - print " -
"; + print "
+ "; -# if ($cat_filter) { -# $checked = "checked=\"1\""; -# } else { -# $checked = ""; -# } - -# print " -#
"; - - print "
"; - print ""; + print "

"; print "

"; @@ -378,8 +265,8 @@ class Pref_Filters extends Handler_Protected { __('Remove').""; print "
"; - print " "; +# print " "; print " "; @@ -390,75 +277,66 @@ class Pref_Filters extends Handler_Protected { print ""; } - 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 "
"; - print ""; - print "
"; + 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 (!$feed_id) $feed_id = "NULL"; - if (!$cat_id) $feed_id = "NULL"; - - /* When processing 'assign label' filters, action_param_label dropbox - * overrides action_param */ - - if ($action_id == 7) { - $action_param = $action_param_label; - } - - if ($action_id == 6) { - $action_param = (int) str_replace("+", "", $action_param); - } - - 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 %s", htmlspecialchars($regexp)); + if (array_search($rule, $rules) === false) { + array_push($rules, $rule); + } } - } else { + foreach ($_REQUEST["action"] as $action) { + $action = json_decode($action, true); + unset($action["id"]); - $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 (array_search($action, $actions) === false) { + array_push($actions, $action); + } + } - print "
"; - print ""; - print "
"; + foreach ($rules as $rule) { + if ($rule) { + $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 (!$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); + } + } + + 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; + } + + if ($action_id == 6) { + $action_param = (int) str_replace("+", "", $action_param); + } + + $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 " "; + print " "; + print " "; @@ -648,5 +564,354 @@ class Pref_Filters extends Handler_Protected { print ""; #container } + + function newfilter() { + + print ""; + + $active_feed_id = (int) db_escape_string($_REQUEST["feed"]); + $cat_filter = db_escape_string($_REQUEST["is_cat"]) == "true"; + + print ""; + print ""; + print ""; + + print "
".__("Match")."
"; + + print "
"; + + print "
". + "" . __('Select').""; + print "
"; + print "
".__('All')."
"; + print "
".__('None')."
"; + print "
"; + + print " "; + + print " "; + + print "
"; + + print ""; + + print ""; + + print "
".__("Apply actions")."
"; + + print "
"; + + print "
". + "" . __('Select').""; + print "
"; + print "
".__('All')."
"; + print "
".__('None')."
"; + print "
"; + + print " "; + + print " "; + + print "
"; + + print ""; + +/* print "
".__("Options")."
"; + print "
"; */ + + print " + "; + + print "
+ "; + + print "

"; + +/* print " +


"; */ + +// print "
"; + + print "
"; + +# print " "; + + print " "; + + print ""; + + print "
"; + + } + + 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 ""; + + $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 "
".__("Match")."
"; + + print "
"; + + print ""; + + print "
" . __("on field") . " "; + print_select_hash("filter_type", $filter_type, $filter_types, + 'dojoType="dijit.form.Select"'); + + print "
"; + + print __("in") . " "; + + print ""; + print_feed_select($this->link, "feed_id", + $cat_filter ? "CAT:$feed_id" : $feed_id, + 'dojoType="dijit.form.FilteringSelect"'); + print ""; + + print "
"; + + print "
"; + + print " "; + + print ""; + + print "
"; + + print "
"; + } + + 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 "
"; + + print "
".__("Perform Action")."
"; + + print "
"; + + print ""; + + $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 ""; + print " " . __("with parameters:") . " "; + print ""; + + print_label_select($this->link, "action_param_label", $action_param, + "id=\"filterDlg_actionParamLabel\" style=\"$label_param_hidden\" + dojoType=\"dijit.form.Select\""); + + print ""; + + print " "; // tiny layout hack + + print "
"; + + print "
"; + + print " "; + + print ""; + + print "
"; + + print "
"; + } + + 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"); + } } ?> diff --git a/classes/pref/labels.php b/classes/pref/labels.php index 317f92738..a7f79146a 100644 --- a/classes/pref/labels.php +++ b/classes/pref/labels.php @@ -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 { diff --git a/include/functions.php b/include/functions.php index ddd166f3a..ac0276fc7 100644 --- a/include/functions.php +++ b/include/functions.php @@ -1,6 +1,6 @@ $check_timestamp) { - $match_ok = true; - } - - if ($inverse) $match_ok = !$match_ok; - - if ($match_ok) { - array_push($matches, array($filter["action"], $filter["action_param"])); - } - } - } - } - - 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 ($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; @@ -604,8 +557,8 @@ 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); }; } } @@ -3650,45 +3603,65 @@ 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"]; - 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"]); + $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'"); - array_push($filters[$line["name"]], $filter); + $rules = array(); + $actions = array(); + + while ($rule_line = db_fetch_assoc($result2)) { +# print_r($rule_line); + + $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; } @@ -5595,4 +5568,16 @@ 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; + } + + } + ?> diff --git a/include/rssfuncs.php b/include/rssfuncs.php index 241896f8b..47e0c68f3 100644 --- a/include/rssfuncs.php +++ b/include/rssfuncs.php @@ -818,8 +818,8 @@ $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 @@ -1190,9 +1190,9 @@ // 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)) { diff --git a/js/functions.js b/js/functions.js index 3aa730359..f2c5e3bf5 100644 --- a/js/functions.js +++ b/js/functions.js @@ -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®_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®_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); } diff --git a/js/prefs.js b/js/prefs.js index b308d011d..1fbbc55a5 100644 --- a/js/prefs.js +++ b/js/prefs.js @@ -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®_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(); diff --git a/schema/ttrss_schema_mysql.sql b/schema/ttrss_schema_mysql.sql index e5109de27..9a160f2aa 100644 --- a/schema/ttrss_schema_mysql.sql +++ b/schema/ttrss_schema_mysql.sql @@ -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, diff --git a/schema/ttrss_schema_pgsql.sql b/schema/ttrss_schema_pgsql.sql index 778e2111a..600714e6e 100644 --- a/schema/ttrss_schema_pgsql.sql +++ b/schema/ttrss_schema_pgsql.sql @@ -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 index 000000000..4d4e2445c --- /dev/null +++ b/schema/versions/mysql/96.sql @@ -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 index 000000000..86895e5e0 --- /dev/null +++ b/schema/versions/pgsql/96.sql @@ -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; diff --git a/tt-rss.css b/tt-rss.css index 421e6f153..801a96ac9 100644 --- a/tt-rss.css +++ b/tt-rss.css @@ -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; +} diff --git a/update.php b/update.php index e28729293..51930beab 100755 --- a/update.php +++ b/update.php @@ -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; } @@ -237,6 +238,54 @@ 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) {