af_redditimgur: import link flair as tags

This commit is contained in:
Andrew Dolgov 2021-03-09 08:19:55 +03:00
parent bc7cb76379
commit b1961163b8
1 changed files with 13 additions and 2 deletions

View File

@ -244,6 +244,7 @@ class Af_RedditImgur extends Plugin {
$post_is_nsfw = false; $post_is_nsfw = false;
$num_comments = 0; $num_comments = 0;
$score = 0; $score = 0;
$link_flairs = [];
$apply_nsfw_tags = FeedItem_Common::normalize_categories($this->host->get_array($this, "apply_nsfw_tags", [])); $apply_nsfw_tags = FeedItem_Common::normalize_categories($this->host->get_array($this, "apply_nsfw_tags", []));
// embed before reddit <table> post layout // embed before reddit <table> post layout
@ -275,6 +276,10 @@ class Af_RedditImgur extends Plugin {
$score += $data['score'] ?? 0; $score += $data['score'] ?? 0;
$num_comments += $data["num_comments"] ?? 0; $num_comments += $data["num_comments"] ?? 0;
if (!empty($data["link_flair_text"])) {
array_push($link_flairs, $data["link_flair_text"]);
}
if ($over_18) { if ($over_18) {
Debug::log("JSON: post is NSFW", Debug::$LOG_EXTENDED); Debug::log("JSON: post is NSFW", Debug::$LOG_EXTENDED);
$post_is_nsfw = true; $post_is_nsfw = true;
@ -317,6 +322,10 @@ class Af_RedditImgur extends Plugin {
$article["tags"] = array_merge($article["tags"], $apply_nsfw_tags); $article["tags"] = array_merge($article["tags"], $apply_nsfw_tags);
} }
if (count($link_flairs) > 0) {
$article["tags"] = array_merge($article["tags"], FeedItem_Common::normalize_categories($link_flairs));
}
$article["num_comments"] = $num_comments; $article["num_comments"] = $num_comments;
if ($import_score && $score > 0) if ($import_score && $score > 0)
@ -694,8 +703,8 @@ class Af_RedditImgur extends Plugin {
function testurl() { function testurl() {
$url = clean($_POST["url"]); $url = clean($_POST["url"] ?? "");
$article_url = clean($_POST["article_url"]); $article_url = clean($_POST["article_url"] ?? "");
$this->dump_json_data = true; $this->dump_json_data = true;
@ -743,6 +752,8 @@ class Af_RedditImgur extends Plugin {
Debug::log("Inline result: $found", Debug::$LOG_VERBOSE); Debug::log("Inline result: $found", Debug::$LOG_VERBOSE);
print_r($article);
if (!$found) { if (!$found) {
Debug::log("Readability result:", Debug::$LOG_VERBOSE); Debug::log("Readability result:", Debug::$LOG_VERBOSE);