]>
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 | ||
13 | $reg_exp = htmlspecialchars(db_unescape_string(db_fetch_result($result, 0, "reg_exp"))); | |
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 AD |
21 | |
22 | print "<div id=\"infoBoxTitle\">Filter editor</div>"; | |
23 | print "<div class=\"infoBoxContents\">"; | |
24 | ||
25 | print "<form id=\"filter_edit_form\">"; | |
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\">"; | |
30 | ||
31 | // print "<div class=\"notice\"><b>Note:</b> filter will only apply to new articles.</div>"; | |
32 | ||
33 | $result = db_query($link, "SELECT id,description | |
34 | FROM ttrss_filter_types ORDER BY description"); | |
35 | ||
36 | $filter_types = array(); | |
37 | ||
38 | while ($line = db_fetch_assoc($result)) { | |
39 | //array_push($filter_types, $line["description"]); | |
40 | $filter_types[$line["id"]] = $line["description"]; | |
41 | } | |
42 | ||
43 | print "<table width='100%'>"; | |
44 | ||
45 | print "<tr><td>Match:</td> | |
46 | <td><input onkeypress=\"return filterCR(event, filterEditSave)\" | |
47 | onkeyup=\"toggleSubmitNotEmpty(this, 'infobox_submit')\" | |
48 | name=\"reg_exp\" class=\"iedit\" value=\"$reg_exp\">"; | |
49 | ||
8011ac36 | 50 | print "</td></tr><tr><td>On field:</td><td>"; |
ef8be8ea | 51 | |
8011ac36 | 52 | print_select_hash("filter_type", $filter_type, $filter_types, "class=\"_iedit\""); |
ef8be8ea AD |
53 | |
54 | print "</td></tr>"; | |
55 | print "<tr><td>Feed:</td><td colspan='2'>"; | |
56 | ||
57 | print_feed_select($link, "feed_id", $feed_id); | |
58 | ||
59 | print "</td></tr>"; | |
60 | ||
61 | print "<tr><td>Action:</td>"; | |
62 | ||
073ca0e6 AD |
63 | print "<td colspan='2'><select name=\"action_id\" |
64 | onchange=\"filterDlgCheckAction(this)\">"; | |
ef8be8ea AD |
65 | |
66 | $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions | |
67 | ORDER BY name"); | |
68 | ||
69 | while ($line = db_fetch_assoc($result)) { | |
70 | $is_sel = ($line["id"] == $action_id) ? "selected" : ""; | |
71 | printf("<option value='%d' $is_sel>%s</option>", $line["id"], $line["description"]); | |
72 | } | |
73 | ||
74 | print "</select>"; | |
75 | ||
76 | print "</td></tr>"; | |
77 | ||
073ca0e6 AD |
78 | print "<tr><td>Params:</td>"; |
79 | ||
80 | $param_disabled = ($action_id == 4) ? "" : "disabled"; | |
81 | ||
82 | print "<td><input $param_disabled class='iedit' | |
83 | name=\"action_param\" value=\"$action_param\"></td></tr>"; | |
84 | ||
ef8be8ea AD |
85 | if ($enabled) { |
86 | $checked = "checked"; | |
87 | } else { | |
88 | $checked = ""; | |
89 | } | |
90 | ||
3f2ff803 | 91 | print "<tr><td valign='top'>Options:</td><td> |
ef8be8ea | 92 | <input type=\"checkbox\" name=\"enabled\" id=\"enabled\" $checked> |
3f2ff803 AD |
93 | <label for=\"enabled\">Enabled</label><br/>"; |
94 | ||
95 | if ($inverse) { | |
96 | $checked = "checked"; | |
97 | } else { | |
98 | $checked = ""; | |
99 | } | |
100 | ||
101 | print "<input type=\"checkbox\" name=\"inverse\" id=\"inverse\" $checked> | |
102 | <label for=\"inverse\">Inverse match</label>"; | |
ef8be8ea AD |
103 | |
104 | print "</td></tr></table>"; | |
105 | ||
106 | print "</form>"; | |
107 | ||
108 | print "<div align='right'>"; | |
109 | ||
110 | print "<input type=\"submit\" | |
111 | id=\"infobox_submit\" | |
112 | class=\"button\" onclick=\"return filterEditSave()\" | |
113 | value=\"Save\"> "; | |
114 | ||
115 | print "<input class=\"button\" | |
116 | type=\"submit\" onclick=\"return filterEditCancel()\" | |
117 | value=\"Cancel\">"; | |
118 | ||
119 | print "</div>"; | |
120 | ||
121 | return; | |
122 | } | |
123 | ||
124 | ||
125 | if ($subop == "editSave") { | |
126 | ||
127 | $reg_exp = db_escape_string(trim($_GET["reg_exp"])); | |
128 | $filter_type = db_escape_string(trim($_GET["filter_type"])); | |
129 | $filter_id = db_escape_string($_GET["id"]); | |
130 | $feed_id = db_escape_string($_GET["feed_id"]); | |
131 | $action_id = db_escape_string($_GET["action_id"]); | |
073ca0e6 | 132 | $action_param = db_escape_string($_GET["action_param"]); |
ef8be8ea | 133 | $enabled = checkbox_to_sql_bool(db_escape_string($_GET["enabled"])); |
3f2ff803 | 134 | $inverse = checkbox_to_sql_bool(db_escape_string($_GET["inverse"])); |
ef8be8ea AD |
135 | |
136 | if (!$feed_id) { | |
137 | $feed_id = 'NULL'; | |
138 | } else { | |
139 | $feed_id = sprintf("'%s'", db_escape_string($feed_id)); | |
140 | } | |
141 | ||
142 | $result = db_query($link, "UPDATE ttrss_filters SET | |
143 | reg_exp = '$reg_exp', | |
144 | feed_id = $feed_id, | |
145 | action_id = '$action_id', | |
146 | filter_type = '$filter_type', | |
073ca0e6 | 147 | enabled = $enabled, |
3f2ff803 | 148 | inverse = $inverse, |
073ca0e6 | 149 | action_param = '$action_param' |
ef8be8ea AD |
150 | WHERE id = '$filter_id' AND owner_uid = " . $_SESSION["uid"]); |
151 | } | |
152 | ||
153 | if ($subop == "remove") { | |
154 | ||
155 | if (!WEB_DEMO_MODE) { | |
156 | ||
157 | $ids = split(",", db_escape_string($_GET["ids"])); | |
158 | ||
159 | foreach ($ids as $id) { | |
160 | db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id' AND owner_uid = ". $_SESSION["uid"]); | |
161 | ||
162 | } | |
163 | } | |
164 | } | |
165 | ||
166 | if ($subop == "add") { | |
167 | ||
168 | if (!WEB_DEMO_MODE) { | |
169 | ||
170 | $regexp = db_escape_string(trim($_GET["reg_exp"])); | |
171 | $filter_type = db_escape_string(trim($_GET["filter_type"])); | |
172 | $feed_id = db_escape_string($_GET["feed_id"]); | |
173 | $action_id = db_escape_string($_GET["action_id"]); | |
073ca0e6 | 174 | $action_param = db_escape_string($_GET["action_param"]); |
ef8be8ea | 175 | |
3f2ff803 AD |
176 | $inverse = checkbox_to_sql_bool(db_escape_string($_GET["inverse"])); |
177 | ||
ef8be8ea AD |
178 | if (!$regexp) return; |
179 | ||
180 | if (!$feed_id) { | |
181 | $feed_id = 'NULL'; | |
182 | } else { | |
183 | $feed_id = sprintf("'%s'", db_escape_string($feed_id)); | |
184 | } | |
185 | ||
186 | $result = db_query($link, | |
187 | "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id, | |
3f2ff803 | 188 | action_id, action_param, inverse) |
ef8be8ea AD |
189 | VALUES |
190 | ('$regexp', '$filter_type','".$_SESSION["uid"]."', | |
3f2ff803 | 191 | $feed_id, '$action_id', '$action_param', $inverse)"); |
ef8be8ea AD |
192 | } |
193 | } | |
194 | ||
195 | if ($quiet) return; | |
196 | ||
197 | $sort = db_escape_string($_GET["sort"]); | |
198 | ||
199 | if (!$sort || $sort == "undefined") { | |
200 | $sort = "reg_exp"; | |
201 | } | |
202 | ||
203 | // print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>"; | |
204 | ||
205 | $result = db_query($link, "SELECT id,description | |
206 | FROM ttrss_filter_types ORDER BY description"); | |
207 | ||
208 | $filter_types = array(); | |
209 | ||
210 | while ($line = db_fetch_assoc($result)) { | |
211 | //array_push($filter_types, $line["description"]); | |
212 | $filter_types[$line["id"]] = $line["description"]; | |
213 | } | |
214 | ||
215 | print "<input type=\"submit\" | |
216 | class=\"button\" | |
217 | onclick=\"return displayDlg('quickAddFilter', false)\" | |
218 | id=\"create_filter_btn\" | |
219 | value=\"Create filter\">"; | |
220 | ||
221 | $result = db_query($link, "SELECT | |
222 | ttrss_filters.id AS id,reg_exp, | |
223 | ttrss_filter_types.name AS filter_type_name, | |
224 | ttrss_filter_types.description AS filter_type_descr, | |
225 | enabled, | |
3f2ff803 | 226 | inverse, |
ef8be8ea AD |
227 | feed_id, |
228 | ttrss_filter_actions.description AS action_description, | |
229 | ttrss_feeds.title AS feed_title | |
230 | FROM | |
231 | ttrss_filter_types,ttrss_filter_actions,ttrss_filters LEFT JOIN | |
232 | ttrss_feeds ON (ttrss_filters.feed_id = ttrss_feeds.id) | |
233 | WHERE | |
234 | filter_type = ttrss_filter_types.id AND | |
235 | ttrss_filter_actions.id = action_id AND | |
236 | ttrss_filters.owner_uid = ".$_SESSION["uid"]." | |
237 | ORDER by $sort"); | |
238 | ||
239 | if (db_num_rows($result) != 0) { | |
240 | ||
241 | print "<form id=\"filter_edit_form\">"; | |
242 | ||
243 | print "<p><table width=\"100%\" cellspacing=\"0\" class=\"prefFilterList\" | |
244 | id=\"prefFilterList\">"; | |
245 | ||
246 | print "<tr><td class=\"selectPrompt\" colspan=\"8\"> | |
247 | Select: | |
248 | <a href=\"javascript:selectPrefRows('filter', true)\">All</a>, | |
249 | <a href=\"javascript:selectPrefRows('filter', false)\">None</a> | |
250 | </td</tr>"; | |
251 | ||
252 | print "<tr class=\"title\"> | |
253 | <td align='center' width=\"5%\"> </td> | |
254 | <td width=\"20%\"><a href=\"javascript:updateFilterList('reg_exp')\">Filter expression</a></td> | |
255 | <td width=\"20%\"><a href=\"javascript:updateFilterList('feed_title')\">Feed</a></td> | |
256 | <td width=\"15%\"><a href=\"javascript:updateFilterList('filter_type')\">Match</a></td> | |
257 | <td width=\"15%\"><a href=\"javascript:updateFilterList('action_description')\">Action</a></td>"; | |
258 | ||
259 | $lnum = 0; | |
260 | ||
261 | while ($line = db_fetch_assoc($result)) { | |
262 | ||
263 | $class = ($lnum % 2) ? "even" : "odd"; | |
264 | ||
265 | $filter_id = $line["id"]; | |
266 | $edit_filter_id = $_GET["id"]; | |
267 | ||
268 | $enabled = sql_bool_to_bool($line["enabled"]); | |
3f2ff803 AD |
269 | $inverse = sql_bool_to_bool($line["inverse"]); |
270 | ||
ef8be8ea AD |
271 | if ($subop == "edit" && $filter_id != $edit_filter_id) { |
272 | $class .= "Grayed"; | |
273 | $this_row_id = ""; | |
274 | } else { | |
275 | $this_row_id = "id=\"FILRR-$filter_id\""; | |
276 | } | |
277 | ||
278 | print "<tr class=\"$class\" $this_row_id>"; | |
279 | ||
280 | $line["reg_exp"] = htmlspecialchars(db_unescape_string($line["reg_exp"])); | |
281 | ||
282 | if (!$line["feed_title"]) $line["feed_title"] = "All feeds"; | |
283 | ||
284 | $line["feed_title"] = htmlspecialchars(db_unescape_string($line["feed_title"])); | |
285 | ||
286 | print "<td align='center'><input onclick='toggleSelectPrefRow(this, \"filter\");' | |
287 | type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>"; | |
288 | ||
289 | if (!$enabled) { | |
290 | $line["reg_exp"] = "<span class=\"insensitive\">" . | |
291 | $line["reg_exp"] . " (Disabled)</span>"; | |
292 | $line["feed_title"] = "<span class=\"insensitive\">" . | |
293 | $line["feed_title"] . "</span>"; | |
294 | $line["filter_type_descr"] = "<span class=\"insensitive\">" . | |
295 | $line["filter_type_descr"] . "</span>"; | |
296 | $line["action_description"] = "<span class=\"insensitive\">" . | |
297 | $line["action_description"] . "</span>"; | |
298 | } | |
299 | ||
300 | print "<td><a href=\"javascript:editFilter($filter_id);\">" . | |
301 | $line["reg_exp"] . "</td>"; | |
302 | ||
303 | print "<td><a href=\"javascript:editFilter($filter_id);\">" . | |
304 | $line["feed_title"] . "</td>"; | |
3f2ff803 AD |
305 | |
306 | $inverse_label = ""; | |
307 | ||
308 | if ($inverse) { | |
309 | $inverse_label = " <span class='insensitive'>(Inverse)</span>"; | |
310 | } | |
ef8be8ea AD |
311 | |
312 | print "<td><a href=\"javascript:editFilter($filter_id);\">" . | |
3f2ff803 | 313 | $line["filter_type_descr"] . "$inverse_label</td>"; |
ef8be8ea AD |
314 | |
315 | print "<td><a href=\"javascript:editFilter($filter_id);\">" . | |
316 | $line["action_description"] . "</td>"; | |
317 | ||
318 | print "</tr>"; | |
319 | ||
320 | ++$lnum; | |
321 | } | |
322 | ||
323 | if ($lnum == 0) { | |
324 | print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>"; | |
325 | } | |
326 | ||
327 | print "</table>"; | |
328 | ||
329 | print "</form>"; | |
2d1a44af | 330 | |
ef8be8ea | 331 | print "<p id=\"filterOpToolbar\">"; |
2d1a44af | 332 | |
ef8be8ea AD |
333 | print " |
334 | Selection: | |
335 | <input type=\"submit\" class=\"button\" disabled=\"true\" | |
336 | onclick=\"return editSelectedFilter()\" value=\"Edit\"> | |
337 | <input type=\"submit\" class=\"button\" disabled=\"true\" | |
338 | onclick=\"return removeSelectedFilters()\" value=\"Remove\">"; | |
339 | ||
340 | print "</p>"; | |
341 | ||
d4d6d528 AD |
342 | print "<div class=\"insensitive\" style=\"float : right\">See |
343 | <a target=\"_new\" href=\"http://tt-rss.spb.ru/trac/wiki/ContentFilters\">this page</a> | |
344 | for additional information on filtering</div>"; | |
345 | ||
f8382011 | 346 | /* print "<div class=\"insensitive\" style=\"float : right\"> |
d0d0dd47 | 347 | First matching filter is used, filtering is performed |
f8382011 | 348 | when importing articles from the feed.</div>"; */ |
d0d0dd47 | 349 | |
ef8be8ea AD |
350 | } else { |
351 | ||
352 | print "<p>No filters defined.</p>"; | |
353 | ||
354 | } | |
355 | } | |
356 | ?> |