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