]>
Commit | Line | Data |
---|---|---|
1b9f9925 AD |
1 | <?php |
2 | class NSFW extends Plugin { | |
3 | ||
4 | private $link; | |
5 | private $host; | |
6 | ||
7 | function about() { | |
8 | return array(1.0, | |
cd616c4c | 9 | "Hide article content based on tags", |
1b9f9925 AD |
10 | "fox", |
11 | false); | |
12 | } | |
13 | ||
14 | function init($host) { | |
15 | $this->link = $host->get_link(); | |
16 | $this->host = $host; | |
17 | ||
18 | $host->add_hook($host::HOOK_RENDER_ARTICLE, $this); | |
19 | $host->add_hook($host::HOOK_RENDER_ARTICLE_CDM, $this); | |
cd616c4c | 20 | $host->add_hook($host::HOOK_PREFS_TAB, $this); |
1b9f9925 AD |
21 | |
22 | } | |
23 | ||
24 | function get_js() { | |
25 | return file_get_contents(dirname(__FILE__) . "/init.js"); | |
26 | } | |
27 | ||
28 | function hook_render_article($article) { | |
cd616c4c | 29 | $tags = array_map("trim", explode(", ", $this->host->get($this, "tags"))); |
1b9f9925 | 30 | |
cd616c4c | 31 | if (count(array_intersect($tags, $article["tags"])) > 0) { |
1b9f9925 AD |
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>"; | |
34 | } | |
35 | ||
36 | return $article; | |
37 | } | |
38 | ||
39 | function hook_render_article_cdm($article) { | |
cd616c4c AD |
40 | $tags = array_map("trim", explode(", ", $this->host->get($this, "tags"))); |
41 | ||
42 | if (count(array_intersect($tags, $article["tags"])) > 0) { | |
1b9f9925 AD |
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>"; | |
45 | } | |
46 | ||
47 | return $article; | |
48 | } | |
49 | ||
cd616c4c AD |
50 | function hook_prefs_tab($args) { |
51 | if ($args != "prefPrefs") return; | |
52 | ||
53 | print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__("NSFW Plugin")."\">"; | |
54 | ||
55 | print "<br/>"; | |
56 | ||
57 | $tags = $this->host->get($this, "tags"); | |
58 | ||
59 | print "<form dojoType=\"dijit.form.Form\">"; | |
60 | ||
61 | print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\"> | |
62 | evt.preventDefault(); | |
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); | |
68 | } | |
69 | }); | |
70 | //this.reset(); | |
71 | } | |
72 | </script>"; | |
73 | ||
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\">"; | |
77 | ||
78 | print "<table width=\"100%\" class=\"prefPrefsList\">"; | |
79 | ||
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>"; | |
82 | ||
83 | print "</table>"; | |
84 | ||
85 | print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">". | |
86 | __("Save")."</button>"; | |
87 | ||
88 | print "</form>"; | |
89 | ||
90 | print "</div>"; #pane | |
91 | } | |
92 | ||
93 | function save() { | |
3972bf59 | 94 | $tags = explode(",", db_escape_string($this->link, $_POST["tags"])); |
cd616c4c AD |
95 | $tags = array_map("trim", $tags); |
96 | $tags = array_map("mb_strtolower", $tags); | |
97 | $tags = join(", ", $tags); | |
98 | ||
99 | $this->host->set($this, "tags", $tags); | |
100 | ||
101 | echo __("Configuration saved."); | |
102 | } | |
103 | ||
1b9f9925 AD |
104 | } |
105 | ?> |