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()
|
3
|
6 local Http = require "luan:http/Http.luan"
|
6
|
7 local Io = require "luan:Io.luan"
|
|
8 local uri = Io.uri or error()
|
|
9 local Parsers = require "luan:Parsers.luan"
|
|
10 local json_parse = Parsers.json_parse or error()
|
0
|
11 local Forum = require "site:/lib/Forum.luan"
|
6
|
12 local forum_title = Forum.title or error()
|
|
13 local mailer_url = Forum.mailer_url or error()
|
3
|
14 local User = require "site:/lib/User.luan"
|
|
15 local Logging = require "luan:logging/Logging.luan"
|
|
16 local logger = Logging.logger "Shared"
|
0
|
17
|
|
18
|
|
19 local Shared = {}
|
|
20
|
|
21 function Shared.head()
|
|
22 %>
|
|
23 <meta name="viewport" content="width=device-width, initial-scale=1">
|
|
24 <style>
|
|
25 @import "/site.css";
|
|
26 </style>
|
7
|
27 <script src="/site.js"></script>
|
0
|
28 <%
|
|
29 end
|
|
30
|
|
31 function Shared.header()
|
3
|
32 local user = User.current()
|
0
|
33 %>
|
7
|
34 <p style="text-align:center">Yes the aesthetics suck. Will be fixed later.</p>
|
0
|
35 <div header>
|
6
|
36 <a href="/"><%=forum_title%></a>
|
3
|
37 <% if user == nil then %>
|
|
38 <a href="/login.html">login</a>
|
|
39 <% else %>
|
|
40 <a href="/account.html"><%=user.name_html%></a>
|
|
41 <% end %>
|
0
|
42 </div>
|
|
43 <%
|
|
44 end
|
|
45
|
|
46 function Shared.footer()
|
|
47 %>
|
|
48 <div footer>
|
|
49 <a href="/config.html">Configuration</a>
|
|
50 </div>
|
|
51 <%
|
|
52 end
|
|
53
|
4
|
54 function Shared.admin_header()
|
|
55 %>
|
|
56 <div header>
|
|
57 <a href="/private/admin.html">Admin</a>
|
|
58 </div>
|
|
59 <%
|
|
60 end
|
|
61
|
3
|
62 function Shared.base_url()
|
|
63 return Http.request.scheme.."://"..Http.request.headers["host"]
|
|
64 end
|
|
65
|
6
|
66 function Shared.call_mail_api(cmd,parameters)
|
|
67 local url = mailer_url.."/api/"..cmd..".json"
|
|
68 local options = {
|
|
69 parameters = parameters
|
|
70 }
|
|
71 local response = uri(url,options).read_text()
|
|
72 return json_parse(response)
|
|
73 end
|
|
74
|
13
|
75 local set_mt = {}
|
|
76 function set_mt.__index(table,key)
|
|
77 return false
|
|
78 end
|
|
79
|
|
80 function Shared.list_to_set(list)
|
|
81 local set = {}
|
|
82 for _, v in ipairs(list) do
|
|
83 set[v] = true
|
|
84 end
|
|
85 set_metatable(set,set_mt)
|
|
86 return set
|
|
87 end
|
|
88
|
20
|
89 function Shared.to_list(input)
|
|
90 if input == nil then
|
|
91 return {}
|
|
92 elseif type(input) == "table" then
|
|
93 return input
|
|
94 else
|
|
95 return {input}
|
|
96 end
|
|
97 end
|
|
98
|
0
|
99 return Shared
|