X-Git-Url: http://git.plutz.net/?a=blobdiff_plain;f=widgets.sh;h=dd34bc0b627ae68b395d235fa0b024996cc45568;hb=21b87390a05a69a53d5c66e385443d1397273f1a;hp=ba47062a9f775b9020b1cacebdd8a412edf1e0a8;hpb=0cebf2d806b0ef9d791987a4969143dc79403db7;p=serve0 diff --git a/widgets.sh b/widgets.sh index ba47062..dd34bc0 100644 --- a/widgets.sh +++ b/widgets.sh @@ -5,38 +5,80 @@ include_widgets="$0" . "$_EXEC/cgilite/storage.sh" -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)" +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 link bm - bm="$_DATA/.index/bookmarks" - - printf '[form #bookmarks action=?a=bookmarks method=POST - [a href="#" X] + 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"] - ' "$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 + [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 ']' } @@ -128,7 +170,7 @@ w_advsearch(){ $n "$category" "$t" "$lbid" "$lbid" "$category" $n printf '%s\n' "$w_tags" \ - | { [ "$category" = '*' ] && grep -vF ':' |grep -vxF '' || grep -wF "${category}"; } \ + | { [ "$category" = '*' ] && grep -avF ':' |grep -avxF '' || grep -awF "${category}"; } \ | while read -r tag; do t=''; [ ! "${f%%*|${tag}|*}" ] && t=checked printf '[option %s value="%s"\n%s]' "$t" "$tag" "${tag#*:}" @@ -159,7 +201,7 @@ w_tagging(){ | while read -r category; do printf '[fieldset [legend %s:][select name=tag size=4 multiple' "$category" printf %s "$w_tags" \ - | { [ "$category" = 'Tags' ] && grep -vF ':' | grep -vxF '' || grep -wF "${category}"; } \ + | { [ "$category" = 'Tags' ] && grep -avF ':' | grep -avxF '' || grep -awF "${category}"; } \ | while read -r tag; do printf '[option value="%s"\n%s]' "$tag" "${tag#*:}" done