]>
Commit | Line | Data |
---|---|---|
ef8be8ea AD |
1 | <?php |
2 | function module_pref_filters($link) { | |
b4e75b2a AD |
3 | $subop = $_REQUEST["subop"]; |
4 | $quiet = $_REQUEST["quiet"]; | |
ef8be8ea | 5 | |
a740f4b5 AD |
6 | if ($subop == "getfiltertree") { |
7 | $root = array(); | |
8 | $root['id'] = 'root'; | |
9 | $root['name'] = __('Filters'); | |
10 | $root['items'] = array(); | |
11 | ||
12 | $result = db_query($link, "SELECT | |
13 | ttrss_filters.id AS id,reg_exp, | |
14 | ttrss_filter_types.name AS filter_type_name, | |
15 | ttrss_filter_types.description AS filter_type_descr, | |
16 | enabled, | |
17 | inverse, | |
18 | feed_id, | |
19 | action_id, | |
20 | filter_param, | |
21 | filter_type, | |
22 | ttrss_filter_actions.description AS action_description, | |
23 | ttrss_feeds.title AS feed_title, | |
24 | ttrss_filter_actions.name AS action_name, | |
25 | ttrss_filters.action_param AS action_param | |
26 | FROM | |
27 | ttrss_filter_types,ttrss_filter_actions,ttrss_filters LEFT JOIN | |
28 | ttrss_feeds ON (ttrss_filters.feed_id = ttrss_feeds.id) | |
29 | WHERE | |
30 | filter_type = ttrss_filter_types.id AND | |
31 | ttrss_filter_actions.id = action_id AND | |
32 | ttrss_filters.owner_uid = ".$_SESSION["uid"]." | |
33 | ORDER by action_description, reg_exp"); | |
34 | ||
35 | $cat = false; | |
36 | $cur_action_description = ""; | |
37 | ||
38 | while ($line = db_fetch_assoc($result)) { | |
39 | if ($cur_action_description != $line['action_description']) { | |
40 | ||
41 | if ($cat) | |
42 | array_push($root['items'], $cat); | |
43 | ||
44 | $cat = array(); | |
45 | $cat['id'] = 'ACTION:' . $line['action_id']; | |
46 | $cat['name'] = $line['action_description']; | |
47 | $cat['items'] = array(); | |
48 | ||
49 | $cur_action_description = $line['action_description']; | |
50 | } | |
51 | ||
52 | if (array_search($line["action_name"], | |
53 | array("score", "tag", "label")) === false) { | |
54 | ||
55 | $line["action_param"] = ''; | |
56 | } else { | |
57 | if ($line['action_name'] == 'label') { | |
58 | ||
59 | $tmp_result = db_query($link, "SELECT fg_color, bg_color | |
60 | FROM ttrss_labels2 WHERE caption = '". | |
61 | db_escape_string($line["action_param"])."' AND | |
62 | owner_uid = " . $_SESSION["uid"]); | |
63 | ||
64 | $fg_color = db_fetch_result($tmp_result, 0, "fg_color"); | |
65 | $bg_color = db_fetch_result($tmp_result, 0, "bg_color"); | |
66 | ||
67 | $tmp = "<span class=\"labelColorIndicator\" style='color : $fg_color; background-color : $bg_color'>α</span> " . $line['action_param']; | |
68 | ||
69 | $line['action_param'] = $tmp; | |
70 | } | |
71 | } | |
72 | ||
73 | $filter = array(); | |
74 | $filter['id'] = 'FILTER:' . $line['id']; | |
75 | $filter['bare_id'] = $line['id']; | |
76 | $filter['name'] = $line['reg_exp']; | |
77 | $filter['type'] = $line['filter_type']; | |
78 | $filter['enabled'] = sql_bool_to_bool($line['enabled']); | |
79 | $filter['param'] = $line['action_param']; | |
80 | $filter['inverse'] = sql_bool_to_bool($line['inverse']); | |
81 | $filter['checkbox'] = false; | |
82 | ||
83 | if ($line['feed_id']) | |
84 | $filter['feed'] = $line['feed_title']; | |
85 | ||
86 | array_push($cat['items'], $filter); | |
87 | } | |
88 | ||
89 | array_push($root['items'], $cat); | |
90 | ||
91 | $fl = array(); | |
92 | $fl['identifier'] = 'id'; | |
93 | $fl['label'] = 'name'; | |
94 | $fl['items'] = array($root); | |
95 | ||
96 | print json_encode($fl); | |
97 | return; | |
98 | } | |
99 | ||
ef8be8ea AD |
100 | if ($subop == "edit") { |
101 | ||
b4e75b2a | 102 | $filter_id = db_escape_string($_REQUEST["id"]); |
ef8be8ea | 103 | |
951906dc AD |
104 | header("Content-Type: text/xml"); |
105 | print "<dlg id=\"$subop\">"; | |
106 | print "<title>".__('Filter Editor')."</title>"; | |
107 | print "<content><![CDATA["; | |
108 | ||
ef8be8ea AD |
109 | $result = db_query($link, |
110 | "SELECT * FROM ttrss_filters WHERE id = '$filter_id' AND owner_uid = " . $_SESSION["uid"]); | |
111 | ||
47439031 | 112 | $reg_exp = htmlspecialchars(db_fetch_result($result, 0, "reg_exp")); |
ef8be8ea AD |
113 | $filter_type = db_fetch_result($result, 0, "filter_type"); |
114 | $feed_id = db_fetch_result($result, 0, "feed_id"); | |
115 | $action_id = db_fetch_result($result, 0, "action_id"); | |
073ca0e6 | 116 | $action_param = db_fetch_result($result, 0, "action_param"); |
44d0e774 | 117 | $filter_param = db_fetch_result($result, 0, "filter_param"); |
ef8be8ea AD |
118 | |
119 | $enabled = sql_bool_to_bool(db_fetch_result($result, 0, "enabled")); | |
3f2ff803 | 120 | $inverse = sql_bool_to_bool(db_fetch_result($result, 0, "inverse")); |
ef8be8ea | 121 | |
e6312f6c | 122 | print "<form id=\"filter_edit_form\" onsubmit='return false'>"; |
ef8be8ea AD |
123 | |
124 | print "<input type=\"hidden\" name=\"op\" value=\"pref-filters\">"; | |
125 | print "<input type=\"hidden\" name=\"id\" value=\"$filter_id\">"; | |
126 | print "<input type=\"hidden\" name=\"subop\" value=\"editSave\">"; | |
ef8be8ea AD |
127 | |
128 | $result = db_query($link, "SELECT id,description | |
129 | FROM ttrss_filter_types ORDER BY description"); | |
130 | ||
131 | $filter_types = array(); | |
132 | ||
133 | while ($line = db_fetch_assoc($result)) { | |
134 | //array_push($filter_types, $line["description"]); | |
89cb787e | 135 | $filter_types[$line["id"]] = __($line["description"]); |
ef8be8ea AD |
136 | } |
137 | ||
10fa6615 AD |
138 | print "<div class=\"dlgSec\">".__("Match")."</div>"; |
139 | ||
140 | print "<div class=\"dlgSecCont\">"; | |
141 | ||
6e278744 | 142 | if ($filter_type != 5) { |
df00fb80 | 143 | $date_ops_invisible = 'style="display : none"'; |
6e278744 AD |
144 | } |
145 | ||
146 | print "<span id=\"filter_dlg_date_mod_box\" $date_ops_invisible>"; | |
147 | print __("Date") . " "; | |
44d0e774 AD |
148 | |
149 | $filter_params = array( | |
150 | "before" => __("before"), | |
151 | "after" => __("after")); | |
152 | ||
153 | print_select_hash("filter_date_modifier", $filter_param, | |
154 | $filter_params); | |
155 | ||
156 | print " </span>"; | |
6e278744 | 157 | |
10fa6615 | 158 | print "<input onkeypress=\"return filterCR(event, filterEditSave)\" |
10fa6615 AD |
159 | name=\"reg_exp\" size=\"30\" value=\"$reg_exp\">"; |
160 | ||
6e278744 | 161 | print "<span id=\"filter_dlg_date_chk_box\" $date_ops_invisible>"; |
a918f5f9 AD |
162 | print " <button onclick=\"return filterDlgCheckDate()\">". |
163 | __('Check it')."</button>"; | |
6e278744 AD |
164 | print "</span>"; |
165 | ||
166 | print "<br/> " . __("on field") . " "; | |
167 | print_select_hash("filter_type", $filter_type, $filter_types, | |
168 | 'onchange="filterDlgCheckType(this)"'); | |
10fa6615 AD |
169 | |
170 | print "<br/>"; | |
171 | ||
172 | print __("in") . " "; | |
173 | print_feed_select($link, "feed_id", $feed_id); | |
174 | ||
175 | print "</div>"; | |
176 | ||
ecace165 | 177 | print "<div class=\"dlgSec\">".__("Perform Action")."</div>"; |
10fa6615 AD |
178 | |
179 | print "<div class=\"dlgSecCont\">"; | |
180 | ||
181 | print "<select name=\"action_id\" | |
182 | onchange=\"filterDlgCheckAction(this)\">"; | |
183 | ||
184 | $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions | |
185 | ORDER BY name"); | |
186 | ||
187 | while ($line = db_fetch_assoc($result)) { | |
188 | $is_sel = ($line["id"] == $action_id) ? "selected" : ""; | |
189 | printf("<option value='%d' $is_sel>%s</option>", $line["id"], __($line["description"])); | |
190 | } | |
191 | ||
192 | print "</select>"; | |
193 | ||
ceb30ba4 | 194 | $param_hidden = ($action_id == 4 || $action_id == 6 || $action_id == 7) ? "" : "display : none"; |
10fa6615 | 195 | |
143a4973 AD |
196 | print "<span id=\"filter_dlg_param_box\" style=\"$param_hidden\">"; |
197 | print " " . __("with parameters:") . " "; | |
ceb30ba4 AD |
198 | |
199 | $param_int_hidden = ($action_id != 7) ? "" : "display : none"; | |
200 | ||
201 | print "<input size=\"20\" style=\"$param_int_hidden\" | |
074bf20c | 202 | onkeypress=\"return filterCR(event, filterEditSave)\" |
143a4973 | 203 | name=\"action_param\" value=\"$action_param\">"; |
ceb30ba4 AD |
204 | |
205 | $param_int_hidden = ($action_id == 7) ? "" : "display : none"; | |
206 | ||
207 | print_label_select($link, "action_param_label", $action_param, | |
208 | $param_int_hidden); | |
209 | ||
143a4973 | 210 | print "</span>"; |
10fa6615 | 211 | |
143a4973 | 212 | print " "; // tiny layout hack |
10fa6615 AD |
213 | |
214 | print "</div>"; | |
215 | ||
216 | print "<div class=\"dlgSec\">".__("Options")."</div>"; | |
217 | print "<div class=\"dlgSecCont\">"; | |
218 | ||
ecace165 AD |
219 | print "<div style=\"line-height : 100%\">"; |
220 | ||
10fa6615 AD |
221 | if ($enabled) { |
222 | $checked = "checked"; | |
223 | } else { | |
224 | $checked = ""; | |
225 | } | |
226 | ||
227 | print "<input type=\"checkbox\" name=\"enabled\" id=\"enabled\" $checked> | |
228 | <label for=\"enabled\">".__('Enabled')."</label><br/>"; | |
229 | ||
230 | if ($inverse) { | |
231 | $checked = "checked"; | |
232 | } else { | |
233 | $checked = ""; | |
234 | } | |
235 | ||
236 | print "<input type=\"checkbox\" name=\"inverse\" id=\"inverse\" $checked> | |
237 | <label for=\"inverse\">".__('Inverse match')."</label>"; | |
238 | ||
239 | print "</div>"; | |
ecace165 | 240 | print "</div>"; |
10fa6615 AD |
241 | |
242 | print "<div class=\"dlgButtons\">"; | |
ef8be8ea | 243 | |
ddb61e79 | 244 | $reg_exp = htmlspecialchars($reg_exp, ENT_QUOTES); // second escaping seems to be needed for javascript |
143a4973 AD |
245 | |
246 | print "<div style=\"float : left\">"; | |
577399e8 AD |
247 | print "<button onclick='return removeFilter($filter_id, \"$reg_exp\")'>". |
248 | __('Remove')."</button>"; | |
143a4973 AD |
249 | print "</div>"; |
250 | ||
577399e8 AD |
251 | print "<button onclick=\"return filterEditSave()\">". |
252 | __('Save')."</button> "; | |
ef8be8ea | 253 | |
577399e8 AD |
254 | print "<button onclick=\"return filterEditCancel()\">". |
255 | __('Cancel')."</button>"; | |
ef8be8ea | 256 | |
951906dc | 257 | print "]]></content></dlg>"; |
ef8be8ea AD |
258 | |
259 | return; | |
260 | } | |
261 | ||
262 | ||
263 | if ($subop == "editSave") { | |
264 | ||
b8ffa322 AD |
265 | global $memcache; |
266 | ||
267 | if ($memcache) $memcache->flush(); | |
268 | ||
b4e75b2a AD |
269 | $reg_exp = db_escape_string(trim($_REQUEST["reg_exp"])); |
270 | $filter_type = db_escape_string(trim($_REQUEST["filter_type"])); | |
271 | $filter_id = db_escape_string($_REQUEST["id"]); | |
272 | $feed_id = db_escape_string($_REQUEST["feed_id"]); | |
273 | $action_id = db_escape_string($_REQUEST["action_id"]); | |
274 | $action_param = db_escape_string($_REQUEST["action_param"]); | |
275 | $action_param_label = db_escape_string($_REQUEST["action_param_label"]); | |
276 | $enabled = checkbox_to_sql_bool(db_escape_string($_REQUEST["enabled"])); | |
277 | $inverse = checkbox_to_sql_bool(db_escape_string($_REQUEST["inverse"])); | |
ef8be8ea | 278 | |
44d0e774 | 279 | # for the time being, no other filters use params anyway... |
b4e75b2a | 280 | $filter_param = db_escape_string($_REQUEST["filter_date_modifier"]); |
44d0e774 | 281 | |
ef8be8ea AD |
282 | if (!$feed_id) { |
283 | $feed_id = 'NULL'; | |
284 | } else { | |
285 | $feed_id = sprintf("'%s'", db_escape_string($feed_id)); | |
286 | } | |
ceb30ba4 AD |
287 | |
288 | /* When processing 'assign label' filters, action_param_label dropbox | |
289 | * overrides action_param */ | |
290 | ||
291 | if ($action_id == 7) { | |
292 | $action_param = $action_param_label; | |
293 | } | |
294 | ||
ef8be8ea AD |
295 | $result = db_query($link, "UPDATE ttrss_filters SET |
296 | reg_exp = '$reg_exp', | |
297 | feed_id = $feed_id, | |
298 | action_id = '$action_id', | |
299 | filter_type = '$filter_type', | |
073ca0e6 | 300 | enabled = $enabled, |
3f2ff803 | 301 | inverse = $inverse, |
44d0e774 AD |
302 | action_param = '$action_param', |
303 | filter_param = '$filter_param' | |
4dccf1ed | 304 | WHERE id = '$filter_id' AND owner_uid = " . $_SESSION["uid"]); |
ef8be8ea AD |
305 | } |
306 | ||
307 | if ($subop == "remove") { | |
a522a767 AD |
308 | |
309 | if ($memcache) $memcache->flush(); | |
ef8be8ea | 310 | |
b4e75b2a | 311 | $ids = split(",", db_escape_string($_REQUEST["ids"])); |
ef8be8ea | 312 | |
4dccf1ed AD |
313 | foreach ($ids as $id) { |
314 | db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id' AND owner_uid = ". $_SESSION["uid"]); | |
ef8be8ea AD |
315 | } |
316 | } | |
317 | ||
318 | if ($subop == "add") { | |
a522a767 AD |
319 | |
320 | if ($memcache) $memcache->flush(); | |
321 | ||
b4e75b2a AD |
322 | $regexp = db_escape_string(trim($_REQUEST["reg_exp"])); |
323 | $filter_type = db_escape_string(trim($_REQUEST["filter_type"])); | |
324 | $feed_id = db_escape_string($_REQUEST["feed_id"]); | |
325 | $action_id = db_escape_string($_REQUEST["action_id"]); | |
326 | $action_param = db_escape_string($_REQUEST["action_param"]); | |
327 | $action_param_label = db_escape_string($_REQUEST["action_param_label"]); | |
328 | $inverse = checkbox_to_sql_bool(db_escape_string($_REQUEST["inverse"])); | |
4dccf1ed | 329 | |
44d0e774 | 330 | # for the time being, no other filters use params anyway... |
b4e75b2a | 331 | $filter_param = db_escape_string($_REQUEST["filter_date_modifier"]); |
44d0e774 | 332 | |
4dccf1ed AD |
333 | if (!$regexp) return; |
334 | ||
335 | if (!$feed_id) { | |
336 | $feed_id = 'NULL'; | |
337 | } else { | |
338 | $feed_id = sprintf("'%s'", db_escape_string($feed_id)); | |
339 | } | |
340 | ||
db34a63e AD |
341 | /* When processing 'assign label' filters, action_param_label dropbox |
342 | * overrides action_param */ | |
343 | ||
344 | if ($action_id == 7) { | |
345 | $action_param = $action_param_label; | |
346 | } | |
347 | ||
4dccf1ed AD |
348 | $result = db_query($link, |
349 | "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id, | |
a8732d0c | 350 | action_id, action_param, inverse, filter_param) |
4dccf1ed AD |
351 | VALUES |
352 | ('$regexp', '$filter_type','".$_SESSION["uid"]."', | |
a8732d0c | 353 | $feed_id, '$action_id', '$action_param', $inverse, '$filter_param')"); |
4dccf1ed | 354 | |
5e6f933a AD |
355 | if (db_affected_rows($link, $result) != 0) { |
356 | print T_sprintf("Created filter <b>%s</b>", htmlspecialchars($regexp)); | |
357 | } | |
358 | ||
359 | return; | |
ef8be8ea AD |
360 | } |
361 | ||
362 | if ($quiet) return; | |
363 | ||
fe8d2059 AD |
364 | set_pref($link, "_PREFS_ACTIVE_TAB", "filterConfig"); |
365 | ||
b4e75b2a | 366 | $sort = db_escape_string($_REQUEST["sort"]); |
ef8be8ea AD |
367 | |
368 | if (!$sort || $sort == "undefined") { | |
369 | $sort = "reg_exp"; | |
370 | } | |
371 | ||
ef8be8ea AD |
372 | $result = db_query($link, "SELECT id,description |
373 | FROM ttrss_filter_types ORDER BY description"); | |
374 | ||
375 | $filter_types = array(); | |
376 | ||
377 | while ($line = db_fetch_assoc($result)) { | |
378 | //array_push($filter_types, $line["description"]); | |
379 | $filter_types[$line["id"]] = $line["description"]; | |
380 | } | |
381 | ||
9c87d75c | 382 | |
b4e75b2a | 383 | $filter_search = db_escape_string($_REQUEST["search"]); |
9c87d75c | 384 | |
b4e75b2a | 385 | if (array_key_exists("search", $_REQUEST)) { |
9c87d75c AD |
386 | $_SESSION["prefs_filter_search"] = $filter_search; |
387 | } else { | |
388 | $filter_search = $_SESSION["prefs_filter_search"]; | |
389 | } | |
8df7184c AD |
390 | |
391 | print "<div id=\"pref-filter-wrap\" dojoType=\"dijit.layout.BorderContainer\" gutters=\"false\">"; | |
392 | print "<div id=\"pref-filter-header\" dojoType=\"dijit.layout.ContentPane\" region=\"top\">"; | |
393 | print "<div id=\"pref-filter-toolbar\" dojoType=\"dijit.Toolbar\">"; | |
9c87d75c | 394 | |
d69fa6d6 AD |
395 | print "<div dojoType=\"dijit.form.DropDownButton\">". |
396 | "<span>" . __('Select')."</span>"; | |
397 | print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; | |
a740f4b5 | 398 | print "<div onclick=\"dijit.byId('filterTree').model.setAllChecked(true)\" |
d69fa6d6 | 399 | dojoType=\"dijit.MenuItem\">".__('All')."</div>"; |
a740f4b5 | 400 | print "<div onclick=\"dijit.byId('filterTree').model.setAllChecked(false)\" |
d69fa6d6 AD |
401 | dojoType=\"dijit.MenuItem\">".__('None')."</div>"; |
402 | print "</div></div>"; | |
403 | ||
1985a5e0 AD |
404 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return quickAddFilter()\">". |
405 | __('Create filter')."</button dojoType=\"dijit.form.Button\"> "; | |
0d32b41e | 406 | |
1985a5e0 AD |
407 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return editSelectedFilter()\">". |
408 | __('Edit')."</button dojoType=\"dijit.form.Button\"> "; | |
ef8be8ea | 409 | |
1985a5e0 AD |
410 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return removeSelectedFilters()\">". |
411 | __('Remove')."</button dojoType=\"dijit.form.Button\"> "; | |
1e5548db | 412 | |
fe1c99af | 413 | if (defined('_ENABLE_FEED_DEBUGGING')) { |
1985a5e0 AD |
414 | print "<button dojoType=\"dijit.form.Button\" onclick=\"rescore_all_feeds()\">". |
415 | __('Rescore articles')."</button dojoType=\"dijit.form.Button\"> "; | |
fe1c99af | 416 | } |
95a948a5 | 417 | |
8df7184c AD |
418 | print "</div>"; # toolbar |
419 | print "</div>"; # toolbar-frame | |
420 | print "<div id=\"pref-filter-content\" dojoType=\"dijit.layout.ContentPane\" region=\"center\">"; | |
421 | ||
a740f4b5 AD |
422 | print "<div id=\"filterlistLoading\"> |
423 | <img src='images/indicator_tiny.gif'>". | |
424 | __("Loading, please wait...")."</div>"; | |
425 | ||
426 | print "<div dojoType=\"dojo.data.ItemFileWriteStore\" jsId=\"filterStore\" | |
427 | url=\"backend.php?op=pref-filters&subop=getfiltertree\"> | |
428 | </div> | |
429 | <div dojoType=\"lib.CheckBoxStoreModel\" jsId=\"filterModel\" store=\"filterStore\" | |
430 | query=\"{id:'root'}\" rootId=\"root\" rootLabel=\"Feeds\" | |
431 | childrenAttrs=\"items\" checkboxStrict=\"false\" checkboxAll=\"false\"> | |
432 | </div> | |
433 | <div dojoType=\"fox.PrefFilterTree\" id=\"filterTree\" | |
434 | model=\"filterModel\" openOnClick=\"true\"> | |
435 | <script type=\"dojo/method\" event=\"onLoad\" args=\"item\"> | |
436 | Element.hide(\"filterlistLoading\"); | |
437 | </script> | |
438 | </div>"; | |
8df7184c AD |
439 | |
440 | print "</div>"; #pane | |
441 | print "</div>"; #container | |
ef8be8ea | 442 | } |
ceb30ba4 | 443 | |
ef8be8ea | 444 | ?> |