From f59c567831662fc78a570c785027e6e7b1c31880 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 20 Dec 2020 23:12:45 +0300 Subject: update_rss_feed: fix BLACKLISTED_TAGS not working properly, simplify tag-related code --- classes/article.php | 2 +- classes/rssutils.php | 41 ++++++++++++++++------------------------- 2 files changed, 17 insertions(+), 26 deletions(-) (limited to 'classes') diff --git a/classes/article.php b/classes/article.php index f6a4462d6..5527b7253 100755 --- a/classes/article.php +++ b/classes/article.php @@ -218,7 +218,7 @@ class Article extends Handler_Protected { $id = clean($_REQUEST["id"]); $tags_str = clean($_REQUEST["tags_str"]); - $tags = array_unique(trim_array(explode(",", $tags_str))); + $tags = array_unique(array_map('trim', explode(",", $tags_str))); $this->pdo->beginTransaction(); diff --git a/classes/rssutils.php b/classes/rssutils.php index bd7256ec7..857bc2948 100755 --- a/classes/rssutils.php +++ b/classes/rssutils.php @@ -1174,7 +1174,7 @@ class RSSUtils { foreach ($article_filters as $f) { if ($f["type"] == "tag") { - $manual_tags = trim_array(explode(",", $f["param"])); + $manual_tags = array_map('trim', explode(",", mb_strtolower($f["param"]))); foreach ($manual_tags as $tag) { array_push($entry_tags, $tag); @@ -1184,28 +1184,19 @@ class RSSUtils { // Skip boring tags - $boring_tags = trim_array(explode(",", mb_strtolower(get_pref( - 'BLACKLISTED_TAGS', $owner_uid, ''), 'utf-8'))); + $boring_tags = array_map('trim', + explode(",", mb_strtolower( + get_pref('BLACKLISTED_TAGS', $owner_uid)))); - $filtered_tags = array(); - $tags_to_cache = array(); + $entry_tags = FeedItem_Common::normalize_categories( + array_unique( + array_diff($entry_tags, $boring_tags))); - foreach ($entry_tags as $tag) { - if (array_search($tag, $boring_tags) === false) { - array_push($filtered_tags, $tag); - } - } - - $filtered_tags = array_unique($filtered_tags); - - if (Debug::get_loglevel() >= Debug::$LOG_VERBOSE) { - Debug::log("filtered tags: " . implode(", ", $filtered_tags), Debug::$LOG_VERBOSE); - - } + Debug::log("filtered tags: " . implode(", ", $entry_tags), Debug::$LOG_VERBOSE); // Save article tags in the database - if (count($filtered_tags) > 0) { + if (count($entry_tags) > 0) { $tsth = $pdo->prepare("SELECT id FROM ttrss_tags WHERE tag_name = ? AND post_int_id = ? AND @@ -1215,25 +1206,25 @@ class RSSUtils { (owner_uid,tag_name,post_int_id) VALUES (?, ?, ?)"); - $filtered_tags = FeedItem_Common::normalize_categories($filtered_tags); - - foreach ($filtered_tags as $tag) { + foreach ($entry_tags as $tag) { $tsth->execute([$tag, $entry_int_id, $owner_uid]); if (!$tsth->fetch()) { $usth->execute([$owner_uid, $tag, $entry_int_id]); } - - array_push($tags_to_cache, $tag); } /* update the cache */ - $tags_str = join(",", $tags_to_cache); $tsth = $pdo->prepare("UPDATE ttrss_user_entries SET tag_cache = ? WHERE ref_id = ? AND owner_uid = ?"); - $tsth->execute([$tags_str, $entry_ref_id, $owner_uid]); + + $tsth->execute([ + join(",", $entry_tags), + $entry_ref_id, + $owner_uid + ]); } Debug::log("article processed", Debug::$LOG_VERBOSE); -- cgit v1.2.3