Updates to blagh: Allow setting date of new posts, blog-editors default group, provide better error repporting using new notification framework, plus other bug fixes.
This commit is contained in:
parent
070ba578f4
commit
58982018d4
2 changed files with 37 additions and 20 deletions
|
|
@ -17,8 +17,12 @@ fn blagh_init {
|
||||||
# && test -d / `{echo '-a -d '^$blagh_root^$blagh_dirs}
|
# && test -d / `{echo '-a -d '^$blagh_root^$blagh_dirs}
|
||||||
blagh_url=$base_url^$blagh_uri
|
blagh_url=$base_url^$blagh_uri
|
||||||
blagh_root=$sitedir^$blagh_uri
|
blagh_root=$sitedir^$blagh_uri
|
||||||
if(check_user $blog_editors admin) {
|
if(check_user $blog_editors blog-editors) {
|
||||||
editor_mode=on
|
editor_mode=on
|
||||||
|
if(~ $"post_arg_date '')
|
||||||
|
post_date=`{/bin/date +%F|sed 's,-,/,g'}
|
||||||
|
if not
|
||||||
|
post_date=$post_arg_date
|
||||||
ll_add handlers_bar_left echo '<a href="'$blagh_uri'new_post">Make a new post</a>'
|
ll_add handlers_bar_left echo '<a href="'$blagh_uri'new_post">Make a new post</a>'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -35,11 +39,12 @@ fn blagh_init {
|
||||||
blagh_setup_feed_handlers rss20.tpl
|
blagh_setup_feed_handlers rss20.tpl
|
||||||
case $blagh_uri^new_post
|
case $blagh_uri^new_post
|
||||||
if(! ~ $#editor_mode 0) {
|
if(! ~ $#editor_mode 0) {
|
||||||
if(~ $REQUEST_METHOD GET)
|
handler_body_main=( tpl_handler `{get_lib_file blagh/new_post.tpl apps/blagh/new_post.tpl} )
|
||||||
handler_body_main=( tpl_handler `{get_lib_file blagh/new_post.tpl apps/blagh/new_post.tpl} )
|
if(~ $REQUEST_METHOD POST) {
|
||||||
if not if(~ $REQUEST_METHOD POST) {
|
if(mkbpost $"post_arg_body $"post_date $"post_arg_title $post_arg_id)
|
||||||
mkbpost $post_arg_id $post_arg_title $post_arg_body
|
post_redirect $blagh_uri
|
||||||
post_redirect $blagh_uri
|
if not
|
||||||
|
notify_errors=$status
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -73,21 +78,30 @@ fn get_post_list {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mkbpost {
|
fn mkbpost {
|
||||||
if(! ~ 0 $#1 $#2) {
|
bptext=$1
|
||||||
|
bpdate=$2
|
||||||
|
bptitle=$3
|
||||||
|
bpid=$4
|
||||||
|
_status=()
|
||||||
|
if(~ $"bptext '')
|
||||||
|
_status=($_status 'You need to provide a post body.')
|
||||||
|
if(! ~ $"bpdate [0-9][0-9][0-9][0-9]/[0-9][0-9]/[0-9][0-9])
|
||||||
|
_status=($_status 'Invalid date: '''^$"bpdate^'''') # XXX Should make semantic check.
|
||||||
|
|
||||||
|
if(~ $#_status 0) {
|
||||||
umask 002 # Let group write
|
umask 002 # Let group write
|
||||||
bptitle=$1
|
if(! ~ $"bpid '')
|
||||||
bptext=$2
|
bpid=`{echo -n '-'^$bpid | sed 's/'$forbidden_uri_chars'+/_/g; 1q'}
|
||||||
if(! ~ $#3 0)
|
|
||||||
bpid=`{echo -n '-'^$"bpid | sed 's/'$forbidden_uri_chars'+/_/g; 1q'}
|
|
||||||
d=`{/bin/date +%F|sed 's,-,/,g'}
|
|
||||||
|
|
||||||
ddir=$blagh_root^$d^'/'
|
ddir=$blagh_root^$bpdate^'/'
|
||||||
n=`{ls $ddir >[2]/dev/null |wc -l}
|
n=`{ls $ddir >[2]/dev/null |wc -l}
|
||||||
|
|
||||||
mkdir -p $ddir/$"n^$"bpid/
|
mkdir -p $ddir/$"n^$"bpid/
|
||||||
{
|
{
|
||||||
echo $bptitle
|
if(! ~ $"bptitle '') {
|
||||||
echo '========================================='
|
echo $bptitle
|
||||||
|
echo '========================================='
|
||||||
|
}
|
||||||
# TODO: Enable metadata
|
# TODO: Enable metadata
|
||||||
#echo '* Posted:' `{date}
|
#echo '* Posted:' `{date}
|
||||||
#if(! ~ $#logged_user 0)
|
#if(! ~ $#logged_user 0)
|
||||||
|
|
@ -96,6 +110,5 @@ fn mkbpost {
|
||||||
echo $bptext
|
echo $bptext
|
||||||
}> $ddir/$"n^$"bpid/index.md
|
}> $ddir/$"n^$"bpid/index.md
|
||||||
}
|
}
|
||||||
if not
|
status=$_status
|
||||||
status=Missing blog post arguments $"1 $"2
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,11 @@
|
||||||
|
<div>
|
||||||
|
% notices_handler
|
||||||
<form method="POST"><fieldset>
|
<form method="POST"><fieldset>
|
||||||
<legend>Submit a new blog post</legend>
|
<legend>Submit a new blog post</legend>
|
||||||
<textarea cols="80" rows=16" name="body"></textarea><br />
|
<textarea cols="94" rows=16" name="body">%($"post_arg_body%)</textarea><br />
|
||||||
<label>Title: <input size="64" type="text" name="title" /></label>
|
<label>Title: <input size="64" type="text" name="title" value="%($"post_arg_title%)" /></label>
|
||||||
<label>Id: <input size="8" type="text" name="id" /></label>
|
<label>Id: <input size="8" type="text" name="id" value="%($"post_arg_id%)" /></label>
|
||||||
|
<label>Date: <input size="10" maxlength="10" type="text" name="date" value="%($"post_date%)" /></label>
|
||||||
<input type="submit" value="Post" />
|
<input type="submit" value="Post" />
|
||||||
</fieldset></form>
|
</fieldset></form>
|
||||||
|
</div>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue