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
|
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
|
-
+
+
|
ForumPost *p;
Stmt q;
int sid = 1;
int firt, fprev;
pThread = fossil_malloc( sizeof(*pThread) );
memset(pThread, 0, sizeof(*pThread));
db_prepare(&q,
"SELECT fpid, firt, fprev, (SELECT uuid FROM blob WHERE rid=fpid)"
"SELECT fpid, firt, fprev, (SELECT uuid FROM blob WHERE rid=fpid), fmtime"
" FROM forumpost"
" WHERE froot=%d ORDER BY fmtime",
froot
);
while( db_step(&q)==SQLITE_ROW ){
pPost = fossil_malloc( sizeof(*pPost) );
memset(pPost, 0, sizeof(*pPost));
pPost->fpid = db_column_int(&q, 0);
firt = db_column_int(&q, 1);
fprev = db_column_int(&q, 2);
pPost->zUuid = fossil_strdup(db_column_text(&q,3));
pPost->rDate = db_column_double(&q,4);
if( !fprev ) pPost->sid = sid++;
pPost->pPrev = pThread->pLast;
pPost->pNext = 0;
if( pThread->pLast==0 ){
pThread->pFirst = pPost;
}else{
pThread->pLast->pNext = pPost;
|
365
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
|
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
|
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
-
+
-
-
-
+
-
-
-
+
-
-
-
-
+
-
-
+
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
+
-
+
-
-
-
-
-
-
-
-
-
-
+
-
+
-
+
|
** 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 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;
}
/*
** Compute and return the display name for a ForumPost. If
** pManifest is not NULL, then it is a Manifest object for the post.
** if pManifest is NULL, this routine has to fetch and parse the
** Manifest object for itself.
**
** Memory to hold the display name is attached to p->zDisplayName
** and will be freed together with the ForumPost object p when it
** is freed.
*/
static char *forum_post_display_name(ForumPost *p, Manifest *pManifest){
Manifest *pToFree = 0;
if( p->zDisplayName ) return p->zDisplayName;
if( pManifest==0 ){
pManifest = pToFree = manifest_get(p->fpid, CFTYPE_FORUM, 0);
if( pManifest==0 ) return "(unknown)";
}
p->zDisplayName = display_name_from_login(pManifest->zUser);
if( pToFree ) manifest_destroy(pToFree);
if( p->zDisplayName==0 ) return "(unknown)";
return p->zDisplayName;
}
/*
** Display a single post in a forum thread.
*/
static void forum_display_post(
ForumPost *p, /* Forum post to display */
int iIndentScale, /* Indent scale factor */
int bRaw, /* True to omit the border */
int bUnf, /* True to leave the post unformatted */
int bHist, /* True if showing edit history */
int bSelect, /* True if this is the selected post */
char *zQuery /* Common query string */
){
char *zDisplayName; /* The display name */
char *zPosterName; /* Name of user who originally made this post */
char *zEditorName; /* Name of user who provided the current edit */
char *zDate; /* The time/date string */
char *zHist; /* History query string */
Manifest *pOriginal; /* Original post artifact */
Manifest *pManifest; /* Manifest comprising the current post */
Manifest *pRevised; /* Revised post artifact (may be same as pOriginal) */
int bPrivate; /* True for posts awaiting moderation */
int bSameUser; /* True if author is also the reader */
int iIndent; /* Indent level */
const char *zMimetype;/* Formatting MIME type */
/* Get the original and revised artifacts for the post. Abort if either is
** not found (e.g. shunned). */
/* Get the manifest for the post. Abort if not found (e.g. shunned). */
if( p->pEditHead ){
pOriginal = manifest_get(p->pEditHead->fpid, CFTYPE_FORUM, 0);
pRevised = manifest_get(p->fpid, CFTYPE_FORUM, 0);
pManifest = manifest_get(p->fpid, CFTYPE_FORUM, 0);
}else{
pOriginal = pRevised = manifest_get(p->fpid, CFTYPE_FORUM, 0);
}
if( !pOriginal || !pRevised ) return;
if( !pManifest ) return;
/* When not in raw mode, create the border around the post. */
if( !bRaw ){
/* Open the <div> enclosing the post. Set the class string to mark the post
** as selected and/or obsolete. */
iIndent = (p->pEditHead ? p->pEditHead->nIndent : p->nIndent)-1;
@ <div id='forum%d(p->fpid)' class='forumTime\
@ %s(bSelect ? " forumSel" : "")\
@ %s(p->pEditTail ? " forumObs" : "")'\
if( iIndent && iIndentScale ){
@ style='margin-left: %d(iIndent*iIndentScale)ex'
}
@ >
/* If this is the first post (or an edit thereof), emit the thread title. */
if( pRevised->zThreadTitle ){
@ <h1>%h(pRevised->zThreadTitle)</h1>
if( pManifest->zThreadTitle ){
@ <h1>%h(pManifest->zThreadTitle)</h1>
}
/* Emit the serial number, revision number, author, and date. */
zDisplayName = display_name_from_login(pOriginal->zUser);
zDate = db_text(0, "SELECT datetime(%.17g)", pOriginal->rDate);
@ <h3 class='forumPostHdr'>(%d(p->sid)\
if( p->nEdit ){
@ .%.*d(fossil_num_digits(p->nEdit))(p->rev)\
}
@ ) By %h(zDisplayName) on %h(zDate)
fossil_free(zDisplayName);
fossil_free(zDate);
/* Begin emitting the header line. The forum of the title
** varies depending on whether:
** * The post is uneditted
** * The post was last editted by the original author
** * The post was last editted by a different person
*/
if( p->pEditHead ){
zDate = db_text(0, "SELECT datetime(%.17g)", p->pEditHead->rDate);
}else{
zPosterName = forum_post_display_name(p, pManifest);
zEditorName = zPosterName;
}
zDate = db_text(0, "SELECT datetime(%.17g)", p->rDate);
if( p->pEditPrev ){
zPosterName = forum_post_display_name(p->pEditHead, 0);
zEditorName = forum_post_display_name(p, pManifest);
zHist = bHist ? "" : "&hist";
@ <h3 class='forumPostHdr'>(%d(p->sid)\
@ .%0*d(fossil_num_digits(p->nEdit))(p->rev)) \
if( fossil_strcmp(zPosterName, zEditorName)==0 ){
@ By %h(zPosterName) on %h(zDate) editted from \
@ %z(href("%R/forumpost/%S?%s%s",p->pEditPrev->zUuid,zQuery,zHist))\
@ %d(p->sid).%0*d(fossil_num_digits(p->nEdit))(p->pEditPrev->rev)</a>
}else{
@ Originally by %h(zPosterName) \
@ with edits by %h(zEditorName) on %h(zDate) from \
@ %z(href("%R/forumpost/%S?%s%s",p->pEditPrev->zUuid,zQuery,zHist))\
@ %d(p->sid).%0*d(fossil_num_digits(p->nEdit))(p->pEditPrev->rev)</a>
}
}else{
zPosterName = forum_post_display_name(p, pManifest);
@ <h3 class='forumPostHdr'>(%d(p->sid)) \
@ By %h(zPosterName) on %h(zDate)
}
fossil_free(zDate);
/* If debugging is enabled, link to the artifact page. */
if( g.perm.Debug ){
@ <span class="debug">\
@ <a href="%R/artifact/%h(p->zUuid)">(artifact-%d(p->fpid))</a></span>
}
/* If this is an edit, refer back to the old version. Be sure "hist" is in
** the query string so the old version will actually be shown. */
if( p->pEditPrev ){
zHist = bHist ? "" : "&hist";
@ edit of \
@ %z(href("%R/forumpost/%S?%s%s",p->pEditPrev->zUuid,zQuery,zHist))\
@ %d(p->sid).%.*d(fossil_num_digits(p->nEdit))(p->pEditPrev->rev)</a>
}
/* If this is a reply, refer back to the parent post. */
if( p->pIrt ){
@ in reply to %z(href("%R/forumpost/%S?%s",p->pIrt->zUuid,zQuery))\
@ %d(p->pIrt->sid)\
if( p->pIrt->nEdit ){
@ .%.*d(fossil_num_digits(p->pIrt->nEdit))(p->pIrt->rev)\
@ .%0*d(fossil_num_digits(p->pIrt->nEdit))(p->pIrt->rev)\
}
@ </a>
}
/* If this post was later edited, refer forward to the next edit. */
if( p->pEditNext ){
@ updated by %z(href("%R/forumpost/%S?%s",p->pEditNext->zUuid,zQuery))\
@ %d(p->pEditNext->sid)\
@ .%.*d(fossil_num_digits(p->nEdit))(p->pEditNext->rev)</a>
@ .%0*d(fossil_num_digits(p->nEdit))(p->pEditNext->rev)</a>
}
/* Provide a link to select the individual post. */
if( !bSelect ){
@ %z(href("%R/forumpost/%S?%s",p->zUuid,zQuery))[link]</a>
}
/* Provide a link to the raw source code. */
if( !bUnf ){
@ %z(href("%R/forumpost/%S?raw",p->zUuid))[source]</a>
}
/* If this is an edit, identify the editor and date. */
if( p->pEditPrev ){
zDisplayName = display_name_from_login(pRevised->zUser);
zDate = db_text(0, "SELECT datetime(%.17g)", pRevised->rDate);
@ <br>Edited by %h(zDisplayName) on %h(zDate)
fossil_free(zDisplayName);
fossil_free(zDate);
}
@ </h3>
}
/* Check if this post is approved, also if it's by the current user. */
bPrivate = content_is_private(p->fpid);
bSameUser = login_is_individual()
&& fossil_strcmp(pOriginal->zUser, g.zLogin)==0;
&& fossil_strcmp(pManifest->zUser, g.zLogin)==0;
/* Render the post if the user is able to see it. */
if( bPrivate && !g.perm.ModForum && !bSameUser ){
@ <p><span class="modpending">Awaiting Moderator Approval</span></p>
}else{
if( bRaw || bUnf || p->pEditTail ){
zMimetype = "text/plain";
}else{
zMimetype = pRevised->zMimetype;
zMimetype = pManifest->zMimetype;
}
forum_render(0, zMimetype, pRevised->zWiki, 0, !bRaw);
forum_render(0, zMimetype, pManifest->zWiki, 0, !bRaw);
}
/* When not in raw mode, finish creating the border around the post. */
if( !bRaw ){
/* If the user is able to write to the forum and if this post has not been
** edited, create a form with various interaction buttons. */
if( g.perm.WrForum && !p->pEditTail ){
|