Skip to content
This repository
tree: 2c8fbaf889
Fetching contributors…

Cannot retrieve contributors at this time

file 227 lines (224 sloc) 7.008 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 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 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
#! stdtmpl
#
#template `%`(idx: expr): expr {.immediate.} =
# row[idx]
#end template
#
#
#proc genThreadsList(c: var TForumData, count: var int): string =
# const query = sql"select id, name, views, modified from thread order by modified desc limit ?, ?"
# const threadId = 0
# const name = 1
# const views = 2
#
# result = ""
# count = 0
<table id="threads">
  <tr>
    <th>Topics</th>
    <th>Author</th>
    <th>Posts</th>
    <th>Views</th>
    <th>Last reply</th>
  </tr>
# for row in Rows(db, query, $((c.pageNum-1) * ThreadsPerPage), $ThreadsPerPage):
# inc(count)
  <tr>
    <td class="topic">
      ${UrlButton(c, XMLencode(%name), c.genThreadUrl(threadid = %threadid))}
      ${genPagenumLocalNav(c, (%threadid).parseInt)}
    </td>
    #let authorName = getValue(db, sql("select name from person where id = " &
    # "(select author from post where id = " &
    # "(select min(id) from post where thread = ?))"), %threadId)
    <td class="author">${authorName}</td>
# let posts = GetValue(db, sql"select count(*) from post where thread = ?", %threadId)
    <td class="posts">$posts</td>
    <td class="views">${XMLencode(%views)}</td>
    #let latestReplyAuthor = getValue(db, sql("select name from person where id = " &
    # "(select author from post where id = " &
    # "(select max(id) from post where thread = ?))"), %threadId)
    #let latestReplyDate = getValue(db, sql("SELECT strftime('%s', " &
    # "(select creation from post where id = (select max(id) from post where thread = ?)))"), %threadId)
    <td class="lastreply">
      <span>${formatTimestamp(latestReplyDate.parseInt())}</span><br/>
      <span>${latestReplyAuthor}</span>
    </td>
  </tr>
# end for
</table>
#end proc
#
#
#proc genPostPreview(c: var TForumData,
# title, content, author, date: string): string =
# result = ""
<a name="preview"></a>
<table class="post">
  <tr>
    <th colspan="2">
      <span>${XMLEncode(title)}</span>
      <span style="float:right;">${XMLencode(date)}</span>
    </th>
  </tr>
  <tr>
    <td class="left">
      <span>${XMLencode(author)}</span>
    </td>
    <td class="content">
    #try:
      ${content.rstToHtml}
    #except EParseError:
    # c.errorMsg = getCurrentExceptionMsg()
    #end
    </td>
  </tr>
</table>
#end proc
#
#
#proc genPostsList(c: var TForumData, threadId: string, count: var int): string =
# const query = sql"""select p.id, u.name, p.header, p.content, p.creation, p.author, u.email from post p,
# person u where u.id = p.author and p.thread = ? order by p.id limit ?, ?"""
# const postId = 0
# const userName = 1
# const postHeader = 2
# const postContent = 3
# const postCreation = 4
# const postAuthor = 5
# const userEmail = 6
# result = ""
# count = 0
# for row in FastRows(db, query, threadId, $((c.pageNum-1) * PostsPerPage), $PostsPerPage):
# inc(count)
<a name="${%postId}"></a>
<table class="post">
  <tr>
    <th colspan="2">
      <span>${XMLencode(%postHeader)}</span>
      <span style="float:right;">${XMLencode(%postCreation)}</span>
    </th>
  </tr>
  <tr>
    <td class="left">
      <span>${XMLencode(%userName)}</span>
      <hr/>
      ${genGravatar(%userEmail)}
      #if c.userId == %postAuthor and c.currentPost.subject.len == 0:
        <hr/>${UrlButton(c, "Edit post", c.genThreadUrl(%postId, "edit"))}
      #elif c.isAdmin and c.currentPost.subject.len == 0:
        <hr/><span style="color:red">
          ${UrlButton(c, "Edit post", c.genThreadUrl(%postId, "edit"))}</span>
      #end if
    </td>
    <td class="content">
    #try:
      ${(%postContent).rstToHtml}
    #except EParseError:
    # c.errorMsg = getCurrentExceptionMsg()
    #end
    </td>
  </tr>
