X-Git-Url: http://git.plutz.net/?a=blobdiff_plain;f=widgets.sh;h=658d2bb2291d87bdf979f6912a6f5ecd62e3139c;hb=08413e5d4b8b918d78685c68fcaa43cf8ca0347a;hp=5cc4db9a7ec03d2526a5e6217896ee20a1b6ad48;hpb=a6d47d63a2ae5495d06c4514be273d5168b71855;p=serve0 diff --git a/widgets.sh b/widgets.sh index 5cc4db9..658d2bb 100644 --- a/widgets.sh +++ b/widgets.sh @@ -5,23 +5,54 @@ 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)" + +CHECK(){ [ "$1" = "$2" ] && printf checked; } + +w_bookmarks(){ + local name link bm + bm="$_DATA/.index/bookmarks" + + printf '[form #bookmarks action=?a=bookmarks method=POST + [a href="#" X] + [hidden "ref" "%s"] + ' "$w_refuri" + + name="$(grep -m1 -F " $(STRING "${REQUEST_URI}")" "$bm")" + printf '[hidden "link" "%s"][input name="name" value="%s"]' \ + "$(HTML "$link")" "$(HTML "$name")" + + sort "$bm" |while read -r name link; do + name="$(UNSTRING "$name")" + link="$(UNSTRING "$link")" + if [ "$link" != "$REQUEST_URI" ]; then + printf '[a href="%s"\n%s]' "$(HTML "$link")" "$(HTML "$name")" + fi + done + printf ']' +} 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"] ] ' \ + "$(CHECK "$ORDER" Name)" \ + "$(CHECK "$ORDER" Date)" \ + "$(CHECK "$ORDER" Length)" \ "$(HTML "$SEARCH")" } @@ -41,10 +72,10 @@ 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" \ + "$([ "$mode" = index ] || CHECK)" \ + "$(CHECK "$mode" index)" \ + "$(CHECK "$fakemp4" yes)" } w_index(){ @@ -55,27 +86,83 @@ w_index(){ [checkbox "recursive" "yes" #spawn_recursive] [label for=spawn_recursive Include subdirectories] [submit "spawn" "spawn" Set up] ] - ' "$(HTML "$REQUEST_URI")" + ' "$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.] + ' + + 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"\n%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 %s Name] + [option value=Date %s Date] + [option value=Length %s Length] + ][button type=submit Apply Filter]] + ]' \ + "$(CHECK "$ORDER" Name)" \ + "$(CHECK "$ORDER" Date)" \ + "$(CHECK "$ORDER" Length)" } w_tagging(){ local tag category - printf '[div #multitag [input type="hidden" name="ref" value="%s"]' "$(HTML "$REQUEST_URI")" + printf '[div #multitag [input type="hidden" name="ref" value="%s"]' "$w_refuri" printf '[a href="#" Hide][br]' - 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")" - done - printf ']]' - - printf %s "$w_tags" |cut -sd: -f1 |sort -u \ + 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"\n%s]' "$tag" "$tn" done printf ']]' done