]> git.plutz.net Git - serve0/blobdiff - widgets.sh
speed and code optimisations
[serve0] / widgets.sh
index dc16b30e0396f5244d8446b630b06b3dd6f5bcc9..3142b4485aedbdeece2d7bd89a0c090c063f4fb3 100644 (file)
@@ -5,9 +5,13 @@ include_widgets="$0"
 
 . "$_EXEC/cgilite/storage.sh"
 
-w_tags="$(find "$_DATA/" -path '*/.index/meta' -exec cut -f4 '{}' + \
+w_refuri="$(HTML "$REQUEST_URI")"
+
+w_tags="$(find "$_DATA/" -path '*/.index/meta' -print0 \
+        | xargs -r0 cut -f4 \
         | cut -d= -f2- |tr , '\n' | sort -u)"
 w_tags="$(UNSTRING "$w_tags")"
+w_tagcategories="$(printf %s "$w_tags" |cut -sd: -f1 |sort -u)"
 
 w_search(){
   printf '
@@ -25,6 +29,7 @@ w_search(){
 }
 
 w_prefs(){
+  local fakemp4 mode
   fakemp4="$(COOKIE fakemp4)"
   mode="$(COOKIE mode)"
   printf '
@@ -39,7 +44,7 @@ w_prefs(){
     [submit "store" "store" Set Cookie]
   ]
   ' \
-  "$(HTML "$REQUEST_URI")" "$LISTSIZE" \
+  "$w_refuri" "$LISTSIZE" \
   "$([ "$mode" = index ] || printf checked)" \
   "$([ "$mode" = index ] && printf checked)" \
   "$([ "$fakemp4" = yes    ] && printf checked)"
@@ -53,26 +58,79 @@ w_index(){
     [checkbox "recursive" "yes" #spawn_recursive] [label for=spawn_recursive Include subdirectories]
     [submit "spawn" "spawn" Set up]
   ]
-  ' "$(HTML "$REQUEST_URI")"
+  ' "$w_refuri"
 }
 
-w_tagging(){
-  printf '[div #multitag [input type="hidden" name="ref" value="%s"]' "$(HTML "$REQUEST_URI")"
-  printf '[a href="#" Hide][br]'
+w_advsearch(){
+  local n lbid tag category tn filter f
+  filter="${FILTER}^"
+
+  printf '[form #advsearch action=?a=advsearch method=POST
+            [a href="#" Hide]
+            [p .help Select multiple tags from each category by holding down the [strong Ctrl] key on your keyboard.[br]
+            Refine the search further by setting additional search tags using the [strong "+and"] button.]
+            [hidden "ref" "%s"]
+         ' "$w_refuri"
+
+  for n in 1 2 3 4 5 6 7 8 9 10; do
+    f="${filter%%^*}"; filter="${filter#*^}"
+
+    lbid="$(HTML "cat_${n}_(none)")"
+    printf '[input .and type=checkbox name=and id="and_%i" %s][label for="and_%i" +and
+            ][fieldset .select
+            [input .pol type="radio" name=pol_%i %s id="pol_pos_%i"][label for=pol_pos_%i Any]
+            [input .pol type="radio" name=pol_%i %s id="pol_neg_%i"][label for=pol_neg_%i None]
+            [label .head Category:]' \
+            $n "$([ "$f" ] && printf 'checked="checked"')" $n \
+            $n "$([ "$f" -a ! "${f%%~*}" ] || printf 'checked="checked"')" $n $n \
+            $n "$([ "$f" -a ! "${f%%~*}" ] && printf 'checked="checked"')" $n $n
+    f="|${f#~}|"
+
+    printf '*\n%s\n' "$w_tagcategories" \
+    | while read -r category; do
+      lbid="$(HTML "cat_${n}_${category}")"
+      printf '[input .cat type=radio %s name="cat_%i" id="%s"][label for="%s" %s]
+              [select name=tag_%s size=10 multiple="multiple"' \
+              "$([ ! "${f%%*|${category}:*}" -o ! "${category%\*}" ] && printf 'checked="checked"')" \
+              $n "$lbid" "$lbid" "$(HTML "$category")" $n
 
-  printf '[fieldset [legend %s:][select name=tag size=4 multiple' "Tags"
-  printf %s "$w_tags" |grep -vF ":" |grep -vxF '' \
-  | while read -r tag; do
-    printf '[option value="%s" %s]' "$(HTML "$tag")" "$(HTML "$tag")"
+      printf %s "$w_tags" \
+      | { [ "$category" = '*' ] && grep -vF ':' || grep -wF "${category}"; } \
+      | while read -r tag; do
+        [ ! "$tag" ] && continue
+        tg="$(HTML "$tag")"; tn="${tg#*:}"
+        printf '[option %s value="%s" %s]' \
+          "$([ ! "${f%%*|${tag}|*}" ] && printf 'selected="selected"')" \
+          "$tg" "$tn"
+      done
+      printf '\n]'
+    done
+    printf ']'
   done
-  printf ']]'
 
-  printf %s "$w_tags" |cut -sd: -f1 |sort -u \
+  printf '[fieldset .submit [select name=order
+            [option disabled=disabled Order By]
+            [option value=Name Name]
+            [option value=Date Date]
+            [option value=Length Length]
+          ][button type=submit Apply Filter]]
+          ]'
+}
+
+w_tagging(){
+  local tag category
+  printf '[div #multitag [input type="hidden" name="ref" value="%s"]' "$w_refuri"
+  printf '[a href="#" Hide][br]'
+
+  printf 'Tags\n%s\n' "$w_tagcategories" \
   | while read -r category; do
     printf '[fieldset [legend %s:][select name=tag size=4 multiple' "$(HTML "$category")"
-    printf %s "$w_tags" |grep -wF "${category}" \
+    printf %s "$w_tags" \
+    | { [ "$category" = 'Tags' ] && grep -vF ':' || grep -wF "${category}"; } \
     | while read -r tag; do
-      printf '[option value="%s" %s]' "$(HTML "$tag")" "$(HTML "${tag#*:}")"
+      [ ! "$tag" ] && continue
+      tag="$(HTML "$tag")"; tn="${tag#*:}"
+      printf '[option value="%s" %s]' "$tag" "$tn"
     done
     printf ']]'
   done