X-Git-Url: http://git.plutz.net/?a=blobdiff_plain;f=widgets.sh;h=ead4c7c88c2c40fc6807ab4f7997579399e17856;hb=7068cdba834b18fd78cb48c3e0e1d72c40887a25;hp=dc16b30e0396f5244d8446b630b06b3dd6f5bcc9;hpb=c7333f20eb9e0f18c5cb1094a2a82411fab71812;p=serve0 diff --git a/widgets.sh b/widgets.sh index dc16b30..ead4c7c 100644 --- a/widgets.sh +++ b/widgets.sh @@ -5,28 +5,41 @@ include_widgets="$0" . "$_EXEC/cgilite/storage.sh" -w_tags="$(find "$_DATA/" -path '*/.index/meta' -exec cut -f4 '{}' + \ - | cut -d= -f2- |tr , '\n' | sort -u)" -w_tags="$(UNSTRING "$w_tags")" +w_refuri="$(HTML "$REQUEST_URI")" + +w_tags="$(find "$_DATA/" -path '*/.index/meta' -print0 \ + | xargs -r0 sed -r ' + s;^.*\t.*\t.*\ttags=(.*)\tcomment=.*\t.*\r$;\1;; + s;,;\n;g;'"$UNSTRING" \ + | sort -u |HTML |sed 's;:\;;:;g; s; \;;\n;g;')" +w_tagcategories="$(printf %s "$w_tags" | cut -sd: -f1 | uniq)" + +[ "$ORDER" = Name ] && w_coname=checked +[ "$ORDER" = Date ] && w_codate=checked +[ "$ORDER" = Length ] && w_colength=checked w_search(){ printf ' [form #search method=GET action=? [select name=o size=1 [option disabled=disabled Order By] - [option value=Name Name] - [option value=Date Date] - [option value=Length Length] + [option value=Name %s Name] + [option value=Date %s Date] + [option value=Length %s Length] ] [input name=s placeholder=Search value="%s"] ] ' \ + "$w_coname" "$w_codate" "$w_colength" \ "$(HTML "$SEARCH")" } w_prefs(){ - fakemp4="$(COOKIE fakemp4)" - mode="$(COOKIE mode)" + local tm tf + + tm=''; [ "$(COOKIE mode)" = index ] && tm=' ' + tf=''; [ "$(COOKIE fakemp4)" = yes ] && tf=checked + printf ' [form #prefs method="POST" action="?a=setprefs" [a href="#" x] @@ -39,10 +52,8 @@ w_prefs(){ [submit "store" "store" Set Cookie] ] ' \ - "$(HTML "$REQUEST_URI")" "$LISTSIZE" \ - "$([ "$mode" = index ] || printf checked)" \ - "$([ "$mode" = index ] && printf checked)" \ - "$([ "$fakemp4" = yes ] && printf checked)" + "$w_refuri" "$LISTSIZE" \ + "${tm:-checked}" "${tm:+checked}" "$tf" } w_index(){ @@ -53,26 +64,81 @@ 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 filter f t + filter="$(HTML "${FILTER}^" |sed 's;~\;;~;g; s;^\;;^;g; s;|\;;|;g; s;:\;;:;g;')" + + 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.]' + + for n in 1 2 3 4 5 6 7 8 9 10; do + f="${filter%%^*}"; filter="${filter#*^}" + + t=''; [ "$f" -a ! "${f%%~*}" ] && t=" " + + lbid="cat_${n}_(none)" + printf '[input .and type=checkbox name=and id="and_%i" %s][label for="and_%i" +and + ][fieldset .select + [radio "pol_%i" "pos" .pol %s #pol_pos_%i"][label for=pol_pos_%i Any] + [radio "pol_%i" "neg" .pol %s #pol_neg_%i"][label for=pol_neg_%i None] + [label .head Category:]' \ + $n "${f:+checked}" $n \ + $n "${t:-checked}" $n $n \ + $n "${t:+checked}" $n $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")" + f="|${f#~}|" + printf '*\n%s\n' "$w_tagcategories" \ + | while read -r category; do + lbid="cat_${n}_${category}" + + t='' + [ "$category" = '*' -a "${f%%|${category}:*}" ] && t=checked + [ "$category" != '*' -a ! "${f%%|${category}:*}" ] && t=checked + + printf '[radio "cat_%i" "%s" .cat %s id="%s"][label for="%s" %s] + [select name=tag_%s size=10 multiple' \ + $n "$category" "$t" "$lbid" "$lbid" "$category" $n + + printf '%s\n' "$w_tags" \ + | { [ "$category" = '*' ] && grep -vF ':' |grep -vxF '' || grep -wF "${category}"; } \ + | while read -r tag; do + t=''; [ ! "${f%%*|${tag}|*}" ] && t=checked + printf '[option %s value="%s"\n%s]' "$t" "$tag" "${tag#*:}" + 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 %s Name] + [option value=Date %s Date] + [option value=Length %s Length] + ][button type=submit Apply Filter]] + ]' \ + "$w_coname" \ + "$w_codate" \ + "$w_colength" +} + +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 '[fieldset [legend %s:][select name=tag size=4 multiple' "$category" + printf %s "$w_tags" \ + | { [ "$category" = 'Tags' ] && grep -vF ':' | grep -vxF '' || grep -wF "${category}"; } \ | while read -r tag; do - printf '[option value="%s" %s]' "$(HTML "$tag")" "$(HTML "${tag#*:}")" + printf '[option value="%s"\n%s]' "$tag" "${tag#*:}" done printf ']]' done