mirror of
https://git.tt-rss.org/git/tt-rss.git
synced 2026-01-06 09:39:15 +00:00
Revert "filters: support matching on multiple feeds/categories"
This reverts commit 0bf7e007bb.
This commit is contained in:
119
classes/opml.php
119
classes/opml.php
@@ -181,37 +181,13 @@ class Opml extends Handler_Protected {
|
||||
|
||||
$cat_filter = sql_bool_to_bool($tmp_line["cat_filter"]);
|
||||
|
||||
if (!$tmp_line["match_on"]) {
|
||||
if ($cat_filter && $tmp_line["cat_id"] || $tmp_line["feed_id"]) {
|
||||
$tmp_line["feed"] = Feeds::getFeedTitle(
|
||||
$cat_filter ? $tmp_line["cat_id"] : $tmp_line["feed_id"],
|
||||
$cat_filter);
|
||||
} else {
|
||||
$tmp_line["feed"] = "";
|
||||
}
|
||||
} else {
|
||||
$match = [];
|
||||
foreach (json_decode($tmp_line["match_on"], true) as $feed_id) {
|
||||
|
||||
if (strpos($feed_id, "CAT:") === 0) {
|
||||
$feed_id = (int)substr($feed_id, 4);
|
||||
if ($feed_id) {
|
||||
array_push($match, [Feeds::getCategoryTitle($feed_id), true, false]);
|
||||
} else {
|
||||
array_push($match, [0, true, true]);
|
||||
}
|
||||
} else {
|
||||
if ($feed_id) {
|
||||
array_push($match, [Feeds::getFeedTitle((int)$feed_id), false, false]);
|
||||
} else {
|
||||
array_push($match, [0, false, true]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$tmp_line["match"] = $match;
|
||||
unset($tmp_line["match_on"]);
|
||||
}
|
||||
if ($cat_filter && $tmp_line["cat_id"] || $tmp_line["feed_id"]) {
|
||||
$tmp_line["feed"] = Feeds::getFeedTitle(
|
||||
$cat_filter ? $tmp_line["cat_id"] : $tmp_line["feed_id"],
|
||||
$cat_filter);
|
||||
} else {
|
||||
$tmp_line["feed"] = "";
|
||||
}
|
||||
|
||||
$tmp_line["cat_filter"] = sql_bool_to_bool($tmp_line["cat_filter"]);
|
||||
$tmp_line["inverse"] = sql_bool_to_bool($tmp_line["inverse"]);
|
||||
@@ -370,71 +346,28 @@ class Opml extends Handler_Protected {
|
||||
$feed_id = "NULL";
|
||||
$cat_id = "NULL";
|
||||
|
||||
if ($rule["match"]) {
|
||||
if (!$rule["cat_filter"]) {
|
||||
$tmp_result = $this->dbh->query("SELECT id FROM ttrss_feeds
|
||||
WHERE title = '".$this->dbh->escape_string($rule["feed"])."' AND owner_uid = ".$_SESSION["uid"]);
|
||||
if ($this->dbh->num_rows($tmp_result) > 0) {
|
||||
$feed_id = $this->dbh->fetch_result($tmp_result, 0, "id");
|
||||
}
|
||||
} else {
|
||||
$tmp_result = $this->dbh->query("SELECT id FROM ttrss_feed_categories
|
||||
WHERE title = '".$this->dbh->escape_string($rule["feed"])."' AND owner_uid = ".$_SESSION["uid"]);
|
||||
|
||||
$match_on = [];
|
||||
if ($this->dbh->num_rows($tmp_result) > 0) {
|
||||
$cat_id = $this->dbh->fetch_result($tmp_result, 0, "id");
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($rule["match"] as $match) {
|
||||
list ($name, $is_cat, $is_id) = $match;
|
||||
$cat_filter = bool_to_sql_bool($rule["cat_filter"]);
|
||||
$reg_exp = $this->dbh->escape_string($rule["reg_exp"]);
|
||||
$filter_type = (int)$rule["filter_type"];
|
||||
$inverse = bool_to_sql_bool($rule["inverse"]);
|
||||
|
||||
if ($is_id) {
|
||||
array_push($match_on, ($is_cat ? "CAT:" : "") . $name);
|
||||
} else {
|
||||
|
||||
$match_id = false;
|
||||
|
||||
if (!$is_cat) {
|
||||
$tmp_result = $this->dbh->query("SELECT id FROM ttrss_feeds
|
||||
WHERE title = '" . $this->dbh->escape_string($name) . "' AND owner_uid = " . $_SESSION["uid"]);
|
||||
if ($this->dbh->num_rows($tmp_result) > 0) {
|
||||
$match_id = $this->dbh->fetch_result($tmp_result, 0, "id");
|
||||
}
|
||||
} else {
|
||||
$tmp_result = $this->dbh->query("SELECT id FROM ttrss_feed_categories
|
||||
WHERE title = '" . $this->dbh->escape_string($name) . "' AND owner_uid = " . $_SESSION["uid"]);
|
||||
|
||||
if ($this->dbh->num_rows($tmp_result) > 0) {
|
||||
$match_id = 'CAT:' . $this->dbh->fetch_result($tmp_result, 0, "id");
|
||||
}
|
||||
}
|
||||
|
||||
if ($match_id) array_push($match_on, $match_id);
|
||||
}
|
||||
}
|
||||
|
||||
$reg_exp = $this->dbh->escape_string($rule["reg_exp"]);
|
||||
$filter_type = (int)$rule["filter_type"];
|
||||
$inverse = bool_to_sql_bool($rule["inverse"]);
|
||||
$match_on = $this->dbh->escape_string(json_encode($match_on));
|
||||
|
||||
$this->dbh->query("INSERT INTO ttrss_filters2_rules (feed_id,cat_id,match_on,filter_id,filter_type,reg_exp,cat_filter,inverse)
|
||||
VALUES (NULL, NULL, '$match_on',$filter_id, $filter_type, '$reg_exp', false, $inverse)");
|
||||
|
||||
} else {
|
||||
|
||||
if (!$rule["cat_filter"]) {
|
||||
$tmp_result = $this->dbh->query("SELECT id FROM ttrss_feeds
|
||||
WHERE title = '" . $this->dbh->escape_string($rule["feed"]) . "' AND owner_uid = " . $_SESSION["uid"]);
|
||||
if ($this->dbh->num_rows($tmp_result) > 0) {
|
||||
$feed_id = $this->dbh->fetch_result($tmp_result, 0, "id");
|
||||
}
|
||||
} else {
|
||||
$tmp_result = $this->dbh->query("SELECT id FROM ttrss_feed_categories
|
||||
WHERE title = '" . $this->dbh->escape_string($rule["feed"]) . "' AND owner_uid = " . $_SESSION["uid"]);
|
||||
|
||||
if ($this->dbh->num_rows($tmp_result) > 0) {
|
||||
$cat_id = $this->dbh->fetch_result($tmp_result, 0, "id");
|
||||
}
|
||||
}
|
||||
|
||||
$cat_filter = bool_to_sql_bool($rule["cat_filter"]);
|
||||
$reg_exp = $this->dbh->escape_string($rule["reg_exp"]);
|
||||
$filter_type = (int)$rule["filter_type"];
|
||||
$inverse = bool_to_sql_bool($rule["inverse"]);
|
||||
|
||||
$this->dbh->query("INSERT INTO ttrss_filters2_rules (feed_id,cat_id,filter_id,filter_type,reg_exp,cat_filter,inverse)
|
||||
VALUES ($feed_id, $cat_id, $filter_id, $filter_type, '$reg_exp', $cat_filter,$inverse)");
|
||||
}
|
||||
$this->dbh->query("INSERT INTO ttrss_filters2_rules (feed_id,cat_id,filter_id,filter_type,reg_exp,cat_filter,inverse)
|
||||
VALUES ($feed_id, $cat_id, $filter_id, $filter_type, '$reg_exp', $cat_filter,$inverse)");
|
||||
}
|
||||
|
||||
foreach ($filter["actions"] as $action) {
|
||||
|
||||
@@ -75,20 +75,18 @@ class Pref_Filters extends Handler_Protected {
|
||||
$rule["type"] = $filter_types[$rule["filter_type"]];
|
||||
unset($rule["filter_type"]);
|
||||
|
||||
$scope_inner_qparts = [];
|
||||
foreach ($rule["feed_id"] as $feed_id) {
|
||||
if (strpos($rule["feed_id"], "CAT:") === 0) {
|
||||
$rule["cat_id"] = (int) substr($rule["feed_id"], 4);
|
||||
unset($rule["feed_id"]);
|
||||
}
|
||||
|
||||
if (strpos($feed_id, "CAT:") === 0) {
|
||||
$cat_id = (int) substr($feed_id, 4);
|
||||
array_push($scope_inner_qparts, "cat_id = " . $cat_id);
|
||||
} else if ($feed_id > 0) {
|
||||
array_push($scope_inner_qparts, "feed_id = " . $feed_id);
|
||||
}
|
||||
}
|
||||
|
||||
if (count($scope_inner_qparts) > 0) {
|
||||
array_push($scope_qparts, "(" . implode(" OR ", $scope_inner_qparts) . ")");
|
||||
}
|
||||
if (isset($rule["feed_id"]) && $rule['feed_id'] > 0) {
|
||||
array_push($scope_qparts, "feed_id = " . $rule["feed_id"]);
|
||||
} else if (isset($rule["cat_id"])) {
|
||||
array_push($scope_qparts, "cat_id = " . $rule["cat_id"]);
|
||||
} else {
|
||||
array_push($scope_qparts, "true");
|
||||
}
|
||||
|
||||
array_push($filter["rules"], $rule);
|
||||
|
||||
@@ -98,8 +96,6 @@ class Pref_Filters extends Handler_Protected {
|
||||
}
|
||||
}
|
||||
|
||||
if (count($scope_qparts) == 0) $scope_qparts = ["true"];
|
||||
|
||||
$glue = $filter['match_any_rule'] ? " OR " : " AND ";
|
||||
$scope_qpart = join($glue, $scope_qparts);
|
||||
|
||||
@@ -211,7 +207,6 @@ class Pref_Filters extends Handler_Protected {
|
||||
private function getfilterrules_concise($filter_id) {
|
||||
$result = $this->dbh->query("SELECT reg_exp,
|
||||
inverse,
|
||||
match_on,
|
||||
feed_id,
|
||||
cat_id,
|
||||
cat_filter,
|
||||
@@ -226,32 +221,10 @@ class Pref_Filters extends Handler_Protected {
|
||||
|
||||
while ($line = $this->dbh->fetch_assoc($result)) {
|
||||
|
||||
if ($line["match_on"]) {
|
||||
$feeds = json_decode($line["match_on"], true);
|
||||
$feeds_fmt = [];
|
||||
|
||||
foreach ($feeds as $feed_id) {
|
||||
|
||||
if (strpos($feed_id, "CAT:") === 0) {
|
||||
$feed_id = (int)substr($feed_id, 4);
|
||||
array_push($feeds_fmt, Feeds::getCategoryTitle($feed_id));
|
||||
} else {
|
||||
if ($feed_id)
|
||||
array_push($feeds_fmt, Feeds::getFeedTitle((int)$feed_id));
|
||||
else
|
||||
array_push($feeds_fmt, __("All feeds"));
|
||||
}
|
||||
}
|
||||
|
||||
$where = implode(", ", $feeds_fmt);
|
||||
|
||||
} else {
|
||||
|
||||
$where = sql_bool_to_bool($line["cat_filter"]) ?
|
||||
Feeds::getCategoryTitle($line["cat_id"]) :
|
||||
($line["feed_id"] ?
|
||||
Feeds::getFeedTitle($line["feed_id"]) : __("All feeds"));
|
||||
}
|
||||
$where = sql_bool_to_bool($line["cat_filter"]) ?
|
||||
Feeds::getCategoryTitle($line["cat_id"]) :
|
||||
($line["feed_id"] ?
|
||||
Feeds::getFeedTitle($line["feed_id"]) : __("All feeds"));
|
||||
|
||||
# $where = $line["cat_id"] . "/" . $line["feed_id"];
|
||||
|
||||
@@ -403,26 +376,17 @@ class Pref_Filters extends Handler_Protected {
|
||||
WHERE filter_id = '$filter_id' ORDER BY reg_exp, id");
|
||||
|
||||
while ($line = $this->dbh->fetch_assoc($rules_result)) {
|
||||
if ($line["match_on"]) {
|
||||
$line["feed_id"] = json_decode($line["match_on"], true);
|
||||
} else {
|
||||
if (sql_bool_to_bool($line["cat_filter"])) {
|
||||
$feed_id = "CAT:" . (int)$line["cat_id"];
|
||||
} else {
|
||||
$feed_id = (int)$line["cat_id"];
|
||||
}
|
||||
if (sql_bool_to_bool($line["cat_filter"])) {
|
||||
$line["feed_id"] = "CAT:" . (int)$line["cat_id"];
|
||||
}
|
||||
|
||||
$line["feed_id"] = ["" . $feed_id]; // set item type to string for in_array()
|
||||
}
|
||||
unset($line["cat_filter"]);
|
||||
unset($line["cat_id"]);
|
||||
unset($line["filter_id"]);
|
||||
unset($line["id"]);
|
||||
if (!sql_bool_to_bool($line["inverse"])) unset($line["inverse"]);
|
||||
|
||||
unset($line["cat_filter"]);
|
||||
unset($line["cat_id"]);
|
||||
unset($line["filter_id"]);
|
||||
unset($line["id"]);
|
||||
if (!sql_bool_to_bool($line["inverse"])) unset($line["inverse"]);
|
||||
unset($line["match_on"]);
|
||||
|
||||
$data = htmlspecialchars(json_encode($line));
|
||||
$data = htmlspecialchars(json_encode($line));
|
||||
|
||||
print "<li><input dojoType='dijit.form.CheckBox' type='checkbox' onclick='toggleSelectListRow2(this)'>".
|
||||
"<span onclick=\"dijit.byId('filterEditDlg').editRule(this)\">".$this->getRuleName($line)."</span>".
|
||||
@@ -527,25 +491,19 @@ class Pref_Filters extends Handler_Protected {
|
||||
private function getRuleName($rule) {
|
||||
if (!$rule) $rule = json_decode($_REQUEST["rule"], true);
|
||||
|
||||
$feeds = $rule["feed_id"];
|
||||
$feeds_fmt = [];
|
||||
$feed_id = $rule["feed_id"];
|
||||
|
||||
if (!is_array($feeds)) $feeds = [$feeds];
|
||||
if (strpos($feed_id, "CAT:") === 0) {
|
||||
$feed_id = (int) substr($feed_id, 4);
|
||||
$feed = Feeds::getCategoryTitle($feed_id);
|
||||
} else {
|
||||
$feed_id = (int) $feed_id;
|
||||
|
||||
foreach ($feeds as $feed_id) {
|
||||
|
||||
if (strpos($feed_id, "CAT:") === 0) {
|
||||
$feed_id = (int)substr($feed_id, 4);
|
||||
array_push($feeds_fmt, Feeds::getCategoryTitle($feed_id));
|
||||
} else {
|
||||
if ($feed_id)
|
||||
array_push($feeds_fmt, Feeds::getFeedTitle((int)$feed_id));
|
||||
else
|
||||
array_push($feeds_fmt, __("All feeds"));
|
||||
}
|
||||
}
|
||||
|
||||
$feed = implode(", ", $feeds_fmt);
|
||||
if ($rule["feed_id"])
|
||||
$feed = Feeds::getFeedTitle((int)$rule["feed_id"]);
|
||||
else
|
||||
$feed = __("All feeds");
|
||||
}
|
||||
|
||||
$result = $this->dbh->query("SELECT description FROM ttrss_filter_types
|
||||
WHERE id = ".(int)$rule["filter_type"]);
|
||||
@@ -663,9 +621,9 @@ class Pref_Filters extends Handler_Protected {
|
||||
$inverse = isset($rule["inverse"]) ? "true" : "false";
|
||||
|
||||
$filter_type = (int) $this->dbh->escape_string(trim($rule["filter_type"]));
|
||||
$match_on = $this->dbh->escape_string(json_encode($rule["feed_id"]));
|
||||
$feed_id = $this->dbh->escape_string(trim($rule["feed_id"]));
|
||||
|
||||
/*if (strpos($feed_id, "CAT:") === 0) {
|
||||
if (strpos($feed_id, "CAT:") === 0) {
|
||||
|
||||
$cat_filter = bool_to_sql_bool(true);
|
||||
$cat_id = (int) substr($feed_id, 4);
|
||||
@@ -678,11 +636,11 @@ class Pref_Filters extends Handler_Protected {
|
||||
$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,match_on,inverse) VALUES
|
||||
('$filter_id', '$reg_exp', '$filter_type', NULL, NULL, '$match_on', $inverse)";
|
||||
(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)";
|
||||
|
||||
$this->dbh->query($query);
|
||||
}
|
||||
@@ -956,16 +914,17 @@ class Pref_Filters extends Handler_Protected {
|
||||
} else {
|
||||
$reg_exp = "";
|
||||
$filter_type = 1;
|
||||
$feed_id = [];
|
||||
$feed_id = 0;
|
||||
$inverse_checked = "";
|
||||
}
|
||||
|
||||
/*if (strpos($feed_id, "CAT:") === 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'>";
|
||||
|
||||
@@ -1001,9 +960,9 @@ class Pref_Filters extends Handler_Protected {
|
||||
print __("in") . " ";
|
||||
|
||||
print "<span id='filterDlg_feeds'>";
|
||||
print_feed_multi_select("feed_id",
|
||||
$feed_id,
|
||||
'dojoType="dijit.form.MultiSelect" style="height : 150px"');
|
||||
print_feed_select("feed_id",
|
||||
$cat_filter ? "CAT:$feed_id" : $feed_id,
|
||||
'dojoType="dijit.form.FilteringSelect"');
|
||||
print "</span>";
|
||||
|
||||
print "</div>";
|
||||
|
||||
@@ -497,10 +497,6 @@ class RSSUtils {
|
||||
|
||||
$filters = load_filters($feed, $owner_uid);
|
||||
|
||||
if ($debug_enabled) {
|
||||
print_r($filters);
|
||||
}
|
||||
|
||||
_debug("" . count($filters) . " filters loaded.", $debug_enabled);
|
||||
|
||||
$items = $rss->get_items();
|
||||
|
||||
Reference in New Issue
Block a user