From 1f43d7916cda16e9680b9087bda1f52934e8f25b Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 16 Feb 2021 14:32:06 +0300 Subject: replace print_hidden with hidden_tag --- plugins/nsfw/init.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'plugins/nsfw/init.php') diff --git a/plugins/nsfw/init.php b/plugins/nsfw/init.php index 02344eb14..1b27cc017 100644 --- a/plugins/nsfw/init.php +++ b/plugins/nsfw/init.php @@ -71,9 +71,9 @@ class NSFW extends Plugin { } "; - print_hidden("op", "pluginhandler"); - print_hidden("method", "save"); - print_hidden("plugin", "nsfw"); + print \Controls\hidden_tag("op", "pluginhandler"); + print \Controls\hidden_tag("method", "save"); + print \Controls\hidden_tag("plugin", "nsfw"); print ""; -- cgit v1.2.3-54-g00ecf From 0fc783e2b350b8ac6ff275fd9b201674cbcf2c16 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 16 Feb 2021 22:07:37 +0300 Subject: cleanup markup in some plugins, make nsfw generate dijit widgets --- include/controls.php | 4 +++ plugins/note/init.php | 21 ++++++------- plugins/nsfw/init.js | 13 +++++--- plugins/nsfw/init.php | 84 ++++++++++++++++++++++---------------------------- plugins/share/init.php | 52 ++++++++++++++----------------- 5 files changed, 83 insertions(+), 91 deletions(-) (limited to 'plugins/nsfw/init.php') diff --git a/include/controls.php b/include/controls.php index 78ff75572..4c60d94f3 100755 --- a/include/controls.php +++ b/include/controls.php @@ -19,6 +19,10 @@ 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 = "") { $attributes_str = attributes_to_string($attributes); $dojo_type = strpos($attributes_str, "dojoType") === false ? "dojoType='fox.form.Select'" : ""; diff --git a/plugins/note/init.php b/plugins/note/init.php index 0634d4c57..12c56f7ad 100644 --- a/plugins/note/init.php +++ b/plugins/note/init.php @@ -42,19 +42,18 @@ class Note extends Plugin { print \Controls\hidden_tag("method", "setNote"); print \Controls\hidden_tag("plugin", "note"); - print ""; - + name='note'> + "; - print " "; - print ""; - print ""; - + ?> +
+ + +
+ 0) { - $article["content"] = "
-
"; + $article["content"] = "
". + \Controls\button_tag(__("Not work safe (click to toggle)"), '', ['onclick' => 'Plugins.NSFW.toggle(this)']). + " +
"; } 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"] = "
-
"; - } - - return $article; + return $this->hook_render_article($article); } function hook_prefs_tab($args) { if ($args != "prefPrefs") return; - print "
extension ".__("NSFW Plugin")."\">"; - - print "
"; - $tags = $this->host->get($this, "tags"); - print "
"; - - print ""; - - print \Controls\hidden_tag("op", "pluginhandler"); - print \Controls\hidden_tag("method", "save"); - print \Controls\hidden_tag("plugin", "nsfw"); - - print "
"; - - print ""; - print ""; + - print "
".__("Tags to consider NSFW (comma-separated)")."
"; +
- print "

"; +

+ +
- print ""; +
- print ""; #pane + + + + host->set($this, "tags", $tags); diff --git a/plugins/share/init.php b/plugins/share/init.php index 42923ed8a..846e1f39c 100644 --- a/plugins/share/init.php +++ b/plugins/share/init.php @@ -41,14 +41,14 @@ class Share extends Plugin { function hook_prefs_tab_section($id) { if ($id == "prefFeedsPublishedGenerated") { + ?> +
- print "
"; - - print "

" . __("You can disable all articles shared by unique URLs here.") . "

"; - - print " "; +

