2006-10-01 10:05:20 +00:00
|
|
|
<?php
|
|
|
|
function module_pref_filters($link) {
|
|
|
|
$subop = $_GET["subop"];
|
|
|
|
$quiet = $_GET["quiet"];
|
|
|
|
|
|
|
|
if ($subop == "edit") {
|
|
|
|
|
|
|
|
$filter_id = db_escape_string($_GET["id"]);
|
|
|
|
|
|
|
|
$result = db_query($link,
|
|
|
|
"SELECT * FROM ttrss_filters WHERE id = '$filter_id' AND owner_uid = " . $_SESSION["uid"]);
|
|
|
|
|
|
|
|
$reg_exp = htmlspecialchars(db_unescape_string(db_fetch_result($result, 0, "reg_exp")));
|
|
|
|
$filter_type = db_fetch_result($result, 0, "filter_type");
|
|
|
|
$feed_id = db_fetch_result($result, 0, "feed_id");
|
|
|
|
$action_id = db_fetch_result($result, 0, "action_id");
|
2006-12-08 07:21:44 +00:00
|
|
|
$action_param = db_fetch_result($result, 0, "action_param");
|
2006-10-01 10:05:20 +00:00
|
|
|
|
|
|
|
$enabled = sql_bool_to_bool(db_fetch_result($result, 0, "enabled"));
|
2007-01-30 16:23:35 +00:00
|
|
|
$inverse = sql_bool_to_bool(db_fetch_result($result, 0, "inverse"));
|
2006-10-01 10:05:20 +00:00
|
|
|
|
2007-03-05 11:02:18 +00:00
|
|
|
print "<div id=\"infoBoxTitle\">".__('Filter editor')."</div>";
|
2006-10-01 10:05:20 +00:00
|
|
|
print "<div class=\"infoBoxContents\">";
|
|
|
|
|
2007-03-02 20:58:29 +00:00
|
|
|
print "<form id=\"filter_edit_form\" onsubmit='return false'>";
|
2006-10-01 10:05:20 +00:00
|
|
|
|
|
|
|
print "<input type=\"hidden\" name=\"op\" value=\"pref-filters\">";
|
|
|
|
print "<input type=\"hidden\" name=\"id\" value=\"$filter_id\">";
|
|
|
|
print "<input type=\"hidden\" name=\"subop\" value=\"editSave\">";
|
|
|
|
|
|
|
|
// print "<div class=\"notice\"><b>Note:</b> filter will only apply to new articles.</div>";
|
|
|
|
|
|
|
|
$result = db_query($link, "SELECT id,description
|
|
|
|
FROM ttrss_filter_types ORDER BY description");
|
|
|
|
|
|
|
|
$filter_types = array();
|
|
|
|
|
|
|
|
while ($line = db_fetch_assoc($result)) {
|
|
|
|
//array_push($filter_types, $line["description"]);
|
|
|
|
$filter_types[$line["id"]] = $line["description"];
|
|
|
|
}
|
|
|
|
|
|
|
|
print "<table width='100%'>";
|
|
|
|
|
|
|
|
print "<tr><td>Match:</td>
|
|
|
|
<td><input onkeypress=\"return filterCR(event, filterEditSave)\"
|
|
|
|
onkeyup=\"toggleSubmitNotEmpty(this, 'infobox_submit')\"
|
2007-02-14 13:52:18 +00:00
|
|
|
onchange=\"toggleSubmitNotEmpty(this, 'infobox_submit')\"
|
|
|
|
name=\"reg_exp\" class=\"iedit\" value=\"$reg_exp\">";
|
2006-10-01 10:05:20 +00:00
|
|
|
|
2007-03-05 11:02:18 +00:00
|
|
|
print "</td></tr><tr><td>".__('On field:')."</td><td>";
|
2006-10-01 10:05:20 +00:00
|
|
|
|
2007-01-30 16:03:44 +00:00
|
|
|
print_select_hash("filter_type", $filter_type, $filter_types, "class=\"_iedit\"");
|
2006-10-01 10:05:20 +00:00
|
|
|
|
|
|
|
print "</td></tr>";
|
2007-03-05 11:02:18 +00:00
|
|
|
print "<tr><td>".__('Feed:')."</td><td colspan='2'>";
|
2006-10-01 10:05:20 +00:00
|
|
|
|
|
|
|
print_feed_select($link, "feed_id", $feed_id);
|
|
|
|
|
|
|
|
print "</td></tr>";
|
|
|
|
|
2007-03-05 11:02:18 +00:00
|
|
|
print "<tr><td>".__('Action:')."</td>";
|
2006-10-01 10:05:20 +00:00
|
|
|
|
2006-12-08 07:21:44 +00:00
|
|
|
print "<td colspan='2'><select name=\"action_id\"
|
|
|
|
onchange=\"filterDlgCheckAction(this)\">";
|
2006-10-01 10:05:20 +00:00
|
|
|
|
|
|
|
$result = db_query($link, "SELECT id,description FROM ttrss_filter_actions
|
|
|
|
ORDER BY name");
|
|
|
|
|
|
|
|
while ($line = db_fetch_assoc($result)) {
|
|
|
|
$is_sel = ($line["id"] == $action_id) ? "selected" : "";
|
|
|
|
printf("<option value='%d' $is_sel>%s</option>", $line["id"], $line["description"]);
|
|
|
|
}
|
|
|
|
|
|
|
|
print "</select>";
|
|
|
|
|
|
|
|
print "</td></tr>";
|
|
|
|
|
2007-03-05 11:02:18 +00:00
|
|
|
print "<tr><td>".__('Params:')."</td>";
|
2006-12-08 07:21:44 +00:00
|
|
|
|
|
|
|
$param_disabled = ($action_id == 4) ? "" : "disabled";
|
|
|
|
|
|
|
|
print "<td><input $param_disabled class='iedit'
|
|
|
|
name=\"action_param\" value=\"$action_param\"></td></tr>";
|
|
|
|
|
2006-10-01 10:05:20 +00:00
|
|
|
if ($enabled) {
|
|
|
|
$checked = "checked";
|
|
|
|
} else {
|
|
|
|
$checked = "";
|
|
|
|
}
|
|
|
|
|
2007-01-30 16:23:35 +00:00
|
|
|
print "<tr><td valign='top'>Options:</td><td>
|
2006-10-01 10:05:20 +00:00
|
|
|
<input type=\"checkbox\" name=\"enabled\" id=\"enabled\" $checked>
|
2007-03-05 11:02:18 +00:00
|
|
|
<label for=\"enabled\">".__('Enabled')."</label><br/>";
|
2007-01-30 16:23:35 +00:00
|
|
|
|
|
|
|
if ($inverse) {
|
|
|
|
$checked = "checked";
|
|
|
|
} else {
|
|
|
|
$checked = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
print "<input type=\"checkbox\" name=\"inverse\" id=\"inverse\" $checked>
|
2007-03-05 11:02:18 +00:00
|
|
|
<label for=\"inverse\">".__('Inverse match')."</label>";
|
2006-10-01 10:05:20 +00:00
|
|
|
|
|
|
|
print "</td></tr></table>";
|
|
|
|
|
|
|
|
print "</form>";
|
|
|
|
|
|
|
|
print "<div align='right'>";
|
|
|
|
|
|
|
|
print "<input type=\"submit\"
|
|
|
|
id=\"infobox_submit\"
|
|
|
|
class=\"button\" onclick=\"return filterEditSave()\"
|
2007-03-05 11:02:18 +00:00
|
|
|
value=\"".__('Save')."\"> ";
|
2006-10-01 10:05:20 +00:00
|
|
|
|
|
|
|
print "<input class=\"button\"
|
|
|
|
type=\"submit\" onclick=\"return filterEditCancel()\"
|
2007-03-05 11:02:18 +00:00
|
|
|
value=\"".__('Cancel')."\">";
|
2006-10-01 10:05:20 +00:00
|
|
|
|
|
|
|
print "</div>";
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ($subop == "editSave") {
|
|
|
|
|
|
|
|
$reg_exp = db_escape_string(trim($_GET["reg_exp"]));
|
|
|
|
$filter_type = db_escape_string(trim($_GET["filter_type"]));
|
|
|
|
$filter_id = db_escape_string($_GET["id"]);
|
|
|
|
$feed_id = db_escape_string($_GET["feed_id"]);
|
|
|
|
$action_id = db_escape_string($_GET["action_id"]);
|
2006-12-08 07:21:44 +00:00
|
|
|
$action_param = db_escape_string($_GET["action_param"]);
|
2006-10-01 10:05:20 +00:00
|
|
|
$enabled = checkbox_to_sql_bool(db_escape_string($_GET["enabled"]));
|
2007-01-30 16:23:35 +00:00
|
|
|
$inverse = checkbox_to_sql_bool(db_escape_string($_GET["inverse"]));
|
2006-10-01 10:05:20 +00:00
|
|
|
|
|
|
|
if (!$feed_id) {
|
|
|
|
$feed_id = 'NULL';
|
|
|
|
} else {
|
|
|
|
$feed_id = sprintf("'%s'", db_escape_string($feed_id));
|
|
|
|
}
|
|
|
|
|
|
|
|
$result = db_query($link, "UPDATE ttrss_filters SET
|
|
|
|
reg_exp = '$reg_exp',
|
|
|
|
feed_id = $feed_id,
|
|
|
|
action_id = '$action_id',
|
|
|
|
filter_type = '$filter_type',
|
2006-12-08 07:21:44 +00:00
|
|
|
enabled = $enabled,
|
2007-01-30 16:23:35 +00:00
|
|
|
inverse = $inverse,
|
2006-12-08 07:21:44 +00:00
|
|
|
action_param = '$action_param'
|
2007-03-05 12:50:46 +00:00
|
|
|
WHERE id = '$filter_id' AND owner_uid = " . $_SESSION["uid"]);
|
|
|
|
|
2006-10-01 10:05:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($subop == "remove") {
|
|
|
|
|
2007-03-05 12:50:46 +00:00
|
|
|
$ids = split(",", db_escape_string($_GET["ids"]));
|
2006-10-01 10:05:20 +00:00
|
|
|
|
2007-03-05 12:50:46 +00:00
|
|
|
foreach ($ids as $id) {
|
|
|
|
db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id' AND owner_uid = ". $_SESSION["uid"]);
|
2006-10-01 10:05:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($subop == "add") {
|
|
|
|
|
2007-03-05 12:50:46 +00:00
|
|
|
$regexp = db_escape_string(trim($_GET["reg_exp"]));
|
|
|
|
$filter_type = db_escape_string(trim($_GET["filter_type"]));
|
|
|
|
$feed_id = db_escape_string($_GET["feed_id"]);
|
|
|
|
$action_id = db_escape_string($_GET["action_id"]);
|
|
|
|
$action_param = db_escape_string($_GET["action_param"]);
|
|
|
|
|
|
|
|
$inverse = checkbox_to_sql_bool(db_escape_string($_GET["inverse"]));
|
|
|
|
|
|
|
|
if (!$regexp) return;
|
|
|
|
|
|
|
|
if (!$feed_id) {
|
|
|
|
$feed_id = 'NULL';
|
|
|
|
} else {
|
|
|
|
$feed_id = sprintf("'%s'", db_escape_string($feed_id));
|
|
|
|
}
|
|
|
|
|
|
|
|
$result = db_query($link,
|
|
|
|
"INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id,
|
|
|
|
action_id, action_param, inverse)
|
|
|
|
VALUES
|
|
|
|
('$regexp', '$filter_type','".$_SESSION["uid"]."',
|
|
|
|
$feed_id, '$action_id', '$action_param', $inverse)");
|
|
|
|
|
|
|
|
print_notice(T_sprintf("Created filter <b>%s</b>", htmlspecialchars($regexp)));
|
2006-10-01 10:05:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($quiet) return;
|
|
|
|
|
|
|
|
$sort = db_escape_string($_GET["sort"]);
|
|
|
|
|
|
|
|
if (!$sort || $sort == "undefined") {
|
|
|
|
$sort = "reg_exp";
|
|
|
|
}
|
|
|
|
|
|
|
|
// print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
|
|
|
|
|
|
|
|
$result = db_query($link, "SELECT id,description
|
|
|
|
FROM ttrss_filter_types ORDER BY description");
|
|
|
|
|
|
|
|
$filter_types = array();
|
|
|
|
|
|
|
|
while ($line = db_fetch_assoc($result)) {
|
|
|
|
//array_push($filter_types, $line["description"]);
|
|
|
|
$filter_types[$line["id"]] = $line["description"];
|
|
|
|
}
|
|
|
|
|
2007-03-02 19:16:45 +00:00
|
|
|
print "<a class='helpLinkPic' href=\"javascript:displayHelpInfobox(2)\">
|
|
|
|
<img src='images/sign_quest.png'></a>";
|
|
|
|
|
2006-10-01 10:05:20 +00:00
|
|
|
print "<input type=\"submit\"
|
|
|
|
class=\"button\"
|
|
|
|
onclick=\"return displayDlg('quickAddFilter', false)\"
|
|
|
|
id=\"create_filter_btn\"
|
2007-03-05 11:02:18 +00:00
|
|
|
value=\"".__('Create filter')."\">";
|
2006-10-01 10:05:20 +00:00
|
|
|
|
|
|
|
$result = db_query($link, "SELECT
|
|
|
|
ttrss_filters.id AS id,reg_exp,
|
|
|
|
ttrss_filter_types.name AS filter_type_name,
|
|
|
|
ttrss_filter_types.description AS filter_type_descr,
|
|
|
|
enabled,
|
2007-01-30 16:23:35 +00:00
|
|
|
inverse,
|
2006-10-01 10:05:20 +00:00
|
|
|
feed_id,
|
|
|
|
ttrss_filter_actions.description AS action_description,
|
|
|
|
ttrss_feeds.title AS feed_title
|
|
|
|
FROM
|
|
|
|
ttrss_filter_types,ttrss_filter_actions,ttrss_filters LEFT JOIN
|
|
|
|
ttrss_feeds ON (ttrss_filters.feed_id = ttrss_feeds.id)
|
|
|
|
WHERE
|
|
|
|
filter_type = ttrss_filter_types.id AND
|
|
|
|
ttrss_filter_actions.id = action_id AND
|
|
|
|
ttrss_filters.owner_uid = ".$_SESSION["uid"]."
|
|
|
|
ORDER by $sort");
|
|
|
|
|
|
|
|
if (db_num_rows($result) != 0) {
|
|
|
|
|
|
|
|
print "<p><table width=\"100%\" cellspacing=\"0\" class=\"prefFilterList\"
|
|
|
|
id=\"prefFilterList\">";
|
|
|
|
|
|
|
|
print "<tr><td class=\"selectPrompt\" colspan=\"8\">
|
|
|
|
Select:
|
|
|
|
<a href=\"javascript:selectPrefRows('filter', true)\">All</a>,
|
|
|
|
<a href=\"javascript:selectPrefRows('filter', false)\">None</a>
|
|
|
|
</td</tr>";
|
|
|
|
|
|
|
|
print "<tr class=\"title\">
|
|
|
|
<td align='center' width=\"5%\"> </td>
|
2007-03-05 11:02:18 +00:00
|
|
|
<td width=\"20%\"><a href=\"javascript:updateFilterList('reg_exp')\">".__('Filter expression')."</a></td>
|
|
|
|
<td width=\"20%\"><a href=\"javascript:updateFilterList('feed_title')\">".__('Feed')."</a></td>
|
|
|
|
<td width=\"15%\"><a href=\"javascript:updateFilterList('filter_type')\">".__('Match')."</a></td>
|
|
|
|
<td width=\"15%\"><a href=\"javascript:updateFilterList('action_description')\">".__('Action')."</a></td>";
|
2006-10-01 10:05:20 +00:00
|
|
|
|
|
|
|
$lnum = 0;
|
|
|
|
|
|
|
|
while ($line = db_fetch_assoc($result)) {
|
|
|
|
|
|
|
|
$class = ($lnum % 2) ? "even" : "odd";
|
|
|
|
|
|
|
|
$filter_id = $line["id"];
|
|
|
|
$edit_filter_id = $_GET["id"];
|
|
|
|
|
|
|
|
$enabled = sql_bool_to_bool($line["enabled"]);
|
2007-01-30 16:23:35 +00:00
|
|
|
$inverse = sql_bool_to_bool($line["inverse"]);
|
|
|
|
|
2006-10-01 10:05:20 +00:00
|
|
|
if ($subop == "edit" && $filter_id != $edit_filter_id) {
|
|
|
|
$class .= "Grayed";
|
|
|
|
$this_row_id = "";
|
|
|
|
} else {
|
|
|
|
$this_row_id = "id=\"FILRR-$filter_id\"";
|
|
|
|
}
|
|
|
|
|
|
|
|
print "<tr class=\"$class\" $this_row_id>";
|
|
|
|
|
|
|
|
$line["reg_exp"] = htmlspecialchars(db_unescape_string($line["reg_exp"]));
|
|
|
|
|
2007-03-05 11:02:18 +00:00
|
|
|
if (!$line["feed_title"]) $line["feed_title"] = __("All feeds");
|
2006-10-01 10:05:20 +00:00
|
|
|
|
|
|
|
$line["feed_title"] = htmlspecialchars(db_unescape_string($line["feed_title"]));
|
|
|
|
|
|
|
|
print "<td align='center'><input onclick='toggleSelectPrefRow(this, \"filter\");'
|
|
|
|
type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>";
|
|
|
|
|
|
|
|
if (!$enabled) {
|
|
|
|
$line["reg_exp"] = "<span class=\"insensitive\">" .
|
2007-03-05 11:02:18 +00:00
|
|
|
$line["reg_exp"] . " " . __("(Disabled)")."</span>";
|
2006-10-01 10:05:20 +00:00
|
|
|
$line["feed_title"] = "<span class=\"insensitive\">" .
|
|
|
|
$line["feed_title"] . "</span>";
|
|
|
|
$line["filter_type_descr"] = "<span class=\"insensitive\">" .
|
|
|
|
$line["filter_type_descr"] . "</span>";
|
|
|
|
$line["action_description"] = "<span class=\"insensitive\">" .
|
|
|
|
$line["action_description"] . "</span>";
|
|
|
|
}
|
|
|
|
|
|
|
|
print "<td><a href=\"javascript:editFilter($filter_id);\">" .
|
|
|
|
$line["reg_exp"] . "</td>";
|
|
|
|
|
|
|
|
print "<td><a href=\"javascript:editFilter($filter_id);\">" .
|
|
|
|
$line["feed_title"] . "</td>";
|
2007-01-30 16:23:35 +00:00
|
|
|
|
|
|
|
$inverse_label = "";
|
|
|
|
|
|
|
|
if ($inverse) {
|
2007-03-05 11:02:18 +00:00
|
|
|
$inverse_label = " <span class='insensitive'>".__('(Inverse)')."</span>";
|
2007-01-30 16:23:35 +00:00
|
|
|
}
|
2006-10-01 10:05:20 +00:00
|
|
|
|
|
|
|
print "<td><a href=\"javascript:editFilter($filter_id);\">" .
|
2007-01-30 16:23:35 +00:00
|
|
|
$line["filter_type_descr"] . "$inverse_label</td>";
|
2006-10-01 10:05:20 +00:00
|
|
|
|
|
|
|
print "<td><a href=\"javascript:editFilter($filter_id);\">" .
|
|
|
|
$line["action_description"] . "</td>";
|
|
|
|
|
|
|
|
print "</tr>";
|
|
|
|
|
|
|
|
++$lnum;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($lnum == 0) {
|
2007-03-05 11:02:18 +00:00
|
|
|
print "<tr><td colspan=\"4\" align=\"center\">".__('No filters defined.')."</td></tr>";
|
2006-10-01 10:05:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
print "</table>";
|
|
|
|
|
|
|
|
print "<p id=\"filterOpToolbar\">";
|
2006-12-08 07:42:18 +00:00
|
|
|
|
2007-03-05 11:02:18 +00:00
|
|
|
print "<input type=\"submit\" class=\"button\" disabled=\"true\"
|
|
|
|
onclick=\"return editSelectedFilter()\" value=\"".__('Edit')."\">
|
2006-10-01 10:05:20 +00:00
|
|
|
<input type=\"submit\" class=\"button\" disabled=\"true\"
|
2007-03-05 11:02:18 +00:00
|
|
|
onclick=\"return removeSelectedFilters()\" value=\"".__('Remove')."\">";
|
2006-10-01 10:05:20 +00:00
|
|
|
|
|
|
|
print "</p>";
|
|
|
|
|
2007-01-30 17:17:34 +00:00
|
|
|
|
2007-01-30 16:00:42 +00:00
|
|
|
/* print "<div class=\"insensitive\" style=\"float : right\">
|
2007-01-30 15:16:57 +00:00
|
|
|
First matching filter is used, filtering is performed
|
2007-01-30 16:00:42 +00:00
|
|
|
when importing articles from the feed.</div>"; */
|
2007-01-30 15:16:57 +00:00
|
|
|
|
2006-10-01 10:05:20 +00:00
|
|
|
} else {
|
|
|
|
|
2007-03-05 11:02:18 +00:00
|
|
|
print "<p>".__('No filters defined.')."</p>";
|
2006-10-01 10:05:20 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|