view src/edit.html.luan @ 12:ad1604c72156

fix bbcode
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 03 Jul 2022 22:01:23 -0600
parents 9674275019bb
children 24668255cede
line wrap: on
line source

local Luan = require "luan:Luan.luan"
local error = Luan.error
local Html = require "luan:Html.luan"
local html_encode = Html.encode or error()
local Io = require "luan:Io.luan"
local Http = require "luan:http/Http.luan"
local Shared = require "site:/lib/Shared.luan"
local head = Shared.head or error()
local header = Shared.header or error()
local footer = Shared.footer or error()
local Forum = require "site:/lib/Forum.luan"
local forum_title = Forum.title or error()
local Post = require "site:/lib/Post.luan"
local User = require "site:/lib/User.luan"


return function()
	local user = User.current_required()
	if user==nil then return end
	local post_id = Http.request.parameters.post or error()
	local post = Post.get_by_id(post_id) or error()
	if Http.request.method == "POST" then
		post.content = Http.request.parameters.content or error()
		post.save()
		Http.response.send_redirect("/thread.html?root="..post.root_id)
		return
	end
	Io.stdout = Http.response.text_writer()
%>
<!doctype html>
<html>
	<head>
<%		head() %>
		<title><%=forum_title%>: edit</title>
	</head>
	<body>
<%		header() %>
		<div content>
			<h1>edit: <%=post.root.subject_html%></h1>
			<p>This page will almost certainly be replaced by ajax, but whatever.  Hack for now.</p>
			<form method=post>
				<p><textarea name=content><%=html_encode(post.content)%></textarea></p>
				<p><input type=submit></p>
			</form>
		</div>
<%		footer() %>
	</body>
</html>
<%
end