]>
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 filter_test($filter_type, $reg_exp,
12 $action_id, $action_param, $filter_param, $inverse, $feed_id, $cat_id,
15 $result = db_query($this->link, "SELECT name FROM ttrss_filter_types WHERE
16 id = " . $filter_type);
17 $type_name = db_fetch_result($result, 0, "name");
19 $result = db_query($this->link, "SELECT name FROM ttrss_filter_actions WHERE
21 $action_name = db_fetch_result($result, 0, "name");
23 $filter["reg_exp"] = $reg_exp;
24 $filter["action"] = $action_name;
25 $filter["type"] = $type_name;
26 $filter["action_param"] = $action_param;
27 $filter["filter_param"] = $filter_param;
28 $filter["inverse"] = $inverse;
30 $filters[$type_name] = array($filter);
37 $regexp_valid = preg_match('/' . $filter['reg_exp'] . '/',
38 $filter['reg_exp']) !== FALSE;
40 print __("Articles matching this filter:");
42 print "<div class=\"filterTestHolder\">";
43 print "<table width=\"100%\" cellspacing=\"0\" id=\"prefErrorFeedList\">";
47 $feed_title = getFeedTitle($this->link, $feed);
49 $qfh_ret = queryFeedHeadlines($this->link, $cat_filter ? $cat_id : $feed,
50 30, "", $cat_filter, false, false,
51 false, "date_entered DESC", 0, $_SESSION["uid"], $filter);
53 $result = $qfh_ret[0];
58 while ($line = db_fetch_assoc($result)) {
60 $entry_timestamp = strtotime($line["updated"]);
61 $entry_tags = get_article_tags($this->link, $line["id"], $_SESSION["uid"]);
63 $content_preview = truncate_string(
64 strip_tags($line["content_preview"]), 100, '...');
66 if ($line["feed_title"])
67 $feed_title = $line["feed_title"];
71 print "<td width='5%' align='center'><input
72 dojoType=\"dijit.form.CheckBox\" checked=\"1\"
73 disabled=\"1\" type=\"checkbox\"></td>";
78 print "<b>" . $feed_title . "</b>";
80 print "<span class=\"insensitive\">" . $content_preview . "</span>";
81 print " " . mb_substr($line["date_entered"], 0, 16);
89 print "<tr><td align='center'>" .
90 __("No articles matching this filter has been found.") . "</td></tr>";
93 print "<tr><td align='center' class='error'>" .
94 __("Invalid regular expression.") . "</td></tr>";
103 function getfiltertree() {
105 $root['id'] = 'root';
106 $root['name'] = __('Filters');
107 $root['items'] = array();
109 $result = db_query($this->link
, "SELECT *,
110 (SELECT action_id FROM ttrss_filters2_actions
111 WHERE filter_id = ttrss_filters2.id ORDER BY id LIMIT 1) AS action_id,
112 (SELECT reg_exp FROM ttrss_filters2_rules
113 WHERE filter_id = ttrss_filters2.id ORDER BY id LIMIT 1) AS reg_exp
114 FROM ttrss_filters2 WHERE
115 owner_uid = ".$_SESSION["uid"]." ORDER BY action_id,reg_exp");
117 while ($line = db_fetch_assoc($result)) {
119 $name = $this->getFilterName($line["id"]);
122 $filter['id'] = 'FILTER:' . $line['id'];
123 $filter['bare_id'] = $line['id'];
124 $filter['name'] = $name[0];
125 $filter['param'] = $name[1];
126 $filter['checkbox'] = false;
127 $filter['enabled'] = $line["enabled"];
129 array_push($root['items'], $filter);
133 $fl['identifier'] = 'id';
134 $fl['label'] = 'name';
135 $fl['items'] = array($root);
137 print json_encode($fl);
143 $filter_id = db_escape_string($_REQUEST["id"]);
145 $result = db_query($this->link
,
146 "SELECT * FROM ttrss_filters2 WHERE id = '$filter_id' AND owner_uid = " . $_SESSION["uid"]);
148 $enabled = sql_bool_to_bool(db_fetch_result($result, 0, "enabled"));
149 $match_any_rule = sql_bool_to_bool(db_fetch_result($result, 0, "match_any_rule"));
151 print "<form id=\"filter_edit_form\" onsubmit='return false'>";
153 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-filters\">";
154 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"id\" value=\"$filter_id\">";
155 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"editSave\">";
156 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"csrf_token\" value=\"".$_SESSION['csrf_token']."\">";
158 print "<div class=\"dlgSec\">".__("Match")."</div>";
160 print "<div dojoType=\"dijit.Toolbar\">";
162 print "<div dojoType=\"dijit.form.DropDownButton\">".
163 "<span>" . __('Select')."</span>";
164 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
165 print "<div onclick=\"dijit.byId('filterEditDlg').selectRules(true)\"
166 dojoType=\"dijit.MenuItem\">".__('All')."</div>";
167 print "<div onclick=\"dijit.byId('filterEditDlg').selectRules(false)\"
168 dojoType=\"dijit.MenuItem\">".__('None')."</div>";
169 print "</div></div>";
171 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').addRule()\">".
172 __('Add')."</button> ";
174 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').deleteRule()\">".
175 __('Delete')."</button> ";
179 print "<ul id='filterDlg_Matches'>";
181 $rules_result = db_query($this->link
, "SELECT * FROM ttrss_filters2_rules
182 WHERE filter_id = '$filter_id' ORDER BY id");
184 while ($line = db_fetch_assoc($rules_result)) {
185 if ($line["cat_filter"]) {
186 unset($line["cat_filter"]);
187 $line["feed_id"] = "CAT:" . (int)$line["cat_id"];
188 unset($line["cat_id"]);
191 $data = htmlspecialchars(json_encode($line));
193 print "<li><input type='checkbox' onclick='toggleSelectListRow(this)'>".
194 "<span onclick=\"dijit.byId('filterEditDlg').editRule(this)\">".$this->getRuleName($line)."</span>".
195 "<input type='hidden' name='rule[]' value=\"$data\"/></li>";
202 print "<div class=\"dlgSec\">".__("Apply actions")."</div>";
204 print "<div dojoType=\"dijit.Toolbar\">";
206 print "<div dojoType=\"dijit.form.DropDownButton\">".
207 "<span>" . __('Select')."</span>";
208 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
209 print "<div onclick=\"dijit.byId('filterEditDlg').selectActions(true)\"
210 dojoType=\"dijit.MenuItem\">".__('All')."</div>";
211 print "<div onclick=\"dijit.byId('filterEditDlg').selectActions(false)\"
212 dojoType=\"dijit.MenuItem\">".__('None')."</div>";
213 print "</div></div>";
215 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').addAction()\">".
216 __('Add')."</button> ";
218 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').deleteAction()\">".
219 __('Delete')."</button> ";
223 print "<ul id='filterDlg_Actions'>";
225 $actions_result = db_query($this->link
, "SELECT * FROM ttrss_filters2_actions
226 WHERE filter_id = '$filter_id' ORDER BY id");
228 while ($line = db_fetch_assoc($actions_result)) {
229 $line["action_param_label"] = $line["action_param"];
230 $data = htmlspecialchars(json_encode($line));
232 print "<li><input type='checkbox' onclick='toggleSelectListRow(this)'>".
233 "<span onclick=\"dijit.byId('filterEditDlg').editAction(this)\">".$this->getActionName($line)."</span>".
234 "<input type='hidden' name='action[]' value=\"$data\"/></li>";
242 $checked = "checked=\"1\"";
247 print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"enabled\" id=\"enabled\" $checked>
248 <label for=\"enabled\">".__('Enabled')."</label>";
250 if ($match_any_rule) {
251 $checked = "checked=\"1\"";
256 print "<br/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"match_any_rule\" id=\"match_any_rule\" $checked>
257 <label for=\"match_any_rule\">".__('Match any rule')."</label>";
261 print "<div class=\"dlgButtons\">";
263 print "<div style=\"float : left\">";
264 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').removeFilter()\">".
265 __('Remove')."</button>";
268 # print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').test()\">".
269 # __('Test')."</button> ";
271 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').execute()\">".
272 __('Save')."</button> ";
274 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').hide()\">".
275 __('Cancel')."</button>";
280 private function getRuleName($rule) {
281 if (!$rule) $rule = json_decode($_REQUEST["rule"], true);
283 $feed_id = $rule["feed_id"];
285 if (strpos($feed_id, "CAT:") === 0) {
286 $feed_id = (int) substr($feed_id, 4);
287 $feed = getCategoryTitle($this->link
, $feed_id);
289 $feed_id = (int) $feed_id;
291 if ($rule["feed_id"])
292 $feed = getFeedTitle($this->link
, (int)$rule["feed_id"]);
294 $feed = __("All feeds");
297 $result = db_query($this->link
, "SELECT description FROM ttrss_filter_types
298 WHERE id = ".(int)$rule["filter_type"]);
299 $match_on = db_fetch_result($result, 0, "description");
301 return T_sprintf("%s on %s in %s", $rule["reg_exp"], $match_on, $feed);
304 function printRuleName() {
305 print $this->getRuleName(json_decode($_REQUEST["rule"], true));
308 private function getActionName($action) {
309 $result = db_query($this->link
, "SELECT description FROM
310 ttrss_filter_actions WHERE id = " .(int)$action["action_id"]);
312 $title = __(db_fetch_result($result, 0, "description"));
314 if ($action["action_id"] == 4 ||
$action["action_id"] == 6 ||
315 $action["action_id"] == 7)
316 $title .= ": " . $action["action_param"];
321 function printActionName() {
322 print $this->getActionName(json_decode($_REQUEST["action"], true));
325 function editSave() {
327 # print_r($_REQUEST);
329 $filter_id = db_escape_string($_REQUEST["id"]);
330 $enabled = checkbox_to_sql_bool(db_escape_string($_REQUEST["enabled"]));
331 $match_any_rule = checkbox_to_sql_bool(db_escape_string($_REQUEST["match_any_rule"]));
333 $result = db_query($this->link
, "UPDATE ttrss_filters2 SET enabled = $enabled,
334 match_any_rule = $match_any_rule
335 WHERE id = '$filter_id'
336 AND owner_uid = ". $_SESSION["uid"]);
338 $this->saveRulesAndActions($filter_id);
344 $ids = split(",", db_escape_string($_REQUEST["ids"]));
346 foreach ($ids as $id) {
347 db_query($this->link
, "DELETE FROM ttrss_filters2 WHERE id = '$id' AND owner_uid = ". $_SESSION["uid"]);
351 private function saveRulesAndActions($filter_id) {
353 db_query($this->link
, "DELETE FROM ttrss_filters2_rules WHERE filter_id = '$filter_id'");
354 db_query($this->link
, "DELETE FROM ttrss_filters2_actions WHERE filter_id = '$filter_id'");
362 foreach ($_REQUEST["rule"] as $rule) {
363 $rule = json_decode($rule, true);
366 if (array_search($rule, $rules) === false) {
367 array_push($rules, $rule);
371 foreach ($_REQUEST["action"] as $action) {
372 $action = json_decode($action, true);
373 unset($action["id"]);
375 if (array_search($action, $actions) === false) {
376 array_push($actions, $action);
380 foreach ($rules as $rule) {
383 $reg_exp = strip_tags(db_escape_string(trim($rule["reg_exp"])));
384 $filter_type = (int) db_escape_string(trim($rule["filter_type"]));
385 $feed_id = db_escape_string(trim($rule["feed_id"]));
387 if (strpos($feed_id, "CAT:") === 0) {
388 $cat_filter = bool_to_sql_bool(true);
389 $cat_id = (int) substr($feed_id, 4);
392 if (!$cat_id) $cat_id = "NULL"; // Uncategorized
394 $cat_filter = bool_to_sql_bool(false);
395 $feed_id = (int) $feed_id;
398 if (!$feed_id) $feed_id = "NULL"; // Uncategorized
401 $query = "INSERT INTO ttrss_filters2_rules
402 (filter_id, reg_exp,filter_type,feed_id,cat_id,cat_filter) VALUES
403 ('$filter_id', '$reg_exp', '$filter_type', $feed_id, $cat_id, $cat_filter)";
405 db_query($this->link
, $query);
409 foreach ($actions as $action) {
412 $action_id = (int) db_escape_string($action["action_id"]);
413 $action_param = db_escape_string($action["action_param"]);
414 $action_param_label = db_escape_string($action["action_param_label"]);
416 if ($action_id == 7) {
417 $action_param = $action_param_label;
420 if ($action_id == 6) {
421 $action_param = (int) str_replace("+", "", $action_param);
424 $query = "INSERT INTO ttrss_filters2_actions
425 (filter_id, action_id, action_param) VALUES
426 ('$filter_id', '$action_id', '$action_param')";
428 db_query($this->link
, $query);
437 # print_r($_REQUEST);
439 $enabled = checkbox_to_sql_bool($_REQUEST["enabled"]);
440 $match_any_rule = checkbox_to_sql_bool($_REQUEST["match_any_rule"]);
442 db_query($this->link
, "BEGIN");
444 /* create base filter */
446 $result = db_query($this->link
, "INSERT INTO ttrss_filters2
447 (owner_uid, match_any_rule, enabled) VALUES
448 (".$_SESSION["uid"].",$match_any_rule,$enabled)");
450 $result = db_query($this->link
, "SELECT MAX(id) AS id FROM ttrss_filters2
451 WHERE owner_uid = ".$_SESSION["uid"]);
453 $filter_id = db_fetch_result($result, 0, "id");
455 $this->saveRulesAndActions($filter_id);
457 db_query($this->link
, "COMMIT");
462 $sort = db_escape_string($_REQUEST["sort"]);
464 if (!$sort ||
$sort == "undefined") {
468 $result = db_query($this->link
, "SELECT id,description
469 FROM ttrss_filter_types ORDER BY description");
471 $filter_types = array();
473 while ($line = db_fetch_assoc($result)) {
474 //array_push($filter_types, $line["description"]);
475 $filter_types[$line["id"]] = $line["description"];
479 $filter_search = db_escape_string($_REQUEST["search"]);
481 if (array_key_exists("search", $_REQUEST)) {
482 $_SESSION["prefs_filter_search"] = $filter_search;
484 $filter_search = $_SESSION["prefs_filter_search"];
487 print "<div id=\"pref-filter-wrap\" dojoType=\"dijit.layout.BorderContainer\" gutters=\"false\">";
488 print "<div id=\"pref-filter-header\" dojoType=\"dijit.layout.ContentPane\" region=\"top\">";
489 print "<div id=\"pref-filter-toolbar\" dojoType=\"dijit.Toolbar\">";
491 $filter_search = db_escape_string($_REQUEST["search"]);
493 if (array_key_exists("search", $_REQUEST)) {
494 $_SESSION["prefs_filter_search"] = $filter_search;
496 $filter_search = $_SESSION["prefs_filter_search"];
499 print "<div style='float : right; padding-right : 4px;'>
500 <input dojoType=\"dijit.form.TextBox\" id=\"filter_search\" size=\"20\" type=\"search\"
501 value=\"$filter_search\">
502 <button dojoType=\"dijit.form.Button\" onclick=\"updateFilterList()\">".
503 __('Search')."</button>
506 print "<div dojoType=\"dijit.form.DropDownButton\">".
507 "<span>" . __('Select')."</span>";
508 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
509 print "<div onclick=\"dijit.byId('filterTree').model.setAllChecked(true)\"
510 dojoType=\"dijit.MenuItem\">".__('All')."</div>";
511 print "<div onclick=\"dijit.byId('filterTree').model.setAllChecked(false)\"
512 dojoType=\"dijit.MenuItem\">".__('None')."</div>";
513 print "</div></div>";
515 print "<button dojoType=\"dijit.form.Button\" onclick=\"return quickAddFilter()\">".
516 __('Create filter')."</button> ";
518 print "<button dojoType=\"dijit.form.Button\" onclick=\"return joinSelectedFilters()\">".
519 __('Combine')."</button> ";
521 print "<button dojoType=\"dijit.form.Button\" onclick=\"return editSelectedFilter()\">".
522 __('Edit')."</button> ";
524 print "<button dojoType=\"dijit.form.Button\" onclick=\"return removeSelectedFilters()\">".
525 __('Remove')."</button> ";
527 if (defined('_ENABLE_FEED_DEBUGGING')) {
528 print "<button dojoType=\"dijit.form.Button\" onclick=\"rescore_all_feeds()\">".
529 __('Rescore articles')."</button> ";
532 print "</div>"; # toolbar
533 print "</div>"; # toolbar-frame
534 print "<div id=\"pref-filter-content\" dojoType=\"dijit.layout.ContentPane\" region=\"center\">";
536 print "<div id=\"filterlistLoading\">
537 <img src='images/indicator_tiny.gif'>".
538 __("Loading, please wait...")."</div>";
540 print "<div dojoType=\"dojo.data.ItemFileWriteStore\" jsId=\"filterStore\"
541 url=\"backend.php?op=pref-filters&method=getfiltertree\">
543 <div dojoType=\"lib.CheckBoxStoreModel\" jsId=\"filterModel\" store=\"filterStore\"
544 query=\"{id:'root'}\" rootId=\"root\" rootLabel=\"Feeds\"
545 childrenAttrs=\"items\" checkboxStrict=\"false\" checkboxAll=\"false\">
547 <div dojoType=\"fox.PrefFilterTree\" id=\"filterTree\"
548 model=\"filterModel\" openOnClick=\"true\">
549 <script type=\"dojo/method\" event=\"onLoad\" args=\"item\">
550 Element.hide(\"filterlistLoading\");
552 <script type=\"dojo/method\" event=\"onClick\" args=\"item\">
553 var id = String(item.id);
554 var bare_id = id.substr(id.indexOf(':')+1);
556 if (id.match('FILTER:')) {
563 print "</div>"; #pane
564 print "</div>"; #container
568 function newfilter() {
570 print "<form name='filter_new_form' id='filter_new_form'>";
572 $active_feed_id = (int) db_escape_string($_REQUEST["feed"]);
573 $cat_filter = db_escape_string($_REQUEST["is_cat"]) == "true";
575 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-filters\">";
576 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"add\">";
577 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"csrf_token\" value=\"".$_SESSION['csrf_token']."\">";
579 print "<div class=\"dlgSec\">".__("Match")."</div>";
581 print "<div dojoType=\"dijit.Toolbar\">";
583 print "<div dojoType=\"dijit.form.DropDownButton\">".
584 "<span>" . __('Select')."</span>";
585 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
586 print "<div onclick=\"dijit.byId('filterEditDlg').selectRules(true)\"
587 dojoType=\"dijit.MenuItem\">".__('All')."</div>";
588 print "<div onclick=\"dijit.byId('filterEditDlg').selectRules(false)\"
589 dojoType=\"dijit.MenuItem\">".__('None')."</div>";
590 print "</div></div>";
592 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').addRule()\">".
593 __('Add')."</button> ";
595 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').deleteRule()\">".
596 __('Delete')."</button> ";
600 print "<ul id='filterDlg_Matches'>";
601 # print "<li>No rules</li>";
606 print "<div class=\"dlgSec\">".__("Apply actions")."</div>";
608 print "<div dojoType=\"dijit.Toolbar\">";
610 print "<div dojoType=\"dijit.form.DropDownButton\">".
611 "<span>" . __('Select')."</span>";
612 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
613 print "<div onclick=\"dijit.byId('filterEditDlg').selectActions(true)\"
614 dojoType=\"dijit.MenuItem\">".__('All')."</div>";
615 print "<div onclick=\"dijit.byId('filterEditDlg').selectActions(false)\"
616 dojoType=\"dijit.MenuItem\">".__('None')."</div>";
617 print "</div></div>";
619 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').addAction()\">".
620 __('Add')."</button> ";
622 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').deleteAction()\">".
623 __('Delete')."</button> ";
627 print "<ul id='filterDlg_Actions'>";
628 # print "<li>No actions</li>";
631 /* print "<div class=\"dlgSec\">".__("Options")."</div>";
632 print "<div class=\"dlgSecCont\">"; */
634 print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"enabled\" id=\"enabled\" checked=\"1\">
635 <label for=\"enabled\">".__('Enabled')."</label>";
637 print "<br/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"match_any_rule\" id=\"match_any_rule\">
638 <label for=\"match_any_rule\">".__('Match any rule')."</label>";
642 /* print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"inverse\" id=\"inverse\">
643 <label for=\"inverse\">".__('Inverse match')."</label><hr/>"; */
647 print "<div class=\"dlgButtons\">";
649 # print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').test()\">".
650 # __('Test')."</button> ";
652 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').execute()\">".
653 __('Create')."</button> ";
655 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').hide()\">".
656 __('Cancel')."</button>";
663 $rule = json_decode($_REQUEST["rule"], true);
666 $reg_exp = htmlspecialchars($rule["reg_exp"]);
667 $filter_type = $rule["filter_type"];
668 $feed_id = $rule["feed_id"];
675 if (strpos($feed_id, "CAT:") === 0) {
676 $feed_id = substr($feed_id, 4);
683 print "<form name='filter_new_rule_form' id='filter_new_rule_form'>";
685 $result = db_query($this->link
, "SELECT id,description
686 FROM ttrss_filter_types ORDER BY description");
688 $filter_types = array();
690 while ($line = db_fetch_assoc($result)) {
691 $filter_types[$line["id"]] = __($line["description"]);
694 print "<div class=\"dlgSec\">".__("Match")."</div>";
696 print "<div class=\"dlgSecCont\">";
698 print "<input dojoType=\"dijit.form.ValidationTextBox\"
699 required=\"true\" id=\"filterDlg_regExp\"
700 style=\"font-size : 16px\"
701 name=\"reg_exp\" value=\"$reg_exp\"/>";
703 print "<hr/>" . __("on field") . " ";
704 print_select_hash("filter_type", $filter_type, $filter_types,
705 'dojoType="dijit.form.Select"');
709 print __("in") . " ";
711 print "<span id='filterDlg_feeds'>";
712 print_feed_select($this->link
, "feed_id",
713 $cat_filter ?
"CAT:$feed_id" : $feed_id,
714 'dojoType="dijit.form.FilteringSelect"');
719 print "<div class=\"dlgButtons\">";
721 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterNewRuleDlg').execute()\">".
722 ($rule ?
__("Save rule") : __('Add rule'))."</button> ";
724 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterNewRuleDlg').hide()\">".
725 __('Cancel')."</button>";
732 function newaction() {
733 $action = json_decode($_REQUEST["action"], true);
736 $action_param = db_escape_string($action["action_param"]);
737 $action_id = (int)$action["action_id"];
743 print "<form name='filter_new_action_form' id='filter_new_action_form'>";
745 print "<div class=\"dlgSec\">".__("Perform Action")."</div>";
747 print "<div class=\"dlgSecCont\">";
749 print "<select name=\"action_id\" dojoType=\"dijit.form.Select\"
750 onchange=\"filterDlgCheckAction(this)\">";
752 $result = db_query($this->link
, "SELECT id,description FROM ttrss_filter_actions
755 while ($line = db_fetch_assoc($result)) {
756 $is_selected = ($line["id"] == $action_id) ?
"selected='1'" : "";
757 printf("<option $is_selected value='%d'>%s</option>", $line["id"], __($line["description"]));
762 $param_box_hidden = ($action_id == 7 ||
$action_id == 4 ||
$action_id == 6) ?
763 "" : "display : none";
765 $param_hidden = ($action_id == 4 ||
$action_id == 6) ?
766 "" : "display : none";
768 $label_param_hidden = ($action_id == 7) ?
"" : "display : none";
770 print "<span id=\"filterDlg_paramBox\" style=\"$param_box_hidden\">";
771 print " " . __("with parameters:") . " ";
772 print "<input dojoType=\"dijit.form.TextBox\"
773 id=\"filterDlg_actionParam\" style=\"$param_hidden\"
774 name=\"action_param\" value=\"$action_param\">";
776 print_label_select($this->link
, "action_param_label", $action_param,
777 "id=\"filterDlg_actionParamLabel\" style=\"$label_param_hidden\"
778 dojoType=\"dijit.form.Select\"");
782 print " "; // tiny layout hack
786 print "<div class=\"dlgButtons\">";
788 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterNewActionDlg').execute()\">".
789 ($action ?
__("Save action") : __('Add action'))."</button> ";
791 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterNewActionDlg').hide()\">".
792 __('Cancel')."</button>";
799 private function getFilterName($id) {
800 $result = db_query($this->link
,
801 "SELECT * FROM ttrss_filters2_rules WHERE filter_id = '$id' ORDER BY id
807 while ($line = db_fetch_assoc($result)) {
809 if ($line["cat_filter"]) {
810 unset($line["cat_filter"]);
811 $line["feed_id"] = "CAT:" . (int)$line["cat_id"];
812 unset($line["cat_id"]);
816 array_push($titles, $this->getRuleName($line));
818 array_push($titles, "...");
824 $result = db_query($this->link
,
825 "SELECT * FROM ttrss_filters2_actions WHERE filter_id = '$id' ORDER BY id LIMIT 3");
830 while ($line = db_fetch_assoc($result)) {
832 array_push($actions, $this->getActionName($line));
834 array_push($actions, "...");
840 return array(join(", ", $titles), join(", ", $actions));
844 $ids = explode(",", db_escape_string($_REQUEST["ids"]));
846 if (count($ids) > 1) {
847 $base_id = array_shift($ids);
848 $ids_str = join(",", $ids);
850 db_query($this->link
, "BEGIN");
851 db_query($this->link
, "UPDATE ttrss_filters2_rules
852 SET filter_id = '$base_id' WHERE filter_id IN ($ids_str)");
853 db_query($this->link
, "UPDATE ttrss_filters2_actions
854 SET filter_id = '$base_id' WHERE filter_id IN ($ids_str)");
856 db_query($this->link
, "DELETE FROM ttrss_filters2 WHERE id IN ($ids_str)");
857 db_query($this->link
, "UPDATE ttrss_filters2 SET match_any_rule = true WHERE id = '$base_id'");
859 db_query($this->link
, "COMMIT");
861 $this->optimizeFilter($base_id);
866 private function optimizeFilter($id) {
867 db_query($this->link
, "BEGIN");
868 $result = db_query($this->link
, "SELECT * FROM ttrss_filters2_actions
869 WHERE filter_id = '$id'");
874 while ($line = db_fetch_assoc($result)) {
878 if (array_search($line, $tmp) === false) {
879 array_push($tmp, $line);
881 array_push($dupe_ids, $id);
885 if (count($dupe_ids) > 0) {
886 $ids_str = join(",", $dupe_ids);
887 db_query($this->link
, "DELETE FROM ttrss_filters2_actions
888 WHERE id IN ($ids_str)");
891 $result = db_query($this->link
, "SELECT * FROM ttrss_filters2_rules
892 WHERE filter_id = '$id'");
897 while ($line = db_fetch_assoc($result)) {
901 if (array_search($line, $tmp) === false) {
902 array_push($tmp, $line);
904 array_push($dupe_ids, $id);
908 if (count($dupe_ids) > 0) {
909 $ids_str = join(",", $dupe_ids);
910 db_query($this->link
, "DELETE FROM ttrss_filters2_rules
911 WHERE id IN ($ids_str)");
914 db_query($this->link
, "COMMIT");