X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=classes%2Fpref%2Ffilters.php;h=12c2f271c28d9c303f1e18c20b04fdc636aa6b47;hb=6322ac79a020ab584d412d782d62b2ee77d7c6cf;hp=1921f2b97ab3f4ad49cb319b06b1d6b89bda68a0;hpb=5b0aec17e9359818e6a9d3161d8539d6ed7a4f70;p=tt-rss.git diff --git a/classes/pref/filters.php b/classes/pref/filters.php index 1921f2b9..12c2f271 100644 --- a/classes/pref/filters.php +++ b/classes/pref/filters.php @@ -3,20 +3,59 @@ class Pref_Filters extends Handler_Protected { function csrf_ignore($method) { $csrf_ignored = array("index", "getfiltertree", "edit", "newfilter", "newrule", - "newaction"); + "newaction", "savefilterorder"); return array_search($method, $csrf_ignored) !== false; } + function filtersortreset() { + db_query( "UPDATE ttrss_filters2 + SET order_id = 0 WHERE owner_uid = " . $_SESSION["uid"]); + return; + } + + function savefilterorder() { + $data = json_decode($_POST['payload'], true); + + #file_put_contents("/tmp/saveorder.json", $_POST['payload']); + #$data = json_decode(file_get_contents("/tmp/saveorder.json"), true); + + if (!is_array($data['items'])) + $data['items'] = json_decode($data['items'], true); + + $index = 0; + + if (is_array($data) && is_array($data['items'])) { + foreach ($data['items'][0]['items'] as $item) { + $filter_id = (int) str_replace("FILTER:", "", $item['_reference']); + + if ($filter_id > 0) { + + db_query( "UPDATE ttrss_filters2 SET + order_id = $index WHERE id = '$filter_id' AND + owner_uid = " .$_SESSION["uid"]); + + ++$index; + } + } + } + + return; + } + + function testFilter() { $filter = array(); $filter["enabled"] = true; $filter["match_any_rule"] = sql_bool_to_bool( - checkbox_to_sql_bool(db_escape_string($_REQUEST["match_any_rule"]))); + checkbox_to_sql_bool(db_escape_string( $_REQUEST["match_any_rule"]))); + $filter["inverse"] = sql_bool_to_bool( + checkbox_to_sql_bool(db_escape_string( $_REQUEST["inverse"]))); + $filter["rules"] = array(); - $result = db_query($this->link, "SELECT id,name FROM ttrss_filter_types"); + $result = db_query( "SELECT id,name FROM ttrss_filter_types"); $filter_types = array(); while ($line = db_fetch_assoc($result)) { @@ -44,9 +83,9 @@ class Pref_Filters extends Handler_Protected { } } - $feed_title = getFeedTitle($this->link, $feed); + $feed_title = getFeedTitle( $feed); - $qfh_ret = queryFeedHeadlines($this->link, -4, 30, "", false, false, false, + $qfh_ret = queryFeedHeadlines( -4, 30, "", false, false, false, "date_entered DESC", 0, $_SESSION["uid"], $filter); $result = $qfh_ret[0]; @@ -62,7 +101,7 @@ class Pref_Filters extends Handler_Protected { while ($line = db_fetch_assoc($result)) { $entry_timestamp = strtotime($line["updated"]); - $entry_tags = get_article_tags($this->link, $line["id"], $_SESSION["uid"]); + $entry_tags = get_article_tags( $line["id"], $_SESSION["uid"]); $content_preview = truncate_string( strip_tags($line["content_preview"]), 100, '...'); @@ -119,7 +158,7 @@ class Pref_Filters extends Handler_Protected { $filter_search = $_SESSION["prefs_filter_search"]; - $result = db_query($this->link, "SELECT *, + $result = db_query( "SELECT *, (SELECT action_param FROM ttrss_filters2_actions WHERE filter_id = ttrss_filters2.id ORDER BY id LIMIT 1) AS action_param, (SELECT action_id FROM ttrss_filters2_actions @@ -130,7 +169,7 @@ class Pref_Filters extends Handler_Protected { (SELECT reg_exp FROM ttrss_filters2_rules WHERE filter_id = ttrss_filters2.id ORDER BY id LIMIT 1) AS reg_exp FROM ttrss_filters2 WHERE - owner_uid = ".$_SESSION["uid"]." ORDER BY action_id,reg_exp"); + owner_uid = ".$_SESSION["uid"]." ORDER BY order_id, title"); $action_id = -1; @@ -139,7 +178,7 @@ class Pref_Filters extends Handler_Protected { while ($line = db_fetch_assoc($result)) { - if ($action_id != $line["action_id"]) { + /* if ($action_id != $line["action_id"]) { if (count($folder['items']) > 0) { array_push($root['items'], $folder); } @@ -149,13 +188,13 @@ class Pref_Filters extends Handler_Protected { $folder['name'] = __($line["action_name"]); $folder['items'] = array(); $action_id = $line["action_id"]; - } + } */ $name = $this->getFilterName($line["id"]); $match_ok = false; if ($filter_search) { - $rules_result = db_query($this->link, + $rules_result = db_query( "SELECT reg_exp FROM ttrss_filters2_rules WHERE filter_id = ".$line["id"]); while ($rule_line = db_fetch_assoc($rules_result)) { @@ -167,8 +206,8 @@ class Pref_Filters extends Handler_Protected { } if ($line['action_id'] == 7) { - $label_result = db_query($this->link, "SELECT fg_color, bg_color - FROM ttrss_labels2 WHERE caption = '".db_escape_string($line['action_param'])."' AND + $label_result = db_query( "SELECT fg_color, bg_color + FROM ttrss_labels2 WHERE caption = '".db_escape_string( $line['action_param'])."' AND owner_uid = " . $_SESSION["uid"]); if (db_num_rows($label_result) > 0) { @@ -192,9 +231,11 @@ class Pref_Filters extends Handler_Protected { } } - if (count($folder['items']) > 0) { + /* if (count($folder['items']) > 0) { array_push($root['items'], $folder); - } + } */ + + $root['items'] = $folder['items']; $fl = array(); $fl['identifier'] = 'id'; @@ -207,13 +248,15 @@ class Pref_Filters extends Handler_Protected { function edit() { - $filter_id = db_escape_string($_REQUEST["id"]); + $filter_id = db_escape_string( $_REQUEST["id"]); - $result = db_query($this->link, + $result = db_query( "SELECT * FROM ttrss_filters2 WHERE id = '$filter_id' AND owner_uid = " . $_SESSION["uid"]); $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")); + $title = htmlspecialchars(db_fetch_result($result, 0, "title")); print "
"; @@ -222,6 +265,12 @@ class Pref_Filters extends Handler_Protected { print ""; print ""; + print "
".__("Caption")."
"; + + print ""; + + print ""; + print "
".__("Match")."
"; print "
"; @@ -245,7 +294,7 @@ class Pref_Filters extends Handler_Protected { print "