]> git.wh0rd.org - tt-rss.git/blame - tt-rss.js
fix owner_uid checking in OPML export
[tt-rss.git] / tt-rss.js
CommitLineData
1cd17194
AD
1/*
2 This program is Copyright (c) 2003-2005 Andrew Dolgov <cthulhoo@gmail.com>
3 Licensed under GPL v.2 or (at your preference) any later version.
4*/
5
6var xmlhttp = false;
7
76798ff3 8var total_unread = 0;
525116d4 9var first_run = true;
76798ff3 10
8143ae1f
AD
11var display_tags = false;
12
fc69e641
AD
13var global_unread = 0;
14
21703604
AD
15var active_title_text = "";
16
17var current_subtitle = "";
18
1cd17194
AD
19/*@cc_on @*/
20/*@if (@_jscript_version >= 5)
21// JScript gives us Conditional compilation, we can cope with old IE versions.
22// and security blocked creation of the objects.
23try {
24 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
25} catch (e) {
26 try {
27 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
28 } catch (E) {
29 xmlhttp = false;
30 }
31}
32@end @*/
33
34if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
35 xmlhttp = new XMLHttpRequest();
36}
37
8143ae1f
AD
38function toggleTags() {
39 display_tags = !display_tags;
40
41 var p = document.getElementById("dispSwitchPrompt");
42
43 if (display_tags) {
44 p.innerHTML = "display feeds";
45 } else {
46 p.innerHTML = "display tags";
47 }
48
49 updateFeedList();
50}
51
6de5d056 52function dlg_frefresh_callback() {
1cd17194 53 if (xmlhttp.readyState == 4) {
e2f8f7b4 54 updateFeedList(false, false);
f84a97a3 55 closeDlg();
c0e5a40e 56 }
1cd17194 57}
e2f8f7b4 58
f84a97a3
AD
59function dialog_refresh_callback() {
60 if (xmlhttp.readyState == 4) {
61 var dlg = document.getElementById("userDlg");
62
63 dlg.innerHTML = xmlhttp.responseText;
64 dlg.style.display = "block";
65 }
66}
1a66d16e 67
8158c57a 68function refetch_callback() {
29fb8c70 69 if (xmlhttp.readyState == 4) {
310da49d 70
fc69e641 71// document.title = "Tiny Tiny RSS";
310da49d 72
bc18bcdd
AD
73 if (!xmlhttp.responseXML) {
74 notify("refetch_callback: backend did not return valid XML");
75 return;
76 }
262bd8ea 77
090e250b
AD
78 var reply = xmlhttp.responseXML.firstChild;
79
bc18bcdd
AD
80 if (!reply) {
81 notify("refetch_callback: backend did not return expected XML object");
82 return;
9cab3250 83 }
bc18bcdd 84
262bd8ea
AD
85 var error_code = reply.getAttribute("error-code");
86
87 if (error_code && error_code != 0) {
88 return fatalError(error_code);
89 }
90
090e250b
AD
91 var f_document = window.frames["feeds-frame"].document;
92
93 for (var l = 0; l < reply.childNodes.length; l++) {
94 var id = reply.childNodes[l].getAttribute("id");
95 var ctr = reply.childNodes[l].getAttribute("counter");
525116d4 96
090e250b
AD
97 var feedctr = f_document.getElementById("FEEDCTR-" + id);
98 var feedu = f_document.getElementById("FEEDU-" + id);
99 var feedr = f_document.getElementById("FEEDR-" + id);
100
fc69e641
AD
101/* TODO figure out how to update this from viewfeed.js->view()
102 disabled for now...
103
104 if (id == "global-unread") {
105 global_unread = ctr;
106 } */
107
8143ae1f
AD
108 if (feedctr && feedu && feedr) {
109
110 feedu.innerHTML = ctr;
111
112 if (ctr > 0) {
113 feedctr.className = "odd";
114 if (!feedr.className.match("Unread")) {
115 feedr.className = feedr.className + "Unread";
116 }
117 } else {
118 feedctr.className = "invisible";
119 feedr.className = feedr.className.replace("Unread", "");
090e250b 120 }
090e250b
AD
121 }
122 }
fc69e641
AD
123
124 updateTitle("");
125 notify("All feeds updated.");
126
090e250b
AD
127 }
128}
1a66d16e 129
295f9b42
AD
130function backend_sanity_check_callback() {
131
132 if (xmlhttp.readyState == 4) {
133
134 if (!xmlhttp.responseXML) {
135 fatalError(3);
136 return;
137 }
138
139 var reply = xmlhttp.responseXML.firstChild;
140
141 if (!reply) {
142 fatalError(3);
143 return;
144 }
145
262bd8ea 146 var error_code = reply.getAttribute("error-code");
295f9b42
AD
147
148 if (error_code && error_code != 0) {
149 return fatalError(error_code);
150 }
151
152 init_second_stage();
153 }
154}
155
a5873b2e 156/* wtf this is obsolete
caa4e57f
AD
157function updateFeed(feed_id) {
158
159 var query_str = "backend.php?op=rpc&subop=updateFeed&feed=" + feed_id;
160
29fb8c70
AD
161 if (xmlhttp_ready(xmlhttp)) {
162 xmlhttp.open("GET", query_str, true);
163 xmlhttp.onreadystatechange=feed_update_callback;
164 xmlhttp.send(null);
caa4e57f
AD
165 } else {
166 printLockingError();
167 }
168
169}
a5873b2e 170*/
caa4e57f 171
cb246176 172function scheduleFeedUpdate(force) {
525116d4
AD
173
174 notify("Updating feeds in background...");
175
fc69e641
AD
176// document.title = "Tiny Tiny RSS - Updating...";
177
21703604 178 updateTitle("Updating");
55193822 179
cb246176
AD
180 var query_str = "backend.php?op=rpc&subop=";
181
182 if (force) {
c3b81db0 183 query_str = query_str + "forceUpdateAllFeeds";
cb246176 184 } else {
c3b81db0 185 query_str = query_str + "updateAllFeeds";
cb246176 186 }
525116d4 187
9826bd2e
AD
188 var omode;
189
190 if (display_tags) {
191 omode = "t";
192 } else {
193 omode = "fl";
194 }
195
196 query_str = query_str + "&omode=" + omode;
197
29fb8c70
AD
198 if (xmlhttp_ready(xmlhttp)) {
199 xmlhttp.open("GET", query_str, true);
200 xmlhttp.onreadystatechange=refetch_callback;
201 xmlhttp.send(null);
525116d4
AD
202 } else {
203 printLockingError();
c0e5a40e 204 }
525116d4 205}
1cd17194 206
525116d4 207function updateFeedList(silent, fetch) {
c0e5a40e 208
1a66d16e
AD
209// if (silent != true) {
210// notify("Loading feed list...");
211// }
82baad4a 212
331900c6
AD
213 var query_str = "backend.php?op=feeds";
214
8143ae1f
AD
215 if (display_tags) {
216 query_str = query_str + "&tags=1";
217 }
218
86741347
AD
219 if (getActiveFeedId()) {
220 query_str = query_str + "&actid=" + getActiveFeedId();
175847de
AD
221 }
222
1a66d16e 223 if (fetch) query_str = query_str + "&fetch=yes";
e1123aee 224
1a66d16e 225 var feeds_frame = document.getElementById("feeds-frame");
e1123aee 226
1a66d16e
AD
227 feeds_frame.src = query_str;
228}
175847de 229
476cac42 230function catchupAllFeeds() {
076682aa 231
476cac42
AD
232 var query_str = "backend.php?op=feeds&subop=catchupAll";
233
234 notify("Marking all feeds as read...");
235
1a66d16e
AD
236 var feeds_frame = document.getElementById("feeds-frame");
237
238 feeds_frame.src = query_str;
476cac42 239
fc69e641 240 global_unread = 0;
21703604 241 updateTitle("");
fc69e641 242
476cac42 243}
1cd17194 244
f0601b87 245function viewCurrentFeed(skip, subop) {
1a66d16e 246
86741347
AD
247 if (getActiveFeedId()) {
248 viewfeed(getActiveFeedId(), skip, subop);
033e47e0
AD
249 } else {
250 disableContainerChildren("headlinesToolbar", false, document);
251 viewfeed(-1, skip, subop); // FIXME
f0601b87
AD
252 }
253}
254
476cac42 255function viewfeed(feed, skip, subop) {
db8d6f67
AD
256 var f = window.frames["feeds-frame"];
257 f.viewfeed(feed, skip, subop);
9cfc649a
AD
258}
259
40d13c28 260function timeout() {
05732aa0 261 scheduleFeedUpdate(false);
ac53063a 262 setTimeout("timeout()", 1800*1000);
ac53063a
AD
263}
264
c374a3fe 265function resetSearch() {
64c620ce
AD
266 var searchbox = document.getElementById("searchbox")
267
86741347 268 if (searchbox.value != "" && getActiveFeedId()) {
64c620ce 269 searchbox.value = "";
86741347 270 viewfeed(getActiveFeedId(), 0, "");
ac43eba1 271 }
c374a3fe 272}
ac53063a 273
f0601b87 274function search() {
4ce19859 275 viewCurrentFeed(0, "");
76798ff3 276}
1cd17194 277
13ad9102
AD
278function localPiggieFunction(enable) {
279 if (enable) {
280 var query_str = "backend.php?op=feeds&subop=piggie";
281
c0e5a40e 282 if (xmlhttp_ready(xmlhttp)) {
13ad9102
AD
283
284 xmlhttp.open("GET", query_str, true);
285 xmlhttp.onreadystatechange=feedlist_callback;
286 xmlhttp.send(null);
287 }
288 }
289}
290
9cfc649a
AD
291function localHotkeyHandler(keycode) {
292
f0601b87 293/* if (keycode == 78) {
c3a8d71a 294 return moveToPost('next');
9cfc649a
AD
295 }
296
297 if (keycode == 80) {
c3a8d71a 298 return moveToPost('prev');
f0601b87 299 } */
c3a8d71a 300
b623b3ed 301 if (keycode == 82) { // r
c3a8d71a
AD
302 return scheduleFeedUpdate(true);
303 }
304
b623b3ed
AD
305 if (keycode == 85) { // u
306 if (getActiveFeedId()) {
307 return viewfeed(getActiveFeedId(), 0, "ForceUpdate");
308 }
309 }
310
311 if (keycode == 65) { // a
312 return toggleDispRead();
c3a8d71a
AD
313 }
314
315// notify("KC: " + keycode);
316
9cfc649a
AD
317}
318
fc69e641
AD
319function updateTitle(s) {
320 var tmp = "Tiny Tiny RSS";
21703604
AD
321
322 if (s && s.length > 0) {
323 current_subtitle = s;
324 }
325
fc69e641
AD
326 if (global_unread > 0) {
327 tmp = tmp + " (" + global_unread + ")";
328 }
329
330 if (s) {
21703604 331 tmp = tmp + " - " + current_subtitle;
fc69e641 332 }
21703604
AD
333
334 if (active_title_text.length > 0) {
335 tmp = tmp + " > " + active_title_text;
336 }
337
fc69e641
AD
338 document.title = tmp;
339}
340
22a93ad8 341function genericSanityCheck() {
ac43eba1 342
295f9b42
AD
343 if (!xmlhttp) fatalError(1);
344
345 setCookie("ttrss_vf_test", "TEST");
346
347 if (getCookie("ttrss_vf_test") != "TEST") {
348 fatalError(2);
349 }
350
351/* if (!xmlhttp) {
c3a8d71a 352 document.getElementById("headlines").innerHTML =
29fb8c70 353 "<b>Fatal error:</b> This program requires XmlHttpRequest " +
c3a8d71a 354 "to function properly. Your browser doesn't seem to support it.";
22a93ad8
AD
355 return false;
356 }
357
358 setCookie("ttrss_vf_test", "TEST");
359 if (getCookie("ttrss_vf_test") != "TEST") {
360
361 document.getElementById("headlines").innerHTML =
362 "<b>Fatal error:</b> This program requires cookies " +
363 "to function properly. Your browser doesn't seem to support them.";
364
365 return false;
295f9b42 366 } */
c3a8d71a 367
22a93ad8
AD
368 return true;
369}
370
371function init() {
372
373 disableContainerChildren("headlinesToolbar", true);
374
375 if (!genericSanityCheck())
376 return;
377
295f9b42
AD
378 xmlhttp.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
379 xmlhttp.onreadystatechange=backend_sanity_check_callback;
380 xmlhttp.send(null);
381
382}
383
384function init_second_stage() {
385
fe2f1970
AD
386 setCookie("ttrss_vf_actfeed", "");
387
476cac42 388 updateFeedList(false, false);
13ad9102 389 document.onkeydown = hotkey_handler;
70830c87
AD
390
391 var content = document.getElementById("content");
ac43eba1 392
ac43eba1
AD
393 if (getCookie("ttrss_vf_vmode")) {
394 var viewbox = document.getElementById("viewbox");
395 viewbox.value = getCookie("ttrss_vf_vmode");
396 }
47179952 397
a8d28f48
AD
398 if (getCookie("ttrss_vf_limit")) {
399 var limitbox = document.getElementById("limitbox");
400 limitbox.value = getCookie("ttrss_vf_limit");
401 }
86741347
AD
402
403// if (getCookie("ttrss_vf_actfeed")) {
404// viewfeed(getCookie("ttrss_vf_actfeed"), 0, '');
405// }
406
13bb6bbe 407// setTimeout("timeout()", 2*1000);
295f9b42
AD
408// scheduleFeedUpdate(true);
409
2f587484
AD
410 var splash = document.getElementById("splash");
411
412 if (splash) {
413 splash.style.display = "none";
414 }
295f9b42 415
1cd17194 416}
ac43eba1 417
e2f8f7b4 418function quickMenuGo() {
e2f8f7b4 419
cbe45fa8
AD
420 var chooser = document.getElementById("quickMenuChooser");
421 var opid = chooser[chooser.selectedIndex].id;
e2f8f7b4 422
cbe45fa8 423 if (opid == "qmcPrefs") {
e2f8f7b4
AD
424 gotoPreferences();
425 }
426
cbe45fa8 427 if (opid == "qmcAdvSearch") {
033e47e0
AD
428 displayDlg("search");
429 return;
430 }
431
cbe45fa8 432 if (opid == "qmcAddFeed") {
f84a97a3 433 displayDlg("quickAddFeed");
6de5d056
AD
434 return;
435 }
436
cbe45fa8 437 if (opid == "qmcRemoveFeed") {
6de5d056
AD
438 var actid = getActiveFeedId();
439
440 if (!actid) {
441 notify("Please select some feed first.");
442 return;
443 }
444
445 displayDlg("quickDelFeed", actid);
446 return;
e2f8f7b4 447 }
7a991cac 448
cbe45fa8 449 if (opid == "qmcUpdateFeeds") {
7a991cac
AD
450 scheduleFeedUpdate(true);
451 return;
452 }
453
cbe45fa8 454 if (opid == "qmcCatchupAll") {
7a991cac
AD
455 catchupAllFeeds();
456 return;
457 }
458
cbe45fa8 459 if (opid == "qmcShowOnlyUnread") {
7a991cac
AD
460 toggleDispRead();
461 return;
462 }
463
e2f8f7b4
AD
464}
465
466function qafAdd() {
ac43eba1 467
e2f8f7b4
AD
468 if (!xmlhttp_ready(xmlhttp)) {
469 printLockingError();
470 return
471 }
472
473 var link = document.getElementById("qafInput");
474
475 if (link.value.length == 0) {
476 notify("Missing feed URL.");
477 } else {
478 notify("Adding feed...");
479
480 var feeds_doc = window.frames["feeds-frame"].document;
481
482 feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
483
484 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=add&link=" +
485 param_escape(link.value), true);
6de5d056 486 xmlhttp.onreadystatechange=dlg_frefresh_callback;
e2f8f7b4
AD
487 xmlhttp.send(null);
488
489 link.value = "";
490
491 }
f84a97a3
AD
492}
493
6de5d056 494function displayDlg(id, param) {
e2f8f7b4 495
40d601c5
AD
496 notify("");
497
f84a97a3 498 xmlhttp.open("GET", "backend.php?op=dlg&id=" +
6de5d056 499 param_escape(id) + "&param=" + param_escape(param), true);
f84a97a3
AD
500 xmlhttp.onreadystatechange=dialog_refresh_callback;
501 xmlhttp.send(null);
e2f8f7b4
AD
502
503}
f84a97a3
AD
504
505function closeDlg() {
506 var dlg = document.getElementById("userDlg");
507 dlg.style.display = "none";
508}
509
6de5d056
AD
510function qfdDelete(feed_id) {
511
512 notify("Removing feed...");
513
514 var feeds_doc = window.frames["feeds-frame"].document;
515 feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
516
517 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=remove&ids=" + feed_id);
518 xmlhttp.onreadystatechange=dlg_frefresh_callback;
519 xmlhttp.send(null);
6de5d056 520}
033e47e0 521
3745788e
AD
522
523function allFeedsMenuGo() {
524 var chooser = document.getElementById("allFeedsChooser");
525
526 var opname = chooser[chooser.selectedIndex].text;
527
528 if (opname == "Update") {
529 scheduleFeedUpdate(true);
530 return;
531 }
532
533 if (opname == "Mark as read") {
534 catchupAllFeeds();
535 return;
536 }
537
bdf7f1bc 538 if (opname == "Show only unread") {
3745788e
AD
539 toggleDispRead();
540 return;
541 }
542
543}
544
21703604
AD
545function updateFeedTitle(t) {
546 active_title_text = t;
547 updateTitle();
548}
549
3745788e
AD
550function toggleDispRead() {
551 var hide_read_feeds = (getCookie("ttrss_vf_hreadf") == 1);
552
553 hide_read_feeds = !hide_read_feeds;
554
555 var feeds_doc = window.frames["feeds-frame"].document;
556
557 hideOrShowFeeds(feeds_doc, hide_read_feeds);
558
559 if (hide_read_feeds) {
560 setCookie("ttrss_vf_hreadf", 1);
561 } else {
562 setCookie("ttrss_vf_hreadf", 0);
563 }
564
565}
295f9b42
AD
566
567