allow filters to work on child categories

This commit is contained in:
Andrew Dolgov 2012-10-09 19:09:50 +04:00
parent bed44d5164
commit 67bd0b1f26
2 changed files with 23 additions and 4 deletions

View File

@ -2262,6 +2262,20 @@
return $search_query_part; return $search_query_part;
} }
function getParentCategories($link, $cat, $owner_uid) {
$rv = array();
$result = db_query($link, "SELECT parent_cat FROM ttrss_feed_categories
WHERE id = '$cat' AND parent_cat IS NOT NULL AND owner_uid = $owner_uid");
while ($line = db_fetch_assoc($result)) {
array_push($rv, $line["parent_cat"]);
$rv = array_merge($rv, getParentCategories($link, $line["parent_cat"], $owner_uid));
}
return $rv;
}
function getChildCategories($link, $cat, $owner_uid) { function getChildCategories($link, $cat, $owner_uid) {
$rv = array(); $rv = array();
@ -3635,6 +3649,10 @@
$result = db_query($link, "SELECT * FROM ttrss_filters2 WHERE $result = db_query($link, "SELECT * FROM ttrss_filters2 WHERE
owner_uid = $owner_uid AND enabled = true"); owner_uid = $owner_uid AND enabled = true");
$check_cats = join(",", array_merge(
getParentCategories($link, $cat_id, $owner_uid),
array($cat_id)));
while ($line = db_fetch_assoc($result)) { while ($line = db_fetch_assoc($result)) {
$filter_id = $line["id"]; $filter_id = $line["id"];
@ -3643,7 +3661,7 @@
FROM ttrss_filters2_rules AS r, FROM ttrss_filters2_rules AS r,
ttrss_filter_types AS t ttrss_filter_types AS t
WHERE WHERE
(cat_id IS NULL OR cat_id = '$cat_id') AND (cat_id IS NULL OR cat_id IN ($check_cats)) AND
(feed_id IS NULL OR feed_id = '$feed_id') AND (feed_id IS NULL OR feed_id = '$feed_id') AND
filter_type = t.id AND filter_id = '$filter_id'"); filter_type = t.id AND filter_id = '$filter_id'");

View File

@ -410,9 +410,10 @@
$filters = load_filters($link, $feed, $owner_uid); $filters = load_filters($link, $feed, $owner_uid);
// if ($debug_enabled) { if ($debug_enabled) {
// print_r($filters); //print_r($filters);
// } _debug("update_rss_feed: " . count($filters) . " filters loaded.");
}
if ($use_simplepie) { if ($use_simplepie) {
$iterator = $rss->get_items(); $iterator = $rss->get_items();