]> git.plutz.net Git - shellwiki/blobdiff - macros/attachments
Merge commit '1b333027ebf2f2cef52548ad5e5f342dcf954464'
[shellwiki] / macros / attachments
index 7acc8063b32af36fa84db64f40d89e6367ca1460..bcd6722117985cf06bab8a0575755e2381fcb876 100755 (executable)
@@ -1,6 +1,8 @@
 #!/bin/sh
 
 . "$_EXEC/cgilite/cgilite.sh"
+. "$_EXEC/acl.sh"
+. "$_EXEC/tools.sh"
 
 page="$1"
 
@@ -8,7 +10,9 @@ if [ "${page#/}" = "$page" ]; then
   page="$(PATH "${PATH_INFO}/$page")"
 fi
 
-printf %s\\n '<ul class="attachment list">'
+acl_read "$page" || exit 0
+
+printf %s\\n '<ul class="macro attachment list">'
 
 for file in "$_EXEC/pages/$page/#attachments"/* "$_DATA/pages/$page/#attachments"/*; do
   [ "$file" = "$_EXEC/pages/$page/#attachments/${file##*/}" \
@@ -16,25 +20,10 @@ for file in "$_EXEC/pages/$page/#attachments"/* "$_DATA/pages/$page/#attachments
   stat="$(stat -c '%s %Y' -- "$file" 2>&-)" || continue
   size="${stat% *}" date="${stat#* }"
 
-  if [ $size -gt $((1024 * 1024 * 1024)) ]; then
-    size=$((size / 1024 / 1024 / 1024 * 10 + size / 1024 / 1024 % 1024 / 100))
-    size="$((size / 10)).$((size % 10)) GB"
-
-  elif [ $size -gt $((1024 * 1024)) ]; then
-    size=$((size / 1024 / 1024 * 10 + size / 1024 % 1024 / 100))
-    size="$((size / 10)).$((size % 10)) MB"
-
-  elif [ $size -gt $((1024)) ]; then
-    size=$((size / 1024 * 10 + size % 1024 / 100))
-    size="$((size / 10)).$((size % 10)) KB"
-
-  else
-    size="${size} B"
-  fi
-
-  printf '<li><span class=name>%s</span>
+  printf '<li><a class=name href="[attachment]/%s">%s</a>
           <span class=size>%s</span><span class=date>%s</span></li>' \
-    "$(HTML "${file##*/}")" "$size" "$(date -d @"$date" +"%F %T")"
+    "$(HTML "${file##*/}")" "$(HTML "${file##*/}")" \
+    "$(size_human "$size")" "$(date -d @"$date" +"%F %T")"
 done
 
 printf %s\\n '</ul>'