]>
git.wh0rd.org - tt-rss.git/blob - js/functions.js
7fbb4e75d59641ab0c83df45c5f63b2617ee3a1a
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=" +
340 param_escape(id
) + "¶m=" + param_escape(param
);
342 new Ajax
.Request("backend.php", {
344 onComplete: function (transport
) {
345 infobox_callback2(transport
, title
);
346 if (callback
) callback(transport
);
352 function infobox_callback2(transport
, title
) {
355 if (dijit
.byId("infoBox")) {
356 dialog
= dijit
.byId("infoBox");
359 //console.log("infobox_callback2");
362 const content
= transport
.responseText
;
365 dialog
= new dijit
.Dialog({
368 style
: "width: 600px",
369 onCancel: function() {
372 onExecute: function() {
375 onClose: function() {
380 dialog
.attr('title', title
);
381 dialog
.attr('content', content
);
389 function getInitParam(key
) {
390 return init_params
[key
];
393 function setInitParam(key
, value
) {
394 init_params
[key
] = value
;
397 function fatalError(code
, msg
, ext_info
) {
399 window
.location
.href
= "index.php";
400 } else if (code
== 5) {
401 window
.location
.href
= "public.php?op=dbupdate";
404 if (msg
== "") msg
= "Unknown error";
407 if (ext_info
.responseText
) {
408 ext_info
= ext_info
.responseText
;
412 if (ERRORS
&& ERRORS
[code
] && !msg
) {
416 let content
= "<div><b>Error code:</b> " + code
+ "</div>" +
417 "<p>" + msg
+ "</p>";
420 content
= content
+ "<div><b>Additional information:</b></div>" +
421 "<textarea style='width: 100%' readonly=\"1\">" +
422 ext_info
+ "</textarea>";
425 const dialog
= new dijit
.Dialog({
426 title
: "Fatal error",
427 style
: "width: 600px",
438 function filterDlgCheckAction(sender
) {
439 const action
= sender
.value
;
441 const action_param
= $("filterDlg_paramBox");
444 console
.log("filterDlgCheckAction: can't find action param box!");
448 // if selected action supports parameters, enable params field
449 if (action
== 4 || action
== 6 || action
== 7 || action
== 9) {
450 new Effect
.Appear(action_param
, {duration
: 0.5});
452 Element
.hide(dijit
.byId("filterDlg_actionParam").domNode
);
453 Element
.hide(dijit
.byId("filterDlg_actionParamLabel").domNode
);
454 Element
.hide(dijit
.byId("filterDlg_actionParamPlugin").domNode
);
457 Element
.show(dijit
.byId("filterDlg_actionParamLabel").domNode
);
458 } else if (action
== 9) {
459 Element
.show(dijit
.byId("filterDlg_actionParamPlugin").domNode
);
461 Element
.show(dijit
.byId("filterDlg_actionParam").domNode
);
465 Element
.hide(action_param
);
470 function explainError(code
) {
471 return displayDlg(__("Error explained"), "explainError", code
);
474 function loading_set_progress(p
) {
475 loading_progress
+= p
;
477 if (dijit
.byId("loading_bar"))
478 dijit
.byId("loading_bar").update({progress
: loading_progress
});
480 if (loading_progress
>= 90)
485 function remove_splash() {
486 Element
.hide("overlay");
489 function strip_tags(s
) {
490 return s
.replace(/<\/?[^>]+(>|$)/g, "");
493 function hotkey_prefix_timeout() {
495 const date
= new Date();
496 const ts
= Math
.round(date
.getTime() / 1000);
498 if (hotkey_prefix_pressed
&& ts
- hotkey_prefix_pressed
>= 5) {
499 console
.log("hotkey_prefix seems to be stuck, aborting");
500 hotkey_prefix_pressed
= false;
501 hotkey_prefix
= false;
502 Element
.hide('cmdline');
505 setTimeout(hotkey_prefix_timeout
, 1000);
509 function uploadIconHandler(rc
) {
512 notify_info("Upload complete.");
513 if (inPreferences()) {
516 setTimeout('updateFeedList(false, false)', 50);
520 notify_error("Upload failed: icon is too big.");
523 notify_error("Upload failed.");
528 function removeFeedIcon(id
) {
529 if (confirm(__("Remove stored feed icon?"))) {
530 const query
= "backend.php?op=pref-feeds&method=removeicon&feed_id=" + param_escape(id
);
534 notify_progress("Removing feed icon...", true);
536 new Ajax
.Request("backend.php", {
538 onComplete: function(transport
) {
539 notify_info("Feed icon removed.");
540 if (inPreferences()) {
543 setTimeout('updateFeedList(false, false)', 50);
551 function uploadFeedIcon() {
552 const file
= $("icon_file");
554 if (file
.value
.length
== 0) {
555 alert(__("Please select an image file to upload."));
556 } else if (confirm(__("Upload new icon for this feed?"))) {
557 notify_progress("Uploading, please wait...", true);
564 function addLabel(select
, callback
) {
566 const caption
= prompt(__("Please enter label caption:"), "");
568 if (caption
!= undefined) {
571 alert(__("Can't create label: missing caption."));
575 let query
= "?op=pref-labels&method=add&caption=" +
576 param_escape(caption
);
579 query
+= "&output=select";
581 notify_progress("Loading, please wait...", true);
583 new Ajax
.Request("backend.php", {
585 onComplete: function(transport
) {
588 } else if (inPreferences()) {
599 function quickAddFeed() {
600 const query
= "backend.php?op=feeds&method=quickAddFeed";
602 // overlapping widgets
603 if (dijit
.byId("batchSubDlg")) dijit
.byId("batchSubDlg").destroyRecursive();
604 if (dijit
.byId("feedAddDlg")) dijit
.byId("feedAddDlg").destroyRecursive();
606 const dialog
= new dijit
.Dialog({
608 title
: __("Subscribe to Feed"),
609 style
: "width: 600px",
610 show_error: function(msg
) {
611 const elem
= $("fadd_error_message");
613 elem
.innerHTML
= msg
;
615 if (!Element
.visible(elem
))
616 new Effect
.Appear(elem
);
619 execute: function() {
620 if (this.validate()) {
621 console
.log(dojo
.objectToQuery(this.attr('value')));
623 const feed_url
= this.attr('value').feed
;
625 Element
.show("feed_add_spinner");
626 Element
.hide("fadd_error_message");
628 new Ajax
.Request("backend.php", {
629 parameters
: dojo
.objectToQuery(this.attr('value')),
630 onComplete: function(transport
) {
634 var reply
= JSON
.parse(transport
.responseText
);
636 Element
.hide("feed_add_spinner");
637 alert(__("Failed to parse output. This can indicate server timeout and/or network issues. Backend output was logged to browser console."));
638 console
.log('quickAddFeed, backend returned:' + transport
.responseText
);
642 const rc
= reply
['result'];
645 Element
.hide("feed_add_spinner");
649 switch (parseInt(rc
['code'])) {
652 notify_info(__("Subscribed to %s").replace("%s", feed_url
));
657 dialog
.show_error(__("Specified URL seems to be invalid."));
660 dialog
.show_error(__("Specified URL doesn't seem to contain any feeds."));
663 var feeds
= rc
['feeds'];
665 Element
.show("fadd_multiple_notify");
667 var select
= dijit
.byId("feedDlg_feedContainerSelect");
669 while (select
.getOptions().length
> 0)
670 select
.removeOption(0);
672 select
.addOption({value
: '', label
: __("Expand to select feed")});
675 for (const feedUrl
in feeds
) {
676 select
.addOption({value
: feedUrl
, label
: feeds
[feedUrl
]});
680 Effect
.Appear('feedDlg_feedsContainer', {duration
: 0.5});
684 dialog
.show_error(__("Couldn't download the specified URL: %s").
685 replace("%s", rc
['message']));
688 dialog
.show_error(__("XML validation failed: %s").
689 replace("%s", rc
['message']));
692 dialog
.show_error(__("You are already subscribed to this feed."));
697 console
.error(transport
.responseText
);
710 function createNewRuleElement(parentNode
, replaceNode
) {
711 const form
= document
.forms
["filter_new_rule_form"];
713 //form.reg_exp.value = form.reg_exp.value.replace(/(<([^>]+)>)/ig,"");
715 const query
= "backend.php?op=pref-filters&method=printrulename&rule="+
716 param_escape(dojo
.formToJson(form
));
720 new Ajax
.Request("backend.php", {
722 onComplete: function (transport
) {
724 const li
= dojo
.create("li");
726 const cb
= dojo
.create("input", { type
: "checkbox" }, li
);
728 new dijit
.form
.CheckBox({
729 onChange: function() {
730 toggleSelectListRow2(this) },
733 dojo
.create("input", { type
: "hidden",
735 value
: dojo
.formToJson(form
) }, li
);
737 dojo
.create("span", {
738 onclick: function() {
739 dijit
.byId('filterEditDlg').editRule(this);
741 innerHTML
: transport
.responseText
}, li
);
744 parentNode
.replaceChild(li
, replaceNode
);
746 parentNode
.appendChild(li
);
754 function createNewActionElement(parentNode
, replaceNode
) {
755 const form
= document
.forms
["filter_new_action_form"];
757 if (form
.action_id
.value
== 7) {
758 form
.action_param
.value
= form
.action_param_label
.value
;
759 } else if (form
.action_id
.value
== 9) {
760 form
.action_param
.value
= form
.action_param_plugin
.value
;
763 const query
= "backend.php?op=pref-filters&method=printactionname&action="+
764 param_escape(dojo
.formToJson(form
));
768 new Ajax
.Request("backend.php", {
770 onComplete: function (transport
) {
772 const li
= dojo
.create("li");
774 const cb
= dojo
.create("input", { type
: "checkbox" }, li
);
776 new dijit
.form
.CheckBox({
777 onChange: function() {
778 toggleSelectListRow2(this) },
781 dojo
.create("input", { type
: "hidden",
783 value
: dojo
.formToJson(form
) }, li
);
785 dojo
.create("span", {
786 onclick: function() {
787 dijit
.byId('filterEditDlg').editAction(this);
789 innerHTML
: transport
.responseText
}, li
);
792 parentNode
.replaceChild(li
, replaceNode
);
794 parentNode
.appendChild(li
);
804 function addFilterRule(replaceNode
, ruleStr
) {
805 if (dijit
.byId("filterNewRuleDlg"))
806 dijit
.byId("filterNewRuleDlg").destroyRecursive();
808 const query
= "backend.php?op=pref-filters&method=newrule&rule=" +
809 param_escape(ruleStr
);
811 const rule_dlg
= new dijit
.Dialog({
812 id
: "filterNewRuleDlg",
813 title
: ruleStr
? __("Edit rule") : __("Add rule"),
814 style
: "width: 600px",
815 execute: function() {
816 if (this.validate()) {
817 createNewRuleElement($("filterDlg_Matches"), replaceNode
);
826 function addFilterAction(replaceNode
, actionStr
) {
827 if (dijit
.byId("filterNewActionDlg"))
828 dijit
.byId("filterNewActionDlg").destroyRecursive();
830 const query
= "backend.php?op=pref-filters&method=newaction&action=" +
831 param_escape(actionStr
);
833 const rule_dlg
= new dijit
.Dialog({
834 id
: "filterNewActionDlg",
835 title
: actionStr
? __("Edit action") : __("Add action"),
836 style
: "width: 600px",
837 execute: function() {
838 if (this.validate()) {
839 createNewActionElement($("filterDlg_Actions"), replaceNode
);
848 function editFilterTest(query
) {
850 if (dijit
.byId("filterTestDlg"))
851 dijit
.byId("filterTestDlg").destroyRecursive();
853 var test_dlg
= new dijit
.Dialog({
855 title
: "Test Filter",
856 style
: "width: 600px",
860 getTestResults: function(query
, offset
) {
861 const updquery
= query
+ "&offset=" + offset
+ "&limit=" + test_dlg
.limit
;
863 console
.log("getTestResults:" + offset
);
865 new Ajax
.Request("backend.php", {
866 parameters
: updquery
,
867 onComplete: function (transport
) {
869 const result
= JSON
.parse(transport
.responseText
);
871 if (result
&& dijit
.byId("filterTestDlg") && dijit
.byId("filterTestDlg").open
) {
872 test_dlg
.results
+= result
.length
;
874 console
.log("got results:" + result
.length
);
876 $("prefFilterProgressMsg").innerHTML
= __("Looking for articles (%d processed, %f found)...")
877 .replace("%f", test_dlg
.results
)
878 .replace("%d", offset
);
880 console
.log(offset
+ " " + test_dlg
.max_offset
);
882 for (let i
= 0; i
< result
.length
; i
++) {
883 const tmp
= new Element("table");
884 tmp
.innerHTML
= result
[i
];
885 dojo
.parser
.parse(tmp
);
887 $("prefFilterTestResultList").innerHTML
+= tmp
.innerHTML
;
890 if (test_dlg
.results
< 30 && offset
< test_dlg
.max_offset
) {
892 // get the next batch
893 window
.setTimeout(function () {
894 test_dlg
.getTestResults(query
, offset
+ test_dlg
.limit
);
900 Element
.hide("prefFilterLoadingIndicator");
902 if (test_dlg
.results
== 0) {
903 $("prefFilterTestResultList").innerHTML
= "<tr><td align='center'>No recent articles matching this filter have been found.</td></tr>";
904 $("prefFilterProgressMsg").innerHTML
= "Articles matching this filter:";
906 $("prefFilterProgressMsg").innerHTML
= __("Found %d articles matching this filter:")
907 .replace("%d", test_dlg
.results
);
912 } else if (!result
) {
913 console
.log("getTestResults: can't parse results object");
915 Element
.hide("prefFilterLoadingIndicator");
917 notify_error("Error while trying to get filter test results.");
920 console
.log("getTestResults: dialog closed, bailing out.");
930 dojo
.connect(test_dlg
, "onLoad", null, function(e
) {
931 test_dlg
.getTestResults(query
, 0);
938 function quickAddFilter() {
940 if (!inPreferences()) {
941 query
= "backend.php?op=pref-filters&method=newfilter&feed=" +
942 param_escape(getActiveFeedId()) + "&is_cat=" +
943 param_escape(activeFeedIsCat());
945 query
= "backend.php?op=pref-filters&method=newfilter";
950 if (dijit
.byId("feedEditDlg"))
951 dijit
.byId("feedEditDlg").destroyRecursive();
953 if (dijit
.byId("filterEditDlg"))
954 dijit
.byId("filterEditDlg").destroyRecursive();
956 const dialog
= new dijit
.Dialog({
958 title
: __("Create Filter"),
959 style
: "width: 600px",
961 const query
= "backend.php?" + dojo
.formToQuery("filter_new_form") + "&savemode=test";
963 editFilterTest(query
);
965 selectRules: function(select
) {
966 $$("#filterDlg_Matches input[type=checkbox]").each(function(e
) {
969 e
.parentNode
.addClassName("Selected");
971 e
.parentNode
.removeClassName("Selected");
974 selectActions: function(select
) {
975 $$("#filterDlg_Actions input[type=checkbox]").each(function(e
) {
979 e
.parentNode
.addClassName("Selected");
981 e
.parentNode
.removeClassName("Selected");
985 editRule: function(e
) {
986 const li
= e
.parentNode
;
987 const rule
= li
.getElementsByTagName("INPUT")[1].value
;
988 addFilterRule(li
, rule
);
990 editAction: function(e
) {
991 const li
= e
.parentNode
;
992 const action
= li
.getElementsByTagName("INPUT")[1].value
;
993 addFilterAction(li
, action
);
995 addAction: function() { addFilterAction(); },
996 addRule: function() { addFilterRule(); },
997 deleteAction: function() {
998 $$("#filterDlg_Actions li[class*=Selected]").each(function(e
) { e
.parentNode
.removeChild(e
) });
1000 deleteRule: function() {
1001 $$("#filterDlg_Matches li[class*=Selected]").each(function(e
) { e
.parentNode
.removeChild(e
) });
1003 execute: function() {
1004 if (this.validate()) {
1006 const query
= dojo
.formToQuery("filter_new_form");
1010 new Ajax
.Request("backend.php", {
1012 onComplete: function (transport
) {
1013 if (inPreferences()) {
1023 if (!inPreferences()) {
1024 const selectedText
= getSelectionText();
1026 var lh
= dojo
.connect(dialog
, "onLoad", function(){
1027 dojo
.disconnect(lh
);
1029 if (selectedText
!= "") {
1031 const feed_id
= activeFeedIsCat() ? 'CAT:' + parseInt(getActiveFeedId()) :
1034 const rule
= { reg_exp
: selectedText
, feed_id
: [feed_id
], filter_type
: 1 };
1036 addFilterRule(null, dojo
.toJson(rule
));
1040 const query
= "op=rpc&method=getlinktitlebyid&id=" + getActiveArticleId();
1042 new Ajax
.Request("backend.php", {
1044 onComplete: function(transport
) {
1045 const reply
= JSON
.parse(transport
.responseText
);
1049 if (reply
&& reply
.title
) title
= reply
.title
;
1051 if (title
|| getActiveFeedId() || activeFeedIsCat()) {
1053 console
.log(title
+ " " + getActiveFeedId());
1055 const feed_id
= activeFeedIsCat() ? 'CAT:' + parseInt(getActiveFeedId()) :
1058 const rule
= { reg_exp
: title
, feed_id
: [feed_id
], filter_type
: 1 };
1060 addFilterRule(null, dojo
.toJson(rule
));
1074 function unsubscribeFeed(feed_id
, title
) {
1076 const msg
= __("Unsubscribe from %s?").replace("%s", title
);
1078 if (title
== undefined || confirm(msg
)) {
1079 notify_progress("Removing feed...");
1081 const query
= "?op=pref-feeds&quiet=1&method=remove&ids=" + feed_id
;
1083 new Ajax
.Request("backend.php", {
1085 onComplete: function(transport
) {
1087 if (dijit
.byId("feedEditDlg")) dijit
.byId("feedEditDlg").hide();
1089 if (inPreferences()) {
1092 if (feed_id
== getActiveFeedId())
1093 setTimeout(function() { viewfeed({feed
:-5}) }, 100);
1095 if (feed_id
< 0) updateFeedList();
1105 function backend_sanity_check_callback(transport
) {
1107 const reply
= JSON
.parse(transport
.responseText
);
1110 fatalError(3, "Sanity check: invalid RPC reply", transport
.responseText
);
1114 const error_code
= reply
['error']['code'];
1116 if (error_code
&& error_code
!= 0) {
1117 return fatalError(error_code
, reply
['error']['message']);
1120 console
.log("sanity check ok");
1122 const params
= reply
['init-params'];
1125 console
.log('reading init-params...');
1127 for (const k
in params
) {
1128 console
.log("IP: " + k
+ " => " + JSON
.stringify(params
[k
]));
1129 if (k
== "label_base_index") _label_base_index
= parseInt(params
[k
]);
1132 init_params
= params
;
1134 // PluginHost might not be available on non-index pages
1135 window
.PluginHost
&& PluginHost
.run(PluginHost
.HOOK_PARAMS_LOADED
, init_params
);
1138 init_second_stage();
1141 function genUrlChangeKey(feed
, is_cat
) {
1142 const ok
= confirm(__("Generate new syndication address for this feed?"));
1146 notify_progress("Trying to change address...", true);
1148 const query
= "?op=pref-feeds&method=regenFeedKey&id=" + param_escape(feed
) +
1149 "&is_cat=" + param_escape(is_cat
);
1151 new Ajax
.Request("backend.php", {
1153 onComplete: function(transport
) {
1154 const reply
= JSON
.parse(transport
.responseText
);
1155 const new_link
= reply
.link
;
1157 const e
= $('gen_feed_url');
1161 e
.innerHTML
= e
.innerHTML
.replace(/\&key=.*$/,
1162 "&key=" + new_link
);
1164 e
.href
= e
.href
.replace(/\&key=.*$/,
1165 "&key=" + new_link
);
1167 new Effect
.Highlight(e
);
1172 notify_error("Could not change feed URL.");
1179 // mode = all, none, invert
1180 function selectTableRows(id
, mode
) {
1181 const rows
= $(id
).rows
;
1183 for (let i
= 0; i
< rows
.length
; i
++) {
1184 const row
= rows
[i
];
1188 if (row
.id
&& row
.className
) {
1189 const bare_id
= row
.id
.replace(/^[A-Z]*?-/, "");
1190 const inputs
= rows
[i
].getElementsByTagName("input");
1192 for (let j
= 0; j
< inputs
.length
; j
++) {
1193 const input
= inputs
[j
];
1195 if (input
.getAttribute("type") == "checkbox" &&
1196 input
.id
.match(bare_id
)) {
1199 dcb
= dijit
.getEnclosingWidget(cb
);
1205 const issel
= row
.hasClassName("Selected");
1207 if (mode
== "all" && !issel
) {
1208 row
.addClassName("Selected");
1210 if (dcb
) dcb
.set("checked", true);
1211 } else if (mode
== "none" && issel
) {
1212 row
.removeClassName("Selected");
1214 if (dcb
) dcb
.set("checked", false);
1216 } else if (mode
== "invert") {
1219 row
.removeClassName("Selected");
1221 if (dcb
) dcb
.set("checked", false);
1223 row
.addClassName("Selected");
1225 if (dcb
) dcb
.set("checked", true);
1234 function getSelectedTableRowIds(id
) {
1237 const elem_rows
= $(id
).rows
;
1239 for (let i
= 0; i
< elem_rows
.length
; i
++) {
1240 if (elem_rows
[i
].hasClassName("Selected")) {
1241 const bare_id
= elem_rows
[i
].id
.replace(/^[A-Z]*?-/, "");
1249 function editFeed(feed
) {
1251 return alert(__("You can't edit this kind of feed."));
1253 const query
= "backend.php?op=pref-feeds&method=editfeed&id=" +
1258 if (dijit
.byId("filterEditDlg"))
1259 dijit
.byId("filterEditDlg").destroyRecursive();
1261 if (dijit
.byId("feedEditDlg"))
1262 dijit
.byId("feedEditDlg").destroyRecursive();
1264 const dialog
= new dijit
.Dialog({
1266 title
: __("Edit Feed"),
1267 style
: "width: 600px",
1268 execute: function() {
1269 if (this.validate()) {
1270 // console.log(dojo.objectToQuery(this.attr('value')));
1272 notify_progress("Saving data...", true);
1274 new Ajax
.Request("backend.php", {
1275 parameters
: dojo
.objectToQuery(dialog
.attr('value')),
1276 onComplete: function(transport
) {
1288 function feedBrowser() {
1289 const query
= "backend.php?op=feeds&method=feedBrowser";
1291 if (dijit
.byId("feedAddDlg"))
1292 dijit
.byId("feedAddDlg").hide();
1294 if (dijit
.byId("feedBrowserDlg"))
1295 dijit
.byId("feedBrowserDlg").destroyRecursive();
1297 const dialog
= new dijit
.Dialog({
1298 id
: "feedBrowserDlg",
1299 title
: __("More Feeds"),
1300 style
: "width: 600px",
1301 getSelectedFeedIds: function () {
1302 const list
= $$("#browseFeedList li[id*=FBROW]");
1303 const selected
= [];
1305 list
.each(function (child
) {
1306 const id
= child
.id
.replace("FBROW-", "");
1308 if (child
.hasClassName('Selected')) {
1315 getSelectedFeeds: function () {
1316 const list
= $$("#browseFeedList li.Selected");
1317 const selected
= [];
1319 list
.each(function (child
) {
1320 const title
= child
.getElementsBySelector("span.fb_feedTitle")[0].innerHTML
;
1321 const url
= child
.getElementsBySelector("a.fb_feedUrl")[0].href
;
1323 selected
.push([title
, url
]);
1330 subscribe: function () {
1331 const mode
= this.attr('value').mode
;
1335 selected
= this.getSelectedFeeds();
1337 selected
= this.getSelectedFeedIds();
1339 if (selected
.length
> 0) {
1340 dijit
.byId("feedBrowserDlg").hide();
1342 notify_progress("Loading, please wait...", true);
1344 // we use dojo.toJson instead of JSON.stringify because
1345 // it somehow escapes everything TWICE, at least in Chrome 9
1347 const query
= "?op=rpc&method=massSubscribe&payload=" +
1348 param_escape(dojo
.toJson(selected
)) + "&mode=" + param_escape(mode
);
1352 new Ajax
.Request("backend.php", {
1354 onComplete: function (transport
) {
1361 alert(__("No feeds are selected."));
1365 update: function () {
1366 const query
= dojo
.objectToQuery(dialog
.attr('value'));
1368 Element
.show('feed_browser_spinner');
1370 new Ajax
.Request("backend.php", {
1372 onComplete: function (transport
) {
1375 Element
.hide('feed_browser_spinner');
1377 const reply
= JSON
.parse(transport
.responseText
);
1378 const mode
= reply
['mode'];
1380 if ($("browseFeedList") && reply
['content']) {
1381 $("browseFeedList").innerHTML
= reply
['content'];
1384 dojo
.parser
.parse("browseFeedList");
1387 Element
.show(dijit
.byId('feed_archive_remove').domNode
);
1389 Element
.hide(dijit
.byId('feed_archive_remove').domNode
);
1395 removeFromArchive: function () {
1396 const selected
= this.getSelectedFeedIds();
1398 if (selected
.length
> 0) {
1400 const pr
= __("Remove selected feeds from the archive? Feeds with stored articles will not be removed.");
1403 Element
.show('feed_browser_spinner');
1405 const query
= "?op=rpc&method=remarchive&ids=" +
1406 param_escape(selected
.toString());
1409 new Ajax
.Request("backend.php", {
1411 onComplete: function (transport
) {
1418 execute: function () {
1419 if (this.validate()) {
1429 function showFeedsWithErrors() {
1430 const query
= "backend.php?op=pref-feeds&method=feedsWithErrors";
1432 if (dijit
.byId("errorFeedsDlg"))
1433 dijit
.byId("errorFeedsDlg").destroyRecursive();
1435 const dialog
= new dijit
.Dialog({
1436 id
: "errorFeedsDlg",
1437 title
: __("Feeds with update errors"),
1438 style
: "width: 600px",
1439 getSelectedFeeds: function() {
1440 return getSelectedTableRowIds("prefErrorFeedList");
1442 removeSelected: function() {
1443 const sel_rows
= this.getSelectedFeeds();
1445 console
.log(sel_rows
);
1447 if (sel_rows
.length
> 0) {
1448 const ok
= confirm(__("Remove selected feeds?"));
1451 notify_progress("Removing selected feeds...", true);
1453 const query
= "?op=pref-feeds&method=remove&ids="+
1454 param_escape(sel_rows
.toString());
1456 new Ajax
.Request("backend.php", {
1458 onComplete: function(transport
) {
1466 alert(__("No feeds are selected."));
1469 execute: function() {
1470 if (this.validate()) {
1478 function get_timestamp() {
1479 const date
= new Date();
1480 return Math
.round(date
.getTime() / 1000);
1483 function helpDialog(topic
) {
1484 const query
= "backend.php?op=backend&method=help&topic=" + param_escape(topic
);
1486 if (dijit
.byId("helpDlg"))
1487 dijit
.byId("helpDlg").destroyRecursive();
1489 const dialog
= new dijit
.Dialog({
1492 style
: "width: 600px",
1499 function htmlspecialchars_decode (string
, quote_style
) {
1500 // http://kevin.vanzonneveld.net
1501 // + original by: Mirek Slugen
1502 // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
1503 // + bugfixed by: Mateusz "loonquawl" Zalega
1504 // + input by: ReverseSyntax
1505 // + input by: Slawomir Kaniecki
1506 // + input by: Scott Cariss
1507 // + input by: Francois
1508 // + bugfixed by: Onno Marsman
1509 // + revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
1510 // + bugfixed by: Brett Zamir (http://brett-zamir.me)
1511 // + input by: Ratheous
1512 // + input by: Mailfaker (http://www.weedem.fr/)
1513 // + reimplemented by: Brett Zamir (http://brett-zamir.me)
1514 // + bugfixed by: Brett Zamir (http://brett-zamir.me)
1515 // * example 1: htmlspecialchars_decode("<p>this -> "</p>", 'ENT_NOQUOTES');
1516 // * returns 1: '<p>this -> "</p>'
1517 // * example 2: htmlspecialchars_decode("&quot;");
1518 // * returns 2: '"'
1522 if (typeof quote_style
=== 'undefined') {
1525 string
= string
.toString().replace(/</g, '<').replace(/>/g, '>');
1528 'ENT_HTML_QUOTE_SINGLE': 1,
1529 'ENT_HTML_QUOTE_DOUBLE': 2,
1534 if (quote_style
=== 0) {
1537 if (typeof quote_style
!== 'number') { // Allow for a single string or an array of string flags
1538 quote_style
= [].concat(quote_style
);
1539 for (i
= 0; i
< quote_style
.length
; i
++) {
1540 // Resolve string input to bitwise e.g. 'PATHINFO_EXTENSION' becomes 4
1541 if (OPTS
[quote_style
[i
]] === 0) {
1543 } else if (OPTS
[quote_style
[i
]]) {
1544 optTemp
= optTemp
| OPTS
[quote_style
[i
]];
1547 quote_style
= optTemp
;
1549 if (quote_style
& OPTS
.ENT_HTML_QUOTE_SINGLE
) {
1550 string
= string
.replace(/�*39;/g, "'"); // PHP doesn't currently escape if more than one 0, but it should
1551 // string = string.replace(/'|�*27;/g, "'"); // This would also be useful here, but not a part of PHP
1554 string
= string
.replace(/"/g, '"');
1556 // Put this in last place to avoid escape being double-decoded
1557 string
= string
.replace(/&/g, '&');
1563 function label_to_feed_id(label
) {
1564 return _label_base_index
- 1 - Math
.abs(label
);
1567 function feed_to_label_id(feed
) {
1568 return _label_base_index
- 1 + Math
.abs(feed
);
1571 // http://stackoverflow.com/questions/6251937/how-to-get-selecteduser-highlighted-text-in-contenteditable-element-and-replac
1573 function getSelectionText() {
1576 if (typeof window
.getSelection
!= "undefined") {
1577 const sel
= window
.getSelection();
1578 if (sel
.rangeCount
) {
1579 const container
= document
.createElement("div");
1580 for (let i
= 0, len
= sel
.rangeCount
; i
< len
; ++i
) {
1581 container
.appendChild(sel
.getRangeAt(i
).cloneContents());
1583 text
= container
.innerHTML
;
1585 } else if (typeof document
.selection
!= "undefined") {
1586 if (document
.selection
.type
== "Text") {
1587 text
= document
.selection
.createRange().textText
;
1591 return text
.stripTags();
1594 function openUrlPopup(url
) {
1595 const w
= window
.open("");
1600 function openArticlePopup(id
) {
1601 const w
= window
.open("",
1602 "ttrss_article_popup",
1603 "height=900,width=900,resizable=yes,status=no,location=no,menubar=no,directories=no,scrollbars=yes,toolbar=no");
1606 w
.location
= "backend.php?op=article&method=view&mode=raw&html=1&zoom=1&id=" + id
+ "&csrf_token=" + getInitParam("csrf_token");