]>
Commit | Line | Data |
---|---|---|
1 | var loading_progress = 0; | |
2 | var sanity_check_done = false; | |
3 | var init_params = {}; | |
4 | var _label_base_index = -1024; | |
5 | var notify_hide_timerid = false; | |
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 | try { | |
54 | new Ajax.Request("backend.php", { | |
55 | parameters: {op: "rpc", method: "log", logmsg: msg}, | |
56 | onComplete: function (transport) { | |
57 | console.log(transport.responseText); | |
58 | } }); | |
59 | ||
60 | } catch (eii) { | |
61 | console.log("Exception while trying to log the error."); | |
62 | console.log(eii); | |
63 | } | |
64 | ||
65 | msg += "<p>"+ __("The error will be reported to the configured log destination.") + | |
66 | "</p>"; | |
67 | ||
68 | var content = "<div class=\"fatalError\">" + | |
69 | "<pre>" + msg + "</pre>"; | |
70 | ||
71 | content += "<form name=\"exceptionForm\" id=\"exceptionForm\" target=\"_blank\" "+ | |
72 | "action=\"http://tt-rss.org/report.php\" method=\"POST\">"; | |
73 | ||
74 | content += "<textarea style=\"display : none\" name=\"message\">" + msg + "</textarea>"; | |
75 | content += "<textarea style=\"display : none\" name=\"params\">N/A</textarea>"; | |
76 | ||
77 | if (ext_info) { | |
78 | content += "<div><b>Additional information:</b></div>" + | |
79 | "<textarea name=\"xinfo\" readonly=\"1\">" + ext_info + "</textarea>"; | |
80 | } | |
81 | ||
82 | content += "<div><b>Stack trace:</b></div>" + | |
83 | "<textarea name=\"stack\" readonly=\"1\">" + e.stack + "</textarea>"; | |
84 | ||
85 | content += "</form>"; | |
86 | ||
87 | content += "</div>"; | |
88 | ||
89 | content += "<div class='dlgButtons'>"; | |
90 | ||
91 | content += "<button dojoType=\"dijit.form.Button\""+ | |
92 | "onclick=\"dijit.byId('exceptionDlg').report()\">" + | |
93 | __('Report to tt-rss.org') + "</button> "; | |
94 | content += "<button dojoType=\"dijit.form.Button\" "+ | |
95 | "onclick=\"dijit.byId('exceptionDlg').hide()\">" + | |
96 | __('Close') + "</button>"; | |
97 | content += "</div>"; | |
98 | ||
99 | if (dijit.byId("exceptionDlg")) | |
100 | dijit.byId("exceptionDlg").destroyRecursive(); | |
101 | ||
102 | var dialog = new dijit.Dialog({ | |
103 | id: "exceptionDlg", | |
104 | title: "Unhandled exception", | |
105 | style: "width: 600px", | |
106 | report: function() { | |
107 | 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."))) { | |
108 | ||
109 | document.forms['exceptionForm'].params.value = $H({ | |
110 | browserName: navigator.appName, | |
111 | browserVersion: navigator.appVersion, | |
112 | browserPlatform: navigator.platform, | |
113 | browserCookies: navigator.cookieEnabled, | |
114 | }).toQueryString(); | |
115 | ||
116 | document.forms['exceptionForm'].submit(); | |
117 | ||
118 | } | |
119 | }, | |
120 | content: content}); | |
121 | ||
122 | dialog.show(); | |
123 | ||
124 | } catch (ei) { | |
125 | console.log("Exception while trying to report an exception. Oh boy."); | |
126 | console.log(ei); | |
127 | console.log("Original exception:"); | |
128 | console.log(e); | |
129 | ||
130 | msg += "\n\nAdditional exception caught while trying to show the error dialog.\n\n" + format_exception_error('exception_error', ei); | |
131 | ||
132 | try { | |
133 | new Ajax.Request("backend.php", { | |
134 | parameters: {op: "rpc", method: "log", logmsg: msg}, | |
135 | onComplete: function (transport) { | |
136 | console.log(transport.responseText); | |
137 | } }); | |
138 | ||
139 | } catch (eii) { | |
140 | console.log("Third exception while trying to log the error! Seriously?"); | |
141 | console.log(eii); | |
142 | } | |
143 | ||
144 | msg += "\n\nThe error will be reported to the configured log destination."; | |
145 | ||
146 | alert(msg); | |
147 | } | |
148 | ||
149 | } | |
150 | ||
151 | function format_exception_error(location, e) { | |
152 | var msg; | |
153 | ||
154 | if (e.fileName) { | |
155 | var base_fname = e.fileName.substring(e.fileName.lastIndexOf("/") + 1); | |
156 | ||
157 | msg = "Exception: " + e.name + ", " + e.message + | |
158 | "\nFunction: " + location + "()" + | |
159 | "\nLocation: " + base_fname + ":" + e.lineNumber; | |
160 | ||
161 | } else if (e.description) { | |
162 | msg = "Exception: " + e.description + "\nFunction: " + location + "()"; | |
163 | } else { | |
164 | msg = "Exception: " + e + "\nFunction: " + location + "()"; | |
165 | } | |
166 | ||
167 | console.error("EXCEPTION: " + msg); | |
168 | ||
169 | return msg; | |
170 | } | |
171 | ||
172 | function param_escape(arg) { | |
173 | if (typeof encodeURIComponent != 'undefined') | |
174 | return encodeURIComponent(arg); | |
175 | else | |
176 | return escape(arg); | |
177 | } | |
178 | ||
179 | function param_unescape(arg) { | |
180 | if (typeof decodeURIComponent != 'undefined') | |
181 | return decodeURIComponent(arg); | |
182 | else | |
183 | return unescape(arg); | |
184 | } | |
185 | ||
186 | ||
187 | function hide_notify() { | |
188 | Element.hide('notify'); | |
189 | } | |
190 | ||
191 | function notify_real(msg, no_hide, n_type) { | |
192 | ||
193 | var n = $("notify"); | |
194 | ||
195 | if (!n) return; | |
196 | ||
197 | if (notify_hide_timerid) { | |
198 | window.clearTimeout(notify_hide_timerid); | |
199 | } | |
200 | ||
201 | if (msg == "") { | |
202 | if (Element.visible(n)) { | |
203 | notify_hide_timerid = window.setTimeout("hide_notify()", 0); | |
204 | } | |
205 | return; | |
206 | } else { | |
207 | Element.show(n); | |
208 | } | |
209 | ||
210 | /* types: | |
211 | ||
212 | 1 - generic | |
213 | 2 - progress | |
214 | 3 - error | |
215 | 4 - info | |
216 | ||
217 | */ | |
218 | ||
219 | msg = "<span class=\"msg\"> " + __(msg) + "</span>"; | |
220 | ||
221 | if (n_type == 1) { | |
222 | n.className = "notify"; | |
223 | } else if (n_type == 2) { | |
224 | n.className = "notify progress"; | |
225 | msg = "<span><img src='images/indicator_white.gif'></span>" + msg; | |
226 | no_hide = true; | |
227 | } else if (n_type == 3) { | |
228 | n.className = "notify error"; | |
229 | msg = "<span><img src='images/alert.png'></span>" + msg; | |
230 | } else if (n_type == 4) { | |
231 | n.className = "notify info"; | |
232 | msg = "<span><img src='images/information.png'></span>" + msg; | |
233 | } | |
234 | ||
235 | msg += " <span><img src=\"images/cross.png\" class=\"close\" title=\"" + | |
236 | __("Click to close") + "\" onclick=\"notify('')\"></span>"; | |
237 | ||
238 | // msg = "<img src='images/live_com_loading.gif'> " + msg; | |
239 | ||
240 | n.innerHTML = msg; | |
241 | ||
242 | if (!no_hide) { | |
243 | notify_hide_timerid = window.setTimeout("hide_notify()", 5*1000); | |
244 | } | |
245 | } | |
246 | ||
247 | function notify(msg, no_hide) { | |
248 | notify_real(msg, no_hide, 1); | |
249 | } | |
250 | ||
251 | function notify_progress(msg, no_hide) { | |
252 | notify_real(msg, no_hide, 2); | |
253 | } | |
254 | ||
255 | function notify_error(msg, no_hide) { | |
256 | notify_real(msg, no_hide, 3); | |
257 | ||
258 | } | |
259 | ||
260 | function notify_info(msg, no_hide) { | |
261 | notify_real(msg, no_hide, 4); | |
262 | } | |
263 | ||
264 | function setCookie(name, value, lifetime, path, domain, secure) { | |
265 | ||
266 | var d = false; | |
267 | ||
268 | if (lifetime) { | |
269 | d = new Date(); | |
270 | d.setTime(d.getTime() + (lifetime * 1000)); | |
271 | } | |
272 | ||
273 | console.log("setCookie: " + name + " => " + value + ": " + d); | |
274 | ||
275 | int_setCookie(name, value, d, path, domain, secure); | |
276 | ||
277 | } | |
278 | ||
279 | function int_setCookie(name, value, expires, path, domain, secure) { | |
280 | document.cookie= name + "=" + escape(value) + | |
281 | ((expires) ? "; expires=" + expires.toGMTString() : "") + | |
282 | ((path) ? "; path=" + path : "") + | |
283 | ((domain) ? "; domain=" + domain : "") + | |
284 | ((secure) ? "; secure" : ""); | |
285 | } | |
286 | ||
287 | function delCookie(name, path, domain) { | |
288 | if (getCookie(name)) { | |
289 | document.cookie = name + "=" + | |
290 | ((path) ? ";path=" + path : "") + | |
291 | ((domain) ? ";domain=" + domain : "" ) + | |
292 | ";expires=Thu, 01-Jan-1970 00:00:01 GMT"; | |
293 | } | |
294 | } | |
295 | ||
296 | ||
297 | function getCookie(name) { | |
298 | ||
299 | var dc = document.cookie; | |
300 | var prefix = name + "="; | |
301 | var begin = dc.indexOf("; " + prefix); | |
302 | if (begin == -1) { | |
303 | begin = dc.indexOf(prefix); | |
304 | if (begin != 0) return null; | |
305 | } | |
306 | else { | |
307 | begin += 2; | |
308 | } | |
309 | var end = document.cookie.indexOf(";", begin); | |
310 | if (end == -1) { | |
311 | end = dc.length; | |
312 | } | |
313 | return unescape(dc.substring(begin + prefix.length, end)); | |
314 | } | |
315 | ||
316 | function gotoPreferences() { | |
317 | document.location.href = "prefs.php"; | |
318 | } | |
319 | ||
320 | function gotoLogout() { | |
321 | document.location.href = "backend.php?op=logout"; | |
322 | } | |
323 | ||
324 | function gotoMain() { | |
325 | document.location.href = "index.php"; | |
326 | } | |
327 | ||
328 | /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj | |
329 | * * @author Sundar Dorai-Raj | |
330 | * * Email: sdoraira@vt.edu | |
331 | * * This program is free software; you can redistribute it and/or | |
332 | * * modify it under the terms of the GNU General Public License | |
333 | * * as published by the Free Software Foundation; either version 2 | |
334 | * * of the License, or (at your option) any later version, | |
335 | * * provided that any use properly credits the author. | |
336 | * * This program is distributed in the hope that it will be useful, | |
337 | * * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
338 | * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
339 | * * GNU General Public License for more details at http://www.gnu.org * * */ | |
340 | ||
341 | var numbers=".0123456789"; | |
342 | function isNumeric(x) { | |
343 | // is x a String or a character? | |
344 | if(x.length>1) { | |
345 | // remove negative sign | |
346 | x=Math.abs(x)+""; | |
347 | for(var j=0;j<x.length;j++) { | |
348 | // call isNumeric recursively for each character | |
349 | number=isNumeric(x.substring(j,j+1)); | |
350 | if(!number) return number; | |
351 | } | |
352 | return number; | |
353 | } | |
354 | else { | |
355 | // if x is number return true | |
356 | if(numbers.indexOf(x)>=0) return true; | |
357 | return false; | |
358 | } | |
359 | } | |
360 | ||
361 | ||
362 | function toggleSelectRowById(sender, id) { | |
363 | var row = $(id); | |
364 | return toggleSelectRow(sender, row); | |
365 | } | |
366 | ||
367 | function toggleSelectListRow(sender) { | |
368 | var row = sender.parentNode; | |
369 | return toggleSelectRow(sender, row); | |
370 | } | |
371 | ||
372 | /* this is for dijit Checkbox */ | |
373 | function toggleSelectListRow2(sender) { | |
374 | var row = sender.domNode.parentNode; | |
375 | return toggleSelectRow(sender, row); | |
376 | } | |
377 | ||
378 | /* this is for dijit Checkbox */ | |
379 | function toggleSelectRow2(sender, row, is_cdm) { | |
380 | ||
381 | if (!row) | |
382 | if (!is_cdm) | |
383 | row = sender.domNode.parentNode.parentNode; | |
384 | else | |
385 | row = sender.domNode.parentNode.parentNode.parentNode; // oh ffs | |
386 | ||
387 | if (sender.checked && !row.hasClassName('Selected')) | |
388 | row.addClassName('Selected'); | |
389 | else | |
390 | row.removeClassName('Selected'); | |
391 | ||
392 | if (typeof updateSelectedPrompt != undefined) | |
393 | updateSelectedPrompt(); | |
394 | } | |
395 | ||
396 | ||
397 | function toggleSelectRow(sender, row) { | |
398 | ||
399 | if (!row) row = sender.parentNode.parentNode; | |
400 | ||
401 | if (sender.checked && !row.hasClassName('Selected')) | |
402 | row.addClassName('Selected'); | |
403 | else | |
404 | row.removeClassName('Selected'); | |
405 | ||
406 | if (typeof updateSelectedPrompt != undefined) | |
407 | updateSelectedPrompt(); | |
408 | } | |
409 | ||
410 | function checkboxToggleElement(elem, id) { | |
411 | if (elem.checked) { | |
412 | Effect.Appear(id, {duration : 0.5}); | |
413 | } else { | |
414 | Effect.Fade(id, {duration : 0.5}); | |
415 | } | |
416 | } | |
417 | ||
418 | function dropboxSelect(e, v) { | |
419 | for (var i = 0; i < e.length; i++) { | |
420 | if (e[i].value == v) { | |
421 | e.selectedIndex = i; | |
422 | break; | |
423 | } | |
424 | } | |
425 | } | |
426 | ||
427 | function getURLParam(param){ | |
428 | return String(window.location.href).parseQuery()[param]; | |
429 | } | |
430 | ||
431 | function closeInfoBox(cleanup) { | |
432 | try { | |
433 | dialog = dijit.byId("infoBox"); | |
434 | ||
435 | if (dialog) dialog.hide(); | |
436 | ||
437 | } catch (e) { | |
438 | //exception_error("closeInfoBox", e); | |
439 | } | |
440 | return false; | |
441 | } | |
442 | ||
443 | ||
444 | function displayDlg(title, id, param, callback) { | |
445 | ||
446 | notify_progress("Loading, please wait...", true); | |
447 | ||
448 | var query = "?op=dlg&method=" + | |
449 | param_escape(id) + "¶m=" + param_escape(param); | |
450 | ||
451 | new Ajax.Request("backend.php", { | |
452 | parameters: query, | |
453 | onComplete: function (transport) { | |
454 | infobox_callback2(transport, title); | |
455 | if (callback) callback(transport); | |
456 | } }); | |
457 | ||
458 | return false; | |
459 | } | |
460 | ||
461 | function infobox_callback2(transport, title) { | |
462 | try { | |
463 | var dialog = false; | |
464 | ||
465 | if (dijit.byId("infoBox")) { | |
466 | dialog = dijit.byId("infoBox"); | |
467 | } | |
468 | ||
469 | //console.log("infobox_callback2"); | |
470 | notify(''); | |
471 | ||
472 | var content = transport.responseText; | |
473 | ||
474 | if (!dialog) { | |
475 | dialog = new dijit.Dialog({ | |
476 | title: title, | |
477 | id: 'infoBox', | |
478 | style: "width: 600px", | |
479 | onCancel: function() { | |
480 | return true; | |
481 | }, | |
482 | onExecute: function() { | |
483 | return true; | |
484 | }, | |
485 | onClose: function() { | |
486 | return true; | |
487 | }, | |
488 | content: content}); | |
489 | } else { | |
490 | dialog.attr('title', title); | |
491 | dialog.attr('content', content); | |
492 | } | |
493 | ||
494 | dialog.show(); | |
495 | ||
496 | notify(""); | |
497 | } catch (e) { | |
498 | exception_error("infobox_callback2", e); | |
499 | } | |
500 | } | |
501 | ||
502 | function filterCR(e, f) | |
503 | { | |
504 | var key; | |
505 | ||
506 | if(window.event) | |
507 | key = window.event.keyCode; //IE | |
508 | else | |
509 | key = e.which; //firefox | |
510 | ||
511 | if (key == 13) { | |
512 | if (typeof f != 'undefined') { | |
513 | f(); | |
514 | return false; | |
515 | } else { | |
516 | return false; | |
517 | } | |
518 | } else { | |
519 | return true; | |
520 | } | |
521 | } | |
522 | ||
523 | function getInitParam(key) { | |
524 | return init_params[key]; | |
525 | } | |
526 | ||
527 | function setInitParam(key, value) { | |
528 | init_params[key] = value; | |
529 | } | |
530 | ||
531 | function fatalError(code, msg, ext_info) { | |
532 | try { | |
533 | ||
534 | if (code == 6) { | |
535 | window.location.href = "index.php"; | |
536 | } else if (code == 5) { | |
537 | window.location.href = "public.php?op=dbupdate"; | |
538 | } else { | |
539 | ||
540 | if (msg == "") msg = "Unknown error"; | |
541 | ||
542 | if (ext_info) { | |
543 | if (ext_info.responseText) { | |
544 | ext_info = ext_info.responseText; | |
545 | } | |
546 | } | |
547 | ||
548 | if (ERRORS && ERRORS[code] && !msg) { | |
549 | msg = ERRORS[code]; | |
550 | } | |
551 | ||
552 | var content = "<div><b>Error code:</b> " + code + "</div>" + | |
553 | "<p>" + msg + "</p>"; | |
554 | ||
555 | if (ext_info) { | |
556 | content = content + "<div><b>Additional information:</b></div>" + | |
557 | "<textarea style='width: 100%' readonly=\"1\">" + | |
558 | ext_info + "</textarea>"; | |
559 | } | |
560 | ||
561 | var dialog = new dijit.Dialog({ | |
562 | title: "Fatal error", | |
563 | style: "width: 600px", | |
564 | content: content}); | |
565 | ||
566 | dialog.show(); | |
567 | ||
568 | } | |
569 | ||
570 | return false; | |
571 | ||
572 | } catch (e) { | |
573 | exception_error("fatalError", e); | |
574 | } | |
575 | } | |
576 | ||
577 | function filterDlgCheckAction(sender) { | |
578 | ||
579 | try { | |
580 | ||
581 | var action = sender.value; | |
582 | ||
583 | var action_param = $("filterDlg_paramBox"); | |
584 | ||
585 | if (!action_param) { | |
586 | console.log("filterDlgCheckAction: can't find action param box!"); | |
587 | return; | |
588 | } | |
589 | ||
590 | // if selected action supports parameters, enable params field | |
591 | if (action == 4 || action == 6 || action == 7) { | |
592 | new Effect.Appear(action_param, {duration : 0.5}); | |
593 | if (action != 7) { | |
594 | Element.show(dijit.byId("filterDlg_actionParam").domNode); | |
595 | Element.hide(dijit.byId("filterDlg_actionParamLabel").domNode); | |
596 | } else { | |
597 | Element.show(dijit.byId("filterDlg_actionParamLabel").domNode); | |
598 | Element.hide(dijit.byId("filterDlg_actionParam").domNode); | |
599 | } | |
600 | } else { | |
601 | Element.hide(action_param); | |
602 | } | |
603 | ||
604 | } catch (e) { | |
605 | exception_error("filterDlgCheckAction", e); | |
606 | } | |
607 | ||
608 | } | |
609 | ||
610 | ||
611 | function explainError(code) { | |
612 | return displayDlg(__("Error explained"), "explainError", code); | |
613 | } | |
614 | ||
615 | function loading_set_progress(p) { | |
616 | try { | |
617 | loading_progress += p; | |
618 | ||
619 | if (dijit.byId("loading_bar")) | |
620 | dijit.byId("loading_bar").update({progress: loading_progress}); | |
621 | ||
622 | if (loading_progress >= 90) | |
623 | remove_splash(); | |
624 | ||
625 | } catch (e) { | |
626 | exception_error("loading_set_progress", e); | |
627 | } | |
628 | } | |
629 | ||
630 | function remove_splash() { | |
631 | ||
632 | if (Element.visible("overlay")) { | |
633 | console.log("about to remove splash, OMG!"); | |
634 | Element.hide("overlay"); | |
635 | console.log("removed splash!"); | |
636 | } | |
637 | } | |
638 | ||
639 | function transport_error_check(transport) { | |
640 | try { | |
641 | if (transport.responseXML) { | |
642 | var error = transport.responseXML.getElementsByTagName("error")[0]; | |
643 | ||
644 | if (error) { | |
645 | var code = error.getAttribute("error-code"); | |
646 | var msg = error.getAttribute("error-msg"); | |
647 | if (code != 0) { | |
648 | fatalError(code, msg); | |
649 | return false; | |
650 | } | |
651 | } | |
652 | } | |
653 | } catch (e) { | |
654 | exception_error("check_for_error_xml", e); | |
655 | } | |
656 | return true; | |
657 | } | |
658 | ||
659 | function strip_tags(s) { | |
660 | return s.replace(/<\/?[^>]+(>|$)/g, ""); | |
661 | } | |
662 | ||
663 | function truncate_string(s, length) { | |
664 | if (!length) length = 30; | |
665 | var tmp = s.substring(0, length); | |
666 | if (s.length > length) tmp += "…"; | |
667 | return tmp; | |
668 | } | |
669 | ||
670 | function hotkey_prefix_timeout() { | |
671 | try { | |
672 | ||
673 | var date = new Date(); | |
674 | var ts = Math.round(date.getTime() / 1000); | |
675 | ||
676 | if (hotkey_prefix_pressed && ts - hotkey_prefix_pressed >= 5) { | |
677 | console.log("hotkey_prefix seems to be stuck, aborting"); | |
678 | hotkey_prefix_pressed = false; | |
679 | hotkey_prefix = false; | |
680 | Element.hide('cmdline'); | |
681 | } | |
682 | ||
683 | setTimeout("hotkey_prefix_timeout()", 1000); | |
684 | ||
685 | } catch (e) { | |
686 | exception_error("hotkey_prefix_timeout", e); | |
687 | } | |
688 | } | |
689 | ||
690 | function uploadIconHandler(rc) { | |
691 | try { | |
692 | switch (rc) { | |
693 | case 0: | |
694 | notify_info("Upload complete."); | |
695 | if (inPreferences()) { | |
696 | updateFeedList(); | |
697 | } else { | |
698 | setTimeout('updateFeedList(false, false)', 50); | |
699 | } | |
700 | break; | |
701 | case 1: | |
702 | notify_error("Upload failed: icon is too big."); | |
703 | break; | |
704 | case 2: | |
705 | notify_error("Upload failed."); | |
706 | break; | |
707 | } | |
708 | ||
709 | } catch (e) { | |
710 | exception_error("uploadIconHandler", e); | |
711 | } | |
712 | } | |
713 | ||
714 | function removeFeedIcon(id) { | |
715 | ||
716 | try { | |
717 | ||
718 | if (confirm(__("Remove stored feed icon?"))) { | |
719 | var query = "backend.php?op=pref-feeds&method=removeicon&feed_id=" + param_escape(id); | |
720 | ||
721 | console.log(query); | |
722 | ||
723 | notify_progress("Removing feed icon...", true); | |
724 | ||
725 | new Ajax.Request("backend.php", { | |
726 | parameters: query, | |
727 | onComplete: function(transport) { | |
728 | notify_info("Feed icon removed."); | |
729 | if (inPreferences()) { | |
730 | updateFeedList(); | |
731 | } else { | |
732 | setTimeout('updateFeedList(false, false)', 50); | |
733 | } | |
734 | } }); | |
735 | } | |
736 | ||
737 | return false; | |
738 | } catch (e) { | |
739 | exception_error("removeFeedIcon", e); | |
740 | } | |
741 | } | |
742 | ||
743 | function uploadFeedIcon() { | |
744 | ||
745 | try { | |
746 | ||
747 | var file = $("icon_file"); | |
748 | ||
749 | if (file.value.length == 0) { | |
750 | alert(__("Please select an image file to upload.")); | |
751 | } else { | |
752 | if (confirm(__("Upload new icon for this feed?"))) { | |
753 | notify_progress("Uploading, please wait...", true); | |
754 | return true; | |
755 | } | |
756 | } | |
757 | ||
758 | return false; | |
759 | ||
760 | } catch (e) { | |
761 | exception_error("uploadFeedIcon", e); | |
762 | } | |
763 | } | |
764 | ||
765 | function addLabel(select, callback) { | |
766 | ||
767 | try { | |
768 | ||
769 | var caption = prompt(__("Please enter label caption:"), ""); | |
770 | ||
771 | if (caption != undefined) { | |
772 | ||
773 | if (caption == "") { | |
774 | alert(__("Can't create label: missing caption.")); | |
775 | return false; | |
776 | } | |
777 | ||
778 | var query = "?op=pref-labels&method=add&caption=" + | |
779 | param_escape(caption); | |
780 | ||
781 | if (select) | |
782 | query += "&output=select"; | |
783 | ||
784 | notify_progress("Loading, please wait...", true); | |
785 | ||
786 | if (inPreferences() && !select) active_tab = "labelConfig"; | |
787 | ||
788 | new Ajax.Request("backend.php", { | |
789 | parameters: query, | |
790 | onComplete: function(transport) { | |
791 | if (callback) { | |
792 | callback(transport); | |
793 | } else if (inPreferences()) { | |
794 | updateLabelList(); | |
795 | } else { | |
796 | updateFeedList(); | |
797 | } | |
798 | } }); | |
799 | ||
800 | } | |
801 | ||
802 | } catch (e) { | |
803 | exception_error("addLabel", e); | |
804 | } | |
805 | } | |
806 | ||
807 | function quickAddFeed() { | |
808 | try { | |
809 | var query = "backend.php?op=feeds&method=quickAddFeed"; | |
810 | ||
811 | // overlapping widgets | |
812 | if (dijit.byId("batchSubDlg")) dijit.byId("batchSubDlg").destroyRecursive(); | |
813 | if (dijit.byId("feedAddDlg")) dijit.byId("feedAddDlg").destroyRecursive(); | |
814 | ||
815 | var dialog = new dijit.Dialog({ | |
816 | id: "feedAddDlg", | |
817 | title: __("Subscribe to Feed"), | |
818 | style: "width: 600px", | |
819 | execute: function() { | |
820 | if (this.validate()) { | |
821 | console.log(dojo.objectToQuery(this.attr('value'))); | |
822 | ||
823 | var feed_url = this.attr('value').feed; | |
824 | ||
825 | Element.show("feed_add_spinner"); | |
826 | ||
827 | new Ajax.Request("backend.php", { | |
828 | parameters: dojo.objectToQuery(this.attr('value')), | |
829 | onComplete: function(transport) { | |
830 | try { | |
831 | ||
832 | var reply = JSON.parse(transport.responseText); | |
833 | ||
834 | var rc = reply['result']; | |
835 | ||
836 | notify(''); | |
837 | Element.hide("feed_add_spinner"); | |
838 | ||
839 | console.log(rc); | |
840 | ||
841 | switch (parseInt(rc['code'])) { | |
842 | case 1: | |
843 | dialog.hide(); | |
844 | notify_info(__("Subscribed to %s").replace("%s", feed_url)); | |
845 | ||
846 | updateFeedList(); | |
847 | break; | |
848 | case 2: | |
849 | alert(__("Specified URL seems to be invalid.")); | |
850 | break; | |
851 | case 3: | |
852 | alert(__("Specified URL doesn't seem to contain any feeds.")); | |
853 | break; | |
854 | case 4: | |
855 | feeds = rc['feeds']; | |
856 | ||
857 | Element.show("fadd_multiple_notify"); | |
858 | ||
859 | var select = dijit.byId("feedDlg_feedContainerSelect"); | |
860 | ||
861 | while (select.getOptions().length > 0) | |
862 | select.removeOption(0); | |
863 | ||
864 | select.addOption({value: '', label: __("Expand to select feed")}); | |
865 | ||
866 | var count = 0; | |
867 | for (var feedUrl in feeds) { | |
868 | select.addOption({value: feedUrl, label: feeds[feedUrl]}); | |
869 | count++; | |
870 | } | |
871 | ||
872 | Effect.Appear('feedDlg_feedsContainer', {duration : 0.5}); | |
873 | ||
874 | break; | |
875 | case 5: | |
876 | alert(__("Couldn't download the specified URL: %s"). | |
877 | replace("%s", rc['message'])); | |
878 | break; | |
879 | case 6: | |
880 | alert(__("XML validation failed: %s"). | |
881 | replace("%s", rc['message'])); | |
882 | break; | |
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 | for (k in params) { | |
1275 | var v = params[k]; | |
1276 | console.log("IP: " + k + " => " + v); | |
1277 | ||
1278 | if (k == "label_base_index") _label_base_index = parseInt(v); | |
1279 | } | |
1280 | ||
1281 | init_params = params; | |
1282 | ||
1283 | // PluginHost might not be available on non-index pages | |
1284 | window.PluginHost && PluginHost.run(PluginHost.HOOK_PARAMS_LOADED, init_params); | |
1285 | } | |
1286 | ||
1287 | sanity_check_done = true; | |
1288 | ||
1289 | init_second_stage(); | |
1290 | ||
1291 | } catch (e) { | |
1292 | exception_error("backend_sanity_check_callback", e, transport); | |
1293 | } | |
1294 | } | |
1295 | ||
1296 | /*function has_local_storage() { | |
1297 | try { | |
1298 | return 'sessionStorage' in window && window['sessionStorage'] != null; | |
1299 | } catch (e) { | |
1300 | return false; | |
1301 | } | |
1302 | } */ | |
1303 | ||
1304 | function catSelectOnChange(elem) { | |
1305 | try { | |
1306 | /* var value = elem[elem.selectedIndex].value; | |
1307 | var def = elem.getAttribute('default'); | |
1308 | ||
1309 | if (value == "ADD_CAT") { | |
1310 | ||
1311 | if (def) | |
1312 | dropboxSelect(elem, def); | |
1313 | else | |
1314 | elem.selectedIndex = 0; | |
1315 | ||
1316 | quickAddCat(elem); | |
1317 | } */ | |
1318 | ||
1319 | } catch (e) { | |
1320 | exception_error("catSelectOnChange", e); | |
1321 | } | |
1322 | } | |
1323 | ||
1324 | function quickAddCat(elem) { | |
1325 | try { | |
1326 | var cat = prompt(__("Please enter category title:")); | |
1327 | ||
1328 | if (cat) { | |
1329 | ||
1330 | var query = "?op=rpc&method=quickAddCat&cat=" + param_escape(cat); | |
1331 | ||
1332 | notify_progress("Loading, please wait...", true); | |
1333 | ||
1334 | new Ajax.Request("backend.php", { | |
1335 | parameters: query, | |
1336 | onComplete: function (transport) { | |
1337 | var response = transport.responseXML; | |
1338 | var select = response.getElementsByTagName("select")[0]; | |
1339 | var options = select.getElementsByTagName("option"); | |
1340 | ||
1341 | dropbox_replace_options(elem, options); | |
1342 | ||
1343 | notify(''); | |
1344 | ||
1345 | } }); | |
1346 | ||
1347 | } | |
1348 | ||
1349 | } catch (e) { | |
1350 | exception_error("quickAddCat", e); | |
1351 | } | |
1352 | } | |
1353 | ||
1354 | function genUrlChangeKey(feed, is_cat) { | |
1355 | ||
1356 | try { | |
1357 | var ok = confirm(__("Generate new syndication address for this feed?")); | |
1358 | ||
1359 | if (ok) { | |
1360 | ||
1361 | notify_progress("Trying to change address...", true); | |
1362 | ||
1363 | var query = "?op=pref-feeds&method=regenFeedKey&id=" + param_escape(feed) + | |
1364 | "&is_cat=" + param_escape(is_cat); | |
1365 | ||
1366 | new Ajax.Request("backend.php", { | |
1367 | parameters: query, | |
1368 | onComplete: function(transport) { | |
1369 | var reply = JSON.parse(transport.responseText); | |
1370 | var new_link = reply.link; | |
1371 | ||
1372 | var e = $('gen_feed_url'); | |
1373 | ||
1374 | if (new_link) { | |
1375 | ||
1376 | e.innerHTML = e.innerHTML.replace(/\&key=.*$/, | |
1377 | "&key=" + new_link); | |
1378 | ||
1379 | e.href = e.href.replace(/\&key=.*$/, | |
1380 | "&key=" + new_link); | |
1381 | ||
1382 | new Effect.Highlight(e); | |
1383 | ||
1384 | notify(''); | |
1385 | ||
1386 | } else { | |
1387 | notify_error("Could not change feed URL."); | |
1388 | } | |
1389 | } }); | |
1390 | } | |
1391 | } catch (e) { | |
1392 | exception_error("genUrlChangeKey", e); | |
1393 | } | |
1394 | return false; | |
1395 | } | |
1396 | ||
1397 | function labelSelectOnChange(elem) { | |
1398 | try { | |
1399 | /* var value = elem[elem.selectedIndex].value; | |
1400 | var def = elem.getAttribute('default'); | |
1401 | ||
1402 | if (value == "ADD_LABEL") { | |
1403 | ||
1404 | if (def) | |
1405 | dropboxSelect(elem, def); | |
1406 | else | |
1407 | elem.selectedIndex = 0; | |
1408 | ||
1409 | addLabel(elem, function(transport) { | |
1410 | ||
1411 | try { | |
1412 | ||
1413 | var response = transport.responseXML; | |
1414 | var select = response.getElementsByTagName("select")[0]; | |
1415 | var options = select.getElementsByTagName("option"); | |
1416 | ||
1417 | dropbox_replace_options(elem, options); | |
1418 | ||
1419 | notify(''); | |
1420 | } catch (e) { | |
1421 | exception_error("addLabel", e); | |
1422 | } | |
1423 | }); | |
1424 | } */ | |
1425 | ||
1426 | } catch (e) { | |
1427 | exception_error("labelSelectOnChange", e); | |
1428 | } | |
1429 | } | |
1430 | ||
1431 | function dropbox_replace_options(elem, options) { | |
1432 | ||
1433 | try { | |
1434 | while (elem.hasChildNodes()) | |
1435 | elem.removeChild(elem.firstChild); | |
1436 | ||
1437 | var sel_idx = -1; | |
1438 | ||
1439 | for (var i = 0; i < options.length; i++) { | |
1440 | var text = options[i].firstChild.nodeValue; | |
1441 | var value = options[i].getAttribute("value"); | |
1442 | ||
1443 | if (value == undefined) value = text; | |
1444 | ||
1445 | var issel = options[i].getAttribute("selected") == "1"; | |
1446 | ||
1447 | var option = new Option(text, value, issel); | |
1448 | ||
1449 | if (options[i].getAttribute("disabled")) | |
1450 | option.setAttribute("disabled", true); | |
1451 | ||
1452 | elem.insert(option); | |
1453 | ||
1454 | if (issel) sel_idx = i; | |
1455 | } | |
1456 | ||
1457 | // Chrome doesn't seem to just select stuff when you pass new Option(x, y, true) | |
1458 | if (sel_idx >= 0) elem.selectedIndex = sel_idx; | |
1459 | ||
1460 | } catch (e) { | |
1461 | exception_error("dropbox_replace_options", e); | |
1462 | } | |
1463 | } | |
1464 | ||
1465 | // mode = all, none, invert | |
1466 | function selectTableRows(id, mode) { | |
1467 | try { | |
1468 | var rows = $(id).rows; | |
1469 | ||
1470 | for (var i = 0; i < rows.length; i++) { | |
1471 | var row = rows[i]; | |
1472 | var cb = false; | |
1473 | var dcb = false; | |
1474 | ||
1475 | if (row.id && row.className) { | |
1476 | var bare_id = row.id.replace(/^[A-Z]*?-/, ""); | |
1477 | var inputs = rows[i].getElementsByTagName("input"); | |
1478 | ||
1479 | for (var j = 0; j < inputs.length; j++) { | |
1480 | var input = inputs[j]; | |
1481 | ||
1482 | if (input.getAttribute("type") == "checkbox" && | |
1483 | input.id.match(bare_id)) { | |
1484 | ||
1485 | cb = input; | |
1486 | dcb = dijit.getEnclosingWidget(cb); | |
1487 | break; | |
1488 | } | |
1489 | } | |
1490 | ||
1491 | if (cb || dcb) { | |
1492 | var issel = row.hasClassName("Selected"); | |
1493 | ||
1494 | if (mode == "all" && !issel) { | |
1495 | row.addClassName("Selected"); | |
1496 | cb.checked = true; | |
1497 | if (dcb) dcb.set("checked", true); | |
1498 | } else if (mode == "none" && issel) { | |
1499 | row.removeClassName("Selected"); | |
1500 | cb.checked = false; | |
1501 | if (dcb) dcb.set("checked", false); | |
1502 | ||
1503 | } else if (mode == "invert") { | |
1504 | ||
1505 | if (issel) { | |
1506 | row.removeClassName("Selected"); | |
1507 | cb.checked = false; | |
1508 | if (dcb) dcb.set("checked", false); | |
1509 | } else { | |
1510 | row.addClassName("Selected"); | |
1511 | cb.checked = true; | |
1512 | if (dcb) dcb.set("checked", true); | |
1513 | } | |
1514 | } | |
1515 | } | |
1516 | } | |
1517 | } | |
1518 | ||
1519 | } catch (e) { | |
1520 | exception_error("selectTableRows", e); | |
1521 | ||
1522 | } | |
1523 | } | |
1524 | ||
1525 | function getSelectedTableRowIds(id) { | |
1526 | var rows = []; | |
1527 | ||
1528 | try { | |
1529 | var elem_rows = $(id).rows; | |
1530 | ||
1531 | for (var i = 0; i < elem_rows.length; i++) { | |
1532 | if (elem_rows[i].hasClassName("Selected")) { | |
1533 | var bare_id = elem_rows[i].id.replace(/^[A-Z]*?-/, ""); | |
1534 | rows.push(bare_id); | |
1535 | } | |
1536 | } | |
1537 | ||
1538 | } catch (e) { | |
1539 | exception_error("getSelectedTableRowIds", e); | |
1540 | } | |
1541 | ||
1542 | return rows; | |
1543 | } | |
1544 | ||
1545 | function editFeed(feed, event) { | |
1546 | try { | |
1547 | if (feed <= 0) | |
1548 | return alert(__("You can't edit this kind of feed.")); | |
1549 | ||
1550 | var query = "backend.php?op=pref-feeds&method=editfeed&id=" + | |
1551 | param_escape(feed); | |
1552 | ||
1553 | console.log(query); | |
1554 | ||
1555 | if (dijit.byId("filterEditDlg")) | |
1556 | dijit.byId("filterEditDlg").destroyRecursive(); | |
1557 | ||
1558 | if (dijit.byId("feedEditDlg")) | |
1559 | dijit.byId("feedEditDlg").destroyRecursive(); | |
1560 | ||
1561 | dialog = new dijit.Dialog({ | |
1562 | id: "feedEditDlg", | |
1563 | title: __("Edit Feed"), | |
1564 | style: "width: 600px", | |
1565 | execute: function() { | |
1566 | if (this.validate()) { | |
1567 | // console.log(dojo.objectToQuery(this.attr('value'))); | |
1568 | ||
1569 | notify_progress("Saving data...", true); | |
1570 | ||
1571 | new Ajax.Request("backend.php", { | |
1572 | parameters: dojo.objectToQuery(dialog.attr('value')), | |
1573 | onComplete: function(transport) { | |
1574 | dialog.hide(); | |
1575 | notify(''); | |
1576 | updateFeedList(); | |
1577 | }}); | |
1578 | } | |
1579 | }, | |
1580 | href: query}); | |
1581 | ||
1582 | dialog.show(); | |
1583 | ||
1584 | } catch (e) { | |
1585 | exception_error("editFeed", e); | |
1586 | } | |
1587 | } | |
1588 | ||
1589 | function feedBrowser() { | |
1590 | try { | |
1591 | var query = "backend.php?op=feeds&method=feedBrowser"; | |
1592 | ||
1593 | if (dijit.byId("feedAddDlg")) | |
1594 | dijit.byId("feedAddDlg").hide(); | |
1595 | ||
1596 | if (dijit.byId("feedBrowserDlg")) | |
1597 | dijit.byId("feedBrowserDlg").destroyRecursive(); | |
1598 | ||
1599 | var dialog = new dijit.Dialog({ | |
1600 | id: "feedBrowserDlg", | |
1601 | title: __("More Feeds"), | |
1602 | style: "width: 600px", | |
1603 | getSelectedFeedIds: function() { | |
1604 | var list = $$("#browseFeedList li[id*=FBROW]"); | |
1605 | var selected = new Array(); | |
1606 | ||
1607 | list.each(function(child) { | |
1608 | var id = child.id.replace("FBROW-", ""); | |
1609 | ||
1610 | if (child.hasClassName('Selected')) { | |
1611 | selected.push(id); | |
1612 | } | |
1613 | }); | |
1614 | ||
1615 | return selected; | |
1616 | }, | |
1617 | getSelectedFeeds: function() { | |
1618 | var list = $$("#browseFeedList li.Selected"); | |
1619 | var selected = new Array(); | |
1620 | ||
1621 | list.each(function(child) { | |
1622 | var title = child.getElementsBySelector("span.fb_feedTitle")[0].innerHTML; | |
1623 | var url = child.getElementsBySelector("a.fb_feedUrl")[0].href; | |
1624 | ||
1625 | selected.push([title,url]); | |
1626 | ||
1627 | }); | |
1628 | ||
1629 | return selected; | |
1630 | }, | |
1631 | ||
1632 | subscribe: function() { | |
1633 | var mode = this.attr('value').mode; | |
1634 | var selected = []; | |
1635 | ||
1636 | if (mode == "1") | |
1637 | selected = this.getSelectedFeeds(); | |
1638 | else | |
1639 | selected = this.getSelectedFeedIds(); | |
1640 | ||
1641 | if (selected.length > 0) { | |
1642 | dijit.byId("feedBrowserDlg").hide(); | |
1643 | ||
1644 | notify_progress("Loading, please wait...", true); | |
1645 | ||
1646 | // we use dojo.toJson instead of JSON.stringify because | |
1647 | // it somehow escapes everything TWICE, at least in Chrome 9 | |
1648 | ||
1649 | var query = "?op=rpc&method=massSubscribe&payload="+ | |
1650 | param_escape(dojo.toJson(selected)) + "&mode=" + param_escape(mode); | |
1651 | ||
1652 | console.log(query); | |
1653 | ||
1654 | new Ajax.Request("backend.php", { | |
1655 | parameters: query, | |
1656 | onComplete: function(transport) { | |
1657 | notify(''); | |
1658 | updateFeedList(); | |
1659 | } }); | |
1660 | ||
1661 | } else { | |
1662 | alert(__("No feeds are selected.")); | |
1663 | } | |
1664 | ||
1665 | }, | |
1666 | update: function() { | |
1667 | var query = dojo.objectToQuery(dialog.attr('value')); | |
1668 | ||
1669 | Element.show('feed_browser_spinner'); | |
1670 | ||
1671 | new Ajax.Request("backend.php", { | |
1672 | parameters: query, | |
1673 | onComplete: function(transport) { | |
1674 | notify(''); | |
1675 | ||
1676 | Element.hide('feed_browser_spinner'); | |
1677 | ||
1678 | var c = $("browseFeedList"); | |
1679 | ||
1680 | var reply = JSON.parse(transport.responseText); | |
1681 | ||
1682 | var r = reply['content']; | |
1683 | var mode = reply['mode']; | |
1684 | ||
1685 | if (c && r) { | |
1686 | c.innerHTML = r; | |
1687 | } | |
1688 | ||
1689 | dojo.parser.parse("browseFeedList"); | |
1690 | ||
1691 | if (mode == 2) { | |
1692 | Element.show(dijit.byId('feed_archive_remove').domNode); | |
1693 | } else { | |
1694 | Element.hide(dijit.byId('feed_archive_remove').domNode); | |
1695 | } | |
1696 | ||
1697 | } }); | |
1698 | }, | |
1699 | removeFromArchive: function() { | |
1700 | var selected = this.getSelectedFeedIds(); | |
1701 | ||
1702 | if (selected.length > 0) { | |
1703 | ||
1704 | var pr = __("Remove selected feeds from the archive? Feeds with stored articles will not be removed."); | |
1705 | ||
1706 | if (confirm(pr)) { | |
1707 | Element.show('feed_browser_spinner'); | |
1708 | ||
1709 | var query = "?op=rpc&method=remarchive&ids=" + | |
1710 | param_escape(selected.toString());; | |
1711 | ||
1712 | new Ajax.Request("backend.php", { | |
1713 | parameters: query, | |
1714 | onComplete: function(transport) { | |
1715 | dialog.update(); | |
1716 | } }); | |
1717 | } | |
1718 | } | |
1719 | }, | |
1720 | execute: function() { | |
1721 | if (this.validate()) { | |
1722 | this.subscribe(); | |
1723 | } | |
1724 | }, | |
1725 | href: query}); | |
1726 | ||
1727 | dialog.show(); | |
1728 | ||
1729 | } catch (e) { | |
1730 | exception_error("editFeed", e); | |
1731 | } | |
1732 | } | |
1733 | ||
1734 | function showFeedsWithErrors() { | |
1735 | try { | |
1736 | var query = "backend.php?op=pref-feeds&method=feedsWithErrors"; | |
1737 | ||
1738 | if (dijit.byId("errorFeedsDlg")) | |
1739 | dijit.byId("errorFeedsDlg").destroyRecursive(); | |
1740 | ||
1741 | dialog = new dijit.Dialog({ | |
1742 | id: "errorFeedsDlg", | |
1743 | title: __("Feeds with update errors"), | |
1744 | style: "width: 600px", | |
1745 | getSelectedFeeds: function() { | |
1746 | return getSelectedTableRowIds("prefErrorFeedList"); | |
1747 | }, | |
1748 | removeSelected: function() { | |
1749 | var sel_rows = this.getSelectedFeeds(); | |
1750 | ||
1751 | console.log(sel_rows); | |
1752 | ||
1753 | if (sel_rows.length > 0) { | |
1754 | var ok = confirm(__("Remove selected feeds?")); | |
1755 | ||
1756 | if (ok) { | |
1757 | notify_progress("Removing selected feeds...", true); | |
1758 | ||
1759 | var query = "?op=pref-feeds&method=remove&ids="+ | |
1760 | param_escape(sel_rows.toString()); | |
1761 | ||
1762 | new Ajax.Request("backend.php", { | |
1763 | parameters: query, | |
1764 | onComplete: function(transport) { | |
1765 | notify(''); | |
1766 | dialog.hide(); | |
1767 | updateFeedList(); | |
1768 | } }); | |
1769 | } | |
1770 | ||
1771 | } else { | |
1772 | alert(__("No feeds are selected.")); | |
1773 | } | |
1774 | }, | |
1775 | execute: function() { | |
1776 | if (this.validate()) { | |
1777 | } | |
1778 | }, | |
1779 | href: query}); | |
1780 | ||
1781 | dialog.show(); | |
1782 | ||
1783 | } catch (e) { | |
1784 | exception_error("showFeedsWithErrors", e); | |
1785 | } | |
1786 | ||
1787 | } | |
1788 | ||
1789 | /* new support functions for SelectByTag */ | |
1790 | ||
1791 | function get_all_tags(selObj){ | |
1792 | try { | |
1793 | if( !selObj ) return ""; | |
1794 | ||
1795 | var result = ""; | |
1796 | var len = selObj.options.length; | |
1797 | ||
1798 | for (var i=0; i < len; i++){ | |
1799 | if (selObj.options[i].selected) { | |
1800 | result += selObj[i].value + "%2C"; // is really a comma | |
1801 | } | |
1802 | } | |
1803 | ||
1804 | if (result.length > 0){ | |
1805 | result = result.substr(0, result.length-3); // remove trailing %2C | |
1806 | } | |
1807 | ||
1808 | return(result); | |
1809 | ||
1810 | } catch (e) { | |
1811 | exception_error("get_all_tags", e); | |
1812 | } | |
1813 | } | |
1814 | ||
1815 | function get_radio_checked(radioObj) { | |
1816 | try { | |
1817 | if (!radioObj) return ""; | |
1818 | ||
1819 | var len = radioObj.length; | |
1820 | ||
1821 | if (len == undefined){ | |
1822 | if(radioObj.checked){ | |
1823 | return(radioObj.value); | |
1824 | } else { | |
1825 | return(""); | |
1826 | } | |
1827 | } | |
1828 | ||
1829 | for( var i=0; i < len; i++ ){ | |
1830 | if( radioObj[i].checked ){ | |
1831 | return( radioObj[i].value); | |
1832 | } | |
1833 | } | |
1834 | ||
1835 | } catch (e) { | |
1836 | exception_error("get_radio_checked", e); | |
1837 | } | |
1838 | return(""); | |
1839 | } | |
1840 | ||
1841 | function get_timestamp() { | |
1842 | var date = new Date(); | |
1843 | return Math.round(date.getTime() / 1000); | |
1844 | } | |
1845 | ||
1846 | function helpDialog(topic) { | |
1847 | try { | |
1848 | var query = "backend.php?op=backend&method=help&topic=" + param_escape(topic); | |
1849 | ||
1850 | if (dijit.byId("helpDlg")) | |
1851 | dijit.byId("helpDlg").destroyRecursive(); | |
1852 | ||
1853 | dialog = new dijit.Dialog({ | |
1854 | id: "helpDlg", | |
1855 | title: __("Help"), | |
1856 | style: "width: 600px", | |
1857 | href: query, | |
1858 | }); | |
1859 | ||
1860 | dialog.show(); | |
1861 | ||
1862 | } catch (e) { | |
1863 | exception_error("helpDialog", e); | |
1864 | } | |
1865 | } | |
1866 | ||
1867 | function htmlspecialchars_decode (string, quote_style) { | |
1868 | // http://kevin.vanzonneveld.net | |
1869 | // + original by: Mirek Slugen | |
1870 | // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) | |
1871 | // + bugfixed by: Mateusz "loonquawl" Zalega | |
1872 | // + input by: ReverseSyntax | |
1873 | // + input by: Slawomir Kaniecki | |
1874 | // + input by: Scott Cariss | |
1875 | // + input by: Francois | |
1876 | // + bugfixed by: Onno Marsman | |
1877 | // + revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) | |
1878 | // + bugfixed by: Brett Zamir (http://brett-zamir.me) | |
1879 | // + input by: Ratheous | |
1880 | // + input by: Mailfaker (http://www.weedem.fr/) | |
1881 | // + reimplemented by: Brett Zamir (http://brett-zamir.me) | |
1882 | // + bugfixed by: Brett Zamir (http://brett-zamir.me) | |
1883 | // * example 1: htmlspecialchars_decode("<p>this -> "</p>", 'ENT_NOQUOTES'); | |
1884 | // * returns 1: '<p>this -> "</p>' | |
1885 | // * example 2: htmlspecialchars_decode("&quot;"); | |
1886 | // * returns 2: '"' | |
1887 | var optTemp = 0, | |
1888 | i = 0, | |
1889 | noquotes = false; | |
1890 | if (typeof quote_style === 'undefined') { | |
1891 | quote_style = 2; | |
1892 | } | |
1893 | string = string.toString().replace(/</g, '<').replace(/>/g, '>'); | |
1894 | var OPTS = { | |
1895 | 'ENT_NOQUOTES': 0, | |
1896 | 'ENT_HTML_QUOTE_SINGLE': 1, | |
1897 | 'ENT_HTML_QUOTE_DOUBLE': 2, | |
1898 | 'ENT_COMPAT': 2, | |
1899 | 'ENT_QUOTES': 3, | |
1900 | 'ENT_IGNORE': 4 | |
1901 | }; | |
1902 | if (quote_style === 0) { | |
1903 | noquotes = true; | |
1904 | } | |
1905 | if (typeof quote_style !== 'number') { // Allow for a single string or an array of string flags | |
1906 | quote_style = [].concat(quote_style); | |
1907 | for (i = 0; i < quote_style.length; i++) { | |
1908 | // Resolve string input to bitwise e.g. 'PATHINFO_EXTENSION' becomes 4 | |
1909 | if (OPTS[quote_style[i]] === 0) { | |
1910 | noquotes = true; | |
1911 | } else if (OPTS[quote_style[i]]) { | |
1912 | optTemp = optTemp | OPTS[quote_style[i]]; | |
1913 | } | |
1914 | } | |
1915 | quote_style = optTemp; | |
1916 | } | |
1917 | if (quote_style & OPTS.ENT_HTML_QUOTE_SINGLE) { | |
1918 | string = string.replace(/�*39;/g, "'"); // PHP doesn't currently escape if more than one 0, but it should | |
1919 | // string = string.replace(/'|�*27;/g, "'"); // This would also be useful here, but not a part of PHP | |
1920 | } | |
1921 | if (!noquotes) { | |
1922 | string = string.replace(/"/g, '"'); | |
1923 | } | |
1924 | // Put this in last place to avoid escape being double-decoded | |
1925 | string = string.replace(/&/g, '&'); | |
1926 | ||
1927 | return string; | |
1928 | } | |
1929 | ||
1930 | ||
1931 | function label_to_feed_id(label) { | |
1932 | return _label_base_index - 1 - Math.abs(label); | |
1933 | } | |
1934 | ||
1935 | function feed_to_label_id(feed) { | |
1936 | return _label_base_index - 1 + Math.abs(feed); | |
1937 | } | |
1938 |