X-Git-Url: http://git.plutz.net/?a=blobdiff_plain;f=widgets.sh;h=62a40271b735f06cd9a8bd255374d79457facdca;hb=875e8557d847cdcbd5c32ae42ff1c3fec451828d;hp=fd9e72e938a165b0087559528010b672985382a7;hpb=10c72cceebb66db98ad621181369edfa6294f924;p=serve0 diff --git a/widgets.sh b/widgets.sh index fd9e72e..62a4027 100644 --- a/widgets.sh +++ b/widgets.sh @@ -1,5 +1,18 @@ #!/bin/sh +[ -n "$include_widgets" ] && return 0 +include_widgets="$0" + +. "$_EXEC/cgilite/storage.sh" + +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 ' [form #search method=GET action=? @@ -12,20 +25,117 @@ w_search(){ [input name=s placeholder=Search value="%s"] ] ' \ - "$(HTML "$search")" + "$(HTML "$SEARCH")" } w_prefs(){ + local fakemp4 mode + fakemp4="$(COOKIE fakemp4)" + mode="$(COOKIE mode)" printf ' [form #prefs method="POST" action="?a=setprefs" + [a href="#" x] [hidden "ref" "%s"] [label for=prefs_ps Pagesize] [input #prefs_ps type=number name=pagesize value="%s"][br] + [radio "mode" "browse" %s #prefs_modebrowse] [label for=prefs_modebrowse Browse Folders][br] + [radio "mode" "index" %s #prefs_modeindex ] [label for=prefs_modeindex View Full Index][br] [checkbox "fakemp4" "yes" %s #prefs_fmp4] [label for=prefs_fmp4 Fake .MP4 file ending][br] [submit "store" "store" Set Cookie] ] ' \ - "$(HTML "$REQUEST_URI")" \ - "$(COOKIE pagesize |grep -m1 -xE '[0-9]+' || printf 50)" \ - "$(COOKIE fakemp4 |grep -m1 -qx yes && printf checked)" + "$w_refuri" "$LISTSIZE" \ + "$([ "$mode" = index ] || printf checked)" \ + "$([ "$mode" = index ] && printf checked)" \ + "$([ "$fakemp4" = yes ] && printf checked)" +} + +w_index(){ + [ -d "$_DATA/$ITEM/.index" ] || printf ' + [form #index method="POST" action="?a=spawnindex" + [hidden "ref" "%s"] + [label Set up for Index view: ] + [checkbox "recursive" "yes" #spawn_recursive] [label for=spawn_recursive Include subdirectories] + [submit "spawn" "spawn" Set up] + ] + ' "$w_refuri" +} + +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 + [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" ] && printf 'checked')" $n \ + $n "$([ "$f" -a ! "${f%%~*}" ] || printf 'checked')" $n $n \ + $n "$([ "$f" -a ! "${f%%~*}" ] && printf 'checked')" $n $n + f="|${f#~}|" + + printf '*\n%s\n' "$w_tagcategories" \ + | while read -r category; do + catn="$(HTML "$category")" + lbid="cat_${n}_${catn}" + printf '[radio "cat_%i" "%s" .cat id="%s" %s][label for="%s" %s] + [select name=tag_%s size=10 multiple' \ + $n "$catn" "$lbid" \ + "$([ ! "${f%%*|${category}:*}" -o ! "${category%\*}" ] && printf 'checked')" \ + "$lbid" "$catn" $n + + 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')" \ + "$tg" "$tn" + done + printf '\n]' + done + printf ']' + done + + 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" \ + | { [ "$category" = 'Tags' ] && grep -vF ':' || grep -wF "${category}"; } \ + | while read -r tag; do + [ ! "$tag" ] && continue + tag="$(HTML "$tag")"; tn="${tag#*:}" + printf '[option value="%s" %s]' "$tag" "$tn" + done + printf ']]' + done + + printf '[fieldset [legend New:][textarea name=newtag\n][button type=Submit Add Tags]]]' }