]>
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 (var i
=0; i
< this.length
; i
++) {
29 if (s
== this[i
]) this.splice(i
, 1);
34 function report_error(message
, filename
, lineno
, colno
, error
) {
35 exception_error(error
, null, filename
, lineno
);
38 function exception_error(e
, e_compat
, filename
, lineno
, colno
) {
39 if (typeof e
== "string") e
= e_compat
;
41 if (!e
) return; // no exception object, nothing to report.
45 var msg
= e
.toString();
48 new Ajax
.Request("backend.php", {
49 parameters
: {op
: "rpc", method
: "log",
50 file
: e
.fileName
? e
.fileName
: filename
,
51 line
: e
.lineNumber
? e
.lineNumber
: lineno
,
52 msg
: msg
, context
: e
.stack
},
53 onComplete: function (transport
) {
54 console
.warn(transport
.responseText
);
58 console
.error("Exception while trying to log the error.", e
);
61 var content
= "<div class='fatalError'><p>" + msg
+ "</p>";
64 content
+= "<div><b>Stack trace:</b></div>" +
65 "<textarea name=\"stack\" readonly=\"1\">" + e
.stack
+ "</textarea>";
70 content
+= "<div class='dlgButtons'>";
72 content
+= "<button dojoType=\"dijit.form.Button\" "+
73 "onclick=\"dijit.byId('exceptionDlg').hide()\">" +
74 __('Close') + "</button>";
77 if (dijit
.byId("exceptionDlg"))
78 dijit
.byId("exceptionDlg").destroyRecursive();
80 var dialog
= new dijit
.Dialog({
82 title
: "Unhandled exception",
83 style
: "width: 600px",
89 console
.error("Exception while trying to report an exception:", ei
);
90 console
.error("Original exception:", e
);
92 alert("Exception occured while trying to report an exception.\n" +
93 ei
.stack
+ "\n\nOriginal exception:\n" + e
.stack
);
98 function param_escape(arg
) {
99 return encodeURIComponent(arg
);
102 function notify_real(msg
, no_hide
, n_type
) {
108 if (notify_hide_timerid
) {
109 window
.clearTimeout(notify_hide_timerid
);
113 if (n
.hasClassName("visible")) {
114 notify_hide_timerid
= window
.setTimeout(function() {
115 n
.removeClassName("visible") }, 0);
129 msg
= "<span class=\"msg\"> " + __(msg
) + "</span>";
132 msg
= "<span><img src=\""+getInitParam("icon_indicator_white")+"\"></span>" + msg
;
134 } else if (n_type
== 3) {
135 msg
= "<span><img src=\""+getInitParam("icon_alert")+"\"></span>" + msg
;
136 } else if (n_type
== 4) {
137 msg
= "<span><img src=\""+getInitParam("icon_information")+"\"></span>" + msg
;
140 msg
+= " <span><img src=\""+getInitParam("icon_cross")+"\" class=\"close\" title=\"" +
141 __("Click to close") + "\" onclick=\"notify('')\"></span>";
145 window
.setTimeout(function() {
148 n
.className
= "notify notify_progress visible";
149 } else if (n_type
== 3) {
150 n
.className
= "notify notify_error visible";
151 msg
= "<span><img src='images/alert.png'></span>" + msg
;
152 } else if (n_type
== 4) {
153 n
.className
= "notify notify_info visible";
155 n
.className
= "notify visible";
159 notify_hide_timerid
= window
.setTimeout(function() {
160 n
.removeClassName("visible") }, 5*1000);
167 function notify(msg
, no_hide
) {
168 notify_real(msg
, no_hide
, 1);
171 function notify_progress(msg
, no_hide
) {
172 notify_real(msg
, no_hide
, 2);
175 function notify_error(msg
, no_hide
) {
176 notify_real(msg
, no_hide
, 3);
180 function notify_info(msg
, no_hide
) {
181 notify_real(msg
, no_hide
, 4);
184 function setCookie(name
, value
, lifetime
, path
, domain
, secure
) {
190 d
.setTime(d
.getTime() + (lifetime
* 1000));
193 console
.log("setCookie: " + name
+ " => " + value
+ ": " + d
);
195 int_setCookie(name
, value
, d
, path
, domain
, secure
);
199 function int_setCookie(name
, value
, expires
, path
, domain
, secure
) {
200 document
.cookie
= name
+ "=" + escape(value
) +
201 ((expires
) ? "; expires=" + expires
.toGMTString() : "") +
202 ((path
) ? "; path=" + path
: "") +
203 ((domain
) ? "; domain=" + domain
: "") +
204 ((secure
) ? "; secure" : "");
207 function delCookie(name
, path
, domain
) {
208 if (getCookie(name
)) {
209 document
.cookie
= name
+ "=" +
210 ((path
) ? ";path=" + path
: "") +
211 ((domain
) ? ";domain=" + domain
: "" ) +
212 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
217 function getCookie(name
) {
219 var dc
= document
.cookie
;
220 var prefix
= name
+ "=";
221 var begin
= dc
.indexOf("; " + prefix
);
223 begin
= dc
.indexOf(prefix
);
224 if (begin
!= 0) return null;
229 var end
= document
.cookie
.indexOf(";", begin
);
233 return unescape(dc
.substring(begin
+ prefix
.length
, end
));
236 function gotoPreferences() {
237 document
.location
.href
= "prefs.php";
240 function gotoLogout() {
241 document
.location
.href
= "backend.php?op=logout";
244 function gotoMain() {
245 document
.location
.href
= "index.php";
248 function toggleSelectRowById(sender
, id
) {
250 return toggleSelectRow(sender
, row
);
253 /* this is for dijit Checkbox */
254 function toggleSelectListRow2(sender
) {
255 var row
= sender
.domNode
.parentNode
;
256 return toggleSelectRow(sender
, row
);
259 /* this is for dijit Checkbox */
260 function toggleSelectRow2(sender
, row
, is_cdm
) {
264 row
= sender
.domNode
.parentNode
.parentNode
;
266 row
= sender
.domNode
.parentNode
.parentNode
.parentNode
; // oh ffs
268 if (sender
.checked
&& !row
.hasClassName('Selected'))
269 row
.addClassName('Selected');
271 row
.removeClassName('Selected');
273 if (typeof updateSelectedPrompt
!= undefined)
274 updateSelectedPrompt();
278 function toggleSelectRow(sender
, row
) {
280 if (!row
) row
= sender
.parentNode
.parentNode
;
282 if (sender
.checked
&& !row
.hasClassName('Selected'))
283 row
.addClassName('Selected');
285 row
.removeClassName('Selected');
287 if (typeof updateSelectedPrompt
!= undefined)
288 updateSelectedPrompt();
291 function checkboxToggleElement(elem
, id
) {
293 Effect
.Appear(id
, {duration
: 0.5});
295 Effect
.Fade(id
, {duration
: 0.5});
299 function getURLParam(param
){
300 return String(window
.location
.href
).parseQuery()[param
];
303 function closeInfoBox() {
304 dialog
= dijit
.byId("infoBox");
306 if (dialog
) dialog
.hide();
312 function displayDlg(title
, id
, param
, callback
) {
314 notify_progress("Loading, please wait...", true);
316 var query
= "?op=dlg&method=" +
317 param_escape(id
) + "¶m=" + param_escape(param
);
319 new Ajax
.Request("backend.php", {
321 onComplete: function (transport
) {
322 infobox_callback2(transport
, title
);
323 if (callback
) callback(transport
);
329 function infobox_callback2(transport
, title
) {
332 if (dijit
.byId("infoBox")) {
333 dialog
= dijit
.byId("infoBox");
336 //console.log("infobox_callback2");
339 var content
= transport
.responseText
;
342 dialog
= new dijit
.Dialog({
345 style
: "width: 600px",
346 onCancel: function() {
349 onExecute: function() {
352 onClose: function() {
357 dialog
.attr('title', title
);
358 dialog
.attr('content', content
);
366 function getInitParam(key
) {
367 return init_params
[key
];
370 function setInitParam(key
, value
) {
371 init_params
[key
] = value
;
374 function fatalError(code
, msg
, ext_info
) {
376 window
.location
.href
= "index.php";
377 } else if (code
== 5) {
378 window
.location
.href
= "public.php?op=dbupdate";
381 if (msg
== "") msg
= "Unknown error";
384 if (ext_info
.responseText
) {
385 ext_info
= ext_info
.responseText
;
389 if (ERRORS
&& ERRORS
[code
] && !msg
) {
393 var content
= "<div><b>Error code:</b> " + code
+ "</div>" +
394 "<p>" + msg
+ "</p>";
397 content
= content
+ "<div><b>Additional information:</b></div>" +
398 "<textarea style='width: 100%' readonly=\"1\">" +
399 ext_info
+ "</textarea>";
402 var dialog
= new dijit
.Dialog({
403 title
: "Fatal error",
404 style
: "width: 600px",
415 function filterDlgCheckAction(sender
) {
416 var action
= sender
.value
;
418 var action_param
= $("filterDlg_paramBox");
421 console
.log("filterDlgCheckAction: can't find action param box!");
425 // if selected action supports parameters, enable params field
426 if (action
== 4 || action
== 6 || action
== 7 || action
== 9) {
427 new Effect
.Appear(action_param
, {duration
: 0.5});
429 Element
.hide(dijit
.byId("filterDlg_actionParam").domNode
);
430 Element
.hide(dijit
.byId("filterDlg_actionParamLabel").domNode
);
431 Element
.hide(dijit
.byId("filterDlg_actionParamPlugin").domNode
);
434 Element
.show(dijit
.byId("filterDlg_actionParamLabel").domNode
);
435 } else if (action
== 9) {
436 Element
.show(dijit
.byId("filterDlg_actionParamPlugin").domNode
);
438 Element
.show(dijit
.byId("filterDlg_actionParam").domNode
);
442 Element
.hide(action_param
);
447 function explainError(code
) {
448 return displayDlg(__("Error explained"), "explainError", code
);
451 function loading_set_progress(p
) {
452 loading_progress
+= p
;
454 if (dijit
.byId("loading_bar"))
455 dijit
.byId("loading_bar").update({progress
: loading_progress
});
457 if (loading_progress
>= 90)
462 function remove_splash() {
464 if (Element
.visible("overlay")) {
465 console
.log("about to remove splash, OMG!");
466 Element
.hide("overlay");
467 console
.log("removed splash!");
471 function strip_tags(s
) {
472 return s
.replace(/<\/?[^>]+(>|$)/g, "");
475 function hotkey_prefix_timeout() {
477 var date
= new Date();
478 var ts
= Math
.round(date
.getTime() / 1000);
480 if (hotkey_prefix_pressed
&& ts
- hotkey_prefix_pressed
>= 5) {
481 console
.log("hotkey_prefix seems to be stuck, aborting");
482 hotkey_prefix_pressed
= false;
483 hotkey_prefix
= false;
484 Element
.hide('cmdline');
487 setTimeout(hotkey_prefix_timeout
, 1000);
491 function uploadIconHandler(rc
) {
494 notify_info("Upload complete.");
495 if (inPreferences()) {
498 setTimeout('updateFeedList(false, false)', 50);
502 notify_error("Upload failed: icon is too big.");
505 notify_error("Upload failed.");
510 function removeFeedIcon(id
) {
511 if (confirm(__("Remove stored feed icon?"))) {
512 var query
= "backend.php?op=pref-feeds&method=removeicon&feed_id=" + param_escape(id
);
516 notify_progress("Removing feed icon...", true);
518 new Ajax
.Request("backend.php", {
520 onComplete: function(transport
) {
521 notify_info("Feed icon removed.");
522 if (inPreferences()) {
525 setTimeout('updateFeedList(false, false)', 50);
533 function uploadFeedIcon() {
534 var file
= $("icon_file");
536 if (file
.value
.length
== 0) {
537 alert(__("Please select an image file to upload."));
539 if (confirm(__("Upload new icon for this feed?"))) {
540 notify_progress("Uploading, please wait...", true);
548 function addLabel(select
, callback
) {
550 var caption
= prompt(__("Please enter label caption:"), "");
552 if (caption
!= undefined) {
555 alert(__("Can't create label: missing caption."));
559 var query
= "?op=pref-labels&method=add&caption=" +
560 param_escape(caption
);
563 query
+= "&output=select";
565 notify_progress("Loading, please wait...", true);
567 if (inPreferences() && !select
) active_tab
= "labelConfig";
569 new Ajax
.Request("backend.php", {
571 onComplete: function(transport
) {
574 } else if (inPreferences()) {
585 function quickAddFeed() {
586 var query
= "backend.php?op=feeds&method=quickAddFeed";
588 // overlapping widgets
589 if (dijit
.byId("batchSubDlg")) dijit
.byId("batchSubDlg").destroyRecursive();
590 if (dijit
.byId("feedAddDlg")) dijit
.byId("feedAddDlg").destroyRecursive();
592 var dialog
= new dijit
.Dialog({
594 title
: __("Subscribe to Feed"),
595 style
: "width: 600px",
596 show_error: function(msg
) {
597 var elem
= $("fadd_error_message");
599 elem
.innerHTML
= msg
;
601 if (!Element
.visible(elem
))
602 new Effect
.Appear(elem
);
605 execute: function() {
606 if (this.validate()) {
607 console
.log(dojo
.objectToQuery(this.attr('value')));
609 var feed_url
= this.attr('value').feed
;
611 Element
.show("feed_add_spinner");
612 Element
.hide("fadd_error_message");
614 new Ajax
.Request("backend.php", {
615 parameters
: dojo
.objectToQuery(this.attr('value')),
616 onComplete: function(transport
) {
620 var reply
= JSON
.parse(transport
.responseText
);
622 Element
.hide("feed_add_spinner");
623 alert(__("Failed to parse output. This can indicate server timeout and/or network issues. Backend output was logged to browser console."));
624 console
.log('quickAddFeed, backend returned:' + transport
.responseText
);
628 var rc
= reply
['result'];
631 Element
.hide("feed_add_spinner");
635 switch (parseInt(rc
['code'])) {
638 notify_info(__("Subscribed to %s").replace("%s", feed_url
));
643 dialog
.show_error(__("Specified URL seems to be invalid."));
646 dialog
.show_error(__("Specified URL doesn't seem to contain any feeds."));
651 Element
.show("fadd_multiple_notify");
653 var select
= dijit
.byId("feedDlg_feedContainerSelect");
655 while (select
.getOptions().length
> 0)
656 select
.removeOption(0);
658 select
.addOption({value
: '', label
: __("Expand to select feed")});
661 for (var feedUrl
in feeds
) {
662 select
.addOption({value
: feedUrl
, label
: feeds
[feedUrl
]});
666 Effect
.Appear('feedDlg_feedsContainer', {duration
: 0.5});
670 dialog
.show_error(__("Couldn't download the specified URL: %s").
671 replace("%s", rc
['message']));
674 dialog
.show_error(__("XML validation failed: %s").
675 replace("%s", rc
['message']));
678 dialog
.show_error(__("You are already subscribed to this feed."));
683 console
.error(transport
.responseText
);
696 function createNewRuleElement(parentNode
, replaceNode
) {
697 var form
= document
.forms
["filter_new_rule_form"];
699 //form.reg_exp.value = form.reg_exp.value.replace(/(<([^>]+)>)/ig,"");
701 var query
= "backend.php?op=pref-filters&method=printrulename&rule="+
702 param_escape(dojo
.formToJson(form
));
706 new Ajax
.Request("backend.php", {
708 onComplete: function (transport
) {
710 var li
= dojo
.create("li");
712 var cb
= dojo
.create("input", { type
: "checkbox" }, li
);
714 new dijit
.form
.CheckBox({
715 onChange: function() {
716 toggleSelectListRow2(this) },
719 dojo
.create("input", { type
: "hidden",
721 value
: dojo
.formToJson(form
) }, li
);
723 dojo
.create("span", {
724 onclick: function() {
725 dijit
.byId('filterEditDlg').editRule(this);
727 innerHTML
: transport
.responseText
}, li
);
730 parentNode
.replaceChild(li
, replaceNode
);
732 parentNode
.appendChild(li
);
740 function createNewActionElement(parentNode
, replaceNode
) {
741 var form
= document
.forms
["filter_new_action_form"];
743 if (form
.action_id
.value
== 7) {
744 form
.action_param
.value
= form
.action_param_label
.value
;
745 } else if (form
.action_id
.value
== 9) {
746 form
.action_param
.value
= form
.action_param_plugin
.value
;
749 var query
= "backend.php?op=pref-filters&method=printactionname&action="+
750 param_escape(dojo
.formToJson(form
));
754 new Ajax
.Request("backend.php", {
756 onComplete: function (transport
) {
758 var li
= dojo
.create("li");
760 var cb
= dojo
.create("input", { type
: "checkbox" }, li
);
762 new dijit
.form
.CheckBox({
763 onChange: function() {
764 toggleSelectListRow2(this) },
767 dojo
.create("input", { type
: "hidden",
769 value
: dojo
.formToJson(form
) }, li
);
771 dojo
.create("span", {
772 onclick: function() {
773 dijit
.byId('filterEditDlg').editAction(this);
775 innerHTML
: transport
.responseText
}, li
);
778 parentNode
.replaceChild(li
, replaceNode
);
780 parentNode
.appendChild(li
);
790 function addFilterRule(replaceNode
, ruleStr
) {
791 if (dijit
.byId("filterNewRuleDlg"))
792 dijit
.byId("filterNewRuleDlg").destroyRecursive();
794 var query
= "backend.php?op=pref-filters&method=newrule&rule=" +
795 param_escape(ruleStr
);
797 var rule_dlg
= new dijit
.Dialog({
798 id
: "filterNewRuleDlg",
799 title
: ruleStr
? __("Edit rule") : __("Add rule"),
800 style
: "width: 600px",
801 execute: function() {
802 if (this.validate()) {
803 createNewRuleElement($("filterDlg_Matches"), replaceNode
);
812 function addFilterAction(replaceNode
, actionStr
) {
813 if (dijit
.byId("filterNewActionDlg"))
814 dijit
.byId("filterNewActionDlg").destroyRecursive();
816 var query
= "backend.php?op=pref-filters&method=newaction&action=" +
817 param_escape(actionStr
);
819 var rule_dlg
= new dijit
.Dialog({
820 id
: "filterNewActionDlg",
821 title
: actionStr
? __("Edit action") : __("Add action"),
822 style
: "width: 600px",
823 execute: function() {
824 if (this.validate()) {
825 createNewActionElement($("filterDlg_Actions"), replaceNode
);
834 function editFilterTest(query
) {
836 if (dijit
.byId("filterTestDlg"))
837 dijit
.byId("filterTestDlg").destroyRecursive();
839 var test_dlg
= new dijit
.Dialog({
841 title
: "Test Filter",
842 style
: "width: 600px",
846 getTestResults: function(query
, offset
) {
847 var updquery
= query
+ "&offset=" + offset
+ "&limit=" + test_dlg
.limit
;
849 console
.log("getTestResults:" + offset
);
851 new Ajax
.Request("backend.php", {
852 parameters
: updquery
,
853 onComplete: function (transport
) {
855 var result
= JSON
.parse(transport
.responseText
);
857 if (result
&& dijit
.byId("filterTestDlg") && dijit
.byId("filterTestDlg").open
) {
858 test_dlg
.results
+= result
.size();
860 console
.log("got results:" + result
.size());
862 $("prefFilterProgressMsg").innerHTML
= __("Looking for articles (%d processed, %f found)...")
863 .replace("%f", test_dlg
.results
)
864 .replace("%d", offset
);
866 console
.log(offset
+ " " + test_dlg
.max_offset
);
868 for (var i
= 0; i
< result
.size(); i
++) {
869 var tmp
= new Element("table");
870 tmp
.innerHTML
= result
[i
];
871 dojo
.parser
.parse(tmp
);
873 $("prefFilterTestResultList").innerHTML
+= tmp
.innerHTML
;
876 if (test_dlg
.results
< 30 && offset
< test_dlg
.max_offset
) {
878 // get the next batch
879 window
.setTimeout(function () {
880 test_dlg
.getTestResults(query
, offset
+ test_dlg
.limit
);
886 Element
.hide("prefFilterLoadingIndicator");
888 if (test_dlg
.results
== 0) {
889 $("prefFilterTestResultList").innerHTML
= "<tr><td align='center'>No recent articles matching this filter have been found.</td></tr>";
890 $("prefFilterProgressMsg").innerHTML
= "Articles matching this filter:";
892 $("prefFilterProgressMsg").innerHTML
= __("Found %d articles matching this filter:")
893 .replace("%d", test_dlg
.results
);
898 } else if (!result
) {
899 console
.log("getTestResults: can't parse results object");
901 Element
.hide("prefFilterLoadingIndicator");
903 notify_error("Error while trying to get filter test results.");
906 console
.log("getTestResults: dialog closed, bailing out.");
916 dojo
.connect(test_dlg
, "onLoad", null, function(e
) {
917 test_dlg
.getTestResults(query
, 0);
924 function quickAddFilter() {
926 if (!inPreferences()) {
927 query
= "backend.php?op=pref-filters&method=newfilter&feed=" +
928 param_escape(getActiveFeedId()) + "&is_cat=" +
929 param_escape(activeFeedIsCat());
931 query
= "backend.php?op=pref-filters&method=newfilter";
936 if (dijit
.byId("feedEditDlg"))
937 dijit
.byId("feedEditDlg").destroyRecursive();
939 if (dijit
.byId("filterEditDlg"))
940 dijit
.byId("filterEditDlg").destroyRecursive();
942 dialog
= new dijit
.Dialog({
944 title
: __("Create Filter"),
945 style
: "width: 600px",
947 var query
= "backend.php?" + dojo
.formToQuery("filter_new_form") + "&savemode=test";
949 editFilterTest(query
);
951 selectRules: function(select
) {
952 $$("#filterDlg_Matches input[type=checkbox]").each(function(e
) {
955 e
.parentNode
.addClassName("Selected");
957 e
.parentNode
.removeClassName("Selected");
960 selectActions: function(select
) {
961 $$("#filterDlg_Actions input[type=checkbox]").each(function(e
) {
965 e
.parentNode
.addClassName("Selected");
967 e
.parentNode
.removeClassName("Selected");
971 editRule: function(e
) {
972 var li
= e
.parentNode
;
973 var rule
= li
.getElementsByTagName("INPUT")[1].value
;
974 addFilterRule(li
, rule
);
976 editAction: function(e
) {
977 var li
= e
.parentNode
;
978 var action
= li
.getElementsByTagName("INPUT")[1].value
;
979 addFilterAction(li
, action
);
981 addAction: function() { addFilterAction(); },
982 addRule: function() { addFilterRule(); },
983 deleteAction: function() {
984 $$("#filterDlg_Actions li[class*=Selected]").each(function(e
) { e
.parentNode
.removeChild(e
) });
986 deleteRule: function() {
987 $$("#filterDlg_Matches li[class*=Selected]").each(function(e
) { e
.parentNode
.removeChild(e
) });
989 execute: function() {
990 if (this.validate()) {
992 var query
= dojo
.formToQuery("filter_new_form");
996 new Ajax
.Request("backend.php", {
998 onComplete: function (transport
) {
999 if (inPreferences()) {
1009 if (!inPreferences()) {
1010 var selectedText
= getSelectionText();
1012 var lh
= dojo
.connect(dialog
, "onLoad", function(){
1013 dojo
.disconnect(lh
);
1015 if (selectedText
!= "") {
1017 var feed_id
= activeFeedIsCat() ? 'CAT:' + parseInt(getActiveFeedId()) :
1020 var rule
= { reg_exp
: selectedText
, feed_id
: [feed_id
], filter_type
: 1 };
1022 addFilterRule(null, dojo
.toJson(rule
));
1026 var query
= "op=rpc&method=getlinktitlebyid&id=" + getActiveArticleId();
1028 new Ajax
.Request("backend.php", {
1030 onComplete: function(transport
) {
1031 var reply
= JSON
.parse(transport
.responseText
);
1035 if (reply
&& reply
) title
= reply
.title
;
1037 if (title
|| getActiveFeedId() || activeFeedIsCat()) {
1039 console
.log(title
+ " " + getActiveFeedId());
1041 var feed_id
= activeFeedIsCat() ? 'CAT:' + parseInt(getActiveFeedId()) :
1044 var rule
= { reg_exp
: title
, feed_id
: [feed_id
], filter_type
: 1 };
1046 addFilterRule(null, dojo
.toJson(rule
));
1060 function unsubscribeFeed(feed_id
, title
) {
1062 var msg
= __("Unsubscribe from %s?").replace("%s", title
);
1064 if (title
== undefined || confirm(msg
)) {
1065 notify_progress("Removing feed...");
1067 var query
= "?op=pref-feeds&quiet=1&method=remove&ids=" + feed_id
;
1069 new Ajax
.Request("backend.php", {
1071 onComplete: function(transport
) {
1073 if (dijit
.byId("feedEditDlg")) dijit
.byId("feedEditDlg").hide();
1075 if (inPreferences()) {
1078 if (feed_id
== getActiveFeedId())
1079 setTimeout(function() { viewfeed({feed
:-5}) }, 100);
1081 if (feed_id
< 0) updateFeedList();
1091 function backend_sanity_check_callback(transport
) {
1093 if (sanity_check_done
) {
1094 fatalError(11, "Sanity check request received twice. This can indicate "+
1095 "presence of Firebug or some other disrupting extension. "+
1096 "Please disable it and try again.");
1100 var reply
= JSON
.parse(transport
.responseText
);
1103 fatalError(3, "Sanity check: invalid RPC reply", transport
.responseText
);
1107 var error_code
= reply
['error']['code'];
1109 if (error_code
&& error_code
!= 0) {
1110 return fatalError(error_code
, reply
['error']['message']);
1113 console
.log("sanity check ok");
1115 var params
= reply
['init-params'];
1118 console
.log('reading init-params...');
1121 console
.log("IP: " + k
+ " => " + JSON
.stringify(params
[k
]));
1122 if (k
== "label_base_index") _label_base_index
= parseInt(params
[k
]);
1125 init_params
= params
;
1127 // PluginHost might not be available on non-index pages
1128 window
.PluginHost
&& PluginHost
.run(PluginHost
.HOOK_PARAMS_LOADED
, init_params
);
1131 sanity_check_done
= true;
1133 init_second_stage();
1137 function genUrlChangeKey(feed
, is_cat
) {
1138 var ok
= confirm(__("Generate new syndication address for this feed?"));
1142 notify_progress("Trying to change address...", true);
1144 var query
= "?op=pref-feeds&method=regenFeedKey&id=" + param_escape(feed
) +
1145 "&is_cat=" + param_escape(is_cat
);
1147 new Ajax
.Request("backend.php", {
1149 onComplete: function(transport
) {
1150 var reply
= JSON
.parse(transport
.responseText
);
1151 var new_link
= reply
.link
;
1153 var e
= $('gen_feed_url');
1157 e
.innerHTML
= e
.innerHTML
.replace(/\&key=.*$/,
1158 "&key=" + new_link
);
1160 e
.href
= e
.href
.replace(/\&key=.*$/,
1161 "&key=" + new_link
);
1163 new Effect
.Highlight(e
);
1168 notify_error("Could not change feed URL.");
1175 // mode = all, none, invert
1176 function selectTableRows(id
, mode
) {
1177 var rows
= $(id
).rows
;
1179 for (var i
= 0; i
< rows
.length
; i
++) {
1184 if (row
.id
&& row
.className
) {
1185 var bare_id
= row
.id
.replace(/^[A-Z]*?-/, "");
1186 var inputs
= rows
[i
].getElementsByTagName("input");
1188 for (var j
= 0; j
< inputs
.length
; j
++) {
1189 var input
= inputs
[j
];
1191 if (input
.getAttribute("type") == "checkbox" &&
1192 input
.id
.match(bare_id
)) {
1195 dcb
= dijit
.getEnclosingWidget(cb
);
1201 var issel
= row
.hasClassName("Selected");
1203 if (mode
== "all" && !issel
) {
1204 row
.addClassName("Selected");
1206 if (dcb
) dcb
.set("checked", true);
1207 } else if (mode
== "none" && issel
) {
1208 row
.removeClassName("Selected");
1210 if (dcb
) dcb
.set("checked", false);
1212 } else if (mode
== "invert") {
1215 row
.removeClassName("Selected");
1217 if (dcb
) dcb
.set("checked", false);
1219 row
.addClassName("Selected");
1221 if (dcb
) dcb
.set("checked", true);
1230 function getSelectedTableRowIds(id
) {
1233 var elem_rows
= $(id
).rows
;
1235 for (var i
= 0; i
< elem_rows
.length
; i
++) {
1236 if (elem_rows
[i
].hasClassName("Selected")) {
1237 var bare_id
= elem_rows
[i
].id
.replace(/^[A-Z]*?-/, "");
1245 function editFeed(feed
) {
1247 return alert(__("You can't edit this kind of feed."));
1249 var query
= "backend.php?op=pref-feeds&method=editfeed&id=" +
1254 if (dijit
.byId("filterEditDlg"))
1255 dijit
.byId("filterEditDlg").destroyRecursive();
1257 if (dijit
.byId("feedEditDlg"))
1258 dijit
.byId("feedEditDlg").destroyRecursive();
1260 dialog
= new dijit
.Dialog({
1262 title
: __("Edit Feed"),
1263 style
: "width: 600px",
1264 execute: function() {
1265 if (this.validate()) {
1266 // console.log(dojo.objectToQuery(this.attr('value')));
1268 notify_progress("Saving data...", true);
1270 new Ajax
.Request("backend.php", {
1271 parameters
: dojo
.objectToQuery(dialog
.attr('value')),
1272 onComplete: function(transport
) {
1284 function feedBrowser() {
1285 var query
= "backend.php?op=feeds&method=feedBrowser";
1287 if (dijit
.byId("feedAddDlg"))
1288 dijit
.byId("feedAddDlg").hide();
1290 if (dijit
.byId("feedBrowserDlg"))
1291 dijit
.byId("feedBrowserDlg").destroyRecursive();
1293 var dialog
= new dijit
.Dialog({
1294 id
: "feedBrowserDlg",
1295 title
: __("More Feeds"),
1296 style
: "width: 600px",
1297 getSelectedFeedIds: function () {
1298 var list
= $$("#browseFeedList li[id*=FBROW]");
1299 var selected
= new Array();
1301 list
.each(function (child
) {
1302 var id
= child
.id
.replace("FBROW-", "");
1304 if (child
.hasClassName('Selected')) {
1311 getSelectedFeeds: function () {
1312 var list
= $$("#browseFeedList li.Selected");
1313 var selected
= new Array();
1315 list
.each(function (child
) {
1316 var title
= child
.getElementsBySelector("span.fb_feedTitle")[0].innerHTML
;
1317 var url
= child
.getElementsBySelector("a.fb_feedUrl")[0].href
;
1319 selected
.push([title
, url
]);
1326 subscribe: function () {
1327 var mode
= this.attr('value').mode
;
1331 selected
= this.getSelectedFeeds();
1333 selected
= this.getSelectedFeedIds();
1335 if (selected
.length
> 0) {
1336 dijit
.byId("feedBrowserDlg").hide();
1338 notify_progress("Loading, please wait...", true);
1340 // we use dojo.toJson instead of JSON.stringify because
1341 // it somehow escapes everything TWICE, at least in Chrome 9
1343 var query
= "?op=rpc&method=massSubscribe&payload=" +
1344 param_escape(dojo
.toJson(selected
)) + "&mode=" + param_escape(mode
);
1348 new Ajax
.Request("backend.php", {
1350 onComplete: function (transport
) {
1357 alert(__("No feeds are selected."));
1361 update: function () {
1362 var query
= dojo
.objectToQuery(dialog
.attr('value'));
1364 Element
.show('feed_browser_spinner');
1366 new Ajax
.Request("backend.php", {
1368 onComplete: function (transport
) {
1371 Element
.hide('feed_browser_spinner');
1373 var c
= $("browseFeedList");
1375 var reply
= JSON
.parse(transport
.responseText
);
1377 var r
= reply
['content'];
1378 var mode
= reply
['mode'];
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 var selected
= this.getSelectedFeedIds();
1398 if (selected
.length
> 0) {
1400 var pr
= __("Remove selected feeds from the archive? Feeds with stored articles will not be removed.");
1403 Element
.show('feed_browser_spinner');
1405 var 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 var query
= "backend.php?op=pref-feeds&method=feedsWithErrors";
1432 if (dijit
.byId("errorFeedsDlg"))
1433 dijit
.byId("errorFeedsDlg").destroyRecursive();
1435 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 var sel_rows
= this.getSelectedFeeds();
1445 console
.log(sel_rows
);
1447 if (sel_rows
.length
> 0) {
1448 var ok
= confirm(__("Remove selected feeds?"));
1451 notify_progress("Removing selected feeds...", true);
1453 var 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 var date
= new Date();
1480 return Math
.round(date
.getTime() / 1000);
1483 function helpDialog(topic
) {
1484 var query
= "backend.php?op=backend&method=help&topic=" + param_escape(topic
);
1486 if (dijit
.byId("helpDlg"))
1487 dijit
.byId("helpDlg").destroyRecursive();
1489 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 var sel
= window
.getSelection();
1578 if (sel
.rangeCount
) {
1579 var container
= document
.createElement("div");
1580 for (var 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 var w
= window
.open("");
1600 function openArticlePopup(id
) {
1601 var 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");