From: Andrew Dolgov Date: Sat, 23 Feb 2013 17:28:09 +0000 (+0400) Subject: nsfw: make tags list configurable X-Git-Tag: 1.7.1~45 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=cd616c4c35a4910486a9903bbfd95f1e9b9f3463;p=tt-rss.git nsfw: make tags list configurable --- diff --git a/plugins/nsfw/init.php b/plugins/nsfw/init.php index fd274ead..9aadde4d 100644 --- a/plugins/nsfw/init.php +++ b/plugins/nsfw/init.php @@ -6,7 +6,7 @@ class NSFW extends Plugin { function about() { return array(1.0, - "Hide article content if tags contain \"nsfw\"", + "Hide article content based on tags", "fox", false); } @@ -17,6 +17,7 @@ class NSFW extends Plugin { $host->add_hook($host::HOOK_RENDER_ARTICLE, $this); $host->add_hook($host::HOOK_RENDER_ARTICLE_CDM, $this); + $host->add_hook($host::HOOK_PREFS_TAB, $this); } @@ -25,8 +26,9 @@ class NSFW extends Plugin { } function hook_render_article($article) { + $tags = array_map("trim", explode(", ", $this->host->get($this, "tags"))); - if (array_search("nsfw", $article["tags"]) !== FALSE) { + if (count(array_intersect($tags, $article["tags"])) > 0) { $article["content"] = "
"; } @@ -35,7 +37,9 @@ class NSFW extends Plugin { } function hook_render_article_cdm($article) { - if (array_search("nsfw", $article["tags"]) !== FALSE) { + $tags = array_map("trim", explode(", ", $this->host->get($this, "tags"))); + + if (count(array_intersect($tags, $article["tags"])) > 0) { $article["content"] = "
"; } @@ -43,5 +47,59 @@ class NSFW extends Plugin { return $article; } + function hook_prefs_tab($args) { + if ($args != "prefPrefs") return; + + print "
"; + + print "
"; + + $tags = $this->host->get($this, "tags"); + + print "
"; + + print ""; + + print ""; + print ""; + print ""; + + print ""; + + print ""; + print ""; + + print "
".__("Tags to consider NSFW (comma-separated)")."
"; + + print "

"; + + print "

"; + + print "
"; #pane + } + + function save() { + $tags = explode(",", db_escape_string($_POST["tags"])); + $tags = array_map("trim", $tags); + $tags = array_map("mb_strtolower", $tags); + $tags = join(", ", $tags); + + $this->host->set($this, "tags", $tags); + + echo __("Configuration saved."); + } + } ?>