$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");
$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'>";
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));
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\">";
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() {
$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"]);
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"]));
}
$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);
}
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>";
$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) {
'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\">";
<?php
define('EXPECTED_CONFIG_VERSION', 26);
- define('SCHEMA_VERSION', 106);
+ define('SCHEMA_VERSION', 107);
$fetch_last_error = false;
$pluginhost = false;
$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
$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);
}
$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;
$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'] . "')";
$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')) {
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;
break;
}
+ if ($rule_inverse) $match = !$match;
+
if ($match_any_rule) {
if ($match) {
$filter_match = true;
}
}
+ if ($inverse) $filter_match = !$filter_match;
+
if ($filter_match) {
foreach ($filter["actions"] AS $action) {
array_push($matches, $action);
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,
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,
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,
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,
--- /dev/null
+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;
--- /dev/null
+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;