annotate src/lib/Shared.luan @ 60:8b5b1bce7d6b

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