Fossil SCM

When viewing a forum thread, use the title of the thread as the page title.

drh 2020-03-02 12:50 trunk merge
Commit 59f126d90b625b14d6f5a742603f15c2882e516e530c3a973b323fd517ff8622
1 file changed +43 -1
+43 -1
--- src/forum.c
+++ src/forum.c
@@ -530,10 +530,52 @@
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 the title when longer than max allowed;
555
+ * in case of UTF-8 make sure the truncated string remains valid,
556
+ * otherwise (different encoding?) pass as-is
557
+ */
558
+ if( mxForumPostTitleLen>0 && blob_size(&title)>mxForumPostTitleLen ){
559
+ Blob truncated;
560
+ int len;
561
+ blob_copy(&truncated, &title);
562
+ for( len = mxForumPostTitleLen; len; --len ){
563
+ blob_truncate(&truncated, len);
564
+ if( !invalid_utf8(&truncated) ) break;
565
+ }
566
+ if( len ){
567
+ blob_append(&truncated, "...", 3);
568
+ blob_copy(&title, &truncated);
569
+ }
570
+ blob_reset(&truncated);
571
+ }
572
+ style_header("%s%s", blob_str(&title), blob_size(&title) ? " - Forum" : "Forum");
573
+ blob_reset(&title);
574
+ fossil_free(zThreadTitle);
575
+ return 0;
576
+}
535577
536578
/*
537579
** WEBPAGE: forumthread
538580
**
539581
** Show all forum messages associated with a particular message thread.
@@ -561,11 +603,10 @@
561603
}
562604
fpid = symbolic_name_to_rid(zName, "f");
563605
if( fpid<=0 ){
564606
webpage_error("Unknown or ambiguous forum id: \"%s\"", zName);
565607
}
566
- style_header("Forum");
567608
froot = db_int(0, "SELECT froot FROM forumpost WHERE fpid=%d", fpid);
568609
if( froot==0 ){
569610
webpage_error("Not a forum post: \"%s\"", zName);
570611
}
571612
if( fossil_strcmp(g.zPath,"forumthread")==0 ) fpid = 0;
@@ -574,10 +615,11 @@
574615
zMode = "c"; /* Default to chronological on mobile */
575616
}else{
576617
zMode = "h";
577618
}
578619
}
620
+ forumthread_page_header(froot, fpid);
579621
if( zMode[0]=='c' ){
580622
style_submenu_element("Hierarchical", "%R/%s/%s?t=h", g.zPath, zName);
581623
forum_display_chronological(froot, fpid);
582624
}else{
583625
style_submenu_element("Chronological", "%R/%s/%s?t=c", g.zPath, zName);
584626
--- src/forum.c
+++ src/forum.c
@@ -530,10 +530,52 @@
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 +603,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 +615,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,52 @@
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 the title when longer than max allowed;
555 * in case of UTF-8 make sure the truncated string remains valid,
556 * otherwise (different encoding?) pass as-is
557 */
558 if( mxForumPostTitleLen>0 && blob_size(&title)>mxForumPostTitleLen ){
559 Blob truncated;
560 int len;
561 blob_copy(&truncated, &title);
562 for( len = mxForumPostTitleLen; len; --len ){
563 blob_truncate(&truncated, len);
564 if( !invalid_utf8(&truncated) ) break;
565 }
566 if( len ){
567 blob_append(&truncated, "...", 3);
568 blob_copy(&title, &truncated);
569 }
570 blob_reset(&truncated);
571 }
572 style_header("%s%s", blob_str(&title), blob_size(&title) ? " - Forum" : "Forum");
573 blob_reset(&title);
574 fossil_free(zThreadTitle);
575 return 0;
576 }
577
578 /*
579 ** WEBPAGE: forumthread
580 **
581 ** Show all forum messages associated with a particular message thread.
@@ -561,11 +603,10 @@
603 }
604 fpid = symbolic_name_to_rid(zName, "f");
605 if( fpid<=0 ){
606 webpage_error("Unknown or ambiguous forum id: \"%s\"", zName);
607 }
 
608 froot = db_int(0, "SELECT froot FROM forumpost WHERE fpid=%d", fpid);
609 if( froot==0 ){
610 webpage_error("Not a forum post: \"%s\"", zName);
611 }
612 if( fossil_strcmp(g.zPath,"forumthread")==0 ) fpid = 0;
@@ -574,10 +615,11 @@
615 zMode = "c"; /* Default to chronological on mobile */
616 }else{
617 zMode = "h";
618 }
619 }
620 forumthread_page_header(froot, fpid);
621 if( zMode[0]=='c' ){
622 style_submenu_element("Hierarchical", "%R/%s/%s?t=h", g.zPath, zName);
623 forum_display_chronological(froot, fpid);
624 }else{
625 style_submenu_element("Chronological", "%R/%s/%s?t=c", g.zPath, zName);
626

Keyboard Shortcuts

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