Compare commits
3 Commits
2773ba5243
...
ccb2819b01
Author | SHA1 | Date | |
---|---|---|---|
ccb2819b01 | |||
fbe582ccbc | |||
22f97dcc82 |
6
app.lua
6
app.lua
@ -1,6 +1,8 @@
|
||||
local lapis = require("lapis")
|
||||
local app = lapis.Application()
|
||||
local constants = require("constants")
|
||||
local babycode = require("lib.babycode")
|
||||
local html_escape = require("lapis.html").escape
|
||||
|
||||
local db = require("lapis.db")
|
||||
-- sqlite starts without foreign key enforcement
|
||||
@ -26,6 +28,10 @@ local function inject_methods(req)
|
||||
req.infobox_message = function (_, s)
|
||||
return util.infobox_message(s)
|
||||
end
|
||||
|
||||
req.babycode_to_html = function (_, bb)
|
||||
return babycode.to_html(bb, html_escape)
|
||||
end
|
||||
|
||||
util.pop_infobox(req)
|
||||
end
|
||||
|
@ -1,4 +1,6 @@
|
||||
local app = require("lapis").Application()
|
||||
local babycode = require("lib.babycode")
|
||||
local html_escape = require("lapis.html").escape
|
||||
|
||||
local db = require("lapis.db")
|
||||
local constants = require("constants")
|
||||
@ -225,11 +227,15 @@ app:post("user_settings", "/:username/settings", function(self)
|
||||
end
|
||||
|
||||
local status = self.params.status:sub(1, 100)
|
||||
local original_sig = self.params.signature or ""
|
||||
local rendered_sig = babycode.to_html(original_sig, html_escape)
|
||||
|
||||
target_user:update({
|
||||
status = status,
|
||||
signature_original_markup = original_sig,
|
||||
signature_rendered = rendered_sig,
|
||||
})
|
||||
util.inject_infobox(self, "Status updated.")
|
||||
util.inject_infobox(self, "Settings updated.")
|
||||
return {redirect_to = self:url_for("user_settings", {username = self.params.username})}
|
||||
end)
|
||||
|
||||
|
@ -10,7 +10,7 @@ Constants.PermissionLevel = {
|
||||
|
||||
Constants.FULL_POSTS_QUERY = [[
|
||||
SELECT
|
||||
posts.id, posts.created_at, post_history.content, post_history.edited_at, users.username, users.status, avatars.file_path AS avatar_path, posts.thread_id, users.id AS user_id, post_history.original_markup
|
||||
posts.id, posts.created_at, post_history.content, post_history.edited_at, users.username, users.status, avatars.file_path AS avatar_path, posts.thread_id, users.id AS user_id, post_history.original_markup, users.signature_rendered
|
||||
FROM
|
||||
posts
|
||||
JOIN
|
||||
|
@ -107,6 +107,12 @@ body {
|
||||
grid-area: post-content;
|
||||
padding: 20px;
|
||||
margin-right: 25%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.post-inner {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
pre code {
|
||||
@ -154,6 +160,14 @@ pre code {
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
blockquote {
|
||||
padding: 10px 20px;
|
||||
margin: 10px;
|
||||
border-radius: 4px;
|
||||
border-left: 10px solid rgb(229.84, 231.92, 227.28);
|
||||
background-color: rgb(135.1928346457, 145.0974015748, 123.0025984252);
|
||||
}
|
||||
|
||||
.user-posts {
|
||||
display: grid;
|
||||
grid-template-columns: 200px 1fr;
|
||||
|
@ -37,6 +37,8 @@ function babycode.to_html(s, escape_html)
|
||||
text = text:gsub("%[b%](.-)%[/b%]", "<strong>%1</strong>")
|
||||
text = text:gsub("%[i%](.-)%[/i%]", "<em>%1</em>")
|
||||
text = text:gsub("%[s%](.-)%[/s%]", "<del>%1</del>")
|
||||
|
||||
text = text:gsub("%[quote%](.-)%[/quote%]", "<blockquote>%1</blockquote>")
|
||||
|
||||
-- replace loose links
|
||||
text = text:gsub("(https?://[%w-_%.%?%.:/%+=&~%@#%%]+[%w-/])", function(url)
|
||||
|
@ -68,4 +68,9 @@ return {
|
||||
schema.add_column("post_history", "original_markup", types.text{null = false})
|
||||
schema.add_column("post_history", "markup_language", types.text{default = "babycode"})
|
||||
end,
|
||||
|
||||
[10] = function ()
|
||||
schema.add_column("users", "signature_original_markup", types.text{default = ""})
|
||||
schema.add_column("users", "signature_rendered", types.text{default = ""})
|
||||
end,
|
||||
}
|
||||
|
@ -143,6 +143,12 @@ body {
|
||||
grid-area: post-content;
|
||||
padding: 20px;
|
||||
margin-right: 25%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.post-inner {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
pre code {
|
||||
@ -192,6 +198,14 @@ pre code {
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
blockquote {
|
||||
padding: 10px 20px;
|
||||
margin: 10px;
|
||||
border-radius: 4px;
|
||||
border-left: 10px solid $lighter;
|
||||
background-color: $dark2;
|
||||
}
|
||||
|
||||
.user-posts {
|
||||
display: grid;
|
||||
grid-template-columns: 200px 1fr;
|
||||
|
@ -4,5 +4,5 @@
|
||||
<button type=button id="post-editor-strike" title="Insert Strikethrough">S</button>
|
||||
<button type=button id="post-editor-code" title="Insert Code block">Code</button>
|
||||
</span>
|
||||
<textarea class="babycode-editor" name="<%= ta_name %>" id="post_content" placeholder="Post body" required><%- prefill or "" %></textarea>
|
||||
<textarea class="babycode-editor" name="<%= ta_name %>" id="<%= ta_id or "post_content" %>" placeholder="<%= ta_placeholder or "Post body"%>" <%= not optional and "required" or "" %>><%- prefill or "" %></textarea>
|
||||
<script src="/static/js/post-editor.js"></script>
|
||||
|
@ -17,45 +17,59 @@
|
||||
|
||||
<div class="post-content-container"<%= is_latest and 'id=latest-post' or "" %>>
|
||||
<div class="post-info">
|
||||
<a href="<%= url_for("thread", {slug = thread.slug}, {page = page}) .. "#post-" .. post.id %>" title="Permalink"><i>
|
||||
<% if tonumber(post.edited_at) > tonumber(post.created_at) then -%>
|
||||
Edited at <%= os.date("%c", post.edited_at) %>
|
||||
<% else -%>
|
||||
Posted at <%= os.date("%c", post.created_at) %>
|
||||
<% end -%>
|
||||
</i></a>
|
||||
<span>
|
||||
<%
|
||||
local show_edit = me.id == post.user_id and not me:is_guest() and not ntob(thread.is_locked) and not no_reply
|
||||
if show_edit then
|
||||
<%
|
||||
local post_url = url_for("thread", {slug = thread.slug}, {page = page}) .. "#post-" .. post.id
|
||||
%>
|
||||
<a href="<%= post_url %>" title="Permalink"><i>
|
||||
<% if tonumber(post.edited_at) > tonumber(post.created_at) then -%>
|
||||
Edited at <%= os.date("%c", post.edited_at) %>
|
||||
<% else -%>
|
||||
Posted on <%= os.date("%c", post.created_at) %>
|
||||
<% end -%>
|
||||
</i></a>
|
||||
<span>
|
||||
<%
|
||||
local show_edit = me.id == post.user_id and not me:is_guest() and not ntob(thread.is_locked) and not no_reply
|
||||
if show_edit then
|
||||
%>
|
||||
<a class="linkbutton" href="<%= url_for("edit_post", {post_id = post.id}) %>">Edit</a>
|
||||
<% end %>
|
||||
<%
|
||||
local show_reply = true
|
||||
if ntob(thread.is_locked) and not me:is_mod() then
|
||||
show_reply = false
|
||||
elseif me:is_guest() then
|
||||
show_reply = false
|
||||
elseif edit then
|
||||
show_reply = false
|
||||
elseif no_reply then
|
||||
show_reply = false
|
||||
end
|
||||
if show_reply then
|
||||
local d = post.created_at < post.edited_at and post.edited_at or post.created_at
|
||||
local quote_src_text = ("On [url=%s]%s[/url], [url=%s]%s[/url] said:"):format(
|
||||
post_url, os.date("%c", d), url_for("user", {username = post.username}), post.username
|
||||
)
|
||||
local reply_text = ("%s\n[quote]%s[/quote]\n---\n\n"):format(quote_src_text, post.original_markup)
|
||||
%>
|
||||
<a class="linkbutton" href="<%= url_for("edit_post", {post_id = post.id}) %>">Edit</a>
|
||||
<button value="<%= reply_text %>" class="reply-button">Reply</button>
|
||||
<% end %>
|
||||
<%
|
||||
local show_reply = true
|
||||
if ntob(thread.is_locked) and not me:is_mod() then
|
||||
show_reply = false
|
||||
elseif me:is_guest() then
|
||||
show_reply = false
|
||||
elseif edit then
|
||||
show_reply = false
|
||||
elseif no_reply then
|
||||
show_reply = false
|
||||
end
|
||||
if show_reply then
|
||||
local d = post.created_at < post.edited_at and post.edited_at or post.created_at
|
||||
local reply_text = ("On %s, %s said:\n%s\n\n---\n\n"):format(os.date("%c", d), post.username, post.original_markup)
|
||||
%>
|
||||
<button value="<%= reply_text %>" class="reply-button">Reply</button>
|
||||
<% end %>
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
<div class="post-content">
|
||||
<% if not edit then %>
|
||||
<div class="post-inner">
|
||||
<%- post.content %>
|
||||
</div>
|
||||
<% if render_sig and #post.signature_rendered > 0 then %>
|
||||
<div class="signature-container">
|
||||
<hr>
|
||||
<%- post.signature_rendered %>
|
||||
</div>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<% render("views.common.babycode-editor", {
|
||||
cancel_url = url_for("thread", {slug = thread.slug}, {page = page}) .. "#post-" .. post.id,
|
||||
cancel_url = post_url,
|
||||
prefill = post.original_markup,
|
||||
ta_name = "new_content"
|
||||
}) %>
|
||||
|
@ -8,7 +8,7 @@
|
||||
<span>Posted in <a href="<%= url_for("topic", {slug = topic.slug}) %>"><%= topic.name %></a></span>
|
||||
</nav>
|
||||
<% for i, post in ipairs(posts) do %>
|
||||
<% render("views.threads.post", {post = post, is_latest = i == #posts}) %>
|
||||
<% render("views.threads.post", {post = post, render_sig = true, is_latest = i == #posts}) %>
|
||||
<% end %>
|
||||
</main>
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
<img src="<%= avatar_url(me) %>">
|
||||
<input id="file" type="file" name="avatar" accept="image/*" required>
|
||||
<div>
|
||||
<input type="submit" value="Update avatar" <%= disable_avatar and "disabled=disabled" %>>
|
||||
<input type="submit" value="Upload avatar" <%= disable_avatar and "disabled=disabled" %>>
|
||||
<% if not me:is_default_avatar() then %>
|
||||
<input type="submit" value="Clear avatar" formaction="<%= url_for("user_clear_avatar", {username = me.username}) %>" formnovalidate>
|
||||
<% end %>
|
||||
@ -16,8 +16,10 @@
|
||||
</form>
|
||||
<form method="post" action="">
|
||||
<label for="status">Status</label>
|
||||
<input type="text" id="status" name="status" value="<%= me.status %>" maxlength="30">
|
||||
<input type="submit" value="Save status">
|
||||
<input type="text" id="status" name="status" value="<%= me.status %>" maxlength="70" placeholder="Will be shown under your username. Max 70 characters">
|
||||
<label for="signature">Signature</label><br>
|
||||
<% render("views.common.babycode-editor-component", {ta_name = "signature", ta_id = "signature", prefill = me.signature_original_markup, ta_placeholder = "Will be shown under each of your posts", optional = true}) %>
|
||||
<input type="submit" value="Save settings">
|
||||
</form>
|
||||
<div>
|
||||
<a class="linkbutton critical" href="<%= url_for("user_delete_confirm", {username = me.username}) %>">Delete account</a>
|
||||
|
@ -29,7 +29,7 @@
|
||||
<% if tonumber(post.edited_at) > tonumber(post.created_at) then -%>
|
||||
Edited in <%= post.thread_title %> at <%= os.date("%c", post.edited_at) %>
|
||||
<% else -%>
|
||||
Posted in <%= post.thread_title %> at <%= os.date("%c", post.created_at) %>
|
||||
Posted in <%= post.thread_title %> on <%= os.date("%c", post.created_at) %>
|
||||
<% end -%>
|
||||
</i></a></div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user