0
|
1 local Luan = require "luan:Luan.luan"
|
|
2 local error = Luan.error
|
13
|
3 local ipairs = Luan.ipairs or error()
|
|
4 local set_metatable = Luan.set_metatable or error()
|
20
|
5 local type = Luan.type or error()
|
42
|
6 local Html = require "luan:Html.luan"
|
|
7 local html_encode = Html.encode or error()
|
3
|
8 local Http = require "luan:http/Http.luan"
|
6
|
9 local Io = require "luan:Io.luan"
|
|
10 local uri = Io.uri or error()
|
|
11 local Parsers = require "luan:Parsers.luan"
|
|
12 local json_parse = Parsers.json_parse or error()
|
0
|
13 local Forum = require "site:/lib/Forum.luan"
|
6
|
14 local forum_title = Forum.title or error()
|
|
15 local mailer_url = Forum.mailer_url or error()
|
3
|
16 local User = require "site:/lib/User.luan"
|
|
17 local Logging = require "luan:logging/Logging.luan"
|
|
18 local logger = Logging.logger "Shared"
|
0
|
19
|
|
20
|
|
21 local Shared = {}
|
|
22
|
|
23 function Shared.head()
|
|
24 %>
|
|
25 <meta name="viewport" content="width=device-width, initial-scale=1">
|
|
26 <style>
|
|
27 @import "/site.css";
|
|
28 </style>
|
7
|
29 <script src="/site.js"></script>
|
51
|
30 <script src="/bbcode/bbcode.js"></script>
|
0
|
31 <%
|
|
32 end
|
|
33
|
|
34 function Shared.header()
|
3
|
35 local user = User.current()
|
0
|
36 %>
|
7
|
37 <p style="text-align:center">Yes the aesthetics suck. Will be fixed later.</p>
|
0
|
38 <div header>
|
6
|
39 <a href="/"><%=forum_title%></a>
|
3
|
40 <% if user == nil then %>
|
54
|
41 <span>
|
|
42 <a href="/login.html">login</a>
|
|
43 / <a href="/register.html">register</a>
|
|
44 </span>
|
3
|
45 <% else %>
|
|
46 <a href="/account.html"><%=user.name_html%></a>
|
|
47 <% end %>
|
0
|
48 </div>
|
|
49 <%
|
|
50 end
|
|
51
|
|
52 function Shared.footer()
|
|
53 %>
|
|
54 <div footer>
|
|
55 <a href="/config.html">Configuration</a>
|
|
56 </div>
|
|
57 <%
|
|
58 end
|
|
59
|
4
|
60 function Shared.admin_header()
|
|
61 %>
|
|
62 <div header>
|
|
63 <a href="/private/admin.html">Admin</a>
|
|
64 </div>
|
|
65 <%
|
|
66 end
|
|
67
|
3
|
68 function Shared.base_url()
|
|
69 return Http.request.scheme.."://"..Http.request.headers["host"]
|
|
70 end
|
|
71
|
6
|
72 function Shared.call_mail_api(cmd,parameters)
|
|
73 local url = mailer_url.."/api/"..cmd..".json"
|
|
74 local options = {
|
|
75 parameters = parameters
|
|
76 }
|
|
77 local response = uri(url,options).read_text()
|
|
78 return json_parse(response)
|
|
79 end
|
|
80
|
13
|
81 local set_mt = {}
|
|
82 function set_mt.__index(table,key)
|
|
83 return false
|
|
84 end
|
|
85
|
|
86 function Shared.list_to_set(list)
|
|
87 local set = {}
|
|
88 for _, v in ipairs(list) do
|
|
89 set[v] = true
|
|
90 end
|
|
91 set_metatable(set,set_mt)
|
|
92 return set
|
|
93 end
|
|
94
|
20
|
95 function Shared.to_list(input)
|
|
96 if input == nil then
|
|
97 return {}
|
|
98 elseif type(input) == "table" then
|
|
99 return input
|
|
100 else
|
|
101 return {input}
|
|
102 end
|
|
103 end
|
|
104
|
42
|
105 local function delete_post()
|
|
106 %><a href="javascript:" onclick="deletePost(parentNode)">delete</a><%
|
|
107 end
|
|
108 Shared.delete_post = delete_post
|
|
109
|
|
110 function Shared.show_post(post,now)
|
44
|
111 local Bbcode = require "site:/bbcode/Bbcode.luan"
|
42
|
112 local bbcode_to_html = Bbcode.to_html or error()
|
|
113 %>
|
|
114 <div post="<%=post.id%>">
|
|
115 <hr>
|
|
116 <div author>
|
|
117 <img src="/images/profile.png">
|
|
118 <a href="/whatever"><%= post.author_name %></a>
|
|
119 <span ago date="<%=post.date%>"><% post.ago(now) %> ago</span>
|
|
120 </div>
|
|
121 <div output>
|
|
122 <% bbcode_to_html(post.content) %>
|
|
123 <p logged_in>
|
|
124 <a href="#">reply</a>
|
|
125 <span only_user="<%=html_encode(post.author_name)%>">
|
|
126 - <a href="javascript:ajax('/edit.js?post=<%=post.id%>')">edit</a>
|
|
127 <span delete_opton> - <span delete><%delete_post()%></span> </span>
|
|
128 <span>
|
|
129 </p>
|
|
130 </div>
|
|
131 <div edit></div>
|
|
132 </div>
|
|
133 <%
|
|
134 end
|
|
135
|
0
|
136 return Shared
|