]> git.wh0rd.org - tt-rss.git/blame - classes/pref/filters.php
scroll to end to show next feed or category
[tt-rss.git] / classes / pref / filters.php
CommitLineData
8e17d663 1<?php
369dbc19 2class Pref_Filters extends Handler_Protected {
8e17d663 3
8484ce22 4 function csrf_ignore($method) {
6aff7845 5 $csrf_ignored = array("index", "getfiltertree", "edit", "newfilter", "newrule",
a86ba0a6 6 "newaction", "savefilterorder");
8484ce22
AD
7
8 return array_search($method, $csrf_ignored) !== false;
9 }
10
a86ba0a6 11 function filtersortreset() {
d9c85e0f 12 $this->dbh->query("UPDATE ttrss_filters2
a86ba0a6
AD
13 SET order_id = 0 WHERE owner_uid = " . $_SESSION["uid"]);
14 return;
15 }
16
17 function savefilterorder() {
18 $data = json_decode($_POST['payload'], true);
19
20 #file_put_contents("/tmp/saveorder.json", $_POST['payload']);
21 #$data = json_decode(file_get_contents("/tmp/saveorder.json"), true);
22
23 if (!is_array($data['items']))
24 $data['items'] = json_decode($data['items'], true);
25
26 $index = 0;
27
28 if (is_array($data) && is_array($data['items'])) {
29 foreach ($data['items'][0]['items'] as $item) {
30 $filter_id = (int) str_replace("FILTER:", "", $item['_reference']);
31
32 if ($filter_id > 0) {
33
d9c85e0f 34 $this->dbh->query("UPDATE ttrss_filters2 SET
a86ba0a6
AD
35 order_id = $index WHERE id = '$filter_id' AND
36 owner_uid = " .$_SESSION["uid"]);
37
38 ++$index;
39 }
40 }
41 }
42
43 return;
44 }
45
46
4e02f582
AD
47 function testFilter() {
48 $filter = array();
8e17d663 49
4e02f582
AD
50 $filter["enabled"] = true;
51 $filter["match_any_rule"] = sql_bool_to_bool(
d9c85e0f 52 checkbox_to_sql_bool($this->dbh->escape_string($_REQUEST["match_any_rule"])));
a3a896a1 53 $filter["inverse"] = sql_bool_to_bool(
d9c85e0f 54 checkbox_to_sql_bool($this->dbh->escape_string($_REQUEST["inverse"])));
a3a896a1 55
4e02f582 56 $filter["rules"] = array();
8e17d663 57
d9c85e0f 58 $result = $this->dbh->query("SELECT id,name FROM ttrss_filter_types");
8e17d663 59
4e02f582 60 $filter_types = array();
d9c85e0f 61 while ($line = $this->dbh->fetch_assoc($result)) {
4e02f582
AD
62 $filter_types[$line["id"]] = $line["name"];
63 }
8e17d663 64
4e02f582
AD
65 $rctr = 0;
66 foreach ($_REQUEST["rule"] AS $r) {
67 $rule = json_decode($r, true);
8e17d663 68
4e02f582
AD
69 if ($rule && $rctr < 5) {
70 $rule["type"] = $filter_types[$rule["filter_type"]];
71 unset($rule["filter_type"]);
8e17d663 72
4e02f582
AD
73 if (strpos($rule["feed_id"], "CAT:") === 0) {
74 $rule["cat_id"] = (int) substr($rule["feed_id"], 4);
75 unset($rule["feed_id"]);
76 }
8e17d663 77
4e02f582 78 array_push($filter["rules"], $rule);
8e17d663 79
4e02f582
AD
80 ++$rctr;
81 } else {
82 break;
83 }
84 }
8e17d663 85
a42c55f0 86 $qfh_ret = queryFeedHeadlines(-4, 30, "", false, false, false,
ca5d9be4 87 "date_entered DESC", 0, $_SESSION["uid"], $filter);
8e17d663 88
4e02f582 89 $result = $qfh_ret[0];
8e17d663 90
4e02f582 91 $found = 0;
8e17d663 92
4e02f582 93 print __("Articles matching this filter:");
8e17d663 94
4e02f582
AD
95 print "<div class=\"filterTestHolder\">";
96 print "<table width=\"100%\" cellspacing=\"0\" id=\"prefErrorFeedList\">";
a290e9ea 97
d9c85e0f 98 while ($line = $this->dbh->fetch_assoc($result)) {
bf5bcb8e 99 $line["content_preview"] = truncate_string(strip_tags($line["content"]), 100, '...');
74175e6a 100
891e36f5 101 foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) {
102 $line = $p->hook_query_headlines($line, 100);
103 }
8e17d663 104
67631438 105 $content_preview = $line["content_preview"];
56fbb82c 106
4e02f582
AD
107 if ($line["feed_title"])
108 $feed_title = $line["feed_title"];
56fbb82c 109
4e02f582 110 print "<tr>";
56fbb82c 111
4e02f582
AD
112 print "<td width='5%' align='center'><input
113 dojoType=\"dijit.form.CheckBox\" checked=\"1\"
114 disabled=\"1\" type=\"checkbox\"></td>";
115 print "<td>";
56fbb82c 116
4e02f582
AD
117 print $line["title"];
118 print "&nbsp;(";
119 print "<b>" . $feed_title . "</b>";
120 print "):&nbsp;";
74175e6a 121 print "<span class=\"insensitive\">" . $content_preview . "</span>";
4e02f582 122 print " " . mb_substr($line["date_entered"], 0, 16);
56fbb82c 123
4e02f582 124 print "</td></tr>";
56fbb82c 125
4e02f582
AD
126 $found++;
127 }
8e17d663 128
4e02f582
AD
129 if ($found == 0) {
130 print "<tr><td align='center'>" .
5cb17306
AD
131 __("No recent articles matching this filter have been found.");
132
133 print "</td></tr><tr><td class='insensitive' align='center'>";
134
135 print __("Complex expressions might not give results while testing due to issues with database server regexp implementation.");
136
137 print "</td></tr>";
138
8e17d663
AD
139 }
140
4e02f582
AD
141 print "</table></div>";
142
143 print "<div style='text-align : center'>";
144 print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('filterTestDlg').hide()\">".
145 __('Close this window')."</button>";
8e17d663
AD
146 print "</div>";
147
4e02f582
AD
148 }
149
50e04efd
AD
150 private function getfilterrules_concise($filter_id) {
151 $result = $this->dbh->query("SELECT reg_exp,
152 inverse,
153 feed_id,
154 cat_id,
155 cat_filter,
156 ttrss_filter_types.description AS field
157 FROM
158 ttrss_filters2_rules, ttrss_filter_types
159 WHERE
160 filter_id = '$filter_id' AND filter_type = ttrss_filter_types.id");
161
162 $rv = "";
163
164 while ($line = $this->dbh->fetch_assoc($result)) {
165
166 $where = sql_bool_to_bool($line["cat_filter"]) ?
167 getCategoryTitle($line["cat_id"]) : getFeedTitle($line["feed_id"]);
168
169# $where = $line["cat_id"] . "/" . $line["feed_id"];
170
171 $inverse = sql_bool_to_bool($line["inverse"]) ? "inverse" : "";
172
173 $rv .= "<span class='$inverse'>" . T_sprintf("%s on %s in %s %s",
174 strip_tags($line["reg_exp"]),
175 $line["field"],
176 $where,
177 sql_bool_to_bool($line["inverse"]) ? __("(inverse)") : "") . "</span>";
178 }
179
180 return $rv;
181 }
8e17d663
AD
182
183 function getfiltertree() {
184 $root = array();
185 $root['id'] = 'root';
186 $root['name'] = __('Filters');
187 $root['items'] = array();
188
69c6e94d
AD
189 $filter_search = $_SESSION["prefs_filter_search"];
190
d9c85e0f 191 $result = $this->dbh->query("SELECT *,
84d9750e
AD
192 (SELECT action_param FROM ttrss_filters2_actions
193 WHERE filter_id = ttrss_filters2.id ORDER BY id LIMIT 1) AS action_param,
6aff7845
AD
194 (SELECT action_id FROM ttrss_filters2_actions
195 WHERE filter_id = ttrss_filters2.id ORDER BY id LIMIT 1) AS action_id,
37f78940
AD
196 (SELECT description FROM ttrss_filter_actions
197 WHERE id = (SELECT action_id FROM ttrss_filters2_actions
198 WHERE filter_id = ttrss_filters2.id ORDER BY id LIMIT 1)) AS action_name,
6aff7845
AD
199 (SELECT reg_exp FROM ttrss_filters2_rules
200 WHERE filter_id = ttrss_filters2.id ORDER BY id LIMIT 1) AS reg_exp
201 FROM ttrss_filters2 WHERE
f0419320 202 owner_uid = ".$_SESSION["uid"]." ORDER BY order_id, title");
8e17d663 203
69c6e94d 204
37f78940
AD
205 $folder = array();
206 $folder['items'] = array();
207
d9c85e0f 208 while ($line = $this->dbh->fetch_assoc($result)) {
8e17d663 209
6aff7845 210 $name = $this->getFilterName($line["id"]);
8e17d663 211
69c6e94d
AD
212 $match_ok = false;
213 if ($filter_search) {
d9c85e0f 214 $rules_result = $this->dbh->query(
69c6e94d
AD
215 "SELECT reg_exp FROM ttrss_filters2_rules WHERE filter_id = ".$line["id"]);
216
d9c85e0f 217 while ($rule_line = $this->dbh->fetch_assoc($rules_result)) {
69c6e94d
AD
218 if (mb_strpos($rule_line['reg_exp'], $filter_search) !== false) {
219 $match_ok = true;
220 break;
221 }
222 }
223 }
224
84d9750e 225 if ($line['action_id'] == 7) {
d9c85e0f
AD
226 $label_result = $this->dbh->query("SELECT fg_color, bg_color
227 FROM ttrss_labels2 WHERE caption = '".$this->dbh->escape_string($line['action_param'])."' AND
84d9750e
AD
228 owner_uid = " . $_SESSION["uid"]);
229
d9c85e0f
AD
230 if ($this->dbh->num_rows($label_result) > 0) {
231 $fg_color = $this->dbh->fetch_result($label_result, 0, "fg_color");
232 $bg_color = $this->dbh->fetch_result($label_result, 0, "bg_color");
84d9750e 233
da46d21e 234 $name[1] = "<span class=\"labelColorIndicator\" id=\"label-editor-indicator\" style='color : $fg_color; background-color : $bg_color; margin-right : 4px'>&alpha;</span>" . $name[1];
84d9750e
AD
235 }
236 }
237
6aff7845
AD
238 $filter = array();
239 $filter['id'] = 'FILTER:' . $line['id'];
240 $filter['bare_id'] = $line['id'];
241 $filter['name'] = $name[0];
242 $filter['param'] = $name[1];
243 $filter['checkbox'] = false;
c2ee5846 244 $filter['enabled'] = sql_bool_to_bool($line["enabled"]);
50e04efd 245 $filter['rules'] = $this->getfilterrules_concise($line['id']);
8e17d663 246
69c6e94d
AD
247 if (!$filter_search || $match_ok) {
248 array_push($folder['items'], $filter);
249 }
8e17d663
AD
250 }
251
da46d21e 252 /* if (count($folder['items']) > 0) {
e8b70387 253 array_push($root['items'], $folder);
da46d21e
AD
254 } */
255
256 $root['items'] = $folder['items'];
e8b70387 257
8e17d663
AD
258 $fl = array();
259 $fl['identifier'] = 'id';
260 $fl['label'] = 'name';
261 $fl['items'] = array($root);
262
263 print json_encode($fl);
264 return;
265 }
266
267 function edit() {
268
d9c85e0f 269 $filter_id = $this->dbh->escape_string($_REQUEST["id"]);
8e17d663 270
d9c85e0f 271 $result = $this->dbh->query(
6aff7845 272 "SELECT * FROM ttrss_filters2 WHERE id = '$filter_id' AND owner_uid = " . $_SESSION["uid"]);
8e17d663 273
d9c85e0f
AD
274 $enabled = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "enabled"));
275 $match_any_rule = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "match_any_rule"));
276 $inverse = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "inverse"));
277 $title = htmlspecialchars($this->dbh->fetch_result($result, 0, "title"));
8e17d663
AD
278
279 print "<form id=\"filter_edit_form\" onsubmit='return false'>";
280
281 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-filters\">";
282 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"id\" value=\"$filter_id\">";
283 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"editSave\">";
b69a09ea 284 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"csrf_token\" value=\"".$_SESSION['csrf_token']."\">";
8e17d663 285
18ad09af
AD
286 print "<div class=\"dlgSec\">".__("Caption")."</div>";
287
442bca27 288 print "<input required=\"true\" dojoType=\"dijit.form.ValidationTextBox\" style=\"width : 20em;\" name=\"title\" value=\"$title\">";
18ad09af
AD
289
290 print "</div>";
291
8e17d663
AD
292 print "<div class=\"dlgSec\">".__("Match")."</div>";
293
6aff7845 294 print "<div dojoType=\"dijit.Toolbar\">";
8e17d663 295
6aff7845
AD
296 print "<div dojoType=\"dijit.form.DropDownButton\">".
297 "<span>" . __('Select')."</span>";
298 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
299 print "<div onclick=\"dijit.byId('filterEditDlg').selectRules(true)\"
300 dojoType=\"dijit.MenuItem\">".__('All')."</div>";
301 print "<div onclick=\"dijit.byId('filterEditDlg').selectRules(false)\"
302 dojoType=\"dijit.MenuItem\">".__('None')."</div>";
303 print "</div></div>";
8e17d663 304
6aff7845
AD
305 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').addRule()\">".
306 __('Add')."</button> ";
8e17d663 307
6aff7845
AD
308 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').deleteRule()\">".
309 __('Delete')."</button> ";
8e17d663 310
6aff7845 311 print "</div>";
8e17d663 312
6aff7845 313 print "<ul id='filterDlg_Matches'>";
8e17d663 314
d9c85e0f 315 $rules_result = $this->dbh->query("SELECT * FROM ttrss_filters2_rules
56b2a409 316 WHERE filter_id = '$filter_id' ORDER BY reg_exp, id");
8e17d663 317
d9c85e0f 318 while ($line = $this->dbh->fetch_assoc($rules_result)) {
5451903c 319 if (sql_bool_to_bool($line["cat_filter"])) {
6aff7845 320 $line["feed_id"] = "CAT:" . (int)$line["cat_id"];
6aff7845 321 }
8e17d663 322
4e02f582
AD
323 unset($line["cat_filter"]);
324 unset($line["cat_id"]);
325 unset($line["filter_id"]);
326 unset($line["id"]);
a3a896a1 327 if (!sql_bool_to_bool($line["inverse"])) unset($line["inverse"]);
4e02f582 328
6aff7845 329 $data = htmlspecialchars(json_encode($line));
8e17d663 330
04e41840 331 print "<li><input dojoType='dijit.form.CheckBox' type='checkbox' onclick='toggleSelectListRow2(this)'>".
6aff7845
AD
332 "<span onclick=\"dijit.byId('filterEditDlg').editRule(this)\">".$this->getRuleName($line)."</span>".
333 "<input type='hidden' name='rule[]' value=\"$data\"/></li>";
334 }
ba975b2e 335
6aff7845 336 print "</ul>";
ba975b2e 337
8e17d663
AD
338 print "</div>";
339
6aff7845 340 print "<div class=\"dlgSec\">".__("Apply actions")."</div>";
8e17d663 341
6aff7845 342 print "<div dojoType=\"dijit.Toolbar\">";
8e17d663 343
6aff7845
AD
344 print "<div dojoType=\"dijit.form.DropDownButton\">".
345 "<span>" . __('Select')."</span>";
346 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
347 print "<div onclick=\"dijit.byId('filterEditDlg').selectActions(true)\"
348 dojoType=\"dijit.MenuItem\">".__('All')."</div>";
349 print "<div onclick=\"dijit.byId('filterEditDlg').selectActions(false)\"
350 dojoType=\"dijit.MenuItem\">".__('None')."</div>";
351 print "</div></div>";
8e17d663 352
6aff7845
AD
353 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').addAction()\">".
354 __('Add')."</button> ";
8e17d663 355
6aff7845
AD
356 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').deleteAction()\">".
357 __('Delete')."</button> ";
8e17d663 358
6aff7845 359 print "</div>";
8e17d663 360
6aff7845 361 print "<ul id='filterDlg_Actions'>";
8e17d663 362
d9c85e0f 363 $actions_result = $this->dbh->query("SELECT * FROM ttrss_filters2_actions
6aff7845 364 WHERE filter_id = '$filter_id' ORDER BY id");
8e17d663 365
d9c85e0f 366 while ($line = $this->dbh->fetch_assoc($actions_result)) {
6aff7845 367 $line["action_param_label"] = $line["action_param"];
4e02f582
AD
368
369 unset($line["filter_id"]);
370 unset($line["id"]);
371
6aff7845 372 $data = htmlspecialchars(json_encode($line));
8e17d663 373
04e41840 374 print "<li><input dojoType='dijit.form.CheckBox' type='checkbox' onclick='toggleSelectListRow2(this)'>".
6aff7845
AD
375 "<span onclick=\"dijit.byId('filterEditDlg').editAction(this)\">".$this->getActionName($line)."</span>".
376 "<input type='hidden' name='action[]' value=\"$data\"/></li>";
377 }
8e17d663 378
6aff7845 379 print "</ul>";
8e17d663
AD
380
381 print "</div>";
382
8e17d663
AD
383 if ($enabled) {
384 $checked = "checked=\"1\"";
385 } else {
386 $checked = "";
387 }
388
389 print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"enabled\" id=\"enabled\" $checked>
6aff7845 390 <label for=\"enabled\">".__('Enabled')."</label>";
8e17d663 391
6aff7845 392 if ($match_any_rule) {
8e17d663
AD
393 $checked = "checked=\"1\"";
394 } else {
395 $checked = "";
396 }
397
6aff7845
AD
398 print "<br/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"match_any_rule\" id=\"match_any_rule\" $checked>
399 <label for=\"match_any_rule\">".__('Match any rule')."</label>";
8e17d663 400
a3a896a1
AD
401 if ($inverse) {
402 $checked = "checked=\"1\"";
403 } else {
404 $checked = "";
405 }
406
407 print "<br/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"inverse\" id=\"inverse\" $checked>
408 <label for=\"inverse\">".__('Inverse matching')."</label>";
409
6aff7845 410 print "<p/>";
8e17d663
AD
411
412 print "<div class=\"dlgButtons\">";
413
414 print "<div style=\"float : left\">";
415 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').removeFilter()\">".
416 __('Remove')."</button>";
417 print "</div>";
418
4e02f582
AD
419 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').test()\">".
420 __('Test')."</button> ";
8e17d663
AD
421
422 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').execute()\">".
423 __('Save')."</button> ";
424
425 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').hide()\">".
426 __('Cancel')."</button>";
427
428 print "</div>";
429 }
430
6aff7845
AD
431 private function getRuleName($rule) {
432 if (!$rule) $rule = json_decode($_REQUEST["rule"], true);
8e17d663 433
6aff7845 434 $feed_id = $rule["feed_id"];
8e17d663 435
4c9d0490 436 if (strpos($feed_id, "CAT:") === 0) {
6aff7845 437 $feed_id = (int) substr($feed_id, 4);
a42c55f0 438 $feed = getCategoryTitle($feed_id);
8e17d663 439 } else {
4c9d0490 440 $feed_id = (int) $feed_id;
6aff7845
AD
441
442 if ($rule["feed_id"])
a42c55f0 443 $feed = getFeedTitle((int)$rule["feed_id"]);
6aff7845
AD
444 else
445 $feed = __("All feeds");
8e17d663
AD
446 }
447
d9c85e0f 448 $result = $this->dbh->query("SELECT description FROM ttrss_filter_types
6aff7845 449 WHERE id = ".(int)$rule["filter_type"]);
d9c85e0f 450 $filter_type = $this->dbh->fetch_result($result, 0, "description");
4c9d0490 451
50e04efd
AD
452 $inverse = isset($rule["inverse"]) ? "inverse" : "";
453
454 return "<span class='filterRule $inverse'>" .
455 T_sprintf("%s on %s in %s %s", strip_tags($rule["reg_exp"]),
456 $filter_type, $feed, isset($rule["inverse"]) ? __("(inverse)") : "") . "</span>";
6aff7845 457 }
ba975b2e 458
6aff7845
AD
459 function printRuleName() {
460 print $this->getRuleName(json_decode($_REQUEST["rule"], true));
461 }
8e17d663 462
6aff7845 463 private function getActionName($action) {
d9c85e0f 464 $result = $this->dbh->query("SELECT description FROM
6aff7845 465 ttrss_filter_actions WHERE id = " .(int)$action["action_id"]);
8e17d663 466
d9c85e0f 467 $title = __($this->dbh->fetch_result($result, 0, "description"));
8e17d663 468
6aff7845
AD
469 if ($action["action_id"] == 4 || $action["action_id"] == 6 ||
470 $action["action_id"] == 7)
471 $title .= ": " . $action["action_param"];
8e17d663 472
6aff7845
AD
473 return $title;
474 }
8e17d663 475
6aff7845
AD
476 function printActionName() {
477 print $this->getActionName(json_decode($_REQUEST["action"], true));
478 }
479
480 function editSave() {
4e02f582
AD
481 if ($_REQUEST["savemode"] && $_REQUEST["savemode"] == "test") {
482 return $this->testFilter();
483 }
6aff7845
AD
484
485# print_r($_REQUEST);
486
d9c85e0f
AD
487 $filter_id = $this->dbh->escape_string($_REQUEST["id"]);
488 $enabled = checkbox_to_sql_bool($this->dbh->escape_string($_REQUEST["enabled"]));
489 $match_any_rule = checkbox_to_sql_bool($this->dbh->escape_string($_REQUEST["match_any_rule"]));
490 $inverse = checkbox_to_sql_bool($this->dbh->escape_string($_REQUEST["inverse"]));
491 $title = $this->dbh->escape_string($_REQUEST["title"]);
6aff7845 492
4a80c57c 493 $this->dbh->query("UPDATE ttrss_filters2 SET enabled = $enabled,
a3a896a1 494 match_any_rule = $match_any_rule,
18ad09af
AD
495 inverse = $inverse,
496 title = '$title'
6aff7845
AD
497 WHERE id = '$filter_id'
498 AND owner_uid = ". $_SESSION["uid"]);
499
500 $this->saveRulesAndActions($filter_id);
8e17d663 501
8e17d663
AD
502 }
503
504 function remove() {
505
d9c85e0f 506 $ids = explode(",", $this->dbh->escape_string($_REQUEST["ids"]));
8e17d663
AD
507
508 foreach ($ids as $id) {
d9c85e0f 509 $this->dbh->query("DELETE FROM ttrss_filters2 WHERE id = '$id' AND owner_uid = ". $_SESSION["uid"]);
8e17d663
AD
510 }
511 }
512
6aff7845 513 private function saveRulesAndActions($filter_id) {
8e17d663 514
d9c85e0f
AD
515 $this->dbh->query("DELETE FROM ttrss_filters2_rules WHERE filter_id = '$filter_id'");
516 $this->dbh->query("DELETE FROM ttrss_filters2_actions WHERE filter_id = '$filter_id'");
8e17d663 517
6aff7845
AD
518 if ($filter_id) {
519 /* create rules */
8e17d663 520
6aff7845
AD
521 $rules = array();
522 $actions = array();
8e17d663 523
6aff7845
AD
524 foreach ($_REQUEST["rule"] as $rule) {
525 $rule = json_decode($rule, true);
526 unset($rule["id"]);
8e17d663 527
6aff7845
AD
528 if (array_search($rule, $rules) === false) {
529 array_push($rules, $rule);
530 }
531 }
4c9d0490 532
6aff7845
AD
533 foreach ($_REQUEST["action"] as $action) {
534 $action = json_decode($action, true);
535 unset($action["id"]);
ba975b2e 536
6aff7845
AD
537 if (array_search($action, $actions) === false) {
538 array_push($actions, $action);
539 }
540 }
8e17d663 541
6aff7845
AD
542 foreach ($rules as $rule) {
543 if ($rule) {
8e17d663 544
d9c85e0f 545 $reg_exp = strip_tags($this->dbh->escape_string(trim($rule["reg_exp"])));
a3a896a1
AD
546 $inverse = isset($rule["inverse"]) ? "true" : "false";
547
d9c85e0f
AD
548 $filter_type = (int) $this->dbh->escape_string(trim($rule["filter_type"]));
549 $feed_id = $this->dbh->escape_string(trim($rule["feed_id"]));
6aff7845
AD
550
551 if (strpos($feed_id, "CAT:") === 0) {
5451903c 552
6aff7845
AD
553 $cat_filter = bool_to_sql_bool(true);
554 $cat_id = (int) substr($feed_id, 4);
555 $feed_id = "NULL";
8e17d663 556
6aff7845
AD
557 if (!$cat_id) $cat_id = "NULL"; // Uncategorized
558 } else {
559 $cat_filter = bool_to_sql_bool(false);
560 $feed_id = (int) $feed_id;
561 $cat_id = "NULL";
562
563 if (!$feed_id) $feed_id = "NULL"; // Uncategorized
564 }
565
566 $query = "INSERT INTO ttrss_filters2_rules
a3a896a1
AD
567 (filter_id, reg_exp,filter_type,feed_id,cat_id,cat_filter,inverse) VALUES
568 ('$filter_id', '$reg_exp', '$filter_type', $feed_id, $cat_id, $cat_filter, $inverse)";
6aff7845 569
d9c85e0f 570 $this->dbh->query($query);
6aff7845 571 }
8e17d663
AD
572 }
573
6aff7845
AD
574 foreach ($actions as $action) {
575 if ($action) {
576
d9c85e0f
AD
577 $action_id = (int) $this->dbh->escape_string($action["action_id"]);
578 $action_param = $this->dbh->escape_string($action["action_param"]);
579 $action_param_label = $this->dbh->escape_string($action["action_param_label"]);
6aff7845
AD
580
581 if ($action_id == 7) {
582 $action_param = $action_param_label;
583 }
8e17d663 584
6aff7845
AD
585 if ($action_id == 6) {
586 $action_param = (int) str_replace("+", "", $action_param);
587 }
8e17d663 588
6aff7845
AD
589 $query = "INSERT INTO ttrss_filters2_actions
590 (filter_id, action_id, action_param) VALUES
591 ('$filter_id', '$action_id', '$action_param')";
8e17d663 592
d9c85e0f 593 $this->dbh->query($query);
6aff7845
AD
594 }
595 }
8e17d663 596 }
6aff7845
AD
597
598
599 }
600
601 function add() {
4e02f582
AD
602 if ($_REQUEST["savemode"] && $_REQUEST["savemode"] == "test") {
603 return $this->testFilter();
604 }
605
6aff7845
AD
606# print_r($_REQUEST);
607
608 $enabled = checkbox_to_sql_bool($_REQUEST["enabled"]);
609 $match_any_rule = checkbox_to_sql_bool($_REQUEST["match_any_rule"]);
d9c85e0f 610 $title = $this->dbh->escape_string($_REQUEST["title"]);
afa1a260 611 $inverse = checkbox_to_sql_bool($_REQUEST["inverse"]);
6aff7845 612
d9c85e0f 613 $this->dbh->query("BEGIN");
6aff7845
AD
614
615 /* create base filter */
616
d9c85e0f 617 $result = $this->dbh->query("INSERT INTO ttrss_filters2
afa1a260
AD
618 (owner_uid, match_any_rule, enabled, title, inverse) VALUES
619 (".$_SESSION["uid"].",$match_any_rule,$enabled, '$title', $inverse)");
6aff7845 620
d9c85e0f 621 $result = $this->dbh->query("SELECT MAX(id) AS id FROM ttrss_filters2
6aff7845
AD
622 WHERE owner_uid = ".$_SESSION["uid"]);
623
d9c85e0f 624 $filter_id = $this->dbh->fetch_result($result, 0, "id");
6aff7845
AD
625
626 $this->saveRulesAndActions($filter_id);
627
d9c85e0f 628 $this->dbh->query("COMMIT");
8e17d663
AD
629 }
630
631 function index() {
632
d9c85e0f 633 $sort = $this->dbh->escape_string($_REQUEST["sort"]);
8e17d663
AD
634
635 if (!$sort || $sort == "undefined") {
636 $sort = "reg_exp";
637 }
638
d9c85e0f 639 $filter_search = $this->dbh->escape_string($_REQUEST["search"]);
8e17d663
AD
640
641 if (array_key_exists("search", $_REQUEST)) {
642 $_SESSION["prefs_filter_search"] = $filter_search;
643 } else {
644 $filter_search = $_SESSION["prefs_filter_search"];
645 }
646
647 print "<div id=\"pref-filter-wrap\" dojoType=\"dijit.layout.BorderContainer\" gutters=\"false\">";
648 print "<div id=\"pref-filter-header\" dojoType=\"dijit.layout.ContentPane\" region=\"top\">";
649 print "<div id=\"pref-filter-toolbar\" dojoType=\"dijit.Toolbar\">";
650
d9c85e0f 651 $filter_search = $this->dbh->escape_string($_REQUEST["search"]);
310fa2dd
AD
652
653 if (array_key_exists("search", $_REQUEST)) {
654 $_SESSION["prefs_filter_search"] = $filter_search;
655 } else {
656 $filter_search = $_SESSION["prefs_filter_search"];
657 }
658
659 print "<div style='float : right; padding-right : 4px;'>
660 <input dojoType=\"dijit.form.TextBox\" id=\"filter_search\" size=\"20\" type=\"search\"
661 value=\"$filter_search\">
662 <button dojoType=\"dijit.form.Button\" onclick=\"updateFilterList()\">".
663 __('Search')."</button>
664 </div>";
665
8e17d663
AD
666 print "<div dojoType=\"dijit.form.DropDownButton\">".
667 "<span>" . __('Select')."</span>";
668 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
669 print "<div onclick=\"dijit.byId('filterTree').model.setAllChecked(true)\"
670 dojoType=\"dijit.MenuItem\">".__('All')."</div>";
671 print "<div onclick=\"dijit.byId('filterTree').model.setAllChecked(false)\"
672 dojoType=\"dijit.MenuItem\">".__('None')."</div>";
673 print "</div></div>";
674
675 print "<button dojoType=\"dijit.form.Button\" onclick=\"return quickAddFilter()\">".
676 __('Create filter')."</button> ";
677
6aff7845
AD
678 print "<button dojoType=\"dijit.form.Button\" onclick=\"return joinSelectedFilters()\">".
679 __('Combine')."</button> ";
680
8e17d663
AD
681 print "<button dojoType=\"dijit.form.Button\" onclick=\"return editSelectedFilter()\">".
682 __('Edit')."</button> ";
683
a86ba0a6
AD
684 print "<button dojoType=\"dijit.form.Button\" onclick=\"return resetFilterOrder()\">".
685 __('Reset sort order')."</button> ";
686
687
8e17d663
AD
688 print "<button dojoType=\"dijit.form.Button\" onclick=\"return removeSelectedFilters()\">".
689 __('Remove')."</button> ";
690
691 if (defined('_ENABLE_FEED_DEBUGGING')) {
692 print "<button dojoType=\"dijit.form.Button\" onclick=\"rescore_all_feeds()\">".
693 __('Rescore articles')."</button> ";
694 }
695
696 print "</div>"; # toolbar
697 print "</div>"; # toolbar-frame
698 print "<div id=\"pref-filter-content\" dojoType=\"dijit.layout.ContentPane\" region=\"center\">";
699
700 print "<div id=\"filterlistLoading\">
701 <img src='images/indicator_tiny.gif'>".
702 __("Loading, please wait...")."</div>";
703
a86ba0a6 704 print "<div dojoType=\"fox.PrefFilterStore\" jsId=\"filterStore\"
8e17d663
AD
705 url=\"backend.php?op=pref-filters&method=getfiltertree\">
706 </div>
707 <div dojoType=\"lib.CheckBoxStoreModel\" jsId=\"filterModel\" store=\"filterStore\"
a86ba0a6 708 query=\"{id:'root'}\" rootId=\"root\" rootLabel=\"Filters\"
8e17d663
AD
709 childrenAttrs=\"items\" checkboxStrict=\"false\" checkboxAll=\"false\">
710 </div>
711 <div dojoType=\"fox.PrefFilterTree\" id=\"filterTree\"
a86ba0a6
AD
712 dndController=\"dijit.tree.dndSource\"
713 betweenThreshold=\"5\"
8e17d663
AD
714 model=\"filterModel\" openOnClick=\"true\">
715 <script type=\"dojo/method\" event=\"onLoad\" args=\"item\">
716 Element.hide(\"filterlistLoading\");
717 </script>
718 <script type=\"dojo/method\" event=\"onClick\" args=\"item\">
719 var id = String(item.id);
720 var bare_id = id.substr(id.indexOf(':')+1);
721
722 if (id.match('FILTER:')) {
723 editFilter(bare_id);
724 }
725 </script>
726
727 </div>";
728
729 print "</div>"; #pane
6065f3ad 730
1ffe3391 731 PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB,
6065f3ad
AD
732 "hook_prefs_tab", "prefFilters");
733
8e17d663
AD
734 print "</div>"; #container
735
736 }
6aff7845
AD
737
738 function newfilter() {
739
740 print "<form name='filter_new_form' id='filter_new_form'>";
741
6aff7845
AD
742 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-filters\">";
743 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"add\">";
744 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"csrf_token\" value=\"".$_SESSION['csrf_token']."\">";
745
18ad09af
AD
746 print "<div class=\"dlgSec\">".__("Caption")."</div>";
747
442bca27 748 print "<input required=\"true\" dojoType=\"dijit.form.ValidationTextBox\" style=\"width : 20em;\" name=\"title\" value=\"\">";
18ad09af 749
6aff7845
AD
750 print "<div class=\"dlgSec\">".__("Match")."</div>";
751
752 print "<div dojoType=\"dijit.Toolbar\">";
753
754 print "<div dojoType=\"dijit.form.DropDownButton\">".
755 "<span>" . __('Select')."</span>";
756 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
757 print "<div onclick=\"dijit.byId('filterEditDlg').selectRules(true)\"
758 dojoType=\"dijit.MenuItem\">".__('All')."</div>";
759 print "<div onclick=\"dijit.byId('filterEditDlg').selectRules(false)\"
760 dojoType=\"dijit.MenuItem\">".__('None')."</div>";
761 print "</div></div>";
762
763 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').addRule()\">".
764 __('Add')."</button> ";
765
766 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').deleteRule()\">".
767 __('Delete')."</button> ";
768
769 print "</div>";
770
771 print "<ul id='filterDlg_Matches'>";
772# print "<li>No rules</li>";
773 print "</ul>";
774
775 print "</div>";
776
777 print "<div class=\"dlgSec\">".__("Apply actions")."</div>";
778
779 print "<div dojoType=\"dijit.Toolbar\">";
780
781 print "<div dojoType=\"dijit.form.DropDownButton\">".
782 "<span>" . __('Select')."</span>";
783 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
784 print "<div onclick=\"dijit.byId('filterEditDlg').selectActions(true)\"
785 dojoType=\"dijit.MenuItem\">".__('All')."</div>";
786 print "<div onclick=\"dijit.byId('filterEditDlg').selectActions(false)\"
787 dojoType=\"dijit.MenuItem\">".__('None')."</div>";
788 print "</div></div>";
789
790 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').addAction()\">".
791 __('Add')."</button> ";
792
793 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').deleteAction()\">".
794 __('Delete')."</button> ";
795
796 print "</div>";
797
798 print "<ul id='filterDlg_Actions'>";
799# print "<li>No actions</li>";
800 print "</ul>";
801
802/* print "<div class=\"dlgSec\">".__("Options")."</div>";
803 print "<div class=\"dlgSecCont\">"; */
804
805 print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"enabled\" id=\"enabled\" checked=\"1\">
806 <label for=\"enabled\">".__('Enabled')."</label>";
807
808 print "<br/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"match_any_rule\" id=\"match_any_rule\">
809 <label for=\"match_any_rule\">".__('Match any rule')."</label>";
810
a3a896a1
AD
811 print "<br/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"inverse\" id=\"inverse\">
812 <label for=\"inverse\">".__('Inverse matching')."</label>";
6aff7845
AD
813
814// print "</div>";
815
816 print "<div class=\"dlgButtons\">";
817
4e02f582
AD
818 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').test()\">".
819 __('Test')."</button> ";
6aff7845
AD
820
821 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').execute()\">".
822 __('Create')."</button> ";
823
824 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').hide()\">".
825 __('Cancel')."</button>";
826
827 print "</div>";
828
829 }
830
831 function newrule() {
832 $rule = json_decode($_REQUEST["rule"], true);
833
834 if ($rule) {
835 $reg_exp = htmlspecialchars($rule["reg_exp"]);
836 $filter_type = $rule["filter_type"];
837 $feed_id = $rule["feed_id"];
a3a896a1 838 $inverse_checked = isset($rule["inverse"]) ? "checked" : "";
6aff7845
AD
839 } else {
840 $reg_exp = "";
841 $filter_type = 1;
842 $feed_id = 0;
a3a896a1 843 $inverse_checked = "";
6aff7845
AD
844 }
845
846 if (strpos($feed_id, "CAT:") === 0) {
847 $feed_id = substr($feed_id, 4);
848 $cat_filter = true;
849 } else {
850 $cat_filter = false;
851 }
852
853
854 print "<form name='filter_new_rule_form' id='filter_new_rule_form'>";
855
d9c85e0f 856 $result = $this->dbh->query("SELECT id,description
37f78940 857 FROM ttrss_filter_types WHERE id != 5 ORDER BY description");
6aff7845
AD
858
859 $filter_types = array();
860
d9c85e0f 861 while ($line = $this->dbh->fetch_assoc($result)) {
6aff7845
AD
862 $filter_types[$line["id"]] = __($line["description"]);
863 }
864
865 print "<div class=\"dlgSec\">".__("Match")."</div>";
866
867 print "<div class=\"dlgSecCont\">";
868
869 print "<input dojoType=\"dijit.form.ValidationTextBox\"
870 required=\"true\" id=\"filterDlg_regExp\"
ff34bac2 871 style=\"font-size : 16px; width : 20em;\"
6aff7845
AD
872 name=\"reg_exp\" value=\"$reg_exp\"/>";
873
ec1f8a3d
AD
874 print "<hr/>";
875 print "<input id=\"filterDlg_inverse\" dojoType=\"dijit.form.CheckBox\"
876 name=\"inverse\" $inverse_checked/>";
877 print "<label for=\"filterDlg_inverse\">".__("Inverse regular expression matching")."</label>";
878
6aff7845
AD
879 print "<hr/>" . __("on field") . " ";
880 print_select_hash("filter_type", $filter_type, $filter_types,
881 'dojoType="dijit.form.Select"');
882
883 print "<hr/>";
884
885 print __("in") . " ";
886
887 print "<span id='filterDlg_feeds'>";
a42c55f0 888 print_feed_select("feed_id",
6aff7845
AD
889 $cat_filter ? "CAT:$feed_id" : $feed_id,
890 'dojoType="dijit.form.FilteringSelect"');
891 print "</span>";
892
893 print "</div>";
894
895 print "<div class=\"dlgButtons\">";
896
e7a40490
AD
897 print "<div style=\"float : left\">
898 <a class=\"visibleLink\" target=\"_blank\" href=\"http://tt-rss.org/wiki/ContentFilters\">".__("Wiki: Filters")."</a>
899 </div>";
900
901
6aff7845
AD
902 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterNewRuleDlg').execute()\">".
903 ($rule ? __("Save rule") : __('Add rule'))."</button> ";
904
905 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterNewRuleDlg').hide()\">".
906 __('Cancel')."</button>";
907
908 print "</div>";
909
910 print "</form>";
911 }
912
913 function newaction() {
914 $action = json_decode($_REQUEST["action"], true);
915
916 if ($action) {
d9c85e0f 917 $action_param = $this->dbh->escape_string($action["action_param"]);
6aff7845
AD
918 $action_id = (int)$action["action_id"];
919 } else {
920 $action_param = "";
921 $action_id = 0;
922 }
923
924 print "<form name='filter_new_action_form' id='filter_new_action_form'>";
925
926 print "<div class=\"dlgSec\">".__("Perform Action")."</div>";
927
928 print "<div class=\"dlgSecCont\">";
929
930 print "<select name=\"action_id\" dojoType=\"dijit.form.Select\"
931 onchange=\"filterDlgCheckAction(this)\">";
932
d9c85e0f 933 $result = $this->dbh->query("SELECT id,description FROM ttrss_filter_actions
6aff7845
AD
934 ORDER BY name");
935
d9c85e0f 936 while ($line = $this->dbh->fetch_assoc($result)) {
6aff7845
AD
937 $is_selected = ($line["id"] == $action_id) ? "selected='1'" : "";
938 printf("<option $is_selected value='%d'>%s</option>", $line["id"], __($line["description"]));
939 }
940
941 print "</select>";
942
943 $param_box_hidden = ($action_id == 7 || $action_id == 4 || $action_id == 6) ?
944 "" : "display : none";
945
946 $param_hidden = ($action_id == 4 || $action_id == 6) ?
947 "" : "display : none";
948
949 $label_param_hidden = ($action_id == 7) ? "" : "display : none";
950
951 print "<span id=\"filterDlg_paramBox\" style=\"$param_box_hidden\">";
952 print " " . __("with parameters:") . " ";
953 print "<input dojoType=\"dijit.form.TextBox\"
954 id=\"filterDlg_actionParam\" style=\"$param_hidden\"
955 name=\"action_param\" value=\"$action_param\">";
956
a42c55f0 957 print_label_select("action_param_label", $action_param,
6aff7845
AD
958 "id=\"filterDlg_actionParamLabel\" style=\"$label_param_hidden\"
959 dojoType=\"dijit.form.Select\"");
960
961 print "</span>";
962
963 print "&nbsp;"; // tiny layout hack
964
965 print "</div>";
966
967 print "<div class=\"dlgButtons\">";
968
969 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterNewActionDlg').execute()\">".
970 ($action ? __("Save action") : __('Add action'))."</button> ";
971
972 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterNewActionDlg').hide()\">".
973 __('Cancel')."</button>";
974
975 print "</div>";
976
977 print "</form>";
978 }
979
980 private function getFilterName($id) {
18ad09af 981
d9c85e0f 982 $result = $this->dbh->query(
1a293f10
AD
983 "SELECT title,COUNT(DISTINCT r.id) AS num_rules,COUNT(DISTINCT a.id) AS num_actions
984 FROM ttrss_filters2 AS f LEFT JOIN ttrss_filters2_rules AS r
985 ON (r.filter_id = f.id)
986 LEFT JOIN ttrss_filters2_actions AS a
987 ON (a.filter_id = f.id) WHERE f.id = '$id' GROUP BY f.title");
18ad09af 988
d9c85e0f
AD
989 $title = $this->dbh->fetch_result($result, 0, "title");
990 $num_rules = $this->dbh->fetch_result($result, 0, "num_rules");
991 $num_actions = $this->dbh->fetch_result($result, 0, "num_actions");
18ad09af 992
1a293f10 993 if (!$title) $title = __("[No caption]");
18ad09af 994
1a293f10 995 $title = sprintf(_ngettext("%s (%d rule)", "%s (%d rules)", $num_rules), $title, $num_rules);
6aff7845 996
d9c85e0f 997 $result = $this->dbh->query(
1a293f10 998 "SELECT * FROM ttrss_filters2_actions WHERE filter_id = '$id' ORDER BY id LIMIT 1");
bcd4d240 999
1a293f10 1000 $actions = "";
da46d21e 1001
d9c85e0f
AD
1002 if ($this->dbh->num_rows($result) > 0) {
1003 $line = $this->dbh->fetch_assoc($result);
1a293f10 1004 $actions = $this->getActionName($line);
da46d21e 1005
1a293f10 1006 $num_actions -= 1;
6aff7845
AD
1007 }
1008
1a293f10
AD
1009 if ($num_actions > 0)
1010 $actions = sprintf(_ngettext("%s (+%d action)", "%s (+%d actions)", $num_actions), $actions, $num_actions);
6aff7845 1011
1a293f10 1012 return array($title, $actions);
6aff7845
AD
1013 }
1014
1015 function join() {
d9c85e0f 1016 $ids = explode(",", $this->dbh->escape_string($_REQUEST["ids"]));
6aff7845
AD
1017
1018 if (count($ids) > 1) {
1019 $base_id = array_shift($ids);
1020 $ids_str = join(",", $ids);
1021
d9c85e0f
AD
1022 $this->dbh->query("BEGIN");
1023 $this->dbh->query("UPDATE ttrss_filters2_rules
6aff7845 1024 SET filter_id = '$base_id' WHERE filter_id IN ($ids_str)");
d9c85e0f 1025 $this->dbh->query("UPDATE ttrss_filters2_actions
6aff7845
AD
1026 SET filter_id = '$base_id' WHERE filter_id IN ($ids_str)");
1027
d9c85e0f
AD
1028 $this->dbh->query("DELETE FROM ttrss_filters2 WHERE id IN ($ids_str)");
1029 $this->dbh->query("UPDATE ttrss_filters2 SET match_any_rule = true WHERE id = '$base_id'");
6aff7845 1030
d9c85e0f 1031 $this->dbh->query("COMMIT");
6aff7845
AD
1032
1033 $this->optimizeFilter($base_id);
1034
1035 }
1036 }
1037
1038 private function optimizeFilter($id) {
d9c85e0f
AD
1039 $this->dbh->query("BEGIN");
1040 $result = $this->dbh->query("SELECT * FROM ttrss_filters2_actions
6aff7845
AD
1041 WHERE filter_id = '$id'");
1042
1043 $tmp = array();
1044 $dupe_ids = array();
1045
d9c85e0f 1046 while ($line = $this->dbh->fetch_assoc($result)) {
6aff7845
AD
1047 $id = $line["id"];
1048 unset($line["id"]);
1049
1050 if (array_search($line, $tmp) === false) {
1051 array_push($tmp, $line);
1052 } else {
1053 array_push($dupe_ids, $id);
1054 }
1055 }
1056
1057 if (count($dupe_ids) > 0) {
1058 $ids_str = join(",", $dupe_ids);
d9c85e0f 1059 $this->dbh->query("DELETE FROM ttrss_filters2_actions
6aff7845
AD
1060 WHERE id IN ($ids_str)");
1061 }
1062
d9c85e0f 1063 $result = $this->dbh->query("SELECT * FROM ttrss_filters2_rules
6aff7845
AD
1064 WHERE filter_id = '$id'");
1065
1066 $tmp = array();
1067 $dupe_ids = array();
1068
d9c85e0f 1069 while ($line = $this->dbh->fetch_assoc($result)) {
6aff7845
AD
1070 $id = $line["id"];
1071 unset($line["id"]);
1072
1073 if (array_search($line, $tmp) === false) {
1074 array_push($tmp, $line);
1075 } else {
1076 array_push($dupe_ids, $id);
1077 }
1078 }
1079
1080 if (count($dupe_ids) > 0) {
1081 $ids_str = join(",", $dupe_ids);
d9c85e0f 1082 $this->dbh->query("DELETE FROM ttrss_filters2_rules
6aff7845
AD
1083 WHERE id IN ($ids_str)");
1084 }
1085
d9c85e0f 1086 $this->dbh->query("COMMIT");
6aff7845 1087 }
8e17d663
AD
1088}
1089?>