X-Git-Url: https://git.plutz.net/?a=blobdiff_plain;f=themes%2Fdefault.sh;h=7edd4b9986c60ad8e989f07a2740c7dc327d7c48;hb=7b1d88cf33d962e2ac98e03d0fd21327aee583a6;hp=6370166017775241ed9691cfca7c23c78b7282d7;hpb=4fb35b146e7aca6faf5945105ab36a270b7f1ad5;p=shellwiki diff --git a/themes/default.sh b/themes/default.sh index 6370166..7edd4b9 100755 --- a/themes/default.sh +++ b/themes/default.sh @@ -1,27 +1,192 @@ #!/bin/sh -theme_404(){ - printf "%s\r\n" "Status: 404 Not Found" +. "$_EXEC/tools.sh" + +theme_head(){ + printf ' + + + + ' "$_BASE" +} - theme_page '/[404]/' +theme_header(){ + printf '
%s
' "$(wiki '[wiki]/header/')" +} + +theme_footer(){ + printf '' "$(wiki '[wiki]/footer/' ||echo No footer)" } theme_page(){ local page="$1" title title="${page%/}"; title="${title##*/}" + if [ ! "$(mdfile "$page")" ]; then + theme_404 + return 0 + elif ! acl_read "$page"; then + theme_403 + return 0 + fi + + # Important! Web Server response including newline printf "%s\r\n" "Content-Type: text/html; charset=utf-8" "" cat <<-EOF - - + $(theme_head) $(HTML "${title}") -
-
$(wiki "$page" || printf 'Page not found')
- + $(theme_header) +
+ $(acl_write "$page" && printf %s \ + '' + ) +
+ $(wiki "$page" || printf 'Error while loading page
function "wiki" of index.sh returned with an error.') +
+
+ $(theme_footer) + + EOF +} + +theme_editor(){ + local page="$1" title + title="${page%/}"; title="${title##*/}" + + if [ ! "$(mdfile "$page")" ]; then + theme_404 + return 0 + elif ! acl_write "$page"; then + theme_403 + return 0 + fi + + # Important! Web Server response including newline + printf "%s\r\n" "Content-Type: text/html; charset=utf-8" "" + + cat <<-EOF + + + $(theme_head) + $(HTML "${title}") + + $(theme_header) +
+ + + + +
+ $(theme_footer) + + EOF +} + +theme_attachments(){ + local page="$1" title + title="${page%/}"; title="${title##*/}" + + if [ ! "$(mdfile "$page")" ]; then + theme_404 + return 0 + elif ! acl_read "$page"; then + theme_403 + return 0 + fi + + # Important! Web Server response including newline + printf "%s\r\n" "Content-Type: text/html; charset=utf-8" "" + + if acl_write "$page"; then + cat <<-EOF + + + $(theme_head) + Attachments $(HTML "${title}") + + $(theme_header) +
+
+ + +
+ +
+
+ $(theme_footer) + + EOF + else + cat <<-EOF + + + $(theme_head) + Attachments $(HTML "${title}") + + $(theme_header) +
+ +
+ $(theme_footer) EOF + fi +} + +theme_login(){ + theme_page '/[wiki]/login/' +} + +theme_register(){ + theme_page '/[wiki]/register/' +} + +theme_403(){ + printf "%s\r\n" "Status: 403 Forbidden" + + if [ "$(mdfile '/[wiki]/403/')" ]; then + theme_page '/[wiki]/403/' + else + printf "Content-Length: 0\r\n\r\n" + fi +} + +theme_404(){ + printf "%s\r\n" "Status: 404 Not Found" + + if [ "$(mdfile '/[wiki]/404/')" ]; then + theme_page '/[wiki]/404/' + else + printf "Content-Length: 0\r\n\r\n" + fi }