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