+ + execute([$uuid, $param, $_SESSION['uid']]); } - print "
" . __("You can share this article by the following unique URL:") . "
"; + $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 "
-
- $url_path -
-
"; +
- /* if (!label_find_id(__('Shared'), $_SESSION["uid"])) - label_create(__('Shared'), $_SESSION["uid"]); - label_add_article($ref_id, __('Shared'), $_SESSION['uid']); */ +
+
+ +
+
+ "; - - print ""; - - print ""; - - print ""; - - print ""; + ?> + + Date: Wed, 17 Feb 2021 21:44:21 +0300 Subject: * add (disabled) shortcut syntax for plugin methods * add controls shortcut for pluginhandler tags * add similar shortcut for frontend * allow plugins to selectively exclude their methods from CSRF checking --- backend.php | 11 +++++++++++ classes/plugin.php | 4 ++++ classes/pluginhandler.php | 2 +- classes/pluginhost.php | 13 ++++++++++++- include/controls.php | 12 +++++++++++- js/App.js | 3 +++ plugins/af_proxy_http/init.php | 4 +--- plugins/af_psql_trgm/init.php | 4 +--- plugins/af_readability/init.js | 2 +- plugins/af_readability/init.php | 6 ++---- plugins/af_redditimgur/init.php | 9 +++++---- plugins/mail/init.php | 12 ++++-------- plugins/mail/mail.js | 2 +- plugins/mailto/init.js | 2 +- plugins/note/init.php | 4 +--- plugins/note/note.js | 2 +- plugins/nsfw/init.php | 4 +--- plugins/share/share.js | 8 +++----- plugins/share/share_prefs.js | 2 +- 19 files changed, 65 insertions(+), 41 deletions(-) (limited to 'plugins/nsfw/init.php') diff --git a/backend.php b/backend.php index 9ecc22914..e64c6561f 100644 --- a/backend.php +++ b/backend.php @@ -88,6 +88,17 @@ 5 => __("Power User"), 10 => __("Administrator")); + // shortcut syntax for plugin methods (?op=plugin--pmethod&...params) + /* if (strpos($op, PluginHost::PUBLIC_METHOD_DELIMITER) !== false) { + list ($plugin, $pmethod) = explode(PluginHost::PUBLIC_METHOD_DELIMITER, $op, 2); + + // TODO: better implementation that won't modify $_REQUEST + $_REQUEST["plugin"] = $plugin; + $method = $pmethod; + $op = "pluginhandler"; + } */ + + // TODO: figure out if is this still needed $op = str_replace("-", "_", $op); $override = PluginHost::getInstance()->lookup_handler($op, $method); diff --git a/classes/plugin.php b/classes/plugin.php index 2416418cd..6c572467a 100644 --- a/classes/plugin.php +++ b/classes/plugin.php @@ -54,4 +54,8 @@ abstract class Plugin { return vsprintf($this->__($msgid), $args); } + + function csrf_ignore($method) { + return false; + } } diff --git a/classes/pluginhandler.php b/classes/pluginhandler.php index a0e60b4e6..608f80dcb 100644 --- a/classes/pluginhandler.php +++ b/classes/pluginhandler.php @@ -11,7 +11,7 @@ class PluginHandler extends Handler_Protected { if ($plugin) { if (method_exists($plugin, $method)) { - if (validate_csrf($csrf_token)) { + if (validate_csrf($csrf_token) || $plugin->csrf_ignore($method)) { $plugin->$method(); } else { user_error("Rejected ${plugin_name}->${method}(): invalid CSRF token.", E_USER_WARNING); diff --git a/classes/pluginhost.php b/classes/pluginhost.php index 097bf987c..065fa99c4 100755 --- a/classes/pluginhost.php +++ b/classes/pluginhost.php @@ -611,6 +611,17 @@ class PluginHost { $params)); } + // shortcut syntax (disabled for now) + /* function get_method_url(Plugin $sender, string $method, $params) { + return get_self_url_prefix() . "/backend.php?" . + http_build_query( + array_merge( + [ + "op" => strtolower(get_class($sender) . self::PUBLIC_METHOD_DELIMITER . $method), + ], + $params)); + } */ + // WARNING: endpoint in public.php, exposed to unauthenticated users function get_public_method_url(Plugin $sender, string $method, $params) { if ($sender->is_public_method($method)) { @@ -618,7 +629,7 @@ class PluginHost { http_build_query( array_merge( [ - "op" => strtolower(get_class($sender) . PluginHost::PUBLIC_METHOD_DELIMITER . $method), + "op" => strtolower(get_class($sender) . self::PUBLIC_METHOD_DELIMITER . $method), ], $params)); } else { diff --git a/include/controls.php b/include/controls.php index 4c60d94f3..d8506877b 100755 --- a/include/controls.php +++ b/include/controls.php @@ -11,6 +11,17 @@ return $rv; } + // shortcut syntax (disabled) + /* function pluginhandler_tags(\Plugin $plugin, string $method) { + return hidden_tag("op", strtolower(get_class($plugin) . \PluginHost::PUBLIC_METHOD_DELIMITER . $method)); + } */ + + function pluginhandler_tags(\Plugin $plugin, string $method) { + return hidden_tag("op", "pluginhandler") . + hidden_tag("plugin", strtolower(get_class($plugin))) . + hidden_tag("method", $method); + } + function button_tag(string $value, string $type, array $attributes = []) { return ""; } @@ -155,4 +166,3 @@ return $ret; } - diff --git a/js/App.js b/js/App.js index 9d8f6c275..aeca688b7 100644 --- a/js/App.js +++ b/js/App.js @@ -101,6 +101,9 @@ const App = { return dijit.getEnclosingWidget(elem.closest('.dijitDialog')); }, + getPhArgs(plugin, method, args = {}) { + return {...{op: "pluginhandler", plugin: plugin, method: method}, ...args}; + }, label_to_feed_id: function(label) { return this.LABEL_BASE_INDEX - 1 - Math.abs(label); }, diff --git a/plugins/af_proxy_http/init.php b/plugins/af_proxy_http/init.php index 5804e450f..d6cee5fcd 100644 --- a/plugins/af_proxy_http/init.php +++ b/plugins/af_proxy_http/init.php @@ -229,9 +229,7 @@ class Af_Proxy_Http extends Plugin { } "; - print \Controls\hidden_tag("op", "pluginhandler"); - print \Controls\hidden_tag("method", "save"); - print \Controls\hidden_tag("plugin", "af_proxy_http"); + print \Controls\pluginhandler_tags($this, "save"); $proxy_all = sql_bool_to_bool($this->host->get($this, "proxy_all")); print \Controls\checkbox_tag("proxy_all", $proxy_all); diff --git a/plugins/af_psql_trgm/init.php b/plugins/af_psql_trgm/init.php index 1d83ce5e0..bfbbdf49c 100644 --- a/plugins/af_psql_trgm/init.php +++ b/plugins/af_psql_trgm/init.php @@ -157,9 +157,7 @@ class Af_Psql_Trgm extends Plugin { } "; - print \Controls\hidden_tag("op", "pluginhandler"); - print \Controls\hidden_tag("method", "save"); - print \Controls\hidden_tag("plugin", "af_psql_trgm"); + print \Controls\pluginhandler_tags($this, "save"); print "

" . __("Global settings") . "

"; diff --git a/plugins/af_readability/init.js b/plugins/af_readability/init.js index 3155475cc..ff2d94e8b 100644 --- a/plugins/af_readability/init.js +++ b/plugins/af_readability/init.js @@ -16,7 +16,7 @@ Plugins.Af_Readability = { Notify.progress("Loading, please wait..."); - xhrJson("backend.php",{ op: "pluginhandler", plugin: "af_readability", method: "embed", param: id }, (reply) => { + xhrJson("backend.php", App.getPhArgs("af_readability", "embed", {id: id}), (reply) => { if (content && reply.content) { content.setAttribute(self.orig_attr_name, content.innerHTML); diff --git a/plugins/af_readability/init.php b/plugins/af_readability/init.php index aeef8cddc..43d064fc7 100755 --- a/plugins/af_readability/init.php +++ b/plugins/af_readability/init.php @@ -67,9 +67,7 @@ class Af_Readability extends Plugin {
- - - +
@@ -350,32 +346,28 @@ class Pref_Prefs extends Handler_Protected { - @@ -459,23 +451,20 @@ class Pref_Prefs extends Handler_Protected { - @@ -521,22 +510,20 @@ class Pref_Prefs extends Handler_Protected {
- @@ -806,26 +793,23 @@ class Pref_Prefs extends Handler_Protected { - @@ -956,20 +940,15 @@ class Pref_Prefs extends Handler_Protected { ?> diff --git a/plugins/af_readability/init.php b/plugins/af_readability/init.php index 43d064fc7..a1f92815c 100755 --- a/plugins/af_readability/init.php +++ b/plugins/af_readability/init.php @@ -69,19 +69,15 @@ class Af_Readability extends Plugin { - +