]> git.wh0rd.org - tt-rss.git/blobdiff - plugins/nsfw/init.php
oops, remove useless db_escape_string() in article class (and nsfw plugin)
[tt-rss.git] / plugins / nsfw / init.php
index fd274eadae59764430caa4abd253595ca68ae2c3..6a1ae3c65a23958c6a167ed43bb43603daa0b8e8 100644 (file)
@@ -1,22 +1,20 @@
 <?php
 class NSFW extends Plugin {
-
-       private $link;
        private $host;
 
        function about() {
                return array(1.0,
-                       "Hide article content if tags contain \"nsfw\"",
+                       "Hide article content based on tags",
                        "fox",
                        false);
        }
 
        function init($host) {
-               $this->link = $host->get_link();
                $this->host = $host;
 
                $host->add_hook($host::HOOK_RENDER_ARTICLE, $this);
                $host->add_hook($host::HOOK_RENDER_ARTICLE_CDM, $this);
+               $host->add_hook($host::HOOK_PREFS_TAB, $this);
 
        }
 
@@ -25,8 +23,10 @@ class NSFW extends Plugin {
        }
 
        function hook_render_article($article) {
+               $tags = array_map("trim", explode(",", $this->host->get($this, "tags")));
+               $a_tags = array_map("trim", explode(",", $article["tag_cache"]));
 
-               if (array_search("nsfw", $article["tags"]) !== FALSE) {
+               if (count(array_intersect($tags, $a_tags)) > 0) {
                        $article["content"] = "<div class='nswf wrapper'><button onclick=\"nsfwShow(this)\">".__("Not work safe (click to toggle)")."</button>
                                <div class='nswf content' style='display : none'>".$article["content"]."</div></div>";
                }
@@ -35,7 +35,10 @@ class NSFW extends Plugin {
        }
 
        function hook_render_article_cdm($article) {
-               if (array_search("nsfw", $article["tags"]) !== FALSE) {
+               $tags = array_map("trim", explode(",", $this->host->get($this, "tags")));
+               $a_tags = array_map("trim", explode(",", $article["tag_cache"]));
+
+               if (count(array_intersect($tags, $a_tags)) > 0) {
                        $article["content"] = "<div class='nswf wrapper'><button onclick=\"nsfwShow(this)\">".__("Not work safe (click to toggle)")."</button>
                                <div class='nswf content' style='display : none'>".$article["content"]."</div></div>";
                }
@@ -43,5 +46,62 @@ class NSFW extends Plugin {
                return $article;
        }
 
-}
-?>
+       function hook_prefs_tab($args) {
+               if ($args != "prefPrefs") return;
+
+               print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__("NSFW Plugin")."\">";
+
+               print "<br/>";
+
+               $tags = $this->host->get($this, "tags");
+
+               print "<form dojoType=\"dijit.form.Form\">";
+
+               print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
+                       evt.preventDefault();
+                       if (this.validate()) {
+                               new Ajax.Request('backend.php', {
+                                       parameters: dojo.objectToQuery(this.getValues()),
+                                       onComplete: function(transport) {
+                                               notify_info(transport.responseText);
+                                       }
+                               });
+                               //this.reset();
+                       }
+                       </script>";
+
+                       print_hidden("op", "pluginhandler");
+                       print_hidden("method", "save");
+                       print_hidden("plugin", "nsfw");
+
+                       print "<table width=\"100%\" class=\"prefPrefsList\">";
+
+                       print "<tr><td width=\"40%\">".__("Tags to consider NSFW (comma-separated)")."</td>";
+                       print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\" name=\"tags\" value=\"$tags\"></td></tr>";
+
+                       print "</table>";
+
+                       print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
+                               __("Save")."</button>";
+
+                       print "</form>";
+
+                       print "</div>"; #pane
+       }
+
+       function save() {
+               $tags = explode(",", $_POST["tags"]);
+               $tags = array_map("trim", $tags);
+               $tags = array_map("mb_strtolower", $tags);
+               $tags = join(", ", $tags);
+
+               $this->host->set($this, "tags", $tags);
+
+               echo __("Configuration saved.");
+       }
+
+       function api_version() {
+               return 2;
+       }
+
+}
\ No newline at end of file