enable processing of article-date filter (closes #225)

This commit is contained in:
Andrew Dolgov 2008-12-13 14:49:19 +01:00
parent 08e618f700
commit 44d0e7742b
3 changed files with 61 additions and 20 deletions

View File

@ -807,10 +807,6 @@
if ($rss_2_date != "") $entry_timestamp = strtotime($rss_2_date); if ($rss_2_date != "") $entry_timestamp = strtotime($rss_2_date);
} }
if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) {
_debug("update_rss_feed: date $entry_timestamp");
}
if ($entry_timestamp == "" || $entry_timestamp == -1 || !$entry_timestamp) { if ($entry_timestamp == "" || $entry_timestamp == -1 || !$entry_timestamp) {
$entry_timestamp = time(); $entry_timestamp = time();
$no_orig_date = 'true'; $no_orig_date = 'true';
@ -820,6 +816,10 @@
$entry_timestamp_fmt = strftime("%Y/%m/%d %H:%M:%S", $entry_timestamp); $entry_timestamp_fmt = strftime("%Y/%m/%d %H:%M:%S", $entry_timestamp);
if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) {
_debug("update_rss_feed: date $entry_timestamp [$entry_timestamp_fmt]");
}
if ($use_simplepie) { if ($use_simplepie) {
$entry_title = $item->get_title(); $entry_title = $item->get_title();
} else { } else {
@ -1156,7 +1156,7 @@
// error_reporting(0); // error_reporting(0);
$article_filters = get_article_filters($filters, $entry_title, $article_filters = get_article_filters($filters, $entry_title,
$entry_content, $entry_link); $entry_content, $entry_link, $entry_timestamp);
if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) {
_debug("update_rss_feed: article filters: "); _debug("update_rss_feed: article filters: ");
@ -1457,7 +1457,7 @@
print "</select>"; print "</select>";
} }
function get_article_filters($filters, $title, $content, $link) { function get_article_filters($filters, $title, $content, $link, $timestamp) {
$matches = array(); $matches = array();
if ($filters["title"]) { if ($filters["title"]) {
@ -1516,6 +1516,32 @@
} }
} }
if ($filters["date"]) {
$reg_exp = $filter["reg_exp"];
foreach ($filters["date"] as $filter) {
$date_modifier = $filter["filter_param"];
$inverse = $filter["inverse"];
$check_timestamp = strtotime($filter["reg_exp"]);
# no-op when timestamp doesn't parse to prevent misfires
if ($check_timestamp) {
$match_ok = false;
if ($date_modifier == "before" && $timestamp < $check_timestamp ||
$date_modifier == "after" && $timestamp > $check_timestamp) {
$match_ok = true;
}
if ($inverse) $match_ok = !$match_ok;
if ($match_ok) {
array_push($matches, array($filter["action"], $filter["action_param"]));
}
}
}
}
return $matches; return $matches;
} }
@ -5767,7 +5793,8 @@
ttrss_filter_types.name AS name, ttrss_filter_types.name AS name,
ttrss_filter_actions.name AS action, ttrss_filter_actions.name AS action,
inverse, inverse,
action_param action_param,
filter_param
FROM ttrss_filters,ttrss_filter_types,ttrss_filter_actions WHERE FROM ttrss_filters,ttrss_filter_types,ttrss_filter_actions WHERE
enabled = true AND enabled = true AND
$ftype_query_part $ftype_query_part
@ -5781,6 +5808,7 @@
$filter["reg_exp"] = $line["reg_exp"]; $filter["reg_exp"] = $line["reg_exp"];
$filter["action"] = $line["action"]; $filter["action"] = $line["action"];
$filter["action_param"] = $line["action_param"]; $filter["action_param"] = $line["action_param"];
$filter["filter_param"] = $line["filter_param"];
$filter["inverse"] = sql_bool_to_bool($line["inverse"]); $filter["inverse"] = sql_bool_to_bool($line["inverse"]);
array_push($filters[$line["name"]], $filter); array_push($filters[$line["name"]], $filter);

View File

@ -360,10 +360,14 @@
print "<span id=\"filter_dlg_date_mod_box\" style=\"display : none\">"; print "<span id=\"filter_dlg_date_mod_box\" style=\"display : none\">";
print __("Date") . " "; print __("Date") . " ";
print "<select name=\"filter_date_modifier\">";
print "<option value=\"before\">".__('before')."</option>"; $filter_params = array(
print "<option value=\"after\">".__('after')."</option>"; "before" => __("before"),
print "</select>&nbsp;</span>"; "after" => __("after"));
print_select_hash("filter_date_modifier", "before", $filter_params);
print "&nbsp;</span>";
print "<input onkeypress=\"return filterCR(event, createFilter)\" print "<input onkeypress=\"return filterCR(event, createFilter)\"
onkeyup=\"toggleSubmitNotEmpty(this, 'infobox_submit')\" onkeyup=\"toggleSubmitNotEmpty(this, 'infobox_submit')\"

