From: Paul Hänsch Date: Wed, 18 Jul 2018 00:25:19 +0000 (+0200) Subject: Merge branch 'cgilite' of git.plutz.net:serve0 into cgilite X-Git-Url: http://git.plutz.net/?p=serve0;a=commitdiff_plain;h=0cebf2d806b0ef9d791987a4969143dc79403db7;hp=-c Merge branch 'cgilite' of git.plutz.net:serve0 into cgilite --- 0cebf2d806b0ef9d791987a4969143dc79403db7 diff --combined widgets.sh index 658d2bb,ead4c7c..ba47062 --- a/widgets.sh +++ b/widgets.sh @@@ -8,36 -8,16 +8,39 @@@ include_widgets="$0 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)" + | 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)" - CHECK(){ [ "$1" = "$2" ] && printf checked; } + [ "$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] + [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=? @@@ -50,16 -30,16 +53,16 @@@ [input name=s placeholder=Search value="%s"] ] ' \ - "$(CHECK "$ORDER" Name)" \ - "$(CHECK "$ORDER" Date)" \ - "$(CHECK "$ORDER" Length)" \ + "$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] @@@ -73,9 -53,7 +76,7 @@@ ] ' \ "$w_refuri" "$LISTSIZE" \ - "$([ "$mode" = index ] || CHECK)" \ - "$(CHECK "$mode" index)" \ - "$(CHECK "$fakemp4" yes)" + "${tm:-checked}" "${tm:+checked}" "$tf" } w_index(){ @@@ -90,47 -68,47 +91,47 @@@ } 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.] - ' + 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 [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#~}|" + $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 - catn="$(HTML "$category")" - lbid="cat_${n}_${catn}" - printf '[radio "cat_%i" "%s" .cat id="%s" %s][label for="%s" %s] + 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 "$catn" "$lbid" \ - "$([ ! "${f%%*|${category}:*}" -o ! "${category%\*}" ] && printf checked)" \ - "$lbid" "$catn" $n + $n "$category" "$t" "$lbid" "$lbid" "$category" $n - printf %s "$w_tags" \ - | { [ "$category" = '*' ] && grep -vF ':' || grep -wF "${category}"; } \ + printf '%s\n' "$w_tags" \ + | { [ "$category" = '*' ] && grep -vF ':' |grep -vxF '' || 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" + t=''; [ ! "${f%%*|${tag}|*}" ] && t=checked + printf '[option %s value="%s"\n%s]' "$t" "$tag" "${tag#*:}" done printf '\n]' done @@@ -144,9 -122,9 +145,9 @@@ [option value=Length %s Length] ][button type=submit Apply Filter]] ]' \ - "$(CHECK "$ORDER" Name)" \ - "$(CHECK "$ORDER" Date)" \ - "$(CHECK "$ORDER" Length)" + "$w_coname" \ + "$w_codate" \ + "$w_colength" } w_tagging(){ @@@ -156,13 -134,11 +157,11 @@@ 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 -vF ':' | grep -vxF '' || grep -wF "${category}"; } \ | while read -r tag; do - [ ! "$tag" ] && continue - tag="$(HTML "$tag")"; tn="${tag#*:}" - printf '[option value="%s"\n%s]' "$tag" "$tn" + printf '[option value="%s"\n%s]' "$tag" "${tag#*:}" done printf ']]' done