]>
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($_REQUEST["match_any_rule"])));
17 $filter["rules"] = array();
19 $result = db_query($this->link
, "SELECT id,name FROM ttrss_filter_types");
21 $filter_types = array();
22 while ($line = db_fetch_assoc($result)) {
23 $filter_types[$line["id"]] = $line["name"];
27 foreach ($_REQUEST["rule"] AS $r) {
28 $rule = json_decode($r, true);
30 if ($rule && $rctr < 5) {
31 $rule["type"] = $filter_types[$rule["filter_type"]];
32 unset($rule["filter_type"]);
34 if (strpos($rule["feed_id"], "CAT:") === 0) {
35 $rule["cat_id"] = (int) substr($rule["feed_id"], 4);
36 unset($rule["feed_id"]);
39 array_push($filter["rules"], $rule);
47 $feed_title = getFeedTitle($this->link
, $feed);
49 $qfh_ret = queryFeedHeadlines($this->link
, -4, 30, "", false, false, false,
50 false, "date_entered DESC", 0, $_SESSION["uid"], $filter);
52 $result = $qfh_ret[0];
57 print __("Articles matching this filter:");
59 print "<div class=\"filterTestHolder\">";
60 print "<table width=\"100%\" cellspacing=\"0\" id=\"prefErrorFeedList\">";
62 while ($line = db_fetch_assoc($result)) {
64 $entry_timestamp = strtotime($line["updated"]);
65 $entry_tags = get_article_tags($this->link
, $line["id"], $_SESSION["uid"]);
67 $content_preview = truncate_string(
68 strip_tags($line["content_preview"]), 100, '...');
70 if ($line["feed_title"])
71 $feed_title = $line["feed_title"];
75 print "<td width='5%' align='center'><input
76 dojoType=\"dijit.form.CheckBox\" checked=\"1\"
77 disabled=\"1\" type=\"checkbox\"></td>";
82 print "<b>" . $feed_title . "</b>";
84 print "<span class=\"insensitive\">" . $content_preview . "</span>";
85 print " " . mb_substr($line["date_entered"], 0, 16);
93 print "<tr><td align='center'>" .
94 __("No recent articles matching this filter have been found.") . "</td></tr>";
97 print "</table></div>";
99 print "<div style='text-align : center'>";
100 print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('filterTestDlg').hide()\">".
101 __('Close this window')."</button>";
107 function getfiltertree() {
109 $root['id'] = 'root';
110 $root['name'] = __('Filters');
111 $root['items'] = array();
113 $filter_search = $_SESSION["prefs_filter_search"];
115 $result = db_query($this->link
, "SELECT *,
116 (SELECT action_param FROM ttrss_filters2_actions
117 WHERE filter_id = ttrss_filters2.id ORDER BY id LIMIT 1) AS action_param,
118 (SELECT action_id FROM ttrss_filters2_actions
119 WHERE filter_id = ttrss_filters2.id ORDER BY id LIMIT 1) AS action_id,
120 (SELECT description FROM ttrss_filter_actions
121 WHERE id = (SELECT action_id FROM ttrss_filters2_actions
122 WHERE filter_id = ttrss_filters2.id ORDER BY id LIMIT 1)) AS action_name,
123 (SELECT reg_exp FROM ttrss_filters2_rules
124 WHERE filter_id = ttrss_filters2.id ORDER BY id LIMIT 1) AS reg_exp
125 FROM ttrss_filters2 WHERE
126 owner_uid = ".$_SESSION["uid"]." ORDER BY action_id,reg_exp");
131 $folder['items'] = array();
133 while ($line = db_fetch_assoc($result)) {
135 if ($action_id != $line["action_id"]) {
136 if (count($folder['items']) > 0) {
137 array_push($root['items'], $folder);
141 $folder['id'] = $line["action_id"];
142 $folder['name'] = $line["action_name"];
143 $folder['items'] = array();
144 $action_id = $line["action_id"];
147 $name = $this->getFilterName($line["id"]);
150 if ($filter_search) {
151 $rules_result = db_query($this->link
,
152 "SELECT reg_exp FROM ttrss_filters2_rules WHERE filter_id = ".$line["id"]);
154 while ($rule_line = db_fetch_assoc($rules_result)) {
155 if (mb_strpos($rule_line['reg_exp'], $filter_search) !== false) {
162 if ($line['action_id'] == 7) {
163 $label_result = db_query($this->link
, "SELECT fg_color, bg_color
164 FROM ttrss_labels2 WHERE caption = '".db_escape_string($line['action_param'])."' AND
165 owner_uid = " . $_SESSION["uid"]);
167 if (db_num_rows($label_result) > 0) {
168 $fg_color = db_fetch_result($label_result, 0, "fg_color");
169 $bg_color = db_fetch_result($label_result, 0, "bg_color");
171 $name[1] = "<span class=\"labelColorIndicator\" id=\"label-editor-indicator\" style='color : $fg_color; background-color : $bg_color; margin-right : 4px'>α</span>" . $name[1];
176 $filter['id'] = 'FILTER:' . $line['id'];
177 $filter['bare_id'] = $line['id'];
178 $filter['name'] = $name[0];
179 $filter['param'] = $name[1];
180 $filter['checkbox'] = false;
181 $filter['enabled'] = sql_bool_to_bool($line["enabled"]);
183 if (!$filter_search ||
$match_ok) {
184 array_push($folder['items'], $filter);
188 if (count($folder['items']) > 0) {
189 array_push($root['items'], $folder);
193 $fl['identifier'] = 'id';
194 $fl['label'] = 'name';
195 $fl['items'] = array($root);
197 print json_encode($fl);
203 $filter_id = db_escape_string($_REQUEST["id"]);
205 $result = db_query($this->link
,
206 "SELECT * FROM ttrss_filters2 WHERE id = '$filter_id' AND owner_uid = " . $_SESSION["uid"]);
208 $enabled = sql_bool_to_bool(db_fetch_result($result, 0, "enabled"));
209 $match_any_rule = sql_bool_to_bool(db_fetch_result($result, 0, "match_any_rule"));
211 print "<form id=\"filter_edit_form\" onsubmit='return false'>";
213 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-filters\">";
214 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"id\" value=\"$filter_id\">";
215 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"editSave\">";
216 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"csrf_token\" value=\"".$_SESSION['csrf_token']."\">";
218 print "<div class=\"dlgSec\">".__("Match")."</div>";
220 print "<div dojoType=\"dijit.Toolbar\">";
222 print "<div dojoType=\"dijit.form.DropDownButton\">".
223 "<span>" . __('Select')."</span>";
224 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
225 print "<div onclick=\"dijit.byId('filterEditDlg').selectRules(true)\"
226 dojoType=\"dijit.MenuItem\">".__('All')."</div>";
227 print "<div onclick=\"dijit.byId('filterEditDlg').selectRules(false)\"
228 dojoType=\"dijit.MenuItem\">".__('None')."</div>";
229 print "</div></div>";
231 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').addRule()\">".
232 __('Add')."</button> ";
234 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').deleteRule()\">".
235 __('Delete')."</button> ";
239 print "<ul id='filterDlg_Matches'>";
241 $rules_result = db_query($this->link
, "SELECT * FROM ttrss_filters2_rules
242 WHERE filter_id = '$filter_id' ORDER BY reg_exp, id");
244 while ($line = db_fetch_assoc($rules_result)) {
245 if (sql_bool_to_bool($line["cat_filter"])) {
246 $line["feed_id"] = "CAT:" . (int)$line["cat_id"];
249 unset($line["cat_filter"]);
250 unset($line["cat_id"]);
251 unset($line["filter_id"]);
254 $data = htmlspecialchars(json_encode($line));
256 print "<li><input dojoType='dijit.form.CheckBox' type='checkbox' onclick='toggleSelectListRow2(this)'>".
257 "<span onclick=\"dijit.byId('filterEditDlg').editRule(this)\">".$this->getRuleName($line)."</span>".
258 "<input type='hidden' name='rule[]' value=\"$data\"/></li>";
265 print "<div class=\"dlgSec\">".__("Apply actions")."</div>";
267 print "<div dojoType=\"dijit.Toolbar\">";
269 print "<div dojoType=\"dijit.form.DropDownButton\">".
270 "<span>" . __('Select')."</span>";
271 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
272 print "<div onclick=\"dijit.byId('filterEditDlg').selectActions(true)\"
273 dojoType=\"dijit.MenuItem\">".__('All')."</div>";
274 print "<div onclick=\"dijit.byId('filterEditDlg').selectActions(false)\"
275 dojoType=\"dijit.MenuItem\">".__('None')."</div>";
276 print "</div></div>";
278 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').addAction()\">".
279 __('Add')."</button> ";
281 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').deleteAction()\">".
282 __('Delete')."</button> ";
286 print "<ul id='filterDlg_Actions'>";
288 $actions_result = db_query($this->link
, "SELECT * FROM ttrss_filters2_actions
289 WHERE filter_id = '$filter_id' ORDER BY id");
291 while ($line = db_fetch_assoc($actions_result)) {
292 $line["action_param_label"] = $line["action_param"];
294 unset($line["filter_id"]);
297 $data = htmlspecialchars(json_encode($line));
299 print "<li><input dojoType='dijit.form.CheckBox' type='checkbox' onclick='toggleSelectListRow2(this)'>".
300 "<span onclick=\"dijit.byId('filterEditDlg').editAction(this)\">".$this->getActionName($line)."</span>".
301 "<input type='hidden' name='action[]' value=\"$data\"/></li>";
309 $checked = "checked=\"1\"";
314 print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"enabled\" id=\"enabled\" $checked>
315 <label for=\"enabled\">".__('Enabled')."</label>";
317 if ($match_any_rule) {
318 $checked = "checked=\"1\"";
323 print "<br/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"match_any_rule\" id=\"match_any_rule\" $checked>
324 <label for=\"match_any_rule\">".__('Match any rule')."</label>";
328 print "<div class=\"dlgButtons\">";
330 print "<div style=\"float : left\">";
331 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').removeFilter()\">".
332 __('Remove')."</button>";
335 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').test()\">".
336 __('Test')."</button> ";
338 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').execute()\">".
339 __('Save')."</button> ";
341 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').hide()\">".
342 __('Cancel')."</button>";
347 private function getRuleName($rule) {
348 if (!$rule) $rule = json_decode($_REQUEST["rule"], true);
350 $feed_id = $rule["feed_id"];
352 if (strpos($feed_id, "CAT:") === 0) {
353 $feed_id = (int) substr($feed_id, 4);
354 $feed = getCategoryTitle($this->link
, $feed_id);
356 $feed_id = (int) $feed_id;
358 if ($rule["feed_id"])
359 $feed = getFeedTitle($this->link
, (int)$rule["feed_id"]);
361 $feed = __("All feeds");
364 $result = db_query($this->link
, "SELECT description FROM ttrss_filter_types
365 WHERE id = ".(int)$rule["filter_type"]);
366 $match_on = db_fetch_result($result, 0, "description");
368 return T_sprintf("%s on %s in %s", $rule["reg_exp"], $match_on, $feed);
371 function printRuleName() {
372 print $this->getRuleName(json_decode($_REQUEST["rule"], true));
375 private function getActionName($action) {
376 $result = db_query($this->link
, "SELECT description FROM
377 ttrss_filter_actions WHERE id = " .(int)$action["action_id"]);
379 $title = __(db_fetch_result($result, 0, "description"));
381 if ($action["action_id"] == 4 ||
$action["action_id"] == 6 ||
382 $action["action_id"] == 7)
383 $title .= ": " . $action["action_param"];
388 function printActionName() {
389 print $this->getActionName(json_decode($_REQUEST["action"], true));
392 function editSave() {
393 if ($_REQUEST["savemode"] && $_REQUEST["savemode"] == "test") {
394 return $this->testFilter();
397 # print_r($_REQUEST);
399 $filter_id = db_escape_string($_REQUEST["id"]);
400 $enabled = checkbox_to_sql_bool(db_escape_string($_REQUEST["enabled"]));
401 $match_any_rule = checkbox_to_sql_bool(db_escape_string($_REQUEST["match_any_rule"]));
403 $result = db_query($this->link
, "UPDATE ttrss_filters2 SET enabled = $enabled,
404 match_any_rule = $match_any_rule
405 WHERE id = '$filter_id'
406 AND owner_uid = ". $_SESSION["uid"]);
408 $this->saveRulesAndActions($filter_id);
414 $ids = split(",", db_escape_string($_REQUEST["ids"]));
416 foreach ($ids as $id) {
417 db_query($this->link
, "DELETE FROM ttrss_filters2 WHERE id = '$id' AND owner_uid = ". $_SESSION["uid"]);
421 private function saveRulesAndActions($filter_id) {
423 db_query($this->link
, "DELETE FROM ttrss_filters2_rules WHERE filter_id = '$filter_id'");
424 db_query($this->link
, "DELETE FROM ttrss_filters2_actions WHERE filter_id = '$filter_id'");
432 foreach ($_REQUEST["rule"] as $rule) {
433 $rule = json_decode($rule, true);
436 if (array_search($rule, $rules) === false) {
437 array_push($rules, $rule);
441 foreach ($_REQUEST["action"] as $action) {
442 $action = json_decode($action, true);
443 unset($action["id"]);
445 if (array_search($action, $actions) === false) {
446 array_push($actions, $action);
450 foreach ($rules as $rule) {
453 $reg_exp = strip_tags(db_escape_string(trim($rule["reg_exp"])));
454 $filter_type = (int) db_escape_string(trim($rule["filter_type"]));
455 $feed_id = db_escape_string(trim($rule["feed_id"]));
457 if (strpos($feed_id, "CAT:") === 0) {
459 $cat_filter = bool_to_sql_bool(true);
460 $cat_id = (int) substr($feed_id, 4);
463 if (!$cat_id) $cat_id = "NULL"; // Uncategorized
465 $cat_filter = bool_to_sql_bool(false);
466 $feed_id = (int) $feed_id;
469 if (!$feed_id) $feed_id = "NULL"; // Uncategorized
472 $query = "INSERT INTO ttrss_filters2_rules
473 (filter_id, reg_exp,filter_type,feed_id,cat_id,cat_filter) VALUES
474 ('$filter_id', '$reg_exp', '$filter_type', $feed_id, $cat_id, $cat_filter)";
476 db_query($this->link
, $query);
480 foreach ($actions as $action) {
483 $action_id = (int) db_escape_string($action["action_id"]);
484 $action_param = db_escape_string($action["action_param"]);
485 $action_param_label = db_escape_string($action["action_param_label"]);
487 if ($action_id == 7) {
488 $action_param = $action_param_label;
491 if ($action_id == 6) {
492 $action_param = (int) str_replace("+", "", $action_param);
495 $query = "INSERT INTO ttrss_filters2_actions
496 (filter_id, action_id, action_param) VALUES
497 ('$filter_id', '$action_id', '$action_param')";
499 db_query($this->link
, $query);
508 if ($_REQUEST["savemode"] && $_REQUEST["savemode"] == "test") {
509 return $this->testFilter();
512 # print_r($_REQUEST);
514 $enabled = checkbox_to_sql_bool($_REQUEST["enabled"]);
515 $match_any_rule = checkbox_to_sql_bool($_REQUEST["match_any_rule"]);
517 db_query($this->link
, "BEGIN");
519 /* create base filter */
521 $result = db_query($this->link
, "INSERT INTO ttrss_filters2
522 (owner_uid, match_any_rule, enabled) VALUES
523 (".$_SESSION["uid"].",$match_any_rule,$enabled)");
525 $result = db_query($this->link
, "SELECT MAX(id) AS id FROM ttrss_filters2
526 WHERE owner_uid = ".$_SESSION["uid"]);
528 $filter_id = db_fetch_result($result, 0, "id");
530 $this->saveRulesAndActions($filter_id);
532 db_query($this->link
, "COMMIT");
537 $sort = db_escape_string($_REQUEST["sort"]);
539 if (!$sort ||
$sort == "undefined") {
543 $filter_search = db_escape_string($_REQUEST["search"]);
545 if (array_key_exists("search", $_REQUEST)) {
546 $_SESSION["prefs_filter_search"] = $filter_search;
548 $filter_search = $_SESSION["prefs_filter_search"];
551 print "<div id=\"pref-filter-wrap\" dojoType=\"dijit.layout.BorderContainer\" gutters=\"false\">";
552 print "<div id=\"pref-filter-header\" dojoType=\"dijit.layout.ContentPane\" region=\"top\">";
553 print "<div id=\"pref-filter-toolbar\" dojoType=\"dijit.Toolbar\">";
555 $filter_search = db_escape_string($_REQUEST["search"]);
557 if (array_key_exists("search", $_REQUEST)) {
558 $_SESSION["prefs_filter_search"] = $filter_search;
560 $filter_search = $_SESSION["prefs_filter_search"];
563 print "<div style='float : right; padding-right : 4px;'>
564 <input dojoType=\"dijit.form.TextBox\" id=\"filter_search\" size=\"20\" type=\"search\"
565 value=\"$filter_search\">
566 <button dojoType=\"dijit.form.Button\" onclick=\"updateFilterList()\">".
567 __('Search')."</button>
570 print "<div dojoType=\"dijit.form.DropDownButton\">".
571 "<span>" . __('Select')."</span>";
572 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
573 print "<div onclick=\"dijit.byId('filterTree').model.setAllChecked(true)\"
574 dojoType=\"dijit.MenuItem\">".__('All')."</div>";
575 print "<div onclick=\"dijit.byId('filterTree').model.setAllChecked(false)\"
576 dojoType=\"dijit.MenuItem\">".__('None')."</div>";
577 print "</div></div>";
579 print "<button dojoType=\"dijit.form.Button\" onclick=\"return quickAddFilter()\">".
580 __('Create filter')."</button> ";
582 print "<button dojoType=\"dijit.form.Button\" onclick=\"return joinSelectedFilters()\">".
583 __('Combine')."</button> ";
585 print "<button dojoType=\"dijit.form.Button\" onclick=\"return editSelectedFilter()\">".
586 __('Edit')."</button> ";
588 print "<button dojoType=\"dijit.form.Button\" onclick=\"return removeSelectedFilters()\">".
589 __('Remove')."</button> ";
591 if (defined('_ENABLE_FEED_DEBUGGING')) {
592 print "<button dojoType=\"dijit.form.Button\" onclick=\"rescore_all_feeds()\">".
593 __('Rescore articles')."</button> ";
596 print "</div>"; # toolbar
597 print "</div>"; # toolbar-frame
598 print "<div id=\"pref-filter-content\" dojoType=\"dijit.layout.ContentPane\" region=\"center\">";
600 print "<div id=\"filterlistLoading\">
601 <img src='images/indicator_tiny.gif'>".
602 __("Loading, please wait...")."</div>";
604 print "<div dojoType=\"dojo.data.ItemFileWriteStore\" jsId=\"filterStore\"
605 url=\"backend.php?op=pref-filters&method=getfiltertree\">
607 <div dojoType=\"lib.CheckBoxStoreModel\" jsId=\"filterModel\" store=\"filterStore\"
608 query=\"{id:'root'}\" rootId=\"root\" rootLabel=\"Feeds\"
609 childrenAttrs=\"items\" checkboxStrict=\"false\" checkboxAll=\"false\">
611 <div dojoType=\"fox.PrefFilterTree\" id=\"filterTree\"
612 model=\"filterModel\" openOnClick=\"true\">
613 <script type=\"dojo/method\" event=\"onLoad\" args=\"item\">
614 Element.hide(\"filterlistLoading\");
616 <script type=\"dojo/method\" event=\"onClick\" args=\"item\">
617 var id = String(item.id);
618 var bare_id = id.substr(id.indexOf(':')+1);
620 if (id.match('FILTER:')) {
627 print "</div>"; #pane
628 print "</div>"; #container
632 function newfilter() {
634 print "<form name='filter_new_form' id='filter_new_form'>";
636 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-filters\">";
637 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"add\">";
638 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"csrf_token\" value=\"".$_SESSION['csrf_token']."\">";
640 print "<div class=\"dlgSec\">".__("Match")."</div>";
642 print "<div dojoType=\"dijit.Toolbar\">";
644 print "<div dojoType=\"dijit.form.DropDownButton\">".
645 "<span>" . __('Select')."</span>";
646 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
647 print "<div onclick=\"dijit.byId('filterEditDlg').selectRules(true)\"
648 dojoType=\"dijit.MenuItem\">".__('All')."</div>";
649 print "<div onclick=\"dijit.byId('filterEditDlg').selectRules(false)\"
650 dojoType=\"dijit.MenuItem\">".__('None')."</div>";
651 print "</div></div>";
653 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').addRule()\">".
654 __('Add')."</button> ";
656 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').deleteRule()\">".
657 __('Delete')."</button> ";
661 print "<ul id='filterDlg_Matches'>";
662 # print "<li>No rules</li>";
667 print "<div class=\"dlgSec\">".__("Apply actions")."</div>";
669 print "<div dojoType=\"dijit.Toolbar\">";
671 print "<div dojoType=\"dijit.form.DropDownButton\">".
672 "<span>" . __('Select')."</span>";
673 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
674 print "<div onclick=\"dijit.byId('filterEditDlg').selectActions(true)\"
675 dojoType=\"dijit.MenuItem\">".__('All')."</div>";
676 print "<div onclick=\"dijit.byId('filterEditDlg').selectActions(false)\"
677 dojoType=\"dijit.MenuItem\">".__('None')."</div>";
678 print "</div></div>";
680 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').addAction()\">".
681 __('Add')."</button> ";
683 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').deleteAction()\">".
684 __('Delete')."</button> ";
688 print "<ul id='filterDlg_Actions'>";
689 # print "<li>No actions</li>";
692 /* print "<div class=\"dlgSec\">".__("Options")."</div>";
693 print "<div class=\"dlgSecCont\">"; */
695 print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"enabled\" id=\"enabled\" checked=\"1\">
696 <label for=\"enabled\">".__('Enabled')."</label>";
698 print "<br/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"match_any_rule\" id=\"match_any_rule\">
699 <label for=\"match_any_rule\">".__('Match any rule')."</label>";
703 /* print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"inverse\" id=\"inverse\">
704 <label for=\"inverse\">".__('Inverse match')."</label><hr/>"; */
708 print "<div class=\"dlgButtons\">";
710 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').test()\">".
711 __('Test')."</button> ";
713 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').execute()\">".
714 __('Create')."</button> ";
716 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').hide()\">".
717 __('Cancel')."</button>";
724 $rule = json_decode($_REQUEST["rule"], true);
727 $reg_exp = htmlspecialchars($rule["reg_exp"]);
728 $filter_type = $rule["filter_type"];
729 $feed_id = $rule["feed_id"];
736 if (strpos($feed_id, "CAT:") === 0) {
737 $feed_id = substr($feed_id, 4);
744 print "<form name='filter_new_rule_form' id='filter_new_rule_form'>";
746 $result = db_query($this->link
, "SELECT id,description
747 FROM ttrss_filter_types WHERE id != 5 ORDER BY description");
749 $filter_types = array();
751 while ($line = db_fetch_assoc($result)) {
752 $filter_types[$line["id"]] = __($line["description"]);
755 print "<div class=\"dlgSec\">".__("Match")."</div>";
757 print "<div class=\"dlgSecCont\">";
759 print "<input dojoType=\"dijit.form.ValidationTextBox\"
760 required=\"true\" id=\"filterDlg_regExp\"
761 style=\"font-size : 16px; width : 20em;\"
762 name=\"reg_exp\" value=\"$reg_exp\"/>";
764 print "<hr/>" . __("on field") . " ";
765 print_select_hash("filter_type", $filter_type, $filter_types,
766 'dojoType="dijit.form.Select"');
770 print __("in") . " ";
772 print "<span id='filterDlg_feeds'>";
773 print_feed_select($this->link
, "feed_id",
774 $cat_filter ?
"CAT:$feed_id" : $feed_id,
775 'dojoType="dijit.form.FilteringSelect"');
780 print "<div class=\"dlgButtons\">";
782 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterNewRuleDlg').execute()\">".
783 ($rule ?
__("Save rule") : __('Add rule'))."</button> ";
785 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterNewRuleDlg').hide()\">".
786 __('Cancel')."</button>";
793 function newaction() {
794 $action = json_decode($_REQUEST["action"], true);
797 $action_param = db_escape_string($action["action_param"]);
798 $action_id = (int)$action["action_id"];
804 print "<form name='filter_new_action_form' id='filter_new_action_form'>";
806 print "<div class=\"dlgSec\">".__("Perform Action")."</div>";
808 print "<div class=\"dlgSecCont\">";
810 print "<select name=\"action_id\" dojoType=\"dijit.form.Select\"
811 onchange=\"filterDlgCheckAction(this)\">";
813 $result = db_query($this->link
, "SELECT id,description FROM ttrss_filter_actions
816 while ($line = db_fetch_assoc($result)) {
817 $is_selected = ($line["id"] == $action_id) ?
"selected='1'" : "";
818 printf("<option $is_selected value='%d'>%s</option>", $line["id"], __($line["description"]));
823 $param_box_hidden = ($action_id == 7 ||
$action_id == 4 ||
$action_id == 6) ?
824 "" : "display : none";
826 $param_hidden = ($action_id == 4 ||
$action_id == 6) ?
827 "" : "display : none";
829 $label_param_hidden = ($action_id == 7) ?
"" : "display : none";
831 print "<span id=\"filterDlg_paramBox\" style=\"$param_box_hidden\">";
832 print " " . __("with parameters:") . " ";
833 print "<input dojoType=\"dijit.form.TextBox\"
834 id=\"filterDlg_actionParam\" style=\"$param_hidden\"
835 name=\"action_param\" value=\"$action_param\">";
837 print_label_select($this->link
, "action_param_label", $action_param,
838 "id=\"filterDlg_actionParamLabel\" style=\"$label_param_hidden\"
839 dojoType=\"dijit.form.Select\"");
843 print " "; // tiny layout hack
847 print "<div class=\"dlgButtons\">";
849 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterNewActionDlg').execute()\">".
850 ($action ?
__("Save action") : __('Add action'))."</button> ";
852 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterNewActionDlg').hide()\">".
853 __('Cancel')."</button>";
860 private function getFilterName($id) {
861 $result = db_query($this->link
,
862 "SELECT * FROM ttrss_filters2_rules WHERE filter_id = '$id' ORDER BY id
868 while ($line = db_fetch_assoc($result)) {
870 if (sql_bool_to_bool($line["cat_filter"])) {
871 unset($line["cat_filter"]);
872 $line["feed_id"] = "CAT:" . (int)$line["cat_id"];
873 unset($line["cat_id"]);
877 array_push($titles, $this->getRuleName($line));
879 array_push($titles, "...");
885 $result = db_query($this->link
,
886 "SELECT * FROM ttrss_filters2_actions WHERE filter_id = '$id' ORDER BY id LIMIT 3");
891 while ($line = db_fetch_assoc($result)) {
893 array_push($actions, $this->getActionName($line));
895 array_push($actions, "...");
901 return array(join(", ", $titles), join(", ", $actions));
905 $ids = explode(",", db_escape_string($_REQUEST["ids"]));
907 if (count($ids) > 1) {
908 $base_id = array_shift($ids);
909 $ids_str = join(",", $ids);
911 db_query($this->link
, "BEGIN");
912 db_query($this->link
, "UPDATE ttrss_filters2_rules
913 SET filter_id = '$base_id' WHERE filter_id IN ($ids_str)");
914 db_query($this->link
, "UPDATE ttrss_filters2_actions
915 SET filter_id = '$base_id' WHERE filter_id IN ($ids_str)");
917 db_query($this->link
, "DELETE FROM ttrss_filters2 WHERE id IN ($ids_str)");
918 db_query($this->link
, "UPDATE ttrss_filters2 SET match_any_rule = true WHERE id = '$base_id'");
920 db_query($this->link
, "COMMIT");
922 $this->optimizeFilter($base_id);
927 private function optimizeFilter($id) {
928 db_query($this->link
, "BEGIN");
929 $result = db_query($this->link
, "SELECT * FROM ttrss_filters2_actions
930 WHERE filter_id = '$id'");
935 while ($line = db_fetch_assoc($result)) {
939 if (array_search($line, $tmp) === false) {
940 array_push($tmp, $line);
942 array_push($dupe_ids, $id);
946 if (count($dupe_ids) > 0) {
947 $ids_str = join(",", $dupe_ids);
948 db_query($this->link
, "DELETE FROM ttrss_filters2_actions
949 WHERE id IN ($ids_str)");
952 $result = db_query($this->link
, "SELECT * FROM ttrss_filters2_rules
953 WHERE filter_id = '$id'");
958 while ($line = db_fetch_assoc($result)) {
962 if (array_search($line, $tmp) === false) {
963 array_push($tmp, $line);
965 array_push($dupe_ids, $id);
969 if (count($dupe_ids) > 0) {
970 $ids_str = join(",", $dupe_ids);
971 db_query($this->link
, "DELETE FROM ttrss_filters2_rules
972 WHERE id IN ($ids_str)");
975 db_query($this->link
, "COMMIT");