]>
git.wh0rd.org - tt-rss.git/blob - js/functions.js
1 var loading_progress
= 0;
2 var sanity_check_done
= false;
4 var _label_base_index
= -1024;
5 var notify_hide_timerid
= false;
7 Ajax
.Base
.prototype.initialize
= Ajax
.Base
.prototype.initialize
.wrap(
8 function (callOriginal
, options
) {
10 if (getInitParam("csrf_token") != undefined) {
11 Object
.extend(options
, options
|| { });
13 if (Object
.isString(options
.parameters
))
14 options
.parameters
= options
.parameters
.toQueryParams();
15 else if (Object
.isHash(options
.parameters
))
16 options
.parameters
= options
.parameters
.toObject();
18 options
.parameters
["csrf_token"] = getInitParam("csrf_token");
21 return callOriginal(options
);
25 /* add method to remove element from array */
27 Array
.prototype.remove = function(s
) {
28 for (let i
=0; i
< this.length
; i
++) {
29 if (s
== this[i
]) this.splice(i
, 1);
33 function report_error(message
, filename
, lineno
, colno
, error
) {
34 exception_error(error
, null, filename
, lineno
);
37 function exception_error(e
, e_compat
, filename
, lineno
, colno
) {
38 if (typeof e
== "string") e
= e_compat
;
40 if (!e
) return; // no exception object, nothing to report.
44 const msg
= e
.toString();
47 new Ajax
.Request("backend.php", {
48 parameters
: {op
: "rpc", method
: "log",
49 file
: e
.fileName
? e
.fileName
: filename
,
50 line
: e
.lineNumber
? e
.lineNumber
: lineno
,
51 msg
: msg
, context
: e
.stack
},
52 onComplete: function (transport
) {
53 console
.warn(transport
.responseText
);
57 console
.error("Exception while trying to log the error.", e
);
60 let content
= "<div class='fatalError'><p>" + msg
+ "</p>";
63 content
+= "<div><b>Stack trace:</b></div>" +
64 "<textarea name=\"stack\" readonly=\"1\">" + e
.stack
+ "</textarea>";
69 content
+= "<div class='dlgButtons'>";
71 content
+= "<button dojoType=\"dijit.form.Button\" "+
72 "onclick=\"dijit.byId('exceptionDlg').hide()\">" +
73 __('Close') + "</button>";
76 if (dijit
.byId("exceptionDlg"))
77 dijit
.byId("exceptionDlg").destroyRecursive();
79 const dialog
= new dijit
.Dialog({
81 title
: "Unhandled exception",
82 style
: "width: 600px",
88 console
.error("Exception while trying to report an exception:", ei
);
89 console
.error("Original exception:", e
);
91 alert("Exception occured while trying to report an exception.\n" +
92 ei
.stack
+ "\n\nOriginal exception:\n" + e
.stack
);
97 function param_escape(arg
) {
98 return encodeURIComponent(arg
);
101 function notify_real(msg
, no_hide
, n_type
) {
103 const n
= $("notify");
107 if (notify_hide_timerid
) {
108 window
.clearTimeout(notify_hide_timerid
);
112 if (n
.hasClassName("visible")) {
113 notify_hide_timerid
= window
.setTimeout(function() {
114 n
.removeClassName("visible") }, 0);
128 msg
= "<span class=\"msg\"> " + __(msg
) + "</span>";
131 msg
= "<span><img src=\""+getInitParam("icon_indicator_white")+"\"></span>" + msg
;
133 } else if (n_type
== 3) {
134 msg
= "<span><img src=\""+getInitParam("icon_alert")+"\"></span>" + msg
;
135 } else if (n_type
== 4) {
136 msg
= "<span><img src=\""+getInitParam("icon_information")+"\"></span>" + msg
;
139 msg
+= " <span><img src=\""+getInitParam("icon_cross")+"\" class=\"close\" title=\"" +
140 __("Click to close") + "\" onclick=\"notify('')\"></span>";
144 window
.setTimeout(function() {
147 n
.className
= "notify notify_progress visible";
148 } else if (n_type
== 3) {
149 n
.className
= "notify notify_error visible";
150 msg
= "<span><img src='images/alert.png'></span>" + msg
;
151 } else if (n_type
== 4) {
152 n
.className
= "notify notify_info visible";
154 n
.className
= "notify visible";
158 notify_hide_timerid
= window
.setTimeout(function() {
159 n
.removeClassName("visible") }, 5*1000);
166 function notify(msg
, no_hide
) {
167 notify_real(msg
, no_hide
, 1);
170 function notify_progress(msg
, no_hide
) {
171 notify_real(msg
, no_hide
, 2);
174 function notify_error(msg
, no_hide
) {
175 notify_real(msg
, no_hide
, 3);
179 function notify_info(msg
, no_hide
) {
180 notify_real(msg
, no_hide
, 4);
183 function setCookie(name
, value
, lifetime
, path
, domain
, secure
) {
189 d
.setTime(d
.getTime() + (lifetime
* 1000));
192 console
.log("setCookie: " + name
+ " => " + value
+ ": " + d
);
194 int_setCookie(name
, value
, d
, path
, domain
, secure
);
198 function int_setCookie(name
, value
, expires
, path
, domain
, secure
) {
199 document
.cookie
= name
+ "=" + escape(value
) +
200 ((expires
) ? "; expires=" + expires
.toGMTString() : "") +
201 ((path
) ? "; path=" + path
: "") +
202 ((domain
) ? "; domain=" + domain
: "") +
203 ((secure
) ? "; secure" : "");
206 function delCookie(name
, path
, domain
) {
207 if (getCookie(name
)) {
208 document
.cookie
= name
+ "=" +
209 ((path
) ? ";path=" + path
: "") +
210 ((domain
) ? ";domain=" + domain
: "" ) +
211 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
216 function getCookie(name
) {
218 const dc
= document
.cookie
;
219 const prefix
= name
+ "=";
220 let begin
= dc
.indexOf("; " + prefix
);
222 begin
= dc
.indexOf(prefix
);
223 if (begin
!= 0) return null;
228 let end
= document
.cookie
.indexOf(";", begin
);
232 return unescape(dc
.substring(begin
+ prefix
.length
, end
));
235 function gotoPreferences() {
236 document
.location
.href
= "prefs.php";
239 function gotoLogout() {
240 document
.location
.href
= "backend.php?op=logout";
243 function gotoMain() {
244 document
.location
.href
= "index.php";
247 function toggleSelectRowById(sender
, id
) {
249 return toggleSelectRow(sender
, row
);
252 /* this is for dijit Checkbox */
253 function toggleSelectListRow2(sender
) {
254 const row
= sender
.domNode
.parentNode
;
255 return toggleSelectRow(sender
, row
);
258 /* this is for dijit Checkbox */
259 function toggleSelectRow2(sender
, row
, is_cdm
) {
263 row
= sender
.domNode
.parentNode
.parentNode
;
265 row
= sender
.domNode
.parentNode
.parentNode
.parentNode
; // oh ffs
267 if (sender
.checked
&& !row
.hasClassName('Selected'))
268 row
.addClassName('Selected');
270 row
.removeClassName('Selected');
272 if (typeof updateSelectedPrompt
!= undefined)
273 updateSelectedPrompt();
277 function toggleSelectRow(sender
, row
) {
279 if (!row
) row
= sender
.parentNode
.parentNode
;
281 if (sender
.checked
&& !row
.hasClassName('Selected'))
282 row
.addClassName('Selected');
284 row
.removeClassName('Selected');
286 if (typeof updateSelectedPrompt
!= undefined)
287 updateSelectedPrompt();
290 function checkboxToggleElement(elem
, id
) {
292 Effect
.Appear(id
, {duration
: 0.5});
294 Effect
.Fade(id
, {duration
: 0.5});
298 function getURLParam(param
){
299 return String(window
.location
.href
).parseQuery()[param
];
302 function closeInfoBox() {
303 const dialog
= dijit
.byId("infoBox");
305 if (dialog
) dialog
.hide();
311 function displayDlg(title
, id
, param
, callback
) {
313 notify_progress("Loading, please wait...", true);
315 const query
= "?op=dlg&method=" +
316 param_escape(id
) + "¶m=" + param_escape(param
);
318 new Ajax
.Request("backend.php", {
320 onComplete: function (transport
) {
321 infobox_callback2(transport
, title
);
322 if (callback
) callback(transport
);
328 function infobox_callback2(transport
, title
) {
331 if (dijit
.byId("infoBox")) {
332 dialog
= dijit
.byId("infoBox");
335 //console.log("infobox_callback2");
338 const content
= transport
.responseText
;
341 dialog
= new dijit
.Dialog({
344 style
: "width: 600px",
345 onCancel: function() {
348 onExecute: function() {
351 onClose: function() {
356 dialog
.attr('title', title
);
357 dialog
.attr('content', content
);
365 function getInitParam(key
) {
366 return init_params
[key
];
369 function setInitParam(key
, value
) {
370 init_params
[key
] = value
;
373 function fatalError(code
, msg
, ext_info
) {
375 window
.location
.href
= "index.php";
376 } else if (code
== 5) {
377 window
.location
.href
= "public.php?op=dbupdate";
380 if (msg
== "") msg
= "Unknown error";
383 if (ext_info
.responseText
) {
384 ext_info
= ext_info
.responseText
;
388 if (ERRORS
&& ERRORS
[code
] && !msg
) {
392 let content
= "<div><b>Error code:</b> " + code
+ "</div>" +
393 "<p>" + msg
+ "</p>";
396 content
= content
+ "<div><b>Additional information:</b></div>" +
397 "<textarea style='width: 100%' readonly=\"1\">" +
398 ext_info
+ "</textarea>";
401 const dialog
= new dijit
.Dialog({
402 title
: "Fatal error",
403 style
: "width: 600px",
414 function filterDlgCheckAction(sender
) {
415 const action
= sender
.value
;
417 const action_param
= $("filterDlg_paramBox");
420 console
.log("filterDlgCheckAction: can't find action param box!");
424 // if selected action supports parameters, enable params field
425 if (action
== 4 || action
== 6 || action
== 7 || action
== 9) {
426 new Effect
.Appear(action_param
, {duration
: 0.5});
428 Element
.hide(dijit
.byId("filterDlg_actionParam").domNode
);
429 Element
.hide(dijit
.byId("filterDlg_actionParamLabel").domNode
);
430 Element
.hide(dijit
.byId("filterDlg_actionParamPlugin").domNode
);
433 Element
.show(dijit
.byId("filterDlg_actionParamLabel").domNode
);
434 } else if (action
== 9) {
435 Element
.show(dijit
.byId("filterDlg_actionParamPlugin").domNode
);
437 Element
.show(dijit
.byId("filterDlg_actionParam").domNode
);
441 Element
.hide(action_param
);
446 function explainError(code
) {
447 return displayDlg(__("Error explained"), "explainError", code
);
450 function loading_set_progress(p
) {
451 loading_progress
+= p
;
453 if (dijit
.byId("loading_bar"))
454 dijit
.byId("loading_bar").update({progress
: loading_progress
});
456 if (loading_progress
>= 90)
461 function remove_splash() {
463 if (Element
.visible("overlay")) {
464 console
.log("about to remove splash, OMG!");
465 Element
.hide("overlay");
466 console
.log("removed splash!");
470 function strip_tags(s
) {
471 return s
.replace(/<\/?[^>]+(>|$)/g, "");
474 function hotkey_prefix_timeout() {
476 const date
= new Date();
477 const ts
= Math
.round(date
.getTime() / 1000);
479 if (hotkey_prefix_pressed
&& ts
- hotkey_prefix_pressed
>= 5) {
480 console
.log("hotkey_prefix seems to be stuck, aborting");
481 hotkey_prefix_pressed
= false;
482 hotkey_prefix
= false;
483 Element
.hide('cmdline');
486 setTimeout(hotkey_prefix_timeout
, 1000);
490 function uploadIconHandler(rc
) {
493 notify_info("Upload complete.");
494 if (inPreferences()) {
497 setTimeout('updateFeedList(false, false)', 50);
501 notify_error("Upload failed: icon is too big.");
504 notify_error("Upload failed.");
509 function removeFeedIcon(id
) {
510 if (confirm(__("Remove stored feed icon?"))) {
511 const query
= "backend.php?op=pref-feeds&method=removeicon&feed_id=" + param_escape(id
);
515 notify_progress("Removing feed icon...", true);
517 new Ajax
.Request("backend.php", {
519 onComplete: function(transport
) {
520 notify_info("Feed icon removed.");
521 if (inPreferences()) {
524 setTimeout('updateFeedList(false, false)', 50);
532 function uploadFeedIcon() {
533 const file
= $("icon_file");
535 if (file
.value
.length
== 0) {
536 alert(__("Please select an image file to upload."));
537 } else if (confirm(__("Upload new icon for this feed?"))) {
538 notify_progress("Uploading, please wait...", true);
545 function addLabel(select
, callback
) {
547 const caption
= prompt(__("Please enter label caption:"), "");
549 if (caption
!= undefined) {
552 alert(__("Can't create label: missing caption."));
556 let query
= "?op=pref-labels&method=add&caption=" +
557 param_escape(caption
);
560 query
+= "&output=select";
562 notify_progress("Loading, please wait...", true);
564 new Ajax
.Request("backend.php", {
566 onComplete: function(transport
) {
569 } else if (inPreferences()) {
580 function quickAddFeed() {
581 const query
= "backend.php?op=feeds&method=quickAddFeed";
583 // overlapping widgets
584 if (dijit
.byId("batchSubDlg")) dijit
.byId("batchSubDlg").destroyRecursive();
585 if (dijit
.byId("feedAddDlg")) dijit
.byId("feedAddDlg").destroyRecursive();
587 var dialog
= new dijit
.Dialog({
589 title
: __("Subscribe to Feed"),
590 style
: "width: 600px",
591 show_error: function(msg
) {
592 const elem
= $("fadd_error_message");
594 elem
.innerHTML
= msg
;
596 if (!Element
.visible(elem
))
597 new Effect
.Appear(elem
);
600 execute: function() {
601 if (this.validate()) {
602 console
.log(dojo
.objectToQuery(this.attr('value')));
604 const feed_url
= this.attr('value').feed
;
606 Element
.show("feed_add_spinner");
607 Element
.hide("fadd_error_message");
609 new Ajax
.Request("backend.php", {
610 parameters
: dojo
.objectToQuery(this.attr('value')),
611 onComplete: function(transport
) {
615 var reply
= JSON
.parse(transport
.responseText
);
617 Element
.hide("feed_add_spinner");
618 alert(__("Failed to parse output. This can indicate server timeout and/or network issues. Backend output was logged to browser console."));
619 console
.log('quickAddFeed, backend returned:' + transport
.responseText
);
623 const rc
= reply
['result'];
626 Element
.hide("feed_add_spinner");
630 switch (parseInt(rc
['code'])) {
633 notify_info(__("Subscribed to %s").replace("%s", feed_url
));
638 dialog
.show_error(__("Specified URL seems to be invalid."));
641 dialog
.show_error(__("Specified URL doesn't seem to contain any feeds."));
644 var feeds
= rc
['feeds'];
646 Element
.show("fadd_multiple_notify");
648 var select
= dijit
.byId("feedDlg_feedContainerSelect");
650 while (select
.getOptions().length
> 0)
651 select
.removeOption(0);
653 select
.addOption({value
: '', label
: __("Expand to select feed")});
656 for (const feedUrl
in feeds
) {
657 select
.addOption({value
: feedUrl
, label
: feeds
[feedUrl
]});
661 Effect
.Appear('feedDlg_feedsContainer', {duration
: 0.5});
665 dialog
.show_error(__("Couldn't download the specified URL: %s").
666 replace("%s", rc
['message']));
669 dialog
.show_error(__("XML validation failed: %s").
670 replace("%s", rc
['message']));
673 dialog
.show_error(__("You are already subscribed to this feed."));
678 console
.error(transport
.responseText
);
691 function createNewRuleElement(parentNode
, replaceNode
) {
692 const form
= document
.forms
["filter_new_rule_form"];
694 //form.reg_exp.value = form.reg_exp.value.replace(/(<([^>]+)>)/ig,"");
696 const query
= "backend.php?op=pref-filters&method=printrulename&rule="+
697 param_escape(dojo
.formToJson(form
));
701 new Ajax
.Request("backend.php", {
703 onComplete: function (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
= "backend.php?op=pref-filters&method=printactionname&action="+
745 param_escape(dojo
.formToJson(form
));
749 new Ajax
.Request("backend.php", {
751 onComplete: function (transport
) {
753 const li
= dojo
.create("li");
755 const cb
= dojo
.create("input", { type
: "checkbox" }, li
);
757 new dijit
.form
.CheckBox({
758 onChange: function() {
759 toggleSelectListRow2(this) },
762 dojo
.create("input", { type
: "hidden",
764 value
: dojo
.formToJson(form
) }, li
);
766 dojo
.create("span", {
767 onclick: function() {
768 dijit
.byId('filterEditDlg').editAction(this);
770 innerHTML
: transport
.responseText
}, li
);
773 parentNode
.replaceChild(li
, replaceNode
);
775 parentNode
.appendChild(li
);
785 function addFilterRule(replaceNode
, ruleStr
) {
786 if (dijit
.byId("filterNewRuleDlg"))
787 dijit
.byId("filterNewRuleDlg").destroyRecursive();
789 const query
= "backend.php?op=pref-filters&method=newrule&rule=" +
790 param_escape(ruleStr
);
792 const rule_dlg
= new dijit
.Dialog({
793 id
: "filterNewRuleDlg",
794 title
: ruleStr
? __("Edit rule") : __("Add rule"),
795 style
: "width: 600px",
796 execute: function() {
797 if (this.validate()) {
798 createNewRuleElement($("filterDlg_Matches"), replaceNode
);
807 function addFilterAction(replaceNode
, actionStr
) {
808 if (dijit
.byId("filterNewActionDlg"))
809 dijit
.byId("filterNewActionDlg").destroyRecursive();
811 const query
= "backend.php?op=pref-filters&method=newaction&action=" +
812 param_escape(actionStr
);
814 const rule_dlg
= new dijit
.Dialog({
815 id
: "filterNewActionDlg",
816 title
: actionStr
? __("Edit action") : __("Add action"),
817 style
: "width: 600px",
818 execute: function() {
819 if (this.validate()) {
820 createNewActionElement($("filterDlg_Actions"), replaceNode
);
829 function editFilterTest(query
) {
831 if (dijit
.byId("filterTestDlg"))
832 dijit
.byId("filterTestDlg").destroyRecursive();
834 var test_dlg
= new dijit
.Dialog({
836 title
: "Test Filter",
837 style
: "width: 600px",
841 getTestResults: function(query
, offset
) {
842 const updquery
= query
+ "&offset=" + offset
+ "&limit=" + test_dlg
.limit
;
844 console
.log("getTestResults:" + offset
);
846 new Ajax
.Request("backend.php", {
847 parameters
: updquery
,
848 onComplete: function (transport
) {
850 const result
= JSON
.parse(transport
.responseText
);
852 if (result
&& dijit
.byId("filterTestDlg") && dijit
.byId("filterTestDlg").open
) {
853 test_dlg
.results
+= result
.size();
855 console
.log("got results:" + result
.size());
857 $("prefFilterProgressMsg").innerHTML
= __("Looking for articles (%d processed, %f found)...")
858 .replace("%f", test_dlg
.results
)
859 .replace("%d", offset
);
861 console
.log(offset
+ " " + test_dlg
.max_offset
);
863 for (let i
= 0; i
< result
.size(); i
++) {
864 const tmp
= new Element("table");
865 tmp
.innerHTML
= result
[i
];
866 dojo
.parser
.parse(tmp
);
868 $("prefFilterTestResultList").innerHTML
+= tmp
.innerHTML
;
871 if (test_dlg
.results
< 30 && offset
< test_dlg
.max_offset
) {
873 // get the next batch
874 window
.setTimeout(function () {
875 test_dlg
.getTestResults(query
, offset
+ test_dlg
.limit
);
881 Element
.hide("prefFilterLoadingIndicator");
883 if (test_dlg
.results
== 0) {
884 $("prefFilterTestResultList").innerHTML
= "<tr><td align='center'>No recent articles matching this filter have been found.</td></tr>";
885 $("prefFilterProgressMsg").innerHTML
= "Articles matching this filter:";
887 $("prefFilterProgressMsg").innerHTML
= __("Found %d articles matching this filter:")
888 .replace("%d", test_dlg
.results
);
893 } else if (!result
) {
894 console
.log("getTestResults: can't parse results object");
896 Element
.hide("prefFilterLoadingIndicator");
898 notify_error("Error while trying to get filter test results.");
901 console
.log("getTestResults: dialog closed, bailing out.");
911 dojo
.connect(test_dlg
, "onLoad", null, function(e
) {
912 test_dlg
.getTestResults(query
, 0);
919 function quickAddFilter() {
921 if (!inPreferences()) {
922 query
= "backend.php?op=pref-filters&method=newfilter&feed=" +
923 param_escape(getActiveFeedId()) + "&is_cat=" +
924 param_escape(activeFeedIsCat());
926 query
= "backend.php?op=pref-filters&method=newfilter";
931 if (dijit
.byId("feedEditDlg"))
932 dijit
.byId("feedEditDlg").destroyRecursive();
934 if (dijit
.byId("filterEditDlg"))
935 dijit
.byId("filterEditDlg").destroyRecursive();
937 var dialog
= new dijit
.Dialog({
939 title
: __("Create Filter"),
940 style
: "width: 600px",
942 const query
= "backend.php?" + dojo
.formToQuery("filter_new_form") + "&savemode=test";
944 editFilterTest(query
);
946 selectRules: function(select
) {
947 $$("#filterDlg_Matches input[type=checkbox]").each(function(e
) {
950 e
.parentNode
.addClassName("Selected");
952 e
.parentNode
.removeClassName("Selected");
955 selectActions: function(select
) {
956 $$("#filterDlg_Actions input[type=checkbox]").each(function(e
) {
960 e
.parentNode
.addClassName("Selected");
962 e
.parentNode
.removeClassName("Selected");
966 editRule: function(e
) {
967 const li
= e
.parentNode
;
968 const rule
= li
.getElementsByTagName("INPUT")[1].value
;
969 addFilterRule(li
, rule
);
971 editAction: function(e
) {
972 const li
= e
.parentNode
;
973 const action
= li
.getElementsByTagName("INPUT")[1].value
;
974 addFilterAction(li
, action
);
976 addAction: function() { addFilterAction(); },
977 addRule: function() { addFilterRule(); },
978 deleteAction: function() {
979 $$("#filterDlg_Actions li[class*=Selected]").each(function(e
) { e
.parentNode
.removeChild(e
) });
981 deleteRule: function() {
982 $$("#filterDlg_Matches li[class*=Selected]").each(function(e
) { e
.parentNode
.removeChild(e
) });
984 execute: function() {
985 if (this.validate()) {
987 const query
= dojo
.formToQuery("filter_new_form");
991 new Ajax
.Request("backend.php", {
993 onComplete: function (transport
) {
994 if (inPreferences()) {
1004 if (!inPreferences()) {
1005 const selectedText
= getSelectionText();
1007 var lh
= dojo
.connect(dialog
, "onLoad", function(){
1008 dojo
.disconnect(lh
);
1010 if (selectedText
!= "") {
1012 const feed_id
= activeFeedIsCat() ? 'CAT:' + parseInt(getActiveFeedId()) :
1015 const rule
= { reg_exp
: selectedText
, feed_id
: [feed_id
], filter_type
: 1 };
1017 addFilterRule(null, dojo
.toJson(rule
));
1021 const query
= "op=rpc&method=getlinktitlebyid&id=" + getActiveArticleId();
1023 new Ajax
.Request("backend.php", {
1025 onComplete: function(transport
) {
1026 const reply
= JSON
.parse(transport
.responseText
);
1030 if (reply
&& reply
.title
) title
= reply
.title
;
1032 if (title
|| getActiveFeedId() || activeFeedIsCat()) {
1034 console
.log(title
+ " " + getActiveFeedId());
1036 const feed_id
= activeFeedIsCat() ? 'CAT:' + parseInt(getActiveFeedId()) :
1039 const rule
= { reg_exp
: title
, feed_id
: [feed_id
], filter_type
: 1 };
1041 addFilterRule(null, dojo
.toJson(rule
));
1055 function unsubscribeFeed(feed_id
, title
) {
1057 const msg
= __("Unsubscribe from %s?").replace("%s", title
);
1059 if (title
== undefined || confirm(msg
)) {
1060 notify_progress("Removing feed...");
1062 const query
= "?op=pref-feeds&quiet=1&method=remove&ids=" + feed_id
;
1064 new Ajax
.Request("backend.php", {
1066 onComplete: function(transport
) {
1068 if (dijit
.byId("feedEditDlg")) dijit
.byId("feedEditDlg").hide();
1070 if (inPreferences()) {
1073 if (feed_id
== getActiveFeedId())
1074 setTimeout(function() { viewfeed({feed
:-5}) }, 100);
1076 if (feed_id
< 0) updateFeedList();
1086 function backend_sanity_check_callback(transport
) {
1088 if (sanity_check_done
) {
1089 fatalError(11, "Sanity check request received twice. This can indicate "+
1090 "presence of Firebug or some other disrupting extension. "+
1091 "Please disable it and try again.");
1095 const reply
= JSON
.parse(transport
.responseText
);
1098 fatalError(3, "Sanity check: invalid RPC reply", transport
.responseText
);
1102 const error_code
= reply
['error']['code'];
1104 if (error_code
&& error_code
!= 0) {
1105 return fatalError(error_code
, reply
['error']['message']);
1108 console
.log("sanity check ok");
1110 const params
= reply
['init-params'];
1113 console
.log('reading init-params...');
1115 for (const k
in params
) {
1116 console
.log("IP: " + k
+ " => " + JSON
.stringify(params
[k
]));
1117 if (k
== "label_base_index") _label_base_index
= parseInt(params
[k
]);
1120 init_params
= params
;
1122 // PluginHost might not be available on non-index pages
1123 window
.PluginHost
&& PluginHost
.run(PluginHost
.HOOK_PARAMS_LOADED
, init_params
);
1126 sanity_check_done
= true;
1128 init_second_stage();
1132 function genUrlChangeKey(feed
, is_cat
) {
1133 const ok
= confirm(__("Generate new syndication address for this feed?"));
1137 notify_progress("Trying to change address...", true);
1139 const query
= "?op=pref-feeds&method=regenFeedKey&id=" + param_escape(feed
) +
1140 "&is_cat=" + param_escape(is_cat
);
1142 new Ajax
.Request("backend.php", {
1144 onComplete: function(transport
) {
1145 const reply
= JSON
.parse(transport
.responseText
);
1146 const new_link
= reply
.link
;
1148 const e
= $('gen_feed_url');
1152 e
.innerHTML
= e
.innerHTML
.replace(/\&key=.*$/,
1153 "&key=" + new_link
);
1155 e
.href
= e
.href
.replace(/\&key=.*$/,
1156 "&key=" + new_link
);
1158 new Effect
.Highlight(e
);
1163 notify_error("Could not change feed URL.");
1170 // mode = all, none, invert
1171 function selectTableRows(id
, mode
) {
1172 const rows
= $(id
).rows
;
1174 for (let i
= 0; i
< rows
.length
; i
++) {
1175 const row
= rows
[i
];
1179 if (row
.id
&& row
.className
) {
1180 const bare_id
= row
.id
.replace(/^[A-Z]*?-/, "");
1181 const inputs
= rows
[i
].getElementsByTagName("input");
1183 for (let j
= 0; j
< inputs
.length
; j
++) {
1184 const input
= inputs
[j
];
1186 if (input
.getAttribute("type") == "checkbox" &&
1187 input
.id
.match(bare_id
)) {
1190 dcb
= dijit
.getEnclosingWidget(cb
);
1196 const issel
= row
.hasClassName("Selected");
1198 if (mode
== "all" && !issel
) {
1199 row
.addClassName("Selected");
1201 if (dcb
) dcb
.set("checked", true);
1202 } else if (mode
== "none" && issel
) {
1203 row
.removeClassName("Selected");
1205 if (dcb
) dcb
.set("checked", false);
1207 } else if (mode
== "invert") {
1210 row
.removeClassName("Selected");
1212 if (dcb
) dcb
.set("checked", false);
1214 row
.addClassName("Selected");
1216 if (dcb
) dcb
.set("checked", true);
1225 function getSelectedTableRowIds(id
) {
1228 const elem_rows
= $(id
).rows
;
1230 for (let i
= 0; i
< elem_rows
.length
; i
++) {
1231 if (elem_rows
[i
].hasClassName("Selected")) {
1232 const bare_id
= elem_rows
[i
].id
.replace(/^[A-Z]*?-/, "");
1240 function editFeed(feed
) {
1242 return alert(__("You can't edit this kind of feed."));
1244 const query
= "backend.php?op=pref-feeds&method=editfeed&id=" +
1249 if (dijit
.byId("filterEditDlg"))
1250 dijit
.byId("filterEditDlg").destroyRecursive();
1252 if (dijit
.byId("feedEditDlg"))
1253 dijit
.byId("feedEditDlg").destroyRecursive();
1255 var dialog
= new dijit
.Dialog({
1257 title
: __("Edit Feed"),
1258 style
: "width: 600px",
1259 execute: function() {
1260 if (this.validate()) {
1261 // console.log(dojo.objectToQuery(this.attr('value')));
1263 notify_progress("Saving data...", true);
1265 new Ajax
.Request("backend.php", {
1266 parameters
: dojo
.objectToQuery(dialog
.attr('value')),
1267 onComplete: function(transport
) {
1279 function feedBrowser() {
1280 const query
= "backend.php?op=feeds&method=feedBrowser";
1282 if (dijit
.byId("feedAddDlg"))
1283 dijit
.byId("feedAddDlg").hide();
1285 if (dijit
.byId("feedBrowserDlg"))
1286 dijit
.byId("feedBrowserDlg").destroyRecursive();
1288 var dialog
= new dijit
.Dialog({
1289 id
: "feedBrowserDlg",
1290 title
: __("More Feeds"),
1291 style
: "width: 600px",
1292 getSelectedFeedIds: function () {
1293 const list
= $$("#browseFeedList li[id*=FBROW]");
1294 const selected
= new Array();
1296 list
.each(function (child
) {
1297 const id
= child
.id
.replace("FBROW-", "");
1299 if (child
.hasClassName('Selected')) {
1306 getSelectedFeeds: function () {
1307 const list
= $$("#browseFeedList li.Selected");
1308 const selected
= new Array();
1310 list
.each(function (child
) {
1311 const title
= child
.getElementsBySelector("span.fb_feedTitle")[0].innerHTML
;
1312 const url
= child
.getElementsBySelector("a.fb_feedUrl")[0].href
;
1314 selected
.push([title
, url
]);
1321 subscribe: function () {
1322 const mode
= this.attr('value').mode
;
1326 selected
= this.getSelectedFeeds();
1328 selected
= this.getSelectedFeedIds();
1330 if (selected
.length
> 0) {
1331 dijit
.byId("feedBrowserDlg").hide();
1333 notify_progress("Loading, please wait...", true);
1335 // we use dojo.toJson instead of JSON.stringify because
1336 // it somehow escapes everything TWICE, at least in Chrome 9
1338 const query
= "?op=rpc&method=massSubscribe&payload=" +
1339 param_escape(dojo
.toJson(selected
)) + "&mode=" + param_escape(mode
);
1343 new Ajax
.Request("backend.php", {
1345 onComplete: function (transport
) {
1352 alert(__("No feeds are selected."));
1356 update: function () {
1357 const query
= dojo
.objectToQuery(dialog
.attr('value'));
1359 Element
.show('feed_browser_spinner');
1361 new Ajax
.Request("backend.php", {
1363 onComplete: function (transport
) {
1366 Element
.hide('feed_browser_spinner');
1368 const c
= $("browseFeedList");
1370 const reply
= JSON
.parse(transport
.responseText
);
1372 const r
= reply
['content'];
1373 const mode
= reply
['mode'];
1379 dojo
.parser
.parse("browseFeedList");
1382 Element
.show(dijit
.byId('feed_archive_remove').domNode
);
1384 Element
.hide(dijit
.byId('feed_archive_remove').domNode
);
1390 removeFromArchive: function () {
1391 const selected
= this.getSelectedFeedIds();
1393 if (selected
.length
> 0) {
1395 const pr
= __("Remove selected feeds from the archive? Feeds with stored articles will not be removed.");
1398 Element
.show('feed_browser_spinner');
1400 const query
= "?op=rpc&method=remarchive&ids=" +
1401 param_escape(selected
.toString());
1404 new Ajax
.Request("backend.php", {
1406 onComplete: function (transport
) {
1413 execute: function () {
1414 if (this.validate()) {
1424 function showFeedsWithErrors() {
1425 const query
= "backend.php?op=pref-feeds&method=feedsWithErrors";
1427 if (dijit
.byId("errorFeedsDlg"))
1428 dijit
.byId("errorFeedsDlg").destroyRecursive();
1430 var dialog
= new dijit
.Dialog({
1431 id
: "errorFeedsDlg",
1432 title
: __("Feeds with update errors"),
1433 style
: "width: 600px",
1434 getSelectedFeeds: function() {
1435 return getSelectedTableRowIds("prefErrorFeedList");
1437 removeSelected: function() {
1438 const sel_rows
= this.getSelectedFeeds();
1440 console
.log(sel_rows
);
1442 if (sel_rows
.length
> 0) {
1443 const ok
= confirm(__("Remove selected feeds?"));
1446 notify_progress("Removing selected feeds...", true);
1448 const query
= "?op=pref-feeds&method=remove&ids="+
1449 param_escape(sel_rows
.toString());
1451 new Ajax
.Request("backend.php", {
1453 onComplete: function(transport
) {
1461 alert(__("No feeds are selected."));
1464 execute: function() {
1465 if (this.validate()) {
1473 function get_timestamp() {
1474 const date
= new Date();
1475 return Math
.round(date
.getTime() / 1000);
1478 function helpDialog(topic
) {
1479 const query
= "backend.php?op=backend&method=help&topic=" + param_escape(topic
);
1481 if (dijit
.byId("helpDlg"))
1482 dijit
.byId("helpDlg").destroyRecursive();
1484 const dialog
= new dijit
.Dialog({
1487 style
: "width: 600px",
1494 function htmlspecialchars_decode (string
, quote_style
) {
1495 // http://kevin.vanzonneveld.net
1496 // + original by: Mirek Slugen
1497 // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
1498 // + bugfixed by: Mateusz "loonquawl" Zalega
1499 // + input by: ReverseSyntax
1500 // + input by: Slawomir Kaniecki
1501 // + input by: Scott Cariss
1502 // + input by: Francois
1503 // + bugfixed by: Onno Marsman
1504 // + revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
1505 // + bugfixed by: Brett Zamir (http://brett-zamir.me)
1506 // + input by: Ratheous
1507 // + input by: Mailfaker (http://www.weedem.fr/)
1508 // + reimplemented by: Brett Zamir (http://brett-zamir.me)
1509 // + bugfixed by: Brett Zamir (http://brett-zamir.me)
1510 // * example 1: htmlspecialchars_decode("<p>this -> "</p>", 'ENT_NOQUOTES');
1511 // * returns 1: '<p>this -> "</p>'
1512 // * example 2: htmlspecialchars_decode("&quot;");
1513 // * returns 2: '"'
1517 if (typeof quote_style
=== 'undefined') {
1520 string
= string
.toString().replace(/</g, '<').replace(/>/g, '>');
1523 'ENT_HTML_QUOTE_SINGLE': 1,
1524 'ENT_HTML_QUOTE_DOUBLE': 2,
1529 if (quote_style
=== 0) {
1532 if (typeof quote_style
!== 'number') { // Allow for a single string or an array of string flags
1533 quote_style
= [].concat(quote_style
);
1534 for (i
= 0; i
< quote_style
.length
; i
++) {
1535 // Resolve string input to bitwise e.g. 'PATHINFO_EXTENSION' becomes 4
1536 if (OPTS
[quote_style
[i
]] === 0) {
1538 } else if (OPTS
[quote_style
[i
]]) {
1539 optTemp
= optTemp
| OPTS
[quote_style
[i
]];
1542 quote_style
= optTemp
;
1544 if (quote_style
& OPTS
.ENT_HTML_QUOTE_SINGLE
) {
1545 string
= string
.replace(/�*39;/g, "'"); // PHP doesn't currently escape if more than one 0, but it should
1546 // string = string.replace(/'|�*27;/g, "'"); // This would also be useful here, but not a part of PHP
1549 string
= string
.replace(/"/g, '"');
1551 // Put this in last place to avoid escape being double-decoded
1552 string
= string
.replace(/&/g, '&');
1558 function label_to_feed_id(label
) {
1559 return _label_base_index
- 1 - Math
.abs(label
);
1562 function feed_to_label_id(feed
) {
1563 return _label_base_index
- 1 + Math
.abs(feed
);
1566 // http://stackoverflow.com/questions/6251937/how-to-get-selecteduser-highlighted-text-in-contenteditable-element-and-replac
1568 function getSelectionText() {
1571 if (typeof window
.getSelection
!= "undefined") {
1572 const sel
= window
.getSelection();
1573 if (sel
.rangeCount
) {
1574 const container
= document
.createElement("div");
1575 for (let i
= 0, len
= sel
.rangeCount
; i
< len
; ++i
) {
1576 container
.appendChild(sel
.getRangeAt(i
).cloneContents());
1578 text
= container
.innerHTML
;
1580 } else if (typeof document
.selection
!= "undefined") {
1581 if (document
.selection
.type
== "Text") {
1582 text
= document
.selection
.createRange().textText
;
1586 return text
.stripTags();
1589 function openUrlPopup(url
) {
1590 const w
= window
.open("");
1595 function openArticlePopup(id
) {
1596 const w
= window
.open("",
1597 "ttrss_article_popup",
1598 "height=900,width=900,resizable=yes,status=no,location=no,menubar=no,directories=no,scrollbars=yes,toolbar=no");
1601 w
.location
= "backend.php?op=article&method=view&mode=raw&html=1&zoom=1&id=" + id
+ "&csrf_token=" + getInitParam("csrf_token");