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