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