]> git.wh0rd.org - tt-rss.git/blob - viewfeed.js
fix multiple TAG filters not being applied properly
[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 date = new Date();
442
443 var neighbor_ids = getRelativePostIds(active_post_id);
444
445 /* only request uncached articles */
446
447 var cids_to_request = Array();
448
449 for (var i = 0; i < neighbor_ids.length; i++) {
450 if (!cache_check(neighbor_ids[i])) {
451 cids_to_request.push(neighbor_ids[i]);
452 }
453 }
454
455 debug("additional ids: " + cids_to_request.toString());
456
457 /* additional info for piggyback counters */
458
459 if (tagsAreDisplayed()) {
460 query = query + "&omode=lt";
461 } else {
462 query = query + "&omode=flc";
463 }
464
465 var date = new Date();
466 var timestamp = Math.round(date.getTime() / 1000);
467 query = query + "&ts=" + timestamp;
468
469 query = query + "&cids=" + cids_to_request.toString();
470
471 var crow = $("RROW-" + id);
472 var article_is_unread = crow.className.match("Unread");
473
474 if (!async_counters_work) {
475 query = query + "&csync=true";
476 }
477
478 showArticleInHeadlines(id);
479
480 if (!cached_article) {
481
482 // notify_progress("Loading, please wait...", true);
483
484 /* var content = $('HLC-' + id);
485
486 if (content && !$('LL-' + id)) {
487 var ll = document.createElement('img');
488
489 ll.src = 'images/indicator_tiny.gif';
490 ll.className = 'hlLoading';
491 ll.id = 'LL-' + id;
492
493 content.appendChild(ll);
494
495 } */
496
497 var upic = $('FUPDPIC-' + id);
498
499 if (upic) {
500 upic.src = getInitParam("sign_progress");
501 }
502
503 } else if (cached_article && article_is_unread) {
504
505 query = query + "&mode=prefetch";
506
507 render_article(cached_article);
508
509 } else if (cached_article) {
510
511 query = query + "&mode=prefetch_old";
512 render_article(cached_article);
513
514 }
515
516 cache_expire();
517
518 last_requested_article = id;
519
520 new Ajax.Request("backend.php", {
521 parameters: query,
522 onComplete: function(transport) {
523 article_callback2(transport, id);
524 } });
525
526 return false;
527
528 } catch (e) {
529 exception_error("view", e);
530 }
531 }
532
533 function tMark(id) {
534 return toggleMark(id);
535 }
536
537 function tPub(id) {
538 return togglePub(id);
539 }
540
541 function tMark_afh_off(effect) {
542 try {
543 var elem = effect.effects[0].element;
544
545 debug("tMark_afh_off : " + elem.id);
546
547 if (elem) {
548 elem.src = elem.src.replace("mark_set", "mark_unset");
549 elem.alt = __("Star article");
550 Element.show(elem);
551 }
552
553 } catch (e) {
554 exception_error("tMark_afh_off", e);
555 }
556 }
557
558 function tPub_afh_off(effect) {
559 try {
560 var elem = effect.effects[0].element;
561
562 debug("tPub_afh_off : " + elem.id);
563
564 if (elem) {
565 elem.src = elem.src.replace("pub_set", "pub_unset");
566 elem.alt = __("Publish article");
567 Element.show(elem);
568 }
569
570 } catch (e) {
571 exception_error("tPub_afh_off", e);
572 }
573 }
574
575 function toggleMark(id, client_only, no_effects) {
576
577 try {
578
579 var query = "?op=rpc&id=" + id + "&subop=mark";
580
581 query = query + "&afid=" + getActiveFeedId();
582
583 if (tagsAreDisplayed()) {
584 query = query + "&omode=tl";
585 } else {
586 query = query + "&omode=flc";
587 }
588
589 var mark_img = $("FMPIC-" + id);
590
591 if (!mark_img) return;
592
593 var vfeedu = $("FEEDU--1");
594 var crow = $("RROW-" + id);
595
596 if (mark_img.src.match("mark_unset")) {
597 mark_img.src = mark_img.src.replace("mark_unset", "mark_set");
598 mark_img.alt = __("Unstar article");
599 query = query + "&mark=1";
600
601 if (db) {
602 db.execute("UPDATE articles SET marked = 1 WHERE id = ?", [id]);
603 }
604
605 } else {
606 //mark_img.src = "images/mark_unset.png";
607 mark_img.alt = __("Please wait...");
608 query = query + "&mark=0";
609
610 if ($("headlinesList") && !no_effects) {
611 Effect.Puff(mark_img, {duration : 0.25, afterFinish: tMark_afh_off});
612 } else {
613 mark_img.src = mark_img.src.replace("mark_set", "mark_unset");
614 mark_img.alt = __("Star article");
615 }
616
617 if (db) {
618 db.execute("UPDATE articles SET marked = 0 WHERE id = ?", [id]);
619 }
620
621 }
622
623 if (!no_effects) update_local_feedlist_counters();
624
625 if (!client_only) {
626 debug(query);
627
628 new Ajax.Request("backend.php", {
629 parameters: query,
630 onComplete: function(transport) {
631 all_counters_callback2(transport);
632 } });
633
634 }
635
636 } catch (e) {
637 exception_error("toggleMark", e);
638 }
639 }
640
641 function togglePub(id, client_only, no_effects, note) {
642
643 try {
644
645 var query = "?op=rpc&id=" + id + "&subop=publ";
646
647 query = query + "&afid=" + getActiveFeedId();
648
649 if (note != undefined) {
650 query = query + "&note=" + param_escape(note);
651 } else {
652 query = query + "&note=undefined";
653 }
654
655 if (tagsAreDisplayed()) {
656 query = query + "&omode=tl";
657 } else {
658 query = query + "&omode=flc";
659 }
660
661 var mark_img = $("FPPIC-" + id);
662
663 if (!mark_img) return;
664
665 var vfeedu = $("FEEDU--2");
666 var crow = $("RROW-" + id);
667
668 if (mark_img.src.match("pub_unset") || note != undefined) {
669 mark_img.src = mark_img.src.replace("pub_unset", "pub_set");
670 mark_img.alt = __("Unpublish article");
671 query = query + "&pub=1";
672
673 } else {
674 //mark_img.src = "images/pub_unset.png";
675 mark_img.alt = __("Please wait...");
676 query = query + "&pub=0";
677
678 if ($("headlinesList") && !no_effects) {
679 Effect.Puff(mark_img, {duration : 0.25, afterFinish: tPub_afh_off});
680 } else {
681 mark_img.src = mark_img.src.replace("pub_set", "pub_unset");
682 mark_img.alt = __("Publish article");
683 }
684 }
685
686 if (!client_only) {
687 new Ajax.Request("backend.php", {
688 parameters: query,
689 onComplete: function(transport) {
690 all_counters_callback2(transport);
691
692 var note = transport.responseXML.getElementsByTagName("note")[0];
693
694 if (note) {
695 var note_id = note.getAttribute("id");
696 var note_size = note.getAttribute("size");
697 var note_content = note.firstChild.nodeValue;
698
699 var container = $('POSTNOTE-' + note_id);
700
701 cache_invalidate(note_id);
702
703 if (container) {
704 if (note_size == "0") {
705 Element.hide(container);
706 } else {
707 container.innerHTML = note_content;
708 Element.show(container);
709 }
710 }
711 }
712
713 } });
714 }
715
716 } catch (e) {
717 exception_error("togglePub", e);
718 }
719 }
720
721 function correctHeadlinesOffset(id) {
722
723 try {
724
725 var hlist = $("headlinesList");
726 var container = $("headlinesInnerContainer");
727 var row = $("RROW-" + id);
728
729 var viewport = container.offsetHeight;
730
731 var rel_offset_top = row.offsetTop - container.scrollTop;
732 var rel_offset_bottom = row.offsetTop + row.offsetHeight - container.scrollTop;
733
734 debug("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
735 debug("Vport: " + viewport);
736
737 if (rel_offset_top <= 0 || rel_offset_top > viewport) {
738 container.scrollTop = row.offsetTop;
739 } else if (rel_offset_bottom > viewport) {
740
741 /* doesn't properly work with Opera in some cases because
742 Opera fucks up element scrolling */
743
744 container.scrollTop = row.offsetTop + row.offsetHeight - viewport;
745 }
746
747 } catch (e) {
748 exception_error("correctHeadlinesOffset", e);
749 }
750
751 }
752
753 function moveToPost(mode) {
754
755 try {
756
757 var rows;
758
759 if (isCdmMode()) {
760 rows = cdmGetVisibleArticles();
761 } else {
762 rows = getVisibleHeadlineIds();
763 }
764
765 var prev_id = false;
766 var next_id = false;
767
768 if (!$('RROW-' + active_post_id)) {
769 active_post_id = false;
770 }
771
772 if (active_post_id == false) {
773 next_id = getFirstVisibleHeadlineId();
774 prev_id = getLastVisibleHeadlineId();
775 } else {
776 for (var i = 0; i < rows.length; i++) {
777 if (rows[i] == active_post_id) {
778 prev_id = rows[i-1];
779 next_id = rows[i+1];
780 }
781 }
782 }
783
784 if (mode == "next") {
785 if (next_id) {
786 if (isCdmMode()) {
787
788 if (!cdmArticleIsActuallyVisible(next_id)) {
789 cdmScrollToArticleId(next_id);
790 }
791 cdmSelectArticles("none");
792 toggleUnread(next_id, 0, true);
793 toggleSelected(next_id);
794
795 } else {
796 correctHeadlinesOffset(next_id);
797 view(next_id, getActiveFeedId());
798 }
799 }
800 }
801
802 if (mode == "prev") {
803 if (prev_id) {
804 if (isCdmMode()) {
805 cdmScrollToArticleId(prev_id);
806 cdmSelectArticles("none");
807 toggleUnread(prev_id, 0, true);
808 toggleSelected(prev_id);
809 } else {
810 correctHeadlinesOffset(prev_id);
811 view(prev_id, getActiveFeedId());
812 }
813 }
814 }
815
816 } catch (e) {
817 exception_error("moveToPost", e);
818 }
819 }
820
821 function toggleSelected(id) {
822 try {
823
824 var cb = $("RCHK-" + id);
825
826 var row = $("RROW-" + id);
827 if (row) {
828 var nc = row.className;
829
830 if (!nc.match("Selected")) {
831 nc = nc + "Selected";
832 if (cb) {
833 cb.checked = true;
834 }
835
836 // In CDM basically last selected article == active article
837 if (isCdmMode()) active_post_id = id;
838 } else {
839 nc = nc.replace("Selected", "");
840 if (cb) {
841 cb.checked = false;
842 }
843
844 }
845
846 row.className = nc;
847 }
848 } catch (e) {
849 exception_error("toggleSelected", e);
850 }
851 }
852
853 function toggleUnread_afh(effect) {
854 try {
855
856 var elem = effect.element;
857 elem.style.backgroundColor = "";
858
859 } catch (e) {
860 exception_error("toggleUnread_afh", e);
861 }
862 }
863
864 function toggleUnread(id, cmode, effect) {
865 try {
866
867 var row = $("RROW-" + id);
868 if (row) {
869 var nc = row.className;
870 var is_selected = row.className.match("Selected");
871 nc = nc.replace("Unread", "");
872 nc = nc.replace("Selected", "");
873
874 // since we are removing selection from the object, uncheck
875 // corresponding checkbox
876
877 var cb = $("RCHK-" + id);
878 if (cb) {
879 cb.checked = false;
880 }
881
882 // NOTE: I'm not sure that resetting selection here is a feature -fox
883
884 if (cmode == undefined || cmode == 2) {
885 if (row.className.match("Unread")) {
886 row.className = nc;
887
888 if (effect) {
889 new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5",
890 afterFinish: toggleUnread_afh,
891 queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } );
892 }
893
894 } else {
895 row.className = nc + "Unread";
896 }
897
898 if (db) {
899 db.execute("UPDATE articles SET unread = not unread "+
900 "WHERE id = ?", [id]);
901 }
902
903 } else if (cmode == 0) {
904 row.className = nc;
905
906 if (effect) {
907 new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5",
908 afterFinish: toggleUnread_afh,
909 queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } );
910 }
911
912 if (db) {
913 db.execute("UPDATE articles SET unread = 0 "+
914 "WHERE id = ?", [id]);
915 }
916
917 } else if (cmode == 1) {
918 row.className = nc + "Unread";
919
920 if (db) {
921 db.execute("UPDATE articles SET unread = 1 "+
922 "WHERE id = ?", [id]);
923 }
924
925 }
926
927 update_local_feedlist_counters();
928
929 // Disable unmarking as selected for the time being (16.05.08) -fox
930 if (is_selected) row.className = row.className + "Selected";
931
932 if (cmode == undefined) cmode = 2;
933
934 var query = "?op=rpc&subop=catchupSelected" +
935 "&cmode=" + param_escape(cmode) + "&ids=" + param_escape(id);
936
937 // notify_progress("Loading, please wait...");
938
939 new Ajax.Request("backend.php", {
940 parameters: query,
941 onComplete: function(transport) {
942 all_counters_callback2(transport);
943 } });
944
945 }
946
947 } catch (e) {
948 exception_error("toggleUnread", e);
949 }
950 }
951
952 function selectionRemoveLabel(id) {
953 try {
954
955 var ids = getSelectedArticleIds2();
956
957 if (ids.length == 0) {
958 alert(__("No articles are selected."));
959 return;
960 }
961
962 // var ok = confirm(__("Remove selected articles from label?"));
963
964 // if (ok) {
965
966 var query = "?op=rpc&subop=removeFromLabel&ids=" +
967 param_escape(ids.toString()) + "&lid=" + param_escape(id);
968
969 // notify_progress("Loading, please wait...");
970
971 cache_invalidate("F:" + (-11 - id));
972
973 new Ajax.Request("backend.php", {
974 parameters: query,
975 onComplete: function(transport) {
976 show_labels_in_headlines(transport);
977 all_counters_callback2(transport);
978 } });
979
980 // }
981
982 } catch (e) {
983 exception_error("selectionAssignLabel", e);
984
985 }
986 }
987
988 function selectionAssignLabel(id) {
989 try {
990
991 var ids = getSelectedArticleIds2();
992
993 if (ids.length == 0) {
994 alert(__("No articles are selected."));
995 return;
996 }
997
998 // var ok = confirm(__("Assign selected articles to label?"));
999
1000 // if (ok) {
1001
1002 cache_invalidate("F:" + (-11 - id));
1003
1004 var query = "?op=rpc&subop=assignToLabel&ids=" +
1005 param_escape(ids.toString()) + "&lid=" + param_escape(id);
1006
1007 // notify_progress("Loading, please wait...");
1008
1009 new Ajax.Request("backend.php", {
1010 parameters: query,
1011 onComplete: function(transport) {
1012 show_labels_in_headlines(transport);
1013 all_counters_callback2(transport);
1014 } });
1015
1016 // }
1017
1018 } catch (e) {
1019 exception_error("selectionAssignLabel", e);
1020
1021 }
1022 }
1023
1024 function selectionToggleUnread(cdm_mode, set_state, callback_func, no_error) {
1025 try {
1026 var rows;
1027
1028 if (cdm_mode) {
1029 rows = cdmGetSelectedArticles();
1030 } else {
1031 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1032 }
1033
1034 if (rows.length == 0 && !no_error) {
1035 alert(__("No articles are selected."));
1036 return;
1037 }
1038
1039 for (i = 0; i < rows.length; i++) {
1040 var row = $("RROW-" + rows[i]);
1041 if (row) {
1042 var nc = row.className;
1043 nc = nc.replace("Unread", "");
1044 nc = nc.replace("Selected", "");
1045
1046 if (set_state == undefined) {
1047 if (row.className.match("Unread")) {
1048 row.className = nc + "Selected";
1049 } else {
1050 row.className = nc + "UnreadSelected";
1051 }
1052 if (db) {
1053 db.execute("UPDATE articles SET unread = NOT unread WHERE id = ?",
1054 [rows[i]]);
1055 }
1056 }
1057
1058 if (set_state == false) {
1059 row.className = nc + "Selected";
1060 if (db) {
1061 db.execute("UPDATE articles SET unread = 0 WHERE id = ?",
1062 [rows[i]]);
1063 }
1064 }
1065
1066 if (set_state == true) {
1067 row.className = nc + "UnreadSelected";
1068 if (db) {
1069 db.execute("UPDATE articles SET unread = 1 WHERE id = ?",
1070 [rows[i]]);
1071 }
1072 }
1073 }
1074 }
1075
1076 if (rows.length > 0) {
1077
1078 update_local_feedlist_counters();
1079
1080 var cmode = "";
1081
1082 if (set_state == undefined) {
1083 cmode = "2";
1084 } else if (set_state == true) {
1085 cmode = "1";
1086 } else if (set_state == false) {
1087 cmode = "0";
1088 }
1089
1090 var query = "?op=rpc&subop=catchupSelected" +
1091 "&cmode=" + cmode + "&ids=" + param_escape(rows.toString());
1092
1093 notify_progress("Loading, please wait...");
1094
1095 new Ajax.Request("backend.php", {
1096 parameters: query,
1097 onComplete: function(transport) {
1098 catchup_callback2(transport, callback_func);
1099 } });
1100
1101 }
1102
1103 } catch (e) {
1104 exception_error("selectionToggleUnread", e);
1105 }
1106 }
1107
1108 function selectionToggleMarked(cdm_mode) {
1109 try {
1110
1111 var rows;
1112
1113 if (cdm_mode) {
1114 rows = cdmGetSelectedArticles();
1115 } else {
1116 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1117 }
1118
1119 if (rows.length == 0) {
1120 alert(__("No articles are selected."));
1121 return;
1122 }
1123
1124 for (i = 0; i < rows.length; i++) {
1125 toggleMark(rows[i], true, true);
1126 }
1127
1128 update_local_feedlist_counters();
1129
1130 if (rows.length > 0) {
1131
1132 var query = "?op=rpc&subop=markSelected&ids=" +
1133 param_escape(rows.toString()) + "&cmode=2";
1134
1135 query = query + "&afid=" + getActiveFeedId();
1136
1137 /* if (tagsAreDisplayed()) {
1138 query = query + "&omode=tl";
1139 } else {
1140 query = query + "&omode=flc";
1141 } */
1142
1143 query = query + "&omode=lc";
1144
1145 new Ajax.Request("backend.php", {
1146 parameters: query,
1147 onComplete: function(transport) {
1148 all_counters_callback2(transport);
1149 } });
1150
1151 }
1152
1153 } catch (e) {
1154 exception_error("selectionToggleMarked", e);
1155 }
1156 }
1157
1158 function selectionTogglePublished(cdm_mode) {
1159 try {
1160
1161 var rows;
1162
1163 if (cdm_mode) {
1164 rows = cdmGetSelectedArticles();
1165 } else {
1166 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1167 }
1168
1169 if (rows.length == 0) {
1170 alert(__("No articles are selected."));
1171 return;
1172 }
1173
1174 for (i = 0; i < rows.length; i++) {
1175 togglePub(rows[i], true, true);
1176 }
1177
1178 if (rows.length > 0) {
1179
1180 var query = "?op=rpc&subop=publishSelected&ids=" +
1181 param_escape(rows.toString()) + "&cmode=2";
1182
1183 query = query + "&afid=" + getActiveFeedId();
1184
1185 /* if (tagsAreDisplayed()) {
1186 query = query + "&omode=tl";
1187 } else {
1188 query = query + "&omode=flc";
1189 } */
1190
1191 query = query + "&omode=lc";
1192
1193 new Ajax.Request("backend.php", {
1194 parameters: query,
1195 onComplete: function(transport) {
1196 all_counters_callback2(transport);
1197 } });
1198
1199 }
1200
1201 } catch (e) {
1202 exception_error("selectionToggleMarked", e);
1203 }
1204 }
1205
1206 function cdmGetSelectedArticles() {
1207 var sel_articles = new Array();
1208 var container = $("headlinesInnerContainer");
1209
1210 for (i = 0; i < container.childNodes.length; i++) {
1211 var child = container.childNodes[i];
1212
1213 if (child.id && child.id.match("RROW-") && child.className.match("Selected")) {
1214 var c_id = child.id.replace("RROW-", "");
1215 sel_articles.push(c_id);
1216 }
1217 }
1218
1219 return sel_articles;
1220 }
1221
1222 function cdmGetVisibleArticles() {
1223 var sel_articles = new Array();
1224 var container = $("headlinesInnerContainer");
1225
1226 if (!container) return sel_articles;
1227
1228 for (i = 0; i < container.childNodes.length; i++) {
1229 var child = container.childNodes[i];
1230
1231 if (child.id && child.id.match("RROW-")) {
1232 var c_id = child.id.replace("RROW-", "");
1233 sel_articles.push(c_id);
1234 }
1235 }
1236
1237 return sel_articles;
1238 }
1239
1240 function cdmGetUnreadArticles() {
1241 var sel_articles = new Array();
1242 var container = $("headlinesInnerContainer");
1243
1244 for (i = 0; i < container.childNodes.length; i++) {
1245 var child = container.childNodes[i];
1246
1247 if (child.id && child.id.match("RROW-") && child.className.match("Unread")) {
1248 var c_id = child.id.replace("RROW-", "");
1249 sel_articles.push(c_id);
1250 }
1251 }
1252
1253 return sel_articles;
1254 }
1255
1256
1257 // mode = all,none,unread
1258 function cdmSelectArticles(mode) {
1259 var container = $("headlinesInnerContainer");
1260
1261 for (i = 0; i < container.childNodes.length; i++) {
1262 var child = container.childNodes[i];
1263
1264 if (child.id && child.id.match("RROW-")) {
1265 var aid = child.id.replace("RROW-", "");
1266
1267 var cb = $("RCHK-" + aid);
1268
1269 if (mode == "all") {
1270 if (!child.className.match("Selected")) {
1271 child.className = child.className + "Selected";
1272 cb.checked = true;
1273 }
1274 } else if (mode == "unread") {
1275 if (child.className.match("Unread") && !child.className.match("Selected")) {
1276 child.className = child.className + "Selected";
1277 cb.checked = true;
1278 }
1279 } else {
1280 child.className = child.className.replace("Selected", "");
1281 cb.checked = false;
1282 }
1283 }
1284 }
1285 }
1286
1287 function catchupPage() {
1288
1289 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
1290
1291 var str = __("Mark all visible articles in %s as read?");
1292
1293 str = str.replace("%s", fn);
1294
1295 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1296 return;
1297 }
1298
1299 if ($("headlinesList")) {
1300 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
1301 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
1302 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1303 } else {
1304 cdmSelectArticles('all');
1305 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1306 cdmSelectArticles('none');
1307 }
1308 }
1309
1310 function deleteSelection() {
1311
1312 try {
1313
1314 var rows;
1315
1316 if ($("headlinesList")) {
1317 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1318 } else {
1319 rows = cdmGetSelectedArticles();
1320 }
1321
1322 if (rows.length == 0) {
1323 alert(__("No articles are selected."));
1324 return;
1325 }
1326
1327
1328 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
1329 var str;
1330 var op;
1331
1332 if (getActiveFeedId() != 0) {
1333 str = __("Delete %d selected articles in %s?");
1334 } else {
1335 str = __("Delete %d selected articles?");
1336 }
1337
1338 str = str.replace("%d", rows.length);
1339 str = str.replace("%s", fn);
1340
1341 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1342 return;
1343 }
1344
1345 query = "?op=rpc&subop=delete&ids=" + param_escape(rows);
1346
1347 debug(query);
1348
1349 new Ajax.Request("backend.php", {
1350 parameters: query,
1351 onComplete: function(transport) {
1352 viewCurrentFeed();
1353 } });
1354
1355 } catch (e) {
1356 exception_error("deleteSelection", e);
1357 }
1358 }
1359
1360 function archiveSelection() {
1361
1362 try {
1363
1364 var rows;
1365
1366 if ($("headlinesList")) {
1367 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1368 } else {
1369 rows = cdmGetSelectedArticles();
1370 }
1371
1372 if (rows.length == 0) {
1373 alert(__("No articles are selected."));
1374 return;
1375 }
1376
1377
1378 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
1379 var str;
1380 var op;
1381
1382 if (getActiveFeedId() != 0) {
1383 str = __("Archive %d selected articles in %s?");
1384 op = "archive";
1385 } else {
1386 str = __("Move %d archived articles back?");
1387 op = "unarchive";
1388 }
1389
1390 str = str.replace("%d", rows.length);
1391 str = str.replace("%s", fn);
1392
1393 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1394 return;
1395 }
1396
1397 query = "?op=rpc&subop="+op+"&ids=" + param_escape(rows);
1398
1399 debug(query);
1400
1401 for (var i = 0; i < rows.length; i++) {
1402 cache_invalidate(rows[i]);
1403 }
1404
1405 new Ajax.Request("backend.php", {
1406 parameters: query,
1407 onComplete: function(transport) {
1408 viewCurrentFeed();
1409 } });
1410
1411 } catch (e) {
1412 exception_error("archiveSelection", e);
1413 }
1414 }
1415
1416 function catchupSelection() {
1417
1418 try {
1419
1420 var rows;
1421
1422 if ($("headlinesList")) {
1423 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1424 } else {
1425 rows = cdmGetSelectedArticles();
1426 }
1427
1428 if (rows.length == 0) {
1429 alert(__("No articles are selected."));
1430 return;
1431 }
1432
1433
1434 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
1435
1436 var str = __("Mark %d selected articles in %s as read?");
1437
1438 str = str.replace("%d", rows.length);
1439 str = str.replace("%s", fn);
1440
1441 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1442 return;
1443 }
1444
1445 if ($("headlinesList")) {
1446 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
1447 // selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1448 } else {
1449 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1450 // cdmSelectArticles('none');
1451 }
1452
1453 } catch (e) {
1454 exception_error("catchupSelection", e);
1455 }
1456 }
1457
1458 function editArticleTags(id, feed_id, cdm_enabled) {
1459 displayDlg('editArticleTags', id,
1460 function () {
1461 new Ajax.Autocompleter('tags_str', 'tags_choices',
1462 "backend.php?op=rpc&subop=completeTags",
1463 { tokens: ',', paramName: "search" });
1464 });
1465 }
1466
1467 function editTagsSave() {
1468
1469 notify_progress("Saving article tags...");
1470
1471 var form = document.forms["tag_edit_form"];
1472
1473 var query = Form.serialize("tag_edit_form");
1474
1475 query = "?op=rpc&subop=setArticleTags&" + query;
1476
1477 debug(query);
1478
1479 new Ajax.Request("backend.php", {
1480 parameters: query,
1481 onComplete: function(transport) {
1482 try {
1483 debug("tags saved...");
1484
1485 closeInfoBox();
1486 notify("");
1487
1488 if (tagsAreDisplayed()) {
1489 _reload_feedlist_after_view = true;
1490 }
1491
1492 if (transport.responseXML) {
1493 var tags_str = transport.responseXML.getElementsByTagName("tags-str")[0];
1494
1495 if (tags_str) {
1496 var id = tags_str.getAttribute("id");
1497
1498 if (id) {
1499 var tags = $("ATSTR-" + id);
1500 if (tags) {
1501 tags.innerHTML = tags_str.firstChild.nodeValue;
1502 }
1503
1504 cache_invalidate(id);
1505 }
1506 }
1507 }
1508
1509 } catch (e) {
1510 exception_error("editTagsSave", e);
1511 }
1512 } });
1513 }
1514
1515 function editTagsInsert() {
1516 try {
1517
1518 var form = document.forms["tag_edit_form"];
1519
1520 var found_tags = form.found_tags;
1521 var tags_str = form.tags_str;
1522
1523 var tag = found_tags[found_tags.selectedIndex].value;
1524
1525 if (tags_str.value.length > 0 &&
1526 tags_str.value.lastIndexOf(", ") != tags_str.value.length - 2) {
1527
1528 tags_str.value = tags_str.value + ", ";
1529 }
1530
1531 tags_str.value = tags_str.value + tag + ", ";
1532
1533 found_tags.selectedIndex = 0;
1534
1535 } catch (e) {
1536 exception_error("editTagsInsert", e);
1537 }
1538 }
1539
1540 function cdmScrollViewport(where) {
1541 debug("cdmScrollViewport: " + where);
1542
1543 var ctr = $("headlinesInnerContainer");
1544
1545 if (!ctr) return;
1546
1547 if (where == "bottom") {
1548 ctr.scrollTop = ctr.scrollHeight;
1549 } else {
1550 ctr.scrollTop = where;
1551 }
1552 }
1553
1554 function cdmArticleIsBelowViewport(id) {
1555 try {
1556 var ctr = $("headlinesInnerContainer");
1557 var e = $("RROW-" + id);
1558
1559 if (!e || !ctr) return;
1560
1561 // article starts below viewport
1562
1563 if (ctr.scrollTop < e.offsetTop) {
1564 return true;
1565 } else {
1566 return false;
1567 }
1568
1569 } catch (e) {
1570 exception_error("cdmArticleIsVisible", e);
1571 }
1572 }
1573
1574 function cdmArticleIsAboveViewport(id) {
1575 try {
1576 var ctr = $("headlinesInnerContainer");
1577 var e = $("RROW-" + id);
1578
1579 if (!e || !ctr) return;
1580
1581 // article starts above viewport
1582
1583 if (ctr.scrollTop > e.offsetTop + e.offsetHeight) {
1584 return true;
1585 } else {
1586 return false;
1587 }
1588
1589 } catch (e) {
1590 exception_error("cdmArticleIsVisible", e);
1591 }
1592 }
1593
1594 function cdmScrollToArticleId(id) {
1595 try {
1596 var ctr = $("headlinesInnerContainer");
1597 var e = $("RROW-" + id);
1598
1599 if (!e || !ctr) return;
1600
1601 ctr.scrollTop = e.offsetTop;
1602
1603 } catch (e) {
1604 exception_error("cdmScrollToArticleId", e);
1605 }
1606 }
1607
1608 function cdmArticleIsActuallyVisible(id) {
1609 try {
1610 var ctr = $("headlinesInnerContainer");
1611 var e = $("RROW-" + id);
1612
1613 if (!e || !ctr) return;
1614
1615 // article fits in viewport OR article is longer than viewport and
1616 // its bottom is visible
1617
1618 if (ctr.scrollTop <= e.offsetTop && e.offsetTop + e.offsetHeight <=
1619 ctr.scrollTop + ctr.offsetHeight) {
1620
1621 return true;
1622
1623 } else if (e.offsetHeight > ctr.offsetHeight &&
1624 e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1625 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight) {
1626
1627 return true;
1628
1629 }
1630
1631 return false;
1632
1633 } catch (e) {
1634 exception_error("cdmArticleIsVisible", e);
1635 }
1636 }
1637
1638 function cdmWatchdog() {
1639
1640 try {
1641
1642 var ctr = $("headlinesInnerContainer");
1643
1644 if (!ctr) return;
1645
1646 var ids = new Array();
1647
1648 var e = ctr.firstChild;
1649
1650 while (e) {
1651 if (e.className && e.className == "cdmArticleUnread" && e.id &&
1652 e.id.match("RROW-")) {
1653
1654 // article fits in viewport OR article is longer than viewport and
1655 // its bottom is visible
1656
1657 if (ctr.scrollTop <= e.offsetTop && e.offsetTop + e.offsetHeight <=
1658 ctr.scrollTop + ctr.offsetHeight) {
1659
1660 // debug(e.id + " is visible " + e.offsetTop + "." +
1661 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1662 // (ctr.scrollTop + ctr.offsetHeight));
1663
1664 ids.push(e.id.replace("RROW-", ""));
1665
1666 } else if (e.offsetHeight > ctr.offsetHeight &&
1667 e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1668 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight) {
1669
1670 ids.push(e.id.replace("RROW-", ""));
1671
1672 }
1673
1674 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1675
1676 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1677 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1678
1679 ids.push(e.id.replace("RROW-", ""));
1680
1681 } */
1682
1683 }
1684
1685 e = e.nextSibling;
1686 }
1687
1688 debug("cdmWatchdog, ids= " + ids.toString());
1689
1690 if (ids.length > 0) {
1691
1692 for (var i = 0; i < ids.length; i++) {
1693 var e = $("RROW-" + ids[i]);
1694 if (e) {
1695 e.className = e.className.replace("Unread", "");
1696 }
1697 }
1698
1699 var query = "?op=rpc&subop=catchupSelected" +
1700 "&cmode=0" + "&ids=" + param_escape(ids.toString());
1701
1702 new Ajax.Request("backend.php", {
1703 parameters: query,
1704 onComplete: function(transport) {
1705 all_counters_callback2(transport);
1706 } });
1707
1708 }
1709
1710 _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 4000);
1711
1712 } catch (e) {
1713 exception_error("cdmWatchdog", e);
1714 }
1715
1716 }
1717
1718
1719 function cache_inject(id, article, param) {
1720 try {
1721 if (!cache_check_param(id, param)) {
1722 debug("cache_article: miss: " + id + " [p=" + param + "]");
1723
1724 if (db) {
1725
1726 var date = new Date();
1727 var ts = Math.round(date.getTime() / 1000);
1728
1729 db.execute("INSERT INTO cache (id, article, param, added) VALUES (?, ?, ?, ?)",
1730 [id, article, param, ts]);
1731 } else {
1732
1733 var cache_obj = new Array();
1734
1735 cache_obj["id"] = id;
1736 cache_obj["data"] = article;
1737 cache_obj["param"] = param;
1738
1739 article_cache.push(cache_obj);
1740 }
1741
1742 } else {
1743 debug("cache_article: hit: " + id + " [p=" + param + "]");
1744 }
1745 } catch (e) {
1746 exception_error("cache_inject", e);
1747 }
1748 }
1749
1750 function cache_find(id) {
1751
1752 if (db) {
1753 var rs = db.execute("SELECT article FROM cache WHERE id = ?", [id]);
1754 var a = false;
1755
1756 if (rs.isValidRow()) {
1757 var a = rs.field(0);
1758 }
1759
1760 rs.close();
1761
1762 return a;
1763
1764 } else {
1765 for (var i = 0; i < article_cache.length; i++) {
1766 if (article_cache[i]["id"] == id) {
1767 return article_cache[i]["data"];
1768 }
1769 }
1770 }
1771 return false;
1772 }
1773
1774 function cache_find_param(id, param) {
1775
1776 if (db) {
1777 var rs = db.execute("SELECT article FROM cache WHERE id = ? AND param = ?",
1778 [id, param]);
1779 var a = false;
1780
1781 if (rs.isValidRow()) {
1782 a = rs.field(0);
1783 }
1784
1785 rs.close();
1786
1787 return a;
1788
1789 } else {
1790 for (var i = 0; i < article_cache.length; i++) {
1791 if (article_cache[i]["id"] == id && article_cache[i]["param"] == param) {
1792 return article_cache[i]["data"];
1793 }
1794 }
1795 }
1796 return false;
1797 }
1798
1799 function cache_check(id) {
1800
1801 if (db) {
1802 var rs = db.execute("SELECT COUNT(*) AS c FROM cache WHERE id = ?",
1803 [id]);
1804 var a = false;
1805
1806 if (rs.isValidRow()) {
1807 a = rs.field(0) != "0";
1808 }
1809
1810 rs.close();
1811
1812 return a;
1813
1814 } else {
1815 for (var i = 0; i < article_cache.length; i++) {
1816 if (article_cache[i]["id"] == id) {
1817 return true;
1818 }
1819 }
1820 }
1821 return false;
1822 }
1823
1824 function cache_check_param(id, param) {
1825
1826 if (db) {
1827 var rs = db.execute("SELECT COUNT(*) AS c FROM cache WHERE id = ? AND param = ?",
1828 [id, param]);
1829 var a = false;
1830
1831 if (rs.isValidRow()) {
1832 a = rs.field(0) != "0";
1833 }
1834
1835 rs.close();
1836
1837 return a;
1838
1839 } else {
1840 for (var i = 0; i < article_cache.length; i++) {
1841 if (article_cache[i]["id"] == id && article_cache[i]["param"] == param) {
1842 return true;
1843 }
1844 }
1845 }
1846 return false;
1847 }
1848
1849 function cache_expire() {
1850 if (db) {
1851 var date = new Date();
1852 var ts = Math.round(date.getTime() / 1000);
1853
1854 db.execute("DELETE FROM cache WHERE added < ? - 1800 AND id LIKE 'FEEDLIST'", [ts]);
1855 db.execute("DELETE FROM cache WHERE added < ? - 600 AND (id LIKE 'F:%' OR id LIKE 'C:%')", [ts]);
1856 db.execute("DELETE FROM cache WHERE added < ? - 86400", [ts]);
1857
1858
1859 } else {
1860 while (article_cache.length > 25) {
1861 article_cache.shift();
1862 }
1863 }
1864 }
1865
1866 function cache_flush() {
1867 article_cache = new Array();
1868 }
1869
1870 function cache_invalidate(id) {
1871 try {
1872
1873 if (db) {
1874 rs = db.execute("DELETE FROM cache WHERE id = ?", [id]);
1875 return rs.rowsAffected != 0;
1876 } else {
1877
1878 var i = 0
1879
1880 while (i < article_cache.length) {
1881 if (article_cache[i]["id"] == id) {
1882 debug("cache_invalidate: removed id " + id);
1883 article_cache.splice(i, 1);
1884 return true;
1885 }
1886 i++;
1887 }
1888 }
1889
1890 debug("cache_invalidate: id not found: " + id);
1891 return false;
1892 } catch (e) {
1893 exception_error("cache_invalidate", e);
1894 }
1895 }
1896
1897 function getActiveArticleId() {
1898 return active_post_id;
1899 }
1900
1901 function cdmClicked(id) {
1902 try {
1903 var elem = $("RROW-" + id);
1904
1905 if (elem) {
1906 var id = elem.id.replace("RROW-", "");
1907 active_post_id = id;
1908
1909 // cdmSelectArticles("none");
1910 toggleUnread(id, 0, true);
1911 // toggleSelected(id);
1912
1913 }
1914 } catch (e) {
1915 exception_error("cdmClicked", e);
1916 }
1917 }
1918
1919 function preloadArticleUnderPointer(id) {
1920 try {
1921 if (getInitParam("bw_limit") == "1") return;
1922
1923 if (post_under_pointer == id && !cache_check(id)) {
1924
1925 debug("trying to preload article " + id);
1926
1927 var neighbor_ids = getRelativePostIds(id, 1);
1928
1929 /* only request uncached articles */
1930
1931 var cids_to_request = Array();
1932
1933 for (var i = 0; i < neighbor_ids.length; i++) {
1934 if (!cache_check(neighbor_ids[i])) {
1935 cids_to_request.push(neighbor_ids[i]);
1936 }
1937 }
1938 debug("additional ids: " + cids_to_request.toString());
1939
1940 cids_to_request.push(id);
1941
1942 var query = "?op=rpc&subop=getArticles&ids=" +
1943 cids_to_request.toString();
1944
1945 new Ajax.Request("backend.php", {
1946 parameters: query,
1947 onComplete: function(transport) {
1948 var articles = transport.responseXML.getElementsByTagName("article");
1949
1950 for (var i = 0; i < articles.length; i++) {
1951 var id = articles[i].getAttribute("id");
1952 if (!cache_check(id)) {
1953 cache_inject(id, articles[i].firstChild.nodeValue);
1954 debug("preloaded article: " + id);
1955 }
1956 }
1957 } });
1958 }
1959 } catch (e) {
1960 exception_error("preloadArticleUnderPointer", e);
1961 }
1962 }
1963
1964 function postMouseIn(id) {
1965 try {
1966 if (post_under_pointer != id) {
1967 post_under_pointer = id;
1968 if (!isCdmMode()) {
1969 window.setTimeout("preloadArticleUnderPointer(" + id + ")", 250);
1970 }
1971 }
1972
1973 } catch (e) {
1974 exception_error("postMouseIn", e);
1975 }
1976 }
1977
1978 function postMouseOut(id) {
1979 try {
1980 post_under_pointer = false;
1981 } catch (e) {
1982 exception_error("postMouseOut", e);
1983 }
1984 }
1985
1986 function headlines_scroll_handler() {
1987 try {
1988
1989 var e = $("headlinesInnerContainer");
1990
1991 var toolbar_form = document.forms["main_toolbar_form"];
1992
1993 debug((e.scrollTop + e.offsetHeight) + " vs " + e.scrollHeight + " dis? " +
1994 _infscroll_disable);
1995
1996 if (e.scrollTop + e.offsetHeight > e.scrollHeight - 100) {
1997 if (!_infscroll_disable) {
1998 debug("more cowbell!");
1999 viewNextFeedPage();
2000 }
2001 }
2002
2003 } catch (e) {
2004 exception_error("headlines_scroll_handler", e);
2005 }
2006 }
2007
2008 function catchupRelativeToArticle(below) {
2009
2010 try {
2011
2012
2013 if (!getActiveArticleId()) {
2014 alert(__("No article is selected."));
2015 return;
2016 }
2017
2018 var visible_ids;
2019
2020 if ($("headlinesList")) {
2021 visible_ids = getVisibleHeadlineIds();
2022 } else {
2023 visible_ids = cdmGetVisibleArticles();
2024 }
2025
2026 var ids_to_mark = new Array();
2027
2028 if (!below) {
2029 for (var i = 0; i < visible_ids.length; i++) {
2030 if (visible_ids[i] != getActiveArticleId()) {
2031 var e = $("RROW-" + visible_ids[i]);
2032
2033 if (e && e.className.match("Unread")) {
2034 ids_to_mark.push(visible_ids[i]);
2035 }
2036 } else {
2037 break;
2038 }
2039 }
2040 } else {
2041 for (var i = visible_ids.length-1; i >= 0; i--) {
2042 if (visible_ids[i] != getActiveArticleId()) {
2043 var e = $("RROW-" + visible_ids[i]);
2044
2045 if (e && e.className.match("Unread")) {
2046 ids_to_mark.push(visible_ids[i]);
2047 }
2048 } else {
2049 break;
2050 }
2051 }
2052 }
2053
2054 if (ids_to_mark.length == 0) {
2055 alert(__("No articles found to mark"));
2056 } else {
2057 var msg = __("Mark %d article(s) as read?").replace("%d", ids_to_mark.length);
2058
2059 if (confirm(msg)) {
2060
2061 for (var i = 0; i < ids_to_mark.length; i++) {
2062 var e = $("RROW-" + ids_to_mark[i]);
2063 e.className = e.className.replace("Unread", "");
2064 }
2065
2066 var query = "?op=rpc&subop=catchupSelected" +
2067 "&cmode=0" + "&ids=" + param_escape(ids_to_mark.toString());
2068
2069 new Ajax.Request("backend.php", {
2070 parameters: query,
2071 onComplete: function(transport) {
2072 catchup_callback2(transport);
2073 } });
2074
2075 }
2076 }
2077
2078 } catch (e) {
2079 exception_error("catchupRelativeToArticle", e);
2080 }
2081 }
2082
2083 function cdmExpandArticle(a_id) {
2084 try {
2085 var id = 'CICD-' + a_id;
2086
2087 try {
2088 Element.hide("CEXC-" + a_id);
2089 } catch (e) { }
2090
2091 Effect.Appear(id, {duration : 0.5,
2092 beforeStart: function(effect) {
2093 var h_id = 'CICH-' + a_id;
2094 var h_elem = $(h_id);
2095 if (h_elem) { h_elem.style.display = "none"; }
2096
2097 toggleUnread(a_id, 0);
2098 }});
2099
2100
2101 } catch (e) {
2102 exception_error("appearBlockElementF", e);
2103 }
2104
2105 }
2106
2107 function fixHeadlinesOrder(ids) {
2108 try {
2109 for (var i = 0; i < ids.length; i++) {
2110 var e = $("RROW-" + ids[i]);
2111
2112 if (e) {
2113 if (i % 2 == 0) {
2114 e.className = e.className.replace("even", "odd");
2115 } else {
2116 e.className = e.className.replace("odd", "even");
2117 }
2118 }
2119 }
2120 } catch (e) {
2121 exception_error("fixHeadlinesOrder", e);
2122 }
2123 }
2124
2125 function hideReadHeadlines() {
2126 try {
2127
2128 var ids = false;
2129 var vis_ids = new Array();
2130
2131 if ($("headlinesList")) {
2132 ids = getVisibleHeadlineIds();
2133 } else {
2134 ids = cdmGetVisibleArticles();
2135 }
2136
2137 var read_headlines_visible = true;
2138
2139 for (var i = 0; i < ids.length; i++) {
2140 var row = $("RROW-" + ids[i]);
2141
2142 if (row && row.className) {
2143 if (read_headlines_visible) {
2144 if (row.className.match("Unread") || row.className.match("Selected")) {
2145 Element.show(row);
2146 vis_ids.push(ids[i]);
2147 } else {
2148 //Effect.Fade(row, {duration : 0.3});
2149 Element.hide(row);
2150 }
2151 } else {
2152 Element.show(row);
2153 vis_ids.push(ids[i]);
2154 }
2155 }
2156 }
2157
2158 fixHeadlinesOrder(vis_ids);
2159
2160 read_headlines_visible = !read_headlines_visible;
2161
2162 } catch (e) {
2163 exception_error("hideReadHeadlines", e);
2164 }
2165 }
2166
2167 function invertHeadlineSelection() {
2168 try {
2169 var rows = new Array();
2170 var r = false;
2171
2172 if (!isCdmMode()) {
2173 r = document.getElementsByTagName("TR");
2174 } else {
2175 r = document.getElementsByTagName("DIV");
2176 }
2177
2178 for (var i = 0; i < r.length; i++) {
2179 if (r[i].id && r[i].id.match("RROW-")) {
2180 rows.push(r[i]);
2181 }
2182 }
2183
2184 for (var i = 0; i < rows.length; i++) {
2185 var nc = rows[i].className;
2186 var id = rows[i].id.replace("RROW-", "");
2187 var cb = $("RCHK-" + id);
2188
2189 if (!rows[i].className.match("Selected")) {
2190 nc = nc + "Selected";
2191 cb.checked = true;
2192 } else {
2193 nc = nc.replace("Selected", "");
2194 cb.checked = false;
2195 }
2196
2197 rows[i].className = nc;
2198
2199 }
2200
2201 } catch (e) {
2202 exception_error("invertHeadlineSelection", e);
2203 }
2204 }
2205
2206 function getArticleUnderPointer() {
2207 return post_under_pointer;
2208 }
2209
2210 function zoomToArticle(id) {
2211 try {
2212 var w = window.open("backend.php?op=view&mode=zoom&id=" + param_escape(id),
2213 "ttrss_zoom_" + id,
2214 "status=0,toolbar=0,location=0,width=450,height=300,scrollbars=1,menubar=0");
2215
2216 } catch (e) {
2217 exception_error("zoomToArticle", e);
2218 }
2219 }
2220
2221 function showOriginalArticleInline(id) {
2222 try {
2223
2224 var query = "?op=rpc&subop=getArticleLink&id=" + id;
2225
2226 notify_progress("Loading, please wait...", true);
2227
2228 new Ajax.Request("backend.php", {
2229 parameters: query,
2230 onComplete: function(transport) {
2231
2232 if (transport.responseXML) {
2233
2234 var link = transport.responseXML.getElementsByTagName("link")[0];
2235 var id = transport.responseXML.getElementsByTagName("id")[0];
2236
2237 notify("");
2238
2239 if (link && id) {
2240 link = link.firstChild.nodeValue;
2241
2242 var ci = $("content-insert");
2243
2244 var tmp = "<iframe id=\"inline_orig_article\" width=\""+ci.offsetWidth+"\" height=\""+ci.offsetHeight+"\" style=\"border-width : 0px;\" src=\""+link+"\"></iframe>";
2245
2246 render_article(tmp);
2247
2248 }
2249 }
2250 } });
2251
2252 } catch (e) {
2253 exception_error("showOriginalArticleInline", e);
2254 }
2255 }
2256
2257
2258 function scrollArticle(offset) {
2259 try {
2260 if (!isCdmMode()) {
2261 var ci = $("content-insert");
2262 if (ci) {
2263 ci.scrollTop += offset;
2264 }
2265 } else {
2266 var hi = $("headlinesInnerContainer");
2267 if (hi) {
2268 hi.scrollTop += offset;
2269 }
2270
2271 }
2272 } catch (e) {
2273 exception_error("scrollArticle", e);
2274 }
2275 }
2276
2277 function show_labels_in_headlines(transport) {
2278 try {
2279 if (transport.responseXML) {
2280 var info = transport.responseXML.getElementsByTagName("info-for-headlines")[0];
2281
2282 var elems = info.getElementsByTagName("entry");
2283
2284 for (var l = 0; l < elems.length; l++) {
2285 var e_id = elems[l].getAttribute("id");
2286
2287 if (e_id) {
2288
2289 var ctr = $("HLLCTR-" + e_id);
2290
2291 if (ctr) {
2292 ctr.innerHTML = elems[l].firstChild.nodeValue;
2293 }
2294 }
2295
2296 }
2297
2298 }
2299 } catch (e) {
2300 exception_error("show_labels_in_headlines", e);
2301
2302 }
2303 }
2304
2305 function toggleHeadlineActions() {
2306 try {
2307 var e = $("headlineActionsBody");
2308 var p = $("headlineActionsDrop");
2309
2310 if (!Element.visible(e)) {
2311 Element.show(e);
2312 } else {
2313 Element.hide(e);
2314 }
2315
2316 e.scrollTop = 0;
2317 e.style.left = (p.offsetLeft + 1) + "px";
2318 e.style.top = (p.offsetTop + p.offsetHeight + 2) + "px";
2319
2320 } catch (e) {
2321 exception_error("toggleHeadlineActions", e);
2322 }
2323 }
2324
2325 function publishWithNote(id, def_note) {
2326 try {
2327 if (!def_note) def_note = '';
2328
2329 var note = prompt(__("Please enter a note for this article:"), def_note);
2330
2331 if (note != undefined) {
2332 togglePub(id, false, false, note);
2333 }
2334
2335 } catch (e) {
2336 exception_error("publishWithNote", e);
2337 }
2338 }