support for filter actions
This commit is contained in:
parent
53d6935b34
commit
19c9cb1143
77
backend.php
77
backend.php
|
@ -1903,6 +1903,7 @@
|
||||||
$match = db_escape_string($_GET["m"]);
|
$match = db_escape_string($_GET["m"]);
|
||||||
$filter_id = db_escape_string($_GET["id"]);
|
$filter_id = db_escape_string($_GET["id"]);
|
||||||
$feed_id = db_escape_string($_GET["fid"]);
|
$feed_id = db_escape_string($_GET["fid"]);
|
||||||
|
$action_id = db_escape_string($_GET["aid"]);
|
||||||
|
|
||||||
if (!$feed_id) {
|
if (!$feed_id) {
|
||||||
$feed_id = 'NULL';
|
$feed_id = 'NULL';
|
||||||
|
@ -1914,6 +1915,7 @@
|
||||||
reg_exp = '$regexp',
|
reg_exp = '$regexp',
|
||||||
description = '$descr',
|
description = '$descr',
|
||||||
feed_id = $feed_id,
|
feed_id = $feed_id,
|
||||||
|
action_id = '$action_id',
|
||||||
filter_type = (SELECT id FROM ttrss_filter_types WHERE
|
filter_type = (SELECT id FROM ttrss_filter_types WHERE
|
||||||
description = '$match')
|
description = '$match')
|
||||||
WHERE id = '$filter_id'");
|
WHERE id = '$filter_id'");
|
||||||
|
@ -1939,6 +1941,7 @@
|
||||||
$regexp = db_escape_string(trim($_GET["regexp"]));
|
$regexp = db_escape_string(trim($_GET["regexp"]));
|
||||||
$match = db_escape_string(trim($_GET["match"]));
|
$match = db_escape_string(trim($_GET["match"]));
|
||||||
$feed_id = db_escape_string($_GET["fid"]);
|
$feed_id = db_escape_string($_GET["fid"]);
|
||||||
|
$action_id = db_escape_string($_GET["aid"]);
|
||||||
|
|
||||||
if (!$feed_id) {
|
if (!$feed_id) {
|
||||||
$feed_id = 'NULL';
|
$feed_id = 'NULL';
|
||||||
|
@ -1947,9 +1950,12 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = db_query($link,
|
$result = db_query($link,
|
||||||
"INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id) VALUES
|
"INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id,
|
||||||
|
action_id)
|
||||||
|
VALUES
|
||||||
('$regexp', (SELECT id FROM ttrss_filter_types WHERE
|
('$regexp', (SELECT id FROM ttrss_filter_types WHERE
|
||||||
description = '$match'),'".$_SESSION["uid"]."', $feed_id)");
|
description = '$match'),'".$_SESSION["uid"]."',
|
||||||
|
$feed_id, '$action_id')");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1983,22 +1989,39 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
print "</select> ";
|
print "</select> ";
|
||||||
|
|
||||||
|
print " Action: ";
|
||||||
|
|
||||||
|
print "<select id=\"fadd_action\">";
|
||||||
|
|
||||||
|
$result = db_query($link, "SELECT id,description FROM ttrss_filter_actions
|
||||||
|
ORDER BY name");
|
||||||
|
|
||||||
|
while ($line = db_fetch_assoc($result)) {
|
||||||
|
printf("<option id='%d'>%s</option>", $line["id"], $line["description"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
print "</select> ";
|
||||||
|
|
||||||
print "<input type=\"submit\"
|
print "<input type=\"submit\"
|
||||||
class=\"button\" onclick=\"javascript:addFilter()\"
|
class=\"button\" onclick=\"javascript:addFilter()\"
|
||||||
value=\"Add filter\">";
|
value=\"Add filter\">";
|
||||||
|
|
||||||
|
print "</div>";
|
||||||
|
|
||||||
$result = db_query($link, "SELECT
|
$result = db_query($link, "SELECT
|
||||||
ttrss_filters.id AS id,reg_exp,
|
ttrss_filters.id AS id,reg_exp,
|
||||||
ttrss_filters.description AS description,
|
ttrss_filters.description AS description,
|
||||||
ttrss_filter_types.name AS filter_type_name,
|
ttrss_filter_types.name AS filter_type_name,
|
||||||
ttrss_filter_types.description AS filter_type_descr,
|
ttrss_filter_types.description AS filter_type_descr,
|
||||||
feed_id,
|
feed_id,
|
||||||
|
ttrss_filter_actions.description AS action_description,
|
||||||
(SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title
|
(SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title
|
||||||
FROM
|
FROM
|
||||||
ttrss_filters,ttrss_filter_types
|
ttrss_filters,ttrss_filter_types,ttrss_filter_actions
|
||||||
WHERE
|
WHERE
|
||||||
filter_type = ttrss_filter_types.id AND
|
filter_type = ttrss_filter_types.id AND
|
||||||
|
ttrss_filter_actions.id = action_id AND
|
||||||
ttrss_filters.owner_uid = ".$_SESSION["uid"]."
|
ttrss_filters.owner_uid = ".$_SESSION["uid"]."
|
||||||
ORDER by reg_exp");
|
ORDER by reg_exp");
|
||||||
|
|
||||||
|
@ -2016,8 +2039,11 @@
|
||||||
</td</tr>";
|
</td</tr>";
|
||||||
|
|
||||||
print "<tr class=\"title\">
|
print "<tr class=\"title\">
|
||||||
<td width=\"5%\">Select</td><td width=\"30%\">Filter expression</td>
|
<td width=\"5%\">Select</td>
|
||||||
<td width=\"30%\">Feed</td><td width=\"10%\">Match</td>
|
<td width=\"20%\">Filter expression</td>
|
||||||
|
<td width=\"20%\">Feed</td>
|
||||||
|
<td width=\"15%\">Match</td>
|
||||||
|
<td width=\"15%\">Action</td>
|
||||||
<td width=\"30%\">Description</td></tr>";
|
<td width=\"30%\">Description</td></tr>";
|
||||||
|
|
||||||
$lnum = 0;
|
$lnum = 0;
|
||||||
|
@ -2058,7 +2084,10 @@
|
||||||
|
|
||||||
print "<td><a href=\"javascript:editFilter($filter_id);\">" .
|
print "<td><a href=\"javascript:editFilter($filter_id);\">" .
|
||||||
$line["filter_type_descr"] . "</td>";
|
$line["filter_type_descr"] . "</td>";
|
||||||
|
|
||||||
|
print "<td><a href=\"javascript:editFilter($filter_id);\">" .
|
||||||
|
$line["action_description"] . "</td>";
|
||||||
|
|
||||||
print "<td><a href=\"javascript:editFilter($filter_id);\">" .
|
print "<td><a href=\"javascript:editFilter($filter_id);\">" .
|
||||||
$line["description"] . "</td>";
|
$line["description"] . "</td>";
|
||||||
|
|
||||||
|
@ -2072,8 +2101,9 @@
|
||||||
print "<td>".$line["reg_exp"]."</td>";
|
print "<td>".$line["reg_exp"]."</td>";
|
||||||
print "<td>".$line["feed_title"]."</td>";
|
print "<td>".$line["feed_title"]."</td>";
|
||||||
print "<td>".$line["filter_type_descr"]."</td>";
|
print "<td>".$line["filter_type_descr"]."</td>";
|
||||||
|
print "<td>".$line["action_description"]."</td>";
|
||||||
print "<td>".$line["description"]."</td>";
|
print "<td>".$line["description"]."</td>";
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
|
print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
|
||||||
|
@ -2082,18 +2112,16 @@
|
||||||
"\"></td>";
|
"\"></td>";
|
||||||
|
|
||||||
print "<td>";
|
print "<td>";
|
||||||
|
|
||||||
print "<select id=\"iedit_feed\">";
|
print "<select id=\"iedit_feed\">";
|
||||||
|
|
||||||
print "<option id=\"0\">All feeds</option>";
|
print "<option id=\"0\">All feeds</option>";
|
||||||
|
|
||||||
if (db_num_rows($result) > 0) {
|
|
||||||
print "<option disabled>--------</option>";
|
|
||||||
}
|
|
||||||
|
|
||||||
$tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds
|
$tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds
|
||||||
WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
|
WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
|
||||||
|
|
||||||
|
if (db_num_rows($tmp_result) > 0) {
|
||||||
|
print "<option disabled>--------</option>";
|
||||||
|
}
|
||||||
|
|
||||||
while ($tmp_line = db_fetch_assoc($tmp_result)) {
|
while ($tmp_line = db_fetch_assoc($tmp_result)) {
|
||||||
if ($tmp_line["id"] == $line["feed_id"]) {
|
if ($tmp_line["id"] == $line["feed_id"]) {
|
||||||
$is_selected = "selected";
|
$is_selected = "selected";
|
||||||
|
@ -2109,7 +2137,26 @@
|
||||||
print "<td>";
|
print "<td>";
|
||||||
print_select("iedit_match", $line["filter_type_descr"], $filter_types);
|
print_select("iedit_match", $line["filter_type_descr"], $filter_types);
|
||||||
print "</td>";
|
print "</td>";
|
||||||
|
|
||||||
|
print "<td>";
|
||||||
|
print "<select id=\"iedit_filter_action\">";
|
||||||
|
|
||||||
|
$tmp_result = db_query($link, "SELECT id,description FROM ttrss_filter_actions
|
||||||
|
ORDER BY description");
|
||||||
|
|
||||||
|
while ($tmp_line = db_fetch_assoc($tmp_result)) {
|
||||||
|
if ($tmp_line["description"] == $line["action_description"]) {
|
||||||
|
$is_selected = "selected";
|
||||||
|
} else {
|
||||||
|
$is_selected = "";
|
||||||
|
}
|
||||||
|
printf("<option $is_selected id='%d'>%s</option>",
|
||||||
|
$tmp_line["id"], $tmp_line["description"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
print "</select></td>";
|
||||||
|
|
||||||
|
|
||||||
print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
|
print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
|
||||||
"\"></td>";
|
"\"></td>";
|
||||||
|
|
||||||
|
|
|
@ -232,14 +232,20 @@
|
||||||
|
|
||||||
$result = db_query($link, "SELECT reg_exp,
|
$result = db_query($link, "SELECT reg_exp,
|
||||||
(SELECT name FROM ttrss_filter_types
|
(SELECT name FROM ttrss_filter_types
|
||||||
WHERE id = filter_type) as name
|
WHERE id = filter_type) as name,
|
||||||
|
(SELECT name FROM ttrss_filter_actions
|
||||||
|
WHERE id = action_id) as action
|
||||||
FROM ttrss_filters WHERE
|
FROM ttrss_filters WHERE
|
||||||
owner_uid = $owner_uid AND
|
owner_uid = $owner_uid AND
|
||||||
(feed_id IS NULL OR feed_id = '$feed')");
|
(feed_id IS NULL OR feed_id = '$feed')");
|
||||||
|
|
||||||
while ($line = db_fetch_assoc($result)) {
|
while ($line = db_fetch_assoc($result)) {
|
||||||
if (!$filters[$line["name"]]) $filters[$line["name"]] = array();
|
if (!$filters[$line["name"]]) $filters[$line["name"]] = array();
|
||||||
array_push($filters[$line["name"]], $line["reg_exp"]);
|
|
||||||
|
$filter["reg_exp"] = $line["reg_exp"];
|
||||||
|
$filter["action"] = $line["action"];
|
||||||
|
|
||||||
|
array_push($filters[$line["name"]], $filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
$iterator = $rss->items;
|
$iterator = $rss->items;
|
||||||
|
@ -374,11 +380,16 @@
|
||||||
$dupcheck_qpart = "";
|
$dupcheck_qpart = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
error_reporting(0);
|
// error_reporting(0);
|
||||||
if (is_filtered($entry_title, $entry_content, $entry_link, $filters)) {
|
|
||||||
|
$filter_name = get_filter_name($entry_title, $entry_content,
|
||||||
|
$entry_link, $filters);
|
||||||
|
|
||||||
|
if ($filter_name == "filter") {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
error_reporting (DEFAULT_ERROR_LEVEL);
|
|
||||||
|
// error_reporting (DEFAULT_ERROR_LEVEL);
|
||||||
|
|
||||||
$result = db_query($link,
|
$result = db_query($link,
|
||||||
"SELECT ref_id FROM ttrss_user_entries WHERE
|
"SELECT ref_id FROM ttrss_user_entries WHERE
|
||||||
|
@ -387,10 +398,20 @@
|
||||||
|
|
||||||
// okay it doesn't exist - create user entry
|
// okay it doesn't exist - create user entry
|
||||||
if (db_num_rows($result) == 0) {
|
if (db_num_rows($result) == 0) {
|
||||||
|
|
||||||
|
if ($filter_name != 'catchup') {
|
||||||
|
$unread = 'true';
|
||||||
|
$last_read_qpart = 'NULL';
|
||||||
|
} else {
|
||||||
|
$unread = 'false';
|
||||||
|
$last_read_qpart = 'NOW()';
|
||||||
|
}
|
||||||
|
|
||||||
$result = db_query($link,
|
$result = db_query($link,
|
||||||
"INSERT INTO ttrss_user_entries
|
"INSERT INTO ttrss_user_entries
|
||||||
(ref_id, owner_uid, feed_id)
|
(ref_id, owner_uid, feed_id, unread, last_read)
|
||||||
VALUES ('$ref_id', '$owner_uid', '$feed')");
|
VALUES ('$ref_id', '$owner_uid', '$feed', $unread,
|
||||||
|
$last_read_qpart)");
|
||||||
}
|
}
|
||||||
|
|
||||||
$post_needs_update = false;
|
$post_needs_update = false;
|
||||||
|
@ -503,33 +524,43 @@
|
||||||
print "</select>";
|
print "</select>";
|
||||||
}
|
}
|
||||||
|
|
||||||
function is_filtered($title, $content, $link, $filters) {
|
function get_filter_name($title, $content, $link, $filters) {
|
||||||
|
|
||||||
if ($filters["title"]) {
|
if ($filters["title"]) {
|
||||||
foreach ($filters["title"] as $title_filter) {
|
foreach ($filters["title"] as $filter) {
|
||||||
if (preg_match("/$title_filter/i", $title))
|
$reg_exp = $filter["reg_exp"];
|
||||||
return true;
|
if (preg_match("/$reg_exp/i", $title)) {
|
||||||
|
return $filter["action"];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($filters["content"]) {
|
if ($filters["content"]) {
|
||||||
foreach ($filters["content"] as $content_filter) {
|
foreach ($filters["content"] as $filter) {
|
||||||
if (preg_match("/$content_filter/i", $content))
|
$reg_exp = $filter["reg_exp"];
|
||||||
return true;
|
if (preg_match("/$reg_exp/i", $content)) {
|
||||||
|
return $filter["action"];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($filters["both"]) {
|
if ($filters["both"]) {
|
||||||
foreach ($filters["both"] as $filter) {
|
foreach ($filters["both"] as $filter) {
|
||||||
if (preg_match("/$filter/i", $title) || preg_match("/$filter/i", $content))
|
$reg_exp = $filter["reg_exp"];
|
||||||
return true;
|
if (preg_match("/$reg_exp/i", $title) ||
|
||||||
|
preg_match("/$reg_exp/i", $content)) {
|
||||||
|
return $filter["action"];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($filters["link"]) {
|
if ($filters["link"]) {
|
||||||
foreach ($filters["link"] as $link_filter) {
|
$reg_exp = $filter["reg_exp"];
|
||||||
if (preg_match("/$link_filter/i", $link))
|
foreach ($filters["link"] as $filter) {
|
||||||
return true;
|
$reg_exp = $filter["reg_exp"];
|
||||||
|
if (preg_match("/$reg_exp/i", $link)) {
|
||||||
|
return $filter["action"];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
13
prefs.js
13
prefs.js
|
@ -235,6 +235,7 @@ function addFilter() {
|
||||||
var regexp = document.getElementById("fadd_regexp");
|
var regexp = document.getElementById("fadd_regexp");
|
||||||
var match = document.getElementById("fadd_match");
|
var match = document.getElementById("fadd_match");
|
||||||
var feed = document.getElementById("fadd_feed");
|
var feed = document.getElementById("fadd_feed");
|
||||||
|
var action = document.getElementById("fadd_action");
|
||||||
|
|
||||||
if (regexp.value.length == 0) {
|
if (regexp.value.length == 0) {
|
||||||
notify("Missing filter expression.");
|
notify("Missing filter expression.");
|
||||||
|
@ -242,12 +243,12 @@ function addFilter() {
|
||||||
notify("Adding filter...");
|
notify("Adding filter...");
|
||||||
|
|
||||||
var v_match = match[match.selectedIndex].text;
|
var v_match = match[match.selectedIndex].text;
|
||||||
|
|
||||||
var feed_id = feed[feed.selectedIndex].id;
|
var feed_id = feed[feed.selectedIndex].id;
|
||||||
|
var action_id = action[action.selectedIndex].id;
|
||||||
|
|
||||||
xmlhttp.open("GET", "backend.php?op=pref-filters&subop=add®exp=" +
|
xmlhttp.open("GET", "backend.php?op=pref-filters&subop=add®exp=" +
|
||||||
param_escape(regexp.value) + "&match=" + v_match +
|
param_escape(regexp.value) + "&match=" + v_match +
|
||||||
"&fid=" + param_escape(feed_id), true);
|
"&fid=" + param_escape(feed_id) + "&aid=" + param_escape(action_id), true);
|
||||||
|
|
||||||
xmlhttp.onreadystatechange=filterlist_callback;
|
xmlhttp.onreadystatechange=filterlist_callback;
|
||||||
xmlhttp.send(null);
|
xmlhttp.send(null);
|
||||||
|
@ -832,12 +833,15 @@ function filterEditSave() {
|
||||||
var regexp = document.getElementById("iedit_regexp").value;
|
var regexp = document.getElementById("iedit_regexp").value;
|
||||||
var descr = document.getElementById("iedit_descr").value;
|
var descr = document.getElementById("iedit_descr").value;
|
||||||
var match = document.getElementById("iedit_match");
|
var match = document.getElementById("iedit_match");
|
||||||
|
|
||||||
var v_match = match[match.selectedIndex].text;
|
var v_match = match[match.selectedIndex].text;
|
||||||
|
|
||||||
var feed = document.getElementById("iedit_feed");
|
var feed = document.getElementById("iedit_feed");
|
||||||
var feed_id = feed[feed.selectedIndex].id;
|
var feed_id = feed[feed.selectedIndex].id;
|
||||||
|
|
||||||
|
var action = document.getElementById("iedit_filter_action");
|
||||||
|
var action_id = action[action.selectedIndex].id;
|
||||||
|
|
||||||
// notify("Saving filter " + filter + ": " + regexp + ", " + descr + ", " + match);
|
// notify("Saving filter " + filter + ": " + regexp + ", " + descr + ", " + match);
|
||||||
|
|
||||||
if (regexp.length == 0) {
|
if (regexp.length == 0) {
|
||||||
|
@ -849,7 +853,8 @@ function filterEditSave() {
|
||||||
|
|
||||||
xmlhttp.open("GET", "backend.php?op=pref-filters&subop=editSave&id=" +
|
xmlhttp.open("GET", "backend.php?op=pref-filters&subop=editSave&id=" +
|
||||||
filter + "&r=" + param_escape(regexp) + "&d=" + param_escape(descr) +
|
filter + "&r=" + param_escape(regexp) + "&d=" + param_escape(descr) +
|
||||||
"&m=" + param_escape(v_match) + "&fid=" + param_escape(feed_id), true);
|
"&m=" + param_escape(v_match) + "&fid=" + param_escape(feed_id) +
|
||||||
|
"&aid=" + param_escape(action_id), true);
|
||||||
|
|
||||||
notify("");
|
notify("");
|
||||||
|
|
||||||
|
|
|
@ -295,7 +295,7 @@ a:hover {
|
||||||
|
|
||||||
#iedit_title, #iedit_link, #iedit_regexp, #iedit_descr, #iedit_expr, #iedit_updintl,
|
#iedit_title, #iedit_link, #iedit_regexp, #iedit_descr, #iedit_expr, #iedit_updintl,
|
||||||
#iedit_purgintl, #iedit_ulogin, #iedit_ulevel, #iedit_match, #iedit_feed,
|
#iedit_purgintl, #iedit_ulogin, #iedit_ulevel, #iedit_match, #iedit_feed,
|
||||||
#iedit_fcat {
|
#iedit_fcat, #iedit_filter_action {
|
||||||
width : 100%;
|
width : 100%;
|
||||||
padding-left : 2px;
|
padding-left : 2px;
|
||||||
}
|
}
|
||||||
|
@ -651,6 +651,11 @@ span.insensitive {
|
||||||
|
|
||||||
.prefGenericAddBox {
|
.prefGenericAddBox {
|
||||||
margin : 5px;
|
margin : 5px;
|
||||||
|
font-size : small;
|
||||||
|
}
|
||||||
|
|
||||||
|
.prefGenericAddBox td {
|
||||||
|
font-size : small;
|
||||||
}
|
}
|
||||||
|
|
||||||
body.logoutBody {
|
body.logoutBody {
|
||||||
|
|
Loading…
Reference in New Issue