]>
git.wh0rd.org - tt-rss.git/blob - modules/pref-filters.php
2 function module_pref_filters($link) {
3 $subop = $_GET["subop"];
4 $quiet = $_GET["quiet"];
6 if ($subop == "edit") {
8 $filter_id = db_escape_string($_GET["id"]);
10 $result = db_query($link,
11 "SELECT * FROM ttrss_filters WHERE id = '$filter_id' AND owner_uid = " . $_SESSION["uid"]);
13 $reg_exp = htmlspecialchars(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");
17 $action_param = db_fetch_result($result, 0, "action_param");
18 $filter_param = db_fetch_result($result, 0, "filter_param");
20 $enabled = sql_bool_to_bool(db_fetch_result($result, 0, "enabled"));
21 $inverse = sql_bool_to_bool(db_fetch_result($result, 0, "inverse"));
23 print "<div id=\"infoBoxTitle\">".__('Filter Editor')."</div>";
24 print "<div class=\"infoBoxContents\">";
26 print "<form id=\"filter_edit_form\" onsubmit='return false'>";
28 print "<input type=\"hidden\" name=\"op\" value=\"pref-filters\">";
29 print "<input type=\"hidden\" name=\"id\" value=\"$filter_id\">";
30 print "<input type=\"hidden\" name=\"subop\" value=\"editSave\">";
32 $result = db_query($link, "SELECT id,description
33 FROM ttrss_filter_types ORDER BY description");
35 $filter_types = array();
37 while ($line = db_fetch_assoc($result)) {
38 //array_push($filter_types, $line["description"]);
39 $filter_types[$line["id"]] = __($line["description"]);
42 print "<div class=\"dlgSec\">".__("Match")."</div>";
44 print "<div class=\"dlgSecCont\">";
46 if ($filter_type != 5) {
47 $date_ops_invisible = 'style="display : none"';
50 print "<span id=\"filter_dlg_date_mod_box\" $date_ops_invisible>";
51 print __("Date") . " ";
53 $filter_params = array(
54 "before" => __("before"),
55 "after" => __("after"));
57 print_select_hash("filter_date_modifier", $filter_param,
60 print " </span>";
62 print "<input onkeypress=\"return filterCR(event, filterEditSave)\"
63 onkeyup=\"toggleSubmitNotEmpty(this, 'infobox_submit')\"
64 onchange=\"toggleSubmitNotEmpty(this, 'infobox_submit')\"
65 name=\"reg_exp\" size=\"30\" value=\"$reg_exp\">";
67 print "<span id=\"filter_dlg_date_chk_box\" $date_ops_invisible>";
68 print " <input class=\"button\"
69 type=\"submit\" onclick=\"return filterDlgCheckDate()\"
70 value=\"".__('Check it')."\">";
73 print "<br/> " . __("on field") . " ";
74 print_select_hash("filter_type", $filter_type, $filter_types,
75 'onchange="filterDlgCheckType(this)"');
80 print_feed_select($link, "feed_id", $feed_id);
84 print "<div class=\"dlgSec\">".__("Perform Action")."</div>";
86 print "<div class=\"dlgSecCont\">";
88 print "<select name=\"action_id\"
89 onchange=\"filterDlgCheckAction(this)\">";
91 $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions
94 while ($line = db_fetch_assoc($result)) {
95 $is_sel = ($line["id"] == $action_id) ?
"selected" : "";
96 printf("<option value='%d' $is_sel>%s</option>", $line["id"], __($line["description"]));
101 $param_hidden = ($action_id == 4 ||
$action_id == 6 ||
$action_id == 7) ?
"" : "display : none";
103 print "<span id=\"filter_dlg_param_box\" style=\"$param_hidden\">";
104 print " " . __("with parameters:") . " ";
106 $param_int_hidden = ($action_id != 7) ?
"" : "display : none";
108 print "<input size=\"20\" style=\"$param_int_hidden\"
109 onkeypress=\"return filterCR(event, filterEditSave)\"
110 name=\"action_param\" value=\"$action_param\">";
112 $param_int_hidden = ($action_id == 7) ?
"" : "display : none";
114 print_label_select($link, "action_param_label", $action_param,
119 print " "; // tiny layout hack
123 print "<div class=\"dlgSec\">".__("Options")."</div>";
124 print "<div class=\"dlgSecCont\">";
126 print "<div style=\"line-height : 100%\">";
129 $checked = "checked";
134 print "<input type=\"checkbox\" name=\"enabled\" id=\"enabled\" $checked>
135 <label for=\"enabled\">".__('Enabled')."</label><br/>";
138 $checked = "checked";
143 print "<input type=\"checkbox\" name=\"inverse\" id=\"inverse\" $checked>
144 <label for=\"inverse\">".__('Inverse match')."</label>";
149 print "<div class=\"dlgButtons\">";
151 $reg_exp = htmlspecialchars($reg_exp, ENT_QUOTES
); // second escaping seems to be needed for javascript
153 print "<div style=\"float : left\">";
154 print "<input type=\"submit\"
155 class=\"button\" onclick='return removeFilter($filter_id, \"$reg_exp\")'
156 value=\"".__('Remove')."\"> ";
159 print "<input type=\"submit\"
160 id=\"infobox_submit\"
161 class=\"button\" onclick=\"return filterEditSave()\"
162 value=\"".__('Save')."\"> ";
164 print "<input class=\"button\"
165 type=\"submit\" onclick=\"return filterEditCancel()\"
166 value=\"".__('Cancel')."\">";
174 if ($subop == "editSave") {
176 $reg_exp = db_escape_string(trim($_GET["reg_exp"]));
177 $filter_type = db_escape_string(trim($_GET["filter_type"]));
178 $filter_id = db_escape_string($_GET["id"]);
179 $feed_id = db_escape_string($_GET["feed_id"]);
180 $action_id = db_escape_string($_GET["action_id"]);
181 $action_param = db_escape_string($_GET["action_param"]);
182 $action_param_label = db_escape_string($_GET["action_param_label"]);
183 $enabled = checkbox_to_sql_bool(db_escape_string($_GET["enabled"]));
184 $inverse = checkbox_to_sql_bool(db_escape_string($_GET["inverse"]));
186 # for the time being, no other filters use params anyway...
187 $filter_param = db_escape_string($_GET["filter_date_modifier"]);
192 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
195 /* When processing 'assign label' filters, action_param_label dropbox
196 * overrides action_param */
198 if ($action_id == 7) {
199 $action_param = $action_param_label;
202 $result = db_query($link, "UPDATE ttrss_filters SET
203 reg_exp = '$reg_exp',
205 action_id = '$action_id',
206 filter_type = '$filter_type',
209 action_param = '$action_param',
210 filter_param = '$filter_param'
211 WHERE id = '$filter_id' AND owner_uid = " . $_SESSION["uid"]);
213 if (db_affected_rows($link, $result) != 0) {
214 print_notice(T_sprintf("Saved filter <b>%s</b>", htmlspecialchars($reg_exp)));
219 if ($subop == "remove") {
221 $ids = split(",", db_escape_string($_GET["ids"]));
223 foreach ($ids as $id) {
224 db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id' AND owner_uid = ". $_SESSION["uid"]);
228 if ($subop == "add") {
230 $regexp = db_escape_string(trim($_GET["reg_exp"]));
231 $filter_type = db_escape_string(trim($_GET["filter_type"]));
232 $feed_id = db_escape_string($_GET["feed_id"]);
233 $action_id = db_escape_string($_GET["action_id"]);
234 $action_param = db_escape_string($_GET["action_param"]);
235 $action_param_label = db_escape_string($_GET["action_param_label"]);
236 $inverse = checkbox_to_sql_bool(db_escape_string($_GET["inverse"]));
238 # for the time being, no other filters use params anyway...
239 $filter_param = db_escape_string($_GET["filter_date_modifier"]);
241 if (!$regexp) return;
246 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
249 /* When processing 'assign label' filters, action_param_label dropbox
250 * overrides action_param */
252 if ($action_id == 7) {
253 $action_param = $action_param_label;
256 $result = db_query($link,
257 "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id,
258 action_id, action_param, inverse, filter_param)
260 ('$regexp', '$filter_type','".$_SESSION["uid"]."',
261 $feed_id, '$action_id', '$action_param', $inverse, '$filter_param')");
263 if (db_affected_rows($link, $result) != 0) {
264 print T_sprintf("Created filter <b>%s</b>", htmlspecialchars($regexp));
272 set_pref($link, "_PREFS_ACTIVE_TAB", "filterConfig");
274 $sort = db_escape_string($_GET["sort"]);
276 if (!$sort ||
$sort == "undefined") {
280 // print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
282 $result = db_query($link, "SELECT id,description
283 FROM ttrss_filter_types ORDER BY description");
285 $filter_types = array();
287 while ($line = db_fetch_assoc($result)) {
288 //array_push($filter_types, $line["description"]);
289 $filter_types[$line["id"]] = $line["description"];
293 $filter_search = db_escape_string($_GET["search"]);
295 if (array_key_exists("search", $_GET)) {
296 $_SESSION["prefs_filter_search"] = $filter_search;
298 $filter_search = $_SESSION["prefs_filter_search"];
301 print "<div class=\"feedEditSearch\">
302 <input id=\"filter_search\" size=\"20\" type=\"search\"
303 onfocus=\"javascript:disableHotkeys();\"
304 onblur=\"javascript:enableHotkeys();\"
305 onchange=\"javascript:updateFilterList()\" value=\"$filter_search\">
306 <input type=\"submit\" class=\"button\"
307 onclick=\"javascript:updateFilterList()\" value=\"".__('Search')."\">
308 <p<a class='helpLinkPic' href=\"javascript:displayHelpInfobox(2)\">
309 <img src='images/sign_quest.gif'></a></p>
313 print "<input type=\"submit\"
315 onclick=\"return displayDlg('quickAddFilter', false)\"
316 id=\"create_filter_btn\"
317 value=\"".__('Create filter')."\">";
321 print "<input type=\"submit\"
323 onclick=\"rescore_all_feeds()\"
324 value=\"".__('Rescore articles')."\">";
326 if ($filter_search) {
327 $filter_search = db_escape_string($filter_search);
328 $filter_search_query = "(
329 UPPER(ttrss_filter_actions.description) LIKE UPPER('%$filter_search%') OR
330 UPPER(reg_exp) LIKE UPPER('%$filter_search%') OR
331 UPPER(ttrss_feeds.title) LIKE UPPER('%$filter_search%') OR
332 UPPER(ttrss_filter_types.description) LIKE UPPER('%$filter_search%')) AND";
334 $filter_search_query = "";
337 $result = db_query($link, "SELECT
338 ttrss_filters.id AS id,reg_exp,
339 ttrss_filter_types.name AS filter_type_name,
340 ttrss_filter_types.description AS filter_type_descr,
346 ttrss_filter_actions.description AS action_description,
347 ttrss_feeds.title AS feed_title,
348 ttrss_filter_actions.name AS action_name,
349 ttrss_filters.action_param AS action_param
351 ttrss_filter_types,ttrss_filter_actions,ttrss_filters LEFT JOIN
352 ttrss_feeds ON (ttrss_filters.feed_id = ttrss_feeds.id)
354 filter_type = ttrss_filter_types.id AND
356 ttrss_filter_actions.id = action_id AND
357 ttrss_filters.owner_uid = ".$_SESSION["uid"]."
358 ORDER by action_description, $sort");
360 if (db_num_rows($result) != 0) {
362 print "<p><table width=\"100%\" cellspacing=\"0\" class=\"prefFilterList\"
363 id=\"prefFilterList\">";
365 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
367 <a href=\"javascript:selectPrefRows('filter', true)\">".__('All')."</a>,
368 <a href=\"javascript:selectPrefRows('filter', false)\">".__('None')."</a>
373 $cur_action_description = "";
375 while ($line = db_fetch_assoc($result)) {
377 $class = ($lnum %
2) ?
"even" : "odd";
379 $filter_id = $line["id"];
380 $edit_filter_id = $_GET["id"];
382 $enabled = sql_bool_to_bool($line["enabled"]);
383 $inverse = sql_bool_to_bool($line["inverse"]);
385 if ($subop == "edit" && $filter_id != $edit_filter_id) {
389 $this_row_id = "id=\"FILRR-$filter_id\"";
392 $line["filter_type_descr"] = __($line["filter_type_descr"]);
393 $line["action_description"] = __($line["action_description"]);
395 if ($line["action_description"] != $cur_action_description) {
396 $cur_action_description = $line["action_description"];
398 print "<tr><td class='filterEditCat' colspan='6'>$cur_action_description</td></tr>";
400 print "<tr class=\"title\">
401 <td align='center' width=\"5%\"> </td>
402 <td width=\"20%\"><a href=\"javascript:updateFilterList('reg_exp')\">".__('Match')."</a></td>
403 <td width=\"\"><a href=\"javascript:updateFilterList('feed_title')\">".__('Feed')."</a></td>
404 <td width=\"20%\"><a href=\"javascript:updateFilterList('filter_type')\">".__('Field')."</a></td>
405 <td width=\"20%\"><a href=\"javascript:updateFilterList('action_param')\">".__('Params')."</a></td>";
409 print "<tr class=\"$class\" $this_row_id>";
411 $line["reg_exp"] = htmlspecialchars($line["reg_exp"]);
413 if (!$line["feed_title"]) $line["feed_title"] = __("All feeds");
415 if (!$line["action_param"]) {
416 $line["action_param"] = "—";
417 } else if ($line["action_name"] == "score") {
419 $score_pic = get_score_pic($line["action_param"]);
421 $score_pic = "<img class='hlScorePic' src=\"images/$score_pic\">";
423 $line["action_param"] = "$score_pic " . $line["action_param"];
427 $line["feed_title"] = htmlspecialchars($line["feed_title"]);
429 print "<td align='center'><input onclick='toggleSelectPrefRow(this, \"filter\");'
430 type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>";
432 $filter_params = array(
433 "before" => __("before"),
434 "after" => __("after"));
436 if ($line["filter_type"] == 5) {
438 if (!strtotime($line["reg_exp"])) {
439 $line["reg_exp"] = "<span class=\"filterDateError\">" .
440 $line["reg_exp"] . "</span>";
443 $line["reg_exp"] = __("Date") . " " .
444 $filter_params[$line['filter_param']] . " " .
449 $line["reg_exp"] = "<span class=\"insensitive\">" .
450 $line["reg_exp"] . " " . __("(Disabled)")."</span>";
451 $line["feed_title"] = "<span class=\"insensitive\">" .
452 $line["feed_title"] . "</span>";
453 $line["filter_type_descr"] = "<span class=\"insensitive\">" .
454 $line["filter_type_descr"] . "</span>";
455 $line["action_description"] = "<span class=\"insensitive\">" .
456 $line["action_description"] . "</span>";
457 $line["action_param"] = "<span class=\"insensitive\">" .
458 $line["action_param"] . "</span>";
461 $onclick = "onclick='editFilter($filter_id)' title='".__('Click to edit')."'";
466 $inverse_label = " <span class='insensitive'>".__('(Inverse)')."</span>";
469 print "<td $onclick>" . $line["reg_exp"] . "$inverse_label</td>";
470 print "<td $onclick>" . $line["feed_title"] . "</td>";
472 print "<td $onclick>" . $line["filter_type_descr"] . "</td>";
473 print "<td $onclick>" . $line["action_param"] . "</td>";
482 print "<p id=\"filterOpToolbar\">";
484 print "<input type=\"submit\" class=\"button\" disabled=\"true\"
485 onclick=\"return editSelectedFilter()\" value=\"".__('Edit')."\">
486 <input type=\"submit\" class=\"button\" disabled=\"true\"
487 onclick=\"return removeSelectedFilters()\" value=\"".__('Remove')."\">";
494 if (!$filter_search) {
495 print __('No filters defined.');
497 print __('No matching filters found.');
504 function print_label_select($link, $name, $value, $style = "") {
506 $result = db_query($link, "SELECT caption FROM ttrss_labels2
507 WHERE owner_uid = '".$_SESSION["uid"]."' ORDER BY caption");
509 print "<select name=\"$name\" style=\"$style\">";
511 while ($line = db_fetch_assoc($result)) {
513 $issel = ($line["caption"] == $value) ?
"selected" : "";
515 print "<option $issel>" . $line["caption"] . "</option>";