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