]> git.plutz.net Git - serve0/blobdiff - list.sh
updated for new cgilite escaping
[serve0] / list.sh
diff --git a/list.sh b/list.sh
index 58eb0628b99378367f230bcaf82e4797917b604d..259b9cdf3bfb6dba4b0cf2d583d5979f5477a04c 100644 (file)
--- a/list.sh
+++ b/list.sh
@@ -9,7 +9,7 @@ list_item() {
 
   if [ "$type" = dir ]; then
     name="${meta%%     *}";
-    display="$(HTML "$name")"; link="$(URL "$ITEM/$name")"
+    display="$(HTML "$name")"; link="$(URL "${PATH_INFO%/}/$name")"
     printf '[a .list .dir href="%s" %s]' "${link}?${w_refuri#*\?}" "$name"
     return 0
   fi
@@ -24,15 +24,15 @@ list_item() {
   if [ "$type" = metashort ]; then
     name="$(list_fullname "$(UNSTRING "${name%${CR}}")")"
   fi
-  if [ -f "$_DATA/$ITEM/$name" ]; then
-    link="$(URL "$ITEM/$name")"
-    name="$(HTML "$ITEM/$name")"
+  if [ -f "$_DATA/${PATH_INFO%/}/$name" ]; then
+    link="$(URL "${PATH_INFO%/}/${name#./}")"
+    name="$(HTML "${PATH_INFO%/}/${name#./}")"
     printf '[div .list .file
-              [a href="%s" [img src="%s?a=thumbnail"]][label %s]
+              [a href="%s" [img src="%s?a=thumbnail"]][label %s]
               [span .time %i:%02imin] [span .dim %ix%i] %s
               [checkbox "select" "%s" id="select_%s"][label for="select_%s" +]
             ]' \
-      "$link" "$link" "${name##*/}" \
+      "$link" "$link" "${name##/}" \
       "$((length / 60))" "$((length % 60))" \
       "$width" "$height" \
       "$(printf '%s\n' "${tags#tags=}" \
@@ -49,12 +49,12 @@ list_item() {
 [ "$FILTER" ] && list_fex="$(
   fex='p'
   STRING "$FILTER^" \
-  | sed -r 's;\^;\n;g; s;[]\/\(\)\\\^\$\?\.\+\*\;\[\{\}];\\&;g' \
+  | sed -E 's;\^;\n;g; s;[]\/\(\)\\\^\$\?\.\+\*\;\[\{\}];\\&;g' \
   | while read -r f; do
-    [ ! "${f#~}" ] && continue
-    [ "${f#~}" = "$f" ] \
+    [ "${f#\~}" ] || continue
+    [ "${f#\~}" = "$f" ] \
     && fex="/(\ttags=([^\t]*,)?)(${f})((,[^\t]*)?\t)/{${fex}}" \
-    || fex="/(\ttags=([^\t]*,)?)(${f#~})((,[^\t]*)?\t)/d; ${fex}"
+    || fex="/(\ttags=([^\t]*,)?)(${f#\~})((,[^\t]*)?\t)/d; ${fex}"
     printf '%s\n' "${fex}"
   done \
   | tail -n1
@@ -71,15 +71,16 @@ list_fullname(){
 
 list_filter(){
   if [ "$FILTER" ]; then
-    sed -nr "$list_fex"
+    printf "FEX: %s\n" "$list_fex" >&2
+    sed -nE "$list_fex"
   elif [ "${SEARCH#!}" != "${SEARCH}" ]; then
     grep -aviEe "$(STRING "${SEARCH}" \
-                 | sed -r ':x s;((^|[^\\])(\\\\)*)\+;\1 ;g; tx;
+                 | sed -E ':x s;((^|[^\\])(\\\\)*)\+;\1 ;g; tx;
                             s;((^|[^\\])(\\\\)*)\\\+;\1+;g;
                             s; ;\\+;g;')"
   elif [ "${SEARCH}" ]; then
     grep -aiEe "$(STRING "${SEARCH}" \
-                 | sed -r ':x s;((^|[^\\])(\\\\)*)\+;\1 ;g; tx;
+                 | sed -E ':x s;((^|[^\\])(\\\\)*)\+;\1 ;g; tx;
                             s;((^|[^\\])(\\\\)*)\\\+;\1+;g;
                             s; ;\\+;g;')"
   else
@@ -95,9 +96,11 @@ list_order(){
   elif [ $ORDER = Group ]; then
     sed -E '
       :X
-      s;^([^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^ 0-9]*)(-[0-9a-zA-Z_-]{11}\r|-ph[0-9a-f]{13}\r|-[0-9]{8}\r|[0-9]+\+?)(.*)$;\1\r\3 \2;;
+      s;^([^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^ 0-9]*)-([0-9a-zA-Z_-]{11}\r|ph[0-9a-f]{13}\r|[0-9]{8}\r)(.*)$;\1-\r\3 \2\n;;
+      t;
+      s;^([^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^ 0-9]*)([0-9]+)(.*)$;\1\r\3 \2;;
       tX;' \
-    | { sort -n -k7 |sort -s -k6,6; echo '0 0 0 tags= comment= _'; } \
+    | { sort -n -k7 -k8 -k9 -k10 -k11 |sort -s -k6,6 ; echo '0 0 0 tags= comment= _'; } \
     | while read -r length h w t c name; do
       if [ "${ln%% *}" = "${name%% *}" ]; then
         al=$((al + length))
@@ -111,7 +114,7 @@ list_order(){
       fi
       ln="$name"
     done \
-    | sort -s -n -k1 |sed -r 's;^[0-9]+\t;metashort\t;;' \
+    | sort -s -n -k1,1 |sed -E 's;^[0-9]+\t;metashort\t;;' \
     | sed -E ':X s;^([^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\r]*)\r([^ ]*) ([^ ]+)( .*)?$;\1\3\2\4;; tX'
   elif [ $ORDER = Length ]; then
     sort -sn -k1 |sed 's;^;metashort\t;;'
@@ -122,7 +125,7 @@ list_order(){
       printf '%i       %s      %s\n' \
              "$(stat -c %Y "$fn")" "${fm%      *}" "$fn"
     done \
-    | sort -srn -k1 |sed -r 's;^[0-9]+\t;metalong\t;;'
+    | sort -srn -k1 |sed -E 's;^[0-9]+\t;metalong\t;;'
   fi
 }