From be91355c20140c797912247bfbfb45b7dbfd41c9 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 20 Feb 2021 18:15:08 +0300 Subject: first for filter frontend overhaul --- classes/pref/filters.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'classes/pref/filters.php') diff --git a/classes/pref/filters.php b/classes/pref/filters.php index f9b3217c9..cfff383d8 100755 --- a/classes/pref/filters.php +++ b/classes/pref/filters.php @@ -861,7 +861,7 @@ class Pref_Filters extends Handler_Protected { print "
"; print " - ".$this->_get_rule_name($line)."". + ".$this->_get_rule_name($line)."". \Controls\hidden_tag("rule[]", (string)json_encode($line)).""; } } @@ -429,7 +429,7 @@ class Pref_Filters extends Handler_Protected { unset($line["id"]); print "
  • - ".$this->_get_action_name($line)."". + ".$this->_get_action_name($line)."". \Controls\hidden_tag("action[]", (string)json_encode($line))."
  • "; } } @@ -861,7 +861,7 @@ class Pref_Filters extends Handler_Protected { print "
    "; print ""; $res = $this->pdo->query("SELECT id,description FROM ttrss_filter_actions @@ -873,17 +873,17 @@ class Pref_Filters extends Handler_Protected { print ""; - $param_box_hidden = ($action_id == 7 || $action_id == 4 || $action_id == 6 || $action_id == 9) ? - "" : "display : none"; + #$param_box_hidden = ($action_id == 7 || $action_id == 4 || $action_id == 6 || $action_id == 9) ? + # "" : "display : none"; - $param_hidden = ($action_id == 4 || $action_id == 6) ? - "" : "display : none"; + #$param_hidden = ($action_id == 4 || $action_id == 6) ? + # "" : "display : none"; - $label_param_hidden = ($action_id == 7) ? "" : "display : none"; - $plugin_param_hidden = ($action_id == 9) ? "" : "display : none"; + #$label_param_hidden = ($action_id == 7) ? "" : "display : none"; + #$plugin_param_hidden = ($action_id == 9) ? "" : "display : none"; - print ""; - print " "; + #print ""; + #print " "; //print " " . __("with parameters:") . " "; print " $plugin_param_hidden], $filter_plugin_disabled), "filterDlg_actionParamPlugin"); - print ""; + #print ""; print " "; // tiny layout hack -- cgit v1.2.3 From 94560132ddf45a5a7c68ce520b40ecb10a6f89fe Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 21 Feb 2021 09:35:07 +0300 Subject: for the most part, deal with filter rules UI --- classes/pref/filters.php | 231 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 160 insertions(+), 71 deletions(-) (limited to 'classes/pref/filters.php') diff --git a/classes/pref/filters.php b/classes/pref/filters.php index 9c250be19..4e52260c9 100755 --- a/classes/pref/filters.php +++ b/classes/pref/filters.php @@ -318,6 +318,84 @@ class Pref_Filters extends Handler_Protected { WHERE id = ? AND owner_uid = ?"); $sth->execute([$filter_id, $_SESSION['uid']]); + if (empty($filter_id) || $row = $sth->fetch()) { + $rv = [ + "id" => $filter_id, + "enabled" => $row["enabled"] ?? true, + "match_any_rule" => $row["match_any_rule"] ?? false, + "inverse" => $row["inverse"] ?? false, + "title" => $row["title"] ?? "", + "rules" => [], + "actions" => [], + "filter_types" => [], + "filter_actions" => [], + "labels" => Labels::get_all($_SESSION["uid"]) + ]; + + $res = $this->pdo->query("SELECT id,description + FROM ttrss_filter_types WHERE id != 5 ORDER BY description"); + + while ($line = $res->fetch()) { + $rv["filter_types"][$line["id"]] = __($line["description"]); + } + + $res = $this->pdo->query("SELECT id,description FROM ttrss_filter_actions + ORDER BY name"); + + while ($line = $res->fetch()) { + $rv["filter_actions"][$line["id"]] = __($line["description"]); + } + + if ($filter_id) { + $rules_sth = $this->pdo->prepare("SELECT * FROM ttrss_filters2_rules + WHERE filter_id = ? ORDER BY reg_exp, id"); + $rules_sth->execute([$filter_id]); + + while ($rrow = $rules_sth->fetch(PDO::FETCH_ASSOC)) { + if ($rrow["match_on"]) { + $rrow["feed_id"] = json_decode($rrow["match_on"], true); + } else { + if ($rrow["cat_filter"]) { + $feed_id = "CAT:" . (int)$rrow["cat_id"]; + } else { + $feed_id = (int)$rrow["feed_id"]; + } + + $rrow["feed_id"] = ["" . $feed_id]; // set item type to string for in_array() + } + + unset($rrow["cat_filter"]); + unset($rrow["cat_id"]); + unset($rrow["filter_id"]); + unset($rrow["id"]); + if (!$rrow["inverse"]) unset($rrow["inverse"]); + unset($rrow["match_on"]); + + $rrow["name"] = $this->_get_rule_name($rrow); + + array_push($rv["rules"], $rrow); + } + + $actions_sth = $this->pdo->prepare("SELECT * FROM ttrss_filters2_actions + WHERE filter_id = ? ORDER BY id"); + $actions_sth->execute([$filter_id]); + + while ($arow = $actions_sth->fetch(PDO::FETCH_ASSOC)) { + $arow["action_param_label"] = $arow["action_param"]; + + unset($arow["filter_id"]); + unset($arow["id"]); + + $arow["name"] = $this->_get_action_name($arow); + + array_push($rv["actions"], $arow); + } + } + print json_encode($rv); + } + + /*return; + if (empty($filter_id) || $row = $sth->fetch()) { $enabled = $row["enabled"] ?? true; @@ -475,7 +553,7 @@ class Pref_Filters extends Handler_Protected { } print ""; - } + } */ } private function _get_rule_name($rule) { @@ -592,8 +670,7 @@ class Pref_Filters extends Handler_Protected { $sth->execute(array_merge($ids, [$_SESSION['uid']])); } - private function _save_rules_and_actions($filter_id) - { + private function _save_rules_and_actions($filter_id) { $sth = $this->pdo->prepare("DELETE FROM ttrss_filters2_rules WHERE filter_id = ?"); $sth->execute([$filter_id]); @@ -670,7 +747,7 @@ class Pref_Filters extends Handler_Protected { } } - function add() { + function add () { $enabled = checkbox_to_sql_bool(clean($_REQUEST["enabled"] ?? false)); $match_any_rule = checkbox_to_sql_bool(clean($_REQUEST["match_any_rule"] ?? false)); $title = clean($_REQUEST["title"]); @@ -764,7 +841,15 @@ class Pref_Filters extends Handler_Protected { $this->feed_multi_select("feed_id", $feed_ids, 'style="width : 500px; height : 300px" dojoType="dijit.form.MultiSelect"') + ]); + + /*return; + $rule = json_decode(clean($_REQUEST["rule"]), true); if ($rule) { @@ -818,7 +903,7 @@ class Pref_Filters extends Handler_Protected { print "
    "; print ""; - $this->feed_multi_select("feed_id", + print $this->feed_multi_select("feed_id", $feed_id, 'style="width : 500px; height : 300px" dojoType="dijit.form.MultiSelect"'); print ""; @@ -840,7 +925,7 @@ class Pref_Filters extends Handler_Protected { print ""; - print ""; + print "";*/ } function newaction() { @@ -1071,102 +1156,106 @@ class Pref_Filters extends Handler_Protected { $attributes = "", $include_all_feeds = true, $root_id = null, $nest_level = 0) { - $pdo = Db::pdo(); + $pdo = Db::pdo(); - // print_r(in_array("CAT:6",$default_ids)); + $rv = ""; - if (!$root_id) { - print ""; + if ($include_all_feeds) { + $is_selected = (in_array("0", $default_ids)) ? "selected=\"1\"" : ""; + $rv .= ""; + } + } - if (!$root_id) $root_id = null; + if (get_pref('ENABLE_FEED_CATS')) { - $sth = $pdo->prepare("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 = :uid AND - (parent_cat = :root_id OR (:root_id IS NULL AND parent_cat IS NULL)) ORDER BY title"); + if (!$root_id) $root_id = null; - $sth->execute([":uid" => $_SESSION['uid'], ":root_id" => $root_id]); + $sth = $pdo->prepare("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 = :uid AND + (parent_cat = :root_id OR (:root_id IS NULL AND parent_cat IS NULL)) ORDER BY title"); - while ($line = $sth->fetch()) { + $sth->execute([":uid" => $_SESSION['uid'], ":root_id" => $root_id]); - for ($i = 0; $i < $nest_level; $i++) - $line["title"] = " " . $line["title"]; + while ($line = $sth->fetch()) { - $is_selected = in_array("CAT:".$line["id"], $default_ids) ? "selected=\"1\"" : ""; + for ($i = 0; $i < $nest_level; $i++) + $line["title"] = " " . $line["title"]; - printf("", - $line["id"], htmlspecialchars($line["title"])); + $is_selected = in_array("CAT:".$line["id"], $default_ids) ? "selected=\"1\"" : ""; - if ($line["num_children"] > 0) - $this->feed_multi_select($id, $default_ids, $attributes, - $include_all_feeds, $line["id"], $nest_level+1); + $rv .= sprintf("", + $line["id"], htmlspecialchars($line["title"])); - $f_sth = $pdo->prepare("SELECT id,title FROM ttrss_feeds - WHERE cat_id = ? AND owner_uid = ? ORDER BY title"); + if ($line["num_children"] > 0) + $rv .= $this->feed_multi_select($id, $default_ids, $attributes, + $include_all_feeds, $line["id"], $nest_level+1); - $f_sth->execute([$line['id'], $_SESSION['uid']]); + $f_sth = $pdo->prepare("SELECT id,title FROM ttrss_feeds + WHERE cat_id = ? AND owner_uid = ? ORDER BY title"); - while ($fline = $f_sth->fetch()) { - $is_selected = (in_array($fline["id"], $default_ids)) ? "selected=\"1\"" : ""; + $f_sth->execute([$line['id'], $_SESSION['uid']]); - $fline["title"] = " " . $fline["title"]; + while ($fline = $f_sth->fetch()) { + $is_selected = (in_array($fline["id"], $default_ids)) ? "selected=\"1\"" : ""; - for ($i = 0; $i < $nest_level; $i++) $fline["title"] = " " . $fline["title"]; - printf("", - $fline["id"], htmlspecialchars($fline["title"])); - } - } + for ($i = 0; $i < $nest_level; $i++) + $fline["title"] = " " . $fline["title"]; - if (!$root_id) { - $is_selected = in_array("CAT:0", $default_ids) ? "selected=\"1\"" : ""; + $rv .= sprintf("", + $fline["id"], htmlspecialchars($fline["title"])); + } + } - printf("", - __("Uncategorized")); + if (!$root_id) { + $is_selected = in_array("CAT:0", $default_ids) ? "selected=\"1\"" : ""; - $f_sth = $pdo->prepare("SELECT id,title FROM ttrss_feeds - WHERE cat_id IS NULL AND owner_uid = ? ORDER BY title"); - $f_sth->execute([$_SESSION['uid']]); + $rv .= sprintf("", + __("Uncategorized")); - while ($fline = $f_sth->fetch()) { - $is_selected = in_array($fline["id"], $default_ids) ? "selected=\"1\"" : ""; + $f_sth = $pdo->prepare("SELECT id,title FROM ttrss_feeds + WHERE cat_id IS NULL AND owner_uid = ? ORDER BY title"); + $f_sth->execute([$_SESSION['uid']]); - $fline["title"] = " " . $fline["title"]; + while ($fline = $f_sth->fetch()) { + $is_selected = in_array($fline["id"], $default_ids) ? "selected=\"1\"" : ""; - for ($i = 0; $i < $nest_level; $i++) $fline["title"] = " " . $fline["title"]; - printf("", - $fline["id"], htmlspecialchars($fline["title"])); + for ($i = 0; $i < $nest_level; $i++) + $fline["title"] = " " . $fline["title"]; + + $rv .= sprintf("", + $fline["id"], htmlspecialchars($fline["title"])); + } } - } - } else { - $sth = $pdo->prepare("SELECT id,title FROM ttrss_feeds - WHERE owner_uid = ? ORDER BY title"); - $sth->execute([$_SESSION['uid']]); + } else { + $sth = $pdo->prepare("SELECT id,title FROM ttrss_feeds + WHERE owner_uid = ? ORDER BY title"); + $sth->execute([$_SESSION['uid']]); - while ($line = $sth->fetch()) { + while ($line = $sth->fetch()) { - $is_selected = (in_array($line["id"], $default_ids)) ? "selected=\"1\"" : ""; + $is_selected = (in_array($line["id"], $default_ids)) ? "selected=\"1\"" : ""; - printf("", - $line["id"], htmlspecialchars($line["title"])); + $rv .= sprintf("", + $line["id"], htmlspecialchars($line["title"])); + } } - } - if (!$root_id) { - print ""; + if (!$root_id) { + $rv .= ""; + } + + return $rv; } } -} -- cgit v1.2.3 From 3b8d69206ccc24b41b45acd55f0c63681e749fd1 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 21 Feb 2021 10:28:59 +0300 Subject: deal with filter actions UI --- classes/pref/filters.php | 354 +++-------------------------------------------- 1 file changed, 16 insertions(+), 338 deletions(-) (limited to 'classes/pref/filters.php') diff --git a/classes/pref/filters.php b/classes/pref/filters.php index 4e52260c9..c00e52bde 100755 --- a/classes/pref/filters.php +++ b/classes/pref/filters.php @@ -328,7 +328,8 @@ class Pref_Filters extends Handler_Protected { "rules" => [], "actions" => [], "filter_types" => [], - "filter_actions" => [], + "action_types" => [], + "plugin_actions" => [], "labels" => Labels::get_all($_SESSION["uid"]) ]; @@ -343,7 +344,17 @@ class Pref_Filters extends Handler_Protected { ORDER BY name"); while ($line = $res->fetch()) { - $rv["filter_actions"][$line["id"]] = __($line["description"]); + $rv["action_types"][$line["id"]] = __($line["description"]); + } + + $filter_actions = PluginHost::getInstance()->get_filter_actions(); + + foreach ($filter_actions as $fclass => $factions) { + foreach ($factions as $faction) { + + $rv["plugin_actions"][$fclass . ":" . $faction["action"]] = + $fclass . ": " . $faction["description"]; + } } if ($filter_id) { @@ -393,167 +404,6 @@ class Pref_Filters extends Handler_Protected { } print json_encode($rv); } - - /*return; - - if (empty($filter_id) || $row = $sth->fetch()) { - - $enabled = $row["enabled"] ?? true; - $match_any_rule = $row["match_any_rule"] ?? false; - $inverse = $row["inverse"] ?? false; - $title = htmlspecialchars($row["title"] ?? ""); - - print "
    "; - - print \Controls\hidden_tag("op", "pref-filters"); - - if ($filter_id) { - print \Controls\hidden_tag("id", "$filter_id"); - print \Controls\hidden_tag("method", "editSave"); - } else { - print \Controls\hidden_tag("method", "add"); - } - - print \Controls\hidden_tag("csrf_token", $_SESSION['csrf_token']); - - print "
    ".__("Caption")."
    -
    - -
    -
    ".__("Match")."
    -
    -
    -
    - " . __('Select')." -
    - -
    ".__('All')."
    -
    ".__('None')."
    -
    -
    - - -
    "; - - print "
      "; - - if ($filter_id) { - $rules_sth = $this->pdo->prepare("SELECT * FROM ttrss_filters2_rules - WHERE filter_id = ? ORDER BY reg_exp, id"); - $rules_sth->execute([$filter_id]); - - while ($line = $rules_sth->fetch()) { - if ($line["match_on"]) { - $line["feed_id"] = json_decode($line["match_on"], true); - } else { - if ($line["cat_filter"]) { - $feed_id = "CAT:" . (int)$line["cat_id"]; - } else { - $feed_id = (int)$line["feed_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 (!$line["inverse"]) unset($line["inverse"]); - unset($line["match_on"]); - - print "
    • - ".$this->_get_rule_name($line)."". - \Controls\hidden_tag("rule[]", (string)json_encode($line))."
    • "; - } - } - - print "
    -
    "; - - print "
    ".__("Apply actions")."
    -
    -
    -
    - ".__('Select')." -
    -
    ".__('All')."
    -
    ".__('None')."
    -
    -
    - - -
    "; - - print "
      "; - - if ($filter_id) { - $actions_sth = $this->pdo->prepare("SELECT * FROM ttrss_filters2_actions - WHERE filter_id = ? ORDER BY id"); - $actions_sth->execute([$filter_id]); - - while ($line = $actions_sth->fetch()) { - $line["action_param_label"] = $line["action_param"]; - - unset($line["filter_id"]); - unset($line["id"]); - - print "
    • - ".$this->_get_action_name($line)."". - \Controls\hidden_tag("action[]", (string)json_encode($line))."
    • "; - } - } - - print "
    "; - - print "
    "; - - print "
    ".__("Options")."
    -
    "; - - print "
    -
    "; - - print "
    - -
    "; - - print "
    -
    "; - - print "
    -
    "; - - if ($filter_id) { - print "
    - -
    - - - "; - } else { - print " - - "; - } - - print "
    "; - } */ } private function _get_rule_name($rule) { @@ -845,180 +695,8 @@ class Pref_Filters extends Handler_Protected { $feed_ids = explode(",", clean($_REQUEST["ids"])); print json_encode([ - "multiselect" => $this->feed_multi_select("feed_id", $feed_ids, 'style="width : 500px; height : 300px" dojoType="dijit.form.MultiSelect"') + "multiselect" => $this->_feed_multi_select("feed_id", $feed_ids, 'style="width : 540px; height : 300px" dojoType="dijit.form.MultiSelect"') ]); - - /*return; - - $rule = json_decode(clean($_REQUEST["rule"]), true); - - if ($rule) { - $reg_exp = htmlspecialchars($rule["reg_exp"]); - $filter_type = $rule["filter_type"]; - $feed_id = $rule["feed_id"]; - $inverse_checked = !empty($rule["inverse"]); - } else { - $reg_exp = ""; - $filter_type = 1; - $feed_id = ["0"]; - $inverse_checked = false; - } - - print "
    "; - - $res = $this->pdo->query("SELECT id,description - FROM ttrss_filter_types WHERE id != 5 ORDER BY description"); - - $filter_types = array(); - - while ($line = $res->fetch()) { - $filter_types[$line["id"]] = __($line["description"]); - } - - print "
    ".__("Match")."
    "; - - print "
    "; - - print ""; - - print "
    "; - - print "
    "; - print ""; - print "
    "; - - print "
    "; - print " "; - print \Controls\select_hash("filter_type", $filter_type, $filter_types); - print " "; - - print "
    "; - - print "
    "; - print ""; - print $this->feed_multi_select("feed_id", - $feed_id, - 'style="width : 500px; height : 300px" dojoType="dijit.form.MultiSelect"'); - print ""; - - print "
    "; - - print "
    "; - - print "
    "; - - print ""; - - print " "; - - print ""; - - print "
    "; - - print "
    ";*/ - } - - function newaction() { - $action = json_decode(clean($_REQUEST["action"]), true); - - if ($action) { - $action_param = $action["action_param"]; - $action_id = (int)$action["action_id"]; - } else { - $action_param = ""; - $action_id = 0; - } - - print "
    "; - - print "
    ".__("Perform Action")."
    "; - - print "
    "; - - print ""; - - #$param_box_hidden = ($action_id == 7 || $action_id == 4 || $action_id == 6 || $action_id == 9) ? - # "" : "display : none"; - - #$param_hidden = ($action_id == 4 || $action_id == 6) ? - # "" : "display : none"; - - #$label_param_hidden = ($action_id == 7) ? "" : "display : none"; - #$plugin_param_hidden = ($action_id == 9) ? "" : "display : none"; - - #print ""; - #print " "; - //print " " . __("with parameters:") . " "; - print ""; - - print \Controls\select_labels("action_param_label", $action_param, - ["style" => $label_param_hidden], - "filterDlg_actionParamLabel"); - - $filter_actions = PluginHost::getInstance()->get_filter_actions(); - $filter_action_hash = array(); - - foreach ($filter_actions as $fclass => $factions) { - foreach ($factions as $faction) { - - $filter_action_hash[$fclass . ":" . $faction["action"]] = - $fclass . ": " . $faction["description"]; - } - } - - if (count($filter_action_hash) == 0) { - $filter_plugin_disabled = ["disabled" => "1"]; - - $filter_action_hash["no-data"] = __("No actions available"); - - } else { - $filter_plugin_disabled = []; - } - - print \Controls\select_hash("action_param_plugin", $action_param, $filter_action_hash, - array_merge(["style" => $plugin_param_hidden], $filter_plugin_disabled), - "filterDlg_actionParamPlugin"); - - #print ""; - - print " "; // tiny layout hack - - print "
    "; - - print ""; - - print "
    "; } private function _get_name($id) { @@ -1152,7 +830,7 @@ class Pref_Filters extends Handler_Protected { $this->pdo->commit(); } - private function feed_multi_select($id, $default_ids = [], + private function _feed_multi_select($id, $default_ids = [], $attributes = "", $include_all_feeds = true, $root_id = null, $nest_level = 0) { @@ -1194,7 +872,7 @@ class Pref_Filters extends Handler_Protected { $line["id"], htmlspecialchars($line["title"])); if ($line["num_children"] > 0) - $rv .= $this->feed_multi_select($id, $default_ids, $attributes, + $rv .= $this->_feed_multi_select($id, $default_ids, $attributes, $include_all_feeds, $line["id"], $nest_level+1); $f_sth = $pdo->prepare("SELECT id,title FROM ttrss_feeds -- cgit v1.2.3