]>
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'] = sql_bool_to_bool($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 (sql_bool_to_bool($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) {
389 $cat_filter = bool_to_sql_bool(true);
390 $cat_id = (int) substr($feed_id, 4);
393 if (!$cat_id) $cat_id = "NULL"; // Uncategorized
395 $cat_filter = bool_to_sql_bool(false);
396 $feed_id = (int) $feed_id;
399 if (!$feed_id) $feed_id = "NULL"; // Uncategorized
402 $query = "INSERT INTO ttrss_filters2_rules
403 (filter_id, reg_exp,filter_type,feed_id,cat_id,cat_filter) VALUES
404 ('$filter_id', '$reg_exp', '$filter_type', $feed_id, $cat_id, $cat_filter)";
406 db_query($this->link
, $query);
410 foreach ($actions as $action) {
413 $action_id = (int) db_escape_string($action["action_id"]);
414 $action_param = db_escape_string($action["action_param"]);
415 $action_param_label = db_escape_string($action["action_param_label"]);
417 if ($action_id == 7) {
418 $action_param = $action_param_label;
421 if ($action_id == 6) {
422 $action_param = (int) str_replace("+", "", $action_param);
425 $query = "INSERT INTO ttrss_filters2_actions
426 (filter_id, action_id, action_param) VALUES
427 ('$filter_id', '$action_id', '$action_param')";
429 db_query($this->link
, $query);
438 # print_r($_REQUEST);
440 $enabled = checkbox_to_sql_bool($_REQUEST["enabled"]);
441 $match_any_rule = checkbox_to_sql_bool($_REQUEST["match_any_rule"]);
443 db_query($this->link
, "BEGIN");
445 /* create base filter */
447 $result = db_query($this->link
, "INSERT INTO ttrss_filters2
448 (owner_uid, match_any_rule, enabled) VALUES
449 (".$_SESSION["uid"].",$match_any_rule,$enabled)");
451 $result = db_query($this->link
, "SELECT MAX(id) AS id FROM ttrss_filters2
452 WHERE owner_uid = ".$_SESSION["uid"]);
454 $filter_id = db_fetch_result($result, 0, "id");
456 $this->saveRulesAndActions($filter_id);
458 db_query($this->link
, "COMMIT");
463 $sort = db_escape_string($_REQUEST["sort"]);
465 if (!$sort ||
$sort == "undefined") {
469 $result = db_query($this->link
, "SELECT id,description
470 FROM ttrss_filter_types ORDER BY description");
472 $filter_types = array();
474 while ($line = db_fetch_assoc($result)) {
475 //array_push($filter_types, $line["description"]);
476 $filter_types[$line["id"]] = $line["description"];
480 $filter_search = db_escape_string($_REQUEST["search"]);
482 if (array_key_exists("search", $_REQUEST)) {
483 $_SESSION["prefs_filter_search"] = $filter_search;
485 $filter_search = $_SESSION["prefs_filter_search"];
488 print "<div id=\"pref-filter-wrap\" dojoType=\"dijit.layout.BorderContainer\" gutters=\"false\">";
489 print "<div id=\"pref-filter-header\" dojoType=\"dijit.layout.ContentPane\" region=\"top\">";
490 print "<div id=\"pref-filter-toolbar\" dojoType=\"dijit.Toolbar\">";
492 $filter_search = db_escape_string($_REQUEST["search"]);
494 if (array_key_exists("search", $_REQUEST)) {
495 $_SESSION["prefs_filter_search"] = $filter_search;
497 $filter_search = $_SESSION["prefs_filter_search"];
500 print "<div style='float : right; padding-right : 4px;'>
501 <input dojoType=\"dijit.form.TextBox\" id=\"filter_search\" size=\"20\" type=\"search\"
502 value=\"$filter_search\">
503 <button dojoType=\"dijit.form.Button\" onclick=\"updateFilterList()\">".
504 __('Search')."</button>
507 print "<div dojoType=\"dijit.form.DropDownButton\">".
508 "<span>" . __('Select')."</span>";
509 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
510 print "<div onclick=\"dijit.byId('filterTree').model.setAllChecked(true)\"
511 dojoType=\"dijit.MenuItem\">".__('All')."</div>";
512 print "<div onclick=\"dijit.byId('filterTree').model.setAllChecked(false)\"
513 dojoType=\"dijit.MenuItem\">".__('None')."</div>";
514 print "</div></div>";
516 print "<button dojoType=\"dijit.form.Button\" onclick=\"return quickAddFilter()\">".
517 __('Create filter')."</button> ";
519 print "<button dojoType=\"dijit.form.Button\" onclick=\"return joinSelectedFilters()\">".
520 __('Combine')."</button> ";
522 print "<button dojoType=\"dijit.form.Button\" onclick=\"return editSelectedFilter()\">".
523 __('Edit')."</button> ";
525 print "<button dojoType=\"dijit.form.Button\" onclick=\"return removeSelectedFilters()\">".
526 __('Remove')."</button> ";
528 if (defined('_ENABLE_FEED_DEBUGGING')) {
529 print "<button dojoType=\"dijit.form.Button\" onclick=\"rescore_all_feeds()\">".
530 __('Rescore articles')."</button> ";
533 print "</div>"; # toolbar
534 print "</div>"; # toolbar-frame
535 print "<div id=\"pref-filter-content\" dojoType=\"dijit.layout.ContentPane\" region=\"center\">";
537 print "<div id=\"filterlistLoading\">
538 <img src='images/indicator_tiny.gif'>".
539 __("Loading, please wait...")."</div>";
541 print "<div dojoType=\"dojo.data.ItemFileWriteStore\" jsId=\"filterStore\"
542 url=\"backend.php?op=pref-filters&method=getfiltertree\">
544 <div dojoType=\"lib.CheckBoxStoreModel\" jsId=\"filterModel\" store=\"filterStore\"
545 query=\"{id:'root'}\" rootId=\"root\" rootLabel=\"Feeds\"
546 childrenAttrs=\"items\" checkboxStrict=\"false\" checkboxAll=\"false\">
548 <div dojoType=\"fox.PrefFilterTree\" id=\"filterTree\"
549 model=\"filterModel\" openOnClick=\"true\">
550 <script type=\"dojo/method\" event=\"onLoad\" args=\"item\">
551 Element.hide(\"filterlistLoading\");
553 <script type=\"dojo/method\" event=\"onClick\" args=\"item\">
554 var id = String(item.id);
555 var bare_id = id.substr(id.indexOf(':')+1);
557 if (id.match('FILTER:')) {
564 print "</div>"; #pane
565 print "</div>"; #container
569 function newfilter() {
571 print "<form name='filter_new_form' id='filter_new_form'>";
573 $active_feed_id = (int) db_escape_string($_REQUEST["feed"]);
574 $cat_filter = db_escape_string($_REQUEST["is_cat"]) == "true";
576 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-filters\">";
577 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"add\">";
578 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"csrf_token\" value=\"".$_SESSION['csrf_token']."\">";
580 print "<div class=\"dlgSec\">".__("Match")."</div>";
582 print "<div dojoType=\"dijit.Toolbar\">";
584 print "<div dojoType=\"dijit.form.DropDownButton\">".
585 "<span>" . __('Select')."</span>";
586 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
587 print "<div onclick=\"dijit.byId('filterEditDlg').selectRules(true)\"
588 dojoType=\"dijit.MenuItem\">".__('All')."</div>";
589 print "<div onclick=\"dijit.byId('filterEditDlg').selectRules(false)\"
590 dojoType=\"dijit.MenuItem\">".__('None')."</div>";
591 print "</div></div>";
593 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').addRule()\">".
594 __('Add')."</button> ";
596 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').deleteRule()\">".
597 __('Delete')."</button> ";
601 print "<ul id='filterDlg_Matches'>";
602 # print "<li>No rules</li>";
607 print "<div class=\"dlgSec\">".__("Apply actions")."</div>";
609 print "<div dojoType=\"dijit.Toolbar\">";
611 print "<div dojoType=\"dijit.form.DropDownButton\">".
612 "<span>" . __('Select')."</span>";
613 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
614 print "<div onclick=\"dijit.byId('filterEditDlg').selectActions(true)\"
615 dojoType=\"dijit.MenuItem\">".__('All')."</div>";
616 print "<div onclick=\"dijit.byId('filterEditDlg').selectActions(false)\"
617 dojoType=\"dijit.MenuItem\">".__('None')."</div>";
618 print "</div></div>";
620 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').addAction()\">".
621 __('Add')."</button> ";
623 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').deleteAction()\">".
624 __('Delete')."</button> ";
628 print "<ul id='filterDlg_Actions'>";
629 # print "<li>No actions</li>";
632 /* print "<div class=\"dlgSec\">".__("Options")."</div>";
633 print "<div class=\"dlgSecCont\">"; */
635 print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"enabled\" id=\"enabled\" checked=\"1\">
636 <label for=\"enabled\">".__('Enabled')."</label>";
638 print "<br/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"match_any_rule\" id=\"match_any_rule\">
639 <label for=\"match_any_rule\">".__('Match any rule')."</label>";
643 /* print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"inverse\" id=\"inverse\">
644 <label for=\"inverse\">".__('Inverse match')."</label><hr/>"; */
648 print "<div class=\"dlgButtons\">";
650 # print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').test()\">".
651 # __('Test')."</button> ";
653 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').execute()\">".
654 __('Create')."</button> ";
656 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').hide()\">".
657 __('Cancel')."</button>";
664 $rule = json_decode($_REQUEST["rule"], true);
667 $reg_exp = htmlspecialchars($rule["reg_exp"]);
668 $filter_type = $rule["filter_type"];
669 $feed_id = $rule["feed_id"];
676 if (strpos($feed_id, "CAT:") === 0) {
677 $feed_id = substr($feed_id, 4);
684 print "<form name='filter_new_rule_form' id='filter_new_rule_form'>";
686 $result = db_query($this->link
, "SELECT id,description
687 FROM ttrss_filter_types ORDER BY description");
689 $filter_types = array();
691 while ($line = db_fetch_assoc($result)) {
692 $filter_types[$line["id"]] = __($line["description"]);
695 print "<div class=\"dlgSec\">".__("Match")."</div>";
697 print "<div class=\"dlgSecCont\">";
699 print "<input dojoType=\"dijit.form.ValidationTextBox\"
700 required=\"true\" id=\"filterDlg_regExp\"
701 style=\"font-size : 16px\"
702 name=\"reg_exp\" value=\"$reg_exp\"/>";
704 print "<hr/>" . __("on field") . " ";
705 print_select_hash("filter_type", $filter_type, $filter_types,
706 'dojoType="dijit.form.Select"');
710 print __("in") . " ";
712 print "<span id='filterDlg_feeds'>";
713 print_feed_select($this->link
, "feed_id",
714 $cat_filter ?
"CAT:$feed_id" : $feed_id,
715 'dojoType="dijit.form.FilteringSelect"');
720 print "<div class=\"dlgButtons\">";
722 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterNewRuleDlg').execute()\">".
723 ($rule ?
__("Save rule") : __('Add rule'))."</button> ";
725 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterNewRuleDlg').hide()\">".
726 __('Cancel')."</button>";
733 function newaction() {
734 $action = json_decode($_REQUEST["action"], true);
737 $action_param = db_escape_string($action["action_param"]);
738 $action_id = (int)$action["action_id"];
744 print "<form name='filter_new_action_form' id='filter_new_action_form'>";
746 print "<div class=\"dlgSec\">".__("Perform Action")."</div>";
748 print "<div class=\"dlgSecCont\">";
750 print "<select name=\"action_id\" dojoType=\"dijit.form.Select\"
751 onchange=\"filterDlgCheckAction(this)\">";
753 $result = db_query($this->link
, "SELECT id,description FROM ttrss_filter_actions
756 while ($line = db_fetch_assoc($result)) {
757 $is_selected = ($line["id"] == $action_id) ?
"selected='1'" : "";
758 printf("<option $is_selected value='%d'>%s</option>", $line["id"], __($line["description"]));
763 $param_box_hidden = ($action_id == 7 ||
$action_id == 4 ||
$action_id == 6) ?
764 "" : "display : none";
766 $param_hidden = ($action_id == 4 ||
$action_id == 6) ?
767 "" : "display : none";
769 $label_param_hidden = ($action_id == 7) ?
"" : "display : none";
771 print "<span id=\"filterDlg_paramBox\" style=\"$param_box_hidden\">";
772 print " " . __("with parameters:") . " ";
773 print "<input dojoType=\"dijit.form.TextBox\"
774 id=\"filterDlg_actionParam\" style=\"$param_hidden\"
775 name=\"action_param\" value=\"$action_param\">";
777 print_label_select($this->link
, "action_param_label", $action_param,
778 "id=\"filterDlg_actionParamLabel\" style=\"$label_param_hidden\"
779 dojoType=\"dijit.form.Select\"");
783 print " "; // tiny layout hack
787 print "<div class=\"dlgButtons\">";
789 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterNewActionDlg').execute()\">".
790 ($action ?
__("Save action") : __('Add action'))."</button> ";
792 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterNewActionDlg').hide()\">".
793 __('Cancel')."</button>";
800 private function getFilterName($id) {
801 $result = db_query($this->link
,
802 "SELECT * FROM ttrss_filters2_rules WHERE filter_id = '$id' ORDER BY id
808 while ($line = db_fetch_assoc($result)) {
810 if (sql_bool_to_bool($line["cat_filter"])) {
811 unset($line["cat_filter"]);
812 $line["feed_id"] = "CAT:" . (int)$line["cat_id"];
813 unset($line["cat_id"]);
817 array_push($titles, $this->getRuleName($line));
819 array_push($titles, "...");
825 $result = db_query($this->link
,
826 "SELECT * FROM ttrss_filters2_actions WHERE filter_id = '$id' ORDER BY id LIMIT 3");
831 while ($line = db_fetch_assoc($result)) {
833 array_push($actions, $this->getActionName($line));
835 array_push($actions, "...");
841 return array(join(", ", $titles), join(", ", $actions));
845 $ids = explode(",", db_escape_string($_REQUEST["ids"]));
847 if (count($ids) > 1) {
848 $base_id = array_shift($ids);
849 $ids_str = join(",", $ids);
851 db_query($this->link
, "BEGIN");
852 db_query($this->link
, "UPDATE ttrss_filters2_rules
853 SET filter_id = '$base_id' WHERE filter_id IN ($ids_str)");
854 db_query($this->link
, "UPDATE ttrss_filters2_actions
855 SET filter_id = '$base_id' WHERE filter_id IN ($ids_str)");
857 db_query($this->link
, "DELETE FROM ttrss_filters2 WHERE id IN ($ids_str)");
858 db_query($this->link
, "UPDATE ttrss_filters2 SET match_any_rule = true WHERE id = '$base_id'");
860 db_query($this->link
, "COMMIT");
862 $this->optimizeFilter($base_id);
867 private function optimizeFilter($id) {
868 db_query($this->link
, "BEGIN");
869 $result = db_query($this->link
, "SELECT * FROM ttrss_filters2_actions
870 WHERE filter_id = '$id'");
875 while ($line = db_fetch_assoc($result)) {
879 if (array_search($line, $tmp) === false) {
880 array_push($tmp, $line);
882 array_push($dupe_ids, $id);
886 if (count($dupe_ids) > 0) {
887 $ids_str = join(",", $dupe_ids);
888 db_query($this->link
, "DELETE FROM ttrss_filters2_actions
889 WHERE id IN ($ids_str)");
892 $result = db_query($this->link
, "SELECT * FROM ttrss_filters2_rules
893 WHERE filter_id = '$id'");
898 while ($line = db_fetch_assoc($result)) {
902 if (array_search($line, $tmp) === false) {
903 array_push($tmp, $line);
905 array_push($dupe_ids, $id);
909 if (count($dupe_ids) > 0) {
910 $ids_str = join(",", $dupe_ids);
911 db_query($this->link
, "DELETE FROM ttrss_filters2_rules
912 WHERE id IN ($ids_str)");
915 db_query($this->link
, "COMMIT");