2013-02-23 12:02:29 +00:00
|
|
|
<?php
|
|
|
|
class NSFW extends Plugin {
|
|
|
|
private $host;
|
|
|
|
|
|
|
|
function about() {
|
|
|
|
return array(1.0,
|
2013-02-23 17:28:09 +00:00
|
|
|
"Hide article content based on tags",
|
2013-02-23 12:02:29 +00:00
|
|
|
"fox",
|
|
|
|
false);
|
|
|
|
}
|
|
|
|
|
|
|
|
function init($host) {
|
|
|
|
$this->host = $host;
|
|
|
|
|
|
|
|
$host->add_hook($host::HOOK_RENDER_ARTICLE, $this);
|
|
|
|
$host->add_hook($host::HOOK_RENDER_ARTICLE_CDM, $this);
|
2013-02-23 17:28:09 +00:00
|
|
|
$host->add_hook($host::HOOK_PREFS_TAB, $this);
|
2013-02-23 12:02:29 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_js() {
|
|
|
|
return file_get_contents(dirname(__FILE__) . "/init.js");
|
|
|
|
}
|
|
|
|
|
|
|
|
function hook_render_article($article) {
|
2013-06-05 06:27:53 +00:00
|
|
|
$tags = array_map("trim", explode(",", $this->host->get($this, "tags")));
|
|
|
|
$a_tags = array_map("trim", explode(",", $article["tag_cache"]));
|
2013-02-23 12:02:29 +00:00
|
|
|
|
2013-06-04 11:34:04 +00:00
|
|
|
if (count(array_intersect($tags, $a_tags)) > 0) {
|
2021-02-16 19:07:37 +00:00
|
|
|
$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>";
|
2013-02-23 12:02:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $article;
|
|
|
|
}
|
|
|
|
|
|
|
|
function hook_render_article_cdm($article) {
|
2021-02-16 19:07:37 +00:00
|
|
|
return $this->hook_render_article($article);
|
2013-02-23 12:02:29 +00:00
|
|
|
}
|
|
|
|
|
2013-02-23 17:28:09 +00:00
|
|
|
function hook_prefs_tab($args) {
|
|
|
|
if ($args != "prefPrefs") return;
|
|
|
|
|
|
|
|
$tags = $this->host->get($this, "tags");
|
|
|
|
|
2021-02-16 19:07:37 +00:00
|
|
|
?>
|
|
|
|
<div dojoType="dijit.layout.AccordionPane"
|
|
|
|
title="<i class='material-icons'>extension</i> <?= __("NSFW Plugin") ?>">
|
|
|
|
<form dojoType="dijit.form.Form">
|
|
|
|
|
|
|
|
<?= \Controls\hidden_tag("op", "pluginhandler") ?>
|
|
|
|
<?= \Controls\hidden_tag("method", "save") ?>
|
|
|
|
<?= \Controls\hidden_tag("plugin", "nsfw") ?>
|
|
|
|
|
|
|
|
<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);
|
|
|
|
}
|
|
|
|
});
|
2013-02-23 17:28:09 +00:00
|
|
|
}
|
2021-02-16 19:07:37 +00:00
|
|
|
</script>
|
2013-02-23 17:28:09 +00:00
|
|
|
|
2021-02-16 19:07:37 +00:00
|
|
|
<header><?= __("Tags to consider NSFW (comma-separated):") ?></header>
|
2013-02-23 17:28:09 +00:00
|
|
|
|
2021-02-16 19:07:37 +00:00
|
|
|
<fieldset>
|
|
|
|
<textarea dojoType='dijit.form.SimpleTextarea' rows='4'
|
|
|
|
style='width: 500px; font-size : 12px;'
|
|
|
|
name='tags'><?= $tags ?></textarea>
|
|
|
|
</fieldset>
|
2013-02-23 17:28:09 +00:00
|
|
|
|
2021-02-16 19:07:37 +00:00
|
|
|
<hr/>
|
2013-02-23 17:28:09 +00:00
|
|
|
|
2021-02-16 19:07:37 +00:00
|
|
|
<?= \Controls\submit_tag(__("Save")) ?>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
<?php
|
2013-02-23 17:28:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function save() {
|
2021-02-16 19:07:37 +00:00
|
|
|
$tags = implode(", ",
|
|
|
|
FeedItem_Common::normalize_categories(explode(",", $_POST["tags"] ?? "")));
|
2013-02-23 17:28:09 +00:00
|
|
|
|
|
|
|
$this->host->set($this, "tags", $tags);
|
|
|
|
|
|
|
|
echo __("Configuration saved.");
|
|
|
|
}
|
|
|
|
|
2013-04-19 13:31:56 +00:00
|
|
|
function api_version() {
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
2017-04-26 17:57:36 +00:00
|
|
|
}
|