diff options
author | Andrew Dolgov <[email protected]> | 2021-02-24 21:56:52 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2021-02-24 21:56:52 +0300 |
commit | 93940d2a9f80d9e1dac49b5eb7db23230d31c5f6 (patch) | |
tree | 71016661f6017918d0934eb462bd9552018d557a /plugins/nsfw | |
parent | 8b022c2bfb356d7dddaf334bc931d6dec77086fb (diff) | |
parent | 1adacd057230aea4ede29dab510385bf01cf99a3 (diff) |
Merge branch 'master' of git.fakecake.org:fox/tt-rss into weblate-integration
Diffstat (limited to 'plugins/nsfw')
-rw-r--r-- | plugins/nsfw/init.js | 13 | ||||
-rw-r--r-- | plugins/nsfw/init.php | 80 |
2 files changed, 42 insertions, 51 deletions
diff --git a/plugins/nsfw/init.js b/plugins/nsfw/init.js index adb6d43c0..4bc2443e8 100644 --- a/plugins/nsfw/init.js +++ b/plugins/nsfw/init.js @@ -1,7 +1,12 @@ -function nsfwShow(elem) { - let content = elem.parentNode.getElementsBySelector("div.nswf.content")[0]; +/* global Plugins */ - if (content) { - Element.toggle(content); +Plugins.NSFW = { + toggle: function(elem) { + const content = elem.domNode.parentNode.querySelector(".nswf.content"); + + if (content) { + Element.toggle(content); + } } } + diff --git a/plugins/nsfw/init.php b/plugins/nsfw/init.php index 02344eb14..7c5b8d00f 100644 --- a/plugins/nsfw/init.php +++ b/plugins/nsfw/init.php @@ -19,7 +19,7 @@ class NSFW extends Plugin { } function get_js() { - return file_get_contents(dirname(__FILE__) . "/init.js"); + return file_get_contents(__DIR__ . "/init.js"); } function hook_render_article($article) { @@ -27,74 +27,60 @@ class NSFW extends Plugin { $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>"; + $article["content"] = "<div class='nswf wrapper'>". + \Controls\button_tag(__("Not work safe (click to toggle)"), '', ['onclick' => 'Plugins.NSFW.toggle(this)']). + "<div class='nswf content' style='display : none'>".$article["content"]."</div> + </div>"; } return $article; } function hook_render_article_cdm($article) { - $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>"; - } - - return $article; + return $this->hook_render_article($article); } function hook_prefs_tab($args) { if ($args != "prefPrefs") return; - print "<div dojoType=\"dijit.layout.AccordionPane\" - title=\"<i class='material-icons'>extension</i> ".__("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"); + ?> + <div dojoType="dijit.layout.AccordionPane" + title="<i class='material-icons'>extension</i> <?= __("NSFW Plugin") ?>"> + <form dojoType="dijit.form.Form"> - print "<table width=\"100%\" class=\"prefPrefsList\">"; + <?= \Controls\pluginhandler_tags($this, "save") ?> - 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>"; + <script type="dojo/method" event="onSubmit" args="evt"> + evt.preventDefault(); + if (this.validate()) { + Notify.progress('Saving data...', true); + xhr.post("backend.php", this.getValues(), (reply) => { + Notify.info(reply); + }) + } + </script> - print "</table>"; + <header><?= __("Tags to consider NSFW (comma-separated):") ?></header> - print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">". - __("Save")."</button>"; + <fieldset> + <textarea dojoType='dijit.form.SimpleTextarea' rows='4' + style='width: 500px; font-size : 12px;' + name='tags'><?= $tags ?></textarea> + </fieldset> - print "</form>"; + <hr/> - print "</div>"; #pane + <?= \Controls\submit_tag(__("Save")) ?> + </form> + </div> + <?php } function save() { - $tags = explode(",", $_POST["tags"]); - $tags = array_map("trim", $tags); - $tags = array_map("mb_strtolower", $tags); - $tags = join(", ", $tags); + $tags = implode(", ", + FeedItem_Common::normalize_categories(explode(",", $_POST["tags"] ?? ""))); $this->host->set($this, "tags", $tags); |