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