]> git.wh0rd.org - tt-rss.git/blob - plugins/nsfw/init.php
Merge pull request #68 from gvmelle/master
[tt-rss.git] / plugins / nsfw / init.php
1 <?php
2 class NSFW extends Plugin {
3
4 private $link;
5 private $host;
6
7 function about() {
8 return array(1.0,
9 "Hide article content based on tags",
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);
20 $host->add_hook($host::HOOK_PREFS_TAB, $this);
21
22 }
23
24 function get_js() {
25 return file_get_contents(dirname(__FILE__) . "/init.js");
26 }
27
28 function hook_render_article($article) {
29 $tags = array_map("trim", explode(", ", $this->host->get($this, "tags")));
30
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>";
34 }
35
36 return $article;
37 }
38
39 function hook_render_article_cdm($article) {
40 $tags = array_map("trim", explode(", ", $this->host->get($this, "tags")));
41
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>";
45 }
46
47 return $article;
48 }
49
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() {
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);
98
99 $this->host->set($this, "tags", $tags);
100
101 echo __("Configuration saved.");
102 }
103
104 }
105 ?>