Fossil

Check-in [aff20904]
Login

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

Overview
Comment:On the main /forum screen, provide the new n= and x= query parameters to enable access to older threads.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:aff20904fad05b078dfe5470686d106247fcffd3decf326bfb5a82e74e2c1c76
User & Date: drh 2018-08-15 20:41:13
Context
2018-08-15
20:50
Improved title on on the /forum page. check-in: dbd96b2c user: drh tags: trunk
20:41
On the main /forum screen, provide the new n= and x= query parameters to enable access to older threads. check-in: aff20904 user: drh tags: trunk
20:17
On the "Recent Threads" page (/forum) show the number of messages and the duration of each thread. check-in: a50dfe6f user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/forum.c.

903
904
905
906
907
908
909





910
911
912
913
914
915
916
917
918
919
920
...
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
...
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

/*
** 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.





*/
void forum_main_page(void){
  Stmt q;
  int iLimit, iOfst;
  login_check_credentials();
  if( !g.perm.RdForum ){
    login_needed(g.anon.RdForum);
    return;
  }
  style_header("Forum");
  if( g.perm.WrForum ){
................................................................................
    style_submenu_element("Moderation Requests", "%R/modreq");
  }
  if( search_screen(SRCH_FORUM, 0) ){
    style_submenu_element("Recent Threads","%R/forum");
    style_footer();
    return;
  }
  iLimit = 50;
  iOfst = 0;
  @ <h1>Recent Threads</h1>
  @ <div class='fileage'><table width="100%%">
  if( db_table_exists("repository","forumpost") ){
    db_prepare(&q,
      "SELECT"
      "  julianday('now') - max(fmtime) AS a,"                       /* 0 */
      "  max(fmtime) - min(fmtime) AS b,"                            /* 1 */
................................................................................
      "  (SELECT substr(uuid,1,10) FROM blob WHERE rid=froot),"      /* 3 */
      "  (SELECT substr(comment,instr(comment,':')+2)"               /* 4 */
      "     FROM event WHERE objid=(SELECT fpid FROM forumpost AS y"
      "                              WHERE y.froot=x.froot"
      "                              ORDER BY fmtime DESC LIMIT 1))"
      " FROM forumpost AS x"
      " GROUP BY froot ORDER BY 1 LIMIT %d OFFSET %d;",
      iLimit, iOfst
    );

    while( db_step(&q)==SQLITE_ROW ){
      char *zAge = human_readable_age(db_column_double(&q,0));
      char *zDuration = human_readable_age(db_column_double(&q,1));
      int nMsg = db_column_int(&q, 2);
      const char *zUuid = db_column_text(&q, 3);
      const char *zTitle = db_column_text(&q, 4);


















      @ <tr><td>%h(zAge) ago</td>
      @ <td>%z(href("%R/forumpost/%S",zUuid))%h(zTitle)</a></td>
      if( nMsg<2 ){
        @ <td>no replies</td>
      }else{

        @ <td>%d(nMsg) posts spanning %h(zDuration)</td>
      }
      @ </tr>
      fossil_free(zAge);
      fossil_free(zDuration);
    }
    db_finalize(&q);
  }
  @ </table></div>
  style_footer();
}







>
>
>
>
>



|







 







|
|







 







|

>

|
|



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





>











903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
...
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
...
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

/*
** 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:
**
**    n=N             The number of threads to show on each page
**    x=X             Skip the first X threads
*/
void forum_main_page(void){
  Stmt q;
  int iLimit, iOfst, iCnt;
  login_check_credentials();
  if( !g.perm.RdForum ){
    login_needed(g.anon.RdForum);
    return;
  }
  style_header("Forum");
  if( g.perm.WrForum ){
................................................................................
    style_submenu_element("Moderation Requests", "%R/modreq");
  }
  if( search_screen(SRCH_FORUM, 0) ){
    style_submenu_element("Recent Threads","%R/forum");
    style_footer();
    return;
  }
  iLimit = atoi(PD("n","25"));
  iOfst = atoi(PD("x","0"));
  @ <h1>Recent Threads</h1>
  @ <div class='fileage'><table width="100%%">
  if( db_table_exists("repository","forumpost") ){
    db_prepare(&q,
      "SELECT"
      "  julianday('now') - max(fmtime) AS a,"                       /* 0 */
      "  max(fmtime) - min(fmtime) AS b,"                            /* 1 */
................................................................................
      "  (SELECT substr(uuid,1,10) FROM blob WHERE rid=froot),"      /* 3 */
      "  (SELECT substr(comment,instr(comment,':')+2)"               /* 4 */
      "     FROM event WHERE objid=(SELECT fpid FROM forumpost AS y"
      "                              WHERE y.froot=x.froot"
      "                              ORDER BY fmtime DESC LIMIT 1))"
      " FROM forumpost AS x"
      " GROUP BY froot ORDER BY 1 LIMIT %d OFFSET %d;",
      iLimit+1, iOfst
    );
    iCnt = 0;
    while( db_step(&q)==SQLITE_ROW ){
      char *zAge = 0;
      char *zDuration = 0;
      int nMsg = db_column_int(&q, 2);
      const char *zUuid = db_column_text(&q, 3);
      const char *zTitle = db_column_text(&q, 4);
      if( iCnt==0 && iOfst>0 ){
        if( iOfst>iLimit ){
          @ <tr><td colspan="3">\
          @ %z(href("%R/forum?x=%d&n=%d",iOfst-iLimit,iLimit))\
          @ &uarr; Newer...</a></td></tr>
        }else{
          @ <tr><td colspan="3">%z(href("%R/forum?n=%d",iLimit))\
          @ &uarr; Newer...</a></td></tr>
        }
      }
      iCnt++;
      if( iCnt>iLimit ){
        @ <tr><td colspan="3">\
        @ %z(href("%R/forum?x=%d&n=%d",iOfst+iLimit,iLimit))\
        @ &darr; Older...</a></td></tr>
        break;
      }
      zAge = human_readable_age(db_column_double(&q,0));
      @ <tr><td>%h(zAge) ago</td>
      @ <td>%z(href("%R/forumpost/%S",zUuid))%h(zTitle)</a></td>
      if( nMsg<2 ){
        @ <td>no replies</td>
      }else{
        zDuration = human_readable_age(db_column_double(&q,1));
        @ <td>%d(nMsg) posts spanning %h(zDuration)</td>
      }
      @ </tr>
      fossil_free(zAge);
      fossil_free(zDuration);
    }
    db_finalize(&q);
  }
  @ </table></div>
  style_footer();
}