X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=classes%2Fpref%2Ffilters.php;h=170c1a5277bedd7fb378c23e27102e3cf019970a;hb=0d703c73bd27147c94e2c5a67eeb115f448fbd70;hp=c97628e51ffa90dde783b48cb4cd02a5d57039c0;hpb=0d6ecb1f1cc663497bdd8fccb3f2dc66d2cdb0b9;p=tt-rss.git diff --git a/classes/pref/filters.php b/classes/pref/filters.php index c97628e5..170c1a52 100644 --- a/classes/pref/filters.php +++ b/classes/pref/filters.php @@ -3,23 +3,62 @@ 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() { + $this->dbh->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) { + + $this->dbh->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($this->link, $_REQUEST["match_any_rule"]))); + checkbox_to_sql_bool($this->dbh->escape_string($_REQUEST["match_any_rule"]))); + $filter["inverse"] = sql_bool_to_bool( + checkbox_to_sql_bool($this->dbh->escape_string($_REQUEST["inverse"]))); + $filter["rules"] = array(); - $result = db_query($this->link, "SELECT id,name FROM ttrss_filter_types"); + $result = $this->dbh->query("SELECT id,name FROM ttrss_filter_types"); $filter_types = array(); - while ($line = db_fetch_assoc($result)) { + while ($line = $this->dbh->fetch_assoc($result)) { $filter_types[$line["id"]] = $line["name"]; } @@ -44,14 +83,11 @@ class Pref_Filters extends Handler_Protected { } } - $feed_title = getFeedTitle($this->link, $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]; - $articles = array(); $found = 0; print __("Articles matching this filter:"); @@ -59,13 +95,14 @@ class Pref_Filters extends Handler_Protected { print "
"; print ""; - while ($line = db_fetch_assoc($result)) { + while ($line = $this->dbh->fetch_assoc($result)) { + $line["content_preview"] = truncate_string(strip_tags($line["content"]), 100, '...'); - $entry_timestamp = strtotime($line["updated"]); - $entry_tags = get_article_tags($this->link, $line["id"], $_SESSION["uid"]); + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) { + $line = $p->hook_query_headlines($line, 100); + } - $content_preview = truncate_string( - strip_tags($line["content_preview"]), 100, '...'); + $content_preview = $line["content_preview"]; if ($line["feed_title"]) $feed_title = $line["feed_title"]; @@ -110,6 +147,40 @@ class Pref_Filters extends Handler_Protected { } + private function getfilterrules_concise($filter_id) { + $result = $this->dbh->query("SELECT reg_exp, + inverse, + feed_id, + cat_id, + cat_filter, + ttrss_filter_types.description AS field + FROM + ttrss_filters2_rules, ttrss_filter_types + WHERE + filter_id = '$filter_id' AND filter_type = ttrss_filter_types.id"); + + $rv = ""; + + while ($line = $this->dbh->fetch_assoc($result)) { + + $where = sql_bool_to_bool($line["cat_filter"]) ? + getCategoryTitle($line["cat_id"]) : + ($line["feed_id"] ? + getFeedTitle($line["feed_id"]) : __("All feeds")); + +# $where = $line["cat_id"] . "/" . $line["feed_id"]; + + $inverse = sql_bool_to_bool($line["inverse"]) ? "inverse" : ""; + + $rv .= "" . T_sprintf("%s on %s in %s %s", + strip_tags($line["reg_exp"]), + $line["field"], + $where, + sql_bool_to_bool($line["inverse"]) ? __("(inverse)") : "") . ""; + } + + return $rv; + } function getfiltertree() { $root = array(); @@ -119,7 +190,7 @@ class Pref_Filters extends Handler_Protected { $filter_search = $_SESSION["prefs_filter_search"]; - $result = db_query($this->link, "SELECT *, + $result = $this->dbh->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,35 +201,22 @@ 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; $folder = array(); $folder['items'] = array(); - while ($line = db_fetch_assoc($result)) { - - if ($action_id != $line["action_id"]) { - if (count($folder['items']) > 0) { - array_push($root['items'], $folder); - } - - $folder = array(); - $folder['id'] = $line["action_id"]; - $folder['name'] = __($line["action_name"]); - $folder['items'] = array(); - $action_id = $line["action_id"]; - } + while ($line = $this->dbh->fetch_assoc($result)) { $name = $this->getFilterName($line["id"]); $match_ok = false; if ($filter_search) { - $rules_result = db_query($this->link, + $rules_result = $this->dbh->query( "SELECT reg_exp FROM ttrss_filters2_rules WHERE filter_id = ".$line["id"]); - while ($rule_line = db_fetch_assoc($rules_result)) { + while ($rule_line = $this->dbh->fetch_assoc($rules_result)) { if (mb_strpos($rule_line['reg_exp'], $filter_search) !== false) { $match_ok = true; break; @@ -167,13 +225,13 @@ 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($this->link, $line['action_param'])."' AND + $label_result = $this->dbh->query("SELECT fg_color, bg_color + FROM ttrss_labels2 WHERE caption = '".$this->dbh->escape_string($line['action_param'])."' AND owner_uid = " . $_SESSION["uid"]); - if (db_num_rows($label_result) > 0) { - $fg_color = db_fetch_result($label_result, 0, "fg_color"); - $bg_color = db_fetch_result($label_result, 0, "bg_color"); + if ($this->dbh->num_rows($label_result) > 0) { + $fg_color = $this->dbh->fetch_result($label_result, 0, "fg_color"); + $bg_color = $this->dbh->fetch_result($label_result, 0, "bg_color"); $name[1] = "α" . $name[1]; } @@ -186,15 +244,18 @@ class Pref_Filters extends Handler_Protected { $filter['param'] = $name[1]; $filter['checkbox'] = false; $filter['enabled'] = sql_bool_to_bool($line["enabled"]); + $filter['rules'] = $this->getfilterrules_concise($line['id']); if (!$filter_search || $match_ok) { array_push($folder['items'], $filter); } } - 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 +268,15 @@ class Pref_Filters extends Handler_Protected { function edit() { - $filter_id = db_escape_string($this->link, $_REQUEST["id"]); + $filter_id = $this->dbh->escape_string($_REQUEST["id"]); - $result = db_query($this->link, + $result = $this->dbh->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")); + $enabled = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "enabled")); + $match_any_rule = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "match_any_rule")); + $inverse = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "inverse")); + $title = htmlspecialchars($this->dbh->fetch_result($result, 0, "title")); print ""; @@ -222,6 +285,12 @@ class Pref_Filters extends Handler_Protected { print ""; print ""; + print "
".__("Caption")."
"; + + print ""; + + print ""; + print "
".__("Match")."
"; print "
"; @@ -245,10 +314,10 @@ class Pref_Filters extends Handler_Protected { print "