]> git.wh0rd.org - tt-rss.git/blob - viewfeed.js
tag cloud shows top 100 instead of top 50
[tt-rss.git] / viewfeed.js
1 var active_post_id = false;
2 var _catchup_callback_func = false;
3 var last_article_view = false;
4 var active_real_feed_id = false;
5
6 var _tag_active_post_id = false;
7 var _tag_active_feed_id = false;
8 var _tag_active_cdm = false;
9
10 // FIXME: kludge, to restore scrollTop after tag editor terminates
11 var _tag_cdm_scroll = false;
12
13 // FIXME: kludges, needs proper implementation
14 var _reload_feedlist_after_view = false;
15
16 var _cdm_wd_timeout = false;
17 var _cdm_wd_vishist = new Array();
18
19 var article_cache = new Array();
20
21 function catchup_callback() {
22 if (xmlhttp_rpc.readyState == 4) {
23 try {
24 debug("catchup_callback");
25 if (_catchup_callback_func) {
26 setTimeout(_catchup_callback_func, 100);
27 }
28 notify("");
29 all_counters_callback();
30 } catch (e) {
31 exception_error("catchup_callback", e);
32 }
33 }
34 }
35
36 function headlines_callback() {
37 if (xmlhttp.readyState == 4) {
38 debug("headlines_callback");
39 var f = document.getElementById("headlines-frame");
40 try {
41 f.scrollTop = 0;
42 } catch (e) { };
43
44 if (xmlhttp.responseXML) {
45 var headlines = xmlhttp.responseXML.getElementsByTagName("headlines")[0];
46 var counters = xmlhttp.responseXML.getElementsByTagName("counters")[0];
47 var articles = xmlhttp.responseXML.getElementsByTagName("article");
48
49 if (headlines) {
50 f.innerHTML = headlines.firstChild.nodeValue;
51 } else {
52 debug("headlines_callback: returned no data");
53 f.innerHTML = "<div class='whiteBox'>" + __('Could not update headlines (missing XML data)') + "</div>";
54
55 }
56
57 if (articles) {
58 for (var i = 0; i < articles.length; i++) {
59 var a_id = articles[i].getAttribute("id");
60 debug("found id: " + a_id);
61 cache_inject(a_id, articles[i].firstChild.nodeValue);
62 }
63 } else {
64 debug("no cached articles received");
65 }
66
67 if (counters) {
68 debug("parsing piggybacked counters: " + counters);
69 parse_counters(counters, false);
70 } else {
71 debug("counters container not found in reply");
72 }
73 } else {
74 debug("headlines_callback: returned no XML object");
75 f.innerHTML = "<div class='whiteBox'>" + __('Could not update headlines (missing XML object)') + "</div>";
76 }
77
78 if (typeof correctPNG != 'undefined') {
79 correctPNG();
80 }
81
82 if (_cdm_wd_timeout) window.clearTimeout(_cdm_wd_timeout);
83
84 if (!document.getElementById("headlinesList") &&
85 getInitParam("cdm_auto_catchup") == 1) {
86 debug("starting CDM watchdog");
87 _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 5000);
88 _cdm_wd_vishist = new Array();
89 } else {
90 debug("not in CDM mode or watchdog disabled");
91 }
92
93 if (_tag_cdm_scroll) {
94 try {
95 document.getElementById("headlinesInnerContainer").scrollTop = _tag_cdm_scroll;
96 _tag_cdm_scroll = false;
97 } catch (e) { }
98 }
99
100 notify("");
101 }
102 }
103
104 function render_article(article) {
105 try {
106 var f = document.getElementById("content-frame");
107 try {
108 f.scrollTop = 0;
109 } catch (e) { };
110
111 f.innerHTML = article;
112
113 } catch (e) {
114 exception_error("render_article", e);
115 }
116 }
117
118 function article_callback() {
119 if (xmlhttp.readyState == 4) {
120 debug("article_callback");
121
122 try {
123 if (xmlhttp.responseXML) {
124 var reply = xmlhttp.responseXML.firstChild.firstChild;
125
126 var articles = xmlhttp.responseXML.getElementsByTagName("article");
127
128 for (var i = 0; i < articles.length; i++) {
129 var a_id = articles[i].getAttribute("id");
130
131 debug("found id: " + a_id);
132
133 if (a_id == active_post_id) {
134 debug("active article, rendering...");
135 render_article(articles[i].firstChild.nodeValue);
136 }
137
138 cache_inject(a_id, articles[i].firstChild.nodeValue);
139 }
140
141 } else {
142 debug("article_callback: returned no XML object");
143 var f = document.getElementById("content-frame");
144 f.innerHTML = "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>";
145 }
146 } catch (e) {
147 exception_error("article_callback", e);
148 }
149
150 var date = new Date();
151 last_article_view = date.getTime() / 1000;
152
153 if (typeof correctPNG != 'undefined') {
154 correctPNG();
155 }
156
157 if (_reload_feedlist_after_view) {
158 setTimeout('updateFeedList(false, false)', 50);
159 _reload_feedlist_after_view = false;
160 } else {
161 var counters = xmlhttp.responseXML.getElementsByTagName("counters")[0];
162
163 if (counters) {
164 debug("parsing piggybacked counters: " + counters);
165 parse_counters(counters, false);
166 } else {
167 debug("counters container not found in reply");
168 }
169 }
170
171 notify("");
172 }
173 }
174
175 function view(id, feed_id, skip_history) {
176
177 try {
178 debug("loading article: " + id + "/" + feed_id);
179
180 active_real_feed_id = feed_id;
181
182 var cached_article = cache_find(id);
183
184 debug("cache check result: " + (cached_article != false));
185
186 /* if (!skip_history) {
187 history_push("ARTICLE:" + id + ":" + feed_id);
188 } */
189
190 enableHotkeys();
191
192 //setActiveFeedId(feed_id);
193
194 var query = "backend.php?op=view&id=" + param_escape(id) +
195 "&feed=" + param_escape(feed_id);
196
197 var date = new Date();
198
199 if (!xmlhttp_ready(xmlhttp) && last_article_view < date.getTime() / 1000 - 15) {
200 debug("<b>xmlhttp seems to be stuck at view, aborting</b>");
201 xmlhttp.abort();
202 }
203
204 if (xmlhttp_ready(xmlhttp)) {
205
206 active_post_id = id;
207
208 cleanSelected("headlinesList");
209
210 var crow = document.getElementById("RROW-" + active_post_id);
211
212 var article_is_unread = crow.className.match("Unread");
213 debug("article is unread: " + article_is_unread);
214
215 crow.className = crow.className.replace("Unread", "");
216
217 var upd_img_pic = document.getElementById("FUPDPIC-" + active_post_id);
218
219 if (upd_img_pic) {
220 upd_img_pic.src = "images/blank_icon.gif";
221 }
222
223 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
224 markHeadline(active_post_id);
225
226 var neighbor_ids = getRelativePostIds(active_post_id);
227
228 /* only request uncached articles */
229
230 var cids_to_request = Array();
231
232 for (var i = 0; i < neighbor_ids.length; i++) {
233 if (!cache_check(neighbor_ids[i])) {
234 cids_to_request.push(neighbor_ids[i]);
235 }
236 }
237
238 debug("additional ids: " + cids_to_request.toString());
239
240 /* additional info for piggyback counters */
241
242 if (tagsAreDisplayed()) {
243 query = query + "&omode=lt";
244 } else {
245 query = query + "&omode=flc";
246 }
247
248 var date = new Date();
249 var timestamp = Math.round(date.getTime() / 1000);
250 query = query + "&ts=" + timestamp;
251
252 query = query + "&cids=" + cids_to_request.toString();
253
254 if (!cached_article) {
255
256 notify_progress("Loading, please wait...");
257
258 debug(query);
259
260 xmlhttp.open("GET", query, true);
261 xmlhttp.onreadystatechange=article_callback;
262 xmlhttp.send(null);
263 } else if (cached_article && article_is_unread) {
264
265 query = query + "&mode=prefetch";
266
267 debug(query);
268
269 xmlhttp.open("GET", query, true);
270 xmlhttp.onreadystatechange=article_callback;
271 xmlhttp.send(null);
272
273 render_article(cached_article);
274
275 } else if (cached_article) {
276
277 query = query + "&mode=prefetch_old";
278
279 debug(query);
280
281 xmlhttp.open("GET", query, true);
282 xmlhttp.onreadystatechange=article_callback;
283 xmlhttp.send(null);
284
285 render_article(cached_article);
286
287 }
288
289 cache_expire();
290
291 } else {
292 debug("xmlhttp busy (@view)");
293 printLockingError();
294 }
295
296 } catch (e) {
297 exception_error("view", e);
298 }
299 }
300
301 function tMark(id) {
302 return toggleMark(id);
303 }
304
305 function toggleMark(id) {
306
307 if (!xmlhttp_ready(xmlhttp_rpc)) {
308 printLockingError();
309 return;
310 }
311
312 var query = "backend.php?op=rpc&id=" + id + "&subop=mark";
313
314 var mark_img = document.getElementById("FMPIC-" + id);
315 var vfeedu = document.getElementById("FEEDU--1");
316 var crow = document.getElementById("RROW-" + id);
317
318 if (mark_img.alt != "Reset mark") {
319 mark_img.src = "images/mark_set.png";
320 mark_img.alt = "Reset mark";
321 query = query + "&mark=1";
322
323 if (vfeedu && crow.className.match("Unread")) {
324 vfeedu.innerHTML = (+vfeedu.innerHTML) + 1;
325 }
326
327 } else {
328 mark_img.src = "images/mark_unset.png";
329 mark_img.alt = "Set mark";
330 query = query + "&mark=0";
331
332 if (vfeedu && crow.className.match("Unread")) {
333 vfeedu.innerHTML = (+vfeedu.innerHTML) - 1;
334 }
335
336 }
337
338 var vfeedctr = document.getElementById("FEEDCTR--1");
339 var vfeedr = document.getElementById("FEEDR--1");
340
341 if (vfeedu && vfeedctr) {
342 if ((+vfeedu.innerHTML) > 0) {
343 if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) {
344 vfeedr.className = vfeedr.className + "Unread";
345 vfeedctr.className = "odd";
346 }
347 } else {
348 vfeedctr.className = "invisible";
349 vfeedr.className = vfeedr.className.replace("Unread", "");
350 }
351 }
352
353 debug("toggle starred for aid " + id);
354
355 new Ajax.Request(query);
356
357 }
358
359 function correctHeadlinesOffset(id) {
360
361 try {
362
363 var hlist = document.getElementById("headlinesList");
364 var container = document.getElementById("headlinesInnerContainer");
365 var row = document.getElementById("RROW-" + id);
366
367 var viewport = container.offsetHeight;
368
369 var rel_offset_top = row.offsetTop - container.scrollTop;
370 var rel_offset_bottom = row.offsetTop + row.offsetHeight - container.scrollTop;
371
372 debug("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
373 debug("Vport: " + viewport);
374
375 if (rel_offset_top <= 0 || rel_offset_top > viewport) {
376 container.scrollTop = row.offsetTop;
377 } else if (rel_offset_bottom > viewport) {
378
379 /* doesn't properly work with Opera in some cases because
380 Opera fucks up element scrolling */
381
382 container.scrollTop = row.offsetTop + row.offsetHeight - viewport;
383 }
384
385 } catch (e) {
386 exception_error("correctHeadlinesOffset", e);
387 }
388
389 }
390
391 function moveToPost(mode) {
392
393 // check for combined mode
394 if (!document.getElementById("headlinesList"))
395 return;
396
397 var rows = getVisibleHeadlineIds();
398
399 var prev_id = false;
400 var next_id = false;
401
402 if (!document.getElementById('RROW-' + active_post_id)) {
403 active_post_id = false;
404 }
405
406 if (active_post_id == false) {
407 next_id = getFirstVisibleHeadlineId();
408 prev_id = getLastVisibleHeadlineId();
409 } else {
410 for (var i = 0; i < rows.length; i++) {
411 if (rows[i] == active_post_id) {
412 prev_id = rows[i-1];
413 next_id = rows[i+1];
414 }
415 }
416 }
417
418 if (mode == "next") {
419 if (next_id) {
420 correctHeadlinesOffset(next_id);
421 view(next_id, getActiveFeedId());
422 }
423 }
424
425 if (mode == "prev") {
426 if (prev_id) {
427 correctHeadlinesOffset(prev_id);
428 view(prev_id, getActiveFeedId());
429 }
430 }
431 }
432
433 function toggleUnread(id, cmode) {
434 try {
435 if (!xmlhttp_ready(xmlhttp_rpc)) {
436 printLockingError();
437 return;
438 }
439
440 var row = document.getElementById("RROW-" + id);
441 if (row) {
442 var nc = row.className;
443 nc = nc.replace("Unread", "");
444 nc = nc.replace("Selected", "");
445
446 if (row.className.match("Unread")) {
447 row.className = nc;
448 } else {
449 row.className = nc + "Unread";
450 }
451
452 if (!cmode) cmode = 2;
453
454 var query = "backend.php?op=rpc&subop=catchupSelected&ids=" +
455 param_escape(id) + "&cmode=" + param_escape(cmode);
456
457 notify_progress("Loading, please wait...");
458
459 xmlhttp_rpc.open("GET", query, true);
460 xmlhttp_rpc.onreadystatechange=all_counters_callback;
461 xmlhttp_rpc.send(null);
462
463 }
464
465
466 } catch (e) {
467 exception_error("toggleUnread", e);
468 }
469 }
470
471 function selectionToggleUnread(cdm_mode, set_state, callback_func, no_error) {
472 try {
473 if (!xmlhttp_ready(xmlhttp_rpc)) {
474 printLockingError();
475 return;
476 }
477
478 var rows;
479
480 if (cdm_mode) {
481 rows = cdmGetSelectedArticles();
482 } else {
483 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
484 }
485
486 if (rows.length == 0 && !no_error) {
487 alert(__("No articles are selected."));
488 return;
489 }
490
491 for (i = 0; i < rows.length; i++) {
492 var row = document.getElementById("RROW-" + rows[i]);
493 if (row) {
494 var nc = row.className;
495 nc = nc.replace("Unread", "");
496 nc = nc.replace("Selected", "");
497
498 if (row.className.match("Unread")) {
499 row.className = nc + "Selected";
500 } else {
501 row.className = nc + "UnreadSelected";
502 }
503 }
504 }
505
506 if (rows.length > 0) {
507
508 var cmode = "";
509
510 if (set_state == undefined) {
511 cmode = "2";
512 } else if (set_state == true) {
513 cmode = "1";
514 } else if (set_state == false) {
515 cmode = "0";
516 }
517
518 var query = "backend.php?op=rpc&subop=catchupSelected&ids=" +
519 param_escape(rows.toString()) + "&cmode=" + cmode;
520
521 _catchup_callback_func = callback_func;
522
523 notify_progress("Loading, please wait...");
524
525 xmlhttp_rpc.open("GET", query, true);
526 xmlhttp_rpc.onreadystatechange=catchup_callback;
527 xmlhttp_rpc.send(null);
528
529 }
530
531 } catch (e) {
532 exception_error("selectionToggleUnread", e);
533 }
534 }
535
536 function selectionToggleMarked(cdm_mode) {
537 try {
538 if (!xmlhttp_ready(xmlhttp_rpc)) {
539 printLockingError();
540 return;
541 }
542
543 var rows;
544
545 if (cdm_mode) {
546 rows = cdmGetSelectedArticles();
547 } else {
548 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
549 }
550
551 if (rows.length == 0) {
552 alert(__("No articles are selected."));
553 return;
554 }
555
556 for (i = 0; i < rows.length; i++) {
557 var row = document.getElementById("RROW-" + rows[i]);
558 var mark_img = document.getElementById("FMARKPIC-" + rows[i]);
559
560 if (row && mark_img) {
561
562 if (mark_img.alt == "Set mark") {
563 mark_img.src = "images/mark_set.png";
564 mark_img.alt = "Reset mark";
565 mark_img.setAttribute('onclick',
566 'javascript:toggleMark('+rows[i]+', false)');
567
568 } else {
569 mark_img.src = "images/mark_unset.png";
570 mark_img.alt = "Set mark";
571 mark_img.setAttribute('onclick',
572 'javascript:toggleMark('+rows[i]+', true)');
573 }
574 }
575 }
576
577 if (rows.length > 0) {
578
579 var query = "backend.php?op=rpc&subop=markSelected&ids=" +
580 param_escape(rows.toString()) + "&cmode=2";
581
582 xmlhttp_rpc.open("GET", query, true);
583 xmlhttp_rpc.onreadystatechange=all_counters_callback;
584 xmlhttp_rpc.send(null);
585
586 }
587
588 } catch (e) {
589 exception_error("selectionToggleMarked", e);
590 }
591 }
592
593 function cdmGetSelectedArticles() {
594 var sel_articles = new Array();
595 var container = document.getElementById("headlinesInnerContainer");
596
597 for (i = 0; i < container.childNodes.length; i++) {
598 var child = container.childNodes[i];
599
600 if (child.id.match("RROW-") && child.className.match("Selected")) {
601 var c_id = child.id.replace("RROW-", "");
602 sel_articles.push(c_id);
603 }
604 }
605
606 return sel_articles;
607 }
608
609 // mode = all,none,unread
610 function cdmSelectArticles(mode) {
611 var container = document.getElementById("headlinesInnerContainer");
612
613 for (i = 0; i < container.childNodes.length; i++) {
614 var child = container.childNodes[i];
615
616 if (child.id.match("RROW-")) {
617 var aid = child.id.replace("RROW-", "");
618
619 var cb = document.getElementById("RCHK-" + aid);
620
621 if (mode == "all") {
622 if (!child.className.match("Selected")) {
623 child.className = child.className + "Selected";
624 cb.checked = true;
625 }
626 } else if (mode == "unread") {
627 if (child.className.match("Unread") && !child.className.match("Selected")) {
628 child.className = child.className + "Selected";
629 cb.checked = true;
630 }
631 } else {
632 child.className = child.className.replace("Selected", "");
633 cb.checked = false;
634 }
635 }
636 }
637 }
638
639 function catchupPage() {
640
641 if (document.getElementById("headlinesList")) {
642 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
643 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
644 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
645 } else {
646 cdmSelectArticles('all');
647 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
648 cdmSelectArticles('none');
649 }
650 }
651
652 function labelFromSearch(search, search_mode, match_on, feed_id, is_cat) {
653
654 if (!xmlhttp_ready(xmlhttp_rpc)) {
655 printLockingError();
656 }
657
658 var title = prompt("Please enter label title:", "");
659
660 if (title) {
661
662 var query = "backend.php?op=labelFromSearch&search=" + param_escape(search) +
663 "&smode=" + param_escape(search_mode) + "&match=" + param_escape(match_on) +
664 "&feed=" + param_escape(feed_id) + "&is_cat=" + param_escape(is_cat) +
665 "&title=" + param_escape(title);
666
667 debug("LFS: " + query);
668
669 xmlhttp_rpc.open("GET", query, true);
670 xmlhttp_rpc.onreadystatechange=dlg_frefresh_callback;
671 xmlhttp_rpc.send(null);
672 }
673
674 }
675
676 function editArticleTags(id, feed_id, cdm_enabled) {
677 _tag_active_post_id = id;
678 _tag_active_feed_id = feed_id;
679 _tag_active_cdm = cdm_enabled;
680
681 cache_invalidate(id);
682
683 try {
684 _tag_cdm_scroll = document.getElementById("headlinesInnerContainer").scrollTop;
685 } catch (e) { }
686 displayDlg('editArticleTags', id);
687 }
688
689
690 function tag_saved_callback() {
691 if (xmlhttp_rpc.readyState == 4) {
692 try {
693 debug("in tag_saved_callback");
694
695 closeInfoBox();
696 notify("");
697
698 if (tagsAreDisplayed()) {
699 _reload_feedlist_after_view = true;
700 }
701
702 if (!_tag_active_cdm) {
703 if (active_post_id == _tag_active_post_id) {
704 debug("reloading current article");
705 view(_tag_active_post_id, _tag_active_feed_id);
706 }
707 } else {
708 debug("reloading current feed");
709 viewCurrentFeed();
710 }
711
712 } catch (e) {
713 exception_error("catchup_callback", e);
714 }
715 }
716 }
717
718 function editTagsSave() {
719
720 if (!xmlhttp_ready(xmlhttp_rpc)) {
721 printLockingError();
722 }
723
724 notify_progress("Saving article tags...");
725
726 var form = document.forms["tag_edit_form"];
727
728 var query = Form.serialize("tag_edit_form");
729
730 xmlhttp_rpc.open("GET", "backend.php?op=rpc&subop=setArticleTags&" + query, true);
731 xmlhttp_rpc.onreadystatechange=tag_saved_callback;
732 xmlhttp_rpc.send(null);
733
734 }
735
736 function editTagsInsert() {
737 try {
738
739 var form = document.forms["tag_edit_form"];
740
741 var found_tags = form.found_tags;
742 var tags_str = form.tags_str;
743
744 var tag = found_tags[found_tags.selectedIndex].value;
745
746 if (tags_str.value.length > 0 &&
747 tags_str.value.lastIndexOf(", ") != tags_str.value.length - 2) {
748
749 tags_str.value = tags_str.value + ", ";
750 }
751
752 tags_str.value = tags_str.value + tag + ", ";
753
754 found_tags.selectedIndex = 0;
755
756 } catch (e) {
757 exception_error(e, "editTagsInsert");
758 }
759 }
760
761 function cdmWatchdog() {
762
763 try {
764
765 var ctr = document.getElementById("headlinesInnerContainer");
766
767 if (!ctr) return;
768
769 var ids = new Array();
770
771 var e = ctr.firstChild;
772
773 while (e) {
774 if (e.className && e.className == "cdmArticleUnread" && e.id &&
775 e.id.match("RROW-")) {
776
777 // article fits in viewport OR article is longer than viewport and
778 // its bottom is visible
779
780 if (ctr.scrollTop <= e.offsetTop && e.offsetTop + e.offsetHeight <=
781 ctr.scrollTop + ctr.offsetHeight) {
782
783 // debug(e.id + " is visible " + e.offsetTop + "." +
784 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
785 // (ctr.scrollTop + ctr.offsetHeight));
786
787 ids.push(e.id.replace("RROW-", ""));
788
789 } else if (e.offsetHeight > ctr.offsetHeight &&
790 e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
791 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight) {
792
793 ids.push(e.id.replace("RROW-", ""));
794
795 }
796
797 // method 2: article bottom is visible and is in upper 1/2 of the viewport
798
799 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
800 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
801
802 ids.push(e.id.replace("RROW-", ""));
803
804 } */
805
806 }
807
808 e = e.nextSibling;
809 }
810
811 debug("cdmWatchdog, ids= " + ids.toString());
812
813 if (ids.length > 0 && xmlhttp_ready(xmlhttp_rpc)) {
814
815 for (var i = 0; i < ids.length; i++) {
816 var e = document.getElementById("RROW-" + ids[i]);
817 if (e) {
818 e.className = e.className.replace("Unread", "");
819 }
820 }
821
822 var query = "backend.php?op=rpc&subop=catchupSelected&ids=" +
823 param_escape(ids.toString()) + "&cmode=0";
824
825 xmlhttp_rpc.open("GET", query, true);
826 xmlhttp_rpc.onreadystatechange=all_counters_callback;
827 xmlhttp_rpc.send(null);
828
829 }
830
831 _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 4000);
832
833 } catch (e) {
834 exception_error(e, "cdmWatchdog");
835 }
836
837 }
838
839
840 function cache_inject(id, article) {
841 if (!cache_check(id)) {
842 debug("cache_article: miss: " + id);
843
844 var cache_obj = new Array();
845
846 cache_obj["id"] = id;
847 cache_obj["data"] = article;
848
849 article_cache.push(cache_obj);
850
851 } else {
852 debug("cache_article: hit: " + id);
853 }
854 }
855
856 function cache_find(id) {
857 for (var i = 0; i < article_cache.length; i++) {
858 if (article_cache[i]["id"] == id) {
859 return article_cache[i]["data"];
860 }
861 }
862 return false;
863 }
864
865 function cache_check(id) {
866 for (var i = 0; i < article_cache.length; i++) {
867 if (article_cache[i]["id"] == id) {
868 return true;
869 }
870 }
871 return false;
872 }
873
874 function cache_expire() {
875 while (article_cache.length > 20) {
876 article_cache.shift();
877 }
878 }
879
880 function cache_invalidate(id) {
881 var i = 0
882
883 try {
884
885 while (i < article_cache.length) {
886 if (article_cache[i]["id"] == id) {
887 debug("cache_invalidate: removed id " + id);
888 article_cache.splice(i, 1);
889 return true;
890 }
891 i++;
892 }
893 debug("cache_invalidate: id not found: " + id);
894 return false;
895 } catch (e) {
896 exception_error("cache_invalidate", e);
897 }
898 }