1
0
mirror of https://git.tt-rss.org/git/tt-rss.git synced 2025-12-21 10:11:28 +00:00

tag-related fixes

1. move tag sanitization to feedparser common item class
2. enforce length limit on tags when parsing
3. support multiple tags passed via one dc:subject and other such elements, parse them as a comma-separated list
4. sort resulting tag list to prevent different order between feed updates
5. remove some duplicate code related to tag validation
6. allow + symbol in tags
This commit is contained in:
Andrew Dolgov
2019-11-20 18:56:34 +03:00
parent ffa3f9309f
commit 304d3a0b88
5 changed files with 52 additions and 83 deletions

View File

@@ -626,28 +626,8 @@ class RSSUtils {
Debug::log("author $entry_author", Debug::$LOG_VERBOSE);
Debug::log("looking for tags...", Debug::$LOG_VERBOSE);
// parse <category> entries into tags
$additional_tags = array();
$additional_tags_src = $item->get_categories();
if (is_array($additional_tags_src)) {
foreach ($additional_tags_src as $tobj) {
array_push($additional_tags, $tobj);
}
}
$entry_tags = array_unique($additional_tags);
for ($i = 0; $i < count($entry_tags); $i++) {
$entry_tags[$i] = mb_strtolower($entry_tags[$i], 'utf-8');
// we don't support numeric tags, let's prefix them
if (is_numeric($entry_tags[$i])) $entry_tags[$i] = 't:' . $entry_tags[$i];
}
Debug::log("tags found: " . join(",", $entry_tags), Debug::$LOG_VERBOSE);
$entry_tags = $item->get_categories();
Debug::log("tags found: " . join(", ", $entry_tags), Debug::$LOG_VERBOSE);
Debug::log("done collecting data.", Debug::$LOG_VERBOSE);
@@ -1107,9 +1087,7 @@ class RSSUtils {
$manual_tags = trim_array(explode(",", $f["param"]));
foreach ($manual_tags as $tag) {
if (Article::tag_is_valid($tag)) {
array_push($entry_tags, $tag);
}
array_push($entry_tags, $tag);
}
}
}
@@ -1122,19 +1100,17 @@ class RSSUtils {
$filtered_tags = array();
$tags_to_cache = array();
if ($entry_tags && is_array($entry_tags)) {
foreach ($entry_tags as $tag) {
if (array_search($tag, $boring_tags) === false) {
array_push($filtered_tags, $tag);
}
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_EXTENDED) {
Debug::log("filtered article tags:", Debug::$LOG_VERBOSE);
print_r($filtered_tags);
if (Debug::get_loglevel() >= Debug::$LOG_VERBOSE) {
Debug::log("filtered tags: " . implode(", ", $filtered_tags), Debug::$LOG_VERBOSE);
}
// Save article tags in the database
@@ -1149,12 +1125,9 @@ class RSSUtils {
(owner_uid,tag_name,post_int_id)
VALUES (?, ?, ?)");
$filtered_tags = FeedItem_Common::normalize_categories($filtered_tags);
foreach ($filtered_tags as $tag) {
$tag = Article::sanitize_tag($tag);
if (!Article::tag_is_valid($tag)) continue;
$tsth->execute([$tag, $entry_int_id, $owner_uid]);
if (!$tsth->fetch()) {
@@ -1165,9 +1138,6 @@ class RSSUtils {
}
/* update the cache */
$tags_to_cache = array_unique($tags_to_cache);
$tags_str = join(",", $tags_to_cache);
$tsth = $pdo->prepare("UPDATE ttrss_user_entries