]> git.wh0rd.org - tt-rss.git/blob - js/functions.js
add a %d articles selected element
[tt-rss.git] / js / functions.js
1 var notify_silent = false;
2 var loading_progress = 0;
3 var sanity_check_done = false;
4 var init_params = {};
5 var _label_base_index = -1024;
6
7 Ajax.Base.prototype.initialize = Ajax.Base.prototype.initialize.wrap(
8 function (callOriginal, options) {
9
10 if (getInitParam("csrf_token") != undefined) {
11 Object.extend(options, options || { });
12
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();
17
18 options.parameters["csrf_token"] = getInitParam("csrf_token");
19 }
20
21 return callOriginal(options);
22 }
23 );
24
25 /* add method to remove element from array */
26
27 Array.prototype.remove = function(s) {
28 for (var i=0; i < this.length; i++) {
29 if (s == this[i]) this.splice(i, 1);
30 }
31 };
32
33 /* create console.log if it doesn't exist */
34
35 if (!window.console) console = {};
36 console.log = console.log || function(msg) { };
37 console.warn = console.warn || function(msg) { };
38 console.error = console.error || function(msg) { };
39
40 function exception_error(location, e, ext_info) {
41 var msg = format_exception_error(location, e);
42
43 if (!ext_info) ext_info = false;
44
45 try {
46
47 if (ext_info) {
48 if (ext_info.responseText) {
49 ext_info = ext_info.responseText;
50 }
51 }
52
53 var content = "<div class=\"fatalError\">" +
54 "<pre>" + msg + "</pre>";
55
56 content += "<form name=\"exceptionForm\" id=\"exceptionForm\" target=\"_blank\" "+
57 "action=\"http://tt-rss.org/report.php\" method=\"POST\">";
58
59 content += "<textarea style=\"display : none\" name=\"message\">" + msg + "</textarea>";
60 content += "<textarea style=\"display : none\" name=\"params\">N/A</textarea>";
61
62 if (ext_info) {
63 content += "<div><b>Additional information:</b></div>" +
64 "<textarea name=\"xinfo\" readonly=\"1\">" + ext_info + "</textarea>";
65 }
66
67 content += "<div><b>Stack trace:</b></div>" +
68 "<textarea name=\"stack\" readonly=\"1\">" + e.stack + "</textarea>";
69
70 content += "</form>";
71
72 content += "</div>";
73
74 content += "<div class='dlgButtons'>";
75
76 content += "<button dojoType=\"dijit.form.Button\""+
77 "onclick=\"dijit.byId('exceptionDlg').report()\">" +
78 __('Report to tt-rss.org') + "</button> ";
79 content += "<button dojoType=\"dijit.form.Button\" "+
80 "onclick=\"dijit.byId('exceptionDlg').hide()\">" +
81 __('Close') + "</button>";
82 content += "</div>";
83
84 if (dijit.byId("exceptionDlg"))
85 dijit.byId("exceptionDlg").destroyRecursive();
86
87 var dialog = new dijit.Dialog({
88 id: "exceptionDlg",
89 title: "Unhandled exception",
90 style: "width: 600px",
91 report: function() {
92 if (confirm(__("Are you sure to report this exception to tt-rss.org? The report will include your browser information. Your IP would be saved in the database."))) {
93
94 document.forms['exceptionForm'].params.value = $H({
95 browserName: navigator.appName,
96 browserVersion: navigator.appVersion,
97 browserPlatform: navigator.platform,
98 browserCookies: navigator.cookieEnabled,
99 }).toQueryString();
100
101 document.forms['exceptionForm'].submit();
102
103 }
104 },
105 content: content});
106
107 dialog.show();
108
109 } catch (e) {
110 alert(msg);
111 }
112
113 }
114
115 function format_exception_error(location, e) {
116 var msg;
117
118 if (e.fileName) {
119 var base_fname = e.fileName.substring(e.fileName.lastIndexOf("/") + 1);
120
121 msg = "Exception: " + e.name + ", " + e.message +
122 "\nFunction: " + location + "()" +
123 "\nLocation: " + base_fname + ":" + e.lineNumber;
124
125 } else if (e.description) {
126 msg = "Exception: " + e.description + "\nFunction: " + location + "()";
127 } else {
128 msg = "Exception: " + e + "\nFunction: " + location + "()";
129 }
130
131 console.error("EXCEPTION: " + msg);
132
133 return msg;
134 }
135
136 function param_escape(arg) {
137 if (typeof encodeURIComponent != 'undefined')
138 return encodeURIComponent(arg);
139 else
140 return escape(arg);
141 }
142
143 function param_unescape(arg) {
144 if (typeof decodeURIComponent != 'undefined')
145 return decodeURIComponent(arg);
146 else
147 return unescape(arg);
148 }
149
150 var notify_hide_timerid = false;
151
152 function hide_notify() {
153 var n = $("notify");
154 if (n) {
155 n.style.display = "none";
156 }
157 }
158
159 function notify_silent_next() {
160 notify_silent = true;
161 }
162
163 function notify_real(msg, no_hide, n_type) {
164
165 if (notify_silent) {
166 notify_silent = false;
167 return;
168 }
169
170 var n = $("notify");
171 var nb = $("notify_body");
172
173 if (!n || !nb) return;
174
175 if (notify_hide_timerid) {
176 window.clearTimeout(notify_hide_timerid);
177 }
178
179 if (msg == "") {
180 if (n.style.display == "block") {
181 notify_hide_timerid = window.setTimeout("hide_notify()", 0);
182 }
183 return;
184 } else {
185 n.style.display = "block";
186 }
187
188 /* types:
189
190 1 - generic
191 2 - progress
192 3 - error
193 4 - info
194
195 */
196
197 msg = __(msg);
198
199 if (n_type == 1) {
200 n.className = "notify";
201 } else if (n_type == 2) {
202 n.className = "notify progress";
203 msg = "<img src='images/indicator_white.gif'> " + msg;
204 } else if (n_type == 3) {
205 n.className = "notify error";
206 msg = "<img src='images/sign_excl.svg'> " + msg;
207 } else if (n_type == 4) {
208 n.className = "notify info";
209 msg = "<img src='images/sign_info.svg'> " + msg;
210 }
211
212 if (no_hide) {
213 msg += " <span>(<a href='#' onclick=\"notify('')\">" +
214 __("close") + "</a>)</span>";
215 }
216
217
218 // msg = "<img src='images/live_com_loading.gif'> " + msg;
219
220 nb.innerHTML = msg;
221
222 if (!no_hide) {
223 notify_hide_timerid = window.setTimeout("hide_notify()", 3000);
224 }
225 }
226
227 function notify(msg, no_hide) {
228 notify_real(msg, no_hide, 1);
229 }
230
231 function notify_progress(msg, no_hide) {
232 notify_real(msg, no_hide, 2);
233 }
234
235 function notify_error(msg, no_hide) {
236 notify_real(msg, no_hide, 3);
237
238 }
239
240 function notify_info(msg, no_hide) {
241 notify_real(msg, no_hide, 4);
242 }
243
244 function setCookie(name, value, lifetime, path, domain, secure) {
245
246 var d = false;
247
248 if (lifetime) {
249 d = new Date();
250 d.setTime(d.getTime() + (lifetime * 1000));
251 }
252
253 console.log("setCookie: " + name + " => " + value + ": " + d);
254
255 int_setCookie(name, value, d, path, domain, secure);
256
257 }
258
259 function int_setCookie(name, value, expires, path, domain, secure) {
260 document.cookie= name + "=" + escape(value) +
261 ((expires) ? "; expires=" + expires.toGMTString() : "") +
262 ((path) ? "; path=" + path : "") +
263 ((domain) ? "; domain=" + domain : "") +
264 ((secure) ? "; secure" : "");
265 }
266
267 function delCookie(name, path, domain) {
268 if (getCookie(name)) {
269 document.cookie = name + "=" +
270 ((path) ? ";path=" + path : "") +
271 ((domain) ? ";domain=" + domain : "" ) +
272 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
273 }
274 }
275
276
277 function getCookie(name) {
278
279 var dc = document.cookie;
280 var prefix = name + "=";
281 var begin = dc.indexOf("; " + prefix);
282 if (begin == -1) {
283 begin = dc.indexOf(prefix);
284 if (begin != 0) return null;
285 }
286 else {
287 begin += 2;
288 }
289 var end = document.cookie.indexOf(";", begin);
290 if (end == -1) {
291 end = dc.length;
292 }
293 return unescape(dc.substring(begin + prefix.length, end));
294 }
295
296 function gotoPreferences() {
297 document.location.href = "prefs.php";
298 }
299
300 function gotoLogout() {
301 document.location.href = "backend.php?op=logout";
302 }
303
304 function gotoMain() {
305 document.location.href = "index.php";
306 }
307
308 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
309 * * @author Sundar Dorai-Raj
310 * * Email: sdoraira@vt.edu
311 * * This program is free software; you can redistribute it and/or
312 * * modify it under the terms of the GNU General Public License
313 * * as published by the Free Software Foundation; either version 2
314 * * of the License, or (at your option) any later version,
315 * * provided that any use properly credits the author.
316 * * This program is distributed in the hope that it will be useful,
317 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
318 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
319 * * GNU General Public License for more details at http://www.gnu.org * * */
320
321 var numbers=".0123456789";
322 function isNumeric(x) {
323 // is x a String or a character?
324 if(x.length>1) {
325 // remove negative sign
326 x=Math.abs(x)+"";
327 for(var j=0;j<x.length;j++) {
328 // call isNumeric recursively for each character
329 number=isNumeric(x.substring(j,j+1));
330 if(!number) return number;
331 }
332 return number;
333 }
334 else {
335 // if x is number return true
336 if(numbers.indexOf(x)>=0) return true;
337 return false;
338 }
339 }
340
341
342 function toggleSelectRowById(sender, id) {
343 var row = $(id);
344 return toggleSelectRow(sender, row);
345 }
346
347 function toggleSelectListRow(sender) {
348 var row = sender.parentNode;
349 return toggleSelectRow(sender, row);
350 }
351
352 /* this is for dijit Checkbox */
353 function toggleSelectListRow2(sender) {
354 var row = sender.domNode.parentNode;
355 return toggleSelectRow(sender, row);
356 }
357
358 /* this is for dijit Checkbox */
359 function toggleSelectRow2(sender, row, is_cdm) {
360
361 if (!row)
362 if (!is_cdm)
363 row = sender.domNode.parentNode.parentNode;
364 else
365 row = sender.domNode.parentNode.parentNode.parentNode; // oh ffs
366
367 if (sender.checked && !row.hasClassName('Selected'))
368 row.addClassName('Selected');
369 else
370 row.removeClassName('Selected');
371
372 if (typeof updateSelectedPrompt != undefined)
373 updateSelectedPrompt();
374 }
375
376
377 function toggleSelectRow(sender, row) {
378
379 if (!row) row = sender.parentNode.parentNode;
380
381 if (sender.checked && !row.hasClassName('Selected'))
382 row.addClassName('Selected');
383 else
384 row.removeClassName('Selected');
385
386 if (typeof updateSelectedPrompt != undefined)
387 updateSelectedPrompt();
388 }
389
390 function checkboxToggleElement(elem, id) {
391 if (elem.checked) {
392 Effect.Appear(id, {duration : 0.5});
393 } else {
394 Effect.Fade(id, {duration : 0.5});
395 }
396 }
397
398 function dropboxSelect(e, v) {
399 for (var i = 0; i < e.length; i++) {
400 if (e[i].value == v) {
401 e.selectedIndex = i;
402 break;
403 }
404 }
405 }
406
407 function getURLParam(param){
408 return String(window.location.href).parseQuery()[param];
409 }
410
411 function closeInfoBox(cleanup) {
412 try {
413 dialog = dijit.byId("infoBox");
414
415 if (dialog) dialog.hide();
416
417 } catch (e) {
418 //exception_error("closeInfoBox", e);
419 }
420 return false;
421 }
422
423
424 function displayDlg(title, id, param, callback) {
425
426 notify_progress("Loading, please wait...", true);
427
428 var query = "?op=dlg&method=" +
429 param_escape(id) + "&param=" + param_escape(param);
430
431 new Ajax.Request("backend.php", {
432 parameters: query,
433 onComplete: function (transport) {
434 infobox_callback2(transport, title);
435 if (callback) callback(transport);
436 } });
437
438 return false;
439 }
440
441 function infobox_callback2(transport, title) {
442 try {
443 var dialog = false;
444
445 if (dijit.byId("infoBox")) {
446 dialog = dijit.byId("infoBox");
447 }
448
449 //console.log("infobox_callback2");
450 notify('');
451
452 var content = transport.responseText;
453
454 if (!dialog) {
455 dialog = new dijit.Dialog({
456 title: title,
457 id: 'infoBox',
458 style: "width: 600px",
459 onCancel: function() {
460 return true;
461 },
462 onExecute: function() {
463 return true;
464 },
465 onClose: function() {
466 return true;
467 },
468 content: content});
469 } else {
470 dialog.attr('title', title);
471 dialog.attr('content', content);
472 }
473
474 dialog.show();
475
476 notify("");
477 } catch (e) {
478 exception_error("infobox_callback2", e);
479 }
480 }
481
482 function filterCR(e, f)
483 {
484 var key;
485
486 if(window.event)
487 key = window.event.keyCode; //IE
488 else
489 key = e.which; //firefox
490
491 if (key == 13) {
492 if (typeof f != 'undefined') {
493 f();
494 return false;
495 } else {
496 return false;
497 }
498 } else {
499 return true;
500 }
501 }
502
503 function getInitParam(key) {
504 return init_params[key];
505 }
506
507 function setInitParam(key, value) {
508 init_params[key] = value;
509 }
510
511 function fatalError(code, msg, ext_info) {
512 try {
513
514 if (code == 6) {
515 window.location.href = "index.php";
516 } else if (code == 5) {
517 window.location.href = "public.php?op=dbupdate";
518 } else {
519
520 if (msg == "") msg = "Unknown error";
521
522 if (ext_info) {
523 if (ext_info.responseText) {
524 ext_info = ext_info.responseText;
525 }
526 }
527
528 if (ERRORS && ERRORS[code] && !msg) {
529 msg = ERRORS[code];
530 }
531
532 var content = "<div><b>Error code:</b> " + code + "</div>" +
533 "<p>" + msg + "</p>";
534
535 if (ext_info) {
536 content = content + "<div><b>Additional information:</b></div>" +
537 "<textarea style='width: 100%' readonly=\"1\">" +
538 ext_info + "</textarea>";
539 }
540
541 var dialog = new dijit.Dialog({
542 title: "Fatal error",
543 style: "width: 600px",
544 content: content});
545
546 dialog.show();
547
548 }
549
550 return false;
551
552 } catch (e) {
553 exception_error("fatalError", e);
554 }
555 }
556
557 function filterDlgCheckAction(sender) {
558
559 try {
560
561 var action = sender.value;
562
563 var action_param = $("filterDlg_paramBox");
564
565 if (!action_param) {
566 console.log("filterDlgCheckAction: can't find action param box!");
567 return;
568 }
569
570 // if selected action supports parameters, enable params field
571 if (action == 4 || action == 6 || action == 7) {
572 new Effect.Appear(action_param, {duration : 0.5});
573 if (action != 7) {
574 Element.show(dijit.byId("filterDlg_actionParam").domNode);
575 Element.hide(dijit.byId("filterDlg_actionParamLabel").domNode);
576 } else {
577 Element.show(dijit.byId("filterDlg_actionParamLabel").domNode);
578 Element.hide(dijit.byId("filterDlg_actionParam").domNode);
579 }
580 } else {
581 Element.hide(action_param);
582 }
583
584 } catch (e) {
585 exception_error("filterDlgCheckAction", e);
586 }
587
588 }
589
590
591 function explainError(code) {
592 return displayDlg(__("Error explained"), "explainError", code);
593 }
594
595 function loading_set_progress(p) {
596 try {
597 loading_progress += p;
598
599 if (dijit.byId("loading_bar"))
600 dijit.byId("loading_bar").update({progress: loading_progress});
601
602 if (loading_progress >= 90)
603 remove_splash();
604
605 } catch (e) {
606 exception_error("loading_set_progress", e);
607 }
608 }
609
610 function remove_splash() {
611
612 if (Element.visible("overlay")) {
613 console.log("about to remove splash, OMG!");
614 Element.hide("overlay");
615 console.log("removed splash!");
616 }
617 }
618
619 function transport_error_check(transport) {
620 try {
621 if (transport.responseXML) {
622 var error = transport.responseXML.getElementsByTagName("error")[0];
623
624 if (error) {
625 var code = error.getAttribute("error-code");
626 var msg = error.getAttribute("error-msg");
627 if (code != 0) {
628 fatalError(code, msg);
629 return false;
630 }
631 }
632 }
633 } catch (e) {
634 exception_error("check_for_error_xml", e);
635 }
636 return true;
637 }
638
639 function strip_tags(s) {
640 return s.replace(/<\/?[^>]+(>|$)/g, "");
641 }
642
643 function truncate_string(s, length) {
644 if (!length) length = 30;
645 var tmp = s.substring(0, length);
646 if (s.length > length) tmp += "&hellip;";
647 return tmp;
648 }
649
650 function hotkey_prefix_timeout() {
651 try {
652
653 var date = new Date();
654 var ts = Math.round(date.getTime() / 1000);
655
656 if (hotkey_prefix_pressed && ts - hotkey_prefix_pressed >= 5) {
657 console.log("hotkey_prefix seems to be stuck, aborting");
658 hotkey_prefix_pressed = false;
659 hotkey_prefix = false;
660 Element.hide('cmdline');
661 }
662
663 setTimeout("hotkey_prefix_timeout()", 1000);
664
665 } catch (e) {
666 exception_error("hotkey_prefix_timeout", e);
667 }
668 }
669
670 function uploadIconHandler(rc) {
671 try {
672 switch (rc) {
673 case 0:
674 notify_info("Upload complete.");
675 if (inPreferences()) {
676 updateFeedList();
677 } else {
678 setTimeout('updateFeedList(false, false)', 50);
679 }
680 break;
681 case 1:
682 notify_error("Upload failed: icon is too big.");
683 break;
684 case 2:
685 notify_error("Upload failed.");
686 break;
687 }
688
689 } catch (e) {
690 exception_error("uploadIconHandler", e);
691 }
692 }
693
694 function removeFeedIcon(id) {
695
696 try {
697
698 if (confirm(__("Remove stored feed icon?"))) {
699 var query = "backend.php?op=pref-feeds&method=removeicon&feed_id=" + param_escape(id);
700
701 console.log(query);
702
703 notify_progress("Removing feed icon...", true);
704
705 new Ajax.Request("backend.php", {
706 parameters: query,
707 onComplete: function(transport) {
708 notify_info("Feed icon removed.");
709 if (inPreferences()) {
710 updateFeedList();
711 } else {
712 setTimeout('updateFeedList(false, false)', 50);
713 }
714 } });
715 }
716
717 return false;
718 } catch (e) {
719 exception_error("removeFeedIcon", e);
720 }
721 }
722
723 function uploadFeedIcon() {
724
725 try {
726
727 var file = $("icon_file");
728
729 if (file.value.length == 0) {
730 alert(__("Please select an image file to upload."));
731 } else {
732 if (confirm(__("Upload new icon for this feed?"))) {
733 notify_progress("Uploading, please wait...", true);
734 return true;
735 }
736 }
737
738 return false;
739
740 } catch (e) {
741 exception_error("uploadFeedIcon", e);
742 }
743 }
744
745 function addLabel(select, callback) {
746
747 try {
748
749 var caption = prompt(__("Please enter label caption:"), "");
750
751 if (caption != undefined) {
752
753 if (caption == "") {
754 alert(__("Can't create label: missing caption."));
755 return false;
756 }
757
758 var query = "?op=pref-labels&method=add&caption=" +
759 param_escape(caption);
760
761 if (select)
762 query += "&output=select";
763
764 notify_progress("Loading, please wait...", true);
765
766 if (inPreferences() && !select) active_tab = "labelConfig";
767
768 new Ajax.Request("backend.php", {
769 parameters: query,
770 onComplete: function(transport) {
771 if (callback) {
772 callback(transport);
773 } else if (inPreferences()) {
774 updateLabelList();
775 } else {
776 updateFeedList();
777 }
778 } });
779
780 }
781
782 } catch (e) {
783 exception_error("addLabel", e);
784 }
785 }
786
787 function quickAddFeed() {
788 try {
789 var query = "backend.php?op=feeds&method=quickAddFeed";
790
791 // overlapping widgets
792 if (dijit.byId("batchSubDlg")) dijit.byId("batchSubDlg").destroyRecursive();
793 if (dijit.byId("feedAddDlg")) dijit.byId("feedAddDlg").destroyRecursive();
794
795 var dialog = new dijit.Dialog({
796 id: "feedAddDlg",
797 title: __("Subscribe to Feed"),
798 style: "width: 600px",
799 execute: function() {
800 if (this.validate()) {
801 console.log(dojo.objectToQuery(this.attr('value')));
802
803 var feed_url = this.attr('value').feed;
804
805 Element.show("feed_add_spinner");
806
807 new Ajax.Request("backend.php", {
808 parameters: dojo.objectToQuery(this.attr('value')),
809 onComplete: function(transport) {
810 try {
811
812 var reply = JSON.parse(transport.responseText);
813
814 var rc = reply['result'];
815
816 notify('');
817 Element.hide("feed_add_spinner");
818
819 console.log(rc);
820
821 switch (parseInt(rc['code'])) {
822 case 1:
823 dialog.hide();
824 notify_info(__("Subscribed to %s").replace("%s", feed_url));
825
826 updateFeedList();
827 break;
828 case 2:
829 alert(__("Specified URL seems to be invalid."));
830 break;
831 case 3:
832 alert(__("Specified URL doesn't seem to contain any feeds."));
833 break;
834 case 4:
835 /* notify_progress("Searching for feed urls...", true);
836
837 new Ajax.Request("backend.php", {
838 parameters: 'op=rpc&method=extractfeedurls&url=' + param_escape(feed_url),
839 onComplete: function(transport, dialog, feed_url) {
840
841 notify('');
842
843 var reply = JSON.parse(transport.responseText);
844
845 var feeds = reply['urls'];
846
847 console.log(transport.responseText);
848
849 var select = dijit.byId("feedDlg_feedContainerSelect");
850
851 while (select.getOptions().length > 0)
852 select.removeOption(0);
853
854 var count = 0;
855 for (var feedUrl in feeds) {
856 select.addOption({value: feedUrl, label: feeds[feedUrl]});
857 count++;
858 }
859
860 // if (count > 5) count = 5;
861 // select.size = count;
862
863 Effect.Appear('feedDlg_feedsContainer', {duration : 0.5});
864 }
865 });
866 break; */
867
868 feeds = rc['feeds'];
869
870 var select = dijit.byId("feedDlg_feedContainerSelect");
871
872 while (select.getOptions().length > 0)
873 select.removeOption(0);
874
875 select.addOption({value: '', label: __("Expand to select feed")});
876
877 var count = 0;
878 for (var feedUrl in feeds) {
879 select.addOption({value: feedUrl, label: feeds[feedUrl]});
880 count++;
881 }
882
883 Effect.Appear('feedDlg_feedsContainer', {duration : 0.5});
884
885 break;
886 case 5:
887 alert(__("Couldn't download the specified URL: %s").
888 replace("%s", rc['message']));
889 break;
890 case 0:
891 alert(__("You are already subscribed to this feed."));
892 break;
893 }
894
895 } catch (e) {
896 exception_error("subscribeToFeed", e, transport);
897 }
898
899 } });
900
901 }
902 },
903 href: query});
904
905 dialog.show();
906 } catch (e) {
907 exception_error("quickAddFeed", e);
908 }
909 }
910
911 function createNewRuleElement(parentNode, replaceNode) {
912 try {
913 var form = document.forms["filter_new_rule_form"];
914
915 form.reg_exp.value = form.reg_exp.value.replace(/(<([^>]+)>)/ig,"");
916
917 var query = "backend.php?op=pref-filters&method=printrulename&rule="+
918 param_escape(dojo.formToJson(form));
919
920 console.log(query);
921
922 new Ajax.Request("backend.php", {
923 parameters: query,
924 onComplete: function (transport) {
925 try {
926 var li = dojo.create("li");
927
928 var cb = dojo.create("input", { type: "checkbox" }, li);
929
930 new dijit.form.CheckBox({
931 onChange: function() {
932 toggleSelectListRow2(this) },
933 }, cb);
934
935 dojo.create("input", { type: "hidden",
936 name: "rule[]",
937 value: dojo.formToJson(form) }, li);
938
939 dojo.create("span", {
940 onclick: function() {
941 dijit.byId('filterEditDlg').editRule(this);
942 },
943 innerHTML: transport.responseText }, li);
944
945 if (replaceNode) {
946 parentNode.replaceChild(li, replaceNode);
947 } else {
948 parentNode.appendChild(li);
949 }
950 } catch (e) {
951 exception_error("createNewRuleElement", e);
952 }
953 } });
954 } catch (e) {
955 exception_error("createNewRuleElement", e);
956 }
957 }
958
959 function createNewActionElement(parentNode, replaceNode) {
960 try {
961 var form = document.forms["filter_new_action_form"];
962
963 if (form.action_id.value == 7) {
964 form.action_param.value = form.action_param_label.value;
965 }
966
967 var query = "backend.php?op=pref-filters&method=printactionname&action="+
968 param_escape(dojo.formToJson(form));
969
970 console.log(query);
971
972 new Ajax.Request("backend.php", {
973 parameters: query,
974 onComplete: function (transport) {
975 try {
976 var li = dojo.create("li");
977
978 var cb = dojo.create("input", { type: "checkbox" }, li);
979
980 new dijit.form.CheckBox({
981 onChange: function() {
982 toggleSelectListRow2(this) },
983 }, cb);
984
985 dojo.create("input", { type: "hidden",
986 name: "action[]",
987 value: dojo.formToJson(form) }, li);
988
989 dojo.create("span", {
990 onclick: function() {
991 dijit.byId('filterEditDlg').editAction(this);
992 },
993 innerHTML: transport.responseText }, li);
994
995 if (replaceNode) {
996 parentNode.replaceChild(li, replaceNode);
997 } else {
998 parentNode.appendChild(li);
999 }
1000
1001 } catch (e) {
1002 exception_error("createNewActionElement", e);
1003 }
1004 } });
1005 } catch (e) {
1006 exception_error("createNewActionElement", e);
1007 }
1008 }
1009
1010
1011 function addFilterRule(replaceNode, ruleStr) {
1012 try {
1013 if (dijit.byId("filterNewRuleDlg"))
1014 dijit.byId("filterNewRuleDlg").destroyRecursive();
1015
1016 var query = "backend.php?op=pref-filters&method=newrule&rule=" +
1017 param_escape(ruleStr);
1018
1019 var rule_dlg = new dijit.Dialog({
1020 id: "filterNewRuleDlg",
1021 title: ruleStr ? __("Edit rule") : __("Add rule"),
1022 style: "width: 600px",
1023 execute: function() {
1024 if (this.validate()) {
1025 createNewRuleElement($("filterDlg_Matches"), replaceNode);
1026 this.hide();
1027 }
1028 },
1029 href: query});
1030
1031 rule_dlg.show();
1032 } catch (e) {
1033 exception_error("addFilterRule", e);
1034 }
1035 }
1036
1037 function addFilterAction(replaceNode, actionStr) {
1038 try {
1039 if (dijit.byId("filterNewActionDlg"))
1040 dijit.byId("filterNewActionDlg").destroyRecursive();
1041
1042 var query = "backend.php?op=pref-filters&method=newaction&action=" +
1043 param_escape(actionStr);
1044
1045 var rule_dlg = new dijit.Dialog({
1046 id: "filterNewActionDlg",
1047 title: actionStr ? __("Edit action") : __("Add action"),
1048 style: "width: 600px",
1049 execute: function() {
1050 if (this.validate()) {
1051 createNewActionElement($("filterDlg_Actions"), replaceNode);
1052 this.hide();
1053 }
1054 },
1055 href: query});
1056
1057 rule_dlg.show();
1058 } catch (e) {
1059 exception_error("addFilterAction", e);
1060 }
1061 }
1062
1063 function quickAddFilter() {
1064 try {
1065 var query = "";
1066 if (!inPreferences()) {
1067 query = "backend.php?op=pref-filters&method=newfilter&feed=" +
1068 param_escape(getActiveFeedId()) + "&is_cat=" +
1069 param_escape(activeFeedIsCat());
1070 } else {
1071 query = "backend.php?op=pref-filters&method=newfilter";
1072 }
1073
1074 console.log(query);
1075
1076 if (dijit.byId("feedEditDlg"))
1077 dijit.byId("feedEditDlg").destroyRecursive();
1078
1079 if (dijit.byId("filterEditDlg"))
1080 dijit.byId("filterEditDlg").destroyRecursive();
1081
1082 dialog = new dijit.Dialog({
1083 id: "filterEditDlg",
1084 title: __("Create Filter"),
1085 style: "width: 600px",
1086 test: function() {
1087 var query = "backend.php?" + dojo.formToQuery("filter_new_form") + "&savemode=test";
1088
1089 if (dijit.byId("filterTestDlg"))
1090 dijit.byId("filterTestDlg").destroyRecursive();
1091
1092 var test_dlg = new dijit.Dialog({
1093 id: "filterTestDlg",
1094 title: "Test Filter",
1095 style: "width: 600px",
1096 href: query});
1097
1098 test_dlg.show();
1099 },
1100 selectRules: function(select) {
1101 $$("#filterDlg_Matches input[type=checkbox]").each(function(e) {
1102 e.checked = select;
1103 if (select)
1104 e.parentNode.addClassName("Selected");
1105 else
1106 e.parentNode.removeClassName("Selected");
1107 });
1108 },
1109 selectActions: function(select) {
1110 $$("#filterDlg_Actions input[type=checkbox]").each(function(e) {
1111 e.checked = select;
1112
1113 if (select)
1114 e.parentNode.addClassName("Selected");
1115 else
1116 e.parentNode.removeClassName("Selected");
1117
1118 });
1119 },
1120 editRule: function(e) {
1121 var li = e.parentNode;
1122 var rule = li.getElementsByTagName("INPUT")[1].value;
1123 addFilterRule(li, rule);
1124 },
1125 editAction: function(e) {
1126 var li = e.parentNode;
1127 var action = li.getElementsByTagName("INPUT")[1].value;
1128 addFilterAction(li, action);
1129 },
1130 addAction: function() { addFilterAction(); },
1131 addRule: function() { addFilterRule(); },
1132 deleteAction: function() {
1133 $$("#filterDlg_Actions li.[class*=Selected]").each(function(e) { e.parentNode.removeChild(e) });
1134 },
1135 deleteRule: function() {
1136 $$("#filterDlg_Matches li.[class*=Selected]").each(function(e) { e.parentNode.removeChild(e) });
1137 },
1138 execute: function() {
1139 if (this.validate()) {
1140
1141 var query = dojo.formToQuery("filter_new_form");
1142
1143 console.log(query);
1144
1145 new Ajax.Request("backend.php", {
1146 parameters: query,
1147 onComplete: function (transport) {
1148 if (inPreferences()) {
1149 updateFilterList();
1150 }
1151
1152 dialog.hide();
1153 } });
1154 }
1155 },
1156 href: query});
1157
1158 if (!inPreferences()) {
1159 var lh = dojo.connect(dialog, "onLoad", function(){
1160 dojo.disconnect(lh);
1161
1162 var query = "op=rpc&method=getlinktitlebyid&id=" + getActiveArticleId();
1163
1164 new Ajax.Request("backend.php", {
1165 parameters: query,
1166 onComplete: function(transport) {
1167 var reply = JSON.parse(transport.responseText);
1168
1169 var title = false;
1170
1171 if (reply && reply) title = reply.title;
1172
1173 if (title || getActiveFeedId() || activeFeedIsCat()) {
1174
1175 console.log(title + " " + getActiveFeedId());
1176
1177 var feed_id = activeFeedIsCat() ? 'CAT:' + parseInt(getActiveFeedId()) :
1178 getActiveFeedId();
1179
1180 var rule = { reg_exp: title, feed_id: feed_id, filter_type: 1 };
1181
1182 addFilterRule(null, dojo.toJson(rule));
1183 }
1184
1185 } });
1186
1187 });
1188 }
1189
1190 dialog.show();
1191
1192 } catch (e) {
1193 exception_error("quickAddFilter", e);
1194 }
1195 }
1196
1197 function resetPubSub(feed_id, title) {
1198
1199 var msg = __("Reset subscription? Tiny Tiny RSS will try to subscribe to the notification hub again on next feed update.").replace("%s", title);
1200
1201 if (title == undefined || confirm(msg)) {
1202 notify_progress("Loading, please wait...");
1203
1204 var query = "?op=pref-feeds&quiet=1&method=resetPubSub&ids=" + feed_id;
1205
1206 new Ajax.Request("backend.php", {
1207 parameters: query,
1208 onComplete: function(transport) {
1209 dijit.byId("pubsubReset_Btn").attr('disabled', true);
1210 notify_info("Subscription reset.");
1211 } });
1212 }
1213
1214 return false;
1215 }
1216
1217
1218 function unsubscribeFeed(feed_id, title) {
1219
1220 var msg = __("Unsubscribe from %s?").replace("%s", title);
1221
1222 if (title == undefined || confirm(msg)) {
1223 notify_progress("Removing feed...");
1224
1225 var query = "?op=pref-feeds&quiet=1&method=remove&ids=" + feed_id;
1226
1227 new Ajax.Request("backend.php", {
1228 parameters: query,
1229 onComplete: function(transport) {
1230
1231 if (dijit.byId("feedEditDlg")) dijit.byId("feedEditDlg").hide();
1232
1233 if (inPreferences()) {
1234 updateFeedList();
1235 } else {
1236 if (feed_id == getActiveFeedId())
1237 setTimeout("viewfeed(-5)", 100);
1238
1239 if (feed_id < 0) updateFeedList();
1240 }
1241
1242 } });
1243 }
1244
1245 return false;
1246 }
1247
1248
1249 function backend_sanity_check_callback(transport) {
1250
1251 try {
1252
1253 if (sanity_check_done) {
1254 fatalError(11, "Sanity check request received twice. This can indicate "+
1255 "presence of Firebug or some other disrupting extension. "+
1256 "Please disable it and try again.");
1257 return;
1258 }
1259
1260 var reply = JSON.parse(transport.responseText);
1261
1262 if (!reply) {
1263 fatalError(3, "Sanity check: invalid RPC reply", transport.responseText);
1264 return;
1265 }
1266
1267 var error_code = reply['error']['code'];
1268
1269 if (error_code && error_code != 0) {
1270 return fatalError(error_code, reply['error']['message']);
1271 }
1272
1273 console.log("sanity check ok");
1274
1275 var params = reply['init-params'];
1276
1277 if (params) {
1278 console.log('reading init-params...');
1279
1280 if (params) {
1281 for (k in params) {
1282 var v = params[k];
1283 console.log("IP: " + k + " => " + v);
1284
1285 if (k == "label_base_index") _label_base_index = parseInt(v);
1286 }
1287 }
1288
1289 init_params = params;
1290 }
1291
1292 sanity_check_done = true;
1293
1294 init_second_stage();
1295
1296 } catch (e) {
1297 exception_error("backend_sanity_check_callback", e, transport);
1298 }
1299 }
1300
1301 /*function has_local_storage() {
1302 try {
1303 return 'sessionStorage' in window && window['sessionStorage'] != null;
1304 } catch (e) {
1305 return false;
1306 }
1307 } */
1308
1309 function catSelectOnChange(elem) {
1310 try {
1311 /* var value = elem[elem.selectedIndex].value;
1312 var def = elem.getAttribute('default');
1313
1314 if (value == "ADD_CAT") {
1315
1316 if (def)
1317 dropboxSelect(elem, def);
1318 else
1319 elem.selectedIndex = 0;
1320
1321 quickAddCat(elem);
1322 } */
1323
1324 } catch (e) {
1325 exception_error("catSelectOnChange", e);
1326 }
1327 }
1328
1329 function quickAddCat(elem) {
1330 try {
1331 var cat = prompt(__("Please enter category title:"));
1332
1333 if (cat) {
1334
1335 var query = "?op=rpc&method=quickAddCat&cat=" + param_escape(cat);
1336
1337 notify_progress("Loading, please wait...", true);
1338
1339 new Ajax.Request("backend.php", {
1340 parameters: query,
1341 onComplete: function (transport) {
1342 var response = transport.responseXML;
1343 var select = response.getElementsByTagName("select")[0];
1344 var options = select.getElementsByTagName("option");
1345
1346 dropbox_replace_options(elem, options);
1347
1348 notify('');
1349
1350 } });
1351
1352 }
1353
1354 } catch (e) {
1355 exception_error("quickAddCat", e);
1356 }
1357 }
1358
1359 function genUrlChangeKey(feed, is_cat) {
1360
1361 try {
1362 var ok = confirm(__("Generate new syndication address for this feed?"));
1363
1364 if (ok) {
1365
1366 notify_progress("Trying to change address...", true);
1367
1368 var query = "?op=pref-feeds&method=regenFeedKey&id=" + param_escape(feed) +
1369 "&is_cat=" + param_escape(is_cat);
1370
1371 new Ajax.Request("backend.php", {
1372 parameters: query,
1373 onComplete: function(transport) {
1374 var reply = JSON.parse(transport.responseText);
1375 var new_link = reply.link;
1376
1377 var e = $('gen_feed_url');
1378
1379 if (new_link) {
1380
1381 e.innerHTML = e.innerHTML.replace(/\&amp;key=.*$/,
1382 "&amp;key=" + new_link);
1383
1384 e.href = e.href.replace(/\&key=.*$/,
1385 "&key=" + new_link);
1386
1387 new Effect.Highlight(e);
1388
1389 notify('');
1390
1391 } else {
1392 notify_error("Could not change feed URL.");
1393 }
1394 } });
1395 }
1396 } catch (e) {
1397 exception_error("genUrlChangeKey", e);
1398 }
1399 return false;
1400 }
1401
1402 function labelSelectOnChange(elem) {
1403 try {
1404 /* var value = elem[elem.selectedIndex].value;
1405 var def = elem.getAttribute('default');
1406
1407 if (value == "ADD_LABEL") {
1408
1409 if (def)
1410 dropboxSelect(elem, def);
1411 else
1412 elem.selectedIndex = 0;
1413
1414 addLabel(elem, function(transport) {
1415
1416 try {
1417
1418 var response = transport.responseXML;
1419 var select = response.getElementsByTagName("select")[0];
1420 var options = select.getElementsByTagName("option");
1421
1422 dropbox_replace_options(elem, options);
1423
1424 notify('');
1425 } catch (e) {
1426 exception_error("addLabel", e);
1427 }
1428 });
1429 } */
1430
1431 } catch (e) {
1432 exception_error("labelSelectOnChange", e);
1433 }
1434 }
1435
1436 function dropbox_replace_options(elem, options) {
1437
1438 try {
1439 while (elem.hasChildNodes())
1440 elem.removeChild(elem.firstChild);
1441
1442 var sel_idx = -1;
1443
1444 for (var i = 0; i < options.length; i++) {
1445 var text = options[i].firstChild.nodeValue;
1446 var value = options[i].getAttribute("value");
1447
1448 if (value == undefined) value = text;
1449
1450 var issel = options[i].getAttribute("selected") == "1";
1451
1452 var option = new Option(text, value, issel);
1453
1454 if (options[i].getAttribute("disabled"))
1455 option.setAttribute("disabled", true);
1456
1457 elem.insert(option);
1458
1459 if (issel) sel_idx = i;
1460 }
1461
1462 // Chrome doesn't seem to just select stuff when you pass new Option(x, y, true)
1463 if (sel_idx >= 0) elem.selectedIndex = sel_idx;
1464
1465 } catch (e) {
1466 exception_error("dropbox_replace_options", e);
1467 }
1468 }
1469
1470 // mode = all, none, invert
1471 function selectTableRows(id, mode) {
1472 try {
1473 var rows = $(id).rows;
1474
1475 for (var i = 0; i < rows.length; i++) {
1476 var row = rows[i];
1477 var cb = false;
1478 var dcb = false;
1479
1480 if (row.id && row.className) {
1481 var bare_id = row.id.replace(/^[A-Z]*?-/, "");
1482 var inputs = rows[i].getElementsByTagName("input");
1483
1484 for (var j = 0; j < inputs.length; j++) {
1485 var input = inputs[j];
1486
1487 if (input.getAttribute("type") == "checkbox" &&
1488 input.id.match(bare_id)) {
1489
1490 cb = input;
1491 dcb = dijit.getEnclosingWidget(cb);
1492 break;
1493 }
1494 }
1495
1496 if (cb || dcb) {
1497 var issel = row.hasClassName("Selected");
1498
1499 if (mode == "all" && !issel) {
1500 row.addClassName("Selected");
1501 cb.checked = true;
1502 if (dcb) dcb.set("checked", true);
1503 } else if (mode == "none" && issel) {
1504 row.removeClassName("Selected");
1505 cb.checked = false;
1506 if (dcb) dcb.set("checked", false);
1507
1508 } else if (mode == "invert") {
1509
1510 if (issel) {
1511 row.removeClassName("Selected");
1512 cb.checked = false;
1513 if (dcb) dcb.set("checked", false);
1514 } else {
1515 row.addClassName("Selected");
1516 cb.checked = true;
1517 if (dcb) dcb.set("checked", true);
1518 }
1519 }
1520 }
1521 }
1522 }
1523
1524 } catch (e) {
1525 exception_error("selectTableRows", e);
1526
1527 }
1528 }
1529
1530 function getSelectedTableRowIds(id) {
1531 var rows = [];
1532
1533 try {
1534 var elem_rows = $(id).rows;
1535
1536 for (var i = 0; i < elem_rows.length; i++) {
1537 if (elem_rows[i].hasClassName("Selected")) {
1538 var bare_id = elem_rows[i].id.replace(/^[A-Z]*?-/, "");
1539 rows.push(bare_id);
1540 }
1541 }
1542
1543 } catch (e) {
1544 exception_error("getSelectedTableRowIds", e);
1545 }
1546
1547 return rows;
1548 }
1549
1550 function editFeed(feed, event) {
1551 try {
1552 if (feed <= 0)
1553 return alert(__("You can't edit this kind of feed."));
1554
1555 var query = "backend.php?op=pref-feeds&method=editfeed&id=" +
1556 param_escape(feed);
1557
1558 console.log(query);
1559
1560 if (dijit.byId("filterEditDlg"))
1561 dijit.byId("filterEditDlg").destroyRecursive();
1562
1563 if (dijit.byId("feedEditDlg"))
1564 dijit.byId("feedEditDlg").destroyRecursive();
1565
1566 dialog = new dijit.Dialog({
1567 id: "feedEditDlg",
1568 title: __("Edit Feed"),
1569 style: "width: 600px",
1570 execute: function() {
1571 if (this.validate()) {
1572 // console.log(dojo.objectToQuery(this.attr('value')));
1573
1574 notify_progress("Saving data...", true);
1575
1576 new Ajax.Request("backend.php", {
1577 parameters: dojo.objectToQuery(dialog.attr('value')),
1578 onComplete: function(transport) {
1579 dialog.hide();
1580 notify('');
1581 updateFeedList();
1582 }});
1583 }
1584 },
1585 href: query});
1586
1587 dialog.show();
1588
1589 } catch (e) {
1590 exception_error("editFeed", e);
1591 }
1592 }
1593
1594 function feedBrowser() {
1595 try {
1596 var query = "backend.php?op=feeds&method=feedBrowser";
1597
1598 if (dijit.byId("feedAddDlg"))
1599 dijit.byId("feedAddDlg").hide();
1600
1601 if (dijit.byId("feedBrowserDlg"))
1602 dijit.byId("feedBrowserDlg").destroyRecursive();
1603
1604 var dialog = new dijit.Dialog({
1605 id: "feedBrowserDlg",
1606 title: __("More Feeds"),
1607 style: "width: 600px",
1608 getSelectedFeedIds: function() {
1609 var list = $$("#browseFeedList li[id*=FBROW]");
1610 var selected = new Array();
1611
1612 list.each(function(child) {
1613 var id = child.id.replace("FBROW-", "");
1614
1615 if (child.hasClassName('Selected')) {
1616 selected.push(id);
1617 }
1618 });
1619
1620 return selected;
1621 },
1622 getSelectedFeeds: function() {
1623 var list = $$("#browseFeedList li.Selected");
1624 var selected = new Array();
1625
1626 list.each(function(child) {
1627 var title = child.getElementsBySelector("span.fb_feedTitle")[0].innerHTML;
1628 var url = child.getElementsBySelector("a.fb_feedUrl")[0].href;
1629
1630 selected.push([title,url]);
1631
1632 });
1633
1634 return selected;
1635 },
1636
1637 subscribe: function() {
1638 var mode = this.attr('value').mode;
1639 var selected = [];
1640
1641 if (mode == "1")
1642 selected = this.getSelectedFeeds();
1643 else
1644 selected = this.getSelectedFeedIds();
1645
1646 if (selected.length > 0) {
1647 dijit.byId("feedBrowserDlg").hide();
1648
1649 notify_progress("Loading, please wait...", true);
1650
1651 // we use dojo.toJson instead of JSON.stringify because
1652 // it somehow escapes everything TWICE, at least in Chrome 9
1653
1654 var query = "?op=rpc&method=massSubscribe&payload="+
1655 param_escape(dojo.toJson(selected)) + "&mode=" + param_escape(mode);
1656
1657 console.log(query);
1658
1659 new Ajax.Request("backend.php", {
1660 parameters: query,
1661 onComplete: function(transport) {
1662 notify('');
1663 updateFeedList();
1664 } });
1665
1666 } else {
1667 alert(__("No feeds are selected."));
1668 }
1669
1670 },
1671 update: function() {
1672 var query = dojo.objectToQuery(dialog.attr('value'));
1673
1674 Element.show('feed_browser_spinner');
1675
1676 new Ajax.Request("backend.php", {
1677 parameters: query,
1678 onComplete: function(transport) {
1679 notify('');
1680
1681 Element.hide('feed_browser_spinner');
1682
1683 var c = $("browseFeedList");
1684
1685 var reply = JSON.parse(transport.responseText);
1686
1687 var r = reply['content'];
1688 var mode = reply['mode'];
1689
1690 if (c && r) {
1691 c.innerHTML = r;
1692 }
1693
1694 dojo.parser.parse("browseFeedList");
1695
1696 if (mode == 2) {
1697 Element.show(dijit.byId('feed_archive_remove').domNode);
1698 } else {
1699 Element.hide(dijit.byId('feed_archive_remove').domNode);
1700 }
1701
1702 } });
1703 },
1704 removeFromArchive: function() {
1705 var selected = this.getSelectedFeedIds();
1706
1707 if (selected.length > 0) {
1708
1709 var pr = __("Remove selected feeds from the archive? Feeds with stored articles will not be removed.");
1710
1711 if (confirm(pr)) {
1712 Element.show('feed_browser_spinner');
1713
1714 var query = "?op=rpc&method=remarchive&ids=" +
1715 param_escape(selected.toString());;
1716
1717 new Ajax.Request("backend.php", {
1718 parameters: query,
1719 onComplete: function(transport) {
1720 dialog.update();
1721 } });
1722 }
1723 }
1724 },
1725 execute: function() {
1726 if (this.validate()) {
1727 this.subscribe();
1728 }
1729 },
1730 href: query});
1731
1732 dialog.show();
1733
1734 } catch (e) {
1735 exception_error("editFeed", e);
1736 }
1737 }
1738
1739 function showFeedsWithErrors() {
1740 try {
1741 var query = "backend.php?op=pref-feeds&method=feedsWithErrors";
1742
1743 if (dijit.byId("errorFeedsDlg"))
1744 dijit.byId("errorFeedsDlg").destroyRecursive();
1745
1746 dialog = new dijit.Dialog({
1747 id: "errorFeedsDlg",
1748 title: __("Feeds with update errors"),
1749 style: "width: 600px",
1750 getSelectedFeeds: function() {
1751 return getSelectedTableRowIds("prefErrorFeedList");
1752 },
1753 removeSelected: function() {
1754 var sel_rows = this.getSelectedFeeds();
1755
1756 console.log(sel_rows);
1757
1758 if (sel_rows.length > 0) {
1759 var ok = confirm(__("Remove selected feeds?"));
1760
1761 if (ok) {
1762 notify_progress("Removing selected feeds...", true);
1763
1764 var query = "?op=pref-feeds&method=remove&ids="+
1765 param_escape(sel_rows.toString());
1766
1767 new Ajax.Request("backend.php", {
1768 parameters: query,
1769 onComplete: function(transport) {
1770 notify('');
1771 dialog.hide();
1772 updateFeedList();
1773 } });
1774 }
1775
1776 } else {
1777 alert(__("No feeds are selected."));
1778 }
1779 },
1780 execute: function() {
1781 if (this.validate()) {
1782 }
1783 },
1784 href: query});
1785
1786 dialog.show();
1787
1788 } catch (e) {
1789 exception_error("showFeedsWithErrors", e);
1790 }
1791
1792 }
1793
1794 /* new support functions for SelectByTag */
1795
1796 function get_all_tags(selObj){
1797 try {
1798 if( !selObj ) return "";
1799
1800 var result = "";
1801 var len = selObj.options.length;
1802
1803 for (var i=0; i < len; i++){
1804 if (selObj.options[i].selected) {
1805 result += selObj[i].value + "%2C"; // is really a comma
1806 }
1807 }
1808
1809 if (result.length > 0){
1810 result = result.substr(0, result.length-3); // remove trailing %2C
1811 }
1812
1813 return(result);
1814
1815 } catch (e) {
1816 exception_error("get_all_tags", e);
1817 }
1818 }
1819
1820 function get_radio_checked(radioObj) {
1821 try {
1822 if (!radioObj) return "";
1823
1824 var len = radioObj.length;
1825
1826 if (len == undefined){
1827 if(radioObj.checked){
1828 return(radioObj.value);
1829 } else {
1830 return("");
1831 }
1832 }
1833
1834 for( var i=0; i < len; i++ ){
1835 if( radioObj[i].checked ){
1836 return( radioObj[i].value);
1837 }
1838 }
1839
1840 } catch (e) {
1841 exception_error("get_radio_checked", e);
1842 }
1843 return("");
1844 }
1845
1846 function get_timestamp() {
1847 var date = new Date();
1848 return Math.round(date.getTime() / 1000);
1849 }
1850
1851 function helpDialog(topic) {
1852 try {
1853 var query = "backend.php?op=backend&method=help&topic=" + param_escape(topic);
1854
1855 if (dijit.byId("helpDlg"))
1856 dijit.byId("helpDlg").destroyRecursive();
1857
1858 dialog = new dijit.Dialog({
1859 id: "helpDlg",
1860 title: __("Help"),
1861 style: "width: 600px",
1862 href: query,
1863 });
1864
1865 dialog.show();
1866
1867 } catch (e) {
1868 exception_error("helpDialog", e);
1869 }
1870 }
1871
1872 function htmlspecialchars_decode (string, quote_style) {
1873 // http://kevin.vanzonneveld.net
1874 // + original by: Mirek Slugen
1875 // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
1876 // + bugfixed by: Mateusz "loonquawl" Zalega
1877 // + input by: ReverseSyntax
1878 // + input by: Slawomir Kaniecki
1879 // + input by: Scott Cariss
1880 // + input by: Francois
1881 // + bugfixed by: Onno Marsman
1882 // + revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
1883 // + bugfixed by: Brett Zamir (http://brett-zamir.me)
1884 // + input by: Ratheous
1885 // + input by: Mailfaker (http://www.weedem.fr/)
1886 // + reimplemented by: Brett Zamir (http://brett-zamir.me)
1887 // + bugfixed by: Brett Zamir (http://brett-zamir.me)
1888 // * example 1: htmlspecialchars_decode("<p>this -&gt; &quot;</p>", 'ENT_NOQUOTES');
1889 // * returns 1: '<p>this -> &quot;</p>'
1890 // * example 2: htmlspecialchars_decode("&amp;quot;");
1891 // * returns 2: '&quot;'
1892 var optTemp = 0,
1893 i = 0,
1894 noquotes = false;
1895 if (typeof quote_style === 'undefined') {
1896 quote_style = 2;
1897 }
1898 string = string.toString().replace(/&lt;/g, '<').replace(/&gt;/g, '>');
1899 var OPTS = {
1900 'ENT_NOQUOTES': 0,
1901 'ENT_HTML_QUOTE_SINGLE': 1,
1902 'ENT_HTML_QUOTE_DOUBLE': 2,
1903 'ENT_COMPAT': 2,
1904 'ENT_QUOTES': 3,
1905 'ENT_IGNORE': 4
1906 };
1907 if (quote_style === 0) {
1908 noquotes = true;
1909 }
1910 if (typeof quote_style !== 'number') { // Allow for a single string or an array of string flags
1911 quote_style = [].concat(quote_style);
1912 for (i = 0; i < quote_style.length; i++) {
1913 // Resolve string input to bitwise e.g. 'PATHINFO_EXTENSION' becomes 4
1914 if (OPTS[quote_style[i]] === 0) {
1915 noquotes = true;
1916 } else if (OPTS[quote_style[i]]) {
1917 optTemp = optTemp | OPTS[quote_style[i]];
1918 }
1919 }
1920 quote_style = optTemp;
1921 }
1922 if (quote_style & OPTS.ENT_HTML_QUOTE_SINGLE) {
1923 string = string.replace(/&#0*39;/g, "'"); // PHP doesn't currently escape if more than one 0, but it should
1924 // string = string.replace(/&apos;|&#x0*27;/g, "'"); // This would also be useful here, but not a part of PHP
1925 }
1926 if (!noquotes) {
1927 string = string.replace(/&quot;/g, '"');
1928 }
1929 // Put this in last place to avoid escape being double-decoded
1930 string = string.replace(/&amp;/g, '&');
1931
1932 return string;
1933 }
1934
1935
1936 function label_to_feed_id(label) {
1937 return _label_base_index - 1 - Math.abs(label);
1938 }
1939
1940 function feed_to_label_id(feed) {
1941 return _label_base_index - 1 + Math.abs(feed);
1942 }
1943