]>
Commit | Line | Data |
---|---|---|
8e17d663 | 1 | <?php |
46da73c2 | 2 | class Pref_Filters extends Protected_Handler { |
8e17d663 | 3 | |
8484ce22 AD |
4 | function csrf_ignore($method) { |
5 | $csrf_ignored = array("index", "getfiltertree", "edit"); | |
6 | ||
7 | return array_search($method, $csrf_ignored) !== false; | |
8 | } | |
9 | ||
8e17d663 | 10 | function filter_test($filter_type, $reg_exp, |
ba975b2e AD |
11 | $action_id, $action_param, $filter_param, $inverse, $feed_id, $cat_id, |
12 | $cat_filter) { | |
8e17d663 AD |
13 | |
14 | $result = db_query($this->link, "SELECT name FROM ttrss_filter_types WHERE | |
15 | id = " . $filter_type); | |
16 | $type_name = db_fetch_result($result, 0, "name"); | |
17 | ||
18 | $result = db_query($this->link, "SELECT name FROM ttrss_filter_actions WHERE | |
19 | id = " . $action_id); | |
20 | $action_name = db_fetch_result($result, 0, "name"); | |
21 | ||
22 | $filter["reg_exp"] = $reg_exp; | |
23 | $filter["action"] = $action_name; | |
24 | $filter["type"] = $type_name; | |
25 | $filter["action_param"] = $action_param; | |
26 | $filter["filter_param"] = $filter_param; | |
27 | $filter["inverse"] = $inverse; | |
28 | ||
29 | $filters[$type_name] = array($filter); | |
30 | ||
31 | if ($feed_id) | |
32 | $feed = $feed_id; | |
33 | else | |
34 | $feed = -4; | |
35 | ||
56fbb82c AD |
36 | $regexp_valid = preg_match('/' . $filter['reg_exp'] . '/', |
37 | $filter['reg_exp']) !== FALSE; | |
8e17d663 AD |
38 | |
39 | print __("Articles matching this filter:"); | |
40 | ||
82ace1ab | 41 | print "<div class=\"filterTestHolder\">"; |
8e17d663 AD |
42 | print "<table width=\"100%\" cellspacing=\"0\" id=\"prefErrorFeedList\">"; |
43 | ||
56fbb82c | 44 | if ($regexp_valid) { |
8e17d663 | 45 | |
56fbb82c | 46 | $feed_title = getFeedTitle($this->link, $feed); |
8e17d663 | 47 | |
56fbb82c AD |
48 | $qfh_ret = queryFeedHeadlines($this->link, $cat_filter ? $cat_id : $feed, |
49 | 30, "", $cat_filter, false, false, | |
50 | false, "date_entered DESC", 0, $_SESSION["uid"], $filter); | |
8e17d663 | 51 | |
56fbb82c | 52 | $result = $qfh_ret[0]; |
8e17d663 | 53 | |
56fbb82c AD |
54 | $articles = array(); |
55 | $found = 0; | |
8e17d663 | 56 | |
56fbb82c | 57 | while ($line = db_fetch_assoc($result)) { |
8e17d663 | 58 | |
56fbb82c AD |
59 | $entry_timestamp = strtotime($line["updated"]); |
60 | $entry_tags = get_article_tags($this->link, $line["id"], $_SESSION["uid"]); | |
8e17d663 | 61 | |
56fbb82c AD |
62 | $content_preview = truncate_string( |
63 | strip_tags($line["content_preview"]), 100, '...'); | |
8e17d663 | 64 | |
56fbb82c AD |
65 | if ($line["feed_title"]) |
66 | $feed_title = $line["feed_title"]; | |
67 | ||
68 | print "<tr>"; | |
69 | ||
70 | print "<td width='5%' align='center'><input | |
71 | dojoType=\"dijit.form.CheckBox\" checked=\"1\" | |
72 | disabled=\"1\" type=\"checkbox\"></td>"; | |
73 | print "<td>"; | |
74 | ||
75 | print $line["title"]; | |
76 | print " ("; | |
77 | print "<b>" . $feed_title . "</b>"; | |
78 | print "): "; | |
79 | print "<span class=\"insensitive\">" . $content_preview . "</span>"; | |
80 | print " " . mb_substr($line["date_entered"], 0, 16); | |
81 | ||
82 | print "</td></tr>"; | |
83 | ||
84 | $found++; | |
85 | } | |
86 | ||
87 | if ($found == 0) { | |
88 | print "<tr><td align='center'>" . | |
89 | __("No articles matching this filter has been found.") . "</td></tr>"; | |
90 | } | |
91 | } else { | |
92 | print "<tr><td align='center' class='error'>" . | |
93 | __("Invalid regular expression.") . "</td></tr>"; | |
8e17d663 | 94 | |
8e17d663 AD |
95 | } |
96 | ||
97 | print "</table>"; | |
98 | print "</div>"; | |
99 | ||
100 | } | |
101 | ||
102 | function getfiltertree() { | |
103 | $root = array(); | |
104 | $root['id'] = 'root'; | |
105 | $root['name'] = __('Filters'); | |
106 | $root['items'] = array(); | |
107 | ||
310fa2dd AD |
108 | $search = $_SESSION["prefs_filter_search"]; |
109 | ||
110 | if ($search) $search_qpart = " (LOWER(reg_exp) LIKE LOWER('%$search%') | |
111 | OR LOWER(ttrss_feeds.title) LIKE LOWER('%$search%') | |
112 | OR LOWER(COALESCE(ttrss_feed_categories.title, '".__('Uncategorized')."')) | |
113 | LIKE LOWER('%$search%') AND cat_filter = true) AND "; | |
114 | ||
8e17d663 AD |
115 | $result = db_query($this->link, "SELECT |
116 | ttrss_filters.id AS id,reg_exp, | |
117 | ttrss_filter_types.name AS filter_type_name, | |
118 | ttrss_filter_types.description AS filter_type_descr, | |
119 | enabled, | |
120 | inverse, | |
ba975b2e | 121 | cat_filter, |
8e17d663 | 122 | feed_id, |
ba975b2e | 123 | ttrss_filters.cat_id, |
8e17d663 AD |
124 | action_id, |
125 | filter_param, | |
126 | filter_type, | |
127 | ttrss_filter_actions.description AS action_description, | |
128 | ttrss_feeds.title AS feed_title, | |
310fa2dd | 129 | COALESCE(ttrss_feed_categories.title, '".__('Uncategorized')."') AS cat_title, |
8e17d663 AD |
130 | ttrss_filter_actions.name AS action_name, |
131 | ttrss_filters.action_param AS action_param | |
132 | FROM | |
133 | ttrss_filter_types,ttrss_filter_actions,ttrss_filters LEFT JOIN | |
ba975b2e AD |
134 | ttrss_feeds ON (ttrss_filters.feed_id = ttrss_feeds.id) LEFT JOIN |
135 | ttrss_feed_categories ON (ttrss_filters.cat_id = ttrss_feed_categories.id) | |
8e17d663 AD |
136 | WHERE |
137 | filter_type = ttrss_filter_types.id AND | |
138 | ttrss_filter_actions.id = action_id AND | |
310fa2dd | 139 | $search_qpart |
8e17d663 AD |
140 | ttrss_filters.owner_uid = ".$_SESSION["uid"]." |
141 | ORDER by action_description, reg_exp"); | |
142 | ||
143 | $cat = false; | |
144 | $cur_action_description = ""; | |
145 | ||
146 | if (db_num_rows($result) > 0) { | |
147 | ||
148 | while ($line = db_fetch_assoc($result)) { | |
149 | if ($cur_action_description != $line['action_description']) { | |
150 | ||
151 | if ($cat) | |
152 | array_push($root['items'], $cat); | |
153 | ||
154 | $cat = array(); | |
155 | $cat['id'] = 'ACTION:' . $line['action_id']; | |
156 | $cat['name'] = $line['action_description']; | |
157 | $cat['items'] = array(); | |
158 | ||
159 | $cur_action_description = $line['action_description']; | |
160 | } | |
161 | ||
162 | if (array_search($line["action_name"], | |
163 | array("score", "tag", "label")) === false) { | |
164 | ||
165 | $line["action_param"] = ''; | |
166 | } else { | |
167 | if ($line['action_name'] == 'label') { | |
168 | ||
169 | $tmp_result = db_query($this->link, "SELECT fg_color, bg_color | |
170 | FROM ttrss_labels2 WHERE caption = '". | |
171 | db_escape_string($line["action_param"])."' AND | |
172 | owner_uid = " . $_SESSION["uid"]); | |
173 | ||
174 | if (db_num_rows($tmp_result) != 0) { | |
175 | $fg_color = db_fetch_result($tmp_result, 0, "fg_color"); | |
176 | $bg_color = db_fetch_result($tmp_result, 0, "bg_color"); | |
177 | ||
178 | $tmp = "<span class=\"labelColorIndicator\" style='color : $fg_color; background-color : $bg_color'>α</span> " . $line['action_param']; | |
179 | ||
180 | $line['action_param'] = $tmp; | |
181 | } | |
182 | } | |
183 | } | |
184 | ||
185 | $filter = array(); | |
186 | $filter['id'] = 'FILTER:' . $line['id']; | |
187 | $filter['bare_id'] = $line['id']; | |
188 | $filter['name'] = $line['reg_exp']; | |
189 | $filter['type'] = $line['filter_type']; | |
190 | $filter['enabled'] = sql_bool_to_bool($line['enabled']); | |
191 | $filter['param'] = $line['action_param']; | |
192 | $filter['inverse'] = sql_bool_to_bool($line['inverse']); | |
193 | $filter['checkbox'] = false; | |
194 | ||
ba975b2e AD |
195 | if (sql_bool_to_bool($line['cat_filter'])) |
196 | if ($line['cat_id'] != 0) { | |
197 | $filter['feed'] = $line['cat_title']; | |
198 | } else { | |
199 | $filter['feed'] = __('Uncategorized'); | |
200 | } | |
201 | else if ($line['feed_id']) | |
8e17d663 AD |
202 | $filter['feed'] = $line['feed_title']; |
203 | ||
204 | array_push($cat['items'], $filter); | |
205 | } | |
206 | ||
207 | array_push($root['items'], $cat); | |
208 | } | |
209 | ||
210 | $fl = array(); | |
211 | $fl['identifier'] = 'id'; | |
212 | $fl['label'] = 'name'; | |
213 | $fl['items'] = array($root); | |
214 | ||
215 | print json_encode($fl); | |
216 | return; | |
217 | } | |
218 | ||
219 | function edit() { | |
220 | ||
221 | $filter_id = db_escape_string($_REQUEST["id"]); | |
222 | ||
223 | $result = db_query($this->link, | |
224 | "SELECT * FROM ttrss_filters WHERE id = '$filter_id' AND owner_uid = " . $_SESSION["uid"]); | |
225 | ||
226 | $reg_exp = htmlspecialchars(db_fetch_result($result, 0, "reg_exp")); | |
227 | $filter_type = db_fetch_result($result, 0, "filter_type"); | |
228 | $feed_id = db_fetch_result($result, 0, "feed_id"); | |
ba975b2e | 229 | $cat_id = db_fetch_result($result, 0, "cat_id"); |
8e17d663 AD |
230 | $action_id = db_fetch_result($result, 0, "action_id"); |
231 | $action_param = db_fetch_result($result, 0, "action_param"); | |
232 | $filter_param = db_fetch_result($result, 0, "filter_param"); | |
233 | ||
234 | $enabled = sql_bool_to_bool(db_fetch_result($result, 0, "enabled")); | |
235 | $inverse = sql_bool_to_bool(db_fetch_result($result, 0, "inverse")); | |
ba975b2e | 236 | $cat_filter = sql_bool_to_bool(db_fetch_result($result, 0, "cat_filter")); |
8e17d663 AD |
237 | |
238 | print "<form id=\"filter_edit_form\" onsubmit='return false'>"; | |
239 | ||
240 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-filters\">"; | |
241 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"id\" value=\"$filter_id\">"; | |
242 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"editSave\">"; | |
b69a09ea | 243 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"csrf_token\" value=\"".$_SESSION['csrf_token']."\">"; |
8e17d663 AD |
244 | |
245 | $result = db_query($this->link, "SELECT id,description | |
246 | FROM ttrss_filter_types ORDER BY description"); | |
247 | ||
248 | $filter_types = array(); | |
249 | ||
250 | while ($line = db_fetch_assoc($result)) { | |
251 | //array_push($filter_types, $line["description"]); | |
252 | $filter_types[$line["id"]] = __($line["description"]); | |
253 | } | |
254 | ||
255 | print "<div class=\"dlgSec\">".__("Match")."</div>"; | |
256 | ||
257 | print "<div class=\"dlgSecCont\">"; | |
258 | ||
259 | if ($filter_type != 5) { | |
260 | $date_ops_invisible = 'style="display : none"'; | |
261 | } | |
262 | ||
263 | print "<span id=\"filterDlg_dateModBox\" $date_ops_invisible>"; | |
264 | print __("Date") . " "; | |
265 | ||
266 | $filter_params = array( | |
267 | "before" => __("before"), | |
268 | "after" => __("after")); | |
269 | ||
270 | print_select_hash("filter_date_modifier", $filter_param, | |
271 | $filter_params, 'dojoType="dijit.form.Select"'); | |
272 | ||
273 | print " </span>"; | |
274 | ||
275 | print "<input dojoType=\"dijit.form.ValidationTextBox\" | |
276 | required=\"1\" | |
277 | name=\"reg_exp\" style=\"font-size : 16px;\" value=\"$reg_exp\">"; | |
278 | ||
279 | print "<span id=\"filterDlg_dateChkBox\" $date_ops_invisible>"; | |
280 | print " <button dojoType=\"dijit.form.Button\" onclick=\"return filterDlgCheckDate()\">". | |
281 | __('Check it')."</button>"; | |
282 | print "</span>"; | |
283 | ||
284 | print "<hr/> " . __("on field") . " "; | |
285 | print_select_hash("filter_type", $filter_type, $filter_types, | |
286 | 'onchange="filterDlgCheckType(this)" dojoType="dijit.form.Select"'); | |
287 | ||
288 | print "<hr/>"; | |
289 | ||
290 | print __("in") . " "; | |
ba975b2e AD |
291 | |
292 | $hidden = $cat_filter ? "style='display:none'" : ""; | |
293 | ||
294 | print "<span id='filterDlg_feeds' $hidden>"; | |
8e17d663 AD |
295 | print_feed_select($this->link, "feed_id", $feed_id, |
296 | 'dojoType="dijit.form.FilteringSelect"'); | |
ba975b2e AD |
297 | print "</span>"; |
298 | ||
299 | $hidden = $cat_filter ? "" : "style='display:none'"; | |
300 | ||
301 | print "<span id='filterDlg_cats' $hidden>"; | |
302 | print_feed_cat_select($this->link, "cat_id", $cat_id, | |
303 | 'dojoType="dijit.form.FilteringSelect"'); | |
304 | print "</span>"; | |
305 | ||
8e17d663 AD |
306 | |
307 | print "</div>"; | |
308 | ||
309 | print "<div class=\"dlgSec\">".__("Perform Action")."</div>"; | |
310 | ||
311 | print "<div class=\"dlgSecCont\">"; | |
312 | ||
313 | print "<select name=\"action_id\" dojoType=\"dijit.form.Select\" | |
314 | onchange=\"filterDlgCheckAction(this)\">"; | |
315 | ||
316 | $result = db_query($this->link, "SELECT id,description FROM ttrss_filter_actions | |
317 | ORDER BY name"); | |
318 | ||
319 | while ($line = db_fetch_assoc($result)) { | |
320 | $is_sel = ($line["id"] == $action_id) ? "selected=\"1\"" : ""; | |
321 | printf("<option value='%d' $is_sel>%s</option>", $line["id"], __($line["description"])); | |
322 | } | |
323 | ||
324 | print "</select>"; | |
325 | ||
326 | $param_hidden = ($action_id == 4 || $action_id == 6 || $action_id == 7) ? "" : "display : none"; | |
327 | ||
328 | print "<span id=\"filterDlg_paramBox\" style=\"$param_hidden\">"; | |
329 | print " " . __("with parameters:") . " "; | |
330 | ||
331 | $param_int_hidden = ($action_id != 7) ? "" : "display : none"; | |
332 | ||
333 | print "<input style=\"$param_int_hidden\" | |
334 | dojoType=\"dijit.form.TextBox\" id=\"filterDlg_actionParam\" | |
335 | name=\"action_param\" value=\"$action_param\">"; | |
336 | ||
337 | $param_int_hidden = ($action_id == 7) ? "" : "display : none"; | |
338 | ||
339 | print_label_select($this->link, "action_param_label", $action_param, | |
340 | "style=\"$param_int_hidden\"" . | |
341 | 'id="filterDlg_actionParamLabel" dojoType="dijit.form.Select"'); | |
342 | ||
343 | print "</span>"; | |
344 | ||
345 | print " "; // tiny layout hack | |
346 | ||
347 | print "</div>"; | |
348 | ||
349 | print "<div class=\"dlgSec\">".__("Options")."</div>"; | |
350 | print "<div class=\"dlgSecCont\">"; | |
351 | ||
352 | print "<div style=\"line-height : 100%\">"; | |
353 | ||
354 | if ($enabled) { | |
355 | $checked = "checked=\"1\""; | |
356 | } else { | |
357 | $checked = ""; | |
358 | } | |
359 | ||
360 | print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"enabled\" id=\"enabled\" $checked> | |
361 | <label for=\"enabled\">".__('Enabled')."</label><hr/>"; | |
362 | ||
363 | if ($inverse) { | |
364 | $checked = "checked=\"1\""; | |
365 | } else { | |
366 | $checked = ""; | |
367 | } | |
368 | ||
369 | print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"inverse\" id=\"inverse\" $checked> | |
ba975b2e AD |
370 | <label for=\"inverse\">".__('Inverse match')."</label><hr/>"; |
371 | ||
372 | if ($cat_filter) { | |
373 | $checked = "checked=\"1\""; | |
374 | } else { | |
375 | $checked = ""; | |
376 | } | |
377 | ||
378 | print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"cat_filter\" id=\"cat_filter\" onchange=\"filterDlgCheckCat(this)\" $checked> | |
379 | <label for=\"cat_filter\">".__('Apply to category')."</label><hr/>"; | |
8e17d663 AD |
380 | |
381 | print "</div>"; | |
382 | print "</div>"; | |
383 | ||
384 | print "<div class=\"dlgButtons\">"; | |
385 | ||
386 | print "<div style=\"float : left\">"; | |
387 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').removeFilter()\">". | |
388 | __('Remove')."</button>"; | |
389 | print "</div>"; | |
390 | ||
391 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').test()\">". | |
392 | __('Test')."</button> "; | |
393 | ||
394 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').execute()\">". | |
395 | __('Save')."</button> "; | |
396 | ||
397 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').hide()\">". | |
398 | __('Cancel')."</button>"; | |
399 | ||
400 | print "</div>"; | |
401 | } | |
402 | ||
403 | function editSave() { | |
404 | ||
8e17d663 AD |
405 | $savemode = db_escape_string($_REQUEST["savemode"]); |
406 | $reg_exp = db_escape_string(trim($_REQUEST["reg_exp"])); | |
407 | $filter_type = db_escape_string(trim($_REQUEST["filter_type"])); | |
408 | $filter_id = db_escape_string($_REQUEST["id"]); | |
409 | $feed_id = db_escape_string($_REQUEST["feed_id"]); | |
410 | $action_id = db_escape_string($_REQUEST["action_id"]); | |
411 | $action_param = db_escape_string($_REQUEST["action_param"]); | |
412 | $action_param_label = db_escape_string($_REQUEST["action_param_label"]); | |
413 | $enabled = checkbox_to_sql_bool(db_escape_string($_REQUEST["enabled"])); | |
414 | $inverse = checkbox_to_sql_bool(db_escape_string($_REQUEST["inverse"])); | |
ba975b2e AD |
415 | $cat_filter = checkbox_to_sql_bool(db_escape_string($_REQUEST["cat_filter"])); |
416 | $cat_id = db_escape_string($_REQUEST['cat_id']); | |
8e17d663 AD |
417 | |
418 | # for the time being, no other filters use params anyway... | |
419 | $filter_param = db_escape_string($_REQUEST["filter_date_modifier"]); | |
420 | ||
421 | if (!$feed_id) { | |
422 | $feed_id = 'NULL'; | |
423 | } else { | |
424 | $feed_id = sprintf("'%s'", db_escape_string($feed_id)); | |
425 | } | |
426 | ||
ba975b2e AD |
427 | if (!$cat_id) { |
428 | $cat_id = 'NULL'; | |
429 | } else { | |
430 | $cat_id = sprintf("'%d'", db_escape_string($cat_id)); | |
431 | } | |
432 | ||
8e17d663 AD |
433 | /* When processing 'assign label' filters, action_param_label dropbox |
434 | * overrides action_param */ | |
435 | ||
436 | if ($action_id == 7) { | |
437 | $action_param = $action_param_label; | |
438 | } | |
439 | ||
440 | if ($action_id == 6) { | |
441 | $action_param = (int) str_replace("+", "", $action_param); | |
442 | } | |
443 | ||
444 | if ($savemode != "test") { | |
445 | $result = db_query($this->link, "UPDATE ttrss_filters SET | |
446 | reg_exp = '$reg_exp', | |
447 | feed_id = $feed_id, | |
ba975b2e | 448 | cat_id = $cat_id, |
8e17d663 AD |
449 | action_id = '$action_id', |
450 | filter_type = '$filter_type', | |
451 | enabled = $enabled, | |
452 | inverse = $inverse, | |
ba975b2e | 453 | cat_filter = $cat_filter, |
8e17d663 AD |
454 | action_param = '$action_param', |
455 | filter_param = '$filter_param' | |
456 | WHERE id = '$filter_id' AND owner_uid = " . $_SESSION["uid"]); | |
457 | } else { | |
458 | ||
459 | $this->filter_test($filter_type, $reg_exp, | |
460 | $action_id, $action_param, $filter_param, sql_bool_to_bool($inverse), | |
ba975b2e AD |
461 | (int) $_REQUEST["feed_id"], (int) $_REQUEST['cat_id'], |
462 | sql_bool_to_bool($cat_filter)); | |
8e17d663 AD |
463 | |
464 | print "<div align='center'>"; | |
465 | print "<button dojoType=\"dijit.form.Button\" | |
466 | onclick=\"return dijit.byId('filterTestDlg').hide()\">". | |
467 | __('Close this window')."</button>"; | |
468 | print "</div>"; | |
469 | ||
470 | } | |
471 | } | |
472 | ||
473 | function remove() { | |
474 | ||
8e17d663 AD |
475 | $ids = split(",", db_escape_string($_REQUEST["ids"])); |
476 | ||
477 | foreach ($ids as $id) { | |
478 | db_query($this->link, "DELETE FROM ttrss_filters WHERE id = '$id' AND owner_uid = ". $_SESSION["uid"]); | |
479 | } | |
480 | } | |
481 | ||
482 | function add() { | |
483 | ||
8e17d663 AD |
484 | $savemode = db_escape_string($_REQUEST["savemode"]); |
485 | $regexp = db_escape_string(trim($_REQUEST["reg_exp"])); | |
486 | $filter_type = db_escape_string(trim($_REQUEST["filter_type"])); | |
487 | $feed_id = db_escape_string($_REQUEST["feed_id"]); | |
ba975b2e | 488 | $cat_id = db_escape_string($_REQUEST["cat_id"]); |
8e17d663 AD |
489 | $action_id = db_escape_string($_REQUEST["action_id"]); |
490 | $action_param = db_escape_string($_REQUEST["action_param"]); | |
491 | $action_param_label = db_escape_string($_REQUEST["action_param_label"]); | |
492 | $inverse = checkbox_to_sql_bool(db_escape_string($_REQUEST["inverse"])); | |
ba975b2e | 493 | $cat_filter = checkbox_to_sql_bool(db_escape_string($_REQUEST["cat_filter"])); |
8e17d663 AD |
494 | |
495 | # for the time being, no other filters use params anyway... | |
496 | $filter_param = db_escape_string($_REQUEST["filter_date_modifier"]); | |
497 | ||
498 | if (!$regexp) return; | |
499 | ||
500 | if (!$feed_id) { | |
501 | $feed_id = 'NULL'; | |
502 | } else { | |
503 | $feed_id = sprintf("'%s'", db_escape_string($feed_id)); | |
504 | } | |
505 | ||
ba975b2e AD |
506 | if (!$cat_id) { |
507 | $cat_id = 'NULL'; | |
508 | } else { | |
509 | $cat_id = sprintf("'%d'", db_escape_string($cat_id)); | |
510 | } | |
511 | ||
8e17d663 AD |
512 | /* When processing 'assign label' filters, action_param_label dropbox |
513 | * overrides action_param */ | |
514 | ||
515 | if ($action_id == 7) { | |
516 | $action_param = $action_param_label; | |
517 | } | |
518 | ||
519 | if ($action_id == 6) { | |
520 | $action_param = (int) str_replace("+", "", $action_param); | |
521 | } | |
522 | ||
523 | if ($savemode != "test") { | |
524 | $result = db_query($this->link, | |
525 | "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id, | |
ba975b2e | 526 | action_id, action_param, inverse, filter_param, cat_id, cat_filter) |
8e17d663 AD |
527 | VALUES |
528 | ('$regexp', '$filter_type','".$_SESSION["uid"]."', | |
529 | $feed_id, '$action_id', '$action_param', $inverse, | |
a5e0ffb0 | 530 | '$filter_param', $cat_id, $cat_filter)"); |
8e17d663 AD |
531 | |
532 | if (db_affected_rows($this->link, $result) != 0) { | |
533 | print T_sprintf("Created filter <b>%s</b>", htmlspecialchars($regexp)); | |
534 | } | |
535 | ||
536 | } else { | |
537 | ||
d0dfb4c8 | 538 | $this->filter_test($filter_type, $regexp, |
8e17d663 | 539 | $action_id, $action_param, $filter_param, sql_bool_to_bool($inverse), |
ba975b2e AD |
540 | (int) $_REQUEST["feed_id"], (int) $_REQUEST['cat_id'], |
541 | sql_bool_to_bool($cat_filter)); | |
8e17d663 AD |
542 | |
543 | print "<div align='center'>"; | |
544 | print "<button dojoType=\"dijit.form.Button\" | |
545 | onclick=\"return dijit.byId('filterTestDlg').hide()\">". | |
546 | __('Close this window')."</button>"; | |
547 | print "</div>"; | |
548 | ||
549 | } | |
550 | } | |
551 | ||
552 | function index() { | |
553 | ||
554 | $sort = db_escape_string($_REQUEST["sort"]); | |
555 | ||
556 | if (!$sort || $sort == "undefined") { | |
557 | $sort = "reg_exp"; | |
558 | } | |
559 | ||
560 | $result = db_query($this->link, "SELECT id,description | |
561 | FROM ttrss_filter_types ORDER BY description"); | |
562 | ||
563 | $filter_types = array(); | |
564 | ||
565 | while ($line = db_fetch_assoc($result)) { | |
566 | //array_push($filter_types, $line["description"]); | |
567 | $filter_types[$line["id"]] = $line["description"]; | |
568 | } | |
569 | ||
570 | ||
571 | $filter_search = db_escape_string($_REQUEST["search"]); | |
572 | ||
573 | if (array_key_exists("search", $_REQUEST)) { | |
574 | $_SESSION["prefs_filter_search"] = $filter_search; | |
575 | } else { | |
576 | $filter_search = $_SESSION["prefs_filter_search"]; | |
577 | } | |
578 | ||
579 | print "<div id=\"pref-filter-wrap\" dojoType=\"dijit.layout.BorderContainer\" gutters=\"false\">"; | |
580 | print "<div id=\"pref-filter-header\" dojoType=\"dijit.layout.ContentPane\" region=\"top\">"; | |
581 | print "<div id=\"pref-filter-toolbar\" dojoType=\"dijit.Toolbar\">"; | |
582 | ||
310fa2dd AD |
583 | $filter_search = db_escape_string($_REQUEST["search"]); |
584 | ||
585 | if (array_key_exists("search", $_REQUEST)) { | |
586 | $_SESSION["prefs_filter_search"] = $filter_search; | |
587 | } else { | |
588 | $filter_search = $_SESSION["prefs_filter_search"]; | |
589 | } | |
590 | ||
591 | print "<div style='float : right; padding-right : 4px;'> | |
592 | <input dojoType=\"dijit.form.TextBox\" id=\"filter_search\" size=\"20\" type=\"search\" | |
593 | value=\"$filter_search\"> | |
594 | <button dojoType=\"dijit.form.Button\" onclick=\"updateFilterList()\">". | |
595 | __('Search')."</button> | |
596 | </div>"; | |
597 | ||
8e17d663 AD |
598 | print "<div dojoType=\"dijit.form.DropDownButton\">". |
599 | "<span>" . __('Select')."</span>"; | |
600 | print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; | |
601 | print "<div onclick=\"dijit.byId('filterTree').model.setAllChecked(true)\" | |
602 | dojoType=\"dijit.MenuItem\">".__('All')."</div>"; | |
603 | print "<div onclick=\"dijit.byId('filterTree').model.setAllChecked(false)\" | |
604 | dojoType=\"dijit.MenuItem\">".__('None')."</div>"; | |
605 | print "</div></div>"; | |
606 | ||
607 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return quickAddFilter()\">". | |
608 | __('Create filter')."</button> "; | |
609 | ||
610 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return editSelectedFilter()\">". | |
611 | __('Edit')."</button> "; | |
612 | ||
613 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return removeSelectedFilters()\">". | |
614 | __('Remove')."</button> "; | |
615 | ||
616 | if (defined('_ENABLE_FEED_DEBUGGING')) { | |
617 | print "<button dojoType=\"dijit.form.Button\" onclick=\"rescore_all_feeds()\">". | |
618 | __('Rescore articles')."</button> "; | |
619 | } | |
620 | ||
621 | print "</div>"; # toolbar | |
622 | print "</div>"; # toolbar-frame | |
623 | print "<div id=\"pref-filter-content\" dojoType=\"dijit.layout.ContentPane\" region=\"center\">"; | |
624 | ||
625 | print "<div id=\"filterlistLoading\"> | |
626 | <img src='images/indicator_tiny.gif'>". | |
627 | __("Loading, please wait...")."</div>"; | |
628 | ||
629 | print "<div dojoType=\"dojo.data.ItemFileWriteStore\" jsId=\"filterStore\" | |
630 | url=\"backend.php?op=pref-filters&method=getfiltertree\"> | |
631 | </div> | |
632 | <div dojoType=\"lib.CheckBoxStoreModel\" jsId=\"filterModel\" store=\"filterStore\" | |
633 | query=\"{id:'root'}\" rootId=\"root\" rootLabel=\"Feeds\" | |
634 | childrenAttrs=\"items\" checkboxStrict=\"false\" checkboxAll=\"false\"> | |
635 | </div> | |
636 | <div dojoType=\"fox.PrefFilterTree\" id=\"filterTree\" | |
637 | model=\"filterModel\" openOnClick=\"true\"> | |
638 | <script type=\"dojo/method\" event=\"onLoad\" args=\"item\"> | |
639 | Element.hide(\"filterlistLoading\"); | |
640 | </script> | |
641 | <script type=\"dojo/method\" event=\"onClick\" args=\"item\"> | |
642 | var id = String(item.id); | |
643 | var bare_id = id.substr(id.indexOf(':')+1); | |
644 | ||
645 | if (id.match('FILTER:')) { | |
646 | editFilter(bare_id); | |
647 | } | |
648 | </script> | |
649 | ||
650 | </div>"; | |
651 | ||
652 | print "</div>"; #pane | |
653 | print "</div>"; #container | |
654 | ||
655 | } | |
656 | } | |
657 | ?> |