Fossil SCM

Include forum thread's title in its page title.

ashepilko 2020-02-28 21:53 forumthread-title
Commit 9559bdb69cea3e1b1617950483a15e6ee5077a9d92a582625e5ca6604b7ccbc0
1 file changed +30 -1
+30 -1
--- src/forum.c
+++ src/forum.c
@@ -530,10 +530,39 @@
530530
** 'h' for hierarchical, or 'a' for automatic.
531531
*/
532532
void forumpost_page(void){
533533
forumthread_page();
534534
}
535
+
536
+/*
537
+** Add an appropriate style_header() to include title of the
538
+** given forum post.
539
+*/
540
+static int forumthread_page_header(int froot, int fpid){
541
+ Blob title;
542
+ int mxForumPostTitleLen = 50;
543
+ char *zThreadTitle = "";
544
+
545
+ zThreadTitle = db_text("",
546
+ "SELECT"
547
+ " substr(event.comment,instr(event.comment,':')+2)"
548
+ " FROM forumpost, event"
549
+ " WHERE event.objid=forumpost.fpid"
550
+ " AND forumpost.fpid=%d;",
551
+ fpid
552
+ );
553
+ blob_set(&title, zThreadTitle);
554
+ /* truncate title when longer than max allowed */
555
+ if ( mxForumPostTitleLen>0 && blob_size(&title)>mxForumPostTitleLen ) {
556
+ blob_resize(&title, mxForumPostTitleLen);
557
+ blob_append(&title, "...", 3);
558
+ }
559
+ style_header("%s%s", blob_str(&title), blob_size(&title) ? " - Forum" : "Forum");
560
+ blob_reset(&title);
561
+ fossil_free(zThreadTitle);
562
+ return 0;
563
+}
535564
536565
/*
537566
** WEBPAGE: forumthread
538567
**
539568
** Show all forum messages associated with a particular message thread.
@@ -561,11 +590,10 @@
561590
}
562591
fpid = symbolic_name_to_rid(zName, "f");
563592
if( fpid<=0 ){
564593
webpage_error("Unknown or ambiguous forum id: \"%s\"", zName);
565594
}
566
- style_header("Forum");
567595
froot = db_int(0, "SELECT froot FROM forumpost WHERE fpid=%d", fpid);
568596
if( froot==0 ){
569597
webpage_error("Not a forum post: \"%s\"", zName);
570598
}
571599
if( fossil_strcmp(g.zPath,"forumthread")==0 ) fpid = 0;
@@ -574,10 +602,11 @@
574602
zMode = "c"; /* Default to chronological on mobile */
575603
}else{
576604
zMode = "h";
577605
}
578606
}
607
+ forumthread_page_header(froot, fpid);
579608
if( zMode[0]=='c' ){
580609
style_submenu_element("Hierarchical", "%R/%s/%s?t=h", g.zPath, zName);
581610
forum_display_chronological(froot, fpid);
582611
}else{
583612
style_submenu_element("Chronological", "%R/%s/%s?t=c", g.zPath, zName);
584613
--- src/forum.c
+++ src/forum.c
@@ -530,10 +530,39 @@
530 ** 'h' for hierarchical, or 'a' for automatic.
531 */
532 void forumpost_page(void){
533 forumthread_page();
534 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
535
536 /*
537 ** WEBPAGE: forumthread
538 **
539 ** Show all forum messages associated with a particular message thread.
@@ -561,11 +590,10 @@
561 }
562 fpid = symbolic_name_to_rid(zName, "f");
563 if( fpid<=0 ){
564 webpage_error("Unknown or ambiguous forum id: \"%s\"", zName);
565 }
566 style_header("Forum");
567 froot = db_int(0, "SELECT froot FROM forumpost WHERE fpid=%d", fpid);
568 if( froot==0 ){
569 webpage_error("Not a forum post: \"%s\"", zName);
570 }
571 if( fossil_strcmp(g.zPath,"forumthread")==0 ) fpid = 0;
@@ -574,10 +602,11 @@
574 zMode = "c"; /* Default to chronological on mobile */
575 }else{
576 zMode = "h";
577 }
578 }
 
579 if( zMode[0]=='c' ){
580 style_submenu_element("Hierarchical", "%R/%s/%s?t=h", g.zPath, zName);
581 forum_display_chronological(froot, fpid);
582 }else{
583 style_submenu_element("Chronological", "%R/%s/%s?t=c", g.zPath, zName);
584
--- src/forum.c
+++ src/forum.c
@@ -530,10 +530,39 @@
530 ** 'h' for hierarchical, or 'a' for automatic.
531 */
532 void forumpost_page(void){
533 forumthread_page();
534 }
535
536 /*
537 ** Add an appropriate style_header() to include title of the
538 ** given forum post.
539 */
540 static int forumthread_page_header(int froot, int fpid){
541 Blob title;
542 int mxForumPostTitleLen = 50;
543 char *zThreadTitle = "";
544
545 zThreadTitle = db_text("",
546 "SELECT"
547 " substr(event.comment,instr(event.comment,':')+2)"
548 " FROM forumpost, event"
549 " WHERE event.objid=forumpost.fpid"
550 " AND forumpost.fpid=%d;",
551 fpid
552 );
553 blob_set(&title, zThreadTitle);
554 /* truncate title when longer than max allowed */
555 if ( mxForumPostTitleLen>0 && blob_size(&title)>mxForumPostTitleLen ) {
556 blob_resize(&title, mxForumPostTitleLen);
557 blob_append(&title, "...", 3);
558 }
559 style_header("%s%s", blob_str(&title), blob_size(&title) ? " - Forum" : "Forum");
560 blob_reset(&title);
561 fossil_free(zThreadTitle);
562 return 0;
563 }
564
565 /*
566 ** WEBPAGE: forumthread
567 **
568 ** Show all forum messages associated with a particular message thread.
@@ -561,11 +590,10 @@
590 }
591 fpid = symbolic_name_to_rid(zName, "f");
592 if( fpid<=0 ){
593 webpage_error("Unknown or ambiguous forum id: \"%s\"", zName);
594 }
 
595 froot = db_int(0, "SELECT froot FROM forumpost WHERE fpid=%d", fpid);
596 if( froot==0 ){
597 webpage_error("Not a forum post: \"%s\"", zName);
598 }
599 if( fossil_strcmp(g.zPath,"forumthread")==0 ) fpid = 0;
@@ -574,10 +602,11 @@
602 zMode = "c"; /* Default to chronological on mobile */
603 }else{
604 zMode = "h";
605 }
606 }
607 forumthread_page_header(froot, fpid);
608 if( zMode[0]=='c' ){
609 style_submenu_element("Hierarchical", "%R/%s/%s?t=h", g.zPath, zName);
610 forum_display_chronological(froot, fpid);
611 }else{
612 style_submenu_element("Chronological", "%R/%s/%s?t=c", g.zPath, zName);
613

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button