4 * BBS View renderer module for WebCit
6 * Note: we briefly had a dynamic UI for this. I thought it was cool, but
7 * it was not received well by the user community. If you want to play
8 * with it, go get r8256 of bbsview_renderer.c and have fun.
10 * Copyright (c) 1996-2010 by the citadel.org team
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #include "webserver.h"
34 * Data which gets passed around between the various functions in this module
36 * We do this weird "pivot point" thing instead of starting the page numbers at 0 or 1 so that
37 * the border between old and new messages always falls on a page boundary. We'll renumber them
38 * to page numbers starting at 1 when presenting them to the user.
41 long *msgs; /* Array of msgnums for messages we are displaying */
42 int num_msgs; /* Number of msgnums stored in 'msgs' */
43 int alloc_msgs; /* Currently allocated size of array */
44 long pivot_msgnum; /* Page numbers are relative to this message number */
45 int requested_page; /* Which page number did the user request? */
50 * Attempt to determine the closest thing to the "last seen message number" using the
51 * results of the GTSN command
53 long bbsview_get_last_seen(void)
58 serv_getln(buf, sizeof buf);
61 char *comma_pos = strchr(buf, ','); /* kill first comma and everything to its right */
66 char *colon_pos = strchr(buf, ':'); /* kill first colon and everything to its left */
68 strcpy(buf, ++colon_pos);
78 * Entry point for message read operations.
80 int bbsview_GetParamsGetServerCall(SharedMessageStatus *Stat,
86 struct bbsview *BBS = malloc(sizeof(struct bbsview));
87 memset(BBS, 0, sizeof(struct bbsview));
90 Stat->startmsg = -1; /* not used here */
91 Stat->sortit = 1; /* not used here */
92 Stat->num_displayed = DEFAULT_MAXMSGS; /* not used here */
93 BBS->requested_page = 0;
95 if (havebstr("page")) {
96 BBS->requested_page = ibstr("page");
99 if (havebstr("pivot")) {
100 BBS->pivot_msgnum = ibstr("pivot");
102 else if (oper == 2) { /* 2 == "read all" (otherwise we pivot at the beginning of new msgs) */
103 BBS->pivot_msgnum = 0; /* start from the top */
106 BBS->pivot_msgnum = bbsview_get_last_seen();
109 if (havebstr("maxmsgs")) {
110 Stat->maxmsgs = ibstr("maxmsgs");
112 if (Stat->maxmsgs == 0) Stat->maxmsgs = DEFAULT_MAXMSGS;
114 /* perform a "read all" call to fetch the message list -- we'll cut it down later */
115 rlid[2].cmd(cmd, len);
122 * This function is called for every message in the list.
124 int bbsview_LoadMsgFromServer(SharedMessageStatus *Stat,
126 message_summary* Msg,
130 struct bbsview *BBS = (struct bbsview *) *ViewSpecific;
132 if (BBS->alloc_msgs == 0) {
133 BBS->alloc_msgs = 1000;
134 BBS->msgs = malloc(BBS->alloc_msgs * sizeof(long));
137 /* Check our buffer size */
138 if (BBS->num_msgs >= BBS->alloc_msgs) {
139 BBS->alloc_msgs *= 2;
140 BBS->msgs = realloc(BBS->msgs, (BBS->alloc_msgs * sizeof(long)));
143 BBS->msgs[BBS->num_msgs++] = Msg->msgnum;
149 int bbsview_sortfunc(const void *s1, const void *s2) {
156 if (l1 > l2) return(+1);
157 if (l1 < l2) return(-1);
162 int bbsview_RenderView_or_Tail(SharedMessageStatus *Stat,
166 struct bbsview *BBS = (struct bbsview *) *ViewSpecific;
175 /* Cut the message list down to the requested size */
176 if (Stat->nummsgs > 0) {
177 lprintf(9, "sorting %d messages\n", BBS->num_msgs);
178 qsort(BBS->msgs, (size_t)(BBS->num_msgs), sizeof(long), bbsview_sortfunc);
180 /* Cut it down to 20 messages (or whatever value Stat->maxmsgs is set to) */
182 if (BBS->num_msgs > Stat->maxmsgs) {
184 /* Locate the pivot point in our message index */
185 for (i=0; i<(BBS->num_msgs); ++i) {
186 if (BBS->msgs[i] <= BBS->pivot_msgnum) {
191 page_offset = (pivot_index / Stat->maxmsgs) + 2;
196 start_index = pivot_index + (BBS->requested_page * Stat->maxmsgs) ;
197 if (start_index < 0) start_index = 0;
198 end_index = start_index + Stat->maxmsgs - 1;
200 for (seq = 0; seq < 3; ++seq) { /* cheap and sleazy way of rendering the funbar twice */
203 /* display the selected range of messages */
205 if (Stat->nummsgs > 0) {
206 wc_printf("<font size=\"-1\">\n");
207 for (i=start_index; (i<=end_index && i<=BBS->num_msgs); ++i) {
208 if (BBS->msgs[i] > 0L) {
209 read_message(WC->WBuf, HKEY("view_message"), BBS->msgs[i], NULL, &Mime);
212 wc_printf("</font><br>\n");
216 /* Display the range selecto-bar */
218 wc_printf("<div class=\"moreprompt\">");
219 wc_printf(_("Go to page: "));
222 int last = (BBS->num_msgs / Stat->maxmsgs) + 2 ;
224 for (i=1; i<=last; ++i) {
229 || ((i - page_offset) == BBS->requested_page)
231 ((BBS->requested_page - (i - page_offset)) < RANGE)
232 && ((BBS->requested_page - (i - page_offset)) > (0 - RANGE))
238 && (last - (BBS->requested_page + page_offset) > RANGE)
240 wc_printf("... ");
242 if ((i - page_offset) == BBS->requested_page) {
246 wc_printf("<a href=\"readfwd?pivot=%ld?page=%d\">",
250 wc_printf("<span class=\"moreprompt_link\">");
254 && ((BBS->requested_page + page_offset) > (RANGE + 1))
256 wc_printf(_("First"));
260 && (last - (BBS->requested_page + page_offset) > RANGE)
262 wc_printf(_("Last"));
267 if ((i - page_offset) == BBS->requested_page) {
271 wc_printf("</span>");
276 && ((BBS->requested_page + page_offset) > (RANGE + 1))
278 wc_printf(" ...");
285 wc_printf("</div>\n");
293 int bbsview_Cleanup(void **ViewSpecific)
295 struct bbsview *BBS = (struct bbsview *) *ViewSpecific;
297 if (BBS->alloc_msgs != 0) {
308 InitModule_BBSVIEWRENDERERS
311 RegisterReadLoopHandlerset(
313 bbsview_GetParamsGetServerCall,
316 bbsview_LoadMsgFromServer,
317 bbsview_RenderView_or_Tail,