2009-01-25 22:12:45 -07:00
|
|
|
comment_file_types=(md html)
|
2009-01-30 08:10:14 -07:00
|
|
|
|
|
|
|
fn conf_enable_comments {
|
|
|
|
if(~ $1 -n) {
|
|
|
|
allow_new_user_comments=yes
|
|
|
|
shift
|
|
|
|
}
|
2009-10-19 18:09:55 -06:00
|
|
|
if not if(~ $1 -a) {
|
|
|
|
bridge_anon_comments=yes
|
|
|
|
}
|
2009-01-30 08:10:14 -07:00
|
|
|
enable_comments=yes
|
|
|
|
groups_allowed_comments=$*
|
2009-02-07 17:22:46 -07:00
|
|
|
conf_enable_app bridge
|
2009-01-30 08:10:14 -07:00
|
|
|
}
|
|
|
|
|
2009-01-08 19:08:02 -07:00
|
|
|
fn bridge_init {
|
2009-02-26 03:42:20 -07:00
|
|
|
if(~ $#enable_comments 1 && ! ~ `{ls $local_path.$comment_file_types >[2]/dev/null|wc -l} 0) {
|
|
|
|
|
2009-02-15 20:46:21 -07:00
|
|
|
comments_dir=$sitedir$req_path'_werc/comments'
|
2009-02-26 03:42:20 -07:00
|
|
|
if(~ $REQUEST_METHOD GET && test -d $comments_dir)
|
2009-02-15 20:46:21 -07:00
|
|
|
ll_add handlers_body_foot template apps/bridge/comments_list.tpl
|
2009-01-30 08:10:14 -07:00
|
|
|
|
2009-10-19 18:28:10 -06:00
|
|
|
if(check_user $groups_allowed_comments || {~ $#logged_user 0 && ~ 1 $#allow_new_user_comments $#bridge_anon_comments}) {
|
2009-02-26 03:42:20 -07:00
|
|
|
|
|
|
|
if(~ $#post_arg_bridge_post 1) {
|
|
|
|
ll_add handlers_body_foot template apps/bridge/foot.tpl
|
2009-01-30 08:10:14 -07:00
|
|
|
|
2009-02-26 03:42:20 -07:00
|
|
|
if(mk_new_comment $comments_dir)
|
|
|
|
post_redirect $base_url^$req_path
|
|
|
|
if not
|
|
|
|
saved_comment_text=$post_arg_comment_text
|
|
|
|
}
|
|
|
|
if not if(~ $REQUEST_METHOD GET)
|
|
|
|
ll_add handlers_body_foot template apps/bridge/foot.tpl
|
2009-01-30 08:10:14 -07:00
|
|
|
}
|
2009-02-26 03:42:20 -07:00
|
|
|
if not if(~ $REQUEST_METHOD GET)
|
2010-04-16 19:05:13 -06:00
|
|
|
ll_add handlers_body_foot echo '<hr><p>To post a comment you need to <a href="/_users/login">login</a> first.</p>'
|
2009-01-30 08:10:14 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn validate_new_user {
|
|
|
|
usr=$1; pass=$2; pass2=$3
|
|
|
|
_status=()
|
2009-01-08 19:08:02 -07:00
|
|
|
|
2009-01-30 08:10:14 -07:00
|
|
|
if(~ $"usr '' || ! echo $usr |sed 1q|grep -s '^'$allowed_user_chars'+$')
|
|
|
|
_status='Requested user name is invalid, must match: '^$allowed_user_chars^'+'
|
|
|
|
if not if(test -d etc/users/$usr)
|
|
|
|
_status='Sorry, user name '''^$usr^''' already taken, please pick a different one.'
|
|
|
|
|
|
|
|
if(~ $"pass '' || ! ~ $"pass $"pass2)
|
|
|
|
_status=($_status 'Provided passwords don''t match.')
|
|
|
|
|
|
|
|
status=$_status
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn mk_new_comment {
|
|
|
|
_status=()
|
|
|
|
dir=$1
|
|
|
|
if(~ $"post_arg_comment_text '')
|
|
|
|
_status='Provide a comment!'
|
|
|
|
if not if(~ $#logged_user 0) {
|
|
|
|
if(! ~ $#allow_new_user_comments 0) {
|
|
|
|
if(validate_new_user $"post_arg_comment_user $post_arg_comment_passwd $post_arg_comment_passwd2) {
|
|
|
|
u=$post_arg_comment_user':'$post_arg_comment_passwd
|
2009-02-15 20:46:21 -07:00
|
|
|
dir=$comments_dir^'_pending'
|
2009-01-30 08:48:49 -07:00
|
|
|
# XXX: This doesn't work because we then do a redirect.
|
2009-01-30 08:10:14 -07:00
|
|
|
notify_notes='Saved comment and registration info, they will be enabled when approved by an admin.'
|
2009-01-23 23:11:39 -07:00
|
|
|
}
|
2009-01-30 08:10:14 -07:00
|
|
|
if not
|
|
|
|
_status=$status
|
2009-01-10 20:03:46 -07:00
|
|
|
}
|
2009-10-19 18:09:55 -06:00
|
|
|
if not if(! ~ $#bridge_anon_comments 0) {
|
|
|
|
if(~ $"post_arg_ima_robot 'not')
|
|
|
|
u='Glenda' # Anonymous
|
|
|
|
if not
|
|
|
|
_status='You are a robot!'
|
|
|
|
}
|
2009-01-30 08:10:14 -07:00
|
|
|
if not
|
|
|
|
_status='You need to log in to comment.'
|
2009-01-08 19:08:02 -07:00
|
|
|
}
|
2009-01-30 08:10:14 -07:00
|
|
|
if not if(check_user $groups_allowed_comments)
|
|
|
|
u=$logged_user
|
|
|
|
if not
|
2009-06-20 03:55:26 -06:00
|
|
|
_status='You are not a member of a group allowed to comment.'
|
2009-01-30 08:10:14 -07:00
|
|
|
|
|
|
|
if(~ $#_status 0) {
|
|
|
|
umask 002
|
2009-01-08 19:08:02 -07:00
|
|
|
|
2009-01-30 08:10:14 -07:00
|
|
|
dir=$dir'/'`{date -n} # FIXME Obvious race
|
|
|
|
mkdir -m 775 -p $dir &&
|
|
|
|
echo $u > $dir/user &&
|
2009-02-01 12:02:22 -07:00
|
|
|
echo $current_date_time > $dir/posted &&
|
2009-01-30 08:10:14 -07:00
|
|
|
echo $post_arg_comment_text > $dir/body
|
|
|
|
_s=$status
|
|
|
|
if(! ~ $"_s '') {
|
|
|
|
dprint 'ERROR XXX: Could not create comment: ' $_s
|
|
|
|
_status='Could not post comment due internal error, sorry.'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
notify_errors=$_status
|
|
|
|
status=$_status
|
2009-01-08 19:08:02 -07:00
|
|
|
}
|