From 2b2833bb4fa6f958b89a83adea89d9e7c73daee7 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 17 Feb 2021 14:56:36 +0300 Subject: plugins: load dialogs via xhr instead of http --- plugins/note/note.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'plugins/note/note.js') diff --git a/plugins/note/note.js b/plugins/note/note.js index ab2ed9208..215058b21 100644 --- a/plugins/note/note.js +++ b/plugins/note/note.js @@ -1,11 +1,8 @@ -/* global Plugins, xhrJson, Notify, fox, __ */ +/* global dojo, xhrPost, Plugins, xhrJson, Notify, fox, __ */ Plugins.Note = { edit: function(id) { - const query = "backend.php?op=pluginhandler&plugin=note&method=edit¶m=" + encodeURIComponent(id); - const dialog = new fox.SingleUseDialog({ - id: "editNoteDlg", title: __("Edit article note"), execute: function () { if (this.validate()) { @@ -30,7 +27,15 @@ Plugins.Note = { }); } }, - href: query, + content: __("Loading, please wait...") + }); + + const tmph = dojo.connect(dialog, 'onShow', function () { + dojo.disconnect(tmph); + + xhrPost("backend.php", {op: "pluginhandler", plugin: "note", method: "edit", id: id}, (transport) => { + dialog.attr('content', transport.responseText); + }); }); dialog.show(); -- cgit v1.2.3-54-g00ecf From e4609c18efceebb1e021d814f53061ada7f6489a Mon Sep 17 00:00:00 2001 From: Andrew Dolgov 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/note/note.js') 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 {
- - - + @@ -351,16 +351,16 @@ class Pref_Prefs extends Handler_Protected { evt.preventDefault(); if (this.validate()) { Notify.progress('Saving data...', true); - xhrPost("backend.php", this.getValues(), (transport) => { + xhr.post("backend.php", this.getValues(), (reply) => { Notify.close(); - if (transport.responseText.indexOf('ERROR: ') == 0) { + if (reply.indexOf('ERROR: ') == 0) { App.byId('pwd_change_infobox').innerHTML = - transport.responseText.replace('ERROR: ', ''); + reply.replace('ERROR: ', ''); } else { App.byId('pwd_change_infobox').innerHTML = - transport.responseText.replace('ERROR: ', ''); + reply.replace('ERROR: ', ''); const warn = App.byId('default_pass_warning'); if (warn) Element.hide(warn); @@ -456,11 +456,11 @@ class Pref_Prefs extends Handler_Protected { evt.preventDefault(); if (this.validate()) { Notify.progress('Saving data...', true); - xhrPost("backend.php", this.getValues(), (transport) => { + xhr.post("backend.php", this.getValues(), (reply) => { Notify.close(); - if (transport.responseText.indexOf('ERROR: ') == 0) { - Notify.error(transport.responseText.replace('ERROR: ', '')); + if (reply.indexOf('ERROR: ') == 0) { + Notify.error(reply.replace('ERROR: ', '')); } else { window.location.reload(); } @@ -515,11 +515,11 @@ class Pref_Prefs extends Handler_Protected { evt.preventDefault(); if (this.validate()) { Notify.progress('Saving data...', true); - xhrPost("backend.php", this.getValues(), (transport) => { + xhr.post("backend.php", this.getValues(), (reply) => { Notify.close(); - if (transport.responseText.indexOf('ERROR:') == 0) { - Notify.error(transport.responseText.replace('ERROR:', '')); + if (reply.indexOf('ERROR:') == 0) { + Notify.error(reply.replace('ERROR:', '')); } else { window.location.reload(); } @@ -797,16 +797,14 @@ class Pref_Prefs extends Handler_Protected { @@ -1023,8 +1021,8 @@ class Pref_Prefs extends Handler_Protected { diff --git a/classes/rpc.php b/classes/rpc.php index 0fd06da4d..c4a1887c7 100755 --- a/classes/rpc.php +++ b/classes/rpc.php @@ -64,6 +64,14 @@ class RPC extends Handler_Protected { print json_encode(array("message" => "UPDATE_COUNTERS")); } + function getRuntimeInfo() { + $reply = [ + 'runtime-info' => $this->make_runtime_info() + ]; + + print json_encode($reply); + } + function getAllCounters() { @$seq = (int) $_REQUEST['seq']; diff --git a/js/App.js b/js/App.js index 1b0fa7c65..544057101 100644 --- a/js/App.js +++ b/js/App.js @@ -2,7 +2,7 @@ /* eslint-disable new-cap */ /* global __, Article, Headlines, Filters, fox */ -/* global xhrPost, xhr, dojo, dijit, PluginHost, Notify, Feeds, Cookie */ +/* global xhr, dojo, dijit, PluginHost, Notify, Feeds, Cookie */ /* global CommonDialogs, Plugins */ const App = { @@ -371,72 +371,57 @@ const App = { dialog.show(); }); }, - handleRpcJson: function(transport) { + handleRpcJson: function(reply) { - const netalert = App.findAll("#toolbar .net-alert")[0]; + const netalert = App.find(".net-alert"); - try { - const reply = JSON.parse(transport.responseText); - - if (reply) { - const error = reply['error']; - - if (error) { - const code = error['code']; - const msg = error['message']; - - console.warn("[handleRpcJson] received fatal error ", code, msg); - - if (code != 0) { - /* global ERRORS */ - this.Error.fatal(ERRORS[code], {info: msg, code: code}); - return false; - } - } + if (reply) { + const error = reply['error']; + const seq = reply['seq']; + const message = reply['message']; + const counters = reply['counters']; + const runtime_info = reply['runtime-info']; - const seq = reply['seq']; + if (error) { + const code = error['code']; - if (seq && this.get_seq() != seq) { - console.log("[handleRpcJson] sequence mismatch: ", seq, '!=', this.get_seq()); - return true; - } - - const message = reply['message']; - - if (message == "UPDATE_COUNTERS") { - console.log("need to refresh counters..."); - Feeds.requestCounters(true); - } + if (code && code != 0) { + const msg = error['message']; - const counters = reply['counters']; + console.warn("[handleRpcJson] received fatal error ", code, msg); - if (counters) - Feeds.parseCounters(counters); - - const runtime_info = reply['runtime-info']; - - if (runtime_info) - this.parseRuntimeInfo(runtime_info); + /* global ERRORS */ + this.Error.fatal(ERRORS[code], {info: msg, code: code}); + return false; + } + } - if (netalert) netalert.hide(); + if (seq && this.get_seq() != seq) { + console.warn("[handleRpcJson] sequence mismatch: ", seq, '!=', this.get_seq()); + return; + } - return reply; + // not in preferences + if (typeof Feeds != "undefined") { + if (message == "UPDATE_COUNTERS") { + console.log("need to refresh counters..."); + Feeds.requestCounters(true); + } - } else { - if (netalert) netalert.show(); + if (counters) + Feeds.parseCounters(counters); + } - Notify.error("Communication problem with server."); - } + if (runtime_info) + this.parseRuntimeInfo(runtime_info); - } catch (e) { - if (netalert) netalert.show(); + if (netalert) netalert.hide(); - Notify.error("Communication problem with server."); + } else { + if (netalert) netalert.show(); - console.error(e); + Notify.error("Communication problem with server."); } - - return false; }, parseRuntimeInfo: function(data) { Object.keys(data).forEach((k) => { @@ -450,7 +435,7 @@ const App = { } if (k == "recent_log_events") { - const alert = App.findAll(".log-alert")[0]; + const alert = App.find(".log-alert"); if (alert) { v > 0 ? alert.show() : alert.hide(); @@ -462,10 +447,12 @@ const App = { return; } - if (k == "max_feed_id" || k == "num_feeds") { - if (this.getInitParam(k) != v) { - console.log("feed count changed, need to reload feedlist."); - Feeds.reload(); + if (typeof Feeds != "undefined") { + if (k == "max_feed_id" || k == "num_feeds") { + if (this.getInitParam(k) && this.getInitParam(k) != v) { + console.log("feed count changed, need to reload feedlist:", this.getInitParam(k), v); + Feeds.reload(); + } } } @@ -668,6 +655,11 @@ const App = { return errorMsg == ""; }, + updateRuntimeInfo: function() { + xhr.json("backend.php", {op: "rpc", method: "getruntimeinfo"}, () => { + // handled by xhr.json() + }); + }, initSecondStage: function() { document.onkeydown = (event) => this.hotkeyHandler(event); @@ -685,14 +677,18 @@ const App = { if (tab) { dijit.byId("pref-tabs").selectChild(tab); - switch (this.urlParam('method')) { - case "editfeed": - window.setTimeout(() => { - CommonDialogs.editFeed(this.urlParam('methodparam')) - }, 100); - break; - default: - console.warn("initSecondStage, unknown method:", this.urlParam("method")); + const method = this.urlParam("method"); + + if (method) { + switch (method) { + case "editfeed": + window.setTimeout(() => { + CommonDialogs.editFeed(this.urlParam('methodparam')) + }, 100); + break; + default: + console.warn("initSecondStage, unknown method:", method); + } } } } else { @@ -708,8 +704,14 @@ const App = { dojo.connect(dijit.byId("pref-tabs"), "selectChild", function (elem) { localStorage.setItem("ttrss:prefs-tab", elem.id); + App.updateRuntimeInfo(); }); + if (!this.getInitParam("bw_limit")) + window.setInterval(() => { + App.updateRuntimeInfo(); + }, 60 * 1000) + } else { Feeds.reload(); diff --git a/js/CommonDialogs.js b/js/CommonDialogs.js index 516da5c98..a75b36ed8 100644 --- a/js/CommonDialogs.js +++ b/js/CommonDialogs.js @@ -430,8 +430,8 @@ const CommonDialogs = { const tmph = dojo.connect(dialog, 'onShow', function () { dojo.disconnect(tmph); - xhrPost("backend.php", {op: "pref-feeds", method: "editfeed", id: feed}, (transport) => { - dialog.attr('content', transport.responseText); + xhr.post("backend.php", {op: "pref-feeds", method: "editfeed", id: feed}, (reply) => { + dialog.attr('content', reply); }) }); diff --git a/js/CommonFilters.js b/js/CommonFilters.js index 9cc93d7b8..0fc8f87ae 100644 --- a/js/CommonFilters.js +++ b/js/CommonFilters.js @@ -39,12 +39,12 @@ const Filters = { createNewRuleElement: function(parentNode, replaceNode) { const rule = dojo.formToJson("filter_new_rule_form"); - xhrPost("backend.php", {op: "pref-filters", method: "printrulename", rule: rule}, (transport) => { + xhr.post("backend.php", {op: "pref-filters", method: "printrulename", rule: rule}, (reply) => { try { const li = document.createElement('li'); li.innerHTML = ` - ${transport.responseText} + ${reply} ${App.FormFields.hidden_tag("rule[]", rule)}`; dojo.parser.parse(li); @@ -70,12 +70,12 @@ const Filters = { const action = dojo.formToJson(form); - xhrPost("backend.php", { op: "pref-filters", method: "printactionname", action: action }, (transport) => { + xhr.post("backend.php", { op: "pref-filters", method: "printactionname", action: action }, (reply) => { try { const li = document.createElement('li'); li.innerHTML = ` - ${transport.responseText} + ${reply} ${App.FormFields.hidden_tag("action[]", action)}`; dojo.parser.parse(li); @@ -107,8 +107,8 @@ const Filters = { const tmph = dojo.connect(dialog, "onShow", null, function (/* e */) { dojo.disconnect(tmph); - xhrPost("backend.php", {op: 'pref-filters', method: 'newrule', rule: ruleStr}, (transport) => { - dialog.attr('content', transport.responseText); + xhr.post("backend.php", {op: 'pref-filters', method: 'newrule', rule: ruleStr}, (reply) => { + dialog.attr('content', reply); }); }); @@ -128,8 +128,8 @@ const Filters = { const tmph = dojo.connect(dialog, "onShow", null, function (/* e */) { dojo.disconnect(tmph); - xhrPost("backend.php", {op: 'pref-filters', method: 'newaction', action: actionStr}, (transport) => { - dialog.attr('content', transport.responseText); + xhr.post("backend.php", {op: 'pref-filters', method: 'newaction', action: actionStr}, (reply) => { + dialog.attr('content', reply); }); }); @@ -149,10 +149,8 @@ const Filters = { console.log("getTestResults:" + offset); - xhrPost("backend.php", params, (transport) => { + xhr.json("backend.php", params, (result) => { try { - const result = JSON.parse(transport.responseText); - if (result && dialog && dialog.open) { dialog.results += result.length; @@ -239,7 +237,7 @@ const Filters = { console.log('Filters.edit', query); - xhrPost("backend.php", query, function (transport) { + xhr.post("backend.php", query, function (reply) { try { const dialog = new fox.SingleUseDialog({ id: "filterEditDlg", @@ -311,7 +309,7 @@ const Filters = { }); } }, - content: transport.responseText + content: reply }); if (!App.isPrefs()) { @@ -334,9 +332,7 @@ const Filters = { const query = {op: "article", method: "getmetadatabyid", id: Article.getActive()}; - xhrPost("backend.php", query, (transport) => { - const reply = JSON.parse(transport.responseText); - + xhr.json("backend.php", query, (reply) => { let title = false; if (reply && reply.title) title = reply.title; diff --git a/js/Feeds.js b/js/Feeds.js index e9681953e..01d31f3c1 100644 --- a/js/Feeds.js +++ b/js/Feeds.js @@ -130,8 +130,8 @@ const Feeds = { this.reloadCurrent(); }, requestCounters: function() { - xhrPost("backend.php", {op: "rpc", method: "getAllCounters", seq: App.next_seq()}, (transport) => { - App.handleRpcJson(transport); + xhr.json("backend.php", {op: "rpc", method: "getAllCounters", seq: App.next_seq()}, () => { + // }); }, reload: function() { @@ -260,7 +260,7 @@ const Feeds = { // bw_limit disables timeout() so we request initial counters separately if (App.getInitParam("bw_limit")) { - this.requestCounters(true); + App.requestCounters(true); } else { setTimeout(() => { this.requestCounters(true); @@ -361,8 +361,6 @@ const Feeds = { query.m = "ForceUpdate"; } - //Form.enable("toolbar-main"); - if (!delayed) if (!this.setExpando(feed, is_cat, (is_cat) ? 'images/indicator_tiny.gif' : 'images/indicator_white.gif')) @@ -374,11 +372,11 @@ const Feeds = { window.clearTimeout(this._viewfeed_wait_timeout); this._viewfeed_wait_timeout = window.setTimeout(() => { - xhrPost("backend.php", query, (transport) => { + xhr.json("backend.php", query, (reply) => { try { window.clearTimeout(this._infscroll_timeout); this.setExpando(feed, is_cat, 'images/blank_icon.gif'); - Headlines.onLoaded(transport, offset, append); + Headlines.onLoaded(reply, offset, append); PluginHost.run(PluginHost.HOOK_FEED_LOADED, [feed, is_cat]); } catch (e) { App.Error.report(e); @@ -439,9 +437,7 @@ const Feeds = { Notify.progress("Loading, please wait...", true); - xhrPost("backend.php", catchup_query, (transport) => { - App.handleRpcJson(transport); - + xhr.json("backend.php", catchup_query, () => { const show_next_feed = App.getInitParam("on_catchup_show_next_feed"); // only select next unread feed if catching up entirely (as opposed to last week etc) @@ -633,8 +629,8 @@ const Feeds = { updateRandom: function() { console.log("in update_random_feed"); - xhrPost("backend.php", {op: "rpc", method: "updaterandomfeed"}, (transport) => { - App.handleRpcJson(transport, true); + xhr.json("backend.php", {op: "rpc", method: "updaterandomfeed"}, () => { + // }); }, }; diff --git a/js/Headlines.js b/js/Headlines.js index 34dc9385e..18e0a3687 100755 --- a/js/Headlines.js +++ b/js/Headlines.js @@ -1,7 +1,7 @@ 'use strict'; /* global __, ngettext, Article, App */ -/* global xhrPost, dojo, dijit, PluginHost, Notify, $$, Feeds */ +/* global dojo, dijit, PluginHost, Notify, xhr, Feeds */ /* global CommonDialogs */ const Headlines = { @@ -149,26 +149,26 @@ const Headlines = { const promises = []; if (ops.tmark.length != 0) - promises.push(xhrPost("backend.php", + promises.push(xhr.post("backend.php", {op: "rpc", method: "markSelected", ids: ops.tmark.toString(), cmode: 2})); if (ops.tpub.length != 0) - promises.push(xhrPost("backend.php", + promises.push(xhr.post("backend.php", {op: "rpc", method: "publishSelected", ids: ops.tpub.toString(), cmode: 2})); if (ops.read.length != 0) - promises.push(xhrPost("backend.php", + promises.push(xhr.post("backend.php", {op: "rpc", method: "catchupSelected", ids: ops.read.toString(), cmode: 0})); if (ops.unread.length != 0) - promises.push(xhrPost("backend.php", + promises.push(xhr.post("backend.php", {op: "rpc", method: "catchupSelected", ids: ops.unread.toString(), cmode: 1})); const scores = Object.keys(ops.rescore); if (scores.length != 0) { scores.forEach((score) => { - promises.push(xhrPost("backend.php", + promises.push(xhr.post("backend.php", {op: "article", method: "setScore", id: ops.rescore[score].toString(), score: score})); }); } @@ -622,9 +622,7 @@ const Headlines = { dojo.parser.parse(target.domNode); }, - onLoaded: function (transport, offset, append) { - const reply = App.handleRpcJson(transport); - + onLoaded: function (reply, offset, append) { console.log("Headlines.onLoaded: offset=", offset, "append=", append); let is_cat = false; @@ -785,7 +783,6 @@ const Headlines = { }); } else { - console.error("Invalid object received: " + transport.responseText); dijit.byId("headlines-frame").attr('content', "
" + __('Could not update headlines (invalid object received - see error console for details)') + "
"); @@ -1011,9 +1008,8 @@ const Headlines = { ids: ids.toString(), lid: id }; - xhrPost("backend.php", query, (transport) => { - App.handleRpcJson(transport); - this.onLabelsUpdated(transport); + xhr.json("backend.php", query, (reply) => { + this.onLabelsUpdated(reply); }); }, selectionAssignLabel: function (id, ids) { @@ -1029,9 +1025,8 @@ const Headlines = { ids: ids.toString(), lid: id }; - xhrPost("backend.php", query, (transport) => { - App.handleRpcJson(transport); - this.onLabelsUpdated(transport); + xhr.json("backend.php", query, (reply) => { + this.onLabelsUpdated(reply); }); }, deleteSelection: function () { @@ -1060,8 +1055,7 @@ const Headlines = { const query = {op: "rpc", method: "delete", ids: rows.toString()}; - xhrPost("backend.php", query, (transport) => { - App.handleRpcJson(transport); + xhr.json("backend.php", query, () => { Feeds.reloadCurrent(); }); }, @@ -1246,9 +1240,7 @@ const Headlines = { } } }, - onLabelsUpdated: function (transport) { - const data = JSON.parse(transport.responseText); - + onLabelsUpdated: function (data) { if (data) { data['info-for-headlines'].forEach(function (elem) { App.findAll(".HLLCTR-" + elem.id).forEach(function (ctr) { diff --git a/js/PrefFeedTree.js b/js/PrefFeedTree.js index d3a4cd33d..a2a7f9141 100644 --- a/js/PrefFeedTree.js +++ b/js/PrefFeedTree.js @@ -129,8 +129,8 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dojo/_b const searchElem = App.byId("feed_search"); const search = (searchElem) ? searchElem.value : ""; - xhrPost("backend.php", { op: "pref-feeds", search: search }, (transport) => { - dijit.byId('feedsTab').attr('content', transport.responseText); + xhr.post("backend.php", { op: "pref-feeds", search: search }, (reply) => { + dijit.byId('feedsTab').attr('content', reply); Notify.close(); }); }, @@ -295,7 +295,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dojo/_b Notify.progress("Loading, please wait..."); - xhrPost("backend.php", {op: "pref-feeds", method: "editfeeds", ids: rows.toString()}, (transport) => { + xhr.post("backend.php", {op: "pref-feeds", method: "editfeeds", ids: rows.toString()}, (reply) => { Notify.close(); try { @@ -347,7 +347,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dojo/_b }); } }, - content: transport.responseText + content: reply }); dialog.show(); diff --git a/js/PrefFilterTree.js b/js/PrefFilterTree.js index cc37808be..fff58ff1a 100644 --- a/js/PrefFilterTree.js +++ b/js/PrefFilterTree.js @@ -1,5 +1,5 @@ /* eslint-disable prefer-rest-params */ -/* global __, define, lib, dijit, dojo, xhr, Notify */ +/* global __, define, lib, dijit, dojo, xhr, App, Notify */ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], function (declare, domConstruct) { @@ -91,8 +91,8 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio let search = ""; if (user_search) { search = user_search.value; } - xhrPost("backend.php", { op: "pref-filters", search: search }, (transport) => { - dijit.byId('filtersTab').attr('content', transport.responseText); + xhr.post("backend.php", { op: "pref-filters", search: search }, (reply) => { + dijit.byId('filtersTab').attr('content', reply); Notify.close(); }); }, diff --git a/js/PrefHelpers.js b/js/PrefHelpers.js index abf5fff51..d27e0e071 100644 --- a/js/PrefHelpers.js +++ b/js/PrefHelpers.js @@ -19,8 +19,8 @@ const Helpers = { alert("No passwords selected."); } else if (confirm(__("Remove selected app passwords?"))) { - xhrPost("backend.php", {op: "pref-prefs", method: "deleteAppPassword", ids: rows.toString()}, (transport) => { - this.updateContent(transport.responseText); + xhr.post("backend.php", {op: "pref-prefs", method: "deleteAppPassword", ids: rows.toString()}, (reply) => { + this.updateContent(reply); Notify.close(); }); @@ -31,8 +31,8 @@ const Helpers = { const title = prompt("Password description:") if (title) { - xhrPost("backend.php", {op: "pref-prefs", method: "generateAppPassword", title: title}, (transport) => { - this.updateContent(transport.responseText); + xhr.post("backend.php", {op: "pref-prefs", method: "generateAppPassword", title: title}, (reply) => { + this.updateContent(reply); Notify.close(); }); @@ -63,8 +63,13 @@ const Helpers = { this.update(); }, update: function() { - xhrPost("backend.php", { op: "pref-system", severity: dijit.byId("severity").attr('value'), page: Helpers.EventLog.log_page }, (transport) => { - dijit.byId('systemTab').attr('content', transport.responseText); + xhr.post("backend.php", { + op: "pref-system", + severity: dijit.byId("severity").attr('value'), + page: Helpers.EventLog.log_page + }, (reply) => { + + dijit.byId('systemTab').attr('content', reply); Notify.close(); }); }, @@ -164,8 +169,8 @@ const Helpers = { `${profile.title} @@ -267,9 +272,9 @@ const Helpers = { }, confirmReset: function() { if (confirm(__("Reset to defaults?"))) { - xhrPost("backend.php", {op: "pref-prefs", method: "resetconfig"}, (transport) => { + xhr.post("backend.php", {op: "pref-prefs", method: "resetconfig"}, (reply) => { Helpers.Prefs.refresh(); - Notify.info(transport.responseText); + Notify.info(reply); }); } }, @@ -283,8 +288,8 @@ const Helpers = { } }, refresh: function() { - xhrPost("backend.php", { op: "pref-prefs" }, (transport) => { - dijit.byId('prefsTab').attr('content', transport.responseText); + xhr.post("backend.php", { op: "pref-prefs" }, (reply) => { + dijit.byId('prefsTab').attr('content', reply); Notify.close(); }); }, diff --git a/js/PrefLabelTree.js b/js/PrefLabelTree.js index 5e024afde..627b2cfbe 100644 --- a/js/PrefLabelTree.js +++ b/js/PrefLabelTree.js @@ -55,8 +55,8 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dijit/f return rv; }, reload: function() { - xhrPost("backend.php", { op: "pref-labels" }, (transport) => { - dijit.byId('labelsTab').attr('content', transport.responseText); + xhr.post("backend.php", { op: "pref-labels" }, (reply) => { + dijit.byId('labelsTab').attr('content', reply); Notify.close(); }); }, diff --git a/js/PrefUsers.js b/js/PrefUsers.js index 9b9c1deaf..3eb83b02a 100644 --- a/js/PrefUsers.js +++ b/js/PrefUsers.js @@ -8,8 +8,8 @@ const Users = { const user_search = App.byId("user_search"); const search = user_search ? user_search.value : ""; - xhrPost("backend.php", { op: "pref-users", sort: sort, search: search }, (transport) => { - dijit.byId('usersTab').attr('content', transport.responseText); + xhr.post("backend.php", { op: "pref-users", sort: sort, search: search }, (reply) => { + dijit.byId('usersTab').attr('content', reply); Notify.close(); }); }, @@ -19,8 +19,8 @@ const Users = { if (login) { Notify.progress("Adding user..."); - xhrPost("backend.php", {op: "pref-users", method: "add", login: login}, (transport) => { - alert(transport.responseText); + xhr.post("backend.php", {op: "pref-users", method: "add", login: login}, (reply) => { + alert(reply); Users.reload(); }); @@ -99,8 +99,8 @@ const Users = {
@@ -141,9 +141,9 @@ const Users = { const id = rows[0]; - xhrPost("backend.php", {op: "pref-users", method: "resetPass", id: id}, (transport) => { + xhr.post("backend.php", {op: "pref-users", method: "resetPass", id: id}, (reply) => { Notify.close(); - Notify.info(transport.responseText, true); + Notify.info(reply, true); }); } diff --git a/js/common.js b/js/common.js index 1c9a0453c..e88b62602 100755 --- a/js/common.js +++ b/js/common.js @@ -155,7 +155,7 @@ const xhr = { reject(error); }, load: function(data, ioargs) { - //console.log('xhr.post', '<<<', data, ioargs); + console.log('xhr.post', '<<<', ioargs.xhr); if (complete != undefined) complete(data, ioargs.xhr); @@ -179,6 +179,9 @@ const xhr = { console.log('xhr.json', '<<<', obj); + if (obj && typeof App != "undefined") + App.handleRpcJson(obj); + if (complete != undefined) complete(obj); resolve(obj); diff --git a/js/prefs.js b/js/prefs.js index 803a7edf3..a23a74856 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -41,6 +41,7 @@ require(["dojo/_base/kernel", "dojo/data/ItemFileWriteStore", "lib/CheckBoxStoreModel", "lib/CheckBoxTree", + "fox/PluginHost", "fox/CommonDialogs", "fox/CommonFilters", "fox/PrefUsers", diff --git a/plugins/af_proxy_http/init.php b/plugins/af_proxy_http/init.php index 2c472a32d..a5ba1d62d 100644 --- a/plugins/af_proxy_http/init.php +++ b/plugins/af_proxy_http/init.php @@ -221,8 +221,8 @@ class Af_Proxy_Http extends Plugin { diff --git a/plugins/af_psql_trgm/init.js b/plugins/af_psql_trgm/init.js index e5bc21885..921272c4b 100644 --- a/plugins/af_psql_trgm/init.js +++ b/plugins/af_psql_trgm/init.js @@ -1,4 +1,4 @@ -/* global dijit, dojo, Plugins, xhrPost, __ */ +/* global dijit, dojo, Plugins, xhr, __ */ Plugins.Psql_Trgm = { showRelated: function (id) { @@ -10,8 +10,8 @@ Plugins.Psql_Trgm = { const tmph = dojo.connect(dialog, "onShow", null, function (/* e */) { dojo.disconnect(tmph); - xhrPost("backend.php", {op: 'pluginhandler', plugin: 'af_psql_trgm', method: 'showrelated', id: id}, (transport) => { - dialog.attr('content', transport.responseText); + xhr.post("backend.php", {op: 'pluginhandler', plugin: 'af_psql_trgm', method: 'showrelated', id: id}, (reply) => { + dialog.attr('content', reply); }); }); diff --git a/plugins/af_psql_trgm/init.php b/plugins/af_psql_trgm/init.php index 4ecfe0cd5..3b7ed6b14 100644 --- a/plugins/af_psql_trgm/init.php +++ b/plugins/af_psql_trgm/init.php @@ -152,8 +152,8 @@ class Af_Psql_Trgm extends Plugin { evt.preventDefault(); if (this.validate()) { Notify.progress('Saving data...', true); - xhrPost("backend.php", this.getValues(), (transport) => { - Notify.info(transport.responseText); + xhr.post("backend.php", this.getValues(), (reply) => { + Notify.info(reply); }) } diff --git a/plugins/af_readability/init.php b/plugins/af_readability/init.php index 4cd72904a..be9220cda 100755 --- a/plugins/af_readability/init.php +++ b/plugins/af_readability/init.php @@ -71,8 +71,8 @@ class Af_Readability extends Plugin { evt.preventDefault(); if (this.validate()) { Notify.progress('Saving data...', true); - xhrPost("backend.php", this.getValues(), (transport) => { - Notify.info(transport.responseText); + xhr.post("backend.php", this.getValues(), (reply) => { + Notify.info(reply); }) } diff --git a/plugins/af_redditimgur/init.php b/plugins/af_redditimgur/init.php index 827a4c310..2677fdd90 100755 --- a/plugins/af_redditimgur/init.php +++ b/plugins/af_redditimgur/init.php @@ -47,8 +47,8 @@ class Af_RedditImgur extends Plugin { evt.preventDefault(); if (this.validate()) { Notify.progress('Saving data...', true); - xhrPost("backend.php", this.getValues(), (transport) => { - Notify.info(transport.responseText); + xhr.post("backend.php", this.getValues(), (reply) => { + Notify.info(reply); }) } diff --git a/plugins/mail/init.php b/plugins/mail/init.php index 16e22f342..467f8294a 100644 --- a/plugins/mail/init.php +++ b/plugins/mail/init.php @@ -51,8 +51,8 @@ class Mail extends Plugin { evt.preventDefault(); if (this.validate()) { Notify.progress('Saving data...', true); - xhrPost("backend.php", this.getValues(), (transport) => { - Notify.info(transport.responseText); + xhr.post("backend.php", this.getValues(), (reply) => { + Notify.info(reply); }) } diff --git a/plugins/mail/mail.js b/plugins/mail/mail.js index fc0898085..d2bafe0e9 100644 --- a/plugins/mail/mail.js +++ b/plugins/mail/mail.js @@ -1,4 +1,4 @@ -/* global Plugins, Headlines, dojo, xhrPost, xhrJson, Notify, fox, __ */ +/* global Plugins, Headlines, dojo, App, xhr, Notify, fox, __ */ Plugins.Mail = { send: function(id) { @@ -38,8 +38,8 @@ Plugins.Mail = { const tmph = dojo.connect(dialog, 'onShow', function () { dojo.disconnect(tmph); - xhrPost("backend.php", App.getPhArgs("mail", "emailArticle", {ids: id}), (transport) => { - dialog.attr('content', transport.responseText); + xhr.post("backend.php", App.getPhArgs("mail", "emailArticle", {ids: id}), (reply) => { + dialog.attr('content', reply); }); }); diff --git a/plugins/mailto/init.js b/plugins/mailto/init.js index b5e68680b..4a9557249 100644 --- a/plugins/mailto/init.js +++ b/plugins/mailto/init.js @@ -1,4 +1,4 @@ -/* global Plugins, Headlines, xhrPost, dojo, fox, __ */ +/* global Plugins, Headlines, xhr, dojo, fox, __ */ Plugins.Mailto = { send: function (id) { @@ -21,8 +21,8 @@ Plugins.Mailto = { const tmph = dojo.connect(dialog, 'onShow', function () { dojo.disconnect(tmph); - xhrPost("backend.php", App.getPhArgs("mailto", "emailArticle", {ids: id}), (transport) => { - dialog.attr('content', transport.responseText); + xhr.post("backend.php", App.getPhArgs("mailto", "emailArticle", {ids: id}), (reply) => { + dialog.attr('content', reply); }); }); diff --git a/plugins/note/note.js b/plugins/note/note.js index 36bc426cd..d42fca2c1 100644 --- a/plugins/note/note.js +++ b/plugins/note/note.js @@ -1,4 +1,4 @@ -/* global dojo, xhrPost, Plugins, xhrJson, Notify, fox, __ */ +/* global dojo, Plugins, xhr, App, Notify, fox, __ */ Plugins.Note = { edit: function(id) { @@ -33,8 +33,8 @@ Plugins.Note = { const tmph = dojo.connect(dialog, 'onShow', function () { dojo.disconnect(tmph); - xhrPost("backend.php", App.getPhArgs("note", "edit", {id: id}), (transport) => { - dialog.attr('content', transport.responseText); + xhr.post("backend.php", App.getPhArgs("note", "edit", {id: id}), (reply) => { + dialog.attr('content', reply); }); }); diff --git a/plugins/nsfw/init.php b/plugins/nsfw/init.php index fdc6a3974..3205b436b 100644 --- a/plugins/nsfw/init.php +++ b/plugins/nsfw/init.php @@ -56,8 +56,8 @@ class NSFW extends Plugin { evt.preventDefault(); if (this.validate()) { Notify.progress('Saving data...', true); - xhrPost("backend.php", this.getValues(), (transport) => { - Notify.info(transport.responseText); + xhr.post("backend.php", this.getValues(), (reply) => { + Notify.info(reply); }) } diff --git a/plugins/share/share.js b/plugins/share/share.js index d7b8cd1f9..1be9db682 100644 --- a/plugins/share/share.js +++ b/plugins/share/share.js @@ -1,4 +1,4 @@ -/* global dojo, Effect, Plugins, xhrJson, Notify, fox, xhrPost, __ */ +/* global dojo, Plugins, App, Notify, fox, xhr, __ */ Plugins.Share = { shareArticle: function(id) { @@ -40,8 +40,8 @@ Plugins.Share = { }, unshare: function () { if (confirm(__("Remove sharing for this article?"))) { - xhrPost("backend.php", App.getPhArgs("share", "unshare", {id: id}), (transport) => { - Notify.info(transport.responseText); + xhr.post("backend.php", App.getPhArgs("share", "unshare", {id: id}), (reply) => { + Notify.info(reply); const icon = document.querySelector(".share-icon-" + id); @@ -59,8 +59,8 @@ Plugins.Share = { const tmph = dojo.connect(dialog, 'onShow', function () { dojo.disconnect(tmph); - xhrPost("backend.php", App.getPhArgs("share", "shareDialog", {id: id}), (transport) => { - dialog.attr('content', transport.responseText) + xhr.post("backend.php", App.getPhArgs("share", "shareDialog", {id: id}), (reply) => { + dialog.attr('content', reply) const icon = document.querySelector(".share-icon-" + id); diff --git a/plugins/share/share_prefs.js b/plugins/share/share_prefs.js index 91f979daf..d974af618 100644 --- a/plugins/share/share_prefs.js +++ b/plugins/share/share_prefs.js @@ -1,12 +1,12 @@ -/* global Plugins, Notify, xhrPost */ +/* global Plugins, Notify, xhr, App */ Plugins.Share = { clearKeys: function() { if (confirm(__("This will invalidate all previously shared article URLs. Continue?"))) { Notify.progress("Clearing URLs..."); - xhrPost("backend.php", App.getPhArgs("share", "clearArticleKeys"), (transport) => { - Notify.info(transport.responseText); + xhr.post("backend.php", App.getPhArgs("share", "clearArticleKeys"), (reply) => { + Notify.info(reply); }); } diff --git a/prefs.php b/prefs.php index 2b2af8452..d11c6281e 100644 --- a/prefs.php +++ b/prefs.php @@ -124,7 +124,10 @@
diff --git a/themes/compact.css b/themes/compact.css index 0116fa45b..e92db1659 100644 --- a/themes/compact.css +++ b/themes/compact.css @@ -754,6 +754,17 @@ body.ttrss_main #header { top: 0px; z-index: 5; } +body.ttrss_main #header i.net-alert, +body.ttrss_main #header .left i.icon-error { + color: red; +} +body.ttrss_main #header i.log-alert { + color: #ddba1c; + cursor: pointer; +} +body.ttrss_main #header i { + margin: 0 4px; +} body.ttrss_main #content-insert { padding: 0px; border-color: #ddd; diff --git a/themes/compact_night.css b/themes/compact_night.css index 2709cf196..42b850536 100644 --- a/themes/compact_night.css +++ b/themes/compact_night.css @@ -754,6 +754,17 @@ body.ttrss_main #header { top: 0px; z-index: 5; } +body.ttrss_main #header i.net-alert, +body.ttrss_main #header .left i.icon-error { + color: red; +} +body.ttrss_main #header i.log-alert { + color: #ddba1c; + cursor: pointer; +} +body.ttrss_main #header i { + margin: 0 4px; +} body.ttrss_main #content-insert { padding: 0px; border-color: #222; diff --git a/themes/light.css b/themes/light.css index 492daf08f..0b69ef84b 100644 --- a/themes/light.css +++ b/themes/light.css @@ -754,6 +754,17 @@ body.ttrss_main #header { top: 0px; z-index: 5; } +body.ttrss_main #header i.net-alert, +body.ttrss_main #header .left i.icon-error { + color: red; +} +body.ttrss_main #header i.log-alert { + color: #ddba1c; + cursor: pointer; +} +body.ttrss_main #header i { + margin: 0 4px; +} body.ttrss_main #content-insert { padding: 0px; border-color: #ddd; diff --git a/themes/light/tt-rss.less b/themes/light/tt-rss.less index 3cf1a2d5e..b1895f318 100644 --- a/themes/light/tt-rss.less +++ b/themes/light/tt-rss.less @@ -877,6 +877,19 @@ body.ttrss_main { right : 0px; top : 0px; z-index : 5; + + i.net-alert, .left i.icon-error { + color : red; + } + + i.log-alert { + color : #ddba1c; + cursor : pointer; + } + + i { + margin : 0 4px; + } } #content-insert { diff --git a/themes/night.css b/themes/night.css index a52ef701d..65484b82b 100644 --- a/themes/night.css +++ b/themes/night.css @@ -755,6 +755,17 @@ body.ttrss_main #header { top: 0px; z-index: 5; } +body.ttrss_main #header i.net-alert, +body.ttrss_main #header .left i.icon-error { + color: red; +} +body.ttrss_main #header i.log-alert { + color: #ddba1c; + cursor: pointer; +} +body.ttrss_main #header i { + margin: 0 4px; +} body.ttrss_main #content-insert { padding: 0px; border-color: #222; diff --git a/themes/night_blue.css b/themes/night_blue.css index 2a7debf35..1c16a6f22 100644 --- a/themes/night_blue.css +++ b/themes/night_blue.css @@ -755,6 +755,17 @@ body.ttrss_main #header { top: 0px; z-index: 5; } +body.ttrss_main #header i.net-alert, +body.ttrss_main #header .left i.icon-error { + color: red; +} +body.ttrss_main #header i.log-alert { + color: #ddba1c; + cursor: pointer; +} +body.ttrss_main #header i { + margin: 0 4px; +} body.ttrss_main #content-insert { padding: 0px; border-color: #222; -- cgit v1.2.3-54-g00ecf From d445530fa08cdbe2088150a3e7d23596eab9b142 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 19 Feb 2021 17:15:22 +0300 Subject: format note on the client --- classes/article.php | 15 --------------- classes/feeds.php | 5 ----- js/Article.js | 7 ++++++- js/Headlines.js | 2 +- js/common.js | 4 ++-- plugins/note/init.php | 9 +++------ plugins/note/note.js | 14 ++++++-------- 7 files changed, 18 insertions(+), 38 deletions(-) (limited to 'plugins/note/note.js') diff --git a/classes/article.php b/classes/article.php index 1e90c843e..e64c17a32 100755 --- a/classes/article.php +++ b/classes/article.php @@ -419,21 +419,6 @@ class Article extends Handler_Protected { return $tags; } - static function _format_note_html($id, $note, $allow_edit = true) { - if ($allow_edit) { - $onclick = "onclick='Plugins.Note.edit($id)'"; - $note_class = 'editable'; - } else { - $onclick = ''; - $note_class = ''; - } - - return "
- note -
$note
-
"; - } - function getmetadatabyid() { $id = clean($_REQUEST['id']); diff --git a/classes/feeds.php b/classes/feeds.php index 5ad21ded9..b95ade2f5 100755 --- a/classes/feeds.php +++ b/classes/feeds.php @@ -260,11 +260,6 @@ class Feeds extends Handler_Protected { $this->_mark_timestamp(" disk_cache_rewrite"); - if ($line['note']) - $line['note'] = Article::_format_note_html($id, $line['note']); - else - $line['note'] = ""; - $this->_mark_timestamp(" note"); if (!get_pref("CDM_EXPANDED")) { diff --git a/js/Article.js b/js/Article.js index 21973518c..d039882ec 100644 --- a/js/Article.js +++ b/js/Article.js @@ -130,6 +130,11 @@ const Article = { Headlines.toggleUnread(id, 0); }, + renderNote: function (id, note) { + return `
+ ${App.FormFields.icon('note')}
${note ? App.escapeHtml(note) : ""}
+
`; + }, renderTags: function (id, tags) { const tags_short = tags.length > 5 ? tags.slice(0, 5) : tags; @@ -300,7 +305,7 @@ const Article = {
${hl.buttons}
-
${hl.note}
+ ${Article.renderNote(hl.id, hl.note)}
${hl.content} ${Article.renderEnclosures(hl.enclosures)} diff --git a/js/Headlines.js b/js/Headlines.js index 9bc5747c2..60066164f 100755 --- a/js/Headlines.js +++ b/js/Headlines.js @@ -483,7 +483,7 @@ const Headlines = {
-
${hl.note}
+ ${Article.renderNote(hl.id, hl.note)}
diff --git a/js/common.js b/js/common.js index e88b62602..e616c70ba 100755 --- a/js/common.js +++ b/js/common.js @@ -71,9 +71,9 @@ Element.prototype.fadeOut = function() { }()); }; -Element.prototype.fadeIn = function(display){ +Element.prototype.fadeIn = function(display = undefined){ this.style.opacity = 0; - this.style.display = display || "block"; + this.style.display = display == undefined ? "block" : display; const self = this; (function fade() { diff --git a/plugins/note/init.php b/plugins/note/init.php index 278cfe6c3..f4bdf45bc 100644 --- a/plugins/note/init.php +++ b/plugins/note/init.php @@ -55,17 +55,14 @@ class Note extends Plugin { } function setNote() { - $id = $_REQUEST["id"]; - $note = trim(strip_tags($_REQUEST["note"])); + $id = (int)clean($_REQUEST["id"]); + $note = clean($_REQUEST["note"]); $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET note = ? WHERE ref_id = ? AND owner_uid = ?"); $sth->execute([$note, $id, $_SESSION['uid']]); - $formatted_note = Article::_format_note_html($id, $note); - - print json_encode(array("note" => $formatted_note, - "raw_length" => mb_strlen($note))); + print json_encode(["id" => $id, "note" => $note]); } function api_version() { diff --git a/plugins/note/note.js b/plugins/note/note.js index d42fca2c1..a46acb355 100644 --- a/plugins/note/note.js +++ b/plugins/note/note.js @@ -13,16 +13,14 @@ Plugins.Note = { dialog.hide(); if (reply) { - const elem = App.byId("POSTNOTE-" + id); + App.findAll(`div[data-note-for="${reply.id}"]`).forEach((elem) => { + elem.querySelector(".body").innerHTML = reply.note; - if (elem) { - elem.innerHTML = reply.note; - - if (reply.raw_length != 0) - Element.show(elem); + if (reply.note) + elem.show(); else - Element.hide(elem); - } + elem.hide(); + }); } }); } -- cgit v1.2.3-54-g00ecf