Handler interface reorg, take oportunity to cleanup default_master.tpl and move comments bits to bridge app.
This commit is contained in:
parent
11900bdb0e
commit
e75232761a
4 changed files with 80 additions and 91 deletions
|
|
@ -1,14 +1,15 @@
|
||||||
fn bridge_init {
|
fn bridge_init {
|
||||||
if(! ~ $#allowComments 0 && ~ $REQUEST_METHOD POST) {
|
if(! ~ $#allowComments 0) {
|
||||||
get_post_args comment_text
|
ll_add handlers_body_foot bridge_body_foot
|
||||||
|
if(get_post_args comment_text) {
|
||||||
|
dprint POST COMMNET $"comment_text
|
||||||
d=`{date -n} # FIXME Obvious race
|
d=`{date -n} # FIXME Obvious race
|
||||||
d=$local_path.md_werc/comments/$d/
|
d=$local_path^'_werc/comments/'^$d/
|
||||||
|
|
||||||
u=$logged_user
|
u=$logged_user
|
||||||
if(~ $#logged_user 0) {
|
if(~ $#logged_user 0) {
|
||||||
get_post_args comment_user_name comment_user_password
|
get_post_args comment_user_name comment_user_password
|
||||||
# TODO Should take this path too if the user can login but doesn't
|
# XXX Should do this too if user not in required group
|
||||||
# belong to required group
|
|
||||||
if(! login_user $comment_user_name $comment_user_password) {
|
if(! login_user $comment_user_name $comment_user_password) {
|
||||||
u=$comment_user_name ':' $comment_user_password
|
u=$comment_user_name ':' $comment_user_password
|
||||||
d=$d^'_pending'
|
d=$d^'_pending'
|
||||||
|
|
@ -22,5 +23,13 @@ fn bridge_init {
|
||||||
echo $u > $d/user
|
echo $u > $d/user
|
||||||
echo $comment_text > $d/body
|
echo $comment_text > $d/body
|
||||||
}
|
}
|
||||||
|
if not
|
||||||
|
dprint SSS $status
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn bridge_body_foot {
|
||||||
|
template apps/bridge/foot.tpl
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
25
apps/bridge/foot.tpl
Normal file
25
apps/bridge/foot.tpl
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
% cdir = $local_path^'_werc/comments'
|
||||||
|
% if(test -d $cdir) {
|
||||||
|
<hr /><h2>Comments</h2>
|
||||||
|
% for(c in `{ls $cdir/}) {
|
||||||
|
<div>By: '`{cat $c/user} '<br />
|
||||||
|
% cat $c/body | escape_html | sed 's,$,<br />,'
|
||||||
|
<hr /></div>
|
||||||
|
% }
|
||||||
|
% }
|
||||||
|
|
||||||
|
% get_post_args action
|
||||||
|
% dprint XXX $"action
|
||||||
|
|
||||||
|
<hr /><hr />
|
||||||
|
<form action="" method="post">
|
||||||
|
% if(! check_user) {
|
||||||
|
User: <input type="text" name="comment_user_name" value="" />
|
||||||
|
Password: <input type="password" name="comment_user_password" value="" />
|
||||||
|
<small>If you are not registered enter your desired user/password and your account will be created when your comment is approved.</small>
|
||||||
|
% }
|
||||||
|
|
||||||
|
<textarea name="comment_text" id="comment_text" cols="80" rows="16"></textarea>
|
||||||
|
<input type="submit" name="post_comment" value="Post a comment" />
|
||||||
|
</form>
|
||||||
|
|
||||||
66
bin/werc.rc
66
bin/werc.rc
|
|
@ -58,8 +58,6 @@ fn gensidebar {
|
||||||
|
|
||||||
|
|
||||||
# Handlers
|
# Handlers
|
||||||
fn set_handler { handler=$* }
|
|
||||||
|
|
||||||
fn md_handler { cat $* | $formatter }
|
fn md_handler { cat $* | $formatter }
|
||||||
|
|
||||||
fn tpl_handler { template $1 }
|
fn tpl_handler { template $1 }
|
||||||
|
|
@ -86,68 +84,48 @@ fn dir_listing_handler {
|
||||||
echo '</ul>'
|
echo '</ul>'
|
||||||
}
|
}
|
||||||
|
|
||||||
fn select_handler {
|
fn setup_handlers {
|
||||||
|
|
||||||
if(test -f $local_path.md)
|
if(test -f $local_path.md)
|
||||||
set_handler md_handler $local_path.md
|
handler_body_main=(md_handler $local_path.md)
|
||||||
|
|
||||||
if not if(test -f $local_path.tpl)
|
if not if(test -f $local_path.tpl)
|
||||||
set_handler tpl_handler $local_path.tpl
|
handler_body_main=(tpl_handler $local_path.tpl)
|
||||||
|
|
||||||
if not if(test -f $local_path.html)
|
if not if(test -f $local_path.html)
|
||||||
set_handler html_handler $local_path.html
|
handler_body_main=(html_handler $local_path.html)
|
||||||
|
|
||||||
# Global tpl (eg sitemap.tpl), should take precedence over txt handler!
|
# Global tpl (eg sitemap.tpl), should take precedence over txt handler!
|
||||||
if not if(test -f lib^$req_path^.tpl)
|
if not if(test -f lib^$req_path^.tpl)
|
||||||
set_handler tpl_handler lib^$req_path^.tpl
|
handler_body_main=(tpl_handler lib^$req_path^.tpl)
|
||||||
|
|
||||||
if not if(test -f $local_path.txt)
|
if not if(test -f $local_path.txt)
|
||||||
set_handler txt_handler $local_path.txt
|
handler_body_main=(txt_handler $local_path.txt)
|
||||||
|
|
||||||
# Apps
|
# Apps
|
||||||
if not if(! ~ $#enabled_apps 0 && select_apps)
|
if(! ~ $#enabled_apps 0)
|
||||||
set_handler app_handler
|
init_apps
|
||||||
|
|
||||||
# Dir listing
|
# Dir listing
|
||||||
if not if(~ $local_path */index)
|
if(~ $#handler_body_main 0 && ~ $local_path */index)
|
||||||
set_handler dir_listing_handler $local_path
|
set_handler dir_listing_handler $local_path
|
||||||
|
# Explicit .html urls, the web server might handle this first!
|
||||||
# Explicit .html urls, unfortunately usually the web server will handle this as static files
|
if not if(~ $#handler_body_main 0 && ~ $local_path *.html && test -f $local_path)
|
||||||
if not if(~ $local_path *.html && test -f $local_path)
|
|
||||||
perm_redirect `{ echo $req_path|sed 's/.html$//' }
|
perm_redirect `{ echo $req_path|sed 's/.html$//' }
|
||||||
|
|
||||||
# Fallback static file handler
|
# Fallback static file handler
|
||||||
if not if(test -f $local_path) {
|
if not if(~ $#handler_body_main 0 && test -f $local_path)
|
||||||
m='text/plain'
|
static_file $local_path
|
||||||
if(~ $req_path *.css)
|
|
||||||
m='text/css'
|
|
||||||
if not if(~ $req_path *.ico)
|
|
||||||
m='image/x-icon'
|
|
||||||
if not if(~ $req_path *.png)
|
|
||||||
m='image/png'
|
|
||||||
if not if(~ $req_path *.jpg *.jpeg)
|
|
||||||
m='image/jpeg'
|
|
||||||
if not if(~ $req_path *.gif)
|
|
||||||
m='image/gif'
|
|
||||||
if not if(~ $req_path *.pdf)
|
|
||||||
m='application/pdf'
|
|
||||||
|
|
||||||
echo 'Content-Type: '^$m
|
|
||||||
echo
|
|
||||||
cat $local_path
|
|
||||||
exit
|
|
||||||
}
|
|
||||||
|
|
||||||
# File not found
|
# File not found
|
||||||
if not {
|
if not if(~ $#handler_body_main 0) {
|
||||||
set_handler tpl_handler `{get_lib_file 404.tpl}
|
set_handler tpl_handler `{get_lib_file 404.tpl}
|
||||||
dprint 'NOT FOUND: '$SERVER_NAME^$"REQUEST_URI^' - '^$"HTTP_REFERER^' - '^$"HTTP_USER_AGENT
|
dprint 'NOT FOUND: '$SERVER_NAME^$"REQUEST_URI^' - '^$"HTTP_REFERER^' - '^$"HTTP_USER_AGENT
|
||||||
echo 'Status: 404 Not Found'
|
echo 'Status: 404 Not Found'
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn genbody { $handler(1) $handler(2-) }
|
fn run_handlers {
|
||||||
|
for(h in $*)
|
||||||
|
run_handler $$h
|
||||||
|
}
|
||||||
|
fn run_handler {
|
||||||
|
$*(1) $*(2-)
|
||||||
|
}
|
||||||
|
|
||||||
# Careful, the proper p9p path might not be set until initrc.local is sourced
|
# Careful, the proper p9p path might not be set until initrc.local is sourced
|
||||||
path=(. $PLAN9/bin ./bin/ /bin/ /usr/bin)
|
path=(. $PLAN9/bin ./bin/ /bin/ /usr/bin)
|
||||||
|
|
@ -226,7 +204,7 @@ if(~ $pageTitle '')
|
||||||
if not
|
if not
|
||||||
pageTitle=$"pageTitle^' | '^$"siteTitle^' '^$"siteSubTitle
|
pageTitle=$"pageTitle^' | '^$"siteTitle^' '^$"siteSubTitle
|
||||||
|
|
||||||
select_handler
|
setup_handlers
|
||||||
|
|
||||||
if(! ~ $#debug 0)
|
if(! ~ $#debug 0)
|
||||||
dprint ' '$"SERVER_NAME^$"REQUEST_URI' - '$"HTTP_USER_AGENT' - '$"REQUEST_METHOD' - '$"handler
|
dprint ' '$"SERVER_NAME^$"REQUEST_URI' - '$"HTTP_USER_AGENT' - '$"REQUEST_METHOD' - '$"handler
|
||||||
|
|
|
||||||
|
|
@ -42,39 +42,16 @@ gensidebar
|
||||||
% }
|
% }
|
||||||
|
|
||||||
<div id="main-copy">
|
<div id="main-copy">
|
||||||
% genbody
|
|
||||||
|
|
||||||
% if(! ~ $#allowComments 0) {
|
% run_handlers $handlers_body_head
|
||||||
|
|
||||||
%{
|
% run_handler $handler_body_main
|
||||||
cdir = $local_path.md_werc/comments
|
|
||||||
if(test -d $cdir) {
|
% run_handlers $handlers_body_foot
|
||||||
echo '<hr /><h2>Comments</h2>'
|
|
||||||
for(c in `{ls $cdir/}) {
|
|
||||||
%}
|
|
||||||
<div>
|
|
||||||
% echo By: `{cat $c/user}
|
|
||||||
<br />
|
|
||||||
% cat $c/body | escape_html | sed 's,$,<br />,'
|
|
||||||
<hr /></div>
|
|
||||||
%{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
%}
|
|
||||||
<hr /><hr />
|
|
||||||
<form action="" method="post">
|
|
||||||
% if(! check_user) {
|
|
||||||
User: <input type="text" name="comment_user_name" value="" /> Password:
|
|
||||||
<input type="password" name="comment_user_password" value="" />
|
|
||||||
<small>If you are not registered enter your desired user/password and your account will be created when your comment is approved.</small>
|
|
||||||
% }
|
|
||||||
<textarea name="comment_text" id="comment_text" cols="80" rows="16"></textarea>
|
|
||||||
<input type="submit" name="post_comment" value="Post a comment" />
|
|
||||||
</form>
|
|
||||||
% }
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="footer">
|
<div id="footer">
|
||||||
% cat `{ get_lib_file footer.inc }
|
% cat `{ get_lib_file footer.inc }
|
||||||
|
% echo $"logged_user
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue