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"
27 * Array type for a blog post. The first message is the post; the rest are comments
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 */
36 * Destructor for 'struct blogpost' which does the rendering first.
37 * By rendering from here, we eliminate the need for a separate iterator.
39 void blogpost_render_and_destroy(struct blogpost *bp) {
40 if (bp->num_msgs > 0) wc_printf("Blog post %ld<br>\n", bp->msgs[0]);
41 if (bp->num_msgs > 1) wc_printf(" <i>%d comments</i><br>\n", bp->num_msgs - 1);
43 if (bp->alloc_msgs > 0) {
52 * Data which gets returned from a call to blogview_learn_thread_references()
61 * Entry point for message read operations.
63 int blogview_GetParamsGetServerCall(SharedMessageStatus *Stat,
69 HashList *BLOG = NewHash(1, NULL);
72 Stat->startmsg = (-1); /* not used here */
73 Stat->sortit = 1; /* not used here */
74 Stat->num_displayed = DEFAULT_MAXMSGS; /* not used here */
75 if (Stat->maxmsgs == 0) Stat->maxmsgs = DEFAULT_MAXMSGS;
77 /* perform a "read all" call to fetch the message list -- we'll cut it down later */
78 rlid[2].cmd(cmd, len);
86 * Given a 'struct blogpost' containing a msgnum, populate the id
87 * and refs fields by fetching them from the Citadel server
89 struct bltr blogview_learn_thread_references(long msgnum)
93 struct bltr bltr = { 0, 0 } ;
96 serv_printf("MSG0 %ld|1", msgnum); /* top level citadel headers only */
97 StrBuf_ServGetln(Buf);
98 if (GetServerStatus(Buf, NULL) == 1) {
99 while (StrBuf_ServGetln(Buf), strcmp(ChrPtr(Buf), "000")) {
100 if (!strncasecmp(ChrPtr(Buf), "msgn=", 5)) {
101 StrBufCutLeft(Buf, 5);
102 bltr.id = HashLittle(ChrPtr(Buf), StrLength(Buf));
104 else if (!strncasecmp(ChrPtr(Buf), "wefw=", 5)) {
105 StrBufCutLeft(Buf, 5); /* trim the field name */
106 StrBufExtract_token(r, Buf, 0, '|');
107 bltr.refs = HashLittle(ChrPtr(r), StrLength(r));
119 * This function is called for every message in the list.
121 int blogview_LoadMsgFromServer(SharedMessageStatus *Stat,
123 message_summary* Msg,
127 HashList *BLOG = (HashList *) *ViewSpecific;
129 struct blogpost *bp = NULL;
131 b = blogview_learn_thread_references(Msg->msgnum);
133 bp = malloc(sizeof(struct blogpost));
134 if (!bp) return(200);
135 memset(bp, 0, sizeof (struct blogpost));
136 Put(BLOG, (const char *)&b.id, sizeof(b.id), bp,
137 (DeleteHashDataFunc)blogpost_render_and_destroy);
140 GetHash(BLOG, (const char *)&b.refs , sizeof(b.refs), (void *)&bp);
144 * Now we have a 'struct blogpost' to which we can add a message. It's either the
145 * blog post itself or a comment attached to it; either way, the code is the same from
149 if (bp->alloc_msgs == 0) {
150 bp->alloc_msgs = 1000;
151 bp->msgs = malloc(bp->alloc_msgs * sizeof(long));
152 memset(bp->msgs, 0, (bp->alloc_msgs * sizeof(long)) );
154 if (bp->num_msgs >= bp->alloc_msgs) {
156 bp->msgs = realloc(bp->msgs, (bp->alloc_msgs * sizeof(long)));
157 memset(&bp->msgs[bp->num_msgs], 0,
158 ((bp->alloc_msgs - bp->num_msgs) * sizeof(long)) );
160 bp->msgs[bp->num_msgs++] = Msg->msgnum;
169 * Sort a list of 'struct blogpost' objects by newest-to-oldest msgnum.
171 int blogview_sortfunc(const void *s1, const void *s2) {
172 long *l1 = (long *)(s1);
173 long *l2 = (long *)(s2);
175 if (*l1 > *l2) return(-1);
176 if (*l1 < *l2) return(+1);
184 int blogview_render(SharedMessageStatus *Stat, void **ViewSpecific, long oper)
186 /*HashList *BLOG = (HashList *) *ViewSpecific;*/
189 * This will require several different modes:
191 * * Single story permalink
200 int blogview_Cleanup(void **ViewSpecific)
202 HashList *BLOG = (HashList *) *ViewSpecific;
212 InitModule_BLOGVIEWRENDERERS
215 RegisterReadLoopHandlerset(
217 blogview_GetParamsGetServerCall,
220 blogview_LoadMsgFromServer,