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