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