]>
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 | ||
e43399b7 AD |
38 | if (db_num_rows($result) > 0) { |
39 | ||
40 | while ($line = db_fetch_assoc($result)) { | |
41 | if ($cur_action_description != $line['action_description']) { | |
42 | ||
43 | if ($cat) | |
44 | array_push($root['items'], $cat); | |
45 | ||
46 | $cat = array(); | |
47 | $cat['id'] = 'ACTION:' . $line['action_id']; | |
48 | $cat['name'] = $line['action_description']; | |
49 | $cat['items'] = array(); | |
50 | ||
51 | $cur_action_description = $line['action_description']; | |
52 | } | |
53 | ||
54 | if (array_search($line["action_name"], | |
55 | array("score", "tag", "label")) === false) { | |
56 | ||
57 | $line["action_param"] = ''; | |
58 | } else { | |
59 | if ($line['action_name'] == 'label') { | |
60 | ||
61 | $tmp_result = db_query($link, "SELECT fg_color, bg_color | |
62 | FROM ttrss_labels2 WHERE caption = '". | |
63 | db_escape_string($line["action_param"])."' AND | |
64 | owner_uid = " . $_SESSION["uid"]); | |
65 | ||
66 | if (db_num_rows($tmp_result) != 0) { | |
67 | $fg_color = db_fetch_result($tmp_result, 0, "fg_color"); | |
68 | $bg_color = db_fetch_result($tmp_result, 0, "bg_color"); | |
69 | ||
70 | $tmp = "<span class=\"labelColorIndicator\" style='color : $fg_color; background-color : $bg_color'>α</span> " . $line['action_param']; | |
71 | ||
72 | $line['action_param'] = $tmp; | |
73 | } | |
42623d7f | 74 | } |
a740f4b5 | 75 | } |
e43399b7 AD |
76 | |
77 | $filter = array(); | |
78 | $filter['id'] = 'FILTER:' . $line['id']; | |
79 | $filter['bare_id'] = $line['id']; | |
80 | $filter['name'] = $line['reg_exp']; | |
81 | $filter['type'] = $line['filter_type']; | |
82 | $filter['enabled'] = sql_bool_to_bool($line['enabled']); | |
83 | $filter['param'] = $line['action_param']; | |
84 | $filter['inverse'] = sql_bool_to_bool($line['inverse']); | |
85 | $filter['checkbox'] = false; | |
86 | ||
87 | if ($line['feed_id']) | |
88 | $filter['feed'] = $line['feed_title']; | |
89 | ||
90 | array_push($cat['items'], $filter); | |
a740f4b5 | 91 | } |
e43399b7 AD |
92 | |
93 | array_push($root['items'], $cat); | |
a740f4b5 AD |
94 | } |
95 | ||
a740f4b5 AD |
96 | $fl = array(); |
97 | $fl['identifier'] = 'id'; | |
98 | $fl['label'] = 'name'; | |
99 | $fl['items'] = array($root); | |
100 | ||
101 | print json_encode($fl); | |
102 | return; | |
103 | } | |
104 | ||
ef8be8ea AD |
105 | if ($subop == "edit") { |
106 | ||
b4e75b2a | 107 | $filter_id = db_escape_string($_REQUEST["id"]); |
ef8be8ea AD |
108 | |
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 | 123 | |
d90868d7 AD |
124 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-filters\">"; |
125 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"id\" value=\"$filter_id\">"; | |
126 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" 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 | ||
d90868d7 | 146 | print "<span id=\"filterDlg_dateModBox\" $date_ops_invisible>"; |
6e278744 | 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, | |
d90868d7 | 154 | $filter_params, 'dojoType="dijit.form.Select"'); |
44d0e774 AD |
155 | |
156 | print " </span>"; | |
6e278744 | 157 | |
d90868d7 AD |
158 | print "<input dojoType=\"dijit.form.ValidationTextBox\" |
159 | required=\"1\" | |
160 | name=\"reg_exp\" style=\"font-size : 16px;\" value=\"$reg_exp\">"; | |
10fa6615 | 161 | |
d90868d7 | 162 | print "<span id=\"filterDlg_dateChkBox\" $date_ops_invisible>"; |
59216e08 | 163 | print " <button dojoType=\"dijit.form.Button\" onclick=\"return filterDlgCheckDate()\">". |
a918f5f9 | 164 | __('Check it')."</button>"; |
6e278744 AD |
165 | print "</span>"; |
166 | ||
167 | print "<br/> " . __("on field") . " "; | |
168 | print_select_hash("filter_type", $filter_type, $filter_types, | |
d90868d7 | 169 | 'onchange="filterDlgCheckType(this)" dojoType="dijit.form.Select"'); |
10fa6615 AD |
170 | |
171 | print "<br/>"; | |
172 | ||
173 | print __("in") . " "; | |
d90868d7 AD |
174 | print_feed_select($link, "feed_id", $feed_id, |
175 | 'dojoType="dijit.form.FilteringSelect"'); | |
10fa6615 AD |
176 | |
177 | print "</div>"; | |
178 | ||
ecace165 | 179 | print "<div class=\"dlgSec\">".__("Perform Action")."</div>"; |
10fa6615 AD |
180 | |
181 | print "<div class=\"dlgSecCont\">"; | |
182 | ||
d90868d7 | 183 | print "<select name=\"action_id\" dojoType=\"dijit.form.Select\" |
10fa6615 AD |
184 | onchange=\"filterDlgCheckAction(this)\">"; |
185 | ||
186 | $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions | |
187 | ORDER BY name"); | |
188 | ||
189 | while ($line = db_fetch_assoc($result)) { | |
d90868d7 | 190 | $is_sel = ($line["id"] == $action_id) ? "selected=\"1\"" : ""; |
10fa6615 AD |
191 | printf("<option value='%d' $is_sel>%s</option>", $line["id"], __($line["description"])); |
192 | } | |
193 | ||
194 | print "</select>"; | |
195 | ||
ceb30ba4 | 196 | $param_hidden = ($action_id == 4 || $action_id == 6 || $action_id == 7) ? "" : "display : none"; |
10fa6615 | 197 | |
d90868d7 | 198 | print "<span id=\"filterDlg_paramBox\" style=\"$param_hidden\">"; |
143a4973 | 199 | print " " . __("with parameters:") . " "; |
ceb30ba4 AD |
200 | |
201 | $param_int_hidden = ($action_id != 7) ? "" : "display : none"; | |
202 | ||
d90868d7 AD |
203 | print "<input style=\"$param_int_hidden\" |
204 | dojoType=\"dijit.form.TextBox\" id=\"filterDlg_actionParam\" | |
143a4973 | 205 | name=\"action_param\" value=\"$action_param\">"; |
ceb30ba4 AD |
206 | |
207 | $param_int_hidden = ($action_id == 7) ? "" : "display : none"; | |
208 | ||
209 | print_label_select($link, "action_param_label", $action_param, | |
d90868d7 AD |
210 | "style=\"$param_int_hidden\"" . |
211 | 'id="filterDlg_actionParamLabel" dojoType="dijit.form.Select"'); | |
ceb30ba4 | 212 | |
143a4973 | 213 | print "</span>"; |
10fa6615 | 214 | |
143a4973 | 215 | print " "; // tiny layout hack |
10fa6615 AD |
216 | |
217 | print "</div>"; | |
218 | ||
219 | print "<div class=\"dlgSec\">".__("Options")."</div>"; | |
220 | print "<div class=\"dlgSecCont\">"; | |
221 | ||
ecace165 AD |
222 | print "<div style=\"line-height : 100%\">"; |
223 | ||
10fa6615 | 224 | if ($enabled) { |
d90868d7 | 225 | $checked = "checked=\"1\""; |
10fa6615 AD |
226 | } else { |
227 | $checked = ""; | |
228 | } | |
229 | ||
d90868d7 | 230 | print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"enabled\" id=\"enabled\" $checked> |
10fa6615 AD |
231 | <label for=\"enabled\">".__('Enabled')."</label><br/>"; |
232 | ||
233 | if ($inverse) { | |
d90868d7 | 234 | $checked = "checked=\"1\""; |
10fa6615 AD |
235 | } else { |
236 | $checked = ""; | |
237 | } | |
238 | ||
d90868d7 | 239 | print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"inverse\" id=\"inverse\" $checked> |
10fa6615 AD |
240 | <label for=\"inverse\">".__('Inverse match')."</label>"; |
241 | ||
242 | print "</div>"; | |
ecace165 | 243 | print "</div>"; |
10fa6615 AD |
244 | |
245 | print "<div class=\"dlgButtons\">"; | |
ef8be8ea | 246 | |
143a4973 | 247 | print "<div style=\"float : left\">"; |
90e4e726 | 248 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').removeFilter()\">". |
577399e8 | 249 | __('Remove')."</button>"; |
143a4973 AD |
250 | print "</div>"; |
251 | ||
59216e08 | 252 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').execute()\">". |
577399e8 | 253 | __('Save')."</button> "; |
ef8be8ea | 254 | |
59216e08 | 255 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').hide()\">". |
577399e8 | 256 | __('Cancel')."</button>"; |
ef8be8ea | 257 | |
d90868d7 | 258 | print "</div>"; |
ef8be8ea AD |
259 | |
260 | return; | |
261 | } | |
262 | ||
263 | ||
264 | if ($subop == "editSave") { | |
265 | ||
b8ffa322 AD |
266 | global $memcache; |
267 | ||
268 | if ($memcache) $memcache->flush(); | |
269 | ||
b4e75b2a AD |
270 | $reg_exp = db_escape_string(trim($_REQUEST["reg_exp"])); |
271 | $filter_type = db_escape_string(trim($_REQUEST["filter_type"])); | |
272 | $filter_id = db_escape_string($_REQUEST["id"]); | |
273 | $feed_id = db_escape_string($_REQUEST["feed_id"]); | |
274 | $action_id = db_escape_string($_REQUEST["action_id"]); | |
275 | $action_param = db_escape_string($_REQUEST["action_param"]); | |
276 | $action_param_label = db_escape_string($_REQUEST["action_param_label"]); | |
277 | $enabled = checkbox_to_sql_bool(db_escape_string($_REQUEST["enabled"])); | |
278 | $inverse = checkbox_to_sql_bool(db_escape_string($_REQUEST["inverse"])); | |
ef8be8ea | 279 | |
44d0e774 | 280 | # for the time being, no other filters use params anyway... |
b4e75b2a | 281 | $filter_param = db_escape_string($_REQUEST["filter_date_modifier"]); |
44d0e774 | 282 | |
ef8be8ea AD |
283 | if (!$feed_id) { |
284 | $feed_id = 'NULL'; | |
285 | } else { | |
286 | $feed_id = sprintf("'%s'", db_escape_string($feed_id)); | |
287 | } | |
ceb30ba4 AD |
288 | |
289 | /* When processing 'assign label' filters, action_param_label dropbox | |
290 | * overrides action_param */ | |
291 | ||
292 | if ($action_id == 7) { | |
293 | $action_param = $action_param_label; | |
294 | } | |
295 | ||
ef8be8ea AD |
296 | $result = db_query($link, "UPDATE ttrss_filters SET |
297 | reg_exp = '$reg_exp', | |
298 | feed_id = $feed_id, | |
299 | action_id = '$action_id', | |
300 | filter_type = '$filter_type', | |
073ca0e6 | 301 | enabled = $enabled, |
3f2ff803 | 302 | inverse = $inverse, |
44d0e774 AD |
303 | action_param = '$action_param', |
304 | filter_param = '$filter_param' | |
4dccf1ed | 305 | WHERE id = '$filter_id' AND owner_uid = " . $_SESSION["uid"]); |
ef8be8ea AD |
306 | } |
307 | ||
308 | if ($subop == "remove") { | |
a522a767 AD |
309 | |
310 | if ($memcache) $memcache->flush(); | |
ef8be8ea | 311 | |
b4e75b2a | 312 | $ids = split(",", db_escape_string($_REQUEST["ids"])); |
ef8be8ea | 313 | |
4dccf1ed AD |
314 | foreach ($ids as $id) { |
315 | db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id' AND owner_uid = ". $_SESSION["uid"]); | |
ef8be8ea | 316 | } |
90e4e726 | 317 | return; |
ef8be8ea AD |
318 | } |
319 | ||
320 | if ($subop == "add") { | |
a522a767 AD |
321 | |
322 | if ($memcache) $memcache->flush(); | |
323 | ||
b4e75b2a AD |
324 | $regexp = db_escape_string(trim($_REQUEST["reg_exp"])); |
325 | $filter_type = db_escape_string(trim($_REQUEST["filter_type"])); | |
326 | $feed_id = db_escape_string($_REQUEST["feed_id"]); | |
327 | $action_id = db_escape_string($_REQUEST["action_id"]); | |
328 | $action_param = db_escape_string($_REQUEST["action_param"]); | |
329 | $action_param_label = db_escape_string($_REQUEST["action_param_label"]); | |
330 | $inverse = checkbox_to_sql_bool(db_escape_string($_REQUEST["inverse"])); | |
4dccf1ed | 331 | |
44d0e774 | 332 | # for the time being, no other filters use params anyway... |
b4e75b2a | 333 | $filter_param = db_escape_string($_REQUEST["filter_date_modifier"]); |
44d0e774 | 334 | |
4dccf1ed AD |
335 | if (!$regexp) return; |
336 | ||
337 | if (!$feed_id) { | |
338 | $feed_id = 'NULL'; | |
339 | } else { | |
340 | $feed_id = sprintf("'%s'", db_escape_string($feed_id)); | |
341 | } | |
342 | ||
db34a63e AD |
343 | /* When processing 'assign label' filters, action_param_label dropbox |
344 | * overrides action_param */ | |
345 | ||
346 | if ($action_id == 7) { | |
347 | $action_param = $action_param_label; | |
348 | } | |
349 | ||
4dccf1ed AD |
350 | $result = db_query($link, |
351 | "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id, | |
a8732d0c | 352 | action_id, action_param, inverse, filter_param) |
4dccf1ed AD |
353 | VALUES |
354 | ('$regexp', '$filter_type','".$_SESSION["uid"]."', | |
a8732d0c | 355 | $feed_id, '$action_id', '$action_param', $inverse, '$filter_param')"); |
4dccf1ed | 356 | |
5e6f933a AD |
357 | if (db_affected_rows($link, $result) != 0) { |
358 | print T_sprintf("Created filter <b>%s</b>", htmlspecialchars($regexp)); | |
359 | } | |
360 | ||
361 | return; | |
ef8be8ea AD |
362 | } |
363 | ||
364 | if ($quiet) return; | |
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 | 404 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return quickAddFilter()\">". |
c33f56f3 | 405 | __('Create filter')."</button> "; |
0d32b41e | 406 | |
1985a5e0 | 407 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return editSelectedFilter()\">". |
c33f56f3 | 408 | __('Edit')."</button> "; |
ef8be8ea | 409 | |
1985a5e0 | 410 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return removeSelectedFilters()\">". |
c33f56f3 | 411 | __('Remove')."</button> "; |
1e5548db | 412 | |
fe1c99af | 413 | if (defined('_ENABLE_FEED_DEBUGGING')) { |
1985a5e0 | 414 | print "<button dojoType=\"dijit.form.Button\" onclick=\"rescore_all_feeds()\">". |
c33f56f3 | 415 | __('Rescore articles')."</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 | ?> |