From 8f8675a26abf86ff6a77bc750096b77491d71213 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 12 Feb 2021 14:31:36 +0300 Subject: * filters: remove duplicate code, overall cleanup * check if some tres exist before trying to reload them --- classes/pref/filters.php | 291 +++++++++++++++-------------------------------- 1 file changed, 90 insertions(+), 201 deletions(-) (limited to 'classes') diff --git a/classes/pref/filters.php b/classes/pref/filters.php index eb7c87746..62f6fc1a0 100755 --- a/classes/pref/filters.php +++ b/classes/pref/filters.php @@ -2,7 +2,7 @@ class Pref_Filters extends Handler_Protected { function csrf_ignore($method) { - $csrf_ignored = array("index", "getfiltertree", "edit", "newfilter", "newrule", + $csrf_ignored = array("index", "getfiltertree", "newrule", "newaction", "savefilterorder"); return array_search($method, $csrf_ignored) !== false; @@ -313,24 +313,30 @@ class Pref_Filters extends Handler_Protected { function edit() { - $filter_id = clean($_REQUEST["id"]); + $filter_id = (int) clean($_REQUEST["id"] ?? 0); $sth = $this->pdo->prepare("SELECT * FROM ttrss_filters2 WHERE id = ? AND owner_uid = ?"); $sth->execute([$filter_id, $_SESSION['uid']]); - if ($row = $sth->fetch()) { + if (empty($filter_id) || $row = $sth->fetch()) { - $enabled = $row["enabled"]; - $match_any_rule = $row["match_any_rule"]; - $inverse = $row["inverse"]; - $title = htmlspecialchars($row["title"]); + $enabled = $row["enabled"] ?? true; + $match_any_rule = $row["match_any_rule"] ?? false; + $inverse = $row["inverse"] ?? false; + $title = htmlspecialchars($row["title"] ?? ""); - print "
"; + print ""; print_hidden("op", "pref-filters"); - print_hidden("id", "$filter_id"); - print_hidden("method", "editSave"); + + if ($filter_id) { + print_hidden("id", "$filter_id"); + print_hidden("method", "editSave"); + } else { + print_hidden("method", "add"); + } + print_hidden("csrf_token", $_SESSION['csrf_token']); print "
".__("Caption")."
@@ -358,35 +364,37 @@ class Pref_Filters extends Handler_Protected { print " @@ -412,79 +420,66 @@ class Pref_Filters extends Handler_Protected { print ""; print ""; - print "
".__("Options")."
"; - print "
"; - - if ($enabled) { - $checked = "checked=\"1\""; - } else { - $checked = ""; - } - - print "
"; - print ""; - - if ($match_any_rule) { - $checked = "checked=\"1\""; - } else { - $checked = ""; - } - - print "
"; - - print ""; - - print "
"; - - if ($inverse) { - $checked = "checked=\"1\""; + print "
".__("Options")."
+
"; + + print "
+
"; + + print "
+ +
"; + + print "
+
"; + + print "
+
"; + + if ($filter_id) { + print "
+ +
+ + + "; } else { - $checked = ""; + print " + + "; } - print ""; - - print "
"; - - print "
"; - - print "
-
- -
- - - -
-
"; + print ""; } } @@ -736,7 +731,7 @@ class Pref_Filters extends Handler_Protected { dojoType=\"dijit.MenuItem\">".__('None').""; print ""; - print " "; print " "; - - print " "; - - print ""; - - print ""; - - print ""; - - print "
".__("Apply actions")."
"; - - print "
"; - - print "
"; - - print "
". - "" . __('Select').""; - print "
"; - print "
".__('All')."
"; - print "
".__('None')."
"; - print "
"; - - print " "; - - print " "; - - print "
"; - - print ""; - - print "
"; - - print "
".__("Options")."
"; - - print "
"; - print "
"; - - print ""; - - print "
"; - - print ""; - - print "
"; - - print ""; - - print "
"; - - print "
"; - - print ""; - - } - function newrule() { $rule = json_decode(clean($_REQUEST["rule"]), true); -- cgit v1.2.3-54-g00ecf