+void sitemap_do_blog(void) {
+ wcsession *WCC = WC;
+ blogpost oneBP;
+ int num_msgs = 0;
+ int i;
+ SharedMessageStatus Stat;
+ message_summary *Msg = NULL;
+ StrBuf *Buf = NewStrBuf();
+ StrBuf *FoundCharset = NewStrBuf();
+ WCTemplputParams SubTP;
+
+ memset(&Stat, 0, sizeof Stat);
+ memset(&oneBP, 0, sizeof(blogpost));
+ memset(&SubTP, 0, sizeof(WCTemplputParams));
+ StackContext(NULL, &SubTP, &oneBP, CTX_BLOGPOST, 0, NULL);
+
+ Stat.maxload = INT_MAX;
+ Stat.lowest_found = (-1);
+ Stat.highest_found = (-1);
+ num_msgs = load_msg_ptrs("MSGS ALL", NULL, NULL, &Stat, NULL, NULL, NULL, NULL, 0);
+ if (num_msgs < 1) return;
+
+ for (i=0; i<num_msgs; ++i) {
+ Msg = GetMessagePtrAt(i, WCC->summ);
+ if (Msg != NULL) {
+ ReadOneMessageSummary(Msg, FoundCharset, Buf);
+ /* Show only top level posts, not comments */
+ if ((Msg->reply_inreplyto_hash != 0) && (Msg->reply_references_hash == 0)) {
+ oneBP.top_level_id = Msg->reply_inreplyto_hash;
+ DoTemplate(HKEY("view_blog_sitemap"), WCC->WBuf, &SubTP);
+ }
+ }
+ }
+ UnStackContext(&SubTP);
+ FreeStrBuf(&Buf);
+ FreeStrBuf(&FoundCharset);
+}
+
+
+
+/*
+ * Generate a permalink for a post
+ * (Call with NULL arguments to make this function wcprintf() the permalink
+ * instead of writing it to the template)
+ */
+void tmplput_blog_toplevel_id(StrBuf *Target, WCTemplputParams *TP) {
+ blogpost *bp = (blogpost*) CTX(CTX_BLOGPOST);
+ char buf[SIZ];
+ snprintf(buf, SIZ, "%d", bp->top_level_id);
+ StrBufAppendTemplateStr(Target, TP, buf, 0);
+}
+
+void tmplput_blog_comment_count(StrBuf *Target, WCTemplputParams *TP) {
+ blogpost *bp = (blogpost*) CTX(CTX_BLOGPOST);
+ char buf[SIZ];
+ snprintf(buf, SIZ, "%d", bp->num_msgs -1);
+ StrBufAppendTemplateStr(Target, TP, buf, 0);
+}
+void tmplput_blog_comment_unread_count(StrBuf *Target, WCTemplputParams *TP) {
+ blogpost *bp = (blogpost*) CTX(CTX_BLOGPOST);
+ char buf[SIZ];
+ snprintf(buf, SIZ, "%d", bp->unread_oments);
+ StrBufAppendTemplateStr(Target, TP, buf, 0);
+}
+
+
+
+/*
+ * Render a single blog post and (optionally) its comments
+ */
+void blogpost_render(blogpost *bp, int with_comments, WCTemplputParams *TP)
+{
+ wcsession *WCC = WC;
+ WCTemplputParams SubTP;