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