3 var loading_progress = 0;
4 var sanity_check_done = false;
6 var _label_base_index = -1024;
7 var notify_hide_timerid = false;
9 Ajax.Base.prototype.initialize = Ajax.Base.prototype.initialize.wrap(
10 function (callOriginal, options) {
12 if (getInitParam("csrf_token") != undefined) {
13 Object.extend(options, options || { });
15 if (Object.isString(options.parameters))
16 options.parameters = options.parameters.toQueryParams();
17 else if (Object.isHash(options.parameters))
18 options.parameters = options.parameters.toObject();
20 options.parameters["csrf_token"] = getInitParam("csrf_token");
23 return callOriginal(options);
27 /* add method to remove element from array */
29 Array.prototype.remove = function(s) {
30 for (let i=0; i < this.length; i++) {
31 if (s == this[i]) this.splice(i, 1);
35 function report_error(message, filename, lineno, colno, error) {
36 exception_error(error, null, filename, lineno);
39 function exception_error(e, e_compat, filename, lineno, colno) {
40 if (typeof e == "string") e = e_compat;
42 if (!e) return; // no exception object, nothing to report.
46 const msg = e.toString();
49 new Ajax.Request("backend.php", {
50 parameters: {op: "rpc", method: "log",
51 file: e.fileName ? e.fileName : filename,
52 line: e.lineNumber ? e.lineNumber : lineno,
53 msg: msg, context: e.stack},
54 onComplete: function (transport) {
55 console.warn(transport.responseText);
59 console.error("Exception while trying to log the error.", e);
62 let content = "<div class='fatalError'><p>" + msg + "</p>";
65 content += "<div><b>Stack trace:</b></div>" +
66 "<textarea name=\"stack\" readonly=\"1\">" + e.stack + "</textarea>";
71 content += "<div class='dlgButtons'>";
73 content += "<button dojoType=\"dijit.form.Button\" "+
74 "onclick=\"dijit.byId('exceptionDlg').hide()\">" +
75 __('Close') + "</button>";
78 if (dijit.byId("exceptionDlg"))
79 dijit.byId("exceptionDlg").destroyRecursive();
81 const dialog = new dijit.Dialog({
83 title: "Unhandled exception",
84 style: "width: 600px",
90 console.error("Exception while trying to report an exception:", ei);
91 console.error("Original exception:", e);
93 alert("Exception occured while trying to report an exception.\n" +
94 ei.stack + "\n\nOriginal exception:\n" + e.stack);
99 function param_escape(arg) {
100 return encodeURIComponent(arg);
103 function notify_real(msg, no_hide, n_type) {
105 const n = $("notify");
109 if (notify_hide_timerid) {
110 window.clearTimeout(notify_hide_timerid);
114 if (n.hasClassName("visible")) {
115 notify_hide_timerid = window.setTimeout(function() {
116 n.removeClassName("visible") }, 0);
130 msg = "<span class=\"msg\"> " + __(msg) + "</span>";
133 msg = "<span><img src=\""+getInitParam("icon_indicator_white")+"\"></span>" + msg;
135 } else if (n_type == 3) {
136 msg = "<span><img src=\""+getInitParam("icon_alert")+"\"></span>" + msg;
137 } else if (n_type == 4) {
138 msg = "<span><img src=\""+getInitParam("icon_information")+"\"></span>" + msg;
141 msg += " <span><img src=\""+getInitParam("icon_cross")+"\" class=\"close\" title=\"" +
142 __("Click to close") + "\" onclick=\"notify('')\"></span>";
146 window.setTimeout(function() {
149 n.className = "notify notify_progress visible";
150 } else if (n_type == 3) {
151 n.className = "notify notify_error visible";
152 msg = "<span><img src='images/alert.png'></span>" + msg;
153 } else if (n_type == 4) {
154 n.className = "notify notify_info visible";
156 n.className = "notify visible";
160 notify_hide_timerid = window.setTimeout(function() {
161 n.removeClassName("visible") }, 5*1000);
168 function notify(msg, no_hide) {
169 notify_real(msg, no_hide, 1);
172 function notify_progress(msg, no_hide) {
173 notify_real(msg, no_hide, 2);
176 function notify_error(msg, no_hide) {
177 notify_real(msg, no_hide, 3);
181 function notify_info(msg, no_hide) {
182 notify_real(msg, no_hide, 4);
185 function setCookie(name, value, lifetime, path, domain, secure) {
191 d.setTime(d.getTime() + (lifetime * 1000));
194 console.log("setCookie: " + name + " => " + value + ": " + d);
196 int_setCookie(name, value, d, path, domain, secure);
200 function int_setCookie(name, value, expires, path, domain, secure) {
201 document.cookie= name + "=" + escape(value) +
202 ((expires) ? "; expires=" + expires.toGMTString() : "") +
203 ((path) ? "; path=" + path : "") +
204 ((domain) ? "; domain=" + domain : "") +
205 ((secure) ? "; secure" : "");
208 function delCookie(name, path, domain) {
209 if (getCookie(name)) {
210 document.cookie = name + "=" +
211 ((path) ? ";path=" + path : "") +
212 ((domain) ? ";domain=" + domain : "" ) +
213 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
218 function getCookie(name) {
220 const dc = document.cookie;
221 const prefix = name + "=";
222 let begin = dc.indexOf("; " + prefix);
224 begin = dc.indexOf(prefix);
225 if (begin != 0) return null;
230 let end = document.cookie.indexOf(";", begin);
234 return unescape(dc.substring(begin + prefix.length, end));
237 function gotoPreferences() {
238 document.location.href = "prefs.php";
241 function gotoLogout() {
242 document.location.href = "backend.php?op=logout";
245 function gotoMain() {
246 document.location.href = "index.php";
249 function toggleSelectRowById(sender, id) {
251 return toggleSelectRow(sender, row);
254 /* this is for dijit Checkbox */
255 function toggleSelectListRow2(sender) {
256 const row = sender.domNode.parentNode;
257 return toggleSelectRow(sender, row);
260 /* this is for dijit Checkbox */
261 function toggleSelectRow2(sender, row, is_cdm) {
265 row = sender.domNode.parentNode.parentNode;
267 row = sender.domNode.parentNode.parentNode.parentNode; // oh ffs
269 if (sender.checked && !row.hasClassName('Selected'))
270 row.addClassName('Selected');
272 row.removeClassName('Selected');
274 if (typeof updateSelectedPrompt != undefined)
275 updateSelectedPrompt();
279 function toggleSelectRow(sender, row) {
281 if (!row) row = sender.parentNode.parentNode;
283 if (sender.checked && !row.hasClassName('Selected'))
284 row.addClassName('Selected');
286 row.removeClassName('Selected');
288 if (typeof updateSelectedPrompt != undefined)
289 updateSelectedPrompt();
292 function checkboxToggleElement(elem, id) {
294 Effect.Appear(id, {duration : 0.5});
296 Effect.Fade(id, {duration : 0.5});
300 function getURLParam(param){
301 return String(window.location.href).parseQuery()[param];
304 function closeInfoBox() {
305 const dialog = dijit.byId("infoBox");
307 if (dialog) dialog.hide();
313 function displayDlg(title, id, param, callback) {
315 notify_progress("Loading, please wait...", true);
317 const query = "?op=dlg&method=" +
318 param_escape(id) + "¶m=" + param_escape(param);
320 new Ajax.Request("backend.php", {
322 onComplete: function (transport) {
323 infobox_callback2(transport, title);
324 if (callback) callback(transport);
330 function infobox_callback2(transport, title) {
333 if (dijit.byId("infoBox")) {
334 dialog = dijit.byId("infoBox");
337 //console.log("infobox_callback2");
340 const content = transport.responseText;
343 dialog = new dijit.Dialog({
346 style: "width: 600px",
347 onCancel: function() {
350 onExecute: function() {
353 onClose: function() {
358 dialog.attr('title', title);
359 dialog.attr('content', content);
367 function getInitParam(key) {
368 return init_params[key];
371 function setInitParam(key, value) {
372 init_params[key] = value;
375 function fatalError(code, msg, ext_info) {
377 window.location.href = "index.php";
378 } else if (code == 5) {
379 window.location.href = "public.php?op=dbupdate";
382 if (msg == "") msg = "Unknown error";
385 if (ext_info.responseText) {
386 ext_info = ext_info.responseText;
390 if (ERRORS && ERRORS[code] && !msg) {
394 let content = "<div><b>Error code:</b> " + code + "</div>" +
395 "<p>" + msg + "</p>";
398 content = content + "<div><b>Additional information:</b></div>" +
399 "<textarea style='width: 100%' readonly=\"1\">" +
400 ext_info + "</textarea>";
403 const dialog = new dijit.Dialog({
404 title: "Fatal error",
405 style: "width: 600px",
416 function filterDlgCheckAction(sender) {
417 const action = sender.value;
419 const action_param = $("filterDlg_paramBox");
422 console.log("filterDlgCheckAction: can't find action param box!");
426 // if selected action supports parameters, enable params field
427 if (action == 4 || action == 6 || action == 7 || action == 9) {
428 new Effect.Appear(action_param, {duration : 0.5});
430 Element.hide(dijit.byId("filterDlg_actionParam").domNode);
431 Element.hide(dijit.byId("filterDlg_actionParamLabel").domNode);
432 Element.hide(dijit.byId("filterDlg_actionParamPlugin").domNode);
435 Element.show(dijit.byId("filterDlg_actionParamLabel").domNode);
436 } else if (action == 9) {
437 Element.show(dijit.byId("filterDlg_actionParamPlugin").domNode);
439 Element.show(dijit.byId("filterDlg_actionParam").domNode);
443 Element.hide(action_param);
448 function explainError(code) {
449 return displayDlg(__("Error explained"), "explainError", code);
452 function loading_set_progress(p) {
453 loading_progress += p;
455 if (dijit.byId("loading_bar"))
456 dijit.byId("loading_bar").update({progress: loading_progress});
458 if (loading_progress >= 90)
463 function remove_splash() {
464 Element.hide("overlay");
467 function strip_tags(s) {
468 return s.replace(/<\/?[^>]+(>|$)/g, "");
471 function hotkey_prefix_timeout() {
473 const date = new Date();
474 const ts = Math.round(date.getTime() / 1000);
476 if (hotkey_prefix_pressed && ts - hotkey_prefix_pressed >= 5) {
477 console.log("hotkey_prefix seems to be stuck, aborting");
478 hotkey_prefix_pressed = false;
479 hotkey_prefix = false;
480 Element.hide('cmdline');
483 setTimeout(hotkey_prefix_timeout, 1000);
487 function uploadIconHandler(rc) {
490 notify_info("Upload complete.");
491 if (inPreferences()) {
494 setTimeout('updateFeedList(false, false)', 50);
498 notify_error("Upload failed: icon is too big.");
501 notify_error("Upload failed.");
506 function removeFeedIcon(id) {
507 if (confirm(__("Remove stored feed icon?"))) {
508 const query = "backend.php?op=pref-feeds&method=removeicon&feed_id=" + param_escape(id);
512 notify_progress("Removing feed icon...", true);
514 new Ajax.Request("backend.php", {
516 onComplete: function(transport) {
517 notify_info("Feed icon removed.");
518 if (inPreferences()) {
521 setTimeout('updateFeedList(false, false)', 50);
529 function uploadFeedIcon() {
530 const file = $("icon_file");
532 if (file.value.length == 0) {
533 alert(__("Please select an image file to upload."));
534 } else if (confirm(__("Upload new icon for this feed?"))) {
535 notify_progress("Uploading, please wait...", true);
542 function addLabel(select, callback) {
544 const caption = prompt(__("Please enter label caption:"), "");
546 if (caption != undefined) {
549 alert(__("Can't create label: missing caption."));
553 let query = "?op=pref-labels&method=add&caption=" +
554 param_escape(caption);
557 query += "&output=select";
559 notify_progress("Loading, please wait...", true);
561 new Ajax.Request("backend.php", {
563 onComplete: function(transport) {
566 } else if (inPreferences()) {
577 function quickAddFeed() {
578 const query = "backend.php?op=feeds&method=quickAddFeed";
580 // overlapping widgets
581 if (dijit.byId("batchSubDlg")) dijit.byId("batchSubDlg").destroyRecursive();
582 if (dijit.byId("feedAddDlg")) dijit.byId("feedAddDlg").destroyRecursive();
584 const dialog = new dijit.Dialog({
586 title: __("Subscribe to Feed"),
587 style: "width: 600px",
588 show_error: function(msg) {
589 const elem = $("fadd_error_message");
591 elem.innerHTML = msg;
593 if (!Element.visible(elem))
594 new Effect.Appear(elem);
597 execute: function() {
598 if (this.validate()) {
599 console.log(dojo.objectToQuery(this.attr('value')));
601 const feed_url = this.attr('value').feed;
603 Element.show("feed_add_spinner");
604 Element.hide("fadd_error_message");
606 new Ajax.Request("backend.php", {
607 parameters: dojo.objectToQuery(this.attr('value')),
608 onComplete: function(transport) {
612 var reply = JSON.parse(transport.responseText);
614 Element.hide("feed_add_spinner");
615 alert(__("Failed to parse output. This can indicate server timeout and/or network issues. Backend output was logged to browser console."));
616 console.log('quickAddFeed, backend returned:' + transport.responseText);
620 const rc = reply['result'];
623 Element.hide("feed_add_spinner");
627 switch (parseInt(rc['code'])) {
630 notify_info(__("Subscribed to %s").replace("%s", feed_url));
635 dialog.show_error(__("Specified URL seems to be invalid."));
638 dialog.show_error(__("Specified URL doesn't seem to contain any feeds."));
641 var feeds = rc['feeds'];
643 Element.show("fadd_multiple_notify");
645 var select = dijit.byId("feedDlg_feedContainerSelect");
647 while (select.getOptions().length > 0)
648 select.removeOption(0);
650 select.addOption({value: '', label: __("Expand to select feed")});
653 for (const feedUrl in feeds) {
654 select.addOption({value: feedUrl, label: feeds[feedUrl]});
658 Effect.Appear('feedDlg_feedsContainer', {duration : 0.5});
662 dialog.show_error(__("Couldn't download the specified URL: %s").
663 replace("%s", rc['message']));
666 dialog.show_error(__("XML validation failed: %s").
667 replace("%s", rc['message']));
670 dialog.show_error(__("You are already subscribed to this feed."));
675 console.error(transport.responseText);
688 function createNewRuleElement(parentNode, replaceNode) {
689 const form = document.forms["filter_new_rule_form"];
691 //form.reg_exp.value = form.reg_exp.value.replace(/(<([^>]+)>)/ig,"");
693 const query = "backend.php?op=pref-filters&method=printrulename&rule="+
694 param_escape(dojo.formToJson(form));
698 new Ajax.Request("backend.php", {
700 onComplete: function (transport) {
702 const li = dojo.create("li");
704 const cb = dojo.create("input", { type: "checkbox" }, li);
706 new dijit.form.CheckBox({
707 onChange: function() {
708 toggleSelectListRow2(this) },
711 dojo.create("input", { type: "hidden",
713 value: dojo.formToJson(form) }, li);
715 dojo.create("span", {
716 onclick: function() {
717 dijit.byId('filterEditDlg').editRule(this);
719 innerHTML: transport.responseText }, li);
722 parentNode.replaceChild(li, replaceNode);
724 parentNode.appendChild(li);
732 function createNewActionElement(parentNode, replaceNode) {
733 const form = document.forms["filter_new_action_form"];
735 if (form.action_id.value == 7) {
736 form.action_param.value = form.action_param_label.value;
737 } else if (form.action_id.value == 9) {
738 form.action_param.value = form.action_param_plugin.value;
741 const query = "backend.php?op=pref-filters&method=printactionname&action="+
742 param_escape(dojo.formToJson(form));
746 new Ajax.Request("backend.php", {
748 onComplete: function (transport) {
750 const li = dojo.create("li");
752 const cb = dojo.create("input", { type: "checkbox" }, li);
754 new dijit.form.CheckBox({
755 onChange: function() {
756 toggleSelectListRow2(this) },
759 dojo.create("input", { type: "hidden",
761 value: dojo.formToJson(form) }, li);
763 dojo.create("span", {
764 onclick: function() {
765 dijit.byId('filterEditDlg').editAction(this);
767 innerHTML: transport.responseText }, li);
770 parentNode.replaceChild(li, replaceNode);
772 parentNode.appendChild(li);
782 function addFilterRule(replaceNode, ruleStr) {
783 if (dijit.byId("filterNewRuleDlg"))
784 dijit.byId("filterNewRuleDlg").destroyRecursive();
786 const query = "backend.php?op=pref-filters&method=newrule&rule=" +
787 param_escape(ruleStr);
789 const rule_dlg = new dijit.Dialog({
790 id: "filterNewRuleDlg",
791 title: ruleStr ? __("Edit rule") : __("Add rule"),
792 style: "width: 600px",
793 execute: function() {
794 if (this.validate()) {
795 createNewRuleElement($("filterDlg_Matches"), replaceNode);
804 function addFilterAction(replaceNode, actionStr) {
805 if (dijit.byId("filterNewActionDlg"))
806 dijit.byId("filterNewActionDlg").destroyRecursive();
808 const query = "backend.php?op=pref-filters&method=newaction&action=" +
809 param_escape(actionStr);
811 const rule_dlg = new dijit.Dialog({
812 id: "filterNewActionDlg",
813 title: actionStr ? __("Edit action") : __("Add action"),
814 style: "width: 600px",
815 execute: function() {
816 if (this.validate()) {
817 createNewActionElement($("filterDlg_Actions"), replaceNode);
826 function editFilterTest(query) {
828 if (dijit.byId("filterTestDlg"))
829 dijit.byId("filterTestDlg").destroyRecursive();
831 var test_dlg = new dijit.Dialog({
833 title: "Test Filter",
834 style: "width: 600px",
838 getTestResults: function(query, offset) {
839 const updquery = query + "&offset=" + offset + "&limit=" + test_dlg.limit;
841 console.log("getTestResults:" + offset);
843 new Ajax.Request("backend.php", {
844 parameters: updquery,
845 onComplete: function (transport) {
847 const result = JSON.parse(transport.responseText);
849 if (result && dijit.byId("filterTestDlg") && dijit.byId("filterTestDlg").open) {
850 test_dlg.results += result.length;
852 console.log("got results:" + result.length);
854 $("prefFilterProgressMsg").innerHTML = __("Looking for articles (%d processed, %f found)...")
855 .replace("%f", test_dlg.results)
856 .replace("%d", offset);
858 console.log(offset + " " + test_dlg.max_offset);
860 for (let i = 0; i < result.length; i++) {
861 const tmp = new Element("table");
862 tmp.innerHTML = result[i];
863 dojo.parser.parse(tmp);
865 $("prefFilterTestResultList").innerHTML += tmp.innerHTML;
868 if (test_dlg.results < 30 && offset < test_dlg.max_offset) {
870 // get the next batch
871 window.setTimeout(function () {
872 test_dlg.getTestResults(query, offset + test_dlg.limit);
878 Element.hide("prefFilterLoadingIndicator");
880 if (test_dlg.results == 0) {
881 $("prefFilterTestResultList").innerHTML = "<tr><td align='center'>No recent articles matching this filter have been found.</td></tr>";
882 $("prefFilterProgressMsg").innerHTML = "Articles matching this filter:";
884 $("prefFilterProgressMsg").innerHTML = __("Found %d articles matching this filter:")
885 .replace("%d", test_dlg.results);
890 } else if (!result) {
891 console.log("getTestResults: can't parse results object");
893 Element.hide("prefFilterLoadingIndicator");
895 notify_error("Error while trying to get filter test results.");
898 console.log("getTestResults: dialog closed, bailing out.");
908 dojo.connect(test_dlg, "onLoad", null, function(e) {
909 test_dlg.getTestResults(query, 0);
916 function quickAddFilter() {
918 if (!inPreferences()) {
919 query = "backend.php?op=pref-filters&method=newfilter&feed=" +
920 param_escape(getActiveFeedId()) + "&is_cat=" +
921 param_escape(activeFeedIsCat());
923 query = "backend.php?op=pref-filters&method=newfilter";
928 if (dijit.byId("feedEditDlg"))
929 dijit.byId("feedEditDlg").destroyRecursive();
931 if (dijit.byId("filterEditDlg"))
932 dijit.byId("filterEditDlg").destroyRecursive();
934 const dialog = new dijit.Dialog({
936 title: __("Create Filter"),
937 style: "width: 600px",
939 const query = "backend.php?" + dojo.formToQuery("filter_new_form") + "&savemode=test";
941 editFilterTest(query);
943 selectRules: function(select) {
944 $$("#filterDlg_Matches input[type=checkbox]").each(function(e) {
947 e.parentNode.addClassName("Selected");
949 e.parentNode.removeClassName("Selected");
952 selectActions: function(select) {
953 $$("#filterDlg_Actions input[type=checkbox]").each(function(e) {
957 e.parentNode.addClassName("Selected");
959 e.parentNode.removeClassName("Selected");
963 editRule: function(e) {
964 const li = e.parentNode;
965 const rule = li.getElementsByTagName("INPUT")[1].value;
966 addFilterRule(li, rule);
968 editAction: function(e) {
969 const li = e.parentNode;
970 const action = li.getElementsByTagName("INPUT")[1].value;
971 addFilterAction(li, action);
973 addAction: function() { addFilterAction(); },
974 addRule: function() { addFilterRule(); },
975 deleteAction: function() {
976 $$("#filterDlg_Actions li[class*=Selected]").each(function(e) { e.parentNode.removeChild(e) });
978 deleteRule: function() {
979 $$("#filterDlg_Matches li[class*=Selected]").each(function(e) { e.parentNode.removeChild(e) });
981 execute: function() {
982 if (this.validate()) {
984 const query = dojo.formToQuery("filter_new_form");
988 new Ajax.Request("backend.php", {
990 onComplete: function (transport) {
991 if (inPreferences()) {
1001 if (!inPreferences()) {
1002 const selectedText = getSelectionText();
1004 var lh = dojo.connect(dialog, "onLoad", function(){
1005 dojo.disconnect(lh);
1007 if (selectedText != "") {
1009 const feed_id = activeFeedIsCat() ? 'CAT:' + parseInt(getActiveFeedId()) :
1012 const rule = { reg_exp: selectedText, feed_id: [feed_id], filter_type: 1 };
1014 addFilterRule(null, dojo.toJson(rule));
1018 const query = "op=rpc&method=getlinktitlebyid&id=" + getActiveArticleId();
1020 new Ajax.Request("backend.php", {
1022 onComplete: function(transport) {
1023 const reply = JSON.parse(transport.responseText);
1027 if (reply && reply.title) title = reply.title;
1029 if (title || getActiveFeedId() || activeFeedIsCat()) {
1031 console.log(title + " " + getActiveFeedId());
1033 const feed_id = activeFeedIsCat() ? 'CAT:' + parseInt(getActiveFeedId()) :
1036 const rule = { reg_exp: title, feed_id: [feed_id], filter_type: 1 };
1038 addFilterRule(null, dojo.toJson(rule));
1052 function unsubscribeFeed(feed_id, title) {
1054 const msg = __("Unsubscribe from %s?").replace("%s", title);
1056 if (title == undefined || confirm(msg)) {
1057 notify_progress("Removing feed...");
1059 const query = "?op=pref-feeds&quiet=1&method=remove&ids=" + feed_id;
1061 new Ajax.Request("backend.php", {
1063 onComplete: function(transport) {
1065 if (dijit.byId("feedEditDlg")) dijit.byId("feedEditDlg").hide();
1067 if (inPreferences()) {
1070 if (feed_id == getActiveFeedId())
1071 setTimeout(function() { viewfeed({feed:-5}) }, 100);
1073 if (feed_id < 0) updateFeedList();
1083 function backend_sanity_check_callback(transport) {
1085 if (sanity_check_done) {
1086 fatalError(11, "Sanity check request received twice. This can indicate "+
1087 "presence of Firebug or some other disrupting extension. "+
1088 "Please disable it and try again.");
1092 const reply = JSON.parse(transport.responseText);
1095 fatalError(3, "Sanity check: invalid RPC reply", transport.responseText);
1099 const error_code = reply['error']['code'];
1101 if (error_code && error_code != 0) {
1102 return fatalError(error_code, reply['error']['message']);
1105 console.log("sanity check ok");
1107 const params = reply['init-params'];
1110 console.log('reading init-params...');
1112 for (const k in params) {
1113 console.log("IP: " + k + " => " + JSON.stringify(params[k]));
1114 if (k == "label_base_index") _label_base_index = parseInt(params[k]);
1117 init_params = params;
1119 // PluginHost might not be available on non-index pages
1120 window.PluginHost && PluginHost.run(PluginHost.HOOK_PARAMS_LOADED, init_params);
1123 sanity_check_done = true;
1125 init_second_stage();
1129 function genUrlChangeKey(feed, is_cat) {
1130 const ok = confirm(__("Generate new syndication address for this feed?"));
1134 notify_progress("Trying to change address...", true);
1136 const query = "?op=pref-feeds&method=regenFeedKey&id=" + param_escape(feed) +
1137 "&is_cat=" + param_escape(is_cat);
1139 new Ajax.Request("backend.php", {
1141 onComplete: function(transport) {
1142 const reply = JSON.parse(transport.responseText);
1143 const new_link = reply.link;
1145 const e = $('gen_feed_url');
1149 e.innerHTML = e.innerHTML.replace(/\&key=.*$/,
1150 "&key=" + new_link);
1152 e.href = e.href.replace(/\&key=.*$/,
1153 "&key=" + new_link);
1155 new Effect.Highlight(e);
1160 notify_error("Could not change feed URL.");
1167 // mode = all, none, invert
1168 function selectTableRows(id, mode) {
1169 const rows = $(id).rows;
1171 for (let i = 0; i < rows.length; i++) {
1172 const row = rows[i];
1176 if (row.id && row.className) {
1177 const bare_id = row.id.replace(/^[A-Z]*?-/, "");
1178 const inputs = rows[i].getElementsByTagName("input");
1180 for (let j = 0; j < inputs.length; j++) {
1181 const input = inputs[j];
1183 if (input.getAttribute("type") == "checkbox" &&
1184 input.id.match(bare_id)) {
1187 dcb = dijit.getEnclosingWidget(cb);
1193 const issel = row.hasClassName("Selected");
1195 if (mode == "all" && !issel) {
1196 row.addClassName("Selected");
1198 if (dcb) dcb.set("checked", true);
1199 } else if (mode == "none" && issel) {
1200 row.removeClassName("Selected");
1202 if (dcb) dcb.set("checked", false);
1204 } else if (mode == "invert") {
1207 row.removeClassName("Selected");
1209 if (dcb) dcb.set("checked", false);
1211 row.addClassName("Selected");
1213 if (dcb) dcb.set("checked", true);
1222 function getSelectedTableRowIds(id) {
1225 const elem_rows = $(id).rows;
1227 for (let i = 0; i < elem_rows.length; i++) {
1228 if (elem_rows[i].hasClassName("Selected")) {
1229 const bare_id = elem_rows[i].id.replace(/^[A-Z]*?-/, "");
1237 function editFeed(feed) {
1239 return alert(__("You can't edit this kind of feed."));
1241 const query = "backend.php?op=pref-feeds&method=editfeed&id=" +
1246 if (dijit.byId("filterEditDlg"))
1247 dijit.byId("filterEditDlg").destroyRecursive();
1249 if (dijit.byId("feedEditDlg"))
1250 dijit.byId("feedEditDlg").destroyRecursive();
1252 const dialog = new dijit.Dialog({
1254 title: __("Edit Feed"),
1255 style: "width: 600px",
1256 execute: function() {
1257 if (this.validate()) {
1258 // console.log(dojo.objectToQuery(this.attr('value')));
1260 notify_progress("Saving data...", true);
1262 new Ajax.Request("backend.php", {
1263 parameters: dojo.objectToQuery(dialog.attr('value')),
1264 onComplete: function(transport) {
1276 function feedBrowser() {
1277 const query = "backend.php?op=feeds&method=feedBrowser";
1279 if (dijit.byId("feedAddDlg"))
1280 dijit.byId("feedAddDlg").hide();
1282 if (dijit.byId("feedBrowserDlg"))
1283 dijit.byId("feedBrowserDlg").destroyRecursive();
1285 const dialog = new dijit.Dialog({
1286 id: "feedBrowserDlg",
1287 title: __("More Feeds"),
1288 style: "width: 600px",
1289 getSelectedFeedIds: function () {
1290 const list = $$("#browseFeedList li[id*=FBROW]");
1291 const selected = [];
1293 list.each(function (child) {
1294 const id = child.id.replace("FBROW-", "");
1296 if (child.hasClassName('Selected')) {
1303 getSelectedFeeds: function () {
1304 const list = $$("#browseFeedList li.Selected");
1305 const selected = [];
1307 list.each(function (child) {
1308 const title = child.getElementsBySelector("span.fb_feedTitle")[0].innerHTML;
1309 const url = child.getElementsBySelector("a.fb_feedUrl")[0].href;
1311 selected.push([title, url]);
1318 subscribe: function () {
1319 const mode = this.attr('value').mode;
1323 selected = this.getSelectedFeeds();
1325 selected = this.getSelectedFeedIds();
1327 if (selected.length > 0) {
1328 dijit.byId("feedBrowserDlg").hide();
1330 notify_progress("Loading, please wait...", true);
1332 // we use dojo.toJson instead of JSON.stringify because
1333 // it somehow escapes everything TWICE, at least in Chrome 9
1335 const query = "?op=rpc&method=massSubscribe&payload=" +
1336 param_escape(dojo.toJson(selected)) + "&mode=" + param_escape(mode);
1340 new Ajax.Request("backend.php", {
1342 onComplete: function (transport) {
1349 alert(__("No feeds are selected."));
1353 update: function () {
1354 const query = dojo.objectToQuery(dialog.attr('value'));
1356 Element.show('feed_browser_spinner');
1358 new Ajax.Request("backend.php", {
1360 onComplete: function (transport) {
1363 Element.hide('feed_browser_spinner');
1365 const reply = JSON.parse(transport.responseText);
1366 const mode = reply['mode'];
1368 if ($("browseFeedList") && reply['content']) {
1369 $("browseFeedList").innerHTML = reply['content'];
1372 dojo.parser.parse("browseFeedList");
1375 Element.show(dijit.byId('feed_archive_remove').domNode);
1377 Element.hide(dijit.byId('feed_archive_remove').domNode);
1383 removeFromArchive: function () {
1384 const selected = this.getSelectedFeedIds();
1386 if (selected.length > 0) {
1388 const pr = __("Remove selected feeds from the archive? Feeds with stored articles will not be removed.");
1391 Element.show('feed_browser_spinner');
1393 const query = "?op=rpc&method=remarchive&ids=" +
1394 param_escape(selected.toString());
1397 new Ajax.Request("backend.php", {
1399 onComplete: function (transport) {
1406 execute: function () {
1407 if (this.validate()) {
1417 function showFeedsWithErrors() {
1418 const query = "backend.php?op=pref-feeds&method=feedsWithErrors";
1420 if (dijit.byId("errorFeedsDlg"))
1421 dijit.byId("errorFeedsDlg").destroyRecursive();
1423 const dialog = new dijit.Dialog({
1424 id: "errorFeedsDlg",
1425 title: __("Feeds with update errors"),
1426 style: "width: 600px",
1427 getSelectedFeeds: function() {
1428 return getSelectedTableRowIds("prefErrorFeedList");
1430 removeSelected: function() {
1431 const sel_rows = this.getSelectedFeeds();
1433 console.log(sel_rows);
1435 if (sel_rows.length > 0) {
1436 const ok = confirm(__("Remove selected feeds?"));
1439 notify_progress("Removing selected feeds...", true);
1441 const query = "?op=pref-feeds&method=remove&ids="+
1442 param_escape(sel_rows.toString());
1444 new Ajax.Request("backend.php", {
1446 onComplete: function(transport) {
1454 alert(__("No feeds are selected."));
1457 execute: function() {
1458 if (this.validate()) {
1466 function get_timestamp() {
1467 const date = new Date();
1468 return Math.round(date.getTime() / 1000);
1471 function helpDialog(topic) {
1472 const query = "backend.php?op=backend&method=help&topic=" + param_escape(topic);
1474 if (dijit.byId("helpDlg"))
1475 dijit.byId("helpDlg").destroyRecursive();
1477 const dialog = new dijit.Dialog({
1480 style: "width: 600px",
1487 function htmlspecialchars_decode (string, quote_style) {
1488 // http://kevin.vanzonneveld.net
1489 // + original by: Mirek Slugen
1490 // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
1491 // + bugfixed by: Mateusz "loonquawl" Zalega
1492 // + input by: ReverseSyntax
1493 // + input by: Slawomir Kaniecki
1494 // + input by: Scott Cariss
1495 // + input by: Francois
1496 // + bugfixed by: Onno Marsman
1497 // + revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
1498 // + bugfixed by: Brett Zamir (http://brett-zamir.me)
1499 // + input by: Ratheous
1500 // + input by: Mailfaker (http://www.weedem.fr/)
1501 // + reimplemented by: Brett Zamir (http://brett-zamir.me)
1502 // + bugfixed by: Brett Zamir (http://brett-zamir.me)
1503 // * example 1: htmlspecialchars_decode("<p>this -> "</p>", 'ENT_NOQUOTES');
1504 // * returns 1: '<p>this -> "</p>'
1505 // * example 2: htmlspecialchars_decode("&quot;");
1506 // * returns 2: '"'
1510 if (typeof quote_style === 'undefined') {
1513 string = string.toString().replace(/</g, '<').replace(/>/g, '>');
1516 'ENT_HTML_QUOTE_SINGLE': 1,
1517 'ENT_HTML_QUOTE_DOUBLE': 2,
1522 if (quote_style === 0) {
1525 if (typeof quote_style !== 'number') { // Allow for a single string or an array of string flags
1526 quote_style = [].concat(quote_style);
1527 for (i = 0; i < quote_style.length; i++) {
1528 // Resolve string input to bitwise e.g. 'PATHINFO_EXTENSION' becomes 4
1529 if (OPTS[quote_style[i]] === 0) {
1531 } else if (OPTS[quote_style[i]]) {
1532 optTemp = optTemp | OPTS[quote_style[i]];
1535 quote_style = optTemp;
1537 if (quote_style & OPTS.ENT_HTML_QUOTE_SINGLE) {
1538 string = string.replace(/�*39;/g, "'"); // PHP doesn't currently escape if more than one 0, but it should
1539 // string = string.replace(/'|�*27;/g, "'"); // This would also be useful here, but not a part of PHP
1542 string = string.replace(/"/g, '"');
1544 // Put this in last place to avoid escape being double-decoded
1545 string = string.replace(/&/g, '&');
1551 function label_to_feed_id(label) {
1552 return _label_base_index - 1 - Math.abs(label);
1555 function feed_to_label_id(feed) {
1556 return _label_base_index - 1 + Math.abs(feed);
1559 // http://stackoverflow.com/questions/6251937/how-to-get-selecteduser-highlighted-text-in-contenteditable-element-and-replac
1561 function getSelectionText() {
1564 if (typeof window.getSelection != "undefined") {
1565 const sel = window.getSelection();
1566 if (sel.rangeCount) {
1567 const container = document.createElement("div");
1568 for (let i = 0, len = sel.rangeCount; i < len; ++i) {
1569 container.appendChild(sel.getRangeAt(i).cloneContents());
1571 text = container.innerHTML;
1573 } else if (typeof document.selection != "undefined") {
1574 if (document.selection.type == "Text") {
1575 text = document.selection.createRange().textText;
1579 return text.stripTags();
1582 function openUrlPopup(url) {
1583 const w = window.open("");
1588 function openArticlePopup(id) {
1589 const w = window.open("",
1590 "ttrss_article_popup",
1591 "height=900,width=900,resizable=yes,status=no,location=no,menubar=no,directories=no,scrollbars=yes,toolbar=no");
1594 w.location = "backend.php?op=article&method=view&mode=raw&html=1&zoom=1&id=" + id + "&csrf_token=" + getInitParam("csrf_token");