4 let _label_base_index = -1024;
5 let loading_progress = 0;
6 let notify_hide_timerid = false;
8 Ajax.Base.prototype.initialize = Ajax.Base.prototype.initialize.wrap(
9 function (callOriginal, options) {
11 if (getInitParam("csrf_token") != undefined) {
12 Object.extend(options, options || { });
14 if (Object.isString(options.parameters))
15 options.parameters = options.parameters.toQueryParams();
16 else if (Object.isHash(options.parameters))
17 options.parameters = options.parameters.toObject();
19 options.parameters["csrf_token"] = getInitParam("csrf_token");
22 return callOriginal(options);
26 /* xhr shorthand helpers */
28 function xhrPost(url, params, complete) {
29 console.log("xhrPost:", params);
30 new Ajax.Request(url, {
36 function xhrJson(url, params, complete) {
37 xhrPost(url, params, (reply) => {
39 const obj = JSON.parse(reply.responseText);
42 console.error("xhrJson", e, reply);
49 /* add method to remove element from array */
51 Array.prototype.remove = function(s) {
52 for (let i=0; i < this.length; i++) {
53 if (s == this[i]) this.splice(i, 1);
57 function report_error(message, filename, lineno, colno, error) {
58 exception_error(error, null, filename, lineno);
61 function exception_error(e, e_compat, filename, lineno, colno) {
62 if (typeof e == "string") e = e_compat;
64 if (!e) return; // no exception object, nothing to report.
68 const msg = e.toString();
71 xhrPost("backend.php",
72 {op: "rpc", method: "log",
73 file: e.fileName ? e.fileName : filename,
74 line: e.lineNumber ? e.lineNumber : lineno,
75 msg: msg, context: e.stack},
77 console.warn(transport.responseText);
81 console.error("Exception while trying to log the error.", e);
84 let content = "<div class='fatalError'><p>" + msg + "</p>";
87 content += "<div><b>Stack trace:</b></div>" +
88 "<textarea name=\"stack\" readonly=\"1\">" + e.stack + "</textarea>";
93 content += "<div class='dlgButtons'>";
95 content += "<button dojoType=\"dijit.form.Button\" "+
96 "onclick=\"dijit.byId('exceptionDlg').hide()\">" +
97 __('Close') + "</button>";
100 if (dijit.byId("exceptionDlg"))
101 dijit.byId("exceptionDlg").destroyRecursive();
103 const dialog = new dijit.Dialog({
105 title: "Unhandled exception",
106 style: "width: 600px",
112 console.error("Exception while trying to report an exception:", ei);
113 console.error("Original exception:", e);
115 alert("Exception occured while trying to report an exception.\n" +
116 ei.stack + "\n\nOriginal exception:\n" + e.stack);
121 function param_escape(arg) {
122 return encodeURIComponent(arg);
125 function notify_real(msg, no_hide, n_type) {
127 const n = $("notify");
131 if (notify_hide_timerid) {
132 window.clearTimeout(notify_hide_timerid);
136 if (n.hasClassName("visible")) {
137 notify_hide_timerid = window.setTimeout(function() {
138 n.removeClassName("visible") }, 0);
152 msg = "<span class=\"msg\"> " + __(msg) + "</span>";
155 msg = "<span><img src=\""+getInitParam("icon_indicator_white")+"\"></span>" + msg;
157 } else if (n_type == 3) {
158 msg = "<span><img src=\""+getInitParam("icon_alert")+"\"></span>" + msg;
159 } else if (n_type == 4) {
160 msg = "<span><img src=\""+getInitParam("icon_information")+"\"></span>" + msg;
163 msg += " <span><img src=\""+getInitParam("icon_cross")+"\" class=\"close\" title=\"" +
164 __("Click to close") + "\" onclick=\"notify('')\"></span>";
168 window.setTimeout(function() {
171 n.className = "notify notify_progress visible";
172 } else if (n_type == 3) {
173 n.className = "notify notify_error visible";
174 msg = "<span><img src='images/alert.png'></span>" + msg;
175 } else if (n_type == 4) {
176 n.className = "notify notify_info visible";
178 n.className = "notify visible";
182 notify_hide_timerid = window.setTimeout(function() {
183 n.removeClassName("visible") }, 5*1000);
190 function notify(msg, no_hide) {
191 notify_real(msg, no_hide, 1);
194 function notify_progress(msg, no_hide) {
195 notify_real(msg, no_hide, 2);
198 function notify_error(msg, no_hide) {
199 notify_real(msg, no_hide, 3);
203 function notify_info(msg, no_hide) {
204 notify_real(msg, no_hide, 4);
207 function setCookie(name, value, lifetime, path, domain, secure) {
213 d.setTime(d.getTime() + (lifetime * 1000));
216 console.log("setCookie: " + name + " => " + value + ": " + d);
218 int_setCookie(name, value, d, path, domain, secure);
222 function int_setCookie(name, value, expires, path, domain, secure) {
223 document.cookie= name + "=" + escape(value) +
224 ((expires) ? "; expires=" + expires.toGMTString() : "") +
225 ((path) ? "; path=" + path : "") +
226 ((domain) ? "; domain=" + domain : "") +
227 ((secure) ? "; secure" : "");
230 function delCookie(name, path, domain) {
231 if (getCookie(name)) {
232 document.cookie = name + "=" +
233 ((path) ? ";path=" + path : "") +
234 ((domain) ? ";domain=" + domain : "" ) +
235 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
240 function getCookie(name) {
242 const dc = document.cookie;
243 const prefix = name + "=";
244 let begin = dc.indexOf("; " + prefix);
246 begin = dc.indexOf(prefix);
247 if (begin != 0) return null;
252 let end = document.cookie.indexOf(";", begin);
256 return unescape(dc.substring(begin + prefix.length, end));
259 function gotoPreferences() {
260 document.location.href = "prefs.php";
263 function gotoLogout() {
264 document.location.href = "backend.php?op=logout";
267 function gotoMain() {
268 document.location.href = "index.php";
271 function toggleSelectRowById(sender, id) {
273 return toggleSelectRow(sender, row);
276 /* this is for dijit Checkbox */
277 function toggleSelectListRow2(sender) {
278 const row = sender.domNode.parentNode;
279 return toggleSelectRow(sender, row);
282 /* this is for dijit Checkbox */
283 function toggleSelectRow2(sender, row, is_cdm) {
287 row = sender.domNode.parentNode.parentNode;
289 row = sender.domNode.parentNode.parentNode.parentNode; // oh ffs
291 if (sender.checked && !row.hasClassName('Selected'))
292 row.addClassName('Selected');
294 row.removeClassName('Selected');
296 if (typeof updateSelectedPrompt != undefined)
297 updateSelectedPrompt();
301 function toggleSelectRow(sender, row) {
303 if (!row) row = sender.parentNode.parentNode;
305 if (sender.checked && !row.hasClassName('Selected'))
306 row.addClassName('Selected');
308 row.removeClassName('Selected');
310 if (typeof updateSelectedPrompt != undefined)
311 updateSelectedPrompt();
314 function checkboxToggleElement(elem, id) {
316 Effect.Appear(id, {duration : 0.5});
318 Effect.Fade(id, {duration : 0.5});
322 function getURLParam(param){
323 return String(window.location.href).parseQuery()[param];
326 function closeInfoBox() {
327 const dialog = dijit.byId("infoBox");
329 if (dialog) dialog.hide();
335 function displayDlg(title, id, param, callback) {
337 notify_progress("Loading, please wait...", true);
339 const query = { op: "dlg", method: id, param: param };
341 xhrPost("backend.php", query, (transport) => {
342 infobox_callback2(transport, title);
343 if (callback) callback(transport);
349 function infobox_callback2(transport, title) {
352 if (dijit.byId("infoBox")) {
353 dialog = dijit.byId("infoBox");
356 //console.log("infobox_callback2");
359 const content = transport.responseText;
362 dialog = new dijit.Dialog({
365 style: "width: 600px",
366 onCancel: function() {
369 onExecute: function() {
372 onClose: function() {
377 dialog.attr('title', title);
378 dialog.attr('content', content);
386 function getInitParam(key) {
387 return init_params[key];
390 function setInitParam(key, value) {
391 init_params[key] = value;
394 function fatalError(code, msg, ext_info) {
396 window.location.href = "index.php";
397 } else if (code == 5) {
398 window.location.href = "public.php?op=dbupdate";
401 if (msg == "") msg = "Unknown error";
404 if (ext_info.responseText) {
405 ext_info = ext_info.responseText;
409 if (ERRORS && ERRORS[code] && !msg) {
413 let content = "<div><b>Error code:</b> " + code + "</div>" +
414 "<p>" + msg + "</p>";
417 content = content + "<div><b>Additional information:</b></div>" +
418 "<textarea style='width: 100%' readonly=\"1\">" +
419 ext_info + "</textarea>";
422 const dialog = new dijit.Dialog({
423 title: "Fatal error",
424 style: "width: 600px",
435 function filterDlgCheckAction(sender) {
436 const action = sender.value;
438 const action_param = $("filterDlg_paramBox");
441 console.log("filterDlgCheckAction: can't find action param box!");
445 // if selected action supports parameters, enable params field
446 if (action == 4 || action == 6 || action == 7 || action == 9) {
447 new Effect.Appear(action_param, {duration : 0.5});
449 Element.hide(dijit.byId("filterDlg_actionParam").domNode);
450 Element.hide(dijit.byId("filterDlg_actionParamLabel").domNode);
451 Element.hide(dijit.byId("filterDlg_actionParamPlugin").domNode);
454 Element.show(dijit.byId("filterDlg_actionParamLabel").domNode);
455 } else if (action == 9) {
456 Element.show(dijit.byId("filterDlg_actionParamPlugin").domNode);
458 Element.show(dijit.byId("filterDlg_actionParam").domNode);
462 Element.hide(action_param);
467 function explainError(code) {
468 return displayDlg(__("Error explained"), "explainError", code);
471 function loading_set_progress(p) {
472 loading_progress += p;
474 if (dijit.byId("loading_bar"))
475 dijit.byId("loading_bar").update({progress: loading_progress});
477 if (loading_progress >= 90)
482 function remove_splash() {
483 Element.hide("overlay");
486 function strip_tags(s) {
487 return s.replace(/<\/?[^>]+(>|$)/g, "");
490 function hotkey_prefix_timeout() {
492 const date = new Date();
493 const ts = Math.round(date.getTime() / 1000);
495 if (hotkey_prefix_pressed && ts - hotkey_prefix_pressed >= 5) {
496 console.log("hotkey_prefix seems to be stuck, aborting");
497 hotkey_prefix_pressed = false;
498 hotkey_prefix = false;
499 Element.hide('cmdline');
502 setTimeout(hotkey_prefix_timeout, 1000);
506 function uploadIconHandler(rc) {
509 notify_info("Upload complete.");
510 if (inPreferences()) {
513 setTimeout('updateFeedList(false, false)', 50);
517 notify_error("Upload failed: icon is too big.");
520 notify_error("Upload failed.");
525 function removeFeedIcon(id) {
526 if (confirm(__("Remove stored feed icon?"))) {
528 notify_progress("Removing feed icon...", true);
530 const query = { op: "pref-feeds", method: "removeicon", feed_id: id };
532 xhrPost("backend.php", query, (transport) => {
533 notify_info("Feed icon removed.");
534 if (inPreferences()) {
537 setTimeout('updateFeedList(false, false)', 50);
545 function uploadFeedIcon() {
546 const file = $("icon_file");
548 if (file.value.length == 0) {
549 alert(__("Please select an image file to upload."));
550 } else if (confirm(__("Upload new icon for this feed?"))) {
551 notify_progress("Uploading, please wait...", true);
558 function addLabel(select, callback) {
560 const caption = prompt(__("Please enter label caption:"), "");
562 if (caption != undefined) {
565 alert(__("Can't create label: missing caption."));
569 const query = { op: "pref-labels", method: "add", caption: caption };
572 Object.extend(query, {output: "select"});
574 notify_progress("Loading, please wait...", true);
576 xhrPost("backend.php", query, (transport) => {
579 } else if (inPreferences()) {
589 function quickAddFeed() {
590 const query = "backend.php?op=feeds&method=quickAddFeed";
592 // overlapping widgets
593 if (dijit.byId("batchSubDlg")) dijit.byId("batchSubDlg").destroyRecursive();
594 if (dijit.byId("feedAddDlg")) dijit.byId("feedAddDlg").destroyRecursive();
596 const dialog = new dijit.Dialog({
598 title: __("Subscribe to Feed"),
599 style: "width: 600px",
600 show_error: function(msg) {
601 const elem = $("fadd_error_message");
603 elem.innerHTML = msg;
605 if (!Element.visible(elem))
606 new Effect.Appear(elem);
609 execute: function() {
610 if (this.validate()) {
611 console.log(dojo.objectToQuery(this.attr('value')));
613 const feed_url = this.attr('value').feed;
615 Element.show("feed_add_spinner");
616 Element.hide("fadd_error_message");
618 xhrPost("backend.php", this.attr('value'), (transport) => {
622 var reply = JSON.parse(transport.responseText);
624 Element.hide("feed_add_spinner");
625 alert(__("Failed to parse output. This can indicate server timeout and/or network issues. Backend output was logged to browser console."));
626 console.log('quickAddFeed, backend returned:' + transport.responseText);
630 const rc = reply['result'];
633 Element.hide("feed_add_spinner");
637 switch (parseInt(rc['code'])) {
640 notify_info(__("Subscribed to %s").replace("%s", feed_url));
645 dialog.show_error(__("Specified URL seems to be invalid."));
648 dialog.show_error(__("Specified URL doesn't seem to contain any feeds."));
651 const feeds = rc['feeds'];
653 Element.show("fadd_multiple_notify");
655 const select = dijit.byId("feedDlg_feedContainerSelect");
657 while (select.getOptions().length > 0)
658 select.removeOption(0);
660 select.addOption({value: '', label: __("Expand to select feed")});
663 for (const feedUrl in feeds) {
664 select.addOption({value: feedUrl, label: feeds[feedUrl]});
668 Effect.Appear('feedDlg_feedsContainer', {duration : 0.5});
672 dialog.show_error(__("Couldn't download the specified URL: %s").
673 replace("%s", rc['message']));
676 dialog.show_error(__("XML validation failed: %s").
677 replace("%s", rc['message']));
680 dialog.show_error(__("You are already subscribed to this feed."));
685 console.error(transport.responseText);
696 function createNewRuleElement(parentNode, replaceNode) {
697 const form = document.forms["filter_new_rule_form"];
699 //form.reg_exp.value = form.reg_exp.value.replace(/(<([^>]+)>)/ig,"");
701 const query = { op: "pref-filters", method: "printrulename", rule: dojo.formToJson(form) };
703 xhrPost("backend.php", query, (transport) => {
705 const li = dojo.create("li");
707 const cb = dojo.create("input", { type: "checkbox" }, li);
709 new dijit.form.CheckBox({
710 onChange: function() {
711 toggleSelectListRow2(this) },
714 dojo.create("input", { type: "hidden",
716 value: dojo.formToJson(form) }, li);
718 dojo.create("span", {
719 onclick: function() {
720 dijit.byId('filterEditDlg').editRule(this);
722 innerHTML: transport.responseText }, li);
725 parentNode.replaceChild(li, replaceNode);
727 parentNode.appendChild(li);
735 function createNewActionElement(parentNode, replaceNode) {
736 const form = document.forms["filter_new_action_form"];
738 if (form.action_id.value == 7) {
739 form.action_param.value = form.action_param_label.value;
740 } else if (form.action_id.value == 9) {
741 form.action_param.value = form.action_param_plugin.value;
744 const query = { op: "pref-filters", method: "printactionname",
745 action: dojo.formToJson(form) };
747 xhrPost("backend.php", query, (transport) => {
749 const li = dojo.create("li");
751 const cb = dojo.create("input", { type: "checkbox" }, li);
753 new dijit.form.CheckBox({
754 onChange: function() {
755 toggleSelectListRow2(this) },
758 dojo.create("input", { type: "hidden",
760 value: dojo.formToJson(form) }, li);
762 dojo.create("span", {
763 onclick: function() {
764 dijit.byId('filterEditDlg').editAction(this);
766 innerHTML: transport.responseText }, li);
769 parentNode.replaceChild(li, replaceNode);
771 parentNode.appendChild(li);
781 function addFilterRule(replaceNode, ruleStr) {
782 if (dijit.byId("filterNewRuleDlg"))
783 dijit.byId("filterNewRuleDlg").destroyRecursive();
785 const query = "backend.php?op=pref-filters&method=newrule&rule=" +
786 param_escape(ruleStr);
788 const rule_dlg = new dijit.Dialog({
789 id: "filterNewRuleDlg",
790 title: ruleStr ? __("Edit rule") : __("Add rule"),
791 style: "width: 600px",
792 execute: function() {
793 if (this.validate()) {
794 createNewRuleElement($("filterDlg_Matches"), replaceNode);
803 function addFilterAction(replaceNode, actionStr) {
804 if (dijit.byId("filterNewActionDlg"))
805 dijit.byId("filterNewActionDlg").destroyRecursive();
807 const query = "backend.php?op=pref-filters&method=newaction&action=" +
808 param_escape(actionStr);
810 const rule_dlg = new dijit.Dialog({
811 id: "filterNewActionDlg",
812 title: actionStr ? __("Edit action") : __("Add action"),
813 style: "width: 600px",
814 execute: function() {
815 if (this.validate()) {
816 createNewActionElement($("filterDlg_Actions"), replaceNode);
825 function editFilterTest(query) {
827 if (dijit.byId("filterTestDlg"))
828 dijit.byId("filterTestDlg").destroyRecursive();
830 var test_dlg = new dijit.Dialog({
832 title: "Test Filter",
833 style: "width: 600px",
837 getTestResults: function(query, offset) {
838 const updquery = query + "&offset=" + offset + "&limit=" + test_dlg.limit;
840 console.log("getTestResults:" + offset);
842 xhrPost("backend.php", updquery, (transport) => {
844 const result = JSON.parse(transport.responseText);
846 if (result && dijit.byId("filterTestDlg") && dijit.byId("filterTestDlg").open) {
847 test_dlg.results += result.length;
849 console.log("got results:" + result.length);
851 $("prefFilterProgressMsg").innerHTML = __("Looking for articles (%d processed, %f found)...")
852 .replace("%f", test_dlg.results)
853 .replace("%d", offset);
855 console.log(offset + " " + test_dlg.max_offset);
857 for (let i = 0; i < result.length; i++) {
858 const tmp = new Element("table");
859 tmp.innerHTML = result[i];
860 dojo.parser.parse(tmp);
862 $("prefFilterTestResultList").innerHTML += tmp.innerHTML;
865 if (test_dlg.results < 30 && offset < test_dlg.max_offset) {
867 // get the next batch
868 window.setTimeout(function () {
869 test_dlg.getTestResults(query, offset + test_dlg.limit);
875 Element.hide("prefFilterLoadingIndicator");
877 if (test_dlg.results == 0) {
878 $("prefFilterTestResultList").innerHTML = "<tr><td align='center'>No recent articles matching this filter have been found.</td></tr>";
879 $("prefFilterProgressMsg").innerHTML = "Articles matching this filter:";
881 $("prefFilterProgressMsg").innerHTML = __("Found %d articles matching this filter:")
882 .replace("%d", test_dlg.results);
887 } else if (!result) {
888 console.log("getTestResults: can't parse results object");
890 Element.hide("prefFilterLoadingIndicator");
892 notify_error("Error while trying to get filter test results.");
895 console.log("getTestResults: dialog closed, bailing out.");
905 dojo.connect(test_dlg, "onLoad", null, function(e) {
906 test_dlg.getTestResults(query, 0);
913 function quickAddFilter() {
915 if (!inPreferences()) {
916 query = "backend.php?op=pref-filters&method=newfilter&feed=" +
917 param_escape(getActiveFeedId()) + "&is_cat=" +
918 param_escape(activeFeedIsCat());
920 query = "backend.php?op=pref-filters&method=newfilter";
925 if (dijit.byId("feedEditDlg"))
926 dijit.byId("feedEditDlg").destroyRecursive();
928 if (dijit.byId("filterEditDlg"))
929 dijit.byId("filterEditDlg").destroyRecursive();
931 const dialog = new dijit.Dialog({
933 title: __("Create Filter"),
934 style: "width: 600px",
936 const query = "backend.php?" + dojo.formToQuery("filter_new_form") + "&savemode=test";
938 editFilterTest(query);
940 selectRules: function(select) {
941 $$("#filterDlg_Matches input[type=checkbox]").each(function(e) {
944 e.parentNode.addClassName("Selected");
946 e.parentNode.removeClassName("Selected");
949 selectActions: function(select) {
950 $$("#filterDlg_Actions input[type=checkbox]").each(function(e) {
954 e.parentNode.addClassName("Selected");
956 e.parentNode.removeClassName("Selected");
960 editRule: function(e) {
961 const li = e.parentNode;
962 const rule = li.getElementsByTagName("INPUT")[1].value;
963 addFilterRule(li, rule);
965 editAction: function(e) {
966 const li = e.parentNode;
967 const action = li.getElementsByTagName("INPUT")[1].value;
968 addFilterAction(li, action);
970 addAction: function() { addFilterAction(); },
971 addRule: function() { addFilterRule(); },
972 deleteAction: function() {
973 $$("#filterDlg_Actions li[class*=Selected]").each(function(e) { e.parentNode.removeChild(e) });
975 deleteRule: function() {
976 $$("#filterDlg_Matches li[class*=Selected]").each(function(e) { e.parentNode.removeChild(e) });
978 execute: function() {
979 if (this.validate()) {
981 const query = dojo.formToQuery("filter_new_form");
983 xhrPost("backend.php", query, (transport) => {
984 if (inPreferences()) {
994 if (!inPreferences()) {
995 const selectedText = getSelectionText();
997 var lh = dojo.connect(dialog, "onLoad", function(){
1000 if (selectedText != "") {
1002 const feed_id = activeFeedIsCat() ? 'CAT:' + parseInt(getActiveFeedId()) :
1005 const rule = { reg_exp: selectedText, feed_id: [feed_id], filter_type: 1 };
1007 addFilterRule(null, dojo.toJson(rule));
1011 const query = { op: "rpc", method: "getlinktitlebyid", id: getActiveArticleId() };
1013 xhrPost("backend.php", query, (transport) => {
1014 const reply = JSON.parse(transport.responseText);
1018 if (reply && reply.title) title = reply.title;
1020 if (title || getActiveFeedId() || activeFeedIsCat()) {
1022 console.log(title + " " + getActiveFeedId());
1024 const feed_id = activeFeedIsCat() ? 'CAT:' + parseInt(getActiveFeedId()) :
1027 const rule = { reg_exp: title, feed_id: [feed_id], filter_type: 1 };
1029 addFilterRule(null, dojo.toJson(rule));
1040 function unsubscribeFeed(feed_id, title) {
1042 const msg = __("Unsubscribe from %s?").replace("%s", title);
1044 if (title == undefined || confirm(msg)) {
1045 notify_progress("Removing feed...");
1047 const query = { op: "pref-feeds", quiet: 1, method: "remove", ids: feed_id };
1049 xhrPost("backend.php", query, (transport) => {
1050 if (dijit.byId("feedEditDlg")) dijit.byId("feedEditDlg").hide();
1052 if (inPreferences()) {
1055 if (feed_id == getActiveFeedId())
1056 setTimeout(function() { viewfeed({feed:-5}) }, 100);
1058 if (feed_id < 0) updateFeedList();
1067 function backend_sanity_check_callback(transport) {
1069 const reply = JSON.parse(transport.responseText);
1072 fatalError(3, "Sanity check: invalid RPC reply", transport.responseText);
1076 const error_code = reply['error']['code'];
1078 if (error_code && error_code != 0) {
1079 return fatalError(error_code, reply['error']['message']);
1082 console.log("sanity check ok");
1084 const params = reply['init-params'];
1087 console.log('reading init-params...');
1089 for (const k in params) {
1090 console.log("IP:", k, "=>", params[k]);
1091 if (k == "label_base_index") _label_base_index = parseInt(params[k]);
1094 init_params = params;
1096 // PluginHost might not be available on non-index pages
1097 window.PluginHost && PluginHost.run(PluginHost.HOOK_PARAMS_LOADED, init_params);
1100 init_second_stage();
1103 function genUrlChangeKey(feed, is_cat) {
1104 const ok = confirm(__("Generate new syndication address for this feed?"));
1108 notify_progress("Trying to change address...", true);
1110 const query = { op: "pref-feeds", method: "regenFeedKey", id: feed, is_cat: is_cat };
1112 xhrJson("backend.php", query, (reply) => {
1113 const new_link = reply.link;
1114 const e = $('gen_feed_url');
1117 e.innerHTML = e.innerHTML.replace(/\&key=.*$/,
1118 "&key=" + new_link);
1120 e.href = e.href.replace(/\&key=.*$/,
1121 "&key=" + new_link);
1123 new Effect.Highlight(e);
1128 notify_error("Could not change feed URL.");
1135 // mode = all, none, invert
1136 function selectTableRows(id, mode) {
1137 const rows = $(id).rows;
1139 for (let i = 0; i < rows.length; i++) {
1140 const row = rows[i];
1144 if (row.id && row.className) {
1145 const bare_id = row.id.replace(/^[A-Z]*?-/, "");
1146 const inputs = rows[i].getElementsByTagName("input");
1148 for (let j = 0; j < inputs.length; j++) {
1149 const input = inputs[j];
1151 if (input.getAttribute("type") == "checkbox" &&
1152 input.id.match(bare_id)) {
1155 dcb = dijit.getEnclosingWidget(cb);
1161 const issel = row.hasClassName("Selected");
1163 if (mode == "all" && !issel) {
1164 row.addClassName("Selected");
1166 if (dcb) dcb.set("checked", true);
1167 } else if (mode == "none" && issel) {
1168 row.removeClassName("Selected");
1170 if (dcb) dcb.set("checked", false);
1172 } else if (mode == "invert") {
1175 row.removeClassName("Selected");
1177 if (dcb) dcb.set("checked", false);
1179 row.addClassName("Selected");
1181 if (dcb) dcb.set("checked", true);
1190 function getSelectedTableRowIds(id) {
1193 const elem_rows = $(id).rows;
1195 for (let i = 0; i < elem_rows.length; i++) {
1196 if (elem_rows[i].hasClassName("Selected")) {
1197 const bare_id = elem_rows[i].id.replace(/^[A-Z]*?-/, "");
1205 function editFeed(feed) {
1207 return alert(__("You can't edit this kind of feed."));
1209 const query = "backend.php?op=pref-feeds&method=editfeed&id=" +
1214 if (dijit.byId("filterEditDlg"))
1215 dijit.byId("filterEditDlg").destroyRecursive();
1217 if (dijit.byId("feedEditDlg"))
1218 dijit.byId("feedEditDlg").destroyRecursive();
1220 const dialog = new dijit.Dialog({
1222 title: __("Edit Feed"),
1223 style: "width: 600px",
1224 execute: function() {
1225 if (this.validate()) {
1226 notify_progress("Saving data...", true);
1228 xhrPost("backend.php", dialog.attr('value'), (transport) => {
1240 function feedBrowser() {
1241 const query = "backend.php?op=feeds&method=feedBrowser";
1243 if (dijit.byId("feedAddDlg"))
1244 dijit.byId("feedAddDlg").hide();
1246 if (dijit.byId("feedBrowserDlg"))
1247 dijit.byId("feedBrowserDlg").destroyRecursive();
1249 const dialog = new dijit.Dialog({
1250 id: "feedBrowserDlg",
1251 title: __("More Feeds"),
1252 style: "width: 600px",
1253 getSelectedFeedIds: function () {
1254 const list = $$("#browseFeedList li[id*=FBROW]");
1255 const selected = [];
1257 list.each(function (child) {
1258 const id = child.id.replace("FBROW-", "");
1260 if (child.hasClassName('Selected')) {
1267 getSelectedFeeds: function () {
1268 const list = $$("#browseFeedList li.Selected");
1269 const selected = [];
1271 list.each(function (child) {
1272 const title = child.getElementsBySelector("span.fb_feedTitle")[0].innerHTML;
1273 const url = child.getElementsBySelector("a.fb_feedUrl")[0].href;
1275 selected.push([title, url]);
1282 subscribe: function () {
1283 const mode = this.attr('value').mode;
1287 selected = this.getSelectedFeeds();
1289 selected = this.getSelectedFeedIds();
1291 if (selected.length > 0) {
1292 dijit.byId("feedBrowserDlg").hide();
1294 notify_progress("Loading, please wait...", true);
1296 const query = { op: "rpc", method: "massSubscribe",
1297 payload: JSON.stringify(selected), mode: mode };
1299 xhrPost("backend.php", query, () => {
1305 alert(__("No feeds are selected."));
1309 update: function () {
1310 Element.show('feed_browser_spinner');
1312 xhrPost("backend.php", dialog.attr("value"), (transport) => {
1315 Element.hide('feed_browser_spinner');
1317 const reply = JSON.parse(transport.responseText);
1318 const mode = reply['mode'];
1320 if ($("browseFeedList") && reply['content']) {
1321 $("browseFeedList").innerHTML = reply['content'];
1324 dojo.parser.parse("browseFeedList");
1327 Element.show(dijit.byId('feed_archive_remove').domNode);
1329 Element.hide(dijit.byId('feed_archive_remove').domNode);
1333 removeFromArchive: function () {
1334 const selected = this.getSelectedFeedIds();
1336 if (selected.length > 0) {
1338 const pr = __("Remove selected feeds from the archive? Feeds with stored articles will not be removed.");
1341 Element.show('feed_browser_spinner');
1343 const query = { op: "rpc", method: "remarchive", ids: selected.toString() };
1345 xhrPost("backend.php", query, () => {
1351 execute: function () {
1352 if (this.validate()) {
1362 function showFeedsWithErrors() {
1363 const query = "backend.php?op=pref-feeds&method=feedsWithErrors";
1365 if (dijit.byId("errorFeedsDlg"))
1366 dijit.byId("errorFeedsDlg").destroyRecursive();
1368 const dialog = new dijit.Dialog({
1369 id: "errorFeedsDlg",
1370 title: __("Feeds with update errors"),
1371 style: "width: 600px",
1372 getSelectedFeeds: function() {
1373 return getSelectedTableRowIds("prefErrorFeedList");
1375 removeSelected: function() {
1376 const sel_rows = this.getSelectedFeeds();
1378 console.log(sel_rows);
1380 if (sel_rows.length > 0) {
1381 const ok = confirm(__("Remove selected feeds?"));
1384 notify_progress("Removing selected feeds...", true);
1386 const query = { op: "pref-feeds", method: "remove",
1387 ids: sel_rows.toString() };
1389 xhrPost("backend.php", query, () => {
1397 alert(__("No feeds are selected."));
1400 execute: function() {
1401 if (this.validate()) {
1410 function get_timestamp() {
1411 const date = new Date();
1412 return Math.round(date.getTime() / 1000);
1415 function helpDialog(topic) {
1416 const query = "backend.php?op=backend&method=help&topic=" + param_escape(topic);
1418 if (dijit.byId("helpDlg"))
1419 dijit.byId("helpDlg").destroyRecursive();
1421 const dialog = new dijit.Dialog({
1424 style: "width: 600px",
1431 function htmlspecialchars_decode (string, quote_style) {
1432 // http://kevin.vanzonneveld.net
1433 // + original by: Mirek Slugen
1434 // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
1435 // + bugfixed by: Mateusz "loonquawl" Zalega
1436 // + input by: ReverseSyntax
1437 // + input by: Slawomir Kaniecki
1438 // + input by: Scott Cariss
1439 // + input by: Francois
1440 // + bugfixed by: Onno Marsman
1441 // + revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
1442 // + bugfixed by: Brett Zamir (http://brett-zamir.me)
1443 // + input by: Ratheous
1444 // + input by: Mailfaker (http://www.weedem.fr/)
1445 // + reimplemented by: Brett Zamir (http://brett-zamir.me)
1446 // + bugfixed by: Brett Zamir (http://brett-zamir.me)
1447 // * example 1: htmlspecialchars_decode("<p>this -> "</p>", 'ENT_NOQUOTES');
1448 // * returns 1: '<p>this -> "</p>'
1449 // * example 2: htmlspecialchars_decode("&quot;");
1450 // * returns 2: '"'
1454 if (typeof quote_style === 'undefined') {
1457 string = string.toString().replace(/</g, '<').replace(/>/g, '>');
1460 'ENT_HTML_QUOTE_SINGLE': 1,
1461 'ENT_HTML_QUOTE_DOUBLE': 2,
1466 if (quote_style === 0) {
1469 if (typeof quote_style !== 'number') { // Allow for a single string or an array of string flags
1470 quote_style = [].concat(quote_style);
1471 for (i = 0; i < quote_style.length; i++) {
1472 // Resolve string input to bitwise e.g. 'PATHINFO_EXTENSION' becomes 4
1473 if (OPTS[quote_style[i]] === 0) {
1475 } else if (OPTS[quote_style[i]]) {
1476 optTemp = optTemp | OPTS[quote_style[i]];
1479 quote_style = optTemp;
1481 if (quote_style & OPTS.ENT_HTML_QUOTE_SINGLE) {
1482 string = string.replace(/�*39;/g, "'"); // PHP doesn't currently escape if more than one 0, but it should
1483 // string = string.replace(/'|�*27;/g, "'"); // This would also be useful here, but not a part of PHP
1486 string = string.replace(/"/g, '"');
1488 // Put this in last place to avoid escape being double-decoded
1489 string = string.replace(/&/g, '&');
1495 function label_to_feed_id(label) {
1496 return _label_base_index - 1 - Math.abs(label);
1499 function feed_to_label_id(feed) {
1500 return _label_base_index - 1 + Math.abs(feed);
1503 // http://stackoverflow.com/questions/6251937/how-to-get-selecteduser-highlighted-text-in-contenteditable-element-and-replac
1505 function getSelectionText() {
1508 if (typeof window.getSelection != "undefined") {
1509 const sel = window.getSelection();
1510 if (sel.rangeCount) {
1511 const container = document.createElement("div");
1512 for (let i = 0, len = sel.rangeCount; i < len; ++i) {
1513 container.appendChild(sel.getRangeAt(i).cloneContents());
1515 text = container.innerHTML;
1517 } else if (typeof document.selection != "undefined") {
1518 if (document.selection.type == "Text") {
1519 text = document.selection.createRange().textText;
1523 return text.stripTags();
1526 function openUrlPopup(url) {
1527 const w = window.open("");
1532 function openArticlePopup(id) {
1533 const w = window.open("",
1534 "ttrss_article_popup",
1535 "height=900,width=900,resizable=yes,status=no,location=no,menubar=no,directories=no,scrollbars=yes,toolbar=no");
1538 w.location = "backend.php?op=article&method=view&mode=raw&html=1&zoom=1&id=" + id + "&csrf_token=" + getInitParam("csrf_token");