2 * Blog view renderer module for WebCit
4 * Copyright (c) 1996-2010 by the citadel.org team
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "webserver.h"
26 * Data which gets passed around between the various functions in this module
30 long *msgs; /* Array of msgnums for messages we are displaying */
31 int num_msgs; /* Number of msgnums stored in 'msgs' */
32 int alloc_msgs; /* Currently allocated size of array */
37 * Entry point for message read operations.
39 int blogview_GetParamsGetServerCall(SharedMessageStatus *Stat,
45 struct blogview *BLOG = malloc(sizeof(struct blogview));
46 memset(BLOG, 0, sizeof(struct blogview));
49 Stat->startmsg = (-1); /* not used here */
50 Stat->sortit = 1; /* not used here */
51 Stat->num_displayed = DEFAULT_MAXMSGS; /* not used here */
52 if (Stat->maxmsgs == 0) Stat->maxmsgs = DEFAULT_MAXMSGS;
54 /* perform a "read all" call to fetch the message list -- we'll cut it down later */
55 rlid[2].cmd(cmd, len);
62 * This function is called for every message in the list.
64 int blogview_LoadMsgFromServer(SharedMessageStatus *Stat,
70 struct blogview *BLOG = (struct blogview *) *ViewSpecific;
72 if (BLOG->alloc_msgs == 0) {
73 BLOG->alloc_msgs = 1000;
74 BLOG->msgs = malloc(BLOG->alloc_msgs * sizeof(long));
75 memset(BLOG->msgs, 0, (BLOG->alloc_msgs * sizeof(long)) );
78 /* Check our buffer size */
79 if (BLOG->num_msgs >= BLOG->alloc_msgs) {
80 BLOG->alloc_msgs *= 2;
81 BLOG->msgs = realloc(BLOG->msgs, (BLOG->alloc_msgs * sizeof(long)));
82 memset(&BLOG->msgs[BLOG->num_msgs], 0, ((BLOG->alloc_msgs - BLOG->num_msgs) * sizeof(long)) );
85 BLOG->msgs[BLOG->num_msgs++] = Msg->msgnum;
92 * People expect blogs to be sorted newest-to-oldest
94 int blogview_sortfunc(const void *s1, const void *s2) {
101 if (l1 > l2) return(-1);
102 if (l1 < l2) return(+1);
107 int blogview_render(SharedMessageStatus *Stat,
111 struct blogview *BLOG = (struct blogview *) *ViewSpecific;
114 wc_printf("<div class=\"fix_scrollbar_bug\">");
116 if (Stat->nummsgs > 0) {
117 lprintf(9, "sorting %d messages\n", BLOG->num_msgs);
118 qsort(BLOG->msgs, (size_t)(BLOG->num_msgs), sizeof(long), blogview_sortfunc);
121 for (i=0; (i<BLOG->num_msgs); ++i) {
122 if (BLOG->msgs[i] > 0L) {
123 wc_printf("<p>Message %d %ld</p>\n", i, BLOG->msgs[i]);
125 /* maybe put some of this into its own function later */
128 serv_printf("MSG0 %ld|1", BLOG->msgs[i]); /* top level citadel headers only */
129 StrBuf_ServGetln(Buf);
130 if (GetServerStatus(Buf, NULL) == 1) {
131 while (StrBuf_ServGetln(Buf), strcmp(ChrPtr(Buf), "000")) {
132 wc_printf("%s<br>\n", ChrPtr(Buf));
139 wc_printf("</div>\n");
144 int blogview_Cleanup(void **ViewSpecific)
146 struct blogview *BLOG = (struct blogview *) *ViewSpecific;
148 if (BLOG->alloc_msgs != 0) {
159 InitModule_BLOGVIEWRENDERERS
162 RegisterReadLoopHandlerset(
164 blogview_GetParamsGetServerCall,
167 blogview_LoadMsgFromServer,