View File

@ -15,6 +15,7 @@
$feed_id = db_fetch_result($result, 0, "feed_id"); $feed_id = db_fetch_result($result, 0, "feed_id");
$action_id = db_fetch_result($result, 0, "action_id"); $action_id = db_fetch_result($result, 0, "action_id");
$action_param = db_fetch_result($result, 0, "action_param"); $action_param = db_fetch_result($result, 0, "action_param");
$filter_param = db_fetch_result($result, 0, "filter_param");
$enabled = sql_bool_to_bool(db_fetch_result($result, 0, "enabled")); $enabled = sql_bool_to_bool(db_fetch_result($result, 0, "enabled"));
$inverse = sql_bool_to_bool(db_fetch_result($result, 0, "inverse")); $inverse = sql_bool_to_bool(db_fetch_result($result, 0, "inverse"));
@ -48,10 +49,15 @@
print "<span id=\"filter_dlg_date_mod_box\" $date_ops_invisible>"; print "<span id=\"filter_dlg_date_mod_box\" $date_ops_invisible>";
print __("Date") . " "; print __("Date") . " ";
print "<select name=\"filter_date_modifier\">";
print "<option value=\"before\">".__('before')."</option>"; $filter_params = array(
print "<option value=\"after\">".__('after')."</option>"; "before" => __("before"),
print "</select>&nbsp;</span>"; "after" => __("after"));
print_select_hash("filter_date_modifier", $filter_param,
$filter_params);
print "&nbsp;</span>";
print "<input onkeypress=\"return filterCR(event, filterEditSave)\" print "<input onkeypress=\"return filterCR(event, filterEditSave)\"
onkeyup=\"toggleSubmitNotEmpty(this, 'infobox_submit')\" onkeyup=\"toggleSubmitNotEmpty(this, 'infobox_submit')\"
@ -167,6 +173,9 @@
$enabled = checkbox_to_sql_bool(db_escape_string($_GET["enabled"])); $enabled = checkbox_to_sql_bool(db_escape_string($_GET["enabled"]));
$inverse = checkbox_to_sql_bool(db_escape_string($_GET["inverse"])); $inverse = checkbox_to_sql_bool(db_escape_string($_GET["inverse"]));
# for the time being, no other filters use params anyway...
$filter_param = db_escape_string($_GET["filter_date_modifier"]);
if (!$feed_id) { if (!$feed_id) {
$feed_id = 'NULL'; $feed_id = 'NULL';
} else { } else {
@ -180,7 +189,8 @@
filter_type = '$filter_type', filter_type = '$filter_type',
enabled = $enabled, enabled = $enabled,
inverse = $inverse, inverse = $inverse,
action_param = '$action_param' action_param = '$action_param',
filter_param = '$filter_param'
WHERE id = '$filter_id' AND owner_uid = " . $_SESSION["uid"]); WHERE id = '$filter_id' AND owner_uid = " . $_SESSION["uid"]);
if (db_affected_rows($link, $result) != 0) { if (db_affected_rows($link, $result) != 0) {
@ -205,9 +215,11 @@
$feed_id = db_escape_string($_GET["feed_id"]); $feed_id = db_escape_string($_GET["feed_id"]);
$action_id = db_escape_string($_GET["action_id"]); $action_id = db_escape_string($_GET["action_id"]);
$action_param = db_escape_string($_GET["action_param"]); $action_param = db_escape_string($_GET["action_param"]);
$inverse = checkbox_to_sql_bool(db_escape_string($_GET["inverse"])); $inverse = checkbox_to_sql_bool(db_escape_string($_GET["inverse"]));
# for the time being, no other filters use params anyway...
$filter_param = db_escape_string($_GET["filter_date_modifier"]);
if (!$regexp) return; if (!$regexp) return;
if (!$feed_id) { if (!$feed_id) {
@ -216,9 +228,6 @@
$feed_id = sprintf("'%s'", db_escape_string($feed_id)); $feed_id = sprintf("'%s'", db_escape_string($feed_id));
} }
# for the time being, no other filters use params anyway...
$filter_param = db_escape_string($_GET["filter_date_modifier"]);
$result = db_query($link, $result = db_query($link,
"INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id, "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id,
action_id, action_param, inverse, filter_param) action_id, action_param, inverse, filter_param)