| | @@ -18,21 +18,55 @@ |
| 18 | 18 | ** This file contains code used to generate the user forum. |
| 19 | 19 | */ |
| 20 | 20 | #include "config.h" |
| 21 | 21 | #include <assert.h> |
| 22 | 22 | #include "forum.h" |
| 23 | + |
| 24 | +/* |
| 25 | +** Render a forum post for display |
| 26 | +*/ |
| 27 | +void forum_render(const char *zMimetype, const char *zContent){ |
| 28 | + Blob x; |
| 29 | + blob_init(&x, zContent, -1); |
| 30 | + wiki_render_by_mimetype(&x, zMimetype); |
| 31 | + blob_reset(&x); |
| 32 | +} |
| 23 | 33 | |
| 24 | 34 | /* |
| 25 | 35 | ** Display all posts in a forum thread in chronological order |
| 26 | 36 | */ |
| 27 | 37 | static void forum_thread_chronological(int froot){ |
| 28 | 38 | Stmt q; |
| 29 | | - db_prepare(&q, "SELECT fpid FROM forumpost WHERE froot=%d" |
| 30 | | - " ORDER BY fmtime", froot); |
| 39 | + int i = 0; |
| 40 | + db_prepare(&q, |
| 41 | + "SELECT fpid, fprev, firt, uuid, datetime(fmtime,'unixepoch')\n" |
| 42 | + " FROM forumpost, blob\n" |
| 43 | + " WHERE froot=%d AND rid=fpid\n" |
| 44 | + " ORDER BY fmtime", froot); |
| 31 | 45 | while( db_step(&q)==SQLITE_ROW ){ |
| 32 | 46 | int fpid = db_column_int(&q, 0); |
| 47 | + int fprev = db_column_int(&q, 1); |
| 48 | + int firt = db_column_int(&q, 2); |
| 49 | + const char *zUuid = db_column_text(&q, 3); |
| 50 | + const char *zDate = db_column_text(&q, 4); |
| 33 | 51 | Manifest *pPost = manifest_get(fpid, CFTYPE_FORUM, 0); |
| 52 | + if( i==0 ){ |
| 53 | + @ <hr> |
| 54 | + } |
| 55 | + i++; |
| 56 | + @ <p>%d(fpid) %h(zUuid)<br> |
| 57 | + @ By %h(pPost->zUser) on %h(zDate) |
| 58 | + if( fprev ){ |
| 59 | + @ edit of %d(fprev) %h(pPost->azParent[0]) |
| 60 | + } |
| 61 | + if( firt ){ |
| 62 | + @ in reply to %d(firt) %h(pPost->zInReplyTo) |
| 63 | + } |
| 64 | + if( pPost->zThreadTitle ){ |
| 65 | + @ <h1>%h(pPost->zThreadTitle)</h1> |
| 66 | + } |
| 67 | + forum_render(pPost->zMimetype, pPost->zWiki); |
| 34 | 68 | if( pPost==0 ) continue; |
| 35 | 69 | manifest_destroy(pPost); |
| 36 | 70 | } |
| 37 | 71 | db_finalize(&q); |
| 38 | 72 | } |
| | @@ -86,12 +120,14 @@ |
| 86 | 120 | return !g.perm.WrTForum && !g.perm.ModForum && P("domod")==0; |
| 87 | 121 | } |
| 88 | 122 | |
| 89 | 123 | /* |
| 90 | 124 | ** Add a new Forum Post artifact to the repository. |
| 125 | +** |
| 126 | +** Return true if a redirect occurs. |
| 91 | 127 | */ |
| 92 | | -static void forum_post( |
| 128 | +static int forum_post( |
| 93 | 129 | const char *zTitle, /* Title. NULL for replies */ |
| 94 | 130 | int iInReplyTo, /* Post replying to. 0 for new threads */ |
| 95 | 131 | int iEdit, /* Post being edited, or zero for a new post */ |
| 96 | 132 | const char *zUser, /* Username. NULL means use login name */ |
| 97 | 133 | const char *zMimetype, /* Mimetype of content. */ |
| | @@ -142,26 +178,18 @@ |
| 142 | 178 | blob_appendf(&x, "Z %b\n", &cksum); |
| 143 | 179 | blob_reset(&cksum); |
| 144 | 180 | if( P("dryrun") ){ |
| 145 | 181 | @ <pre>%h(blob_str(&x))</pre><hr> |
| 146 | 182 | }else{ |
| 147 | | - wiki_put(&x, 0, forum_need_moderation()); |
| 148 | | - return; |
| 183 | + int nrid = wiki_put(&x, 0, forum_need_moderation()); |
| 184 | + cgi_redirectf("%R/forumthread/%S", rid_to_uuid(nrid)); |
| 185 | + return 1; |
| 149 | 186 | } |
| 150 | 187 | |
| 151 | 188 | forum_post_error: |
| 152 | 189 | blob_reset(&x); |
| 153 | | -} |
| 154 | | - |
| 155 | | -/* |
| 156 | | -** Render a forum post for display |
| 157 | | -*/ |
| 158 | | -void forum_render(const char *zMimetype, const char *zContent){ |
| 159 | | - Blob x; |
| 160 | | - blob_init(&x, zContent, -1); |
| 161 | | - wiki_render_by_mimetype(&x, zMimetype); |
| 162 | | - blob_reset(&x); |
| 190 | + return 0; |
| 163 | 191 | } |
| 164 | 192 | |
| 165 | 193 | /* |
| 166 | 194 | ** WEBPAGE: forumnew |
| 167 | 195 | ** WEBPAGE: test-forumnew |
| | @@ -178,11 +206,11 @@ |
| 178 | 206 | if( !g.perm.WrForum ){ |
| 179 | 207 | login_needed(g.anon.WrForum); |
| 180 | 208 | return; |
| 181 | 209 | } |
| 182 | 210 | if( P("submit") ){ |
| 183 | | - forum_post(zTitle, 0, 0, 0, zMimetype, zContent); |
| 211 | + if( forum_post(zTitle, 0, 0, 0, zMimetype, zContent) ) return; |
| 184 | 212 | } |
| 185 | 213 | if( P("preview") ){ |
| 186 | 214 | @ <h1>%h(zTitle)</h1> |
| 187 | 215 | forum_render(zMimetype, zContent); |
| 188 | 216 | @ <hr> |
| 189 | 217 | |