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