]>
git.wh0rd.org - tt-rss.git/blob - plugins/nsfw/init.php
2 class NSFW
extends Plugin
{
9 "Hide article content based on tags",
14 function init($host) {
15 $this->link
= $host->get_link();
18 $host->add_hook($host::HOOK_RENDER_ARTICLE
, $this);
19 $host->add_hook($host::HOOK_RENDER_ARTICLE_CDM
, $this);
20 $host->add_hook($host::HOOK_PREFS_TAB
, $this);
25 return file_get_contents(dirname(__FILE__
) . "/init.js");
28 function hook_render_article($article) {
29 $tags = array_map("trim", explode(", ", $this->host
->get($this, "tags")));
31 if (count(array_intersect($tags, $article["tags"])) > 0) {
32 $article["content"] = "<div class='nswf wrapper'><button onclick=\"nsfwShow(this)\">".__("Not work safe (click to toggle)")."</button>
33 <div class='nswf content' style='display : none'>".$article["content"]."</div></div>";
39 function hook_render_article_cdm($article) {
40 $tags = array_map("trim", explode(", ", $this->host
->get($this, "tags")));
42 if (count(array_intersect($tags, $article["tags"])) > 0) {
43 $article["content"] = "<div class='nswf wrapper'><button onclick=\"nsfwShow(this)\">".__("Not work safe (click to toggle)")."</button>
44 <div class='nswf content' style='display : none'>".$article["content"]."</div></div>";
50 function hook_prefs_tab($args) {
51 if ($args != "prefPrefs") return;
53 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__("NSFW Plugin")."\">";
57 $tags = $this->host
->get($this, "tags");
59 print "<form dojoType=\"dijit.form.Form\">";
61 print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
63 if (this.validate()) {
64 new Ajax.Request('backend.php', {
65 parameters: dojo.objectToQuery(this.getValues()),
66 onComplete: function(transport) {
67 notify_info(transport.responseText);
74 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pluginhandler\">";
75 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"save\">";
76 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"plugin\" value=\"nsfw\">";
78 print "<table width=\"100%\" class=\"prefPrefsList\">";
80 print "<tr><td width=\"40%\">".__("Tags to consider NSFW (comma-separated)")."</td>";
81 print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\" name=\"tags\" value=\"$tags\"></td></tr>";
85 print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
86 __("Save")."</button>";
94 $tags = explode(",", db_escape_string($this->link
, $_POST["tags"]));
95 $tags = array_map("trim", $tags);
96 $tags = array_map("mb_strtolower", $tags);
97 $tags = join(", ", $tags);
99 $this->host
->set($this, "tags", $tags);
101 echo __("Configuration saved.");