+ int num_blogposts = 0;
+ int with_comments = 0;
+ WCTemplputParams SubTP;
+ WCTemplputParams StopSubTP;
+ blogpost oneBP;
+ long firstPOffset = 0;
+ int count = 0;
+ int totalCount = 0;
+ StrBuf *PrevNext = NULL;
+
+ num_blogposts = GetCount(BL->BLOGPOSTS);
+ if (num_blogposts == 0) {
+ /* Nothing to do... */
+ return 0;
+ }
+ memset(&SubTP, 0, sizeof(WCTemplputParams));
+ memset(&StopSubTP, 0, sizeof(WCTemplputParams));
+ memset(&oneBP, 0, sizeof(blogpost));
+
+ /* Comments are shown if we are only viewing a single blog post */
+ with_comments = (BL->p != 0);
+
+ it = GetNewHashPos(BL->BLOGPOSTS, 0);
+
+ if ((BL->gotonext) && (BL->p == 0)) {
+ /* did we come here via gotonext? lets find out whether
+ * this blog has just one blogpost with new comments just display
+ * this one.
+ */
+ blogpost *unread_bp = NULL;
+ int unread_count = 0;
+ while (GetNextHashPos(BL->BLOGPOSTS, it, &len, &Key, &Data)) {
+ blogpost *one_bp = (blogpost *) Data;
+ if (one_bp->unread_oments > 0) {
+ unread_bp = one_bp;
+ unread_count++;
+ }
+ }
+ if (unread_count == 1) {
+ blogpost_render(unread_bp, 1, NULL);/// TODO other than null?
+
+ DeleteHashPos(&it);
+ return 0;
+ }
+ }
+
+ /* Now we have our array. It is ONLY an array of pointers. The objects to
+ * which they point are still owned by the hash list.
+ */
+
+ /* get it into the right sort of order - blogposts may have been edited */
+ SortByPayload(BL->BLOGPOSTS, blogview_sortfunc);
+
+ /* Find the start post to display: */
+ if (BL->firstp != 0) {
+ /* Translate the firstpost id into an offset */
+ RewindHashPos(BL->BLOGPOSTS, it, 0);
+ while (GetNextHashPos(BL->BLOGPOSTS, it, &len, &Key, &Data)) {
+ thisBlogpost = (blogpost *) Data;
+ if (thisBlogpost->top_level_id == BL->firstp) {
+ firstPOffset = count;
+ break;
+ }
+ count ++;
+ }
+ }
+
+ if ((num_blogposts > BL->maxp) || (firstPOffset != 0)){
+ PrevNext = NewStrBuf();
+ if (firstPOffset > 0) {
+ const char *k;
+ long len;
+ long posPrev = 0;
+ /* we now need to go up to maxp items back */
+ if (firstPOffset > BL->maxp) {
+ posPrev = firstPOffset - BL->maxp;
+ }
+ GetHashAt(BL->BLOGPOSTS, posPrev, &len, &k, &Data);
+ thisBlogpost = (blogpost *) Data;
+ StackContext(NULL, &SubTP, thisBlogpost, CTX_BLOGPOST, 0, NULL);
+ DoTemplate(HKEY("view_blog_newer_posts"), PrevNext, &SubTP);
+ }
+ if (firstPOffset + BL->maxp <= num_blogposts) {
+ const char *k;
+ long len;
+ long posNext = firstPOffset + BL->maxp;
+ GetHashAt(BL->BLOGPOSTS, posNext, &len, &k, &Data);
+ thisBlogpost = (blogpost *) Data;
+ StackContext(NULL, &SubTP, thisBlogpost, CTX_BLOGPOST, 0, NULL);
+ DoTemplate(HKEY("view_blog_older_posts"), PrevNext, &SubTP);