]>
Commit | Line | Data |
---|---|---|
1b9f9925 AD |
1 | <?php |
2 | class NSFW extends Plugin { | |
1b9f9925 AD |
3 | private $host; |
4 | ||
5 | function about() { | |
6 | return array(1.0, | |
cd616c4c | 7 | "Hide article content based on tags", |
1b9f9925 AD |
8 | "fox", |
9 | false); | |
10 | } | |
11 | ||
12 | function init($host) { | |
1b9f9925 AD |
13 | $this->host = $host; |
14 | ||
15 | $host->add_hook($host::HOOK_RENDER_ARTICLE, $this); | |
16 | $host->add_hook($host::HOOK_RENDER_ARTICLE_CDM, $this); | |
cd616c4c | 17 | $host->add_hook($host::HOOK_PREFS_TAB, $this); |
1b9f9925 AD |
18 | |
19 | } | |
20 | ||
21 | function get_js() { | |
22 | return file_get_contents(dirname(__FILE__) . "/init.js"); | |
23 | } | |
24 | ||
25 | function hook_render_article($article) { | |
838b3744 AD |
26 | $tags = array_map("trim", explode(",", $this->host->get($this, "tags"))); |
27 | $a_tags = array_map("trim", explode(",", $article["tag_cache"])); | |
1b9f9925 | 28 | |
445d1c10 | 29 | if (count(array_intersect($tags, $a_tags)) > 0) { |
1b9f9925 AD |
30 | $article["content"] = "<div class='nswf wrapper'><button onclick=\"nsfwShow(this)\">".__("Not work safe (click to toggle)")."</button> |
31 | <div class='nswf content' style='display : none'>".$article["content"]."</div></div>"; | |
32 | } | |
33 | ||
34 | return $article; | |
35 | } | |
36 | ||
37 | function hook_render_article_cdm($article) { | |
838b3744 AD |
38 | $tags = array_map("trim", explode(",", $this->host->get($this, "tags"))); |
39 | $a_tags = array_map("trim", explode(",", $article["tag_cache"])); | |
cd616c4c | 40 | |
445d1c10 | 41 | if (count(array_intersect($tags, $a_tags)) > 0) { |
1b9f9925 AD |
42 | $article["content"] = "<div class='nswf wrapper'><button onclick=\"nsfwShow(this)\">".__("Not work safe (click to toggle)")."</button> |
43 | <div class='nswf content' style='display : none'>".$article["content"]."</div></div>"; | |
44 | } | |
45 | ||
46 | return $article; | |
47 | } | |
48 | ||
cd616c4c AD |
49 | function hook_prefs_tab($args) { |
50 | if ($args != "prefPrefs") return; | |
51 | ||
52 | print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__("NSFW Plugin")."\">"; | |
53 | ||
54 | print "<br/>"; | |
55 | ||
56 | $tags = $this->host->get($this, "tags"); | |
57 | ||
58 | print "<form dojoType=\"dijit.form.Form\">"; | |
59 | ||
60 | print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\"> | |
61 | evt.preventDefault(); | |
62 | if (this.validate()) { | |
63 | new Ajax.Request('backend.php', { | |
64 | parameters: dojo.objectToQuery(this.getValues()), | |
65 | onComplete: function(transport) { | |
66 | notify_info(transport.responseText); | |
67 | } | |
68 | }); | |
69 | //this.reset(); | |
70 | } | |
71 | </script>"; | |
72 | ||
73 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pluginhandler\">"; | |
74 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"save\">"; | |
75 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"plugin\" value=\"nsfw\">"; | |
76 | ||
77 | print "<table width=\"100%\" class=\"prefPrefsList\">"; | |
78 | ||
79 | print "<tr><td width=\"40%\">".__("Tags to consider NSFW (comma-separated)")."</td>"; | |
80 | print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\" name=\"tags\" value=\"$tags\"></td></tr>"; | |
81 | ||
82 | print "</table>"; | |
83 | ||
84 | print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">". | |
85 | __("Save")."</button>"; | |
86 | ||
87 | print "</form>"; | |
88 | ||
89 | print "</div>"; #pane | |
90 | } | |
91 | ||
92 | function save() { | |
a42c55f0 | 93 | $tags = explode(",", db_escape_string($_POST["tags"])); |
cd616c4c AD |
94 | $tags = array_map("trim", $tags); |
95 | $tags = array_map("mb_strtolower", $tags); | |
96 | $tags = join(", ", $tags); | |
97 | ||
98 | $this->host->set($this, "tags", $tags); | |
99 | ||
100 | echo __("Configuration saved."); | |
101 | } | |
102 | ||
106a3de9 AD |
103 | function api_version() { |
104 | return 2; | |
105 | } | |
106 | ||
1b9f9925 AD |
107 | } |
108 | ?> |