]>
git.wh0rd.org - tt-rss.git/blob - classes/pref/filters.php
2 class Pref_Filters
extends Handler_Protected
{
4 function csrf_ignore($method) {
5 $csrf_ignored = array("index", "getfiltertree", "edit", "newfilter", "newrule",
8 return array_search($method, $csrf_ignored) !== false;
11 function testFilter() {
14 $filter["enabled"] = true;
15 $filter["match_any_rule"] = sql_bool_to_bool(
16 checkbox_to_sql_bool(db_escape_string($this->link
, $_REQUEST["match_any_rule"])));
17 $filter["inverse"] = sql_bool_to_bool(
18 checkbox_to_sql_bool(db_escape_string($this->link
, $_REQUEST["inverse"])));
20 $filter["rules"] = array();
22 $result = db_query($this->link
, "SELECT id,name FROM ttrss_filter_types");
24 $filter_types = array();
25 while ($line = db_fetch_assoc($result)) {
26 $filter_types[$line["id"]] = $line["name"];
30 foreach ($_REQUEST["rule"] AS $r) {
31 $rule = json_decode($r, true);
33 if ($rule && $rctr < 5) {
34 $rule["type"] = $filter_types[$rule["filter_type"]];
35 unset($rule["filter_type"]);
37 if (strpos($rule["feed_id"], "CAT:") === 0) {
38 $rule["cat_id"] = (int) substr($rule["feed_id"], 4);
39 unset($rule["feed_id"]);
42 array_push($filter["rules"], $rule);
50 $feed_title = getFeedTitle($this->link
, $feed);
52 $qfh_ret = queryFeedHeadlines($this->link
, -4, 30, "", false, false, false,
53 "date_entered DESC", 0, $_SESSION["uid"], $filter);
55 $result = $qfh_ret[0];
60 print __("Articles matching this filter:");
62 print "<div class=\"filterTestHolder\">";
63 print "<table width=\"100%\" cellspacing=\"0\" id=\"prefErrorFeedList\">";
65 while ($line = db_fetch_assoc($result)) {
67 $entry_timestamp = strtotime($line["updated"]);
68 $entry_tags = get_article_tags($this->link
, $line["id"], $_SESSION["uid"]);
70 $content_preview = truncate_string(
71 strip_tags($line["content_preview"]), 100, '...');
73 if ($line["feed_title"])
74 $feed_title = $line["feed_title"];
78 print "<td width='5%' align='center'><input
79 dojoType=\"dijit.form.CheckBox\" checked=\"1\"
80 disabled=\"1\" type=\"checkbox\"></td>";
85 print "<b>" . $feed_title . "</b>";
87 print "<span class=\"insensitive\">" . $content_preview . "</span>";
88 print " " . mb_substr($line["date_entered"], 0, 16);
96 print "<tr><td align='center'>" .
97 __("No recent articles matching this filter have been found.");
99 print "</td></tr><tr><td class='insensitive' align='center'>";
101 print __("Complex expressions might not give results while testing due to issues with database server regexp implementation.");
107 print "</table></div>";
109 print "<div style='text-align : center'>";
110 print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('filterTestDlg').hide()\">".
111 __('Close this window')."</button>";
117 function getfiltertree() {
119 $root['id'] = 'root';
120 $root['name'] = __('Filters');
121 $root['items'] = array();
123 $filter_search = $_SESSION["prefs_filter_search"];
125 $result = db_query($this->link
, "SELECT *,
126 (SELECT action_param FROM ttrss_filters2_actions
127 WHERE filter_id = ttrss_filters2.id ORDER BY id LIMIT 1) AS action_param,
128 (SELECT action_id FROM ttrss_filters2_actions
129 WHERE filter_id = ttrss_filters2.id ORDER BY id LIMIT 1) AS action_id,
130 (SELECT description FROM ttrss_filter_actions
131 WHERE id = (SELECT action_id FROM ttrss_filters2_actions
132 WHERE filter_id = ttrss_filters2.id ORDER BY id LIMIT 1)) AS action_name,
133 (SELECT reg_exp FROM ttrss_filters2_rules
134 WHERE filter_id = ttrss_filters2.id ORDER BY id LIMIT 1) AS reg_exp
135 FROM ttrss_filters2 WHERE
136 owner_uid = ".$_SESSION["uid"]." ORDER BY order_id");
141 $folder['items'] = array();
143 while ($line = db_fetch_assoc($result)) {
145 /* if ($action_id != $line["action_id"]) {
146 if (count($folder['items']) > 0) {
147 array_push($root['items'], $folder);
151 $folder['id'] = $line["action_id"];
152 $folder['name'] = __($line["action_name"]);
153 $folder['items'] = array();
154 $action_id = $line["action_id"];
157 $name = $this->getFilterName($line["id"]);
160 if ($filter_search) {
161 $rules_result = db_query($this->link
,
162 "SELECT reg_exp FROM ttrss_filters2_rules WHERE filter_id = ".$line["id"]);
164 while ($rule_line = db_fetch_assoc($rules_result)) {
165 if (mb_strpos($rule_line['reg_exp'], $filter_search) !== false) {
172 if ($line['action_id'] == 7) {
173 $label_result = db_query($this->link
, "SELECT fg_color, bg_color
174 FROM ttrss_labels2 WHERE caption = '".db_escape_string($this->link
, $line['action_param'])."' AND
175 owner_uid = " . $_SESSION["uid"]);
177 if (db_num_rows($label_result) > 0) {
178 $fg_color = db_fetch_result($label_result, 0, "fg_color");
179 $bg_color = db_fetch_result($label_result, 0, "bg_color");
181 $name[1] = "<span class=\"labelColorIndicator\" id=\"label-editor-indicator\" style='color : $fg_color; background-color : $bg_color; margin-right : 4px'>α</span>" . $name[1];
186 $filter['id'] = 'FILTER:' . $line['id'];
187 $filter['bare_id'] = $line['id'];
188 $filter['name'] = $name[0];
189 $filter['param'] = $name[1];
190 $filter['checkbox'] = false;
191 $filter['enabled'] = sql_bool_to_bool($line["enabled"]);
193 if (!$filter_search ||
$match_ok) {
194 array_push($folder['items'], $filter);
198 /* if (count($folder['items']) > 0) {
199 array_push($root['items'], $folder);
202 $root['items'] = $folder['items'];
205 $fl['identifier'] = 'id';
206 $fl['label'] = 'name';
207 $fl['items'] = array($root);
209 print json_encode($fl);
215 $filter_id = db_escape_string($this->link
, $_REQUEST["id"]);
217 $result = db_query($this->link
,
218 "SELECT * FROM ttrss_filters2 WHERE id = '$filter_id' AND owner_uid = " . $_SESSION["uid"]);
220 $enabled = sql_bool_to_bool(db_fetch_result($result, 0, "enabled"));
221 $match_any_rule = sql_bool_to_bool(db_fetch_result($result, 0, "match_any_rule"));
222 $inverse = sql_bool_to_bool(db_fetch_result($result, 0, "inverse"));
223 $title = htmlspecialchars(db_fetch_result($result, 0, "title"));
225 print "<form id=\"filter_edit_form\" onsubmit='return false'>";
227 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-filters\">";
228 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"id\" value=\"$filter_id\">";
229 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"editSave\">";
230 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"csrf_token\" value=\"".$_SESSION['csrf_token']."\">";
232 print "<div class=\"dlgSec\">".__("Caption")."</div>";
234 print "<input dojoType=\"dijit.form.TextBox\" style=\"width : 20em;\" name=\"title\" value=\"$title\">";
238 print "<div class=\"dlgSec\">".__("Match")."</div>";
240 print "<div dojoType=\"dijit.Toolbar\">";
242 print "<div dojoType=\"dijit.form.DropDownButton\">".
243 "<span>" . __('Select')."</span>";
244 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
245 print "<div onclick=\"dijit.byId('filterEditDlg').selectRules(true)\"
246 dojoType=\"dijit.MenuItem\">".__('All')."</div>";
247 print "<div onclick=\"dijit.byId('filterEditDlg').selectRules(false)\"
248 dojoType=\"dijit.MenuItem\">".__('None')."</div>";
249 print "</div></div>";
251 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').addRule()\">".
252 __('Add')."</button> ";
254 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').deleteRule()\">".
255 __('Delete')."</button> ";
259 print "<ul id='filterDlg_Matches'>";
261 $rules_result = db_query($this->link
, "SELECT * FROM ttrss_filters2_rules
262 WHERE filter_id = '$filter_id' ORDER BY reg_exp, id");
264 while ($line = db_fetch_assoc($rules_result)) {
265 if (sql_bool_to_bool($line["cat_filter"])) {
266 $line["feed_id"] = "CAT:" . (int)$line["cat_id"];
269 unset($line["cat_filter"]);
270 unset($line["cat_id"]);
271 unset($line["filter_id"]);
273 if (!sql_bool_to_bool($line["inverse"])) unset($line["inverse"]);
275 $data = htmlspecialchars(json_encode($line));
277 print "<li><input dojoType='dijit.form.CheckBox' type='checkbox' onclick='toggleSelectListRow2(this)'>".
278 "<span onclick=\"dijit.byId('filterEditDlg').editRule(this)\">".$this->getRuleName($line)."</span>".
279 "<input type='hidden' name='rule[]' value=\"$data\"/></li>";
286 print "<div class=\"dlgSec\">".__("Apply actions")."</div>";
288 print "<div dojoType=\"dijit.Toolbar\">";
290 print "<div dojoType=\"dijit.form.DropDownButton\">".
291 "<span>" . __('Select')."</span>";
292 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
293 print "<div onclick=\"dijit.byId('filterEditDlg').selectActions(true)\"
294 dojoType=\"dijit.MenuItem\">".__('All')."</div>";
295 print "<div onclick=\"dijit.byId('filterEditDlg').selectActions(false)\"
296 dojoType=\"dijit.MenuItem\">".__('None')."</div>";
297 print "</div></div>";
299 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').addAction()\">".
300 __('Add')."</button> ";
302 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').deleteAction()\">".
303 __('Delete')."</button> ";
307 print "<ul id='filterDlg_Actions'>";
309 $actions_result = db_query($this->link
, "SELECT * FROM ttrss_filters2_actions
310 WHERE filter_id = '$filter_id' ORDER BY id");
312 while ($line = db_fetch_assoc($actions_result)) {
313 $line["action_param_label"] = $line["action_param"];
315 unset($line["filter_id"]);
318 $data = htmlspecialchars(json_encode($line));
320 print "<li><input dojoType='dijit.form.CheckBox' type='checkbox' onclick='toggleSelectListRow2(this)'>".
321 "<span onclick=\"dijit.byId('filterEditDlg').editAction(this)\">".$this->getActionName($line)."</span>".
322 "<input type='hidden' name='action[]' value=\"$data\"/></li>";
330 $checked = "checked=\"1\"";
335 print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"enabled\" id=\"enabled\" $checked>
336 <label for=\"enabled\">".__('Enabled')."</label>";
338 if ($match_any_rule) {
339 $checked = "checked=\"1\"";
344 print "<br/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"match_any_rule\" id=\"match_any_rule\" $checked>
345 <label for=\"match_any_rule\">".__('Match any rule')."</label>";
348 $checked = "checked=\"1\"";
353 print "<br/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"inverse\" id=\"inverse\" $checked>
354 <label for=\"inverse\">".__('Inverse matching')."</label>";
358 print "<div class=\"dlgButtons\">";
360 print "<div style=\"float : left\">";
361 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').removeFilter()\">".
362 __('Remove')."</button>";
365 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').test()\">".
366 __('Test')."</button> ";
368 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').execute()\">".
369 __('Save')."</button> ";
371 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').hide()\">".
372 __('Cancel')."</button>";
377 private function getRuleName($rule) {
378 if (!$rule) $rule = json_decode($_REQUEST["rule"], true);
380 $feed_id = $rule["feed_id"];
382 if (strpos($feed_id, "CAT:") === 0) {
383 $feed_id = (int) substr($feed_id, 4);
384 $feed = getCategoryTitle($this->link
, $feed_id);
386 $feed_id = (int) $feed_id;
388 if ($rule["feed_id"])
389 $feed = getFeedTitle($this->link
, (int)$rule["feed_id"]);
391 $feed = __("All feeds");
394 $result = db_query($this->link
, "SELECT description FROM ttrss_filter_types
395 WHERE id = ".(int)$rule["filter_type"]);
396 $filter_type = db_fetch_result($result, 0, "description");
398 return T_sprintf("%s on %s in %s %s", strip_tags($rule["reg_exp"]),
399 $filter_type, $feed, isset($rule["inverse"]) ?
__("(inverse)") : "");
402 function printRuleName() {
403 print $this->getRuleName(json_decode($_REQUEST["rule"], true));
406 private function getActionName($action) {
407 $result = db_query($this->link
, "SELECT description FROM
408 ttrss_filter_actions WHERE id = " .(int)$action["action_id"]);
410 $title = __(db_fetch_result($result, 0, "description"));
412 if ($action["action_id"] == 4 ||
$action["action_id"] == 6 ||
413 $action["action_id"] == 7)
414 $title .= ": " . $action["action_param"];
419 function printActionName() {
420 print $this->getActionName(json_decode($_REQUEST["action"], true));
423 function editSave() {
424 if ($_REQUEST["savemode"] && $_REQUEST["savemode"] == "test") {
425 return $this->testFilter();
428 # print_r($_REQUEST);
430 $filter_id = db_escape_string($this->link
, $_REQUEST["id"]);
431 $enabled = checkbox_to_sql_bool(db_escape_string($this->link
, $_REQUEST["enabled"]));
432 $match_any_rule = checkbox_to_sql_bool(db_escape_string($this->link
, $_REQUEST["match_any_rule"]));
433 $inverse = checkbox_to_sql_bool(db_escape_string($this->link
, $_REQUEST["inverse"]));
434 $title = db_escape_string($this->link
, $_REQUEST["title"]);
436 $result = db_query($this->link
, "UPDATE ttrss_filters2 SET enabled = $enabled,
437 match_any_rule = $match_any_rule,
440 WHERE id = '$filter_id'
441 AND owner_uid = ". $_SESSION["uid"]);
443 $this->saveRulesAndActions($filter_id);
449 $ids = split(",", db_escape_string($this->link
, $_REQUEST["ids"]));
451 foreach ($ids as $id) {
452 db_query($this->link
, "DELETE FROM ttrss_filters2 WHERE id = '$id' AND owner_uid = ". $_SESSION["uid"]);
456 private function saveRulesAndActions($filter_id) {
458 db_query($this->link
, "DELETE FROM ttrss_filters2_rules WHERE filter_id = '$filter_id'");
459 db_query($this->link
, "DELETE FROM ttrss_filters2_actions WHERE filter_id = '$filter_id'");
467 foreach ($_REQUEST["rule"] as $rule) {
468 $rule = json_decode($rule, true);
471 if (array_search($rule, $rules) === false) {
472 array_push($rules, $rule);
476 foreach ($_REQUEST["action"] as $action) {
477 $action = json_decode($action, true);
478 unset($action["id"]);
480 if (array_search($action, $actions) === false) {
481 array_push($actions, $action);
485 foreach ($rules as $rule) {
488 $reg_exp = strip_tags(db_escape_string($this->link
, trim($rule["reg_exp"])));
489 $inverse = isset($rule["inverse"]) ?
"true" : "false";
491 $filter_type = (int) db_escape_string($this->link
, trim($rule["filter_type"]));
492 $feed_id = db_escape_string($this->link
, trim($rule["feed_id"]));
494 if (strpos($feed_id, "CAT:") === 0) {
496 $cat_filter = bool_to_sql_bool(true);
497 $cat_id = (int) substr($feed_id, 4);
500 if (!$cat_id) $cat_id = "NULL"; // Uncategorized
502 $cat_filter = bool_to_sql_bool(false);
503 $feed_id = (int) $feed_id;
506 if (!$feed_id) $feed_id = "NULL"; // Uncategorized
509 $query = "INSERT INTO ttrss_filters2_rules
510 (filter_id, reg_exp,filter_type,feed_id,cat_id,cat_filter,inverse) VALUES
511 ('$filter_id', '$reg_exp', '$filter_type', $feed_id, $cat_id, $cat_filter, $inverse)";
513 db_query($this->link
, $query);
517 foreach ($actions as $action) {
520 $action_id = (int) db_escape_string($this->link
, $action["action_id"]);
521 $action_param = db_escape_string($this->link
, $action["action_param"]);
522 $action_param_label = db_escape_string($this->link
, $action["action_param_label"]);
524 if ($action_id == 7) {
525 $action_param = $action_param_label;
528 if ($action_id == 6) {
529 $action_param = (int) str_replace("+", "", $action_param);
532 $query = "INSERT INTO ttrss_filters2_actions
533 (filter_id, action_id, action_param) VALUES
534 ('$filter_id', '$action_id', '$action_param')";
536 db_query($this->link
, $query);
545 if ($_REQUEST["savemode"] && $_REQUEST["savemode"] == "test") {
546 return $this->testFilter();
549 # print_r($_REQUEST);
551 $enabled = checkbox_to_sql_bool($_REQUEST["enabled"]);
552 $match_any_rule = checkbox_to_sql_bool($_REQUEST["match_any_rule"]);
553 $title = db_escape_string($this->link
, $_REQUEST["title"]);
555 db_query($this->link
, "BEGIN");
557 /* create base filter */
559 $result = db_query($this->link
, "INSERT INTO ttrss_filters2
560 (owner_uid, match_any_rule, enabled, title) VALUES
561 (".$_SESSION["uid"].",$match_any_rule,$enabled, '$title')");
563 $result = db_query($this->link
, "SELECT MAX(id) AS id FROM ttrss_filters2
564 WHERE owner_uid = ".$_SESSION["uid"]);
566 $filter_id = db_fetch_result($result, 0, "id");
568 $this->saveRulesAndActions($filter_id);
570 db_query($this->link
, "COMMIT");
575 $sort = db_escape_string($this->link
, $_REQUEST["sort"]);
577 if (!$sort ||
$sort == "undefined") {
581 $filter_search = db_escape_string($this->link
, $_REQUEST["search"]);
583 if (array_key_exists("search", $_REQUEST)) {
584 $_SESSION["prefs_filter_search"] = $filter_search;
586 $filter_search = $_SESSION["prefs_filter_search"];
589 print "<div id=\"pref-filter-wrap\" dojoType=\"dijit.layout.BorderContainer\" gutters=\"false\">";
590 print "<div id=\"pref-filter-header\" dojoType=\"dijit.layout.ContentPane\" region=\"top\">";
591 print "<div id=\"pref-filter-toolbar\" dojoType=\"dijit.Toolbar\">";
593 $filter_search = db_escape_string($this->link
, $_REQUEST["search"]);
595 if (array_key_exists("search", $_REQUEST)) {
596 $_SESSION["prefs_filter_search"] = $filter_search;
598 $filter_search = $_SESSION["prefs_filter_search"];
601 print "<div style='float : right; padding-right : 4px;'>
602 <input dojoType=\"dijit.form.TextBox\" id=\"filter_search\" size=\"20\" type=\"search\"
603 value=\"$filter_search\">
604 <button dojoType=\"dijit.form.Button\" onclick=\"updateFilterList()\">".
605 __('Search')."</button>
608 print "<div dojoType=\"dijit.form.DropDownButton\">".
609 "<span>" . __('Select')."</span>";
610 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
611 print "<div onclick=\"dijit.byId('filterTree').model.setAllChecked(true)\"
612 dojoType=\"dijit.MenuItem\">".__('All')."</div>";
613 print "<div onclick=\"dijit.byId('filterTree').model.setAllChecked(false)\"
614 dojoType=\"dijit.MenuItem\">".__('None')."</div>";
615 print "</div></div>";
617 print "<button dojoType=\"dijit.form.Button\" onclick=\"return quickAddFilter()\">".
618 __('Create filter')."</button> ";
620 print "<button dojoType=\"dijit.form.Button\" onclick=\"return joinSelectedFilters()\">".
621 __('Combine')."</button> ";
623 print "<button dojoType=\"dijit.form.Button\" onclick=\"return editSelectedFilter()\">".
624 __('Edit')."</button> ";
626 print "<button dojoType=\"dijit.form.Button\" onclick=\"return removeSelectedFilters()\">".
627 __('Remove')."</button> ";
629 if (defined('_ENABLE_FEED_DEBUGGING')) {
630 print "<button dojoType=\"dijit.form.Button\" onclick=\"rescore_all_feeds()\">".
631 __('Rescore articles')."</button> ";
634 print "</div>"; # toolbar
635 print "</div>"; # toolbar-frame
636 print "<div id=\"pref-filter-content\" dojoType=\"dijit.layout.ContentPane\" region=\"center\">";
638 print "<div id=\"filterlistLoading\">
639 <img src='images/indicator_tiny.gif'>".
640 __("Loading, please wait...")."</div>";
642 print "<div dojoType=\"dojo.data.ItemFileWriteStore\" jsId=\"filterStore\"
643 url=\"backend.php?op=pref-filters&method=getfiltertree\">
645 <div dojoType=\"lib.CheckBoxStoreModel\" jsId=\"filterModel\" store=\"filterStore\"
646 query=\"{id:'root'}\" rootId=\"root\" rootLabel=\"Feeds\"
647 childrenAttrs=\"items\" checkboxStrict=\"false\" checkboxAll=\"false\">
649 <div dojoType=\"fox.PrefFilterTree\" id=\"filterTree\"
650 model=\"filterModel\" openOnClick=\"true\">
651 <script type=\"dojo/method\" event=\"onLoad\" args=\"item\">
652 Element.hide(\"filterlistLoading\");
654 <script type=\"dojo/method\" event=\"onClick\" args=\"item\">
655 var id = String(item.id);
656 var bare_id = id.substr(id.indexOf(':')+1);
658 if (id.match('FILTER:')) {
665 print "</div>"; #pane
668 $pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB
,
669 "hook_prefs_tab", "prefFilters");
671 print "</div>"; #container
675 function newfilter() {
677 print "<form name='filter_new_form' id='filter_new_form'>";
679 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-filters\">";
680 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"add\">";
681 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"csrf_token\" value=\"".$_SESSION['csrf_token']."\">";
683 print "<div class=\"dlgSec\">".__("Caption")."</div>";
685 print "<input dojoType=\"dijit.form.TextBox\" style=\"width : 20em;\" name=\"title\" value=\"\">";
687 print "<div class=\"dlgSec\">".__("Match")."</div>";
689 print "<div dojoType=\"dijit.Toolbar\">";
691 print "<div dojoType=\"dijit.form.DropDownButton\">".
692 "<span>" . __('Select')."</span>";
693 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
694 print "<div onclick=\"dijit.byId('filterEditDlg').selectRules(true)\"
695 dojoType=\"dijit.MenuItem\">".__('All')."</div>";
696 print "<div onclick=\"dijit.byId('filterEditDlg').selectRules(false)\"
697 dojoType=\"dijit.MenuItem\">".__('None')."</div>";
698 print "</div></div>";
700 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').addRule()\">".
701 __('Add')."</button> ";
703 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').deleteRule()\">".
704 __('Delete')."</button> ";
708 print "<ul id='filterDlg_Matches'>";
709 # print "<li>No rules</li>";
714 print "<div class=\"dlgSec\">".__("Apply actions")."</div>";
716 print "<div dojoType=\"dijit.Toolbar\">";
718 print "<div dojoType=\"dijit.form.DropDownButton\">".
719 "<span>" . __('Select')."</span>";
720 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
721 print "<div onclick=\"dijit.byId('filterEditDlg').selectActions(true)\"
722 dojoType=\"dijit.MenuItem\">".__('All')."</div>";
723 print "<div onclick=\"dijit.byId('filterEditDlg').selectActions(false)\"
724 dojoType=\"dijit.MenuItem\">".__('None')."</div>";
725 print "</div></div>";
727 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').addAction()\">".
728 __('Add')."</button> ";
730 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').deleteAction()\">".
731 __('Delete')."</button> ";
735 print "<ul id='filterDlg_Actions'>";
736 # print "<li>No actions</li>";
739 /* print "<div class=\"dlgSec\">".__("Options")."</div>";
740 print "<div class=\"dlgSecCont\">"; */
742 print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"enabled\" id=\"enabled\" checked=\"1\">
743 <label for=\"enabled\">".__('Enabled')."</label>";
745 print "<br/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"match_any_rule\" id=\"match_any_rule\">
746 <label for=\"match_any_rule\">".__('Match any rule')."</label>";
748 print "<br/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"inverse\" id=\"inverse\">
749 <label for=\"inverse\">".__('Inverse matching')."</label>";
753 print "<div class=\"dlgButtons\">";
755 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').test()\">".
756 __('Test')."</button> ";
758 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').execute()\">".
759 __('Create')."</button> ";
761 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').hide()\">".
762 __('Cancel')."</button>";
769 $rule = json_decode($_REQUEST["rule"], true);
772 $reg_exp = htmlspecialchars($rule["reg_exp"]);
773 $filter_type = $rule["filter_type"];
774 $feed_id = $rule["feed_id"];
775 $inverse_checked = isset($rule["inverse"]) ?
"checked" : "";
780 $inverse_checked = "";
783 if (strpos($feed_id, "CAT:") === 0) {
784 $feed_id = substr($feed_id, 4);
791 print "<form name='filter_new_rule_form' id='filter_new_rule_form'>";
793 $result = db_query($this->link
, "SELECT id,description
794 FROM ttrss_filter_types WHERE id != 5 ORDER BY description");
796 $filter_types = array();
798 while ($line = db_fetch_assoc($result)) {
799 $filter_types[$line["id"]] = __($line["description"]);
802 print "<div class=\"dlgSec\">".__("Match")."</div>";
804 print "<div class=\"dlgSecCont\">";
806 print "<input dojoType=\"dijit.form.ValidationTextBox\"
807 required=\"true\" id=\"filterDlg_regExp\"
808 style=\"font-size : 16px; width : 20em;\"
809 name=\"reg_exp\" value=\"$reg_exp\"/>";
812 print "<input id=\"filterDlg_inverse\" dojoType=\"dijit.form.CheckBox\"
813 name=\"inverse\" $inverse_checked/>";
814 print "<label for=\"filterDlg_inverse\">".__("Inverse regular expression matching")."</label>";
816 print "<hr/>" . __("on field") . " ";
817 print_select_hash("filter_type", $filter_type, $filter_types,
818 'dojoType="dijit.form.Select"');
822 print __("in") . " ";
824 print "<span id='filterDlg_feeds'>";
825 print_feed_select($this->link
, "feed_id",
826 $cat_filter ?
"CAT:$feed_id" : $feed_id,
827 'dojoType="dijit.form.FilteringSelect"');
832 print "<div class=\"dlgButtons\">";
834 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterNewRuleDlg').execute()\">".
835 ($rule ?
__("Save rule") : __('Add rule'))."</button> ";
837 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterNewRuleDlg').hide()\">".
838 __('Cancel')."</button>";
845 function newaction() {
846 $action = json_decode($_REQUEST["action"], true);
849 $action_param = db_escape_string($this->link
, $action["action_param"]);
850 $action_id = (int)$action["action_id"];
856 print "<form name='filter_new_action_form' id='filter_new_action_form'>";
858 print "<div class=\"dlgSec\">".__("Perform Action")."</div>";
860 print "<div class=\"dlgSecCont\">";
862 print "<select name=\"action_id\" dojoType=\"dijit.form.Select\"
863 onchange=\"filterDlgCheckAction(this)\">";
865 $result = db_query($this->link
, "SELECT id,description FROM ttrss_filter_actions
868 while ($line = db_fetch_assoc($result)) {
869 $is_selected = ($line["id"] == $action_id) ?
"selected='1'" : "";
870 printf("<option $is_selected value='%d'>%s</option>", $line["id"], __($line["description"]));
875 $param_box_hidden = ($action_id == 7 ||
$action_id == 4 ||
$action_id == 6) ?
876 "" : "display : none";
878 $param_hidden = ($action_id == 4 ||
$action_id == 6) ?
879 "" : "display : none";
881 $label_param_hidden = ($action_id == 7) ?
"" : "display : none";
883 print "<span id=\"filterDlg_paramBox\" style=\"$param_box_hidden\">";
884 print " " . __("with parameters:") . " ";
885 print "<input dojoType=\"dijit.form.TextBox\"
886 id=\"filterDlg_actionParam\" style=\"$param_hidden\"
887 name=\"action_param\" value=\"$action_param\">";
889 print_label_select($this->link
, "action_param_label", $action_param,
890 "id=\"filterDlg_actionParamLabel\" style=\"$label_param_hidden\"
891 dojoType=\"dijit.form.Select\"");
895 print " "; // tiny layout hack
899 print "<div class=\"dlgButtons\">";
901 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterNewActionDlg').execute()\">".
902 ($action ?
__("Save action") : __('Add action'))."</button> ";
904 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterNewActionDlg').hide()\">".
905 __('Cancel')."</button>";
912 private function getFilterName($id) {
914 $result = db_query($this->link
,
915 "SELECT title FROM ttrss_filters2 WHERE id = '$id'");
917 $title = db_fetch_result($result, 0, "title");
921 $result = db_query($this->link
,
922 "SELECT * FROM ttrss_filters2_rules WHERE filter_id = '$id' ORDER BY id
928 while ($line = db_fetch_assoc($result)) {
930 if (sql_bool_to_bool($line["cat_filter"])) {
931 unset($line["cat_filter"]);
932 $line["feed_id"] = "CAT:" . (int)$line["cat_id"];
933 unset($line["cat_id"]);
936 if (!sql_bool_to_bool($line["inverse"])) unset($line["inverse"]);
939 array_push($titles, $this->getRuleName($line));
941 array_push($titles, "...");
947 $title = truncate_string(join(", ", $titles), 64, "...");
951 $result = db_query($this->link
,
952 "SELECT * FROM ttrss_filters2_actions WHERE filter_id = '$id' ORDER BY id LIMIT 3");
957 while ($line = db_fetch_assoc($result)) {
959 array_push($actions, $this->getActionName($line));
961 array_push($actions, "...");
967 return array($title, join(", ", $actions));
971 $ids = explode(",", db_escape_string($this->link
, $_REQUEST["ids"]));
973 if (count($ids) > 1) {
974 $base_id = array_shift($ids);
975 $ids_str = join(",", $ids);
977 db_query($this->link
, "BEGIN");
978 db_query($this->link
, "UPDATE ttrss_filters2_rules
979 SET filter_id = '$base_id' WHERE filter_id IN ($ids_str)");
980 db_query($this->link
, "UPDATE ttrss_filters2_actions
981 SET filter_id = '$base_id' WHERE filter_id IN ($ids_str)");
983 db_query($this->link
, "DELETE FROM ttrss_filters2 WHERE id IN ($ids_str)");
984 db_query($this->link
, "UPDATE ttrss_filters2 SET match_any_rule = true WHERE id = '$base_id'");
986 db_query($this->link
, "COMMIT");
988 $this->optimizeFilter($base_id);
993 private function optimizeFilter($id) {
994 db_query($this->link
, "BEGIN");
995 $result = db_query($this->link
, "SELECT * FROM ttrss_filters2_actions
996 WHERE filter_id = '$id'");
1001 while ($line = db_fetch_assoc($result)) {
1005 if (array_search($line, $tmp) === false) {
1006 array_push($tmp, $line);
1008 array_push($dupe_ids, $id);
1012 if (count($dupe_ids) > 0) {
1013 $ids_str = join(",", $dupe_ids);
1014 db_query($this->link
, "DELETE FROM ttrss_filters2_actions
1015 WHERE id IN ($ids_str)");
1018 $result = db_query($this->link
, "SELECT * FROM ttrss_filters2_rules
1019 WHERE filter_id = '$id'");
1022 $dupe_ids = array();
1024 while ($line = db_fetch_assoc($result)) {
1028 if (array_search($line, $tmp) === false) {
1029 array_push($tmp, $line);
1031 array_push($dupe_ids, $id);
1035 if (count($dupe_ids) > 0) {
1036 $ids_str = join(",", $dupe_ids);
1037 db_query($this->link
, "DELETE FROM ttrss_filters2_rules
1038 WHERE id IN ($ids_str)");
1041 db_query($this->link
, "COMMIT");