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