filter_test: proper implementation using queryFeedHeadlines

master
Andrew Dolgov 14 years ago
parent 452a329b97
commit 361840203b

@ -2338,7 +2338,7 @@
} }
function sql_bool_to_bool($s) { function sql_bool_to_bool($s) {
if ($s == "t" || $s == "1") { if ($s == "t" || $s == "1" || $s == "true") {
return true; return true;
} else { } else {
return false; return false;
@ -3369,7 +3369,7 @@
return $search_query_part; return $search_query_part;
} }
function queryFeedHeadlines($link, $feed, $limit, $view_mode, $cat_view, $search, $search_mode, $match_on, $override_order = false, $offset = 0, $owner_uid = 0) { function queryFeedHeadlines($link, $feed, $limit, $view_mode, $cat_view, $search, $search_mode, $match_on, $override_order = false, $offset = 0, $owner_uid = 0, $filter = false) {
if (!$owner_uid) $owner_uid = $_SESSION["uid"]; if (!$owner_uid) $owner_uid = $_SESSION["uid"];
@ -3394,6 +3394,12 @@
$search_query_part = ""; $search_query_part = "";
} }
if ($filter) {
$filter_query_part = filter_to_sql($filter);
} else {
$filter_query_part = "";
}
$view_query_part = ""; $view_query_part = "";
if ($view_mode == "adaptive" || $view_query_part == "noscores") { if ($view_mode == "adaptive" || $view_query_part == "noscores") {
@ -3623,6 +3629,7 @@
ttrss_user_entries.ref_id = ttrss_entries.id AND ttrss_user_entries.ref_id = ttrss_entries.id AND
ttrss_user_entries.owner_uid = '$owner_uid' AND ttrss_user_entries.owner_uid = '$owner_uid' AND
$search_query_part $search_query_part
$filter_query_part
$view_query_part $view_query_part
$query_strategy_part ORDER BY $order_by $query_strategy_part ORDER BY $order_by
$limit_query_part $offset_query_part"; $limit_query_part $offset_query_part";
@ -7245,4 +7252,58 @@
return $result; return $result;
} }
function filter_to_sql($filter) {
$query = "";
if (DB_TYPE == "pgsql")
$reg_qpart = "~";
else
$reg_qpart = "REGEXP";
switch ($filter["type"]) {
case "title":
$query = "LOWER(ttrss_entries.title) $reg_qpart LOWER('".
$filter['reg_exp'] . "')";
break;
case "content":
$query = "LOWER(ttrss_entries.content) $reg_qpart LOWER('".
$filter['reg_exp'] . "')";
break;
case "both":
$query = "LOWER(ttrss_entries.title) $reg_qpart LOWER('".
$filter['reg_exp'] . "') OR LOWER(" .
"ttrss_entries.content) $reg_qpart LOWER('" . $filter['reg_exp'] . "')";
break;
case "tag":
$query = "LOWER(ttrss_user_entries.tag_cache) $reg_qpart LOWER('".
$filter['reg_exp'] . "')";
break;
case "link":
$query = "LOWER(ttrss_entries.link) $reg_qpart LOWER('".
$filter['reg_exp'] . "')";
break;
case "date":
if ($filter["filter_param"] == "before")
$cmp_qpart = "<";
else
$cmp_qpart = ">=";
$timestamp = date("Y-m-d H:N:s", strtotime($filter["reg_exp"]));
$query = "ttrss_entries.date_entered $cmp_qpart '$timestamp'";
break;
case "author":
$query = "LOWER(ttrss_entries.author) $reg_qpart LOWER('".
$filter['reg_exp'] . "')";
break;
}
if ($filter["inverse"])
$query = "NOT ($query)";
if ($query)
$query .= " AND ";
return $query;
}
?> ?>

@ -12,10 +12,10 @@
$filter["reg_exp"] = $reg_exp; $filter["reg_exp"] = $reg_exp;
$filter["action"] = $action_name; $filter["action"] = $action_name;
$filter["type"] = $type_name;
$filter["action_param"] = $action_param; $filter["action_param"] = $action_param;
$filter["filter_param"] = $filter_param; $filter["filter_param"] = $filter_param;
$filter["inverse"] = sql_bool_to_bool($inverse); $filter["inverse"] = $inverse;
$filters[$type_name] = array($filter); $filters[$type_name] = array($filter);
@ -27,8 +27,8 @@
$feed_title = getFeedTitle($link, $feed); $feed_title = getFeedTitle($link, $feed);
$qfh_ret = queryFeedHeadlines($link, $feed, $qfh_ret = queryFeedHeadlines($link, $feed,
300, "", false, false, false, 30, "", false, false, false,
false, "date_entered DESC", 0, $_SESSION["uid"]); false, "date_entered DESC", 0, $_SESSION["uid"], $filter);
$result = $qfh_ret[0]; $result = $qfh_ret[0];
@ -45,43 +45,34 @@
$entry_timestamp = strtotime($line["updated"]); $entry_timestamp = strtotime($line["updated"]);
$entry_tags = get_article_tags($link, $line["id"], $_SESSION["uid"]); $entry_tags = get_article_tags($link, $line["id"], $_SESSION["uid"]);
$article_filters = get_article_filters($filters, $line["title"], $content_preview = truncate_string(
$line["content_preview"], $line["link"], strip_tags($line["content_preview"]), 100, '...');
$entry_timestamp, $line["author"], $entry_tags);
if (count($article_filters) != 0) {
$content_preview = truncate_string(
strip_tags($line["content_preview"]), 100, '...');
if ($line["feed_title"]) if ($line["feed_title"])
$feed_title = $line["feed_title"]; $feed_title = $line["feed_title"];
print "<tr>"; print "<tr>";
print "<td width='5%' align='center'><input print "<td width='5%' align='center'><input
dojoType=\"dijit.form.CheckBox\" checked=\"1\" dojoType=\"dijit.form.CheckBox\" checked=\"1\"
disabled=\"1\" type=\"checkbox\"></td>"; disabled=\"1\" type=\"checkbox\"></td>";
print "<td>"; print "<td>";
print $line["title"]; print $line["title"];
print "&nbsp;("; print "&nbsp;(";
print "<b>" . $feed_title . "</b>"; print "<b>" . $feed_title . "</b>";
print "):&nbsp;"; print "):&nbsp;";
print "<span class=\"insensitive\">" . $content_preview . "</span>"; print "<span class=\"insensitive\">" . $content_preview . "</span>";
print $line["date_entered"];
print "</td></tr>"; print "</td></tr>";
$found++;
}
if ($found >= 30) $found++;
break;
} }
if ($found == 0) { if ($found == 0) {
print "<tr><td align='center'>" . print "<tr><td align='center'>" .
__("No recent articles matching this filter has been found.") . "</td></tr>"; __("No articles matching this filter has been found.") . "</td></tr>";
} }
print "</table>"; print "</table>";

Loading…
Cancel
Save