thirdculture/werc/apps/dirdir/app.rc

60 lines
2.9 KiB
Text
Raw Normal View History

2024-07-18 14:09:32 -04:00
fn conf_enable_wiki {
enable_wiki=yes
wiki_editors_groups=$*
conf_enable_app dirdir
2024-11-11 14:52:00 -05:00
if(~ $"conf_dirdir_index_type '')
conf_dirdir_index_type='md'
2024-07-18 14:09:32 -04:00
}
fn dirdir_init {
if(! ~ $#enable_wiki 0 && check_user $wiki_editors_groups) {
lp=$local_path
# werc.rc doesn't append /index when $local_path doesn't exist
# maybe it should, but for now we can fix it up here.
if(~ $lp */)
lp=$lp^'index'
2024-11-11 14:52:00 -05:00
dirdir_file=$lp.^$"conf_dirdir_index_type
if (test -f $lp.tpl) {
dirdir_file=$lp.tpl
}
2024-07-18 14:09:32 -04:00
dirdir_dir=$dirdir_file^'_werc/dirdir/'
if(~ 1 $#post_arg_dirdir_edit $#post_arg_dirdir_preview)
handler_body_main=(tpl_handler `{get_lib_file dirdir/edit.tpl apps/dirdir/edit.tpl})
2024-11-11 14:52:00 -05:00
if not if(~ 1 $#post_arg_dirdir_delete && ! ~ $#post_arg_dirdir_delete_yes 1)
handler_body_main=(tpl_handler `{get_lib_file dirdir/delete_sure.tpl apps/dirdir/delete_sure.tpl})
if not if(~ 1 $#post_arg_dirdir_delete_folder && ! ~ $#post_arg_dirdir_delete_yes 1)
handler_body_main=(tpl_handler `{get_lib_file dirdir/delete_sure.tpl apps/dirdir/delete_sure.tpl})
if not if(~ 1 $#post_arg_dirdir_delete && ! ~ $#post_arg_dirdir_delete_yes 0)
rm $dirdir_file
if not if(~ 1 $#post_arg_dirdir_delete_folder && ! ~ $#post_arg_dirdir_delete_yes 0)
rm -rf `{dirname $dirdir_file}
if not if(~ 1 $#post_arg_dirdir_add_child_file && ! ~ $#post_arg_dirdir_search 0)
touch `{dirname $dirdir_file}^'/'^$post_arg_dirdir_search^'.md'
if not if(~ 1 $#post_arg_dirdir_add_child_folder! ~ $#post_arg_dirdir_search 0)
mkdir `{dirname $dirdir_file}^'/'^$post_arg_dirdir_search
if not if(~ 1 $#post_arg_dirdir_upload_file_pressed && ! ~ $#post_arg_dirdir_file_name 0 && ! ~ $post_arg_dirdir_file_name "" && ! ~ $#post_arg_dirdir_upload_file 0)
mv /tmp/werc_file.*.data `{dirname $dirdir_file}^'/'^$post_arg_dirdir_file_name
if not if(~ 1 $#post_arg_dirdir_upload_file_pressed && ! ~ $#post_arg_dirdir_upload_file 0)
mv /tmp/werc_file.*.data `{dirname $dirdir_file}^'/'^$post_arg_dirdir_upload_file
2024-07-18 14:09:32 -04:00
if not if(! ~ '' $"post_arg_dirdir_save $"post_arg_edit_text)
save_page
2024-11-11 14:52:00 -05:00
if not if(~ $"handler_body_main '' || {~ $REQUEST_METHOD GET && test -f $local_path.md} || {~ $REQUEST_METHOD GET && test -f $local_path.tpl} )
2024-07-18 14:09:32 -04:00
ll_add handlers_bar_left tpl_handler apps/dirdir/sidebar_controls.tpl
}
}
fn save_page {
dirdir_verdir=$dirdir_dir/^`{date -n}^/
mkdir -p $dirdir_verdir
umask 002
# XXX Use a tmp file and mv(1) to ensure updates are atomic?
echo $logged_user > $dirdir_verdir/author
2024-11-11 14:52:00 -05:00
echo $post_arg_edit_text | dos2unix > $dirdir_verdir/data
echo $post_arg_edit_text | dos2unix > $dirdir_file
2024-07-18 14:09:32 -04:00
post_redirect $base_url^$req_path
}