+ /* 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);
+ }
+ }
+
+ StrBufAppendBuf(WCC->WBuf, PrevNext, 0);
+ count = totalCount = 0;
+ RewindHashPos(BL->BLOGPOSTS, it, 0);
+
+ /* FIXME -- allow the user (or a default setting) to select a maximum number of posts to display */
+ while (GetNextHashPos(BL->BLOGPOSTS, it, &len, &Key, &Data)) {
+ thisBlogpost = (blogpost *) Data;
+
+ /* allow the user to select a starting point in the list */
+ if (totalCount < firstPOffset) {
+ /* skip all till we found the first valid: */
+ totalCount ++;
+ continue;
+ }
+ if (count >= BL->maxp) {
+ /* enough is enough. */
+ break;
+ }
+ StackContext(NULL, &SubTP, thisBlogpost, CTX_BLOGPOST, 0, NULL);
+ blogpost_render(thisBlogpost, with_comments, &SubTP);
+ UnStackContext(&SubTP);
+ count ++;
+ totalCount ++;
+ }
+ StrBufAppendBuf(WCC->WBuf, PrevNext, 0);
+ FreeStrBuf(&PrevNext);
+ DeleteHashPos(&it);
+