X-Git-Url: http://git.plutz.net/?a=blobdiff_plain;f=widgets.sh;h=dd34bc0b627ae68b395d235fa0b024996cc45568;hb=21b87390a05a69a53d5c66e385443d1397273f1a;hp=3142b4485aedbdeece2d7bd89a0c090c063f4fb3;hpb=bbf0a951d1ff6106d1d2dd8032333b1b1ccd67f2;p=serve0 diff --git a/widgets.sh b/widgets.sh index 3142b44..dd34bc0 100644 --- a/widgets.sh +++ b/widgets.sh @@ -5,33 +5,106 @@ 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_refuri="$(URL "$PATH_INFO")?$(HTML "$QUERY_STRING")" + +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 \ + | while read tag; do + [ "$tag" = "$otag" ] \ + && cn=$((${cn:-0} + 1)) \ + || { + printf "%i %s\n" "$cn" "$otag" + cn=1 + } + otag="$tag" + done + printf "%i %s\n" "$cn" "$otag" +} |sort -rn |cut -f2- )" +w_tagcategories="$(printf %s "$w_tags" | cut -sd: -f1 | sort -u \ + |HTML |sed 's;:\;;:;g; s; \;;\n;g;')" +w_tags="$( printf %s "$w_tags" |HTML |sed 's;:\;;:;g; s; \;;\n;g;')" + +[ "$ORDER" = Name ] && w_coname=checked +[ "$ORDER" = Date ] && w_codate=checked +[ "$ORDER" = Length ] && w_colength=checked + +w_bookmarks(){ + local name='' cf='' cs='' bm="$_DATA/.index/bookmarks" proposed_name='' + [ ! -d "${bm%/*}" ] && return 0 + [ ! -f "$bm" ] && touch "$bm" + + [ "$SEARCH" ] && cs="$(STRING "$SEARCH")" + [ "$FILTER" ] && cf="$(STRING "$FILTER")" + + name="$(grep -m1 -aF " search=$cs filter=$cf${CR}" "$bm" |cut -f1 |UNSTRING)" + [ ! "$name" ] && proposed_name="$( + printf '%s\t%s' "$SEARCH" "$FILTER" \ + |sed -r '/^\t$/{ s;\t;All;; q;} + /.*\t$/{ s;\t$;;; q;} + /^\t.*/{ s;^\t;;; + :x; s;(^|[~^|])([^|^~:]+):;\1;; tx; + s;\^; and ;g; s;\|;,;g; s;~;not ;g; q;}' + )" + + printf '[form #bookmarks action=?a=bookmark method=POST + [a href="#" x] + [hidden "ref" "%s"] + [hidden "search" "%s"][hidden "filter" "%s"] + [label Name for current page:] + [input name="name" value="%s" placeholder="Name" ] + [button type="submit" %s]' \ + "$w_refuri" \ + "$(HTML "$SEARCH")" "$(HTML "$FILTER")" \ + "$(HTML "${name:-${proposed_name}}")" \ + "${name:+Update}${proposed_name:+Add}" + [ "$name" ] && printf ' [submit "delete" "delete" Delete]' + + sort "$bm" |while read -r name search filter; do + search="${search#search=}" filter="${filter#filter=}" filter="${filter%${CR}}" + [ "$search" = "${cs}" -a "$filter" = "${cf}" ] && continue + + name="$(UNSTRING "$name")"; + search="$(UNSTRING "${search}" |URL)"; + filter="$(UNSTRING "${filter}" |URL)"; + printf '[label .link %s] + [a .link target=blank href="?o=Name&s=%s&f=%s" by Name] + [a .link target=blank href="?o=Date&s=%s&f=%s" by Date] + [a .link target=blank href="?o=Length&s=%s&f=%s" by Length] + [br]' \ + "$(HTML "$name" |sed 's;,\;;&[wbr];g;')" \ + "$search" "$filter" \ + "$search" "$filter" \ + "$search" "$filter" + 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"] ] ' \ + "$w_coname" "$w_codate" "$w_colength" \ "$(HTML "$SEARCH")" } w_prefs(){ - local fakemp4 mode - 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] @@ -45,9 +118,7 @@ w_prefs(){ ] ' \ "$w_refuri" "$LISTSIZE" \ - "$([ "$mode" = index ] || printf checked)" \ - "$([ "$mode" = index ] && printf checked)" \ - "$([ "$fakemp4" = yes ] && printf checked)" + "${tm:-checked}" "${tm:+checked}" "$tf" } w_index(){ @@ -62,46 +133,47 @@ w_index(){ } w_advsearch(){ - local n lbid tag category tn filter f - filter="${FILTER}^" + 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.] - [hidden "ref" "%s"] - ' "$w_refuri" + 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)")" + 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 - [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] + [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="checked"')" $n \ - $n "$([ "$f" -a ! "${f%%~*}" ] || printf 'checked="checked"')" $n $n \ - $n "$([ "$f" -a ! "${f%%~*}" ] && printf 'checked="checked"')" $n $n - f="|${f#~}|" + $n "${f:+checked}" $n \ + $n "${t:-checked}" $n $n \ + $n "${t:+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 %s "$w_tags" \ - | { [ "$category" = '*' ] && grep -vF ':' || grep -wF "${category}"; } \ + 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 -avF ':' |grep -avxF '' || grep -awF "${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" + t=''; [ ! "${f%%*|${tag}|*}" ] && t=checked + printf '[option %s value="%s"\n%s]' "$t" "$tag" "${tag#*:}" done printf '\n]' done @@ -110,11 +182,14 @@ w_advsearch(){ printf '[fieldset .submit [select name=order [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] ][button type=submit Apply Filter]] - ]' + ]' \ + "$w_coname" \ + "$w_codate" \ + "$w_colength" } w_tagging(){ @@ -124,13 +199,11 @@ w_tagging(){ 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 '[fieldset [legend %s:][select name=tag size=4 multiple' "$category" printf %s "$w_tags" \ - | { [ "$category" = 'Tags' ] && grep -vF ':' || grep -wF "${category}"; } \ + | { [ "$category" = 'Tags' ] && grep -avF ':' | grep -avxF '' || grep -awF "${category}"; } \ | while read -r tag; do - [ ! "$tag" ] && continue - tag="$(HTML "$tag")"; tn="${tag#*:}" - printf '[option value="%s" %s]' "$tag" "$tn" + printf '[option value="%s"\n%s]' "$tag" "${tag#*:}" done printf ']]' done