]> git.plutz.net Git - shellwiki/commitdiff
delete buttons in attachment list (non-functional)
authorPaul Hänsch <paul@plutz.net>
Tue, 10 May 2022 22:22:59 +0000 (00:22 +0200)
committerPaul Hänsch <paul@plutz.net>
Tue, 10 May 2022 22:22:59 +0000 (00:22 +0200)
themes/default.css
themes/default.sh

index d038d5ba8e984500e635039e4f05f0eefaf1da69..c8db7182216a943ab36f4932d2e682cd1e35a2e6 100644 (file)
@@ -80,6 +80,11 @@ body.editor textarea {
 
 /* === Attachments === */
 
+.attachment.list button[name=delete] {
+  font-size: .75em;
+  line-height: 1.25em;
+  margin-right: 1.25em;
+}
 .attachment.list .size,
 .attachment.list .date {
   font-size: .875em;
index 022a29ab4985bbad8dd05a8624fdbae6dc6084d9..7edd4b9986c60ad8e989f07a2740c7dc327d7c48 100755 (executable)
@@ -93,10 +93,19 @@ 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" ""
 
-  cat <<-EOF
+  if acl_write "$page"; then
+    cat <<-EOF
        <!DOCTYPE HTML>
        <html><head>
          $(theme_head)
@@ -109,6 +118,32 @@ theme_attachments(){
              <button type=submit name=action value=upload>Upload</button>
            </form>
 
+            <form method=POST><ul class="attachment list">
+           $(for file in "$_EXEC/pages/$page/#attachments"/* "$_DATA/pages/$page/#attachments"/*; do
+             [ "$file" = "$_EXEC/pages/$page/#attachments/${file##*/}" \
+                   -a -f "$_DATA/pages/$page/#attachments/${file##*/}" ] && continue
+             stat="$(stat -c '%s %Y' -- "$file" 2>&-)" || continue
+             size="${stat% *}" date="${stat#* }"
+           
+             printf '<li><button type=submit name=delete value="%s">Delete</button><a class=name href="%s">%s</a>
+                     <span class=size>%s</span><span class=date>%s</span></li>' \
+               "$(HTML "${file##*/}")" "$(HTML "${file##*/}")" "$(HTML "${file##*/}")" \
+               "$(size_human "$size")" "$(date -d @"$date" +"%F %T")"
+           done)
+            </ul></form>
+         </main>
+         $(theme_footer)
+       </body></html>
+       EOF
+  else
+    cat <<-EOF
+       <!DOCTYPE HTML>
+       <html><head>
+         $(theme_head)
+         <title>Attachments $(HTML "${title}")</title>
+       </head><body id="$(HTML "$page")[attachment]/">
+         $(theme_header)
+         <main>
             <ul class="attachment list">
            $(for file in "$_EXEC/pages/$page/#attachments"/* "$_DATA/pages/$page/#attachments"/*; do
              [ "$file" = "$_EXEC/pages/$page/#attachments/${file##*/}" \
@@ -116,15 +151,16 @@ theme_attachments(){
              stat="$(stat -c '%s %Y' -- "$file" 2>&-)" || continue
              size="${stat% *}" date="${stat#* }"
            
-             printf '<li><span class=name>%s</span>
+             printf '<li><a class=name href="%s">%s</a>
                      <span class=size>%s</span><span class=date>%s</span></li>' \
-               "$(HTML "${file##*/}")" "$(size_human "$size")" "$(date -d @"$date" +"%F %T")"
+               "$(HTML "${file##*/}")" "$(HTML "${file##*/}")" "$(size_human "$size")" "$(date -d @"$date" +"%F %T")"
            done)
             </ul>
          </main>
          $(theme_footer)
        </body></html>
        EOF
+  fi
 }
 
 theme_login(){