filters: support matching on multiple feeds/categories
opml: update filter export/import for new format
This commit is contained in:
parent
12b7b90c70
commit
0bf7e007bb
119
classes/opml.php
119
classes/opml.php
|
@ -181,13 +181,37 @@ class Opml extends Handler_Protected {
|
||||||
|
|
||||||
$cat_filter = sql_bool_to_bool($tmp_line["cat_filter"]);
|
$cat_filter = sql_bool_to_bool($tmp_line["cat_filter"]);
|
||||||
|
|
||||||
if ($cat_filter && $tmp_line["cat_id"] || $tmp_line["feed_id"]) {
|
if (!$tmp_line["match_on"]) {
|
||||||
$tmp_line["feed"] = Feeds::getFeedTitle(
|
if ($cat_filter && $tmp_line["cat_id"] || $tmp_line["feed_id"]) {
|
||||||
$cat_filter ? $tmp_line["cat_id"] : $tmp_line["feed_id"],
|
$tmp_line["feed"] = Feeds::getFeedTitle(
|
||||||
$cat_filter);
|
$cat_filter ? $tmp_line["cat_id"] : $tmp_line["feed_id"],
|
||||||
} else {
|
$cat_filter);
|
||||||
$tmp_line["feed"] = "";
|
} 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"]);
|
||||||
|
}
|
||||||
|
|
||||||
$tmp_line["cat_filter"] = sql_bool_to_bool($tmp_line["cat_filter"]);
|
$tmp_line["cat_filter"] = sql_bool_to_bool($tmp_line["cat_filter"]);
|
||||||
$tmp_line["inverse"] = sql_bool_to_bool($tmp_line["inverse"]);
|
$tmp_line["inverse"] = sql_bool_to_bool($tmp_line["inverse"]);
|
||||||
|
@ -346,28 +370,71 @@ class Opml extends Handler_Protected {
|
||||||
$feed_id = "NULL";
|
$feed_id = "NULL";
|
||||||
$cat_id = "NULL";
|
$cat_id = "NULL";
|
||||||
|
|
||||||
if (!$rule["cat_filter"]) {
|
if ($rule["match"]) {
|
||||||
$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) {
|
$match_on = [];
|
||||||
$cat_id = $this->dbh->fetch_result($tmp_result, 0, "id");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$cat_filter = bool_to_sql_bool($rule["cat_filter"]);
|
foreach ($rule["match"] as $match) {
|
||||||
$reg_exp = $this->dbh->escape_string($rule["reg_exp"]);
|
list ($name, $is_cat, $is_id) = $match;
|
||||||
$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)
|
if ($is_id) {
|
||||||
VALUES ($feed_id, $cat_id, $filter_id, $filter_type, '$reg_exp', $cat_filter,$inverse)");
|
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)");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($filter["actions"] as $action) {
|
foreach ($filter["actions"] as $action) {
|
||||||
|
|
|
@ -75,18 +75,20 @@ class Pref_Filters extends Handler_Protected {
|
||||||
$rule["type"] = $filter_types[$rule["filter_type"]];
|
$rule["type"] = $filter_types[$rule["filter_type"]];
|
||||||
unset($rule["filter_type"]);
|
unset($rule["filter_type"]);
|
||||||
|
|
||||||
if (strpos($rule["feed_id"], "CAT:") === 0) {
|
$scope_inner_qparts = [];
|
||||||
$rule["cat_id"] = (int) substr($rule["feed_id"], 4);
|
foreach ($rule["feed_id"] as $feed_id) {
|
||||||
unset($rule["feed_id"]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($rule["feed_id"]) && $rule['feed_id'] > 0) {
|
if (strpos($feed_id, "CAT:") === 0) {
|
||||||
array_push($scope_qparts, "feed_id = " . $rule["feed_id"]);
|
$cat_id = (int) substr($feed_id, 4);
|
||||||
} else if (isset($rule["cat_id"])) {
|
array_push($scope_inner_qparts, "cat_id = " . $cat_id);
|
||||||
array_push($scope_qparts, "cat_id = " . $rule["cat_id"]);
|
} else if ($feed_id > 0) {
|
||||||
} else {
|
array_push($scope_inner_qparts, "feed_id = " . $feed_id);
|
||||||
array_push($scope_qparts, "true");
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (count($scope_inner_qparts) > 0) {
|
||||||
|
array_push($scope_qparts, "(" . implode(" OR ", $scope_inner_qparts) . ")");
|
||||||
|
}
|
||||||
|
|
||||||
array_push($filter["rules"], $rule);
|
array_push($filter["rules"], $rule);
|
||||||
|
|
||||||
|
@ -96,6 +98,8 @@ class Pref_Filters extends Handler_Protected {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (count($scope_qparts) == 0) $scope_qparts = ["true"];
|
||||||
|
|
||||||
$glue = $filter['match_any_rule'] ? " OR " : " AND ";
|
$glue = $filter['match_any_rule'] ? " OR " : " AND ";
|
||||||
$scope_qpart = join($glue, $scope_qparts);
|
$scope_qpart = join($glue, $scope_qparts);
|
||||||
|
|
||||||
|
@ -207,6 +211,7 @@ class Pref_Filters extends Handler_Protected {
|
||||||
private function getfilterrules_concise($filter_id) {
|
private function getfilterrules_concise($filter_id) {
|
||||||
$result = $this->dbh->query("SELECT reg_exp,
|
$result = $this->dbh->query("SELECT reg_exp,
|
||||||
inverse,
|
inverse,
|
||||||
|
match_on,
|
||||||
feed_id,
|
feed_id,
|
||||||
cat_id,
|
cat_id,
|
||||||
cat_filter,
|
cat_filter,
|
||||||
|
@ -221,10 +226,32 @@ class Pref_Filters extends Handler_Protected {
|
||||||
|
|
||||||
while ($line = $this->dbh->fetch_assoc($result)) {
|
while ($line = $this->dbh->fetch_assoc($result)) {
|
||||||
|
|
||||||
$where = sql_bool_to_bool($line["cat_filter"]) ?
|
if ($line["match_on"]) {
|
||||||
Feeds::getCategoryTitle($line["cat_id"]) :
|
$feeds = json_decode($line["match_on"], true);
|
||||||
($line["feed_id"] ?
|
$feeds_fmt = [];
|
||||||
Feeds::getFeedTitle($line["feed_id"]) : __("All feeds"));
|
|
||||||
|
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 = $line["cat_id"] . "/" . $line["feed_id"];
|
# $where = $line["cat_id"] . "/" . $line["feed_id"];
|
||||||
|
|
||||||
|
@ -376,17 +403,26 @@ class Pref_Filters extends Handler_Protected {
|
||||||
WHERE filter_id = '$filter_id' ORDER BY reg_exp, id");
|
WHERE filter_id = '$filter_id' ORDER BY reg_exp, id");
|
||||||
|
|
||||||
while ($line = $this->dbh->fetch_assoc($rules_result)) {
|
while ($line = $this->dbh->fetch_assoc($rules_result)) {
|
||||||
if (sql_bool_to_bool($line["cat_filter"])) {
|
if ($line["match_on"]) {
|
||||||
$line["feed_id"] = "CAT:" . (int)$line["cat_id"];
|
$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"];
|
||||||
|
}
|
||||||
|
|
||||||
unset($line["cat_filter"]);
|
$line["feed_id"] = ["" . $feed_id]; // set item type to string for in_array()
|
||||||
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));
|
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));
|
||||||
|
|
||||||
print "<li><input dojoType='dijit.form.CheckBox' type='checkbox' onclick='toggleSelectListRow2(this)'>".
|
print "<li><input dojoType='dijit.form.CheckBox' type='checkbox' onclick='toggleSelectListRow2(this)'>".
|
||||||
"<span onclick=\"dijit.byId('filterEditDlg').editRule(this)\">".$this->getRuleName($line)."</span>".
|
"<span onclick=\"dijit.byId('filterEditDlg').editRule(this)\">".$this->getRuleName($line)."</span>".
|
||||||
|
@ -491,19 +527,25 @@ class Pref_Filters extends Handler_Protected {
|
||||||
private function getRuleName($rule) {
|
private function getRuleName($rule) {
|
||||||
if (!$rule) $rule = json_decode($_REQUEST["rule"], true);
|
if (!$rule) $rule = json_decode($_REQUEST["rule"], true);
|
||||||
|
|
||||||
$feed_id = $rule["feed_id"];
|
$feeds = $rule["feed_id"];
|
||||||
|
$feeds_fmt = [];
|
||||||
|
|
||||||
if (strpos($feed_id, "CAT:") === 0) {
|
if (!is_array($feeds)) $feeds = [$feeds];
|
||||||
$feed_id = (int) substr($feed_id, 4);
|
|
||||||
$feed = Feeds::getCategoryTitle($feed_id);
|
|
||||||
} else {
|
|
||||||
$feed_id = (int) $feed_id;
|
|
||||||
|
|
||||||
if ($rule["feed_id"])
|
foreach ($feeds as $feed_id) {
|
||||||
$feed = Feeds::getFeedTitle((int)$rule["feed_id"]);
|
|
||||||
else
|
if (strpos($feed_id, "CAT:") === 0) {
|
||||||
$feed = __("All feeds");
|
$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);
|
||||||
|
|
||||||
$result = $this->dbh->query("SELECT description FROM ttrss_filter_types
|
$result = $this->dbh->query("SELECT description FROM ttrss_filter_types
|
||||||
WHERE id = ".(int)$rule["filter_type"]);
|
WHERE id = ".(int)$rule["filter_type"]);
|
||||||
|
@ -621,9 +663,9 @@ class Pref_Filters extends Handler_Protected {
|
||||||
$inverse = isset($rule["inverse"]) ? "true" : "false";
|
$inverse = isset($rule["inverse"]) ? "true" : "false";
|
||||||
|
|
||||||
$filter_type = (int) $this->dbh->escape_string(trim($rule["filter_type"]));
|
$filter_type = (int) $this->dbh->escape_string(trim($rule["filter_type"]));
|
||||||
$feed_id = $this->dbh->escape_string(trim($rule["feed_id"]));
|
$match_on = $this->dbh->escape_string(json_encode($rule["feed_id"]));
|
||||||
|
|
||||||
if (strpos($feed_id, "CAT:") === 0) {
|
/*if (strpos($feed_id, "CAT:") === 0) {
|
||||||
|
|
||||||
$cat_filter = bool_to_sql_bool(true);
|
$cat_filter = bool_to_sql_bool(true);
|
||||||
$cat_id = (int) substr($feed_id, 4);
|
$cat_id = (int) substr($feed_id, 4);
|
||||||
|
@ -636,11 +678,11 @@ class Pref_Filters extends Handler_Protected {
|
||||||
$cat_id = "NULL";
|
$cat_id = "NULL";
|
||||||
|
|
||||||
if (!$feed_id) $feed_id = "NULL"; // Uncategorized
|
if (!$feed_id) $feed_id = "NULL"; // Uncategorized
|
||||||
}
|
}*/
|
||||||
|
|
||||||
$query = "INSERT INTO ttrss_filters2_rules
|
$query = "INSERT INTO ttrss_filters2_rules
|
||||||
(filter_id, reg_exp,filter_type,feed_id,cat_id,cat_filter,inverse) VALUES
|
(filter_id, reg_exp,filter_type,feed_id,cat_id,match_on,inverse) VALUES
|
||||||
('$filter_id', '$reg_exp', '$filter_type', $feed_id, $cat_id, $cat_filter, $inverse)";
|
('$filter_id', '$reg_exp', '$filter_type', NULL, NULL, '$match_on', $inverse)";
|
||||||
|
|
||||||
$this->dbh->query($query);
|
$this->dbh->query($query);
|
||||||
}
|
}
|
||||||
|
@ -914,17 +956,16 @@ class Pref_Filters extends Handler_Protected {
|
||||||
} else {
|
} else {
|
||||||
$reg_exp = "";
|
$reg_exp = "";
|
||||||
$filter_type = 1;
|
$filter_type = 1;
|
||||||
$feed_id = 0;
|
$feed_id = [];
|
||||||
$inverse_checked = "";
|
$inverse_checked = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strpos($feed_id, "CAT:") === 0) {
|
/*if (strpos($feed_id, "CAT:") === 0) {
|
||||||
$feed_id = substr($feed_id, 4);
|
$feed_id = substr($feed_id, 4);
|
||||||
$cat_filter = true;
|
$cat_filter = true;
|
||||||
} else {
|
} else {
|
||||||
$cat_filter = false;
|
$cat_filter = false;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
|
||||||
print "<form name='filter_new_rule_form' id='filter_new_rule_form'>";
|
print "<form name='filter_new_rule_form' id='filter_new_rule_form'>";
|
||||||
|
|
||||||
|
@ -960,9 +1001,9 @@ class Pref_Filters extends Handler_Protected {
|
||||||
print __("in") . " ";
|
print __("in") . " ";
|
||||||
|
|
||||||
print "<span id='filterDlg_feeds'>";
|
print "<span id='filterDlg_feeds'>";
|
||||||
print_feed_select("feed_id",
|
print_feed_multi_select("feed_id",
|
||||||
$cat_filter ? "CAT:$feed_id" : $feed_id,
|
$feed_id,
|
||||||
'dojoType="dijit.form.FilteringSelect"');
|
'dojoType="dijit.form.MultiSelect" style="height : 150px"');
|
||||||
print "</span>";
|
print "</span>";
|
||||||
|
|
||||||
print "</div>";
|
print "</div>";
|
||||||
|
|
|
@ -497,6 +497,10 @@ class RSSUtils {
|
||||||
|
|
||||||
$filters = load_filters($feed, $owner_uid);
|
$filters = load_filters($feed, $owner_uid);
|
||||||
|
|
||||||
|
if ($debug_enabled) {
|
||||||
|
print_r($filters);
|
||||||
|
}
|
||||||
|
|
||||||
_debug("" . count($filters) . " filters loaded.", $debug_enabled);
|
_debug("" . count($filters) . " filters loaded.", $debug_enabled);
|
||||||
|
|
||||||
$items = $rss->get_items();
|
$items = $rss->get_items();
|
||||||
|
|
|
@ -70,6 +70,104 @@ function print_radio($id, $default, $true_is, $values, $attributes = "") {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function print_feed_multi_select($id, $default_ids = [],
|
||||||
|
$attributes = "", $include_all_feeds = true,
|
||||||
|
$root_id = false, $nest_level = 0) {
|
||||||
|
|
||||||
|
print_r(in_array("CAT:6",$default_ids));
|
||||||
|
|
||||||
|
if (!$root_id) {
|
||||||
|
print "<select multiple=\true\" id=\"$id\" name=\"$id\" $attributes>";
|
||||||
|
if ($include_all_feeds) {
|
||||||
|
$is_selected = (in_array("0", $default_ids)) ? "selected=\"1\"" : "";
|
||||||
|
print "<option $is_selected value=\"0\">".__('All feeds')."</option>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (get_pref('ENABLE_FEED_CATS')) {
|
||||||
|
|
||||||
|
if ($root_id)
|
||||||
|
$parent_qpart = "parent_cat = '$root_id'";
|
||||||
|
else
|
||||||
|
$parent_qpart = "parent_cat IS NULL";
|
||||||
|
|
||||||
|
$result = db_query("SELECT id,title,
|
||||||
|
(SELECT COUNT(id) FROM ttrss_feed_categories AS c2 WHERE
|
||||||
|
c2.parent_cat = ttrss_feed_categories.id) AS num_children
|
||||||
|
FROM ttrss_feed_categories
|
||||||
|
WHERE owner_uid = ".$_SESSION["uid"]." AND $parent_qpart ORDER BY title");
|
||||||
|
|
||||||
|
while ($line = db_fetch_assoc($result)) {
|
||||||
|
|
||||||
|
for ($i = 0; $i < $nest_level; $i++)
|
||||||
|
$line["title"] = " - " . $line["title"];
|
||||||
|
|
||||||
|
$is_selected = in_array("CAT:".$line["id"], $default_ids) ? "selected=\"1\"" : "";
|
||||||
|
|
||||||
|
printf("<option $is_selected value='CAT:%d'>%s</option>",
|
||||||
|
$line["id"], htmlspecialchars($line["title"]));
|
||||||
|
|
||||||
|
if ($line["num_children"] > 0)
|
||||||
|
print_feed_multi_select($id, $default_ids, $attributes,
|
||||||
|
$include_all_feeds, $line["id"], $nest_level+1);
|
||||||
|
|
||||||
|
$feed_result = db_query("SELECT id,title FROM ttrss_feeds
|
||||||
|
WHERE cat_id = '".$line["id"]."' AND owner_uid = ".$_SESSION["uid"] . " ORDER BY title");
|
||||||
|
|
||||||
|
while ($fline = db_fetch_assoc($feed_result)) {
|
||||||
|
$is_selected = (in_array($fline["id"], $default_ids)) ? "selected=\"1\"" : "";
|
||||||
|
|
||||||
|
$fline["title"] = " + " . $fline["title"];
|
||||||
|
|
||||||
|
for ($i = 0; $i < $nest_level; $i++)
|
||||||
|
$fline["title"] = " - " . $fline["title"];
|
||||||
|
|
||||||
|
printf("<option $is_selected value='%d'>%s</option>",
|
||||||
|
$fline["id"], htmlspecialchars($fline["title"]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$root_id) {
|
||||||
|
$is_selected = in_array("CAT:0", $default_ids) ? "selected=\"1\"" : "";
|
||||||
|
|
||||||
|
printf("<option $is_selected value='CAT:0'>%s</option>",
|
||||||
|
__("Uncategorized"));
|
||||||
|
|
||||||
|
$feed_result = db_query("SELECT id,title FROM ttrss_feeds
|
||||||
|
WHERE cat_id IS NULL AND owner_uid = ".$_SESSION["uid"] . " ORDER BY title");
|
||||||
|
|
||||||
|
while ($fline = db_fetch_assoc($feed_result)) {
|
||||||
|
$is_selected = in_array($fline["id"], $default_ids) ? "selected=\"1\"" : "";
|
||||||
|
|
||||||
|
$fline["title"] = " + " . $fline["title"];
|
||||||
|
|
||||||
|
for ($i = 0; $i < $nest_level; $i++)
|
||||||
|
$fline["title"] = " - " . $fline["title"];
|
||||||
|
|
||||||
|
printf("<option $is_selected value='%d'>%s</option>",
|
||||||
|
$fline["id"], htmlspecialchars($fline["title"]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$result = db_query("SELECT id,title FROM ttrss_feeds
|
||||||
|
WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
|
||||||
|
|
||||||
|
while ($line = db_fetch_assoc($result)) {
|
||||||
|
|
||||||
|
$is_selected = (in_array($line["id"], $default_ids)) ? "selected=\"1\"" : "";
|
||||||
|
|
||||||
|
printf("<option $is_selected value='%d'>%s</option>",
|
||||||
|
$line["id"], htmlspecialchars($line["title"]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$root_id) {
|
||||||
|
print "</select>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function print_feed_select($id, $default_id = "",
|
function print_feed_select($id, $default_id = "",
|
||||||
$attributes = "", $include_all_feeds = true,
|
$attributes = "", $include_all_feeds = true,
|
||||||
$root_id = false, $nest_level = 0) {
|
$root_id = false, $nest_level = 0) {
|
||||||
|
|
|
@ -1813,20 +1813,26 @@
|
||||||
$result = db_query("SELECT * FROM ttrss_filters2 WHERE
|
$result = db_query("SELECT * FROM ttrss_filters2 WHERE
|
||||||
owner_uid = $owner_uid AND enabled = true ORDER BY order_id, title");
|
owner_uid = $owner_uid AND enabled = true ORDER BY order_id, title");
|
||||||
|
|
||||||
$check_cats = join(",", array_merge(
|
$check_cats = array_merge(
|
||||||
Feeds::getParentCategories($cat_id, $owner_uid),
|
Feeds::getParentCategories($cat_id, $owner_uid),
|
||||||
array($cat_id)));
|
[$cat_id]);
|
||||||
|
|
||||||
|
$check_cats_str = join(",", $check_cats);
|
||||||
|
$check_cats_fullids = array_map(function($a) { return "CAT:$a"; }, $check_cats);
|
||||||
|
|
||||||
while ($line = db_fetch_assoc($result)) {
|
while ($line = db_fetch_assoc($result)) {
|
||||||
$filter_id = $line["id"];
|
$filter_id = $line["id"];
|
||||||
|
|
||||||
|
$match_any_rule = sql_bool_to_bool($line["match_any_rule"]);
|
||||||
|
|
||||||
$result2 = db_query("SELECT
|
$result2 = db_query("SELECT
|
||||||
r.reg_exp, r.inverse, 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, r.match_on, t.name AS type_name
|
||||||
FROM ttrss_filters2_rules AS r,
|
FROM ttrss_filters2_rules AS r,
|
||||||
ttrss_filter_types AS t
|
ttrss_filter_types AS t
|
||||||
WHERE
|
WHERE
|
||||||
($null_cat_qpart (cat_id IS NULL AND cat_filter = false) OR cat_id IN ($check_cats)) AND
|
(match_on IS NOT NULL OR
|
||||||
(feed_id IS NULL OR feed_id = '$feed_id') AND
|
(($null_cat_qpart (cat_id IS NULL AND cat_filter = false) OR cat_id IN ($check_cats_str)) AND
|
||||||
|
(feed_id IS NULL OR feed_id = '$feed_id'))) AND
|
||||||
filter_type = t.id AND filter_id = '$filter_id'");
|
filter_type = t.id AND filter_id = '$filter_id'");
|
||||||
|
|
||||||
$rules = array();
|
$rules = array();
|
||||||
|
@ -1835,30 +1841,53 @@
|
||||||
while ($rule_line = db_fetch_assoc($result2)) {
|
while ($rule_line = db_fetch_assoc($result2)) {
|
||||||
# print_r($rule_line);
|
# print_r($rule_line);
|
||||||
|
|
||||||
$rule = array();
|
if ($rule_line["match_on"]) {
|
||||||
$rule["reg_exp"] = $rule_line["reg_exp"];
|
$match_on = json_decode($rule_line["match_on"], true);
|
||||||
$rule["type"] = $rule_line["type_name"];
|
|
||||||
$rule["inverse"] = sql_bool_to_bool($rule_line["inverse"]);
|
|
||||||
|
|
||||||
array_push($rules, $rule);
|
if (in_array("0", $match_on) || in_array($feed_id, $match_on) || count(array_intersect($check_cats_fullids, $match_on)) > 0) {
|
||||||
|
|
||||||
|
$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);
|
||||||
|
} else if (!$match_any_rule) {
|
||||||
|
// this filter contains a rule that doesn't match to this feed/category combination
|
||||||
|
// thus filter has to be rejected
|
||||||
|
|
||||||
|
$rules = [];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
$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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$result2 = db_query("SELECT a.action_param,t.name AS type_name
|
if (count($rules) > 0) {
|
||||||
FROM ttrss_filters2_actions AS a,
|
$result2 = db_query("SELECT a.action_param,t.name AS type_name
|
||||||
ttrss_filter_actions AS t
|
FROM ttrss_filters2_actions AS a,
|
||||||
WHERE
|
ttrss_filter_actions AS t
|
||||||
action_id = t.id AND filter_id = '$filter_id'");
|
WHERE
|
||||||
|
action_id = t.id AND filter_id = '$filter_id'");
|
||||||
|
|
||||||
while ($action_line = db_fetch_assoc($result2)) {
|
while ($action_line = db_fetch_assoc($result2)) {
|
||||||
# print_r($action_line);
|
# print_r($action_line);
|
||||||
|
|
||||||
$action = array();
|
$action = array();
|
||||||
$action["type"] = $action_line["type_name"];
|
$action["type"] = $action_line["type_name"];
|
||||||
$action["param"] = $action_line["action_param"];
|
$action["param"] = $action_line["action_param"];
|
||||||
|
|
||||||
array_push($actions, $action);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
array_push($actions, $action);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$filter = array();
|
$filter = array();
|
||||||
$filter["match_any_rule"] = sql_bool_to_bool($line["match_any_rule"]);
|
$filter["match_any_rule"] = sql_bool_to_bool($line["match_any_rule"]);
|
||||||
|
|
Loading…
Reference in New Issue