]>
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");
20 $type_name = db_fetch_result($result, 0, "name");
22 $filter_types = array();
23 while ($line = db_fetch_assoc($result)) {
24 $filter_types[$line["id"]] = $line["name"];
28 foreach ($_REQUEST["rule"] AS $r) {
29 $rule = json_decode($r, true);
31 if ($rule && $rctr < 5) {
32 $rule["type"] = $filter_types[$rule["filter_type"]];
33 unset($rule["filter_type"]);
35 if (strpos($rule["feed_id"], "CAT:") === 0) {
36 $rule["cat_id"] = (int) substr($rule["feed_id"], 4);
37 unset($rule["feed_id"]);
40 array_push($filter["rules"], $rule);
48 $feed_title = getFeedTitle($this->link
, $feed);
50 $qfh_ret = queryFeedHeadlines($this->link
, -4, 30, "", false, false, false,
51 false, "date_entered DESC", 0, $_SESSION["uid"], $filter);
53 $result = $qfh_ret[0];
58 print __("Articles matching this filter:");
60 print "<div class=\"filterTestHolder\">";
61 print "<table width=\"100%\" cellspacing=\"0\" id=\"prefErrorFeedList\">";
63 while ($line = db_fetch_assoc($result)) {
65 $entry_timestamp = strtotime($line["updated"]);
66 $entry_tags = get_article_tags($this->link
, $line["id"], $_SESSION["uid"]);
68 $content_preview = truncate_string(
69 strip_tags($line["content_preview"]), 100, '...');
71 if ($line["feed_title"])
72 $feed_title = $line["feed_title"];
76 print "<td width='5%' align='center'><input
77 dojoType=\"dijit.form.CheckBox\" checked=\"1\"
78 disabled=\"1\" type=\"checkbox\"></td>";
83 print "<b>" . $feed_title . "</b>";
85 print "<span class=\"insensitive\">" . $content_preview . "</span>";
86 print " " . mb_substr($line["date_entered"], 0, 16);
94 print "<tr><td align='center'>" .
95 __("No recent articles matching this filter have been found.") . "</td></tr>";
98 print "</table></div>";
100 print "<div style='text-align : center'>";
101 print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('filterTestDlg').hide()\">".
102 __('Close this window')."</button>";
108 function getfiltertree() {
110 $root['id'] = 'root';
111 $root['name'] = __('Filters');
112 $root['items'] = array();
114 $filter_search = $_SESSION["prefs_filter_search"];
116 $result = db_query($this->link
, "SELECT *,
117 (SELECT action_param FROM ttrss_filters2_actions
118 WHERE filter_id = ttrss_filters2.id ORDER BY id LIMIT 1) AS action_param,
119 (SELECT action_id FROM ttrss_filters2_actions
120 WHERE filter_id = ttrss_filters2.id ORDER BY id LIMIT 1) AS action_id,
121 (SELECT description FROM ttrss_filter_actions
122 WHERE id = (SELECT action_id FROM ttrss_filters2_actions
123 WHERE filter_id = ttrss_filters2.id ORDER BY id LIMIT 1)) AS action_name,
124 (SELECT reg_exp FROM ttrss_filters2_rules
125 WHERE filter_id = ttrss_filters2.id ORDER BY id LIMIT 1) AS reg_exp
126 FROM ttrss_filters2 WHERE
127 owner_uid = ".$_SESSION["uid"]." ORDER BY action_id,reg_exp");
132 $folder['items'] = array();
134 while ($line = db_fetch_assoc($result)) {
136 if ($action_id != $line["action_id"]) {
137 if (count($folder['items']) > 0) {
138 array_push($root['items'], $folder);
142 $folder['id'] = $line["action_id"];
143 $folder['name'] = $line["action_name"];
144 $folder['items'] = array();
145 $action_id = $line["action_id"];
148 $name = $this->getFilterName($line["id"]);
151 if ($filter_search) {
152 $rules_result = db_query($this->link
,
153 "SELECT reg_exp FROM ttrss_filters2_rules WHERE filter_id = ".$line["id"]);
155 while ($rule_line = db_fetch_assoc($rules_result)) {
156 if (mb_strpos($rule_line['reg_exp'], $filter_search) !== false) {
163 if ($line['action_id'] == 7) {
164 $label_result = db_query($this->link
, "SELECT fg_color, bg_color
165 FROM ttrss_labels2 WHERE caption = '".db_escape_string($line['action_param'])."' AND
166 owner_uid = " . $_SESSION["uid"]);
168 if (db_num_rows($label_result) > 0) {
169 $fg_color = db_fetch_result($label_result, 0, "fg_color");
170 $bg_color = db_fetch_result($label_result, 0, "bg_color");
172 $name[1] = "<span class=\"labelColorIndicator\" id=\"label-editor-indicator\" style='color : $fg_color; background-color : $bg_color; margin-right : 4px'>α</span>" . $name[1];
177 $filter['id'] = 'FILTER:' . $line['id'];
178 $filter['bare_id'] = $line['id'];
179 $filter['name'] = $name[0];
180 $filter['param'] = $name[1];
181 $filter['checkbox'] = false;
182 $filter['enabled'] = sql_bool_to_bool($line["enabled"]);
184 if (!$filter_search ||
$match_ok) {
185 array_push($folder['items'], $filter);
189 if (count($folder['items']) > 0) {
190 array_push($root['items'], $folder);
194 $fl['identifier'] = 'id';
195 $fl['label'] = 'name';
196 $fl['items'] = array($root);
198 print json_encode($fl);
204 $filter_id = db_escape_string($_REQUEST["id"]);
206 $result = db_query($this->link
,
207 "SELECT * FROM ttrss_filters2 WHERE id = '$filter_id' AND owner_uid = " . $_SESSION["uid"]);
209 $enabled = sql_bool_to_bool(db_fetch_result($result, 0, "enabled"));
210 $match_any_rule = sql_bool_to_bool(db_fetch_result($result, 0, "match_any_rule"));
212 print "<form id=\"filter_edit_form\" onsubmit='return false'>";
214 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-filters\">";
215 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"id\" value=\"$filter_id\">";
216 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"editSave\">";
217 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"csrf_token\" value=\"".$_SESSION['csrf_token']."\">";
219 print "<div class=\"dlgSec\">".__("Match")."</div>";
221 print "<div dojoType=\"dijit.Toolbar\">";
223 print "<div dojoType=\"dijit.form.DropDownButton\">".
224 "<span>" . __('Select')."</span>";
225 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
226 print "<div onclick=\"dijit.byId('filterEditDlg').selectRules(true)\"
227 dojoType=\"dijit.MenuItem\">".__('All')."</div>";
228 print "<div onclick=\"dijit.byId('filterEditDlg').selectRules(false)\"
229 dojoType=\"dijit.MenuItem\">".__('None')."</div>";
230 print "</div></div>";
232 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').addRule()\">".
233 __('Add')."</button> ";
235 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').deleteRule()\">".
236 __('Delete')."</button> ";
240 print "<ul id='filterDlg_Matches'>";
242 $rules_result = db_query($this->link
, "SELECT * FROM ttrss_filters2_rules
243 WHERE filter_id = '$filter_id' ORDER BY id");
245 while ($line = db_fetch_assoc($rules_result)) {
246 if (sql_bool_to_bool($line["cat_filter"])) {
247 $line["feed_id"] = "CAT:" . (int)$line["cat_id"];
250 unset($line["cat_filter"]);
251 unset($line["cat_id"]);
252 unset($line["filter_id"]);
255 $data = htmlspecialchars(json_encode($line));
257 print "<li><input dojoType='dijit.form.CheckBox' type='checkbox' onclick='toggleSelectListRow2(this)'>".
258 "<span onclick=\"dijit.byId('filterEditDlg').editRule(this)\">".$this->getRuleName($line)."</span>".
259 "<input type='hidden' name='rule[]' value=\"$data\"/></li>";
266 print "<div class=\"dlgSec\">".__("Apply actions")."</div>";
268 print "<div dojoType=\"dijit.Toolbar\">";
270 print "<div dojoType=\"dijit.form.DropDownButton\">".
271 "<span>" . __('Select')."</span>";
272 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
273 print "<div onclick=\"dijit.byId('filterEditDlg').selectActions(true)\"
274 dojoType=\"dijit.MenuItem\">".__('All')."</div>";
275 print "<div onclick=\"dijit.byId('filterEditDlg').selectActions(false)\"
276 dojoType=\"dijit.MenuItem\">".__('None')."</div>";
277 print "</div></div>";
279 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').addAction()\">".
280 __('Add')."</button> ";
282 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').deleteAction()\">".
283 __('Delete')."</button> ";
287 print "<ul id='filterDlg_Actions'>";
289 $actions_result = db_query($this->link
, "SELECT * FROM ttrss_filters2_actions
290 WHERE filter_id = '$filter_id' ORDER BY id");
292 while ($line = db_fetch_assoc($actions_result)) {
293 $line["action_param_label"] = $line["action_param"];
295 unset($line["filter_id"]);
298 $data = htmlspecialchars(json_encode($line));
300 print "<li><input dojoType='dijit.form.CheckBox' type='checkbox' onclick='toggleSelectListRow2(this)'>".
301 "<span onclick=\"dijit.byId('filterEditDlg').editAction(this)\">".$this->getActionName($line)."</span>".
302 "<input type='hidden' name='action[]' value=\"$data\"/></li>";
310 $checked = "checked=\"1\"";
315 print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"enabled\" id=\"enabled\" $checked>
316 <label for=\"enabled\">".__('Enabled')."</label>";
318 if ($match_any_rule) {
319 $checked = "checked=\"1\"";
324 print "<br/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"match_any_rule\" id=\"match_any_rule\" $checked>
325 <label for=\"match_any_rule\">".__('Match any rule')."</label>";
329 print "<div class=\"dlgButtons\">";
331 print "<div style=\"float : left\">";
332 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').removeFilter()\">".
333 __('Remove')."</button>";
336 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').test()\">".
337 __('Test')."</button> ";
339 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').execute()\">".
340 __('Save')."</button> ";
342 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').hide()\">".
343 __('Cancel')."</button>";
348 private function getRuleName($rule) {
349 if (!$rule) $rule = json_decode($_REQUEST["rule"], true);
351 $feed_id = $rule["feed_id"];
353 if (strpos($feed_id, "CAT:") === 0) {
354 $feed_id = (int) substr($feed_id, 4);
355 $feed = getCategoryTitle($this->link
, $feed_id);
357 $feed_id = (int) $feed_id;
359 if ($rule["feed_id"])
360 $feed = getFeedTitle($this->link
, (int)$rule["feed_id"]);
362 $feed = __("All feeds");
365 $result = db_query($this->link
, "SELECT description FROM ttrss_filter_types
366 WHERE id = ".(int)$rule["filter_type"]);
367 $match_on = db_fetch_result($result, 0, "description");
369 return T_sprintf("%s on %s in %s", $rule["reg_exp"], $match_on, $feed);
372 function printRuleName() {
373 print $this->getRuleName(json_decode($_REQUEST["rule"], true));
376 private function getActionName($action) {
377 $result = db_query($this->link
, "SELECT description FROM
378 ttrss_filter_actions WHERE id = " .(int)$action["action_id"]);
380 $title = __(db_fetch_result($result, 0, "description"));
382 if ($action["action_id"] == 4 ||
$action["action_id"] == 6 ||
383 $action["action_id"] == 7)
384 $title .= ": " . $action["action_param"];
389 function printActionName() {
390 print $this->getActionName(json_decode($_REQUEST["action"], true));
393 function editSave() {
394 if ($_REQUEST["savemode"] && $_REQUEST["savemode"] == "test") {
395 return $this->testFilter();
398 # print_r($_REQUEST);
400 $filter_id = db_escape_string($_REQUEST["id"]);
401 $enabled = checkbox_to_sql_bool(db_escape_string($_REQUEST["enabled"]));
402 $match_any_rule = checkbox_to_sql_bool(db_escape_string($_REQUEST["match_any_rule"]));
404 $result = db_query($this->link
, "UPDATE ttrss_filters2 SET enabled = $enabled,
405 match_any_rule = $match_any_rule
406 WHERE id = '$filter_id'
407 AND owner_uid = ". $_SESSION["uid"]);
409 $this->saveRulesAndActions($filter_id);
415 $ids = split(",", db_escape_string($_REQUEST["ids"]));
417 foreach ($ids as $id) {
418 db_query($this->link
, "DELETE FROM ttrss_filters2 WHERE id = '$id' AND owner_uid = ". $_SESSION["uid"]);
422 private function saveRulesAndActions($filter_id) {
424 db_query($this->link
, "DELETE FROM ttrss_filters2_rules WHERE filter_id = '$filter_id'");
425 db_query($this->link
, "DELETE FROM ttrss_filters2_actions WHERE filter_id = '$filter_id'");
433 foreach ($_REQUEST["rule"] as $rule) {
434 $rule = json_decode($rule, true);
437 if (array_search($rule, $rules) === false) {
438 array_push($rules, $rule);
442 foreach ($_REQUEST["action"] as $action) {
443 $action = json_decode($action, true);
444 unset($action["id"]);
446 if (array_search($action, $actions) === false) {
447 array_push($actions, $action);
451 foreach ($rules as $rule) {
454 $reg_exp = strip_tags(db_escape_string(trim($rule["reg_exp"])));
455 $filter_type = (int) db_escape_string(trim($rule["filter_type"]));
456 $feed_id = db_escape_string(trim($rule["feed_id"]));
458 if (strpos($feed_id, "CAT:") === 0) {
460 $cat_filter = bool_to_sql_bool(true);
461 $cat_id = (int) substr($feed_id, 4);
464 if (!$cat_id) $cat_id = "NULL"; // Uncategorized
466 $cat_filter = bool_to_sql_bool(false);
467 $feed_id = (int) $feed_id;
470 if (!$feed_id) $feed_id = "NULL"; // Uncategorized
473 $query = "INSERT INTO ttrss_filters2_rules
474 (filter_id, reg_exp,filter_type,feed_id,cat_id,cat_filter) VALUES
475 ('$filter_id', '$reg_exp', '$filter_type', $feed_id, $cat_id, $cat_filter)";
477 db_query($this->link
, $query);
481 foreach ($actions as $action) {
484 $action_id = (int) db_escape_string($action["action_id"]);
485 $action_param = db_escape_string($action["action_param"]);
486 $action_param_label = db_escape_string($action["action_param_label"]);
488 if ($action_id == 7) {
489 $action_param = $action_param_label;
492 if ($action_id == 6) {
493 $action_param = (int) str_replace("+", "", $action_param);
496 $query = "INSERT INTO ttrss_filters2_actions
497 (filter_id, action_id, action_param) VALUES
498 ('$filter_id', '$action_id', '$action_param')";
500 db_query($this->link
, $query);
509 if ($_REQUEST["savemode"] && $_REQUEST["savemode"] == "test") {
510 return $this->testFilter();
513 # print_r($_REQUEST);
515 $enabled = checkbox_to_sql_bool($_REQUEST["enabled"]);
516 $match_any_rule = checkbox_to_sql_bool($_REQUEST["match_any_rule"]);
518 db_query($this->link
, "BEGIN");
520 /* create base filter */
522 $result = db_query($this->link
, "INSERT INTO ttrss_filters2
523 (owner_uid, match_any_rule, enabled) VALUES
524 (".$_SESSION["uid"].",$match_any_rule,$enabled)");
526 $result = db_query($this->link
, "SELECT MAX(id) AS id FROM ttrss_filters2
527 WHERE owner_uid = ".$_SESSION["uid"]);
529 $filter_id = db_fetch_result($result, 0, "id");
531 $this->saveRulesAndActions($filter_id);
533 db_query($this->link
, "COMMIT");
538 $sort = db_escape_string($_REQUEST["sort"]);
540 if (!$sort ||
$sort == "undefined") {
544 $filter_search = db_escape_string($_REQUEST["search"]);
546 if (array_key_exists("search", $_REQUEST)) {
547 $_SESSION["prefs_filter_search"] = $filter_search;
549 $filter_search = $_SESSION["prefs_filter_search"];
552 print "<div id=\"pref-filter-wrap\" dojoType=\"dijit.layout.BorderContainer\" gutters=\"false\">";
553 print "<div id=\"pref-filter-header\" dojoType=\"dijit.layout.ContentPane\" region=\"top\">";
554 print "<div id=\"pref-filter-toolbar\" dojoType=\"dijit.Toolbar\">";
556 $filter_search = db_escape_string($_REQUEST["search"]);
558 if (array_key_exists("search", $_REQUEST)) {
559 $_SESSION["prefs_filter_search"] = $filter_search;
561 $filter_search = $_SESSION["prefs_filter_search"];
564 print "<div style='float : right; padding-right : 4px;'>
565 <input dojoType=\"dijit.form.TextBox\" id=\"filter_search\" size=\"20\" type=\"search\"
566 value=\"$filter_search\">
567 <button dojoType=\"dijit.form.Button\" onclick=\"updateFilterList()\">".
568 __('Search')."</button>
571 print "<div dojoType=\"dijit.form.DropDownButton\">".
572 "<span>" . __('Select')."</span>";
573 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
574 print "<div onclick=\"dijit.byId('filterTree').model.setAllChecked(true)\"
575 dojoType=\"dijit.MenuItem\">".__('All')."</div>";
576 print "<div onclick=\"dijit.byId('filterTree').model.setAllChecked(false)\"
577 dojoType=\"dijit.MenuItem\">".__('None')."</div>";
578 print "</div></div>";
580 print "<button dojoType=\"dijit.form.Button\" onclick=\"return quickAddFilter()\">".
581 __('Create filter')."</button> ";
583 print "<button dojoType=\"dijit.form.Button\" onclick=\"return joinSelectedFilters()\">".
584 __('Combine')."</button> ";
586 print "<button dojoType=\"dijit.form.Button\" onclick=\"return editSelectedFilter()\">".
587 __('Edit')."</button> ";
589 print "<button dojoType=\"dijit.form.Button\" onclick=\"return removeSelectedFilters()\">".
590 __('Remove')."</button> ";
592 if (defined('_ENABLE_FEED_DEBUGGING')) {
593 print "<button dojoType=\"dijit.form.Button\" onclick=\"rescore_all_feeds()\">".
594 __('Rescore articles')."</button> ";
597 print "</div>"; # toolbar
598 print "</div>"; # toolbar-frame
599 print "<div id=\"pref-filter-content\" dojoType=\"dijit.layout.ContentPane\" region=\"center\">";
601 print "<div id=\"filterlistLoading\">
602 <img src='images/indicator_tiny.gif'>".
603 __("Loading, please wait...")."</div>";
605 print "<div dojoType=\"dojo.data.ItemFileWriteStore\" jsId=\"filterStore\"
606 url=\"backend.php?op=pref-filters&method=getfiltertree\">
608 <div dojoType=\"lib.CheckBoxStoreModel\" jsId=\"filterModel\" store=\"filterStore\"
609 query=\"{id:'root'}\" rootId=\"root\" rootLabel=\"Feeds\"
610 childrenAttrs=\"items\" checkboxStrict=\"false\" checkboxAll=\"false\">
612 <div dojoType=\"fox.PrefFilterTree\" id=\"filterTree\"
613 model=\"filterModel\" openOnClick=\"true\">
614 <script type=\"dojo/method\" event=\"onLoad\" args=\"item\">
615 Element.hide(\"filterlistLoading\");
617 <script type=\"dojo/method\" event=\"onClick\" args=\"item\">
618 var id = String(item.id);
619 var bare_id = id.substr(id.indexOf(':')+1);
621 if (id.match('FILTER:')) {
628 print "</div>"; #pane
629 print "</div>"; #container
633 function newfilter() {
635 print "<form name='filter_new_form' id='filter_new_form'>";
637 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-filters\">";
638 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"add\">";
639 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"csrf_token\" value=\"".$_SESSION['csrf_token']."\">";
641 print "<div class=\"dlgSec\">".__("Match")."</div>";
643 print "<div dojoType=\"dijit.Toolbar\">";
645 print "<div dojoType=\"dijit.form.DropDownButton\">".
646 "<span>" . __('Select')."</span>";
647 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
648 print "<div onclick=\"dijit.byId('filterEditDlg').selectRules(true)\"
649 dojoType=\"dijit.MenuItem\">".__('All')."</div>";
650 print "<div onclick=\"dijit.byId('filterEditDlg').selectRules(false)\"
651 dojoType=\"dijit.MenuItem\">".__('None')."</div>";
652 print "</div></div>";
654 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').addRule()\">".
655 __('Add')."</button> ";
657 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').deleteRule()\">".
658 __('Delete')."</button> ";
662 print "<ul id='filterDlg_Matches'>";
663 # print "<li>No rules</li>";
668 print "<div class=\"dlgSec\">".__("Apply actions")."</div>";
670 print "<div dojoType=\"dijit.Toolbar\">";
672 print "<div dojoType=\"dijit.form.DropDownButton\">".
673 "<span>" . __('Select')."</span>";
674 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
675 print "<div onclick=\"dijit.byId('filterEditDlg').selectActions(true)\"
676 dojoType=\"dijit.MenuItem\">".__('All')."</div>";
677 print "<div onclick=\"dijit.byId('filterEditDlg').selectActions(false)\"
678 dojoType=\"dijit.MenuItem\">".__('None')."</div>";
679 print "</div></div>";
681 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').addAction()\">".
682 __('Add')."</button> ";
684 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').deleteAction()\">".
685 __('Delete')."</button> ";
689 print "<ul id='filterDlg_Actions'>";
690 # print "<li>No actions</li>";
693 /* print "<div class=\"dlgSec\">".__("Options")."</div>";
694 print "<div class=\"dlgSecCont\">"; */
696 print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"enabled\" id=\"enabled\" checked=\"1\">
697 <label for=\"enabled\">".__('Enabled')."</label>";
699 print "<br/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"match_any_rule\" id=\"match_any_rule\">
700 <label for=\"match_any_rule\">".__('Match any rule')."</label>";
704 /* print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"inverse\" id=\"inverse\">
705 <label for=\"inverse\">".__('Inverse match')."</label><hr/>"; */
709 print "<div class=\"dlgButtons\">";
711 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').test()\">".
712 __('Test')."</button> ";
714 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').execute()\">".
715 __('Create')."</button> ";
717 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').hide()\">".
718 __('Cancel')."</button>";
725 $rule = json_decode($_REQUEST["rule"], true);
728 $reg_exp = htmlspecialchars($rule["reg_exp"]);
729 $filter_type = $rule["filter_type"];
730 $feed_id = $rule["feed_id"];
737 if (strpos($feed_id, "CAT:") === 0) {
738 $feed_id = substr($feed_id, 4);
745 print "<form name='filter_new_rule_form' id='filter_new_rule_form'>";
747 $result = db_query($this->link
, "SELECT id,description
748 FROM ttrss_filter_types WHERE id != 5 ORDER BY description");
750 $filter_types = array();
752 while ($line = db_fetch_assoc($result)) {
753 $filter_types[$line["id"]] = __($line["description"]);
756 print "<div class=\"dlgSec\">".__("Match")."</div>";
758 print "<div class=\"dlgSecCont\">";
760 print "<input dojoType=\"dijit.form.ValidationTextBox\"
761 required=\"true\" id=\"filterDlg_regExp\"
762 style=\"font-size : 16px; width : 20em;\"
763 name=\"reg_exp\" value=\"$reg_exp\"/>";
765 print "<hr/>" . __("on field") . " ";
766 print_select_hash("filter_type", $filter_type, $filter_types,
767 'dojoType="dijit.form.Select"');
771 print __("in") . " ";
773 print "<span id='filterDlg_feeds'>";
774 print_feed_select($this->link
, "feed_id",
775 $cat_filter ?
"CAT:$feed_id" : $feed_id,
776 'dojoType="dijit.form.FilteringSelect"');
781 print "<div class=\"dlgButtons\">";
783 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterNewRuleDlg').execute()\">".
784 ($rule ?
__("Save rule") : __('Add rule'))."</button> ";
786 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterNewRuleDlg').hide()\">".
787 __('Cancel')."</button>";
794 function newaction() {
795 $action = json_decode($_REQUEST["action"], true);
798 $action_param = db_escape_string($action["action_param"]);
799 $action_id = (int)$action["action_id"];
805 print "<form name='filter_new_action_form' id='filter_new_action_form'>";
807 print "<div class=\"dlgSec\">".__("Perform Action")."</div>";
809 print "<div class=\"dlgSecCont\">";
811 print "<select name=\"action_id\" dojoType=\"dijit.form.Select\"
812 onchange=\"filterDlgCheckAction(this)\">";
814 $result = db_query($this->link
, "SELECT id,description FROM ttrss_filter_actions
817 while ($line = db_fetch_assoc($result)) {
818 $is_selected = ($line["id"] == $action_id) ?
"selected='1'" : "";
819 printf("<option $is_selected value='%d'>%s</option>", $line["id"], __($line["description"]));
824 $param_box_hidden = ($action_id == 7 ||
$action_id == 4 ||
$action_id == 6) ?
825 "" : "display : none";
827 $param_hidden = ($action_id == 4 ||
$action_id == 6) ?
828 "" : "display : none";
830 $label_param_hidden = ($action_id == 7) ?
"" : "display : none";
832 print "<span id=\"filterDlg_paramBox\" style=\"$param_box_hidden\">";
833 print " " . __("with parameters:") . " ";
834 print "<input dojoType=\"dijit.form.TextBox\"
835 id=\"filterDlg_actionParam\" style=\"$param_hidden\"
836 name=\"action_param\" value=\"$action_param\">";
838 print_label_select($this->link
, "action_param_label", $action_param,
839 "id=\"filterDlg_actionParamLabel\" style=\"$label_param_hidden\"
840 dojoType=\"dijit.form.Select\"");
844 print " "; // tiny layout hack
848 print "<div class=\"dlgButtons\">";
850 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterNewActionDlg').execute()\">".
851 ($action ?
__("Save action") : __('Add action'))."</button> ";
853 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterNewActionDlg').hide()\">".
854 __('Cancel')."</button>";
861 private function getFilterName($id) {
862 $result = db_query($this->link
,
863 "SELECT * FROM ttrss_filters2_rules WHERE filter_id = '$id' ORDER BY id
869 while ($line = db_fetch_assoc($result)) {
871 if (sql_bool_to_bool($line["cat_filter"])) {
872 unset($line["cat_filter"]);
873 $line["feed_id"] = "CAT:" . (int)$line["cat_id"];
874 unset($line["cat_id"]);
878 array_push($titles, $this->getRuleName($line));
880 array_push($titles, "...");
886 $result = db_query($this->link
,
887 "SELECT * FROM ttrss_filters2_actions WHERE filter_id = '$id' ORDER BY id LIMIT 3");
892 while ($line = db_fetch_assoc($result)) {
894 array_push($actions, $this->getActionName($line));
896 array_push($actions, "...");
902 return array(join(", ", $titles), join(", ", $actions));
906 $ids = explode(",", db_escape_string($_REQUEST["ids"]));
908 if (count($ids) > 1) {
909 $base_id = array_shift($ids);
910 $ids_str = join(",", $ids);
912 db_query($this->link
, "BEGIN");
913 db_query($this->link
, "UPDATE ttrss_filters2_rules
914 SET filter_id = '$base_id' WHERE filter_id IN ($ids_str)");
915 db_query($this->link
, "UPDATE ttrss_filters2_actions
916 SET filter_id = '$base_id' WHERE filter_id IN ($ids_str)");
918 db_query($this->link
, "DELETE FROM ttrss_filters2 WHERE id IN ($ids_str)");
919 db_query($this->link
, "UPDATE ttrss_filters2 SET match_any_rule = true WHERE id = '$base_id'");
921 db_query($this->link
, "COMMIT");
923 $this->optimizeFilter($base_id);
928 private function optimizeFilter($id) {
929 db_query($this->link
, "BEGIN");
930 $result = db_query($this->link
, "SELECT * FROM ttrss_filters2_actions
931 WHERE filter_id = '$id'");
936 while ($line = db_fetch_assoc($result)) {
940 if (array_search($line, $tmp) === false) {
941 array_push($tmp, $line);
943 array_push($dupe_ids, $id);
947 if (count($dupe_ids) > 0) {
948 $ids_str = join(",", $dupe_ids);
949 db_query($this->link
, "DELETE FROM ttrss_filters2_actions
950 WHERE id IN ($ids_str)");
953 $result = db_query($this->link
, "SELECT * FROM ttrss_filters2_rules
954 WHERE filter_id = '$id'");
959 while ($line = db_fetch_assoc($result)) {
963 if (array_search($line, $tmp) === false) {
964 array_push($tmp, $line);
966 array_push($dupe_ids, $id);
970 if (count($dupe_ids) > 0) {
971 $ids_str = join(",", $dupe_ids);
972 db_query($this->link
, "DELETE FROM ttrss_filters2_rules
973 WHERE id IN ($ids_str)");
976 db_query($this->link
, "COMMIT");