Fossil

Check-in [59f126d9]
Login

Check-in [59f126d9]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:When viewing a forum thread, use the title of the thread as the page title.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 59f126d90b625b14d6f5a742603f15c2882e516e530c3a973b323fd517ff8622
User & Date: drh 2020-03-02 12:50:33
Context
2020-03-02
12:57
Add the /favicon.ico web page. ... (check-in: 81b3ce3a user: drh tags: trunk)
12:50
When viewing a forum thread, use the title of the thread as the page title. ... (check-in: 59f126d9 user: drh tags: trunk)
2020-02-29
19:32
Properly truncate a forum thread's title when is UTF-8 encoded. ... (Closed-Leaf check-in: 4b12ad0e user: ashepilko tags: forumthread-title)
2020-02-27
19:16
More information on Setup and in Security-Audit to help admins configure Public Pages with the correct capabilities. ... (check-in: 0c374456 user: drh tags: trunk)
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/forum.c.

528
529
530
531
532
533
534










































535
536
537
538
539
540
541
**   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.







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







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
**   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();
}

/*
** Add an appropriate style_header() to include title of the
** given forum post.
*/
static int forumthread_page_header(int froot, int fpid){
  Blob title;
  int mxForumPostTitleLen = 50;
  char *zThreadTitle = "";

  zThreadTitle = db_text("",
    "SELECT"
    " substr(event.comment,instr(event.comment,':')+2)"
    " FROM forumpost, event"
    " WHERE event.objid=forumpost.fpid"
    "   AND forumpost.fpid=%d;",
    fpid
  );
  blob_set(&title, zThreadTitle);
  /* truncate the title when longer than max allowed;
   * in case of UTF-8 make sure the truncated string remains valid,
   * otherwise (different encoding?) pass as-is
   */
  if( mxForumPostTitleLen>0 && blob_size(&title)>mxForumPostTitleLen ){
    Blob truncated;
    int len;
    blob_copy(&truncated, &title);
    for( len = mxForumPostTitleLen; len; --len ){
      blob_truncate(&truncated, len);
      if( !invalid_utf8(&truncated) ) break;
    }
    if( len ){
      blob_append(&truncated, "...", 3);
      blob_copy(&title, &truncated);
    }
    blob_reset(&truncated);
  }
  style_header("%s%s", blob_str(&title), blob_size(&title) ? " - Forum" : "Forum");
  blob_reset(&title);
  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.
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
  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);
  }







<












>







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
  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";
    }
  }
  forumthread_page_header(froot, fpid);
  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);
  }