]>
git.wh0rd.org - tt-rss.git/blob - classes/pref/filters.php
2 class Pref_Filters
extends Handler_Protected
{
4 function csrf_ignore($method) {
5 $csrf_ignored = array("index", "getfiltertree", "edit", "newfilter", "newrule",
8 return array_search($method, $csrf_ignored) !== false;
11 function testFilter() {
14 $filter["enabled"] = true;
15 $filter["match_any_rule"] = sql_bool_to_bool(
16 checkbox_to_sql_bool(db_escape_string($this->link
, $_REQUEST["match_any_rule"])));
17 $filter["inverse"] = sql_bool_to_bool(
18 checkbox_to_sql_bool(db_escape_string($this->link
, $_REQUEST["inverse"])));
20 $filter["rules"] = array();
22 $result = db_query($this->link
, "SELECT id,name FROM ttrss_filter_types");
24 $filter_types = array();
25 while ($line = db_fetch_assoc($result)) {
26 $filter_types[$line["id"]] = $line["name"];
30 foreach ($_REQUEST["rule"] AS $r) {
31 $rule = json_decode($r, true);
33 if ($rule && $rctr < 5) {
34 $rule["type"] = $filter_types[$rule["filter_type"]];
35 unset($rule["filter_type"]);
37 if (strpos($rule["feed_id"], "CAT:") === 0) {
38 $rule["cat_id"] = (int) substr($rule["feed_id"], 4);
39 unset($rule["feed_id"]);
42 array_push($filter["rules"], $rule);
50 $feed_title = getFeedTitle($this->link
, $feed);
52 $qfh_ret = queryFeedHeadlines($this->link
, -4, 30, "", false, false, false,
53 "date_entered DESC", 0, $_SESSION["uid"], $filter);
55 $result = $qfh_ret[0];
60 print __("Articles matching this filter:");
62 print "<div class=\"filterTestHolder\">";
63 print "<table width=\"100%\" cellspacing=\"0\" id=\"prefErrorFeedList\">";
65 while ($line = db_fetch_assoc($result)) {
67 $entry_timestamp = strtotime($line["updated"]);
68 $entry_tags = get_article_tags($this->link
, $line["id"], $_SESSION["uid"]);
70 $content_preview = truncate_string(
71 strip_tags($line["content_preview"]), 100, '...');
73 if ($line["feed_title"])
74 $feed_title = $line["feed_title"];
78 print "<td width='5%' align='center'><input
79 dojoType=\"dijit.form.CheckBox\" checked=\"1\"
80 disabled=\"1\" type=\"checkbox\"></td>";
85 print "<b>" . $feed_title . "</b>";
87 print "<span class=\"insensitive\">" . $content_preview . "</span>";
88 print " " . mb_substr($line["date_entered"], 0, 16);
96 print "<tr><td align='center'>" .
97 __("No recent articles matching this filter have been found.");
99 print "</td></tr><tr><td class='insensitive' align='center'>";
101 print __("Complex expressions might not give results while testing due to issues with database server regexp implementation.");
107 print "</table></div>";
109 print "<div style='text-align : center'>";
110 print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('filterTestDlg').hide()\">".
111 __('Close this window')."</button>";
117 function getfiltertree() {
119 $root['id'] = 'root';
120 $root['name'] = __('Filters');
121 $root['items'] = array();
123 $filter_search = $_SESSION["prefs_filter_search"];
125 $result = db_query($this->link
, "SELECT *,
126 (SELECT action_param FROM ttrss_filters2_actions
127 WHERE filter_id = ttrss_filters2.id ORDER BY id LIMIT 1) AS action_param,
128 (SELECT action_id FROM ttrss_filters2_actions
129 WHERE filter_id = ttrss_filters2.id ORDER BY id LIMIT 1) AS action_id,
130 (SELECT description FROM ttrss_filter_actions
131 WHERE id = (SELECT action_id FROM ttrss_filters2_actions
132 WHERE filter_id = ttrss_filters2.id ORDER BY id LIMIT 1)) AS action_name,
133 (SELECT reg_exp FROM ttrss_filters2_rules
134 WHERE filter_id = ttrss_filters2.id ORDER BY id LIMIT 1) AS reg_exp
135 FROM ttrss_filters2 WHERE
136 owner_uid = ".$_SESSION["uid"]." ORDER BY action_id,reg_exp");
141 $folder['items'] = array();
143 while ($line = db_fetch_assoc($result)) {
145 if ($action_id != $line["action_id"]) {
146 if (count($folder['items']) > 0) {
147 array_push($root['items'], $folder);
151 $folder['id'] = $line["action_id"];
152 $folder['name'] = __($line["action_name"]);
153 $folder['items'] = array();
154 $action_id = $line["action_id"];
157 $name = $this->getFilterName($line["id"]);
160 if ($filter_search) {
161 $rules_result = db_query($this->link
,
162 "SELECT reg_exp FROM ttrss_filters2_rules WHERE filter_id = ".$line["id"]);
164 while ($rule_line = db_fetch_assoc($rules_result)) {
165 if (mb_strpos($rule_line['reg_exp'], $filter_search) !== false) {
172 if ($line['action_id'] == 7) {
173 $label_result = db_query($this->link
, "SELECT fg_color, bg_color
174 FROM ttrss_labels2 WHERE caption = '".db_escape_string($this->link
, $line['action_param'])."' AND
175 owner_uid = " . $_SESSION["uid"]);
177 if (db_num_rows($label_result) > 0) {
178 $fg_color = db_fetch_result($label_result, 0, "fg_color");
179 $bg_color = db_fetch_result($label_result, 0, "bg_color");
181 $name[1] = "<span class=\"labelColorIndicator\" id=\"label-editor-indicator\" style='color : $fg_color; background-color : $bg_color; margin-right : 4px'>α</span>" . $name[1];
186 $filter['id'] = 'FILTER:' . $line['id'];
187 $filter['bare_id'] = $line['id'];
188 $filter['name'] = $name[0];
189 $filter['param'] = $name[1];
190 $filter['checkbox'] = false;
191 $filter['enabled'] = sql_bool_to_bool($line["enabled"]);
193 if (!$filter_search ||
$match_ok) {
194 array_push($folder['items'], $filter);
198 if (count($folder['items']) > 0) {
199 array_push($root['items'], $folder);
203 $fl['identifier'] = 'id';
204 $fl['label'] = 'name';
205 $fl['items'] = array($root);
207 print json_encode($fl);
213 $filter_id = db_escape_string($this->link
, $_REQUEST["id"]);
215 $result = db_query($this->link
,
216 "SELECT * FROM ttrss_filters2 WHERE id = '$filter_id' AND owner_uid = " . $_SESSION["uid"]);
218 $enabled = sql_bool_to_bool(db_fetch_result($result, 0, "enabled"));
219 $match_any_rule = sql_bool_to_bool(db_fetch_result($result, 0, "match_any_rule"));
220 $inverse = sql_bool_to_bool(db_fetch_result($result, 0, "inverse"));
222 print "<form id=\"filter_edit_form\" onsubmit='return false'>";
224 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-filters\">";
225 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"id\" value=\"$filter_id\">";
226 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"editSave\">";
227 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"csrf_token\" value=\"".$_SESSION['csrf_token']."\">";
229 print "<div class=\"dlgSec\">".__("Match")."</div>";
231 print "<div dojoType=\"dijit.Toolbar\">";
233 print "<div dojoType=\"dijit.form.DropDownButton\">".
234 "<span>" . __('Select')."</span>";
235 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
236 print "<div onclick=\"dijit.byId('filterEditDlg').selectRules(true)\"
237 dojoType=\"dijit.MenuItem\">".__('All')."</div>";
238 print "<div onclick=\"dijit.byId('filterEditDlg').selectRules(false)\"
239 dojoType=\"dijit.MenuItem\">".__('None')."</div>";
240 print "</div></div>";
242 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').addRule()\">".
243 __('Add')."</button> ";
245 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').deleteRule()\">".
246 __('Delete')."</button> ";
250 print "<ul id='filterDlg_Matches'>";
252 $rules_result = db_query($this->link
, "SELECT * FROM ttrss_filters2_rules
253 WHERE filter_id = '$filter_id' ORDER BY reg_exp, id");
255 while ($line = db_fetch_assoc($rules_result)) {
256 if (sql_bool_to_bool($line["cat_filter"])) {
257 $line["feed_id"] = "CAT:" . (int)$line["cat_id"];
260 unset($line["cat_filter"]);
261 unset($line["cat_id"]);
262 unset($line["filter_id"]);
264 if (!sql_bool_to_bool($line["inverse"])) unset($line["inverse"]);
266 $data = htmlspecialchars(json_encode($line));
268 print "<li><input dojoType='dijit.form.CheckBox' type='checkbox' onclick='toggleSelectListRow2(this)'>".
269 "<span onclick=\"dijit.byId('filterEditDlg').editRule(this)\">".$this->getRuleName($line)."</span>".
270 "<input type='hidden' name='rule[]' value=\"$data\"/></li>";
277 print "<div class=\"dlgSec\">".__("Apply actions")."</div>";
279 print "<div dojoType=\"dijit.Toolbar\">";
281 print "<div dojoType=\"dijit.form.DropDownButton\">".
282 "<span>" . __('Select')."</span>";
283 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
284 print "<div onclick=\"dijit.byId('filterEditDlg').selectActions(true)\"
285 dojoType=\"dijit.MenuItem\">".__('All')."</div>";
286 print "<div onclick=\"dijit.byId('filterEditDlg').selectActions(false)\"
287 dojoType=\"dijit.MenuItem\">".__('None')."</div>";
288 print "</div></div>";
290 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').addAction()\">".
291 __('Add')."</button> ";
293 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').deleteAction()\">".
294 __('Delete')."</button> ";
298 print "<ul id='filterDlg_Actions'>";
300 $actions_result = db_query($this->link
, "SELECT * FROM ttrss_filters2_actions
301 WHERE filter_id = '$filter_id' ORDER BY id");
303 while ($line = db_fetch_assoc($actions_result)) {
304 $line["action_param_label"] = $line["action_param"];
306 unset($line["filter_id"]);
309 $data = htmlspecialchars(json_encode($line));
311 print "<li><input dojoType='dijit.form.CheckBox' type='checkbox' onclick='toggleSelectListRow2(this)'>".
312 "<span onclick=\"dijit.byId('filterEditDlg').editAction(this)\">".$this->getActionName($line)."</span>".
313 "<input type='hidden' name='action[]' value=\"$data\"/></li>";
321 $checked = "checked=\"1\"";
326 print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"enabled\" id=\"enabled\" $checked>
327 <label for=\"enabled\">".__('Enabled')."</label>";
329 if ($match_any_rule) {
330 $checked = "checked=\"1\"";
335 print "<br/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"match_any_rule\" id=\"match_any_rule\" $checked>
336 <label for=\"match_any_rule\">".__('Match any rule')."</label>";
339 $checked = "checked=\"1\"";
344 print "<br/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"inverse\" id=\"inverse\" $checked>
345 <label for=\"inverse\">".__('Inverse matching')."</label>";
349 print "<div class=\"dlgButtons\">";
351 print "<div style=\"float : left\">";
352 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').removeFilter()\">".
353 __('Remove')."</button>";
356 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').test()\">".
357 __('Test')."</button> ";
359 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').execute()\">".
360 __('Save')."</button> ";
362 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').hide()\">".
363 __('Cancel')."</button>";
368 private function getRuleName($rule) {
369 if (!$rule) $rule = json_decode($_REQUEST["rule"], true);
371 $feed_id = $rule["feed_id"];
373 if (strpos($feed_id, "CAT:") === 0) {
374 $feed_id = (int) substr($feed_id, 4);
375 $feed = getCategoryTitle($this->link
, $feed_id);
377 $feed_id = (int) $feed_id;
379 if ($rule["feed_id"])
380 $feed = getFeedTitle($this->link
, (int)$rule["feed_id"]);
382 $feed = __("All feeds");
385 $result = db_query($this->link
, "SELECT description FROM ttrss_filter_types
386 WHERE id = ".(int)$rule["filter_type"]);
387 $filter_type = db_fetch_result($result, 0, "description");
389 return T_sprintf("%s on %s in %s %s", strip_tags($rule["reg_exp"]),
390 $filter_type, $feed, isset($rule["inverse"]) ?
__("(inverse)") : "");
393 function printRuleName() {
394 print $this->getRuleName(json_decode($_REQUEST["rule"], true));
397 private function getActionName($action) {
398 $result = db_query($this->link
, "SELECT description FROM
399 ttrss_filter_actions WHERE id = " .(int)$action["action_id"]);
401 $title = __(db_fetch_result($result, 0, "description"));
403 if ($action["action_id"] == 4 ||
$action["action_id"] == 6 ||
404 $action["action_id"] == 7)
405 $title .= ": " . $action["action_param"];
410 function printActionName() {
411 print $this->getActionName(json_decode($_REQUEST["action"], true));
414 function editSave() {
415 if ($_REQUEST["savemode"] && $_REQUEST["savemode"] == "test") {
416 return $this->testFilter();
419 # print_r($_REQUEST);
421 $filter_id = db_escape_string($this->link
, $_REQUEST["id"]);
422 $enabled = checkbox_to_sql_bool(db_escape_string($this->link
, $_REQUEST["enabled"]));
423 $match_any_rule = checkbox_to_sql_bool(db_escape_string($this->link
, $_REQUEST["match_any_rule"]));
424 $inverse = checkbox_to_sql_bool(db_escape_string($this->link
, $_REQUEST["inverse"]));
426 $result = db_query($this->link
, "UPDATE ttrss_filters2 SET enabled = $enabled,
427 match_any_rule = $match_any_rule,
429 WHERE id = '$filter_id'
430 AND owner_uid = ". $_SESSION["uid"]);
432 $this->saveRulesAndActions($filter_id);
438 $ids = split(",", db_escape_string($this->link
, $_REQUEST["ids"]));
440 foreach ($ids as $id) {
441 db_query($this->link
, "DELETE FROM ttrss_filters2 WHERE id = '$id' AND owner_uid = ". $_SESSION["uid"]);
445 private function saveRulesAndActions($filter_id) {
447 db_query($this->link
, "DELETE FROM ttrss_filters2_rules WHERE filter_id = '$filter_id'");
448 db_query($this->link
, "DELETE FROM ttrss_filters2_actions WHERE filter_id = '$filter_id'");
456 foreach ($_REQUEST["rule"] as $rule) {
457 $rule = json_decode($rule, true);
460 if (array_search($rule, $rules) === false) {
461 array_push($rules, $rule);
465 foreach ($_REQUEST["action"] as $action) {
466 $action = json_decode($action, true);
467 unset($action["id"]);
469 if (array_search($action, $actions) === false) {
470 array_push($actions, $action);
474 foreach ($rules as $rule) {
477 $reg_exp = strip_tags(db_escape_string($this->link
, trim($rule["reg_exp"])));
478 $inverse = isset($rule["inverse"]) ?
"true" : "false";
480 $filter_type = (int) db_escape_string($this->link
, trim($rule["filter_type"]));
481 $feed_id = db_escape_string($this->link
, trim($rule["feed_id"]));
483 if (strpos($feed_id, "CAT:") === 0) {
485 $cat_filter = bool_to_sql_bool(true);
486 $cat_id = (int) substr($feed_id, 4);
489 if (!$cat_id) $cat_id = "NULL"; // Uncategorized
491 $cat_filter = bool_to_sql_bool(false);
492 $feed_id = (int) $feed_id;
495 if (!$feed_id) $feed_id = "NULL"; // Uncategorized
498 $query = "INSERT INTO ttrss_filters2_rules
499 (filter_id, reg_exp,filter_type,feed_id,cat_id,cat_filter,inverse) VALUES
500 ('$filter_id', '$reg_exp', '$filter_type', $feed_id, $cat_id, $cat_filter, $inverse)";
502 db_query($this->link
, $query);
506 foreach ($actions as $action) {
509 $action_id = (int) db_escape_string($this->link
, $action["action_id"]);
510 $action_param = db_escape_string($this->link
, $action["action_param"]);
511 $action_param_label = db_escape_string($this->link
, $action["action_param_label"]);
513 if ($action_id == 7) {
514 $action_param = $action_param_label;
517 if ($action_id == 6) {
518 $action_param = (int) str_replace("+", "", $action_param);
521 $query = "INSERT INTO ttrss_filters2_actions
522 (filter_id, action_id, action_param) VALUES
523 ('$filter_id', '$action_id', '$action_param')";
525 db_query($this->link
, $query);
534 if ($_REQUEST["savemode"] && $_REQUEST["savemode"] == "test") {
535 return $this->testFilter();
538 # print_r($_REQUEST);
540 $enabled = checkbox_to_sql_bool($_REQUEST["enabled"]);
541 $match_any_rule = checkbox_to_sql_bool($_REQUEST["match_any_rule"]);
543 db_query($this->link
, "BEGIN");
545 /* create base filter */
547 $result = db_query($this->link
, "INSERT INTO ttrss_filters2
548 (owner_uid, match_any_rule, enabled) VALUES
549 (".$_SESSION["uid"].",$match_any_rule,$enabled)");
551 $result = db_query($this->link
, "SELECT MAX(id) AS id FROM ttrss_filters2
552 WHERE owner_uid = ".$_SESSION["uid"]);
554 $filter_id = db_fetch_result($result, 0, "id");
556 $this->saveRulesAndActions($filter_id);
558 db_query($this->link
, "COMMIT");
563 $sort = db_escape_string($this->link
, $_REQUEST["sort"]);
565 if (!$sort ||
$sort == "undefined") {
569 $filter_search = db_escape_string($this->link
, $_REQUEST["search"]);
571 if (array_key_exists("search", $_REQUEST)) {
572 $_SESSION["prefs_filter_search"] = $filter_search;
574 $filter_search = $_SESSION["prefs_filter_search"];
577 print "<div id=\"pref-filter-wrap\" dojoType=\"dijit.layout.BorderContainer\" gutters=\"false\">";
578 print "<div id=\"pref-filter-header\" dojoType=\"dijit.layout.ContentPane\" region=\"top\">";
579 print "<div id=\"pref-filter-toolbar\" dojoType=\"dijit.Toolbar\">";
581 $filter_search = db_escape_string($this->link
, $_REQUEST["search"]);
583 if (array_key_exists("search", $_REQUEST)) {
584 $_SESSION["prefs_filter_search"] = $filter_search;
586 $filter_search = $_SESSION["prefs_filter_search"];
589 print "<div style='float : right; padding-right : 4px;'>
590 <input dojoType=\"dijit.form.TextBox\" id=\"filter_search\" size=\"20\" type=\"search\"
591 value=\"$filter_search\">
592 <button dojoType=\"dijit.form.Button\" onclick=\"updateFilterList()\">".
593 __('Search')."</button>
596 print "<div dojoType=\"dijit.form.DropDownButton\">".
597 "<span>" . __('Select')."</span>";
598 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
599 print "<div onclick=\"dijit.byId('filterTree').model.setAllChecked(true)\"
600 dojoType=\"dijit.MenuItem\">".__('All')."</div>";
601 print "<div onclick=\"dijit.byId('filterTree').model.setAllChecked(false)\"
602 dojoType=\"dijit.MenuItem\">".__('None')."</div>";
603 print "</div></div>";
605 print "<button dojoType=\"dijit.form.Button\" onclick=\"return quickAddFilter()\">".
606 __('Create filter')."</button> ";
608 print "<button dojoType=\"dijit.form.Button\" onclick=\"return joinSelectedFilters()\">".
609 __('Combine')."</button> ";
611 print "<button dojoType=\"dijit.form.Button\" onclick=\"return editSelectedFilter()\">".
612 __('Edit')."</button> ";
614 print "<button dojoType=\"dijit.form.Button\" onclick=\"return removeSelectedFilters()\">".
615 __('Remove')."</button> ";
617 if (defined('_ENABLE_FEED_DEBUGGING')) {
618 print "<button dojoType=\"dijit.form.Button\" onclick=\"rescore_all_feeds()\">".
619 __('Rescore articles')."</button> ";
622 print "</div>"; # toolbar
623 print "</div>"; # toolbar-frame
624 print "<div id=\"pref-filter-content\" dojoType=\"dijit.layout.ContentPane\" region=\"center\">";
626 print "<div id=\"filterlistLoading\">
627 <img src='images/indicator_tiny.gif'>".
628 __("Loading, please wait...")."</div>";
630 print "<div dojoType=\"dojo.data.ItemFileWriteStore\" jsId=\"filterStore\"
631 url=\"backend.php?op=pref-filters&method=getfiltertree\">
633 <div dojoType=\"lib.CheckBoxStoreModel\" jsId=\"filterModel\" store=\"filterStore\"
634 query=\"{id:'root'}\" rootId=\"root\" rootLabel=\"Feeds\"
635 childrenAttrs=\"items\" checkboxStrict=\"false\" checkboxAll=\"false\">
637 <div dojoType=\"fox.PrefFilterTree\" id=\"filterTree\"
638 model=\"filterModel\" openOnClick=\"true\">
639 <script type=\"dojo/method\" event=\"onLoad\" args=\"item\">
640 Element.hide(\"filterlistLoading\");
642 <script type=\"dojo/method\" event=\"onClick\" args=\"item\">
643 var id = String(item.id);
644 var bare_id = id.substr(id.indexOf(':')+1);
646 if (id.match('FILTER:')) {
653 print "</div>"; #pane
656 $pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB
,
657 "hook_prefs_tab", "prefFilters");
659 print "</div>"; #container
663 function newfilter() {
665 print "<form name='filter_new_form' id='filter_new_form'>";
667 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-filters\">";
668 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"add\">";
669 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"csrf_token\" value=\"".$_SESSION['csrf_token']."\">";
671 print "<div class=\"dlgSec\">".__("Match")."</div>";
673 print "<div dojoType=\"dijit.Toolbar\">";
675 print "<div dojoType=\"dijit.form.DropDownButton\">".
676 "<span>" . __('Select')."</span>";
677 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
678 print "<div onclick=\"dijit.byId('filterEditDlg').selectRules(true)\"
679 dojoType=\"dijit.MenuItem\">".__('All')."</div>";
680 print "<div onclick=\"dijit.byId('filterEditDlg').selectRules(false)\"
681 dojoType=\"dijit.MenuItem\">".__('None')."</div>";
682 print "</div></div>";
684 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').addRule()\">".
685 __('Add')."</button> ";
687 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').deleteRule()\">".
688 __('Delete')."</button> ";
692 print "<ul id='filterDlg_Matches'>";
693 # print "<li>No rules</li>";
698 print "<div class=\"dlgSec\">".__("Apply actions")."</div>";
700 print "<div dojoType=\"dijit.Toolbar\">";
702 print "<div dojoType=\"dijit.form.DropDownButton\">".
703 "<span>" . __('Select')."</span>";
704 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
705 print "<div onclick=\"dijit.byId('filterEditDlg').selectActions(true)\"
706 dojoType=\"dijit.MenuItem\">".__('All')."</div>";
707 print "<div onclick=\"dijit.byId('filterEditDlg').selectActions(false)\"
708 dojoType=\"dijit.MenuItem\">".__('None')."</div>";
709 print "</div></div>";
711 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').addAction()\">".
712 __('Add')."</button> ";
714 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').deleteAction()\">".
715 __('Delete')."</button> ";
719 print "<ul id='filterDlg_Actions'>";
720 # print "<li>No actions</li>";
723 /* print "<div class=\"dlgSec\">".__("Options")."</div>";
724 print "<div class=\"dlgSecCont\">"; */
726 print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"enabled\" id=\"enabled\" checked=\"1\">
727 <label for=\"enabled\">".__('Enabled')."</label>";
729 print "<br/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"match_any_rule\" id=\"match_any_rule\">
730 <label for=\"match_any_rule\">".__('Match any rule')."</label>";
732 print "<br/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"inverse\" id=\"inverse\">
733 <label for=\"inverse\">".__('Inverse matching')."</label>";
737 print "<div class=\"dlgButtons\">";
739 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').test()\">".
740 __('Test')."</button> ";
742 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').execute()\">".
743 __('Create')."</button> ";
745 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').hide()\">".
746 __('Cancel')."</button>";
753 $rule = json_decode($_REQUEST["rule"], true);
756 $reg_exp = htmlspecialchars($rule["reg_exp"]);
757 $filter_type = $rule["filter_type"];
758 $feed_id = $rule["feed_id"];
759 $inverse_checked = isset($rule["inverse"]) ?
"checked" : "";
764 $inverse_checked = "";
767 if (strpos($feed_id, "CAT:") === 0) {
768 $feed_id = substr($feed_id, 4);
775 print "<form name='filter_new_rule_form' id='filter_new_rule_form'>";
777 $result = db_query($this->link
, "SELECT id,description
778 FROM ttrss_filter_types WHERE id != 5 ORDER BY description");
780 $filter_types = array();
782 while ($line = db_fetch_assoc($result)) {
783 $filter_types[$line["id"]] = __($line["description"]);
786 print "<div class=\"dlgSec\">".__("Match")."</div>";
788 print "<div class=\"dlgSecCont\">";
790 print "<input dojoType=\"dijit.form.ValidationTextBox\"
791 required=\"true\" id=\"filterDlg_regExp\"
792 style=\"font-size : 16px; width : 20em;\"
793 name=\"reg_exp\" value=\"$reg_exp\"/>";
796 print "<input id=\"filterDlg_inverse\" dojoType=\"dijit.form.CheckBox\"
797 name=\"inverse\" $inverse_checked/>";
798 print "<label for=\"filterDlg_inverse\">".__("Inverse regular expression matching")."</label>";
800 print "<hr/>" . __("on field") . " ";
801 print_select_hash("filter_type", $filter_type, $filter_types,
802 'dojoType="dijit.form.Select"');
806 print __("in") . " ";
808 print "<span id='filterDlg_feeds'>";
809 print_feed_select($this->link
, "feed_id",
810 $cat_filter ?
"CAT:$feed_id" : $feed_id,
811 'dojoType="dijit.form.FilteringSelect"');
816 print "<div class=\"dlgButtons\">";
818 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterNewRuleDlg').execute()\">".
819 ($rule ?
__("Save rule") : __('Add rule'))."</button> ";
821 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterNewRuleDlg').hide()\">".
822 __('Cancel')."</button>";
829 function newaction() {
830 $action = json_decode($_REQUEST["action"], true);
833 $action_param = db_escape_string($this->link
, $action["action_param"]);
834 $action_id = (int)$action["action_id"];
840 print "<form name='filter_new_action_form' id='filter_new_action_form'>";
842 print "<div class=\"dlgSec\">".__("Perform Action")."</div>";
844 print "<div class=\"dlgSecCont\">";
846 print "<select name=\"action_id\" dojoType=\"dijit.form.Select\"
847 onchange=\"filterDlgCheckAction(this)\">";
849 $result = db_query($this->link
, "SELECT id,description FROM ttrss_filter_actions
852 while ($line = db_fetch_assoc($result)) {
853 $is_selected = ($line["id"] == $action_id) ?
"selected='1'" : "";
854 printf("<option $is_selected value='%d'>%s</option>", $line["id"], __($line["description"]));
859 $param_box_hidden = ($action_id == 7 ||
$action_id == 4 ||
$action_id == 6) ?
860 "" : "display : none";
862 $param_hidden = ($action_id == 4 ||
$action_id == 6) ?
863 "" : "display : none";
865 $label_param_hidden = ($action_id == 7) ?
"" : "display : none";
867 print "<span id=\"filterDlg_paramBox\" style=\"$param_box_hidden\">";
868 print " " . __("with parameters:") . " ";
869 print "<input dojoType=\"dijit.form.TextBox\"
870 id=\"filterDlg_actionParam\" style=\"$param_hidden\"
871 name=\"action_param\" value=\"$action_param\">";
873 print_label_select($this->link
, "action_param_label", $action_param,
874 "id=\"filterDlg_actionParamLabel\" style=\"$label_param_hidden\"
875 dojoType=\"dijit.form.Select\"");
879 print " "; // tiny layout hack
883 print "<div class=\"dlgButtons\">";
885 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterNewActionDlg').execute()\">".
886 ($action ?
__("Save action") : __('Add action'))."</button> ";
888 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterNewActionDlg').hide()\">".
889 __('Cancel')."</button>";
896 private function getFilterName($id) {
897 $result = db_query($this->link
,
898 "SELECT * FROM ttrss_filters2_rules WHERE filter_id = '$id' ORDER BY id
904 while ($line = db_fetch_assoc($result)) {
906 if (sql_bool_to_bool($line["cat_filter"])) {
907 unset($line["cat_filter"]);
908 $line["feed_id"] = "CAT:" . (int)$line["cat_id"];
909 unset($line["cat_id"]);
912 if (!sql_bool_to_bool($line["inverse"])) unset($line["inverse"]);
915 array_push($titles, $this->getRuleName($line));
917 array_push($titles, "...");
923 $result = db_query($this->link
,
924 "SELECT * FROM ttrss_filters2_actions WHERE filter_id = '$id' ORDER BY id LIMIT 3");
929 while ($line = db_fetch_assoc($result)) {
931 array_push($actions, $this->getActionName($line));
933 array_push($actions, "...");
939 return array(join(", ", $titles), join(", ", $actions));
943 $ids = explode(",", db_escape_string($this->link
, $_REQUEST["ids"]));
945 if (count($ids) > 1) {
946 $base_id = array_shift($ids);
947 $ids_str = join(",", $ids);
949 db_query($this->link
, "BEGIN");
950 db_query($this->link
, "UPDATE ttrss_filters2_rules
951 SET filter_id = '$base_id' WHERE filter_id IN ($ids_str)");
952 db_query($this->link
, "UPDATE ttrss_filters2_actions
953 SET filter_id = '$base_id' WHERE filter_id IN ($ids_str)");
955 db_query($this->link
, "DELETE FROM ttrss_filters2 WHERE id IN ($ids_str)");
956 db_query($this->link
, "UPDATE ttrss_filters2 SET match_any_rule = true WHERE id = '$base_id'");
958 db_query($this->link
, "COMMIT");
960 $this->optimizeFilter($base_id);
965 private function optimizeFilter($id) {
966 db_query($this->link
, "BEGIN");
967 $result = db_query($this->link
, "SELECT * FROM ttrss_filters2_actions
968 WHERE filter_id = '$id'");
973 while ($line = db_fetch_assoc($result)) {
977 if (array_search($line, $tmp) === false) {
978 array_push($tmp, $line);
980 array_push($dupe_ids, $id);
984 if (count($dupe_ids) > 0) {
985 $ids_str = join(",", $dupe_ids);
986 db_query($this->link
, "DELETE FROM ttrss_filters2_actions
987 WHERE id IN ($ids_str)");
990 $result = db_query($this->link
, "SELECT * FROM ttrss_filters2_rules
991 WHERE filter_id = '$id'");
996 while ($line = db_fetch_assoc($result)) {
1000 if (array_search($line, $tmp) === false) {
1001 array_push($tmp, $line);
1003 array_push($dupe_ids, $id);
1007 if (count($dupe_ids) > 0) {
1008 $ids_str = join(",", $dupe_ids);
1009 db_query($this->link
, "DELETE FROM ttrss_filters2_rules
1010 WHERE id IN ($ids_str)");
1013 db_query($this->link
, "COMMIT");