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