]>
Commit | Line | Data |
---|---|---|
ef8be8ea AD |
1 | <?php |
2 | function module_pref_filters($link) { | |
3 | $subop = $_GET["subop"]; | |
4 | $quiet = $_GET["quiet"]; | |
5 | ||
6 | if ($subop == "edit") { | |
7 | ||
8 | $filter_id = db_escape_string($_GET["id"]); | |
9 | ||
10 | $result = db_query($link, | |
11 | "SELECT * FROM ttrss_filters WHERE id = '$filter_id' AND owner_uid = " . $_SESSION["uid"]); | |
12 | ||
47439031 | 13 | $reg_exp = htmlspecialchars(db_fetch_result($result, 0, "reg_exp")); |
ef8be8ea AD |
14 | $filter_type = db_fetch_result($result, 0, "filter_type"); |
15 | $feed_id = db_fetch_result($result, 0, "feed_id"); | |
16 | $action_id = db_fetch_result($result, 0, "action_id"); | |
073ca0e6 | 17 | $action_param = db_fetch_result($result, 0, "action_param"); |
ef8be8ea AD |
18 | |
19 | $enabled = sql_bool_to_bool(db_fetch_result($result, 0, "enabled")); | |
3f2ff803 | 20 | $inverse = sql_bool_to_bool(db_fetch_result($result, 0, "inverse")); |
ef8be8ea | 21 | |
a3c159c4 | 22 | print "<div id=\"infoBoxTitle\">".__('Filter editor')."</div>"; |
ef8be8ea AD |
23 | print "<div class=\"infoBoxContents\">"; |
24 | ||
e6312f6c | 25 | print "<form id=\"filter_edit_form\" onsubmit='return false'>"; |
ef8be8ea AD |
26 | |
27 | print "<input type=\"hidden\" name=\"op\" value=\"pref-filters\">"; | |
28 | print "<input type=\"hidden\" name=\"id\" value=\"$filter_id\">"; | |
29 | print "<input type=\"hidden\" name=\"subop\" value=\"editSave\">"; | |
ef8be8ea AD |
30 | |
31 | $result = db_query($link, "SELECT id,description | |
32 | FROM ttrss_filter_types ORDER BY description"); | |
33 | ||
34 | $filter_types = array(); | |
35 | ||
36 | while ($line = db_fetch_assoc($result)) { | |
37 | //array_push($filter_types, $line["description"]); | |
89cb787e | 38 | $filter_types[$line["id"]] = __($line["description"]); |
ef8be8ea AD |
39 | } |
40 | ||
41 | print "<table width='100%'>"; | |
42 | ||
3692e98f | 43 | print "<tr><td>".__('Match:')."</td> |
ef8be8ea AD |
44 | <td><input onkeypress=\"return filterCR(event, filterEditSave)\" |
45 | onkeyup=\"toggleSubmitNotEmpty(this, 'infobox_submit')\" | |
b5015f72 AD |
46 | onchange=\"toggleSubmitNotEmpty(this, 'infobox_submit')\" |
47 | name=\"reg_exp\" class=\"iedit\" value=\"$reg_exp\">"; | |
ef8be8ea | 48 | |
a3c159c4 | 49 | print "</td></tr><tr><td>".__('On field:')."</td><td>"; |
ef8be8ea | 50 | |
8011ac36 | 51 | print_select_hash("filter_type", $filter_type, $filter_types, "class=\"_iedit\""); |
ef8be8ea AD |
52 | |
53 | print "</td></tr>"; | |
a3c159c4 | 54 | print "<tr><td>".__('Feed:')."</td><td colspan='2'>"; |
ef8be8ea AD |
55 | |
56 | print_feed_select($link, "feed_id", $feed_id); | |
57 | ||
58 | print "</td></tr>"; | |
59 | ||
a3c159c4 | 60 | print "<tr><td>".__('Action:')."</td>"; |
ef8be8ea | 61 | |
073ca0e6 AD |
62 | print "<td colspan='2'><select name=\"action_id\" |
63 | onchange=\"filterDlgCheckAction(this)\">"; | |
ef8be8ea AD |
64 | |
65 | $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions | |
66 | ORDER BY name"); | |
67 | ||
68 | while ($line = db_fetch_assoc($result)) { | |
69 | $is_sel = ($line["id"] == $action_id) ? "selected" : ""; | |
89cb787e | 70 | printf("<option value='%d' $is_sel>%s</option>", $line["id"], __($line["description"])); |
ef8be8ea AD |
71 | } |
72 | ||
73 | print "</select>"; | |
74 | ||
75 | print "</td></tr>"; | |
76 | ||
a3c159c4 | 77 | print "<tr><td>".__('Params:')."</td>"; |
073ca0e6 | 78 | |
ff6e357a | 79 | $param_disabled = ($action_id == 4 || $action_id == 6) ? "" : "disabled"; |
073ca0e6 AD |
80 | |
81 | print "<td><input $param_disabled class='iedit' | |
82 | name=\"action_param\" value=\"$action_param\"></td></tr>"; | |
83 | ||
ef8be8ea AD |
84 | if ($enabled) { |
85 | $checked = "checked"; | |
86 | } else { | |
87 | $checked = ""; | |
88 | } | |
89 | ||
3f2ff803 | 90 | print "<tr><td valign='top'>Options:</td><td> |
ef8be8ea | 91 | <input type=\"checkbox\" name=\"enabled\" id=\"enabled\" $checked> |
a3c159c4 | 92 | <label for=\"enabled\">".__('Enabled')."</label><br/>"; |
3f2ff803 AD |
93 | |
94 | if ($inverse) { | |
95 | $checked = "checked"; | |
96 | } else { | |
97 | $checked = ""; | |
98 | } | |
99 | ||
100 | print "<input type=\"checkbox\" name=\"inverse\" id=\"inverse\" $checked> | |
a3c159c4 | 101 | <label for=\"inverse\">".__('Inverse match')."</label>"; |
ef8be8ea AD |
102 | |
103 | print "</td></tr></table>"; | |
104 | ||
105 | print "</form>"; | |
106 | ||
107 | print "<div align='right'>"; | |
108 | ||
109 | print "<input type=\"submit\" | |
110 | id=\"infobox_submit\" | |
111 | class=\"button\" onclick=\"return filterEditSave()\" | |
a3c159c4 | 112 | value=\"".__('Save')."\"> "; |
ef8be8ea AD |
113 | |
114 | print "<input class=\"button\" | |
115 | type=\"submit\" onclick=\"return filterEditCancel()\" | |
a3c159c4 | 116 | value=\"".__('Cancel')."\">"; |
ef8be8ea AD |
117 | |
118 | print "</div>"; | |
119 | ||
120 | return; | |
121 | } | |
122 | ||
123 | ||
124 | if ($subop == "editSave") { | |
125 | ||
126 | $reg_exp = db_escape_string(trim($_GET["reg_exp"])); | |
127 | $filter_type = db_escape_string(trim($_GET["filter_type"])); | |
128 | $filter_id = db_escape_string($_GET["id"]); | |
129 | $feed_id = db_escape_string($_GET["feed_id"]); | |
130 | $action_id = db_escape_string($_GET["action_id"]); | |
073ca0e6 | 131 | $action_param = db_escape_string($_GET["action_param"]); |
ef8be8ea | 132 | $enabled = checkbox_to_sql_bool(db_escape_string($_GET["enabled"])); |
3f2ff803 | 133 | $inverse = checkbox_to_sql_bool(db_escape_string($_GET["inverse"])); |
ef8be8ea AD |
134 | |
135 | if (!$feed_id) { | |
136 | $feed_id = 'NULL'; | |
137 | } else { | |
138 | $feed_id = sprintf("'%s'", db_escape_string($feed_id)); | |
139 | } | |
140 | ||
141 | $result = db_query($link, "UPDATE ttrss_filters SET | |
142 | reg_exp = '$reg_exp', | |
143 | feed_id = $feed_id, | |
144 | action_id = '$action_id', | |
145 | filter_type = '$filter_type', | |
073ca0e6 | 146 | enabled = $enabled, |
3f2ff803 | 147 | inverse = $inverse, |
073ca0e6 | 148 | action_param = '$action_param' |
4dccf1ed | 149 | WHERE id = '$filter_id' AND owner_uid = " . $_SESSION["uid"]); |
5e6f933a AD |
150 | |
151 | if (db_affected_rows($link, $result) != 0) { | |
152 | print_notice(T_sprintf("Saved filter <b>%s</b>", htmlspecialchars($reg_exp))); | |
153 | } | |
154 | ||
ef8be8ea AD |
155 | } |
156 | ||
157 | if ($subop == "remove") { | |
158 | ||
4dccf1ed | 159 | $ids = split(",", db_escape_string($_GET["ids"])); |
ef8be8ea | 160 | |
4dccf1ed AD |
161 | foreach ($ids as $id) { |
162 | db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id' AND owner_uid = ". $_SESSION["uid"]); | |
ef8be8ea AD |
163 | } |
164 | } | |
165 | ||
166 | if ($subop == "add") { | |
167 | ||
4dccf1ed AD |
168 | $regexp = db_escape_string(trim($_GET["reg_exp"])); |
169 | $filter_type = db_escape_string(trim($_GET["filter_type"])); | |
170 | $feed_id = db_escape_string($_GET["feed_id"]); | |
171 | $action_id = db_escape_string($_GET["action_id"]); | |
172 | $action_param = db_escape_string($_GET["action_param"]); | |
173 | ||
174 | $inverse = checkbox_to_sql_bool(db_escape_string($_GET["inverse"])); | |
175 | ||
176 | if (!$regexp) return; | |
177 | ||
178 | if (!$feed_id) { | |
179 | $feed_id = 'NULL'; | |
180 | } else { | |
181 | $feed_id = sprintf("'%s'", db_escape_string($feed_id)); | |
182 | } | |
183 | ||
184 | $result = db_query($link, | |
185 | "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id, | |
186 | action_id, action_param, inverse) | |
187 | VALUES | |
188 | ('$regexp', '$filter_type','".$_SESSION["uid"]."', | |
189 | $feed_id, '$action_id', '$action_param', $inverse)"); | |
190 | ||
5e6f933a AD |
191 | if (db_affected_rows($link, $result) != 0) { |
192 | print T_sprintf("Created filter <b>%s</b>", htmlspecialchars($regexp)); | |
193 | } | |
194 | ||
195 | return; | |
ef8be8ea AD |
196 | } |
197 | ||
198 | if ($quiet) return; | |
199 | ||
fe8d2059 AD |
200 | set_pref($link, "_PREFS_ACTIVE_TAB", "filterConfig"); |
201 | ||
ef8be8ea AD |
202 | $sort = db_escape_string($_GET["sort"]); |
203 | ||
204 | if (!$sort || $sort == "undefined") { | |
205 | $sort = "reg_exp"; | |
206 | } | |
207 | ||
208 | // print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>"; | |
209 | ||
210 | $result = db_query($link, "SELECT id,description | |
211 | FROM ttrss_filter_types ORDER BY description"); | |
212 | ||
213 | $filter_types = array(); | |
214 | ||
215 | while ($line = db_fetch_assoc($result)) { | |
216 | //array_push($filter_types, $line["description"]); | |
217 | $filter_types[$line["id"]] = $line["description"]; | |
218 | } | |
219 | ||
9c87d75c AD |
220 | |
221 | $filter_search = db_escape_string($_GET["search"]); | |
222 | ||
223 | if (array_key_exists("search", $_GET)) { | |
224 | $_SESSION["prefs_filter_search"] = $filter_search; | |
225 | } else { | |
226 | $filter_search = $_SESSION["prefs_filter_search"]; | |
227 | } | |
228 | ||
229 | print "<div class=\"feedEditSearch\"> | |
230 | <input id=\"filter_search\" size=\"20\" type=\"search\" | |
4cf6fc6a AD |
231 | onfocus=\"javascript:disableHotkeys();\" |
232 | onblur=\"javascript:enableHotkeys();\" | |
9c87d75c AD |
233 | onchange=\"javascript:updateFilterList()\" value=\"$filter_search\"> |
234 | <input type=\"submit\" class=\"button\" | |
112d2aec AD |
235 | onclick=\"javascript:updateFilterList()\" value=\"".__('Search')."\"> |
236 | <p<a class='helpLinkPic' href=\"javascript:displayHelpInfobox(2)\"> | |
a3f4e4d3 | 237 | <img src='images/sign_quest.gif'></a></p> |
9c87d75c AD |
238 | </div>"; |
239 | ||
0d32b41e | 240 | |
ef8be8ea AD |
241 | print "<input type=\"submit\" |
242 | class=\"button\" | |
243 | onclick=\"return displayDlg('quickAddFilter', false)\" | |
244 | id=\"create_filter_btn\" | |
a3c159c4 | 245 | value=\"".__('Create filter')."\">"; |
ef8be8ea | 246 | |
95a948a5 AD |
247 | print " "; |
248 | ||
249 | print "<input type=\"submit\" | |
250 | class=\"button\" | |
251 | onclick=\"rescore_all_feeds()\" | |
252 | value=\"".__('Rescore articles')."\">"; | |
253 | ||
9c87d75c AD |
254 | if ($filter_search) { |
255 | $filter_search = db_escape_string($filter_search); | |
256 | $filter_search_query = "( | |
a3f4e4d3 AD |
257 | UPPER(ttrss_filter_actions.description) LIKE UPPER('%$filter_search%') OR |
258 | UPPER(reg_exp) LIKE UPPER('%$filter_search%') OR | |
259 | UPPER(ttrss_feeds.title) LIKE UPPER('%$filter_search%') OR | |
260 | UPPER(ttrss_filter_types.description) LIKE UPPER('%$filter_search%')) AND"; | |
9c87d75c AD |
261 | } else { |
262 | $filter_search_query = ""; | |
263 | } | |
264 | ||
ef8be8ea AD |
265 | $result = db_query($link, "SELECT |
266 | ttrss_filters.id AS id,reg_exp, | |
267 | ttrss_filter_types.name AS filter_type_name, | |
268 | ttrss_filter_types.description AS filter_type_descr, | |
269 | enabled, | |
3f2ff803 | 270 | inverse, |
ef8be8ea AD |
271 | feed_id, |
272 | ttrss_filter_actions.description AS action_description, | |
ff6e357a AD |
273 | ttrss_feeds.title AS feed_title, |
274 | ttrss_filter_actions.name AS action_name, | |
275 | ttrss_filters.action_param AS action_param | |
ef8be8ea AD |
276 | FROM |
277 | ttrss_filter_types,ttrss_filter_actions,ttrss_filters LEFT JOIN | |
278 | ttrss_feeds ON (ttrss_filters.feed_id = ttrss_feeds.id) | |
279 | WHERE | |
280 | filter_type = ttrss_filter_types.id AND | |
9c87d75c | 281 | $filter_search_query |
ef8be8ea AD |
282 | ttrss_filter_actions.id = action_id AND |
283 | ttrss_filters.owner_uid = ".$_SESSION["uid"]." | |
a82dc5e4 | 284 | ORDER by action_description, $sort"); |
ef8be8ea AD |
285 | |
286 | if (db_num_rows($result) != 0) { | |
287 | ||
ef8be8ea AD |
288 | print "<p><table width=\"100%\" cellspacing=\"0\" class=\"prefFilterList\" |
289 | id=\"prefFilterList\">"; | |
290 | ||
291 | print "<tr><td class=\"selectPrompt\" colspan=\"8\"> | |
e8d0177d AD |
292 | ".__('Select:')." |
293 | <a href=\"javascript:selectPrefRows('filter', true)\">".__('All')."</a>, | |
294 | <a href=\"javascript:selectPrefRows('filter', false)\">".__('None')."</a> | |
ef8be8ea AD |
295 | </td</tr>"; |
296 | ||
ef8be8ea | 297 | $lnum = 0; |
a82dc5e4 AD |
298 | |
299 | $cur_action_description = ""; | |
300 | ||
ef8be8ea AD |
301 | while ($line = db_fetch_assoc($result)) { |
302 | ||
303 | $class = ($lnum % 2) ? "even" : "odd"; | |
304 | ||
305 | $filter_id = $line["id"]; | |
306 | $edit_filter_id = $_GET["id"]; | |
307 | ||
308 | $enabled = sql_bool_to_bool($line["enabled"]); | |
3f2ff803 AD |
309 | $inverse = sql_bool_to_bool($line["inverse"]); |
310 | ||
ef8be8ea AD |
311 | if ($subop == "edit" && $filter_id != $edit_filter_id) { |
312 | $class .= "Grayed"; | |
313 | $this_row_id = ""; | |
314 | } else { | |
315 | $this_row_id = "id=\"FILRR-$filter_id\""; | |
316 | } | |
a82dc5e4 AD |
317 | |
318 | $line["filter_type_descr"] = __($line["filter_type_descr"]); | |
319 | $line["action_description"] = __($line["action_description"]); | |
320 | ||
321 | if ($line["action_description"] != $cur_action_description) { | |
322 | $cur_action_description = $line["action_description"]; | |
323 | ||
324 | print "<tr><td class='filterEditCat' colspan='6'>$cur_action_description</td></tr>"; | |
325 | ||
326 | print "<tr class=\"title\"> | |
327 | <td align='center' width=\"5%\"> </td> | |
328 | <td width=\"20%\"><a href=\"javascript:updateFilterList('reg_exp')\">".__('Filter expression')."</a></td> | |
329 | <td width=\"\"><a href=\"javascript:updateFilterList('feed_title')\">".__('Feed')."</a></td> | |
330 | <td width=\"20%\"><a href=\"javascript:updateFilterList('filter_type')\">".__('Match')."</a></td> | |
331 | <!-- <td width=\"15%\"><a href=\"javascript:updateFilterList('action_description')\">".__('Action')."</a></td> --> | |
332 | <td width=\"20%\"><a href=\"javascript:updateFilterList('action_param')\">".__('Params')."</a></td>"; | |
333 | ||
334 | } | |
335 | ||
ef8be8ea AD |
336 | print "<tr class=\"$class\" $this_row_id>"; |
337 | ||
47439031 | 338 | $line["reg_exp"] = htmlspecialchars($line["reg_exp"]); |
ef8be8ea | 339 | |
a3c159c4 | 340 | if (!$line["feed_title"]) $line["feed_title"] = __("All feeds"); |
0966ea37 AD |
341 | |
342 | if (!$line["action_param"]) { | |
343 | $line["action_param"] = "—"; | |
344 | } else if ($line["action_name"] == "score") { | |
345 | ||
e7002fc3 | 346 | $score_pic = get_score_pic($line["action_param"]); |
0966ea37 AD |
347 | |
348 | $score_pic = "<img class='hlScorePic' src=\"images/$score_pic\">"; | |
349 | ||
350 | $line["action_param"] = "$score_pic " . $line["action_param"]; | |
351 | ||
352 | } | |
ef8be8ea | 353 | |
47439031 | 354 | $line["feed_title"] = htmlspecialchars($line["feed_title"]); |
ef8be8ea AD |
355 | |
356 | print "<td align='center'><input onclick='toggleSelectPrefRow(this, \"filter\");' | |
357 | type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>"; | |
358 | ||
359 | if (!$enabled) { | |
360 | $line["reg_exp"] = "<span class=\"insensitive\">" . | |
a3c159c4 | 361 | $line["reg_exp"] . " " . __("(Disabled)")."</span>"; |
ef8be8ea AD |
362 | $line["feed_title"] = "<span class=\"insensitive\">" . |
363 | $line["feed_title"] . "</span>"; | |
364 | $line["filter_type_descr"] = "<span class=\"insensitive\">" . | |
365 | $line["filter_type_descr"] . "</span>"; | |
366 | $line["action_description"] = "<span class=\"insensitive\">" . | |
367 | $line["action_description"] . "</span>"; | |
a82dc5e4 AD |
368 | $line["action_param"] = "<span class=\"insensitive\">" . |
369 | $line["action_param"] . "</span>"; | |
ef8be8ea | 370 | } |
a95da136 AD |
371 | |
372 | $onclick = "onclick='editFilter($filter_id)' title='".__('Click to edit')."'"; | |
373 | ||
374 | print "<td $onclick>" . $line["reg_exp"] . "</td>"; | |
a95da136 | 375 | print "<td $onclick>" . $line["feed_title"] . "</td>"; |
3f2ff803 AD |
376 | |
377 | $inverse_label = ""; | |
378 | ||
379 | if ($inverse) { | |
a3c159c4 | 380 | $inverse_label = " <span class='insensitive'>".__('(Inverse)')."</span>"; |
3f2ff803 | 381 | } |
ef8be8ea | 382 | |
c771953d | 383 | print "<td $onclick>" . $line["filter_type_descr"] . "$inverse_label</td>"; |
a95da136 | 384 | print "<td $onclick>" . $line["action_param"] . "</td>"; |
ff6e357a | 385 | |
ef8be8ea AD |
386 | print "</tr>"; |
387 | ||
388 | ++$lnum; | |
389 | } | |
a5bd7bf0 | 390 | |
ef8be8ea AD |
391 | print "</table>"; |
392 | ||
ef8be8ea | 393 | print "<p id=\"filterOpToolbar\">"; |
2d1a44af | 394 | |
a3c159c4 AD |
395 | print "<input type=\"submit\" class=\"button\" disabled=\"true\" |
396 | onclick=\"return editSelectedFilter()\" value=\"".__('Edit')."\"> | |
ef8be8ea | 397 | <input type=\"submit\" class=\"button\" disabled=\"true\" |
a3c159c4 | 398 | onclick=\"return removeSelectedFilters()\" value=\"".__('Remove')."\">"; |
ef8be8ea AD |
399 | |
400 | print "</p>"; | |
401 | ||
402 | } else { | |
403 | ||
9c87d75c | 404 | print "<p>"; |
9c87d75c AD |
405 | if (!$filter_search) { |
406 | print __('No filters defined.'); | |
407 | } else { | |
408 | print __('No matching filters found.'); | |
409 | } | |
9c87d75c | 410 | print "</p>"; |
ef8be8ea AD |
411 | |
412 | } | |
413 | } | |
414 | ?> |