let us rejoice on being able to create double negative filters (refs #631)
This commit is contained in:
parent
aff02f89c1
commit
a3a896a127
|
@ -14,6 +14,9 @@ class Pref_Filters extends Handler_Protected {
|
|||
$filter["enabled"] = true;
|
||||
$filter["match_any_rule"] = sql_bool_to_bool(
|
||||
checkbox_to_sql_bool(db_escape_string($this->link, $_REQUEST["match_any_rule"])));
|
||||
$filter["inverse"] = sql_bool_to_bool(
|
||||
checkbox_to_sql_bool(db_escape_string($this->link, $_REQUEST["inverse"])));
|
||||
|
||||
$filter["rules"] = array();
|
||||
|
||||
$result = db_query($this->link, "SELECT id,name FROM ttrss_filter_types");
|
||||
|
@ -214,6 +217,7 @@ class Pref_Filters extends Handler_Protected {
|
|||
|
||||
$enabled = sql_bool_to_bool(db_fetch_result($result, 0, "enabled"));
|
||||
$match_any_rule = sql_bool_to_bool(db_fetch_result($result, 0, "match_any_rule"));
|
||||
$inverse = sql_bool_to_bool(db_fetch_result($result, 0, "inverse"));
|
||||
|
||||
print "<form id=\"filter_edit_form\" onsubmit='return false'>";
|
||||
|
||||
|
@ -257,6 +261,7 @@ class Pref_Filters extends Handler_Protected {
|
|||
unset($line["cat_id"]);
|
||||
unset($line["filter_id"]);
|
||||
unset($line["id"]);
|
||||
if (!sql_bool_to_bool($line["inverse"])) unset($line["inverse"]);
|
||||
|
||||
$data = htmlspecialchars(json_encode($line));
|
||||
|
||||
|
@ -330,6 +335,15 @@ class Pref_Filters extends Handler_Protected {
|
|||
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>";
|
||||
|
||||
if ($inverse) {
|
||||
$checked = "checked=\"1\"";
|
||||
} else {
|
||||
$checked = "";
|
||||
}
|
||||
|
||||
print "<br/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"inverse\" id=\"inverse\" $checked>
|
||||
<label for=\"inverse\">".__('Inverse matching')."</label>";
|
||||
|
||||
print "<p/>";
|
||||
|
||||
print "<div class=\"dlgButtons\">";
|
||||
|
@ -372,7 +386,8 @@ class Pref_Filters extends Handler_Protected {
|
|||
WHERE id = ".(int)$rule["filter_type"]);
|
||||
$filter_type = db_fetch_result($result, 0, "description");
|
||||
|
||||
return T_sprintf("%s on %s in %s", strip_tags($rule["reg_exp"]), $filter_type, $feed);
|
||||
return T_sprintf("%s on %s in %s %s", strip_tags($rule["reg_exp"]),
|
||||
$filter_type, $feed, isset($rule["inverse"]) ? __("(inverse)") : "");
|
||||
}
|
||||
|
||||
function printRuleName() {
|
||||
|
@ -406,9 +421,11 @@ class Pref_Filters extends Handler_Protected {
|
|||
$filter_id = db_escape_string($this->link, $_REQUEST["id"]);
|
||||
$enabled = checkbox_to_sql_bool(db_escape_string($this->link, $_REQUEST["enabled"]));
|
||||
$match_any_rule = checkbox_to_sql_bool(db_escape_string($this->link, $_REQUEST["match_any_rule"]));
|
||||
$inverse = checkbox_to_sql_bool(db_escape_string($this->link, $_REQUEST["inverse"]));
|
||||
|
||||
$result = db_query($this->link, "UPDATE ttrss_filters2 SET enabled = $enabled,
|
||||
match_any_rule = $match_any_rule
|
||||
match_any_rule = $match_any_rule,
|
||||
inverse = $inverse
|
||||
WHERE id = '$filter_id'
|
||||
AND owner_uid = ". $_SESSION["uid"]);
|
||||
|
||||
|
@ -458,6 +475,8 @@ class Pref_Filters extends Handler_Protected {
|
|||
if ($rule) {
|
||||
|
||||
$reg_exp = strip_tags(db_escape_string($this->link, trim($rule["reg_exp"])));
|
||||
$inverse = isset($rule["inverse"]) ? "true" : "false";
|
||||
|
||||
$filter_type = (int) db_escape_string($this->link, trim($rule["filter_type"]));
|
||||
$feed_id = db_escape_string($this->link, trim($rule["feed_id"]));
|
||||
|
||||
|
@ -477,8 +496,8 @@ class Pref_Filters extends Handler_Protected {
|
|||
}
|
||||
|
||||
$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)";
|
||||
(filter_id, reg_exp,filter_type,feed_id,cat_id,cat_filter,inverse) VALUES
|
||||
('$filter_id', '$reg_exp', '$filter_type', $feed_id, $cat_id, $cat_filter, $inverse)";
|
||||
|
||||
db_query($this->link, $query);
|
||||
}
|
||||
|
@ -710,10 +729,8 @@ class Pref_Filters extends Handler_Protected {
|
|||
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 "<br/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"inverse\" id=\"inverse\">
|
||||
<label for=\"inverse\">".__('Inverse matching')."</label>";
|
||||
|
||||
// print "</div>";
|
||||
|
||||
|
@ -739,10 +756,12 @@ class Pref_Filters extends Handler_Protected {
|
|||
$reg_exp = htmlspecialchars($rule["reg_exp"]);
|
||||
$filter_type = $rule["filter_type"];
|
||||
$feed_id = $rule["feed_id"];
|
||||
$inverse_checked = isset($rule["inverse"]) ? "checked" : "";
|
||||
} else {
|
||||
$reg_exp = "";
|
||||
$filter_type = 1;
|
||||
$feed_id = 0;
|
||||
$inverse_checked = "";
|
||||
}
|
||||
|
||||
if (strpos($feed_id, "CAT:") === 0) {
|
||||
|
@ -787,6 +806,13 @@ class Pref_Filters extends Handler_Protected {
|
|||
'dojoType="dijit.form.FilteringSelect"');
|
||||
print "</span>";
|
||||
|
||||
print "<p>";
|
||||
|
||||
print "<input id=\"filterDlg_inverse\" dojoType=\"dijit.form.CheckBox\"
|
||||
name=\"inverse\" $inverse_checked/>";
|
||||
|
||||
print "<label for=\"filterDlg_inverse\">".__("Inverse matching")."</label>";
|
||||
|
||||
print "</div>";
|
||||
|
||||
print "<div class=\"dlgButtons\">";
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
define('EXPECTED_CONFIG_VERSION', 26);
|
||||
define('SCHEMA_VERSION', 106);
|
||||
define('SCHEMA_VERSION', 107);
|
||||
|
||||
$fetch_last_error = false;
|
||||
$pluginhost = false;
|
||||
|
@ -3214,7 +3214,7 @@
|
|||
$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
|
||||
r.reg_exp, r.inverse, 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
|
||||
|
@ -3231,6 +3231,7 @@
|
|||
$rule = array();
|
||||
$rule["reg_exp"] = $rule_line["reg_exp"];
|
||||
$rule["type"] = $rule_line["type_name"];
|
||||
$rule["inverse"] = sql_bool_to_bool($rule_line["inverse"]);
|
||||
|
||||
array_push($rules, $rule);
|
||||
}
|
||||
|
@ -3254,6 +3255,7 @@
|
|||
|
||||
$filter = array();
|
||||
$filter["match_any_rule"] = sql_bool_to_bool($line["match_any_rule"]);
|
||||
$filter["inverse"] = sql_bool_to_bool($line["inverse"]);
|
||||
$filter["rules"] = $rules;
|
||||
$filter["actions"] = $actions;
|
||||
|
||||
|
@ -3875,7 +3877,7 @@
|
|||
|
||||
$rule['reg_exp'] = db_escape_string($link, $rule['reg_exp']);
|
||||
|
||||
switch ($rule["type"]) {
|
||||
switch ($rule["type"]) {
|
||||
case "title":
|
||||
$qpart = "LOWER(ttrss_entries.title) $reg_qpart LOWER('".
|
||||
$rule['reg_exp'] . "')";
|
||||
|
@ -3923,16 +3925,22 @@
|
|||
$qpart .= " AND $cat_qpart";
|
||||
}
|
||||
|
||||
if (isset($rule['inverse'])) $qpart = "NOT ($qpart)";
|
||||
|
||||
array_push($query, "($qpart)");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (count($query) > 0) {
|
||||
return "(" . join($filter["match_any_rule"] ? "OR" : "AND", $query) . ")";
|
||||
$fullquery = "(" . join($filter["match_any_rule"] ? "OR" : "AND", $query) . ")";
|
||||
} else {
|
||||
return "(false)";
|
||||
$fullquery = "(false)";
|
||||
}
|
||||
|
||||
if ($filter['inverse']) $fullquery = "(NOT $fullquery)";
|
||||
|
||||
return $fullquery;
|
||||
}
|
||||
|
||||
if (!function_exists('gzdecode')) {
|
||||
|
|
|
@ -1165,11 +1165,13 @@
|
|||
|
||||
foreach ($filters as $filter) {
|
||||
$match_any_rule = $filter["match_any_rule"];
|
||||
$inverse = $filter["inverse"];
|
||||
$filter_match = false;
|
||||
|
||||
foreach ($filter["rules"] as $rule) {
|
||||
$match = false;
|
||||
$reg_exp = $rule["reg_exp"];
|
||||
$rule_inverse = $rule["inverse"];
|
||||
|
||||
if (!$reg_exp)
|
||||
continue;
|
||||
|
@ -1202,6 +1204,8 @@
|
|||
break;
|
||||
}
|
||||
|
||||
if ($rule_inverse) $match = !$match;
|
||||
|
||||
if ($match_any_rule) {
|
||||
if ($match) {
|
||||
$filter_match = true;
|
||||
|
@ -1215,6 +1219,8 @@
|
|||
}
|
||||
}
|
||||
|
||||
if ($inverse) $filter_match = !$filter_match;
|
||||
|
||||
if ($filter_match) {
|
||||
foreach ($filter["actions"] AS $action) {
|
||||
array_push($matches, $action);
|
||||
|
|
|
@ -274,12 +274,14 @@ 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,
|
||||
inverse bool not null default false,
|
||||
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,
|
||||
inverse bool not null default false,
|
||||
filter_type integer not null,
|
||||
feed_id integer default null,
|
||||
cat_id integer default null,
|
||||
|
@ -313,7 +315,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 (106);
|
||||
insert into ttrss_version values (107);
|
||||
|
||||
create table ttrss_enclosures (id integer primary key auto_increment,
|
||||
content_url text not null,
|
||||
|
|
|
@ -236,11 +236,13 @@ create table ttrss_filters (id serial not null primary key,
|
|||
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,
|
||||
inverse 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,
|
||||
inverse boolean not null default false,
|
||||
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,
|
||||
|
@ -261,7 +263,7 @@ create index ttrss_tags_post_int_id_idx on ttrss_tags(post_int_id);
|
|||
|
||||
create table ttrss_version (schema_version int not null);
|
||||
|
||||
insert into ttrss_version values (106);
|
||||
insert into ttrss_version values (107);
|
||||
|
||||
create table ttrss_enclosures (id serial not null primary key,
|
||||
content_url text not null,
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
begin;
|
||||
|
||||
alter table ttrss_filters2 add column inverse bool;
|
||||
update ttrss_filters2 set inverse = false;
|
||||
alter table ttrss_filters2 change inverse inverse bool not null;
|
||||
alter table ttrss_filters2 alter column inverse set default false;
|
||||
|
||||
alter table ttrss_filters2_rules add column inverse bool;
|
||||
update ttrss_filters2_rules set inverse = false;
|
||||
alter table ttrss_filters2_rules change inverse inverse bool not null;
|
||||
alter table ttrss_filters2_rules alter column inverse set default false;
|
||||
|
||||
update ttrss_version set schema_version = 107;
|
||||
|
||||
commit;
|
|
@ -0,0 +1,15 @@
|
|||
begin;
|
||||
|
||||
alter table ttrss_filters2 add column inverse boolean;
|
||||
update ttrss_filters2 set inverse = false;
|
||||
alter table ttrss_filters2 alter column inverse set not null;
|
||||
alter table ttrss_filters2 alter column inverse set default false;
|
||||
|
||||
alter table ttrss_filters2_rules add column inverse boolean;
|
||||
update ttrss_filters2_rules set inverse = false;
|
||||
alter table ttrss_filters2_rules alter column inverse set not null;
|
||||
alter table ttrss_filters2_rules alter column inverse set default false;
|
||||
|
||||
update ttrss_version set schema_version = 107;
|
||||
|
||||
commit;
|
Loading…
Reference in New Issue