host = $host; $host->add_hook(PluginHost::HOOK_RENDER_ARTICLE, $this); $host->add_hook(PluginHost::HOOK_RENDER_ARTICLE_CDM, $this); $host->add_hook(PluginHost::HOOK_RENDER_ARTICLE_API, $this); $host->add_hook(PluginHost::HOOK_ARTICLE_IMAGE, $this); $host->add_hook(PluginHost::HOOK_PREFS_TAB, $this); } function hook_article_image($enclosures, $content, $site_url, $article) { $tags = explode(",", $this->host->get($this, "tags")); $article_tags = $article["tags"]; if (count(array_intersect($tags, $article_tags)) > 0) { return [Config::get_self_url() . "/plugins/nsfw/nsfw.png", "", "nsfw"]; } else { return ["", "", $content]; } } /** * @param array $article * @return array * @throws PDOException */ private function rewrite_contents(array $article) : array { $tags = explode(",", $this->host->get($this, "tags")); $article_tags = $article["tags"]; if (count(array_intersect($tags, $article_tags)) > 0) { $article["content"] = "
" . __("Not safe for work (click to toggle)") . "" . $article["content"] . "
"; } return $article; } function get_css() { return 'details.nsfw { cursor : pointer; user-select : none; }'; } function hook_render_article_api($row) { $article = isset($row['headline']) ? $row['headline'] : $row['article']; return $this->rewrite_contents($article); } function hook_render_article($article) { return $this->rewrite_contents($article); } function hook_render_article_cdm($article) { return $this->rewrite_contents($article); } function hook_prefs_tab($args) { if ($args != "prefPrefs") return; $tags = $this->host->get($this, "tags"); ?>
">

host->set($this, "tags", $tags); echo __("Configuration saved."); } function api_version() { return 2; } }