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