| ︙ | | | ︙ | |
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
ForumEntry *pFirst; /* First entry in chronological order */
ForumEntry *pLast; /* Last entry in chronological order */
ForumEntry *pDisplay; /* Entries in display order */
ForumEntry *pTail; /* Last on the display list */
int mxIndent; /* Maximum indentation level */
};
#endif /* INTERFACE */
/*
** Delete a complete ForumThread and all its entries.
*/
static void forumthread_delete(ForumThread *pThread){
ForumEntry *pEntry, *pNext;
for(pEntry=pThread->pFirst; pEntry; pEntry = pNext){
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
ForumEntry *pFirst; /* First entry in chronological order */
ForumEntry *pLast; /* Last entry in chronological order */
ForumEntry *pDisplay; /* Entries in display order */
ForumEntry *pTail; /* Last on the display list */
int mxIndent; /* Maximum indentation level */
};
#endif /* INTERFACE */
/*
** Return true if the forum entry with the given rid has been
** subsequently edited.
*/
int forum_rid_has_been_edited(int rid){
static Stmt q;
int res;
db_static_prepare(&q,
"SELECT 1 FROM forumpost A, forumpost B"
" WHERE A.fpid=$rid AND B.froot=A.froot AND B.fprev=$rid"
);
db_bind_int(&q, "$rid", rid);
res = db_step(&q)==SQLITE_ROW;
db_reset(&q);
return res;
}
/*
** Delete a complete ForumThread and all its entries.
*/
static void forumthread_delete(ForumThread *pThread){
ForumEntry *pEntry, *pNext;
for(pEntry=pThread->pFirst; pEntry; pEntry = pNext){
|
| ︙ | | | ︙ | |
137
138
139
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
|
** Construct a ForumThread object given the root record id.
*/
static ForumThread *forumthread_create(int froot, int computeHierarchy){
ForumThread *pThread;
ForumEntry *pEntry;
Stmt q;
int sid = 1;
pThread = fossil_malloc( sizeof(*pThread) );
memset(pThread, 0, sizeof(*pThread));
db_prepare(&q,
"SELECT fpid, firt, fprev, (SELECT uuid FROM blob WHERE rid=fpid)"
" FROM forumpost"
" WHERE froot=%d ORDER BY fmtime",
froot
);
while( db_step(&q)==SQLITE_ROW ){
pEntry = fossil_malloc( sizeof(*pEntry) );
memset(pEntry, 0, sizeof(*pEntry));
pEntry->fpid = db_column_int(&q, 0);
pEntry->firt = db_column_int(&q, 1);
pEntry->fprev = db_column_int(&q, 2);
pEntry->zUuid = fossil_strdup(db_column_text(&q,3));
pEntry->mfirt = pEntry->firt;
pEntry->sid = sid++;
pEntry->pPrev = pThread->pLast;
pEntry->pNext = 0;
if( pThread->pLast==0 ){
pThread->pFirst = pEntry;
}else{
pThread->pLast->pNext = pEntry;
}
pThread->pLast = pEntry;
}
db_finalize(&q);
/* Establish which entries are the latest edit. After this loop
** completes, entries that have non-NULL pLeaf should not be
** displayed.
*/
for(pEntry=pThread->pFirst; pEntry; pEntry=pEntry->pNext){
if( pEntry->fprev ){
|
>
>
>
>
>
>
>
|
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
191
192
193
194
195
196
197
198
199
200
201
|
** Construct a ForumThread object given the root record id.
*/
static ForumThread *forumthread_create(int froot, int computeHierarchy){
ForumThread *pThread;
ForumEntry *pEntry;
Stmt q;
int sid = 1;
Bag seen = Bag_INIT;
pThread = fossil_malloc( sizeof(*pThread) );
memset(pThread, 0, sizeof(*pThread));
db_prepare(&q,
"SELECT fpid, firt, fprev, (SELECT uuid FROM blob WHERE rid=fpid)"
" FROM forumpost"
" WHERE froot=%d ORDER BY fmtime",
froot
);
while( db_step(&q)==SQLITE_ROW ){
pEntry = fossil_malloc( sizeof(*pEntry) );
memset(pEntry, 0, sizeof(*pEntry));
pEntry->fpid = db_column_int(&q, 0);
pEntry->firt = db_column_int(&q, 1);
pEntry->fprev = db_column_int(&q, 2);
pEntry->zUuid = fossil_strdup(db_column_text(&q,3));
pEntry->mfirt = pEntry->firt;
pEntry->sid = sid++;
pEntry->pPrev = pThread->pLast;
pEntry->pNext = 0;
bag_insert(&seen, pEntry->fpid);
if( pThread->pLast==0 ){
pThread->pFirst = pEntry;
}else{
pThread->pLast->pNext = pEntry;
}
if( pEntry->firt && !bag_find(&seen,pEntry->firt) ){
pEntry->firt = froot;
pEntry->mfirt = froot;
}
pThread->pLast = pEntry;
}
db_finalize(&q);
bag_clear(&seen);
/* Establish which entries are the latest edit. After this loop
** completes, entries that have non-NULL pLeaf should not be
** displayed.
*/
for(pEntry=pThread->pFirst; pEntry; pEntry=pEntry->pNext){
if( pEntry->fprev ){
|
| ︙ | | | ︙ | |
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
|
forumentry_add_to_display(pThread, pEntry);
forumthread_display_order(pThread, pEntry);
}
/* Return the result */
return pThread;
}
/*
** COMMAND: test-forumthread
**
** Usage: %fossil test-forumthread THREADID
**
** Display a summary of all messages on a thread.
*/
void forumthread_cmd(void){
int fpid;
int froot;
const char *zName;
ForumThread *pThread;
ForumEntry *p;
db_find_and_open_repository(0,0);
verify_all_options();
if( g.argc!=3 ) usage("THREADID");
zName = g.argv[2];
fpid = symbolic_name_to_rid(zName, "f");
if( fpid<=0 ){
fpid = db_int(0, "SELECT rid FROM blob WHERE rid=%d", atoi(zName));
}
if( fpid<=0 ){
fossil_fatal("Unknown or ambiguous forum id: \"%s\"", zName);
}
froot = db_int(0, "SELECT froot FROM forumpost WHERE fpid=%d", fpid);
if( froot==0 ){
fossil_fatal("Not a forum post: \"%s\"", zName);
}
fossil_print("fpid = %d\n", fpid);
fossil_print("froot = %d\n", froot);
pThread = forumthread_create(froot, 1);
fossil_print("Chronological:\n");
/* 123456789 123456789 123456789 123456789 123456789 123456789 */
fossil_print(" fpid firt fprev mfirt pLeaf nReply\n");
for(p=pThread->pFirst; p; p=p->pNext){
fossil_print("%9d %9d %9d %9d %9d %9d\n",
p->fpid, p->firt, p->fprev, p->mfirt, p->pLeaf ? p->pLeaf->fpid : 0,
p->nReply);
}
fossil_print("\nDisplay\n");
for(p=pThread->pDisplay; p; p=p->pDisplay){
fossil_print("%*s", (p->nIndent-1)*3, "");
if( p->pLeaf ){
fossil_print("%d->%d\n", p->fpid, p->pLeaf->fpid);
}else{
fossil_print("%d\n", p->fpid);
}
}
forumthread_delete(pThread);
}
/*
** Render a forum post for display
*/
void forum_render(
const char *zTitle, /* The title. Might be NULL for no title */
const char *zMimetype, /* Mimetype of the message */
const char *zContent, /* Content of the message */
const char *zClass /* Put in a <div> if not NULL */
){
if( zClass ){
@ <div class='%s(zClass)'>
}
if( zTitle ){
if( zTitle[0] ){
@ <h1>%h(zTitle)</h1>
}else{
@ <h1><i>Deleted</i></h1>
}
}
if( zContent && zContent[0] ){
Blob x;
blob_init(&x, 0, 0);
blob_append(&x, zContent, -1);
wiki_render_by_mimetype(&x, zMimetype);
blob_reset(&x);
}else{
@ <i>Deleted</i>
}
if( zClass ){
@ </div>
}
}
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
>
>
>
>
>
>
>
>
>
|
|
|
|
|
>
>
>
>
>
>
>
|
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
|
forumentry_add_to_display(pThread, pEntry);
forumthread_display_order(pThread, pEntry);
}
/* Return the result */
return pThread;
}
/*
** List all forum threads to standard output.
*/
static void forum_thread_list(void){
Stmt q;
db_prepare(&q,
" SELECT"
" datetime(max(fmtime)),"
" sum(fprev IS NULL),"
" froot"
" FROM forumpost"
" GROUP BY froot"
" ORDER BY 1;"
);
fossil_print(" id cnt most recent post\n");
fossil_print("------ ---- -------------------\n");
while( db_step(&q)==SQLITE_ROW ){
fossil_print("%6d %4d %s\n",
db_column_int(&q, 2),
db_column_int(&q, 1),
db_column_text(&q, 0)
);
}
db_finalize(&q);
}
/*
** COMMAND: test-forumthread
**
** Usage: %fossil test-forumthread [THREADID]
**
** Display a summary of all messages on a thread THREADID. If the
** THREADID argument is omitted, then show a list of all threads.
**
** This command is intended for testing an analysis only.
*/
void forumthread_cmd(void){
int fpid;
int froot;
const char *zName;
ForumThread *pThread;
ForumEntry *p;
db_find_and_open_repository(0,0);
verify_all_options();
if( g.argc==2 ){
forum_thread_list();
return;
}
if( g.argc!=3 ) usage("THREADID");
zName = g.argv[2];
fpid = symbolic_name_to_rid(zName, "f");
if( fpid<=0 ){
fpid = db_int(0, "SELECT rid FROM blob WHERE rid=%d", atoi(zName));
}
if( fpid<=0 ){
fossil_fatal("Unknown or ambiguous forum id: \"%s\"", zName);
}
froot = db_int(0, "SELECT froot FROM forumpost WHERE fpid=%d", fpid);
if( froot==0 ){
fossil_fatal("Not a forum post: \"%s\"", zName);
}
fossil_print("fpid = %d\n", fpid);
fossil_print("froot = %d\n", froot);
pThread = forumthread_create(froot, 1);
fossil_print("Chronological:\n");
fossil_print(
/* 0 1 2 3 4 5 6 7 */
/* 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123 */
" sid fpid firt fprev mfirt pLeaf nReply hash\n");
for(p=pThread->pFirst; p; p=p->pNext){
fossil_print("%4d %9d %9d %9d %9d %9d %6d %8.8s\n", p->sid,
p->fpid, p->firt, p->fprev, p->mfirt, p->pLeaf ? p->pLeaf->fpid : 0,
p->nReply, p->zUuid);
}
fossil_print("\nDisplay\n");
for(p=pThread->pDisplay; p; p=p->pDisplay){
fossil_print("%*s", (p->nIndent-1)*3, "");
if( p->pLeaf ){
fossil_print("%d->%d\n", p->fpid, p->pLeaf->fpid);
}else{
fossil_print("%d\n", p->fpid);
}
}
forumthread_delete(pThread);
}
/*
** Render a forum post for display
*/
void forum_render(
const char *zTitle, /* The title. Might be NULL for no title */
const char *zMimetype, /* Mimetype of the message */
const char *zContent, /* Content of the message */
const char *zClass, /* Put in a <div> if not NULL */
int bScroll /* Large message content scrolls if true */
){
if( zClass ){
@ <div class='%s(zClass)'>
}
if( zTitle ){
if( zTitle[0] ){
@ <h1>%h(zTitle)</h1>
}else{
@ <h1><i>Deleted</i></h1>
}
}
if( zContent && zContent[0] ){
Blob x;
if( bScroll ){
@ <div class='forumPostBody'>
}else{
@ <div class='forumPostFullBody'>
}
blob_init(&x, 0, 0);
blob_append(&x, zContent, -1);
wiki_render_by_mimetype(&x, zMimetype);
blob_reset(&x);
@ </div>
}else{
@ <i>Deleted</i>
}
if( zClass ){
@ </div>
}
}
|
| ︙ | | | ︙ | |
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
|
@ <br>
@ <label><input type="checkbox" name="trust">
@ Trust user "%h(pPost->zUser)"
@ so that future posts by "%h(pPost->zUser)" do not require moderation.
@ </label>
@ <input type="hidden" name="trustuser" value="%h(pPost->zUser)">
}
/*
** Display all posts in a forum thread in chronological order
*/
static void forum_display_chronological(int froot, int target){
ForumThread *pThread = forumthread_create(froot, 0);
ForumEntry *p;
int notAnon = login_is_individual();
for(p=pThread->pFirst; p; p=p->pNext){
char *zDate;
Manifest *pPost;
int isPrivate; /* True for posts awaiting moderation */
int sameUser; /* True if author is also the reader */
pPost = manifest_get(p->fpid, CFTYPE_FORUM, 0);
if( pPost==0 ) continue;
if( p->fpid==target ){
@ <div id="forum%d(p->fpid)" class="forumTime forumSel">
}else if( p->pLeaf!=0 ){
@ <div id="forum%d(p->fpid)" class="forumTime forumObs">
}else{
@ <div id="forum%d(p->fpid)" class="forumTime">
}
if( pPost->zThreadTitle ){
@ <h1>%h(pPost->zThreadTitle)</h1>
}
zDate = db_text(0, "SELECT datetime(%.17g)", pPost->rDate);
@ <p>(%d(p->sid)) By %h(pPost->zUser) on %h(zDate)
fossil_free(zDate);
if( p->pEdit ){
@ edit of %z(href("%R/forumpost/%S?t=c",p->pEdit->zUuid))\
@ %d(p->pEdit->sid)</a>
}
if( g.perm.Debug ){
@ <span class="debug">\
@ <a href="%R/artifact/%h(p->zUuid)">(artifact)</a></span>
}
if( p->firt ){
ForumEntry *pIrt = p->pPrev;
while( pIrt && pIrt->fpid!=p->firt ) pIrt = pIrt->pPrev;
if( pIrt ){
@ in reply to %z(href("%R/forumpost/%S?t=c",pIrt->zUuid))\
@ %d(pIrt->sid)</a>
}
}
if( p->pLeaf ){
@ updated by %z(href("%R/forumpost/%S?t=c",p->pLeaf->zUuid))\
@ %d(p->pLeaf->sid)</a>
}
if( p->fpid!=target ){
@ %z(href("%R/forumpost/%S?t=c",p->zUuid))[link]</a>
}
isPrivate = content_is_private(p->fpid);
sameUser = notAnon && fossil_strcmp(pPost->zUser, g.zLogin)==0;
if( isPrivate && !g.perm.ModForum && !sameUser ){
@ <p><span class="modpending">Awaiting Moderator Approval</span></p>
}else{
forum_render(0, pPost->zMimetype, pPost->zWiki, 0);
}
if( g.perm.WrForum && p->pLeaf==0 ){
int sameUser = login_is_individual()
&& fossil_strcmp(pPost->zUser, g.zLogin)==0;
@ <p><form action="%R/forumedit" method="POST">
@ <input type="hidden" name="fpid" value="%s(p->zUuid)">
if( !isPrivate ){
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
|
>
>
>
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
<
<
|
|
>
|
>
|
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
|
@ <br>
@ <label><input type="checkbox" name="trust">
@ Trust user "%h(pPost->zUser)"
@ so that future posts by "%h(pPost->zUser)" do not require moderation.
@ </label>
@ <input type="hidden" name="trustuser" value="%h(pPost->zUser)">
}
/*
** Compute a display name from a login name.
**
** If the input login is found in the USER table, then check the USER.INFO
** field to see if it has display-name followed by an email address.
** If it does, that becomes the new display name. If not, let the display
** name just be the login.
**
** Space to hold the returned name is obtained from fossil_strdup() or
** mprintf() and should be freed by the caller.
*/
char *display_name_from_login(const char *zLogin){
static Stmt q;
char *zResult;
db_static_prepare(&q,
"SELECT display_name(info) FROM user WHERE login=$login"
);
db_bind_text(&q, "$login", zLogin);
if( db_step(&q)==SQLITE_ROW && db_column_type(&q,0)==SQLITE_TEXT ){
const char *zDisplay = db_column_text(&q,0);
if( fossil_strcmp(zDisplay,zLogin)==0 ){
zResult = fossil_strdup(zLogin);
}else{
zResult = mprintf("%s (%s)", zDisplay, zLogin);
}
}else{
zResult = fossil_strdup(zLogin);
}
db_reset(&q);
return zResult;
}
/*
** Display all posts in a forum thread in chronological order
*/
static void forum_display_chronological(int froot, int target, int bRawMode){
ForumThread *pThread = forumthread_create(froot, 0);
ForumEntry *p;
int notAnon = login_is_individual();
char cMode = bRawMode ? 'r' : 'c';
for(p=pThread->pFirst; p; p=p->pNext){
char *zDate;
Manifest *pPost;
int isPrivate; /* True for posts awaiting moderation */
int sameUser; /* True if author is also the reader */
const char *zUuid;
char *zDisplayName; /* The display name */
int sid;
pPost = manifest_get(p->fpid, CFTYPE_FORUM, 0);
if( pPost==0 ) continue;
if( p->fpid==target ){
@ <div id="forum%d(p->fpid)" class="forumTime forumSel">
}else if( p->pLeaf!=0 ){
@ <div id="forum%d(p->fpid)" class="forumTime forumObs">
}else{
@ <div id="forum%d(p->fpid)" class="forumTime">
}
if( pPost->zThreadTitle ){
@ <h1>%h(pPost->zThreadTitle)</h1>
}
zDate = db_text(0, "SELECT datetime(%.17g)", pPost->rDate);
zDisplayName = display_name_from_login(pPost->zUser);
sid = p->pEdit ? p->pEdit->sid : p->sid;
@ <h3 class='forumPostHdr'>(%d(sid)) By %h(zDisplayName) on %h(zDate)
fossil_free(zDisplayName);
fossil_free(zDate);
if( p->pEdit ){
@ edit of %z(href("%R/forumpost/%S?t=%c",p->pEdit->zUuid,cMode))\
@ %d(p->pEdit->sid)</a>
}
if( g.perm.Debug ){
@ <span class="debug">\
@ <a href="%R/artifact/%h(p->zUuid)">(artifact-%d(p->fpid))</a></span>
}
if( p->firt ){
ForumEntry *pIrt = p->pPrev;
while( pIrt && pIrt->fpid!=p->firt ) pIrt = pIrt->pPrev;
if( pIrt ){
@ in reply to %z(href("%R/forumpost/%S?t=%c",pIrt->zUuid,cMode))\
@ %d(pIrt->sid)</a>
}
}
zUuid = p->zUuid;
if( p->pLeaf ){
@ updated by %z(href("%R/forumpost/%S?t=%c",p->pLeaf->zUuid,cMode))\
@ %d(p->pLeaf->sid)</a>
zUuid = p->pLeaf->zUuid;
}
if( p->fpid!=target ){
@ %z(href("%R/forumpost/%S?t=%c",zUuid,cMode))[link]</a>
}
if( !bRawMode ){
@ %z(href("%R/forumpost/%S?raw",zUuid))[source]</a>
}
isPrivate = content_is_private(p->fpid);
sameUser = notAnon && fossil_strcmp(pPost->zUser, g.zLogin)==0;
@ </h3>
if( isPrivate && !g.perm.ModForum && !sameUser ){
@ <p><span class="modpending">Awaiting Moderator Approval</span></p>
}else{
const char *zMimetype;
if( bRawMode ){
zMimetype = "text/plain";
}else if( p->pLeaf!=0 ){
zMimetype = "text/plain";
}else{
zMimetype = pPost->zMimetype;
}
forum_render(0, zMimetype, pPost->zWiki, 0, 1);
}
if( g.perm.WrForum && p->pLeaf==0 ){
int sameUser = login_is_individual()
&& fossil_strcmp(pPost->zUser, g.zLogin)==0;
@ <p><form action="%R/forumedit" method="POST">
@ <input type="hidden" name="fpid" value="%s(p->zUuid)">
if( !isPrivate ){
/* Reply and Edit are only available if the post has already
** been approved */
@ <input type="submit" name="reply" value="Reply">
if( g.perm.Admin || sameUser ){
@ <input type="submit" name="edit" value="Edit">
@ <input type="submit" name="nullout" value="Delete">
}
}else if( g.perm.ModForum ){
/* Provide moderators with moderation buttons for posts that
** are pending moderation */
@ <input type="submit" name="approve" value="Approve">
@ <input type="submit" name="reject" value="Reject">
generateTrustControls(pPost);
}else if( sameUser ){
/* A post that is pending moderation can be deleted by the
** person who originally submitted the post */
@ <input type="submit" name="reject" value="Delete">
}
@ </form></p>
}
manifest_destroy(pPost);
@ </div>
}
/* Undocumented "threadtable" query parameter causes thread table
** to be displayed for debugging purposes.
*/
if( PB("threadtable") ){
@ <hr>
@ <table border="1" cellpadding="3" cellspacing="0">
@ <tr><th>sid<th>fpid<th>firt<th>fprev<th>mfirt<th>pLeaf<th>nReply<th>hash
for(p=pThread->pFirst; p; p=p->pNext){
@ <tr><td>%d(p->sid)<td>%d(p->fpid)<td>%d(p->firt)\
@ <td>%d(p->fprev)<td>%d(p->mfirt)\
@ <td>%d(p->pLeaf?p->pLeaf->fpid:0)<td>%d(p->nReply)\
@ <td>%S(p->zUuid)</tr>
}
@ </table>
}
forumthread_delete(pThread);
}
/*
** Display all the edit history of post "target".
*/
static void forum_display_history(int froot, int target, int bRawMode){
ForumThread *pThread = forumthread_create(froot, 0);
ForumEntry *p;
int notAnon = login_is_individual();
char cMode = bRawMode ? 'r' : 'c';
ForumEntry *pLeaf = 0;
int cnt = 0;
for(p=pThread->pFirst; p; p=p->pNext){
if( p->fpid==target ){
pLeaf = p->pLeaf ? p->pLeaf : p;
break;
}
}
for(p=pThread->pFirst; p; p=p->pNext){
char *zDate;
Manifest *pPost;
int isPrivate; /* True for posts awaiting moderation */
int sameUser; /* True if author is also the reader */
const char *zUuid;
char *zDisplayName; /* The display name */
if( p->fpid!=pLeaf->fpid && p->pLeaf!=pLeaf ) continue;
cnt++;
pPost = manifest_get(p->fpid, CFTYPE_FORUM, 0);
if( pPost==0 ) continue;
@ <div id="forum%d(p->fpid)" class="forumTime">
zDate = db_text(0, "SELECT datetime(%.17g)", pPost->rDate);
zDisplayName = display_name_from_login(pPost->zUser);
@ <h3 class='forumPostHdr'>(%d(p->sid)) By %h(zDisplayName) on %h(zDate)
fossil_free(zDisplayName);
fossil_free(zDate);
if( g.perm.Debug ){
@ <span class="debug">\
@ <a href="%R/artifact/%h(p->zUuid)">(artifact-%d(p->fpid))</a></span>
}
if( p->firt && cnt==1 ){
ForumEntry *pIrt = p->pPrev;
while( pIrt && pIrt->fpid!=p->firt ) pIrt = pIrt->pPrev;
if( pIrt ){
@ in reply to %z(href("%R/forumpost/%S?t=%c",pIrt->zUuid,cMode))\
@ %d(pIrt->sid)</a>
}
}
zUuid = p->zUuid;
@ %z(href("%R/forumpost/%S?t=c",zUuid))[link]</a>
if( !bRawMode ){
@ %z(href("%R/forumpost/%S?raw",zUuid))[source]</a>
}
isPrivate = content_is_private(p->fpid);
sameUser = notAnon && fossil_strcmp(pPost->zUser, g.zLogin)==0;
@ </h3>
if( isPrivate && !g.perm.ModForum && !sameUser ){
@ <p><span class="modpending">Awaiting Moderator Approval</span></p>
}else{
forum_render(0, bRawMode?"text/plain":pPost->zMimetype, pPost->zWiki,
0, 1);
}
if( g.perm.WrForum && p->pLeaf==0 ){
int sameUser = login_is_individual()
&& fossil_strcmp(pPost->zUser, g.zLogin)==0;
@ <p><form action="%R/forumedit" method="POST">
@ <input type="hidden" name="fpid" value="%s(p->zUuid)">
if( !isPrivate ){
|
| ︙ | | | ︙ | |
419
420
421
422
423
424
425
426
427
428
429
430
431
432
|
}
while( iIndentScale>1 && iIndentScale*pThread->mxIndent>25 ){
iIndentScale--;
}
for(p=pThread->pDisplay; p; p=p->pDisplay){
int isPrivate; /* True for posts awaiting moderation */
int sameUser; /* True if reader is also the poster */
pOPost = manifest_get(p->fpid, CFTYPE_FORUM, 0);
if( p->pLeaf ){
fpid = p->pLeaf->fpid;
zUuid = p->pLeaf->zUuid;
pPost = manifest_get(fpid, CFTYPE_FORUM, 0);
}else{
fpid = p->fpid;
|
>
|
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
|
}
while( iIndentScale>1 && iIndentScale*pThread->mxIndent>25 ){
iIndentScale--;
}
for(p=pThread->pDisplay; p; p=p->pDisplay){
int isPrivate; /* True for posts awaiting moderation */
int sameUser; /* True if reader is also the poster */
char *zDisplayName; /* User name to be displayed */
pOPost = manifest_get(p->fpid, CFTYPE_FORUM, 0);
if( p->pLeaf ){
fpid = p->pLeaf->fpid;
zUuid = p->pLeaf->zUuid;
pPost = manifest_get(fpid, CFTYPE_FORUM, 0);
}else{
fpid = p->fpid;
|
| ︙ | | | ︙ | |
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
|
}
pPost = manifest_get(fpid, CFTYPE_FORUM, 0);
if( pPost==0 ) continue;
if( pPost->zThreadTitle ){
@ <h1>%h(pPost->zThreadTitle)</h1>
}
zDate = db_text(0, "SELECT datetime(%.17g)", pOPost->rDate);
@ <p>(%d(p->pLeaf?p->pLeaf->sid:p->sid)) By %h(pOPost->zUser) on %h(zDate)
fossil_free(zDate);
if( g.perm.Debug ){
@ <span class="debug">\
@ <a href="%R/artifact/%h(p->zUuid)">(artifact)</a></span>
}
if( p->pLeaf ){
zDate = db_text(0, "SELECT datetime(%.17g)", pPost->rDate);
if( fossil_strcmp(pOPost->zUser,pPost->zUser)==0 ){
@ and edited on %h(zDate)
}else{
@ as edited by %h(pPost->zUser) on %h(zDate)
}
fossil_free(zDate);
if( g.perm.Debug ){
@ <span class="debug">\
@ <a href="%R/artifact/%h(p->pLeaf->zUuid)">(artifact)</a></span>
}
manifest_destroy(pOPost);
}
if( fpid!=target ){
@ %z(href("%R/forumpost/%S",zUuid))[link]</a>
}
if( p->firt ){
ForumEntry *pIrt = p->pPrev;
while( pIrt && pIrt->fpid!=p->firt ) pIrt = pIrt->pPrev;
if( pIrt ){
@ in reply to %z(href("%R/forumpost/%S?t=h",pIrt->zUuid))\
@ %d(pIrt->sid)</a>
}
}
isPrivate = content_is_private(fpid);
sameUser = notAnon && fossil_strcmp(pPost->zUser, g.zLogin)==0;
if( isPrivate && !g.perm.ModForum && !sameUser ){
@ <p><span class="modpending">Awaiting Moderator Approval</span></p>
}else{
forum_render(0, pPost->zMimetype, pPost->zWiki, 0);
}
if( g.perm.WrForum ){
@ <p><form action="%R/forumedit" method="POST">
@ <input type="hidden" name="fpid" value="%s(zUuid)">
if( !isPrivate ){
/* Reply and Edit are only available if the post has already
** been approved */
|
>
>
|
>
|
|
>
>
>
|
>
|
|
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
|
}
pPost = manifest_get(fpid, CFTYPE_FORUM, 0);
if( pPost==0 ) continue;
if( pPost->zThreadTitle ){
@ <h1>%h(pPost->zThreadTitle)</h1>
}
zDate = db_text(0, "SELECT datetime(%.17g)", pOPost->rDate);
zDisplayName = display_name_from_login(pOPost->zUser);
@ <h3 class='forumPostHdr'>\
@ (%d(p->sid)) By %h(zDisplayName) on %h(zDate)
fossil_free(zDisplayName);
fossil_free(zDate);
if( g.perm.Debug ){
@ <span class="debug">\
@ <a href="%R/artifact/%h(p->zUuid)">(artifact-%d(p->fpid))</a></span>
}
if( p->pLeaf ){
zDate = db_text(0, "SELECT datetime(%.17g)", pPost->rDate);
if( fossil_strcmp(pOPost->zUser,pPost->zUser)==0 ){
@ and edited on %h(zDate)
}else{
@ as edited by %h(pPost->zUser) on %h(zDate)
}
fossil_free(zDate);
if( g.perm.Debug ){
@ <span class="debug">\
@ <a href="%R/artifact/%h(p->pLeaf->zUuid)">\
@ (artifact-%d(p->pLeaf->fpid))</a></span>
}
@ %z(href("%R/forumpost/%S?t=y",p->zUuid))[history]</a>
manifest_destroy(pOPost);
}
if( fpid!=target ){
@ %z(href("%R/forumpost/%S",zUuid))[link]</a>
}
@ %z(href("%R/forumpost/%S?raw",zUuid))[source]</a>
if( p->firt ){
ForumEntry *pIrt = p->pPrev;
while( pIrt && pIrt->fpid!=p->mfirt ) pIrt = pIrt->pPrev;
if( pIrt ){
@ in reply to %z(href("%R/forumpost/%S?t=h",pIrt->zUuid))\
@ %d(pIrt->sid)</a>
}
}
@ </h3>
isPrivate = content_is_private(fpid);
sameUser = notAnon && fossil_strcmp(pPost->zUser, g.zLogin)==0;
if( isPrivate && !g.perm.ModForum && !sameUser ){
@ <p><span class="modpending">Awaiting Moderator Approval</span></p>
}else{
forum_render(0, pPost->zMimetype, pPost->zWiki, 0, 1);
}
if( g.perm.WrForum ){
@ <p><form action="%R/forumedit" method="POST">
@ <input type="hidden" name="fpid" value="%s(zUuid)">
if( !isPrivate ){
/* Reply and Edit are only available if the post has already
** been approved */
|
| ︙ | | | ︙ | |
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
|
** it's entire thread. The selected posting is enclosed within
** <div class='forumSel'>...</div>. Javascript is used to move the
** selected posting into view after the page loads.
**
** Query parameters:
**
** name=X REQUIRED. The hash of the post to display
** t=MODE Display mode. MODE is 'c' for chronological or
** 'h' for hierarchical, or 'a' for automatic.
*/
void forumpost_page(void){
forumthread_page();
}
/*
** WEBPAGE: forumthread
**
** Show all forum messages associated with a particular message thread.
** The result is basically the same as /forumpost except that none of
** the postings in the thread are selected.
**
** Query parameters:
**
** name=X REQUIRED. The hash of any post of the thread.
** t=MODE Display mode. MODE is 'c' for chronological or
** 'h' for hierarchical, or 'a' for automatic.
*/
void forumthread_page(void){
int fpid;
int froot;
const char *zName = P("name");
const char *zMode = PD("t","a");
login_check_credentials();
if( !g.perm.RdForum ){
login_needed(g.anon.RdForum);
return;
}
if( zName==0 ){
webpage_error("Missing \"name=\" query parameter");
}
fpid = symbolic_name_to_rid(zName, "f");
if( fpid<=0 ){
webpage_error("Unknown or ambiguous forum id: \"%s\"", zName);
}
style_header("Forum");
froot = db_int(0, "SELECT froot FROM forumpost WHERE fpid=%d", fpid);
if( froot==0 ){
webpage_error("Not a forum post: \"%s\"", zName);
}
if( fossil_strcmp(g.zPath,"forumthread")==0 ) fpid = 0;
if( zMode[0]=='a' ){
if( cgi_from_mobile() ){
zMode = "c"; /* Default to chronological on mobile */
}else{
zMode = "h";
}
}
if( zMode[0]=='c' ){
style_submenu_element("Hierarchical", "%R/%s/%s?t=h", g.zPath, zName);
forum_display_chronological(froot, fpid);
}else{
style_submenu_element("Chronological", "%R/%s/%s?t=c", g.zPath, zName);
forum_display_hierarchical(froot, fpid);
}
style_load_js("forum.js");
style_footer();
}
/*
** Return true if a forum post should be moderated.
*/
static int forum_need_moderation(void){
if( P("domod") ) return 1;
if( g.perm.WrTForum ) return 0;
if( g.perm.ModForum ) return 0;
return 1;
}
/*
** 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 */
){
char *zDate;
char *zI;
char *zG;
int iBasis;
Blob x, cksum, formatCheck, errMsg;
Manifest *pPost;
schema_forum();
if( iInReplyTo==0 && iEdit>0 ){
iBasis = iEdit;
iInReplyTo = db_int(0, "SELECT firt FROM forumpost WHERE fpid=%d", iEdit);
}else{
iBasis = iInReplyTo;
}
webpage_assert( (zTitle==0)+(iInReplyTo==0)==1 );
|
|
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
|
>
>
>
>
>
<
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
|
** it's entire thread. The selected posting is enclosed within
** <div class='forumSel'>...</div>. Javascript is used to move the
** selected posting into view after the page loads.
**
** Query parameters:
**
** name=X REQUIRED. The hash of the post to display
** t=MODE Display mode.
** 'c' for chronological
** 'h' for hierarchical
** 'a' for automatic
** 'r' for raw
** 'y' for history of post X only
** raw If present, show only the post specified and
** show its original unformatted source text.
*/
void forumpost_page(void){
forumthread_page();
}
/*
** Add an appropriate style_header() to include title of the
** given forum post.
*/
static int forumthread_page_header(int froot, int fpid){
char *zThreadTitle = 0;
zThreadTitle = db_text("",
"SELECT"
" substr(event.comment,instr(event.comment,':')+2)"
" FROM forumpost, event"
" WHERE event.objid=forumpost.fpid"
" AND forumpost.fpid=%d;",
fpid
);
style_header("%s%s", zThreadTitle, zThreadTitle[0] ? "" : "Forum");
fossil_free(zThreadTitle);
return 0;
}
/*
** WEBPAGE: forumthread
**
** Show all forum messages associated with a particular message thread.
** The result is basically the same as /forumpost except that none of
** the postings in the thread are selected.
**
** Query parameters:
**
** name=X REQUIRED. The hash of any post of the thread.
** t=MODE Display mode. MODE is...
** 'c' for chronological, or
** 'h' for hierarchical, or
** 'a' for automatic, or
** 'r' for raw.
** raw Show only the post given by name= and show it unformatted
** hist Show only the edit history for the name= post
*/
void forumthread_page(void){
int fpid;
int froot;
const char *zName = P("name");
const char *zMode = PD("t","a");
int bRaw = PB("raw");
login_check_credentials();
if( !g.perm.RdForum ){
login_needed(g.anon.RdForum);
return;
}
if( zName==0 ){
webpage_error("Missing \"name=\" query parameter");
}
fpid = symbolic_name_to_rid(zName, "f");
if( fpid<=0 ){
webpage_error("Unknown or ambiguous forum id: \"%s\"", zName);
}
froot = db_int(0, "SELECT froot FROM forumpost WHERE fpid=%d", fpid);
if( froot==0 ){
webpage_error("Not a forum post: \"%s\"", zName);
}
if( fossil_strcmp(g.zPath,"forumthread")==0 ) fpid = 0;
if( zMode[0]=='a' ){
if( cgi_from_mobile() ){
zMode = "c"; /* Default to chronological on mobile */
}else{
zMode = "h";
}
}
if( zMode[0]!='y' ){
forumthread_page_header(froot, fpid);
}
if( bRaw && fpid ){
Manifest *pPost;
pPost = manifest_get(fpid, CFTYPE_FORUM, 0);
if( pPost==0 ){
@ <p>No such forum post: %h(zName)
}else{
int isPrivate = content_is_private(fpid);
int notAnon = login_is_individual();
int sameUser = notAnon && fossil_strcmp(pPost->zUser, g.zLogin)==0;
if( isPrivate && !g.perm.ModForum && !sameUser ){
@ <p><span class="modpending">Awaiting Moderator Approval</span></p>
}else{
forum_render(0, "text/plain", pPost->zWiki, 0, 0);
}
manifest_destroy(pPost);
}
}else if( zMode[0]=='c' ){
style_submenu_element("Hierarchical", "%R/%s/%s?t=h", g.zPath, zName);
style_submenu_element("Unformatted", "%R/%s/%s?t=r", g.zPath, zName);
forum_display_chronological(froot, fpid, 0);
}else if( zMode[0]=='r' ){
style_submenu_element("Chronological", "%R/%s/%s?t=c", g.zPath, zName);
style_submenu_element("Hierarchical", "%R/%s/%s?t=h", g.zPath, zName);
forum_display_chronological(froot, fpid, 1);
}else if( zMode[0]=='y' ){
style_header("Edit History Of A Forum Post");
style_submenu_element("Complete Thread", "%R/%s/%s?t=a", g.zPath, zName);
forum_display_history(froot, fpid, 1);
}else{
style_submenu_element("Chronological", "%R/%s/%s?t=c", g.zPath, zName);
style_submenu_element("Unformatted", "%R/%s/%s?t=r", g.zPath, zName);
forum_display_hierarchical(froot, fpid);
}
style_load_js("forum.js");
style_footer();
}
/*
** Return true if a forum post should be moderated.
*/
static int forum_need_moderation(void){
if( P("domod") ) return 1;
if( g.perm.WrTForum ) return 0;
if( g.perm.ModForum ) return 0;
return 1;
}
/*
** Return true if the string is white-space only.
*/
static int whitespace_only(const char *z){
if( z==0 ) return 1;
while( z[0] && fossil_isspace(z[0]) ){ z++; }
return z[0]==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 */
){
char *zDate;
char *zI;
char *zG;
int iBasis;
Blob x, cksum, formatCheck, errMsg;
Manifest *pPost;
int nContent = zContent ? (int)strlen(zContent) : 0;
schema_forum();
if( iEdit==0 && whitespace_only(zContent) ){
return 0;
}
if( iInReplyTo==0 && iEdit>0 ){
iBasis = iEdit;
iInReplyTo = db_int(0, "SELECT firt FROM forumpost WHERE fpid=%d", iEdit);
}else{
iBasis = iInReplyTo;
}
webpage_assert( (zTitle==0)+(iInReplyTo==0)==1 );
|
| ︙ | | | ︙ | |
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
|
if( login_is_nobody() ){
zUser = "anonymous";
}else{
zUser = login_name();
}
}
blob_appendf(&x, "U %F\n", zUser);
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);
/* Verify that the artifact we are creating is well-formed */
blob_init(&formatCheck, 0, 0);
blob_init(&errMsg, 0, 0);
|
|
|
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
|
if( login_is_nobody() ){
zUser = "anonymous";
}else{
zUser = login_name();
}
}
blob_appendf(&x, "U %F\n", zUser);
blob_appendf(&x, "W %d\n%s\n", nContent, zContent);
md5sum_blob(&x, &cksum);
blob_appendf(&x, "Z %b\n", &cksum);
blob_reset(&cksum);
/* Verify that the artifact we are creating is well-formed */
blob_init(&formatCheck, 0, 0);
blob_init(&errMsg, 0, 0);
|
| ︙ | | | ︙ | |
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
|
*/
static void forum_entry_widget(
const char *zTitle,
const char *zMimetype,
const char *zContent
){
if( zTitle ){
@ Title: <input type="input" name="title" value="%h(zTitle)" size="50"><br>
}
@ %z(href("%R/markup_help"))Markup style</a>:
mimetype_option_menu(zMimetype);
@ <br><textarea name="content" class="wikiedit" cols="80" \
@ rows="25" wrap="virtual">%h(zContent)</textarea><br>
}
|
|
>
|
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
|
*/
static void forum_entry_widget(
const char *zTitle,
const char *zMimetype,
const char *zContent
){
if( zTitle ){
@ Title: <input type="input" name="title" value="%h(zTitle)" size="50"
@ maxlength="125"><br>
}
@ %z(href("%R/markup_help"))Markup style</a>:
mimetype_option_menu(zMimetype);
@ <br><textarea name="content" class="wikiedit" cols="80" \
@ rows="25" wrap="virtual">%h(zContent)</textarea><br>
}
|
| ︙ | | | ︙ | |
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
|
const char *zMimetype = PD("mimetype",DEFAULT_FORUM_MIMETYPE);
const char *zContent = PDT("content","");
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>Preview:</h1>
forum_render(zTitle, zMimetype, zContent, "forumEdit");
}
style_header("New Forum Thread");
@ <form action="%R/forume1" method="POST">
@ <h1>New Thread:</h1>
forum_from_line();
forum_entry_widget(zTitle, zMimetype, zContent);
@ <input type="submit" name="preview" value="Preview">
if( P("preview") ){
@ <input type="submit" name="submit" value="Submit">
}else{
@ <input type="submit" name="submit" value="Submit" disabled>
}
if( g.perm.Debug ){
/* For the test-forumnew page add these extra debugging controls */
@ <div class="debug">
|
|
|
|
|
|
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
|
const char *zMimetype = PD("mimetype",DEFAULT_FORUM_MIMETYPE);
const char *zContent = PDT("content","");
login_check_credentials();
if( !g.perm.WrForum ){
login_needed(g.anon.WrForum);
return;
}
if( P("submit") && cgi_csrf_safe(1) ){
if( forum_post(zTitle, 0, 0, 0, zMimetype, zContent) ) return;
}
if( P("preview") && !whitespace_only(zContent) ){
@ <h1>Preview:</h1>
forum_render(zTitle, zMimetype, zContent, "forumEdit", 1);
}
style_header("New Forum Thread");
@ <form action="%R/forume1" method="POST">
@ <h1>New Thread:</h1>
forum_from_line();
forum_entry_widget(zTitle, zMimetype, zContent);
@ <input type="submit" name="preview" value="Preview">
if( P("preview") && !whitespace_only(zContent) ){
@ <input type="submit" name="submit" value="Submit">
}else{
@ <input type="submit" name="submit" value="Submit" disabled>
}
if( g.perm.Debug ){
/* For the test-forumnew page add these extra debugging controls */
@ <div class="debug">
|
| ︙ | | | ︙ | |
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
|
cgi_redirectf("%R/forumpost/%S",P("fpid"));
return;
}
isCsrfSafe = cgi_csrf_safe(1);
if( g.perm.ModForum && isCsrfSafe ){
if( P("approve") ){
const char *zUserToTrust;
moderation_approve(fpid);
if( g.perm.AdminForum
&& PB("trust")
&& (zUserToTrust = P("trustuser"))!=0
){
db_multi_exec("UPDATE user SET cap=cap||'4' "
"WHERE login=%Q AND cap NOT GLOB '*4*'",
zUserToTrust);
|
|
|
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
|
cgi_redirectf("%R/forumpost/%S",P("fpid"));
return;
}
isCsrfSafe = cgi_csrf_safe(1);
if( g.perm.ModForum && isCsrfSafe ){
if( P("approve") ){
const char *zUserToTrust;
moderation_approve('f', fpid);
if( g.perm.AdminForum
&& PB("trust")
&& (zUserToTrust = P("trustuser"))!=0
){
db_multi_exec("UPDATE user SET cap=cap||'4' "
"WHERE login=%Q AND cap NOT GLOB '*4*'",
zUserToTrust);
|
| ︙ | | | ︙ | |
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
|
}else{
cgi_redirectf("%R/forum");
}
return;
}
}
isDelete = P("nullout")!=0;
if( P("submit") && isCsrfSafe ){
int done = 1;
const char *zMimetype = PD("mimetype",DEFAULT_FORUM_MIMETYPE);
const char *zContent = PDT("content","");
if( P("reply") ){
done = forum_post(0, fpid, 0, 0, zMimetype, zContent);
}else if( P("edit") || isDelete ){
done = forum_post(P("title"), 0, fpid, 0, zMimetype, zContent);
}else{
webpage_error("Missing 'reply' query parameter");
}
if( done ) return;
}
if( isDelete ){
zMimetype = "text/x-fossil-wiki";
zContent = "";
if( pPost->zThreadTitle ) zTitle = "";
style_header("Delete %s", zTitle ? "Post" : "Reply");
@ <h1>Original Post:</h1>
forum_render(pPost->zThreadTitle, pPost->zMimetype, pPost->zWiki,
"forumEdit");
@ <h1>Change Into:</h1>
forum_render(zTitle, zMimetype, zContent,"forumEdit");
@ <form action="%R/forume2" method="POST">
@ <input type="hidden" name="fpid" value="%h(P("fpid"))">
@ <input type="hidden" name="nullout" value="1">
@ <input type="hidden" name="mimetype" value="%h(zMimetype)">
@ <input type="hidden" name="content" value="%h(zContent)">
if( zTitle ){
@ <input type="hidden" name="title" value="%h(zTitle)">
}
}else if( P("edit") ){
/* Provide an edit to the fpid post */
zMimetype = P("mimetype");
zContent = PT("content");
zTitle = P("title");
if( zContent==0 ) zContent = fossil_strdup(pPost->zWiki);
if( zMimetype==0 ) zMimetype = fossil_strdup(pPost->zMimetype);
if( zTitle==0 && pPost->zThreadTitle!=0 ){
zTitle = fossil_strdup(pPost->zThreadTitle);
}
style_header("Edit %s", zTitle ? "Post" : "Reply");
@ <h1>Original Post:</h1>
forum_render(pPost->zThreadTitle, pPost->zMimetype, pPost->zWiki,
"forumEdit");
if( P("preview") ){
@ <h1>Preview of Edited Post:</h1>
forum_render(zTitle, zMimetype, zContent,"forumEdit");
}
@ <h1>Revised Message:</h1>
@ <form action="%R/forume2" method="POST">
@ <input type="hidden" name="fpid" value="%h(P("fpid"))">
@ <input type="hidden" name="edit" value="1">
forum_from_line();
forum_entry_widget(zTitle, zMimetype, zContent);
}else{
/* Reply */
zMimetype = PD("mimetype",DEFAULT_FORUM_MIMETYPE);
zContent = PDT("content","");
style_header("Reply");
@ <h1>Replying To:</h1>
if( pRootPost->zThreadTitle ){
@ <h3>%h(pRootPost->zThreadTitle)</h3>
}
zDate = db_text(0, "SELECT datetime(%.17g)", pPost->rDate);
@ <p>%h(pPost->zThreadTitle ? "Post" : "Reply") by %h(pPost->zUser) on %h(zDate)
fossil_free(zDate);
forum_render(0, pPost->zMimetype, pPost->zWiki, "forumEdit");
if( P("preview") ){
@ <h1>Preview:</h1>
forum_render(0, zMimetype,zContent, "forumEdit");
}
@ <h1>Enter Reply:</h1>
@ <form action="%R/forume2" method="POST">
@ <input type="hidden" name="fpid" value="%h(P("fpid"))">
@ <input type="hidden" name="reply" value="1">
forum_from_line();
forum_entry_widget(0, zMimetype, zContent);
}
if( !isDelete ){
@ <input type="submit" name="preview" value="Preview">
}
@ <input type="submit" name="cancel" value="Cancel">
if( P("preview") || isDelete ){
@ <input type="submit" name="submit" value="Submit">
}
if( g.perm.Debug ){
/* For the test-forumnew page add these extra debugging controls */
@ <div class="debug">
@ <label><input type="checkbox" name="dryrun" %s(PCK("dryrun"))> \
@ Dry run</label>
@ <br><label><input type="checkbox" name="domod" %s(PCK("domod"))> \
@ Require moderator approval</label>
@ <br><label><input type="checkbox" name="showqp" %s(PCK("showqp"))> \
@ Show query parameters</label>
@ </div>
}
@ </form>
style_footer();
}
/*
** WEBPAGE: forum
**
** The main page for the forum feature. Show a list of recent forum
** threads. Also show a search box at the top if search is enabled,
** and a button for creating a new thread, if enabled.
**
** Query parameters:
|
|
>
>
>
>
<
|
|
|
|
|
|
|
>
<
|
>
|
>
>
|
|
|
|
|
|
>
|
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
|
}else{
cgi_redirectf("%R/forum");
}
return;
}
}
isDelete = P("nullout")!=0;
if( P("submit")
&& isCsrfSafe
&& (zContent = PDT("content",""))!=0
&& (!whitespace_only(zContent) || isDelete)
){
int done = 1;
const char *zMimetype = PD("mimetype",DEFAULT_FORUM_MIMETYPE);
if( P("reply") ){
done = forum_post(0, fpid, 0, 0, zMimetype, zContent);
}else if( P("edit") || isDelete ){
done = forum_post(P("title"), 0, fpid, 0, zMimetype, zContent);
}else{
webpage_error("Missing 'reply' query parameter");
}
if( done ) return;
}
if( isDelete ){
zMimetype = "text/x-fossil-wiki";
zContent = "";
if( pPost->zThreadTitle ) zTitle = "";
style_header("Delete %s", zTitle ? "Post" : "Reply");
@ <h1>Original Post:</h1>
forum_render(pPost->zThreadTitle, pPost->zMimetype, pPost->zWiki,
"forumEdit", 1);
@ <h1>Change Into:</h1>
forum_render(zTitle, zMimetype, zContent,"forumEdit", 1);
@ <form action="%R/forume2" method="POST">
@ <input type="hidden" name="fpid" value="%h(P("fpid"))">
@ <input type="hidden" name="nullout" value="1">
@ <input type="hidden" name="mimetype" value="%h(zMimetype)">
@ <input type="hidden" name="content" value="%h(zContent)">
if( zTitle ){
@ <input type="hidden" name="title" value="%h(zTitle)">
}
}else if( P("edit") ){
/* Provide an edit to the fpid post */
zMimetype = P("mimetype");
zContent = PT("content");
zTitle = P("title");
if( zContent==0 ) zContent = fossil_strdup(pPost->zWiki);
if( zMimetype==0 ) zMimetype = fossil_strdup(pPost->zMimetype);
if( zTitle==0 && pPost->zThreadTitle!=0 ){
zTitle = fossil_strdup(pPost->zThreadTitle);
}
style_header("Edit %s", zTitle ? "Post" : "Reply");
@ <h2>Original Post:</h2>
forum_render(pPost->zThreadTitle, pPost->zMimetype, pPost->zWiki,
"forumEdit", 1);
if( P("preview") ){
@ <h2>Preview of Edited Post:</h2>
forum_render(zTitle, zMimetype, zContent,"forumEdit", 1);
}
@ <h2>Revised Message:</h2>
@ <form action="%R/forume2" method="POST">
@ <input type="hidden" name="fpid" value="%h(P("fpid"))">
@ <input type="hidden" name="edit" value="1">
forum_from_line();
forum_entry_widget(zTitle, zMimetype, zContent);
}else{
/* Reply */
char *zDisplayName;
zMimetype = PD("mimetype",DEFAULT_FORUM_MIMETYPE);
zContent = PDT("content","");
style_header("Reply");
if( pRootPost->zThreadTitle ){
@ <h1>Thread: %h(pRootPost->zThreadTitle)</h1>
}
@ <h2>Replying To:</h2>
zDate = db_text(0, "SELECT datetime(%.17g)", pPost->rDate);
zDisplayName = display_name_from_login(pPost->zUser);
@ <h3 class='forumPostHdr'>By %h(zDisplayName) on %h(zDate)</h3>
fossil_free(zDisplayName);
fossil_free(zDate);
forum_render(0, pPost->zMimetype, pPost->zWiki, "forumEdit", 1);
if( P("preview") && !whitespace_only(zContent) ){
@ <h2>Preview:</h2>
forum_render(0, zMimetype,zContent, "forumEdit", 1);
}
@ <h2>Enter Reply:</h2>
@ <form action="%R/forume2" method="POST">
@ <input type="hidden" name="fpid" value="%h(P("fpid"))">
@ <input type="hidden" name="reply" value="1">
forum_from_line();
forum_entry_widget(0, zMimetype, zContent);
}
if( !isDelete ){
@ <input type="submit" name="preview" value="Preview">
}
@ <input type="submit" name="cancel" value="Cancel">
if( (P("preview") && !whitespace_only(zContent)) || isDelete ){
@ <input type="submit" name="submit" value="Submit">
}
if( g.perm.Debug ){
/* For the test-forumnew page add these extra debugging controls */
@ <div class="debug">
@ <label><input type="checkbox" name="dryrun" %s(PCK("dryrun"))> \
@ Dry run</label>
@ <br><label><input type="checkbox" name="domod" %s(PCK("domod"))> \
@ Require moderator approval</label>
@ <br><label><input type="checkbox" name="showqp" %s(PCK("showqp"))> \
@ Show query parameters</label>
@ </div>
}
@ </form>
style_footer();
}
/*
** WEBPAGE: forummain
** WEBPAGE: forum
**
** The main page for the forum feature. Show a list of recent forum
** threads. Also show a search box at the top if search is enabled,
** and a button for creating a new thread, if enabled.
**
** Query parameters:
|
| ︙ | | | ︙ | |