cleanup markup in some plugins, make nsfw generate dijit widgets

This commit is contained in:
Andrew Dolgov 2021-02-16 22:07:37 +03:00
parent 89e8176c69
commit 0fc783e2b3
5 changed files with 82 additions and 90 deletions

View File

@ -19,6 +19,10 @@
return button_tag($value, "submit", array_merge(["class" => "alt-primary"], $attributes)); return button_tag($value, "submit", array_merge(["class" => "alt-primary"], $attributes));
} }
function cancel_dialog_tag(string $value, array $attributes = []) {
return button_tag($value, "", array_merge(["onclick" => "App.dialogOf(this).hide()"], $attributes));
}
function select_tag(string $name, $value, array $values, array $attributes = [], string $id = "") { function select_tag(string $name, $value, array $values, array $attributes = [], string $id = "") {
$attributes_str = attributes_to_string($attributes); $attributes_str = attributes_to_string($attributes);
$dojo_type = strpos($attributes_str, "dojoType") === false ? "dojoType='fox.form.Select'" : ""; $dojo_type = strpos($attributes_str, "dojoType") === false ? "dojoType='fox.form.Select'" : "";

View File

@ -42,19 +42,18 @@ class Note extends Plugin {
print \Controls\hidden_tag("method", "setNote"); print \Controls\hidden_tag("method", "setNote");
print \Controls\hidden_tag("plugin", "note"); print \Controls\hidden_tag("plugin", "note");
print "<textarea dojoType='dijit.form.SimpleTextarea' ?>
<textarea dojoType='dijit.form.SimpleTextarea'
style='font-size : 12px; width : 98%; height: 100px;' style='font-size : 12px; width : 98%; height: 100px;'
name='note'>$note</textarea>"; name='note'><?= $note ?></textarea>
<?php
} }
?>
print "<footer class='text-center'>"; <footer class='text-center'>
print "<button dojoType=\"dijit.form.Button\" <?= \Controls\submit_tag(__('Save')) ?>
onclick=\"dijit.byId('editNoteDlg').execute()\">".__('Save')."</button> "; <?= \Controls\cancel_dialog_tag(__('Cancel')) ?>
print "<button dojoType=\"dijit.form.Button\" </footer>
onclick=\"dijit.byId('editNoteDlg').hide()\">".__('Cancel')."</button>"; <?php
print "</footer>";
} }
function setNote() { function setNote() {

View File

@ -1,7 +1,12 @@
function nsfwShow(elem) { /* global Plugins */
let content = elem.parentNode.getElementsBySelector("div.nswf.content")[0];
if (content) { Plugins.NSFW = {
Element.toggle(content); toggle: function(elem) {
const content = elem.domNode.parentNode.querySelector(".nswf.content");
if (content) {
Element.toggle(content);
}
} }
} }

View File

@ -27,74 +27,64 @@ class NSFW extends Plugin {
$a_tags = array_map("trim", explode(",", $article["tag_cache"])); $a_tags = array_map("trim", explode(",", $article["tag_cache"]));
if (count(array_intersect($tags, $a_tags)) > 0) { 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> $article["content"] = "<div class='nswf wrapper'>".
<div class='nswf content' style='display : none'>".$article["content"]."</div></div>"; \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; return $article;
} }
function hook_render_article_cdm($article) { function hook_render_article_cdm($article) {
$tags = array_map("trim", explode(",", $this->host->get($this, "tags"))); return $this->hook_render_article($article);
$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;
} }
function hook_prefs_tab($args) { function hook_prefs_tab($args) {
if ($args != "prefPrefs") return; 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"); $tags = $this->host->get($this, "tags");
print "<form dojoType=\"dijit.form.Form\">"; ?>
<div dojoType="dijit.layout.AccordionPane"
title="<i class='material-icons'>extension</i> <?= __("NSFW Plugin") ?>">
<form dojoType="dijit.form.Form">
print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\"> <?= \Controls\hidden_tag("op", "pluginhandler") ?>
evt.preventDefault(); <?= \Controls\hidden_tag("method", "save") ?>
if (this.validate()) { <?= \Controls\hidden_tag("plugin", "nsfw") ?>
new Ajax.Request('backend.php', {
parameters: dojo.objectToQuery(this.getValues()), <script type="dojo/method" event="onSubmit" args="evt">
onComplete: function(transport) { evt.preventDefault();
Notify.info(transport.responseText); if (this.validate()) {
new Ajax.Request('backend.php', {
parameters: dojo.objectToQuery(this.getValues()),
onComplete: function(transport) {
Notify.info(transport.responseText);
}
});
} }
}); </script>
//this.reset();
}
</script>";
print \Controls\hidden_tag("op", "pluginhandler"); <header><?= __("Tags to consider NSFW (comma-separated):") ?></header>
print \Controls\hidden_tag("method", "save");
print \Controls\hidden_tag("plugin", "nsfw");
print "<table width=\"100%\" class=\"prefPrefsList\">"; <fieldset>
<textarea dojoType='dijit.form.SimpleTextarea' rows='4'
style='width: 500px; font-size : 12px;'
name='tags'><?= $tags ?></textarea>
</fieldset>
print "<tr><td width=\"40%\">".__("Tags to consider NSFW (comma-separated)")."</td>"; <hr/>
print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\" name=\"tags\" value=\"$tags\"></td></tr>";
print "</table>"; <?= \Controls\submit_tag(__("Save")) ?>
</form>
print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">". </div>
__("Save")."</button>"; <?php
print "</form>";
print "</div>"; #pane
} }
function save() { function save() {
$tags = explode(",", $_POST["tags"]); $tags = implode(", ",
$tags = array_map("trim", $tags); FeedItem_Common::normalize_categories(explode(",", $_POST["tags"] ?? "")));
$tags = array_map("mb_strtolower", $tags);
$tags = join(", ", $tags);
$this->host->set($this, "tags", $tags); $this->host->set($this, "tags", $tags);

View File

@ -41,14 +41,14 @@ class Share extends Plugin {
function hook_prefs_tab_section($id) { function hook_prefs_tab_section($id) {
if ($id == "prefFeedsPublishedGenerated") { if ($id == "prefFeedsPublishedGenerated") {
?>
<hr/>
print "<hr/>"; <h2><?= __("You can disable all articles shared by unique URLs here.") ?></h2>
print "<h2>" . __("You can disable all articles shared by unique URLs here.") . "</h2>";
print "<button class='alt-danger' dojoType='dijit.form.Button' onclick=\"return Plugins.Share.clearKeys()\">".
__('Unshare all articles')."</button> ";
<button class='alt-danger' dojoType='dijit.form.Button' onclick="return Plugins.Share.clearKeys()">
<?= __('Unshare all articles') ?></button>
<?php
} }
} }
@ -100,39 +100,33 @@ class Share extends Plugin {
$sth->execute([$uuid, $param, $_SESSION['uid']]); $sth->execute([$uuid, $param, $_SESSION['uid']]);
} }
print "<header>" . __("You can share this article by the following unique URL:") . "</header>"; $url_path = htmlspecialchars(get_self_url_prefix() . "/public.php?op=share&key=$uuid");
$url_path = get_self_url_prefix(); ?>
$url_path .= "/public.php?op=share&key=$uuid";
print "<section> <header><?= __("You can share this article by the following unique URL:") ?></header>
<section>
<div class='panel text-center'> <div class='panel text-center'>
<a id='gen_article_url' href='$url_path' target='_blank' rel='noopener noreferrer'>$url_path</a> <a id='gen_article_url' href="<?= $url_path ?>"
target='_blank' rel='noopener noreferrer'><?= $url_path ?></a>
</div> </div>
</section>"; </section>
/* if (!label_find_id(__('Shared'), $_SESSION["uid"]))
label_create(__('Shared'), $_SESSION["uid"]);
label_add_article($ref_id, __('Shared'), $_SESSION['uid']); */
<?php
} else { } else {
print "Article not found."; print "Article not found.";
} }
print "<footer class='text-center'>"; ?>
<footer class='text-center'>
print "<button dojoType='dijit.form.Button' onclick=\"return App.dialogOf(this).unshare()\">". <?= \Controls\button_tag(__('Unshare article'), '', ['class' => 'alt-danger', 'onclick' => "App.dialogOf(this).unshare()"]) ?>
__('Unshare article')."</button>"; <?= \Controls\button_tag(__('Generate new URL'), '', ['onclick' => "App.dialogOf(this).newurl()"]) ?>
<?= \Controls\submit_tag(__("Close this window")) ?>
print "<button dojoType='dijit.form.Button' onclick=\"return App.dialogOf(this).newurl()\">". </footer>
__('Generate new URL')."</button>"; <?php
print "<button dojoType='dijit.form.Button' type='submit' class='alt-primary'>".
__('Close this window')."</button>";
print "</footer>";
} }
function api_version() { function api_version() {