]> git.wh0rd.org - tt-rss.git/blob - viewfeed.js
allow connections to pgsql without password
[tt-rss.git] / viewfeed.js
1 var active_post_id = false;
2 var last_article_view = false;
3 var active_real_feed_id = false;
4
5 // FIXME: kludges, needs proper implementation
6 var _reload_feedlist_after_view = false;
7
8 var _cdm_wd_timeout = false;
9 var _cdm_wd_vishist = new Array();
10
11 var article_cache = new Array();
12
13 var vgroup_last_feed = false;
14 var post_under_pointer = false;
15
16 var last_requested_article = false;
17
18 function catchup_callback2(transport, callback) {
19 try {
20 debug("catchup_callback2 " + transport + ", " + callback);
21 notify("");
22 all_counters_callback2(transport);
23 if (callback) {
24 setTimeout(callback, 10);
25 }
26 } catch (e) {
27 exception_error("catchup_callback2", e, transport);
28 }
29 }
30
31 function clean_feed_selections() {
32 try {
33 var feeds = $("feedList").getElementsByTagName("LI");
34
35 for (var i = 0; i < feeds.length; i++) {
36 if (feeds[i].id && feeds[i].id.match("FEEDR-")) {
37 feeds[i].className = feeds[i].className.replace("Selected", "");
38 }
39 if (feeds[i].id && feeds[i].id.match("FCAT-")) {
40 feeds[i].className = feeds[i].className.replace("Selected", "");
41 }
42 }
43 } catch (e) {
44 exception_error("clean_feed_selections", e);
45 }
46 }
47
48 function headlines_callback2(transport, feed_cur_page) {
49 try {
50
51 if (!transport.responseText && db) {
52 offlineConfirmModeChange();
53 return;
54 }
55
56 loading_set_progress(100);
57
58 debug("headlines_callback2 [page=" + feed_cur_page + "]");
59
60 if (!transport_error_check(transport)) return;
61
62 clean_feed_selections();
63
64 var is_cat = false;
65 var feed_id = false;
66
67 if (transport.responseXML) {
68 var headlines = transport.responseXML.getElementsByTagName("headlines")[0];
69 if (headlines) {
70 is_cat = headlines.getAttribute("is_cat");
71 feed_id = headlines.getAttribute("id");
72 setActiveFeedId(feed_id, is_cat);
73 }
74 }
75
76 var ll = $('FLL-' + feed_id);
77
78 if (!is_cat) {
79 var feedr = $("FEEDR-" + feed_id);
80 if (feedr && !feedr.className.match("Selected")) {
81 feedr.className = feedr.className + "Selected";
82 }
83 if (feedr && ll) feedr.removeChild(ll);
84 } else {
85 var feedr = $("FCAT-" + feed_id);
86 if (feedr && !feedr.className.match("Selected")) {
87 feedr.className = feedr.className + "Selected";
88 }
89
90 var fcap = $("FCAP-" + feed_id);
91 if (fcap && ll) fcap.removeChild(ll);
92
93 }
94
95 var img = $('FIMG-' + feed_id);
96
97 if (img && !is_cat) {
98 img.src = img.alt;
99 }
100
101 var f = $("headlines-frame");
102 try {
103 if (feed_cur_page == 0) {
104 debug("resetting headlines scrollTop");
105 f.scrollTop = 0;
106 }
107 } catch (e) { };
108
109 if (transport.responseXML) {
110 var headlines = transport.responseXML.getElementsByTagName("headlines")[0];
111 var headlines_count_obj = transport.responseXML.getElementsByTagName("headlines-count")[0];
112 var headlines_unread_obj = transport.responseXML.getElementsByTagName("headlines-unread")[0];
113 var disable_cache_obj = transport.responseXML.getElementsByTagName("disable-cache")[0];
114
115 var vgroup_last_feed_obj = transport.responseXML.getElementsByTagName("vgroup-last-feed")[0];
116
117 var headlines_count = headlines_count_obj.getAttribute("value");
118 var headlines_unread = headlines_unread_obj.getAttribute("value");
119 var disable_cache = disable_cache_obj.getAttribute("value") != "0";
120
121 vgroup_last_feed = vgroup_last_feed_obj.getAttribute("value");
122
123 if (headlines_count == 0) {
124 _infscroll_disable = 1;
125 } else {
126 _infscroll_disable = 0;
127 }
128
129 var counters = transport.responseXML.getElementsByTagName("counters")[0];
130 var articles = transport.responseXML.getElementsByTagName("article");
131 var runtime_info = transport.responseXML.getElementsByTagName("runtime-info");
132
133 if (feed_cur_page == 0) {
134 if (headlines) {
135 f.innerHTML = headlines.firstChild.nodeValue;
136
137 var cache_prefix = "";
138
139 if (is_cat) {
140 cache_prefix = "C:";
141 } else {
142 cache_prefix = "F:";
143 }
144
145 cache_invalidate(cache_prefix + feed_id);
146
147 if (!disable_cache) {
148 cache_inject(cache_prefix + feed_id,
149 headlines.firstChild.nodeValue, headlines_unread);
150 }
151
152 } else {
153 debug("headlines_callback: returned no data");
154 f.innerHTML = "<div class='whiteBox'>" + __('Could not update headlines (missing XML data)') + "</div>";
155
156 }
157 } else {
158 if (headlines) {
159 if (headlines_count > 0) {
160 debug("adding some more headlines...");
161
162 var c = $("headlinesList");
163
164 if (!c) {
165 c = $("headlinesInnerContainer");
166 }
167
168 var ids = getSelectedArticleIds2();
169
170 c.innerHTML = c.innerHTML + headlines.firstChild.nodeValue;
171
172 debug("restore selected ids: " + ids);
173
174 for (var i = 0; i < ids.length; i++) {
175 markHeadline(ids[i]);
176 }
177
178 } else {
179 debug("no new headlines received");
180 }
181 } else {
182 debug("headlines_callback: returned no data");
183 notify_error("Error while trying to load more headlines");
184 }
185
186 }
187
188 if (articles) {
189 for (var i = 0; i < articles.length; i++) {
190 var a_id = articles[i].getAttribute("id");
191 debug("found id: " + a_id);
192 cache_inject(a_id, articles[i].firstChild.nodeValue);
193 }
194 } else {
195 debug("no cached articles received");
196 }
197
198 if (counters) {
199 debug("parsing piggybacked counters: " + counters);
200 parse_counters(counters, false);
201 } else {
202 debug("counters container not found in reply, requesting...");
203 request_counters();
204 }
205
206 if (runtime_info) {
207 debug("parsing runtime info: " + runtime_info[0]);
208 parse_runtime_info(runtime_info[0]);
209 } else {
210 debug("counters container not found in reply");
211 }
212
213 } else {
214 debug("headlines_callback: returned no XML object");
215 f.innerHTML = "<div class='whiteBox'>" + __('Could not update headlines (missing XML object)') + "</div>";
216 }
217
218 if (typeof correctPNG != 'undefined') {
219 correctPNG();
220 }
221
222 if (_cdm_wd_timeout) window.clearTimeout(_cdm_wd_timeout);
223
224 if (!$("headlinesList") &&
225 getActiveFeedId() != -3 &&
226 getInitParam("cdm_auto_catchup") == 1) {
227 debug("starting CDM watchdog");
228 _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 5000);
229 _cdm_wd_vishist = new Array();
230 } else {
231 debug("not in CDM mode or watchdog disabled");
232 }
233
234 _feed_cur_page = feed_cur_page;
235 _infscroll_request_sent = 0;
236
237 notify("");
238
239 remove_splash();
240
241 } catch (e) {
242 exception_error("headlines_callback2", e, transport);
243 }
244 }
245
246 function render_article(article) {
247 try {
248 var f = $("content-frame");
249 try {
250 f.scrollTop = 0;
251 } catch (e) { };
252
253 var fi = $("content-insert");
254
255 try {
256 fi.scrollTop = 0;
257 } catch (e) { };
258
259 fi.innerHTML = article;
260
261 // article.evalScripts();
262
263 } catch (e) {
264 exception_error("render_article", e);
265 }
266 }
267
268 function showArticleInHeadlines(id) {
269
270 try {
271
272 cleanSelected("headlinesList");
273
274 var crow = $("RROW-" + id);
275
276 if (!crow) return;
277
278 var article_is_unread = crow.className.match("Unread");
279
280 crow.className = crow.className.replace("Unread", "");
281
282 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
283
284 var upd_img_pic = $("FUPDPIC-" + id);
285
286 var cache_prefix = "";
287
288 if (activeFeedIsCat()) {
289 cache_prefix = "C:";
290 } else {
291 cache_prefix = "F:";
292 }
293
294 var view_mode = false;
295
296 try {
297 view_mode = document.forms['main_toolbar_form'].view_mode;
298 view_mode = view_mode[view_mode.selectedIndex].value;
299 } catch (e) {
300 //
301 }
302
303 if (upd_img_pic && (upd_img_pic.src.match("updated.png") ||
304 upd_img_pic.src.match("fresh_sign.png"))) {
305
306 upd_img_pic.src = "images/blank_icon.gif";
307
308 cache_invalidate(cache_prefix + getActiveFeedId());
309
310 cache_inject(cache_prefix + getActiveFeedId(),
311 $("headlines-frame").innerHTML,
312 get_feed_unread(getActiveFeedId()));
313
314 } else if (article_is_unread && view_mode == "all_articles") {
315
316 cache_invalidate(cache_prefix + getActiveFeedId());
317
318 cache_inject(cache_prefix + getActiveFeedId(),
319 $("headlines-frame").innerHTML,
320 get_feed_unread(getActiveFeedId())-1);
321
322 } else if (article_is_unread) {
323 cache_invalidate(cache_prefix + getActiveFeedId());
324 }
325
326 markHeadline(id);
327
328 } catch (e) {
329 exception_error("showArticleInHeadlines", e);
330 }
331 }
332
333 function article_callback2(transport, id) {
334 try {
335 debug("article_callback2 " + id);
336
337 if (!transport.responseText && db) {
338 offlineConfirmModeChange();
339 return;
340 }
341
342 if (transport.responseXML) {
343
344 if (!transport_error_check(transport)) return;
345
346 /* var ll = $('LL-' + id);
347 var content = $('HLC-' + id);
348
349 if (ll && content) content.removeChild(ll); */
350
351 var upic = $('FUPDPIC-' + id);
352
353 if (upic) {
354 upic.src = 'images/blank_icon.gif';
355 }
356
357 if (id != last_requested_article) {
358 debug("requested article id is out of sequence, aborting");
359 return;
360 }
361
362 active_post_id = id;
363
364 debug("looking for articles to cache...");
365
366 var articles = transport.responseXML.getElementsByTagName("article");
367
368 for (var i = 0; i < articles.length; i++) {
369 var a_id = articles[i].getAttribute("id");
370
371 debug("found id: " + a_id);
372
373 if (a_id == active_post_id) {
374 debug("active article, rendering...");
375 render_article(articles[i].firstChild.nodeValue);
376 }
377
378 cache_inject(a_id, articles[i].firstChild.nodeValue);
379 }
380
381
382 showArticleInHeadlines(id);
383
384 if (db) {
385 db.execute("UPDATE articles SET unread = 0 WHERE id = ?", [id]);
386 }
387
388 var reply = transport.responseXML.firstChild.firstChild;
389
390 } else {
391 debug("article_callback: returned no XML object");
392 //var f = $("content-frame");
393 //f.innerHTML = "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>";
394 }
395
396 var date = new Date();
397 last_article_view = date.getTime() / 1000;
398
399 if (typeof correctPNG != 'undefined') {
400 correctPNG();
401 }
402
403 if (_reload_feedlist_after_view) {
404 setTimeout('updateFeedList(false, false)', 50);
405 _reload_feedlist_after_view = false;
406 } else {
407 if (transport.responseXML) {
408 var counters = transport.responseXML.getElementsByTagName("counters")[0];
409
410 if (counters) {
411 debug("parsing piggybacked counters: " + counters);
412 parse_counters(counters, false);
413 } else {
414 debug("counters container not found in reply, requesting...");
415 request_counters();
416 }
417 }
418 }
419
420 notify("");
421 } catch (e) {
422 exception_error("article_callback2", e, transport);
423 }
424 }
425
426 function view(id) {
427 try {
428 debug("loading article: " + id);
429
430 if (offline_mode) return view_offline(id);
431
432 var cached_article = cache_find(id);
433
434 debug("cache check result: " + (cached_article != false));
435
436 enableHotkeys();
437 hideAuxDlg();
438
439 var query = "?op=view&id=" + param_escape(id);
440
441 var neighbor_ids = getRelativePostIds(active_post_id);
442
443 /* only request uncached articles */
444
445 var cids_to_request = Array();
446
447 for (var i = 0; i < neighbor_ids.length; i++) {
448 if (!cache_check(neighbor_ids[i])) {
449 cids_to_request.push(neighbor_ids[i]);
450 }
451 }
452
453 debug("additional ids: " + cids_to_request.toString());
454
455 /* additional info for piggyback counters */
456
457 if (tagsAreDisplayed()) {
458 query = query + "&omode=lt";
459 } else {
460 query = query + "&omode=flc";
461 }
462
463 query = query + "&cids=" + cids_to_request.toString();
464
465 var crow = $("RROW-" + id);
466 var article_is_unread = crow.className.match("Unread");
467
468 if (!async_counters_work) {
469 query = query + "&csync=true";
470 }
471
472 showArticleInHeadlines(id);
473
474 if (!cached_article) {
475
476 var upic = $('FUPDPIC-' + id);
477
478 if (upic) {
479 upic.src = getInitParam("sign_progress");
480 }
481
482 } else if (cached_article && article_is_unread) {
483
484 query = query + "&mode=prefetch";
485
486 render_article(cached_article);
487
488 } else if (cached_article) {
489
490 query = query + "&mode=prefetch_old";
491 render_article(cached_article);
492
493 }
494
495 cache_expire();
496
497 last_requested_article = id;
498
499 new Ajax.Request("backend.php", {
500 parameters: query,
501 onComplete: function(transport) {
502 article_callback2(transport, id);
503 } });
504
505 return false;
506
507 } catch (e) {
508 exception_error("view", e);
509 }
510 }
511
512 function tMark(id) {
513 return toggleMark(id);
514 }
515
516 function tPub(id) {
517 return togglePub(id);
518 }
519
520 function tMark_afh_off(effect) {
521 try {
522 var elem = effect.effects[0].element;
523
524 debug("tMark_afh_off : " + elem.id);
525
526 if (elem) {
527 elem.src = elem.src.replace("mark_set", "mark_unset");
528 elem.alt = __("Star article");
529 Element.show(elem);
530 }
531
532 } catch (e) {
533 exception_error("tMark_afh_off", e);
534 }
535 }
536
537 function tPub_afh_off(effect) {
538 try {
539 var elem = effect.effects[0].element;
540
541 debug("tPub_afh_off : " + elem.id);
542
543 if (elem) {
544 elem.src = elem.src.replace("pub_set", "pub_unset");
545 elem.alt = __("Publish article");
546 Element.show(elem);
547 }
548
549 } catch (e) {
550 exception_error("tPub_afh_off", e);
551 }
552 }
553
554 function toggleMark(id, client_only, no_effects) {
555
556 try {
557
558 var query = "?op=rpc&id=" + id + "&subop=mark";
559
560 query = query + "&afid=" + getActiveFeedId();
561
562 if (tagsAreDisplayed()) {
563 query = query + "&omode=tl";
564 } else {
565 query = query + "&omode=flc";
566 }
567
568 var mark_img = $("FMPIC-" + id);
569
570 if (!mark_img) return;
571
572 var vfeedu = $("FEEDU--1");
573 var crow = $("RROW-" + id);
574
575 if (mark_img.src.match("mark_unset")) {
576 mark_img.src = mark_img.src.replace("mark_unset", "mark_set");
577 mark_img.alt = __("Unstar article");
578 query = query + "&mark=1";
579
580 if (db) {
581 db.execute("UPDATE articles SET marked = 1 WHERE id = ?", [id]);
582 }
583
584 } else {
585 mark_img.alt = __("Please wait...");
586 query = query + "&mark=0";
587
588 if ($("headlinesList") && !no_effects) {
589 Effect.Puff(mark_img, {duration : 0.25, afterFinish: tMark_afh_off});
590 } else {
591 mark_img.src = mark_img.src.replace("mark_set", "mark_unset");
592 mark_img.alt = __("Star article");
593 }
594
595 if (db) {
596 db.execute("UPDATE articles SET marked = 0 WHERE id = ?", [id]);
597 }
598
599 }
600
601 if (!no_effects) update_local_feedlist_counters();
602
603 if (!client_only) {
604 debug(query);
605
606 new Ajax.Request("backend.php", {
607 parameters: query,
608 onComplete: function(transport) {
609 all_counters_callback2(transport);
610 } });
611
612 }
613
614 } catch (e) {
615 exception_error("toggleMark", e);
616 }
617 }
618
619 function togglePub(id, client_only, no_effects, note) {
620
621 try {
622
623 var query = "?op=rpc&id=" + id + "&subop=publ";
624
625 query = query + "&afid=" + getActiveFeedId();
626
627 if (note != undefined) {
628 query = query + "&note=" + param_escape(note);
629 } else {
630 query = query + "&note=undefined";
631 }
632
633 if (tagsAreDisplayed()) {
634 query = query + "&omode=tl";
635 } else {
636 query = query + "&omode=flc";
637 }
638
639 var mark_img = $("FPPIC-" + id);
640
641 if (!mark_img) return;
642
643 var vfeedu = $("FEEDU--2");
644 var crow = $("RROW-" + id);
645
646 if (mark_img.src.match("pub_unset") || note != undefined) {
647 mark_img.src = mark_img.src.replace("pub_unset", "pub_set");
648 mark_img.alt = __("Unpublish article");
649 query = query + "&pub=1";
650
651 } else {
652 mark_img.alt = __("Please wait...");
653 query = query + "&pub=0";
654
655 if ($("headlinesList") && !no_effects) {
656 Effect.Puff(mark_img, {duration : 0.25, afterFinish: tPub_afh_off});
657 } else {
658 mark_img.src = mark_img.src.replace("pub_set", "pub_unset");
659 mark_img.alt = __("Publish article");
660 }
661 }
662
663 if (!client_only) {
664 new Ajax.Request("backend.php", {
665 parameters: query,
666 onComplete: function(transport) {
667 all_counters_callback2(transport);
668
669 var note = transport.responseXML.getElementsByTagName("note")[0];
670
671 if (note) {
672 var note_id = note.getAttribute("id");
673 var note_size = note.getAttribute("size");
674 var note_content = note.firstChild.nodeValue;
675
676 var container = $('POSTNOTE-' + note_id);
677
678 cache_invalidate(note_id);
679
680 if (container) {
681 if (note_size == "0") {
682 Element.hide(container);
683 } else {
684 container.innerHTML = note_content;
685 Element.show(container);
686 }
687 }
688 }
689
690 } });
691 }
692
693 } catch (e) {
694 exception_error("togglePub", e);
695 }
696 }
697
698 function correctHeadlinesOffset(id) {
699
700 try {
701
702 var hlist = $("headlinesList");
703 var container = $("headlinesInnerContainer");
704 var row = $("RROW-" + id);
705
706 var viewport = container.offsetHeight;
707
708 var rel_offset_top = row.offsetTop - container.scrollTop;
709 var rel_offset_bottom = row.offsetTop + row.offsetHeight - container.scrollTop;
710
711 debug("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
712 debug("Vport: " + viewport);
713
714 if (rel_offset_top <= 0 || rel_offset_top > viewport) {
715 container.scrollTop = row.offsetTop;
716 } else if (rel_offset_bottom > viewport) {
717
718 /* doesn't properly work with Opera in some cases because
719 Opera fucks up element scrolling */
720
721 container.scrollTop = row.offsetTop + row.offsetHeight - viewport;
722 }
723
724 } catch (e) {
725 exception_error("correctHeadlinesOffset", e);
726 }
727
728 }
729
730 function moveToPost(mode) {
731
732 try {
733
734 var rows;
735
736 if (isCdmMode()) {
737 rows = cdmGetVisibleArticles();
738 } else {
739 rows = getVisibleHeadlineIds();
740 }
741
742 var prev_id = false;
743 var next_id = false;
744
745 if (!$('RROW-' + active_post_id)) {
746 active_post_id = false;
747 }
748
749 if (active_post_id == false) {
750 next_id = getFirstVisibleHeadlineId();
751 prev_id = getLastVisibleHeadlineId();
752 } else {
753 for (var i = 0; i < rows.length; i++) {
754 if (rows[i] == active_post_id) {
755 prev_id = rows[i-1];
756 next_id = rows[i+1];
757 }
758 }
759 }
760
761 if (mode == "next") {
762 if (next_id) {
763 if (isCdmMode()) {
764
765 if (!cdmArticleIsActuallyVisible(next_id)) {
766 cdmScrollToArticleId(next_id);
767 }
768 cdmSelectArticles("none");
769 toggleUnread(next_id, 0, true);
770 toggleSelected(next_id);
771
772 } else {
773 correctHeadlinesOffset(next_id);
774 view(next_id, getActiveFeedId());
775 }
776 }
777 }
778
779 if (mode == "prev") {
780 if (prev_id) {
781 if (isCdmMode()) {
782 cdmScrollToArticleId(prev_id);
783 cdmSelectArticles("none");
784 toggleUnread(prev_id, 0, true);
785 toggleSelected(prev_id);
786 } else {
787 correctHeadlinesOffset(prev_id);
788 view(prev_id, getActiveFeedId());
789 }
790 }
791 }
792
793 } catch (e) {
794 exception_error("moveToPost", e);
795 }
796 }
797
798 function toggleSelected(id) {
799 try {
800
801 var cb = $("RCHK-" + id);
802
803 var row = $("RROW-" + id);
804 if (row) {
805 var nc = row.className;
806
807 if (!nc.match("Selected")) {
808 nc = nc + "Selected";
809 if (cb) {
810 cb.checked = true;
811 }
812
813 // In CDM basically last selected article == active article
814 if (isCdmMode()) active_post_id = id;
815 } else {
816 nc = nc.replace("Selected", "");
817 if (cb) {
818 cb.checked = false;
819 }
820
821 }
822
823 row.className = nc;
824 }
825 } catch (e) {
826 exception_error("toggleSelected", e);
827 }
828 }
829
830 function toggleUnread_afh(effect) {
831 try {
832
833 var elem = effect.element;
834 elem.style.backgroundColor = "";
835
836 } catch (e) {
837 exception_error("toggleUnread_afh", e);
838 }
839 }
840
841 function toggleUnread(id, cmode, effect) {
842 try {
843
844 var row = $("RROW-" + id);
845 if (row) {
846 var nc = row.className;
847 var is_selected = row.className.match("Selected");
848 nc = nc.replace("Unread", "");
849 nc = nc.replace("Selected", "");
850
851 // since we are removing selection from the object, uncheck
852 // corresponding checkbox
853
854 var cb = $("RCHK-" + id);
855 if (cb) {
856 cb.checked = false;
857 }
858
859 // NOTE: I'm not sure that resetting selection here is a feature -fox
860
861 if (cmode == undefined || cmode == 2) {
862 if (row.className.match("Unread")) {
863 row.className = nc;
864
865 if (effect) {
866 new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5",
867 afterFinish: toggleUnread_afh,
868 queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } );
869 }
870
871 } else {
872 row.className = nc + "Unread";
873 }
874
875 if (db) {
876 db.execute("UPDATE articles SET unread = not unread "+
877 "WHERE id = ?", [id]);
878 }
879
880 } else if (cmode == 0) {
881 row.className = nc;
882
883 if (effect) {
884 new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5",
885 afterFinish: toggleUnread_afh,
886 queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } );
887 }
888
889 if (db) {
890 db.execute("UPDATE articles SET unread = 0 "+
891 "WHERE id = ?", [id]);
892 }
893
894 } else if (cmode == 1) {
895 row.className = nc + "Unread";
896
897 if (db) {
898 db.execute("UPDATE articles SET unread = 1 "+
899 "WHERE id = ?", [id]);
900 }
901
902 }
903
904 update_local_feedlist_counters();
905
906 // Disable unmarking as selected for the time being (16.05.08) -fox
907 if (is_selected) row.className = row.className + "Selected";
908
909 if (cmode == undefined) cmode = 2;
910
911 var query = "?op=rpc&subop=catchupSelected" +
912 "&cmode=" + param_escape(cmode) + "&ids=" + param_escape(id);
913
914 // notify_progress("Loading, please wait...");
915
916 new Ajax.Request("backend.php", {
917 parameters: query,
918 onComplete: function(transport) {
919 all_counters_callback2(transport);
920 } });
921
922 }
923
924 } catch (e) {
925 exception_error("toggleUnread", e);
926 }
927 }
928
929 function selectionRemoveLabel(id) {
930 try {
931
932 var ids = getSelectedArticleIds2();
933
934 if (ids.length == 0) {
935 alert(__("No articles are selected."));
936 return;
937 }
938
939 // var ok = confirm(__("Remove selected articles from label?"));
940
941 // if (ok) {
942
943 var query = "?op=rpc&subop=removeFromLabel&ids=" +
944 param_escape(ids.toString()) + "&lid=" + param_escape(id);
945
946 // notify_progress("Loading, please wait...");
947
948 cache_invalidate("F:" + (-11 - id));
949
950 new Ajax.Request("backend.php", {
951 parameters: query,
952 onComplete: function(transport) {
953 show_labels_in_headlines(transport);
954 all_counters_callback2(transport);
955 } });
956
957 // }
958
959 } catch (e) {
960 exception_error("selectionAssignLabel", e);
961
962 }
963 }
964
965 function selectionAssignLabel(id) {
966 try {
967
968 var ids = getSelectedArticleIds2();
969
970 if (ids.length == 0) {
971 alert(__("No articles are selected."));
972 return;
973 }
974
975 // var ok = confirm(__("Assign selected articles to label?"));
976
977 // if (ok) {
978
979 cache_invalidate("F:" + (-11 - id));
980
981 var query = "?op=rpc&subop=assignToLabel&ids=" +
982 param_escape(ids.toString()) + "&lid=" + param_escape(id);
983
984 // notify_progress("Loading, please wait...");
985
986 new Ajax.Request("backend.php", {
987 parameters: query,
988 onComplete: function(transport) {
989 show_labels_in_headlines(transport);
990 all_counters_callback2(transport);
991 } });
992
993 // }
994
995 } catch (e) {
996 exception_error("selectionAssignLabel", e);
997
998 }
999 }
1000
1001 function selectionToggleUnread(cdm_mode, set_state, callback_func, no_error) {
1002 try {
1003 var rows;
1004
1005 if (cdm_mode) {
1006 rows = cdmGetSelectedArticles();
1007 } else {
1008 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1009 }
1010
1011 if (rows.length == 0 && !no_error) {
1012 alert(__("No articles are selected."));
1013 return;
1014 }
1015
1016 for (i = 0; i < rows.length; i++) {
1017 var row = $("RROW-" + rows[i]);
1018 if (row) {
1019 var nc = row.className;
1020 nc = nc.replace("Unread", "");
1021 nc = nc.replace("Selected", "");
1022
1023 if (set_state == undefined) {
1024 if (row.className.match("Unread")) {
1025 row.className = nc + "Selected";
1026 } else {
1027 row.className = nc + "UnreadSelected";
1028 }
1029 if (db) {
1030 db.execute("UPDATE articles SET unread = NOT unread WHERE id = ?",
1031 [rows[i]]);
1032 }
1033 }
1034
1035 if (set_state == false) {
1036 row.className = nc + "Selected";
1037 if (db) {
1038 db.execute("UPDATE articles SET unread = 0 WHERE id = ?",
1039 [rows[i]]);
1040 }
1041 }
1042
1043 if (set_state == true) {
1044 row.className = nc + "UnreadSelected";
1045 if (db) {
1046 db.execute("UPDATE articles SET unread = 1 WHERE id = ?",
1047 [rows[i]]);
1048 }
1049 }
1050 }
1051 }
1052
1053 if (rows.length > 0) {
1054
1055 update_local_feedlist_counters();
1056
1057 var cmode = "";
1058
1059 if (set_state == undefined) {
1060 cmode = "2";
1061 } else if (set_state == true) {
1062 cmode = "1";
1063 } else if (set_state == false) {
1064 cmode = "0";
1065 }
1066
1067 var query = "?op=rpc&subop=catchupSelected" +
1068 "&cmode=" + cmode + "&ids=" + param_escape(rows.toString());
1069
1070 notify_progress("Loading, please wait...");
1071
1072 new Ajax.Request("backend.php", {
1073 parameters: query,
1074 onComplete: function(transport) {
1075 catchup_callback2(transport, callback_func);
1076 } });
1077
1078 }
1079
1080 } catch (e) {
1081 exception_error("selectionToggleUnread", e);
1082 }
1083 }
1084
1085 function selectionToggleMarked(cdm_mode) {
1086 try {
1087
1088 var rows;
1089
1090 if (cdm_mode) {
1091 rows = cdmGetSelectedArticles();
1092 } else {
1093 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1094 }
1095
1096 if (rows.length == 0) {
1097 alert(__("No articles are selected."));
1098 return;
1099 }
1100
1101 for (i = 0; i < rows.length; i++) {
1102 toggleMark(rows[i], true, true);
1103 }
1104
1105 update_local_feedlist_counters();
1106
1107 if (rows.length > 0) {
1108
1109 var query = "?op=rpc&subop=markSelected&ids=" +
1110 param_escape(rows.toString()) + "&cmode=2";
1111
1112 query = query + "&afid=" + getActiveFeedId();
1113
1114 query = query + "&omode=lc";
1115
1116 new Ajax.Request("backend.php", {
1117 parameters: query,
1118 onComplete: function(transport) {
1119 all_counters_callback2(transport);
1120 } });
1121
1122 }
1123
1124 } catch (e) {
1125 exception_error("selectionToggleMarked", e);
1126 }
1127 }
1128
1129 function selectionTogglePublished(cdm_mode) {
1130 try {
1131
1132 var rows;
1133
1134 if (cdm_mode) {
1135 rows = cdmGetSelectedArticles();
1136 } else {
1137 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1138 }
1139
1140 if (rows.length == 0) {
1141 alert(__("No articles are selected."));
1142 return;
1143 }
1144
1145 for (i = 0; i < rows.length; i++) {
1146 togglePub(rows[i], true, true);
1147 }
1148
1149 if (rows.length > 0) {
1150
1151 var query = "?op=rpc&subop=publishSelected&ids=" +
1152 param_escape(rows.toString()) + "&cmode=2";
1153
1154 query = query + "&afid=" + getActiveFeedId();
1155
1156 query = query + "&omode=lc";
1157
1158 new Ajax.Request("backend.php", {
1159 parameters: query,
1160 onComplete: function(transport) {
1161 all_counters_callback2(transport);
1162 } });
1163
1164 }
1165
1166 } catch (e) {
1167 exception_error("selectionToggleMarked", e);
1168 }
1169 }
1170
1171 function cdmGetSelectedArticles() {
1172 var sel_articles = new Array();
1173 var container = $("headlinesInnerContainer");
1174
1175 for (i = 0; i < container.childNodes.length; i++) {
1176 var child = container.childNodes[i];
1177
1178 if (child.id && child.id.match("RROW-") && child.className.match("Selected")) {
1179 var c_id = child.id.replace("RROW-", "");
1180 sel_articles.push(c_id);
1181 }
1182 }
1183
1184 return sel_articles;
1185 }
1186
1187 function cdmGetVisibleArticles() {
1188 var sel_articles = new Array();
1189 var container = $("headlinesInnerContainer");
1190
1191 if (!container) return sel_articles;
1192
1193 for (i = 0; i < container.childNodes.length; i++) {
1194 var child = container.childNodes[i];
1195
1196 if (child.id && child.id.match("RROW-")) {
1197 var c_id = child.id.replace("RROW-", "");
1198 sel_articles.push(c_id);
1199 }
1200 }
1201
1202 return sel_articles;
1203 }
1204
1205 function cdmGetUnreadArticles() {
1206 var sel_articles = new Array();
1207 var container = $("headlinesInnerContainer");
1208
1209 for (i = 0; i < container.childNodes.length; i++) {
1210 var child = container.childNodes[i];
1211
1212 if (child.id && child.id.match("RROW-") && child.className.match("Unread")) {
1213 var c_id = child.id.replace("RROW-", "");
1214 sel_articles.push(c_id);
1215 }
1216 }
1217
1218 return sel_articles;
1219 }
1220
1221
1222 // mode = all,none,unread
1223 function cdmSelectArticles(mode) {
1224 var container = $("headlinesInnerContainer");
1225
1226 for (i = 0; i < container.childNodes.length; i++) {
1227 var child = container.childNodes[i];
1228
1229 if (child.id && child.id.match("RROW-")) {
1230 var aid = child.id.replace("RROW-", "");
1231
1232 var cb = $("RCHK-" + aid);
1233
1234 if (mode == "all") {
1235 if (!child.className.match("Selected")) {
1236 child.className = child.className + "Selected";
1237 cb.checked = true;
1238 }
1239 } else if (mode == "unread") {
1240 if (child.className.match("Unread") && !child.className.match("Selected")) {
1241 child.className = child.className + "Selected";
1242 cb.checked = true;
1243 }
1244 } else {
1245 child.className = child.className.replace("Selected", "");
1246 cb.checked = false;
1247 }
1248 }
1249 }
1250 }
1251
1252 function catchupPage() {
1253
1254 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
1255
1256 var str = __("Mark all visible articles in %s as read?");
1257
1258 str = str.replace("%s", fn);
1259
1260 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1261 return;
1262 }
1263
1264 if ($("headlinesList")) {
1265 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
1266 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
1267 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1268 } else {
1269 cdmSelectArticles('all');
1270 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1271 cdmSelectArticles('none');
1272 }
1273 }
1274
1275 function deleteSelection() {
1276
1277 try {
1278
1279 var rows;
1280
1281 if ($("headlinesList")) {
1282 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1283 } else {
1284 rows = cdmGetSelectedArticles();
1285 }
1286
1287 if (rows.length == 0) {
1288 alert(__("No articles are selected."));
1289 return;
1290 }
1291
1292
1293 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
1294 var str;
1295 var op;
1296
1297 if (getActiveFeedId() != 0) {
1298 str = __("Delete %d selected articles in %s?");
1299 } else {
1300 str = __("Delete %d selected articles?");
1301 }
1302
1303 str = str.replace("%d", rows.length);
1304 str = str.replace("%s", fn);
1305
1306 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1307 return;
1308 }
1309
1310 query = "?op=rpc&subop=delete&ids=" + param_escape(rows);
1311
1312 debug(query);
1313
1314 new Ajax.Request("backend.php", {
1315 parameters: query,
1316 onComplete: function(transport) {
1317 viewCurrentFeed();
1318 } });
1319
1320 } catch (e) {
1321 exception_error("deleteSelection", e);
1322 }
1323 }
1324
1325 function archiveSelection() {
1326
1327 try {
1328
1329 var rows;
1330
1331 if ($("headlinesList")) {
1332 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1333 } else {
1334 rows = cdmGetSelectedArticles();
1335 }
1336
1337 if (rows.length == 0) {
1338 alert(__("No articles are selected."));
1339 return;
1340 }
1341
1342
1343 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
1344 var str;
1345 var op;
1346
1347 if (getActiveFeedId() != 0) {
1348 str = __("Archive %d selected articles in %s?");
1349 op = "archive";
1350 } else {
1351 str = __("Move %d archived articles back?");
1352 op = "unarchive";
1353 }
1354
1355 str = str.replace("%d", rows.length);
1356 str = str.replace("%s", fn);
1357
1358 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1359 return;
1360 }
1361
1362 query = "?op=rpc&subop="+op+"&ids=" + param_escape(rows);
1363
1364 debug(query);
1365
1366 for (var i = 0; i < rows.length; i++) {
1367 cache_invalidate(rows[i]);
1368 }
1369
1370 new Ajax.Request("backend.php", {
1371 parameters: query,
1372 onComplete: function(transport) {
1373 viewCurrentFeed();
1374 } });
1375
1376 } catch (e) {
1377 exception_error("archiveSelection", e);
1378 }
1379 }
1380
1381 function catchupSelection() {
1382
1383 try {
1384
1385 var rows;
1386
1387 if ($("headlinesList")) {
1388 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1389 } else {
1390 rows = cdmGetSelectedArticles();
1391 }
1392
1393 if (rows.length == 0) {
1394 alert(__("No articles are selected."));
1395 return;
1396 }
1397
1398
1399 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
1400
1401 var str = __("Mark %d selected articles in %s as read?");
1402
1403 str = str.replace("%d", rows.length);
1404 str = str.replace("%s", fn);
1405
1406 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1407 return;
1408 }
1409
1410 if ($("headlinesList")) {
1411 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
1412 } else {
1413 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1414 }
1415
1416 } catch (e) {
1417 exception_error("catchupSelection", e);
1418 }
1419 }
1420
1421 function editArticleTags(id, feed_id, cdm_enabled) {
1422 displayDlg('editArticleTags', id,
1423 function () {
1424 new Ajax.Autocompleter('tags_str', 'tags_choices',
1425 "backend.php?op=rpc&subop=completeTags",
1426 { tokens: ',', paramName: "search" });
1427 });
1428 }
1429
1430 function editTagsSave() {
1431
1432 notify_progress("Saving article tags...");
1433
1434 var form = document.forms["tag_edit_form"];
1435
1436 var query = Form.serialize("tag_edit_form");
1437
1438 query = "?op=rpc&subop=setArticleTags&" + query;
1439
1440 debug(query);
1441
1442 new Ajax.Request("backend.php", {
1443 parameters: query,
1444 onComplete: function(transport) {
1445 try {
1446 debug("tags saved...");
1447
1448 closeInfoBox();
1449 notify("");
1450
1451 if (tagsAreDisplayed()) {
1452 _reload_feedlist_after_view = true;
1453 }
1454
1455 if (transport.responseXML) {
1456 var tags_str = transport.responseXML.getElementsByTagName("tags-str")[0];
1457
1458 if (tags_str) {
1459 var id = tags_str.getAttribute("id");
1460
1461 if (id) {
1462 var tags = $("ATSTR-" + id);
1463 if (tags) {
1464 tags.innerHTML = tags_str.firstChild.nodeValue;
1465 }
1466
1467 cache_invalidate(id);
1468 }
1469 }
1470 }
1471
1472 } catch (e) {
1473 exception_error("editTagsSave", e);
1474 }
1475 } });
1476 }
1477
1478 function editTagsInsert() {
1479 try {
1480
1481 var form = document.forms["tag_edit_form"];
1482
1483 var found_tags = form.found_tags;
1484 var tags_str = form.tags_str;
1485
1486 var tag = found_tags[found_tags.selectedIndex].value;
1487
1488 if (tags_str.value.length > 0 &&
1489 tags_str.value.lastIndexOf(", ") != tags_str.value.length - 2) {
1490
1491 tags_str.value = tags_str.value + ", ";
1492 }
1493
1494 tags_str.value = tags_str.value + tag + ", ";
1495
1496 found_tags.selectedIndex = 0;
1497
1498 } catch (e) {
1499 exception_error("editTagsInsert", e);
1500 }
1501 }
1502
1503 function cdmScrollViewport(where) {
1504 debug("cdmScrollViewport: " + where);
1505
1506 var ctr = $("headlinesInnerContainer");
1507
1508 if (!ctr) return;
1509
1510 if (where == "bottom") {
1511 ctr.scrollTop = ctr.scrollHeight;
1512 } else {
1513 ctr.scrollTop = where;
1514 }
1515 }
1516
1517 function cdmArticleIsBelowViewport(id) {
1518 try {
1519 var ctr = $("headlinesInnerContainer");
1520 var e = $("RROW-" + id);
1521
1522 if (!e || !ctr) return;
1523
1524 // article starts below viewport
1525
1526 if (ctr.scrollTop < e.offsetTop) {
1527 return true;
1528 } else {
1529 return false;
1530 }
1531
1532 } catch (e) {
1533 exception_error("cdmArticleIsVisible", e);
1534 }
1535 }
1536
1537 function cdmArticleIsAboveViewport(id) {
1538 try {
1539 var ctr = $("headlinesInnerContainer");
1540 var e = $("RROW-" + id);
1541
1542 if (!e || !ctr) return;
1543
1544 // article starts above viewport
1545
1546 if (ctr.scrollTop > e.offsetTop + e.offsetHeight) {
1547 return true;
1548 } else {
1549 return false;
1550 }
1551
1552 } catch (e) {
1553 exception_error("cdmArticleIsVisible", e);
1554 }
1555 }
1556
1557 function cdmScrollToArticleId(id) {
1558 try {
1559 var ctr = $("headlinesInnerContainer");
1560 var e = $("RROW-" + id);
1561
1562 if (!e || !ctr) return;
1563
1564 ctr.scrollTop = e.offsetTop;
1565
1566 } catch (e) {
1567 exception_error("cdmScrollToArticleId", e);
1568 }
1569 }
1570
1571 function cdmArticleIsActuallyVisible(id) {
1572 try {
1573 var ctr = $("headlinesInnerContainer");
1574 var e = $("RROW-" + id);
1575
1576 if (!e || !ctr) return;
1577
1578 // article fits in viewport OR article is longer than viewport and
1579 // its bottom is visible
1580
1581 if (ctr.scrollTop <= e.offsetTop && e.offsetTop + e.offsetHeight <=
1582 ctr.scrollTop + ctr.offsetHeight) {
1583
1584 return true;
1585
1586 } else if (e.offsetHeight > ctr.offsetHeight &&
1587 e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1588 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight) {
1589
1590 return true;
1591
1592 }
1593
1594 return false;
1595
1596 } catch (e) {
1597 exception_error("cdmArticleIsVisible", e);
1598 }
1599 }
1600
1601 function cdmWatchdog() {
1602
1603 try {
1604
1605 var ctr = $("headlinesInnerContainer");
1606
1607 if (!ctr) return;
1608
1609 var ids = new Array();
1610
1611 var e = ctr.firstChild;
1612
1613 while (e) {
1614 if (e.className && e.className == "cdmArticleUnread" && e.id &&
1615 e.id.match("RROW-")) {
1616
1617 // article fits in viewport OR article is longer than viewport and
1618 // its bottom is visible
1619
1620 if (ctr.scrollTop <= e.offsetTop && e.offsetTop + e.offsetHeight <=
1621 ctr.scrollTop + ctr.offsetHeight) {
1622
1623 // debug(e.id + " is visible " + e.offsetTop + "." +
1624 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1625 // (ctr.scrollTop + ctr.offsetHeight));
1626
1627 ids.push(e.id.replace("RROW-", ""));
1628
1629 } else if (e.offsetHeight > ctr.offsetHeight &&
1630 e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1631 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight) {
1632
1633 ids.push(e.id.replace("RROW-", ""));
1634
1635 }
1636
1637 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1638
1639 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1640 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1641
1642 ids.push(e.id.replace("RROW-", ""));
1643
1644 } */
1645
1646 }
1647
1648 e = e.nextSibling;
1649 }
1650
1651 debug("cdmWatchdog, ids= " + ids.toString());
1652
1653 if (ids.length > 0) {
1654
1655 for (var i = 0; i < ids.length; i++) {
1656 var e = $("RROW-" + ids[i]);
1657 if (e) {
1658 e.className = e.className.replace("Unread", "");
1659 }
1660 }
1661
1662 var query = "?op=rpc&subop=catchupSelected" +
1663 "&cmode=0" + "&ids=" + param_escape(ids.toString());
1664
1665 new Ajax.Request("backend.php", {
1666 parameters: query,
1667 onComplete: function(transport) {
1668 all_counters_callback2(transport);
1669 } });
1670
1671 }
1672
1673 _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 4000);
1674
1675 } catch (e) {
1676 exception_error("cdmWatchdog", e);
1677 }
1678
1679 }
1680
1681
1682 function cache_inject(id, article, param) {
1683 try {
1684 if (!cache_check_param(id, param)) {
1685 debug("cache_article: miss: " + id + " [p=" + param + "]");
1686
1687 if (db) {
1688
1689 var date = new Date();
1690 var ts = Math.round(date.getTime() / 1000);
1691
1692 db.execute("INSERT INTO cache (id, article, param, added) VALUES (?, ?, ?, ?)",
1693 [id, article, param, ts]);
1694 } else {
1695
1696 var cache_obj = new Array();
1697
1698 cache_obj["id"] = id;
1699 cache_obj["data"] = article;
1700 cache_obj["param"] = param;
1701
1702 article_cache.push(cache_obj);
1703 }
1704
1705 } else {
1706 debug("cache_article: hit: " + id + " [p=" + param + "]");
1707 }
1708 } catch (e) {
1709 exception_error("cache_inject", e);
1710 }
1711 }
1712
1713 function cache_find(id) {
1714
1715 if (db) {
1716 var rs = db.execute("SELECT article FROM cache WHERE id = ?", [id]);
1717 var a = false;
1718
1719 if (rs.isValidRow()) {
1720 var a = rs.field(0);
1721 }
1722
1723 rs.close();
1724
1725 return a;
1726
1727 } else {
1728 for (var i = 0; i < article_cache.length; i++) {
1729 if (article_cache[i]["id"] == id) {
1730 return article_cache[i]["data"];
1731 }
1732 }
1733 }
1734 return false;
1735 }
1736
1737 function cache_find_param(id, param) {
1738
1739 if (db) {
1740 var rs = db.execute("SELECT article FROM cache WHERE id = ? AND param = ?",
1741 [id, param]);
1742 var a = false;
1743
1744 if (rs.isValidRow()) {
1745 a = rs.field(0);
1746 }
1747
1748 rs.close();
1749
1750 return a;
1751
1752 } else {
1753 for (var i = 0; i < article_cache.length; i++) {
1754 if (article_cache[i]["id"] == id && article_cache[i]["param"] == param) {
1755 return article_cache[i]["data"];
1756 }
1757 }
1758 }
1759 return false;
1760 }
1761
1762 function cache_check(id) {
1763
1764 if (db) {
1765 var rs = db.execute("SELECT COUNT(*) AS c FROM cache WHERE id = ?",
1766 [id]);
1767 var a = false;
1768
1769 if (rs.isValidRow()) {
1770 a = rs.field(0) != "0";
1771 }
1772
1773 rs.close();
1774
1775 return a;
1776
1777 } else {
1778 for (var i = 0; i < article_cache.length; i++) {
1779 if (article_cache[i]["id"] == id) {
1780 return true;
1781 }
1782 }
1783 }
1784 return false;
1785 }
1786
1787 function cache_check_param(id, param) {
1788
1789 if (db) {
1790 var rs = db.execute("SELECT COUNT(*) AS c FROM cache WHERE id = ? AND param = ?",
1791 [id, param]);
1792 var a = false;
1793
1794 if (rs.isValidRow()) {
1795 a = rs.field(0) != "0";
1796 }
1797
1798 rs.close();
1799
1800 return a;
1801
1802 } else {
1803 for (var i = 0; i < article_cache.length; i++) {
1804 if (article_cache[i]["id"] == id && article_cache[i]["param"] == param) {
1805 return true;
1806 }
1807 }
1808 }
1809 return false;
1810 }
1811
1812 function cache_expire() {
1813 if (db) {
1814 var date = new Date();
1815 var ts = Math.round(date.getTime() / 1000);
1816
1817 db.execute("DELETE FROM cache WHERE added < ? - 1800 AND id LIKE 'FEEDLIST'", [ts]);
1818 db.execute("DELETE FROM cache WHERE added < ? - 600 AND (id LIKE 'F:%' OR id LIKE 'C:%')", [ts]);
1819 db.execute("DELETE FROM cache WHERE added < ? - 86400", [ts]);
1820
1821
1822 } else {
1823 while (article_cache.length > 25) {
1824 article_cache.shift();
1825 }
1826 }
1827 }
1828
1829 function cache_flush() {
1830 article_cache = new Array();
1831 }
1832
1833 function cache_invalidate(id) {
1834 try {
1835
1836 if (db) {
1837 rs = db.execute("DELETE FROM cache WHERE id = ?", [id]);
1838 return rs.rowsAffected != 0;
1839 } else {
1840
1841 var i = 0
1842
1843 while (i < article_cache.length) {
1844 if (article_cache[i]["id"] == id) {
1845 debug("cache_invalidate: removed id " + id);
1846 article_cache.splice(i, 1);
1847 return true;
1848 }
1849 i++;
1850 }
1851 }
1852
1853 debug("cache_invalidate: id not found: " + id);
1854 return false;
1855 } catch (e) {
1856 exception_error("cache_invalidate", e);
1857 }
1858 }
1859
1860 function getActiveArticleId() {
1861 return active_post_id;
1862 }
1863
1864 function cdmClicked(id) {
1865 try {
1866 var elem = $("RROW-" + id);
1867
1868 if (elem) {
1869 var id = elem.id.replace("RROW-", "");
1870 active_post_id = id;
1871
1872 // cdmSelectArticles("none");
1873 toggleUnread(id, 0, true);
1874 // toggleSelected(id);
1875
1876 }
1877 } catch (e) {
1878 exception_error("cdmClicked", e);
1879 }
1880 }
1881
1882 function preloadArticleUnderPointer(id) {
1883 try {
1884 if (getInitParam("bw_limit") == "1") return;
1885
1886 if (post_under_pointer == id && !cache_check(id)) {
1887
1888 debug("trying to preload article " + id);
1889
1890 var neighbor_ids = getRelativePostIds(id, 1);
1891
1892 /* only request uncached articles */
1893
1894 var cids_to_request = Array();
1895
1896 for (var i = 0; i < neighbor_ids.length; i++) {
1897 if (!cache_check(neighbor_ids[i])) {
1898 cids_to_request.push(neighbor_ids[i]);
1899 }
1900 }
1901 debug("additional ids: " + cids_to_request.toString());
1902
1903 cids_to_request.push(id);
1904
1905 var query = "?op=rpc&subop=getArticles&ids=" +
1906 cids_to_request.toString();
1907
1908 new Ajax.Request("backend.php", {
1909 parameters: query,
1910 onComplete: function(transport) {
1911 var articles = transport.responseXML.getElementsByTagName("article");
1912
1913 for (var i = 0; i < articles.length; i++) {
1914 var id = articles[i].getAttribute("id");
1915 if (!cache_check(id)) {
1916 cache_inject(id, articles[i].firstChild.nodeValue);
1917 debug("preloaded article: " + id);
1918 }
1919 }
1920 } });
1921 }
1922 } catch (e) {
1923 exception_error("preloadArticleUnderPointer", e);
1924 }
1925 }
1926
1927 function postMouseIn(id) {
1928 try {
1929 if (post_under_pointer != id) {
1930 post_under_pointer = id;
1931 if (!isCdmMode()) {
1932 window.setTimeout("preloadArticleUnderPointer(" + id + ")", 250);
1933 }
1934 }
1935
1936 } catch (e) {
1937 exception_error("postMouseIn", e);
1938 }
1939 }
1940
1941 function postMouseOut(id) {
1942 try {
1943 post_under_pointer = false;
1944 } catch (e) {
1945 exception_error("postMouseOut", e);
1946 }
1947 }
1948
1949 function headlines_scroll_handler() {
1950 try {
1951
1952 var e = $("headlinesInnerContainer");
1953
1954 var toolbar_form = document.forms["main_toolbar_form"];
1955
1956 debug((e.scrollTop + e.offsetHeight) + " vs " + e.scrollHeight + " dis? " +
1957 _infscroll_disable);
1958
1959 if (e.scrollTop + e.offsetHeight > e.scrollHeight - 100) {
1960 if (!_infscroll_disable) {
1961 debug("more cowbell!");
1962 viewNextFeedPage();
1963 }
1964 }
1965
1966 } catch (e) {
1967 exception_error("headlines_scroll_handler", e);
1968 }
1969 }
1970
1971 function catchupRelativeToArticle(below) {
1972
1973 try {
1974
1975
1976 if (!getActiveArticleId()) {
1977 alert(__("No article is selected."));
1978 return;
1979 }
1980
1981 var visible_ids;
1982
1983 if ($("headlinesList")) {
1984 visible_ids = getVisibleHeadlineIds();
1985 } else {
1986 visible_ids = cdmGetVisibleArticles();
1987 }
1988
1989 var ids_to_mark = new Array();
1990
1991 if (!below) {
1992 for (var i = 0; i < visible_ids.length; i++) {
1993 if (visible_ids[i] != getActiveArticleId()) {
1994 var e = $("RROW-" + visible_ids[i]);
1995
1996 if (e && e.className.match("Unread")) {
1997 ids_to_mark.push(visible_ids[i]);
1998 }
1999 } else {
2000 break;
2001 }
2002 }
2003 } else {
2004 for (var i = visible_ids.length-1; i >= 0; i--) {
2005 if (visible_ids[i] != getActiveArticleId()) {
2006 var e = $("RROW-" + visible_ids[i]);
2007
2008 if (e && e.className.match("Unread")) {
2009 ids_to_mark.push(visible_ids[i]);
2010 }
2011 } else {
2012 break;
2013 }
2014 }
2015 }
2016
2017 if (ids_to_mark.length == 0) {
2018 alert(__("No articles found to mark"));
2019 } else {
2020 var msg = __("Mark %d article(s) as read?").replace("%d", ids_to_mark.length);
2021
2022 if (confirm(msg)) {
2023
2024 for (var i = 0; i < ids_to_mark.length; i++) {
2025 var e = $("RROW-" + ids_to_mark[i]);
2026 e.className = e.className.replace("Unread", "");
2027 }
2028
2029 var query = "?op=rpc&subop=catchupSelected" +
2030 "&cmode=0" + "&ids=" + param_escape(ids_to_mark.toString());
2031
2032 new Ajax.Request("backend.php", {
2033 parameters: query,
2034 onComplete: function(transport) {
2035 catchup_callback2(transport);
2036 } });
2037
2038 }
2039 }
2040
2041 } catch (e) {
2042 exception_error("catchupRelativeToArticle", e);
2043 }
2044 }
2045
2046 function cdmExpandArticle(a_id) {
2047 try {
2048 var id = 'CICD-' + a_id;
2049
2050 try {
2051 Element.hide("CEXC-" + a_id);
2052 } catch (e) { }
2053
2054 Effect.Appear(id, {duration : 0.5,
2055 beforeStart: function(effect) {
2056 var h_id = 'CICH-' + a_id;
2057 var h_elem = $(h_id);
2058 if (h_elem) { h_elem.style.display = "none"; }
2059
2060 toggleUnread(a_id, 0);
2061 }});
2062
2063
2064 } catch (e) {
2065 exception_error("appearBlockElementF", e);
2066 }
2067
2068 }
2069
2070 function fixHeadlinesOrder(ids) {
2071 try {
2072 for (var i = 0; i < ids.length; i++) {
2073 var e = $("RROW-" + ids[i]);
2074
2075 if (e) {
2076 if (i % 2 == 0) {
2077 e.className = e.className.replace("even", "odd");
2078 } else {
2079 e.className = e.className.replace("odd", "even");
2080 }
2081 }
2082 }
2083 } catch (e) {
2084 exception_error("fixHeadlinesOrder", e);
2085 }
2086 }
2087
2088 function hideReadHeadlines() {
2089 try {
2090
2091 var ids = false;
2092 var vis_ids = new Array();
2093
2094 if ($("headlinesList")) {
2095 ids = getVisibleHeadlineIds();
2096 } else {
2097 ids = cdmGetVisibleArticles();
2098 }
2099
2100 var read_headlines_visible = true;
2101
2102 for (var i = 0; i < ids.length; i++) {
2103 var row = $("RROW-" + ids[i]);
2104
2105 if (row && row.className) {
2106 if (read_headlines_visible) {
2107 if (row.className.match("Unread") || row.className.match("Selected")) {
2108 Element.show(row);
2109 vis_ids.push(ids[i]);
2110 } else {
2111 //Effect.Fade(row, {duration : 0.3});
2112 Element.hide(row);
2113 }
2114 } else {
2115 Element.show(row);
2116 vis_ids.push(ids[i]);
2117 }
2118 }
2119 }
2120
2121 fixHeadlinesOrder(vis_ids);
2122
2123 read_headlines_visible = !read_headlines_visible;
2124
2125 } catch (e) {
2126 exception_error("hideReadHeadlines", e);
2127 }
2128 }
2129
2130 function invertHeadlineSelection() {
2131 try {
2132 var rows = new Array();
2133 var r = false;
2134
2135 if (!isCdmMode()) {
2136 r = document.getElementsByTagName("TR");
2137 } else {
2138 r = document.getElementsByTagName("DIV");
2139 }
2140
2141 for (var i = 0; i < r.length; i++) {
2142 if (r[i].id && r[i].id.match("RROW-")) {
2143 rows.push(r[i]);
2144 }
2145 }
2146
2147 for (var i = 0; i < rows.length; i++) {
2148 var nc = rows[i].className;
2149 var id = rows[i].id.replace("RROW-", "");
2150 var cb = $("RCHK-" + id);
2151
2152 if (!rows[i].className.match("Selected")) {
2153 nc = nc + "Selected";
2154 cb.checked = true;
2155 } else {
2156 nc = nc.replace("Selected", "");
2157 cb.checked = false;
2158 }
2159
2160 rows[i].className = nc;
2161
2162 }
2163
2164 } catch (e) {
2165 exception_error("invertHeadlineSelection", e);
2166 }
2167 }
2168
2169 function getArticleUnderPointer() {
2170 return post_under_pointer;
2171 }
2172
2173 function zoomToArticle(id) {
2174 try {
2175 var w = window.open("backend.php?op=view&mode=zoom&id=" + param_escape(id),
2176 "ttrss_zoom_" + id,
2177 "status=0,toolbar=0,location=0,width=450,height=300,scrollbars=1,menubar=0");
2178
2179 } catch (e) {
2180 exception_error("zoomToArticle", e);
2181 }
2182 }
2183
2184 function scrollArticle(offset) {
2185 try {
2186 if (!isCdmMode()) {
2187 var ci = $("content-insert");
2188 if (ci) {
2189 ci.scrollTop += offset;
2190 }
2191 } else {
2192 var hi = $("headlinesInnerContainer");
2193 if (hi) {
2194 hi.scrollTop += offset;
2195 }
2196
2197 }
2198 } catch (e) {
2199 exception_error("scrollArticle", e);
2200 }
2201 }
2202
2203 function show_labels_in_headlines(transport) {
2204 try {
2205 if (transport.responseXML) {
2206 var info = transport.responseXML.getElementsByTagName("info-for-headlines")[0];
2207
2208 var elems = info.getElementsByTagName("entry");
2209
2210 for (var l = 0; l < elems.length; l++) {
2211 var e_id = elems[l].getAttribute("id");
2212
2213 if (e_id) {
2214
2215 var ctr = $("HLLCTR-" + e_id);
2216
2217 if (ctr) {
2218 ctr.innerHTML = elems[l].firstChild.nodeValue;
2219 }
2220 }
2221
2222 }
2223
2224 }
2225 } catch (e) {
2226 exception_error("show_labels_in_headlines", e);
2227
2228 }
2229 }
2230
2231 function toggleHeadlineActions() {
2232 try {
2233 var e = $("headlineActionsBody");
2234 var p = $("headlineActionsDrop");
2235
2236 if (!Element.visible(e)) {
2237 Element.show(e);
2238 } else {
2239 Element.hide(e);
2240 }
2241
2242 e.scrollTop = 0;
2243 e.style.left = (p.offsetLeft + 1) + "px";
2244 e.style.top = (p.offsetTop + p.offsetHeight + 2) + "px";
2245
2246 } catch (e) {
2247 exception_error("toggleHeadlineActions", e);
2248 }
2249 }
2250
2251 function publishWithNote(id, def_note) {
2252 try {
2253 if (!def_note) def_note = '';
2254
2255 var note = prompt(__("Please enter a note for this article:"), def_note);
2256
2257 if (note != undefined) {
2258 togglePub(id, false, false, note);
2259 }
2260
2261 } catch (e) {
2262 exception_error("publishWithNote", e);
2263 }
2264 }