annotate src/new_thread.html.luan @ 61:389e5d8e5f8a default tip

minor
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 06 Dec 2022 13:37:25 -0700
parents 9f8ebc757814
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 local Luan = require "luan:Luan.luan"
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 local error = Luan.error
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 local Io = require "luan:Io.luan"
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 local Http = require "luan:http/Http.luan"
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 local Shared = require "site:/lib/Shared.luan"
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 local head = Shared.head or error()
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 local header = Shared.header or error()
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 local footer = Shared.footer or error()
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 local Forum = require "site:/lib/Forum.luan"
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 local forum_title = Forum.title or error()
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 local Post = require "site:/lib/Post.luan"
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 local User = require "site:/lib/User.luan"
52
9f8ebc757814 add convert urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 51
diff changeset
13 local Bbcode = require "site:/bbcode/Bbcode.luan"
9f8ebc757814 add convert urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 51
diff changeset
14 local preprocess = Bbcode.preprocess or error()
8
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 return function()
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18 local user = User.current_required()
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 if user==nil then return end
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 if Http.request.method == "POST" then
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 local subject = Http.request.parameters.subject or error()
46
289718f121e4 use bbcode editor
Franklin Schmidt <fschmidt@gmail.com>
parents: 42
diff changeset
22 local content = Http.request.parameters.bbcode or error()
52
9f8ebc757814 add convert urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 51
diff changeset
23 local convert_urls = Http.request.parameters.convert_urls or error()
9f8ebc757814 add convert urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 51
diff changeset
24 if convert_urls == "true" then
9f8ebc757814 add convert urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 51
diff changeset
25 content = preprocess(content)
9f8ebc757814 add convert urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 51
diff changeset
26 end
8
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 local post = Post.new_thread(user,subject,content)
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 Http.response.send_redirect("/thread.html?root="..post.id)
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 return
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 end
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 Io.stdout = Http.response.text_writer()
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 %>
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
33 <!doctype html>
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34 <html>
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35 <head>
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36 <% head() %>
9
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents: 8
diff changeset
37 <title><%=forum_title%>: new thread</title>
42
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents: 9
diff changeset
38 <style>
46
289718f121e4 use bbcode editor
Franklin Schmidt <fschmidt@gmail.com>
parents: 42
diff changeset
39 @import "/bbcode/bbcode.css";
42
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents: 9
diff changeset
40 </style>
8
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
41 <body>
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
42 <% header() %>
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43 <div content>
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
44 <h1>New Thread</h1>
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45 <form method=post>
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
46 <p>
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
47 <label>Subject</label>
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
48 <input name=subject required>
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
49 </p>
46
289718f121e4 use bbcode editor
Franklin Schmidt <fschmidt@gmail.com>
parents: 42
diff changeset
50 <p editor></p>
8
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
51 <p><input type=submit></p>
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
52 </form>
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
53 </div>
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
54 <% footer() %>
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
55 </body>
46
289718f121e4 use bbcode editor
Franklin Schmidt <fschmidt@gmail.com>
parents: 42
diff changeset
56 <script>
289718f121e4 use bbcode editor
Franklin Schmidt <fschmidt@gmail.com>
parents: 42
diff changeset
57 bbcodeCreate('p[editor]');
289718f121e4 use bbcode editor
Franklin Schmidt <fschmidt@gmail.com>
parents: 42
diff changeset
58 </script>
8
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
59 </html>
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
60 <%
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
61 end