diff --git a/classes/pref/filters.php b/classes/pref/filters.php index c97628e51..f9828705e 100644 --- a/classes/pref/filters.php +++ b/classes/pref/filters.php @@ -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 "
"; @@ -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 "
"; + if ($inverse) { + $checked = "checked=\"1\""; + } else { + $checked = ""; + } + + print "
+ "; + print "

"; print "

"; @@ -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 "
"; - print "

"; - -/* print " -


"; */ + print "
+ "; // print "
"; @@ -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 ""; + print "

"; + + print ""; + + print ""; + print ""; print "

"; diff --git a/include/functions.php b/include/functions.php index b52531f66..9a855a9bc 100644 --- a/include/functions.php +++ b/include/functions.php @@ -1,6 +1,6 @@ 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')) { diff --git a/include/rssfuncs.php b/include/rssfuncs.php index 92bfaa023..11aa0e4ba 100644 --- a/include/rssfuncs.php +++ b/include/rssfuncs.php @@ -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); diff --git a/schema/ttrss_schema_mysql.sql b/schema/ttrss_schema_mysql.sql index 438865478..0d3358748 100644 --- a/schema/ttrss_schema_mysql.sql +++ b/schema/ttrss_schema_mysql.sql @@ -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, diff --git a/schema/ttrss_schema_pgsql.sql b/schema/ttrss_schema_pgsql.sql index 3895ccc56..895c7e0f4 100644 --- a/schema/ttrss_schema_pgsql.sql +++ b/schema/ttrss_schema_pgsql.sql @@ -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, diff --git a/schema/versions/mysql/107.sql b/schema/versions/mysql/107.sql new file mode 100644 index 000000000..9283d40d9 --- /dev/null +++ b/schema/versions/mysql/107.sql @@ -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; diff --git a/schema/versions/pgsql/107.sql b/schema/versions/pgsql/107.sql new file mode 100644 index 000000000..a4a537c2f --- /dev/null +++ b/schema/versions/pgsql/107.sql @@ -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;