</table>
# end for
#end proc
#
#
#proc genFormPost(c: var TForumData, action: string,
# topText, title, content: string, isEdit: bool): string =
# result = ""
<br />
<a name="reply"></a>
<div id="replywrapper">
  <div id="replytop">
    <span>${topText}</span>
  </div>
  <form action="${c.req.makeUri(action, false) & "#preview"}" method="POST">
    ${FieldValid(c, "subject", "Subject:")}
    ${TextWidget(c, "subject", title, maxlength=100)}
    <br />
    ${FieldValid(c, "content", "Content:")}<br />
    ${TextAreaWidget(c, "content", content, width=100, height=20)}<br />
    ${FormSession(c, action)}

  # if isEdit:
    <input type="checkbox" name="delete" value="Delete">Delete Post<br />
  # end if
    <br/>
    <input type="submit" name="previewBtn" value="Preview" />
    <input type="submit" name="postBtn" value="Submit" />
  
    <a href="http://nimrod-code.org/rst.html">Syntax Cheatsheet</a>
  </form>
</div>
#end proc
#
#
#proc genFormRegister(c: var TForumData): string =
# result = ""
<form action="${c.req.makeUri("/doregister", false)}" method="POST">
  <b>Register</b><br />
  <table border="0">
    <tr>
      <td>${FieldValid(c, "name", "Username:")}</td>
      <td>${TextWidget(c, "name", reuseText, maxlength=20)}</td>
    </tr>
    <tr>
      <td>${FieldValid(c, "new_password", "Password:")}</td>
      <td><input type="password" name="new_password" maxlength="20" /></td>
    </tr>
    <tr>
      <td>${FieldValid(c, "email", "E-Mail:")}</td>
      <td>${TextWidget(c, "email", reuseText, maxlength=30)}</td>
    </tr>
    <tr>
      <td>${FieldValid(c, "antibot", "What is " & antibot(c) & "?")}</td>
      <td>${TextWidget(c, "antibot", "", maxlength=4)}</td>
    </tr>
  </table>
  <input type="submit" value="Register">
</form>
#end proc
#
#proc genFormLogin(c: var TForumData): string =
# result = ""
# if not c.loggedIn:
  <form action="${c.req.makeUri("/dologin", false)}" method="POST">
  <table border="0">
    <tr><td>Username:</td><td>
    <input type="text" name="name" maxlength="20"></td></tr>
    <tr><td>Password:</td><td>
    <input type="password" name="password" maxlength="20"></td></tr>
  </table>
  <input type="submit" value="Login">
  </form>
  <span style="color:red">$c.loginErrorMsg</span>
# else:
  <span style="color:red">You're already logged in!</span>
# end if
#end proc
#
#
#proc genListOnline(c: var TForumData, stats: TForumStats): string =
# result = ""
  <div id="whoisonline">
    <div class="wioHeader">
      <span>Who is online?<span>
    </div>
    <div class="content">
    <span>Out of ${stats.totalUsers} users ${stats.activeUsers.len} are online${if stats.activeUsers.len == 0: "." else: ":"}
      #for index, usr in stats.activeUsers:
      # if usr.isAdmin:
          #if index != 0: result.add ','
          #end if
          #result.add("""<span class="user admin"> """ & usr.nick & """</span>""")
      # else:
          #if index != 0: result.add ','
          #end if
          #result.add("""<span class="user"> """ & usr.nick & """</span>""")
      # end if
      #end for
    </span>
    <hr/>
    <span>Total threads: ${stats.totalThreads} | Total posts: ${stats.totalPosts} | Newest member: ${stats.newestMember.nick}</span>
    </div>
  </div>
  
#end proc
Something went wrong with that request. Please try again.