From: paul Date: Thu, 12 Oct 2017 15:04:40 +0000 (+0000) Subject: introduce combined filter engine X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=16a2240ce347132c7000ca22989e83801cf3ebf0;p=confetti introduce combined filter engine svn path=/trunk/; revision=152 --- diff --git a/actions/filter_card.sh b/actions/filter_card.sh index 9de0288..b5ce333 100755 --- a/actions/filter_card.sh +++ b/actions/filter_card.sh @@ -21,11 +21,22 @@ cgi_post case "${_POST[choice]}"; in new_filter) - filter="${_POST[filter]}" - filtertype="${_POST[filtertype]}" + for n in '' {0..100}; do + debug "N: $n; ${_POST[filter$n]}" + [ -z "${_POST[filter$n]+x}" ] && break + filterval="${_POST[filter$n]}" + filtertype="${_POST[filtertype$n]}" + filter="${filtertype}:${filterval}${filter+^${filter}}" + done order="${_POST[order]}" - echo -n "Location: ?p=cards&filter=$filter&filtertype=$filtertype&order=$order\n\n" + echo -n "Location: ?p=cards&filter=$filter&filtertype=advanced&order=$order\n\n" ;; + #new_filter) + # filter="${_POST[filter]}" + # filtertype="${_POST[filtertype]}" + # order="${_POST[order]}" + # echo -n "Location: ?p=cards&filter=$filter&filtertype=$filtertype&order=$order\n\n" + # ;; *) echo -n "Location: ?p=cards\n\n" ;; diff --git a/pages/cards.sh b/pages/cards.sh index b0e7e94..506022f 100755 --- a/pages/cards.sh +++ b/pages/cards.sh @@ -64,52 +64,42 @@ list_categories() { } listcards() { - case "${_GET[filtertype]}" in - any) - grep -il "${_GET[filter]}" ${_DATA}/vcard/*vcf - ;; - name) - egrep -xil "(FN|NICKNAME|N)(;.+)*:.*${_GET[filter]}.*" ${_DATA}/vcard/*vcf - ;; - street) - egrep -xil "(ADR)(;.+)*:([^;]*;){2}${_GET[filter]}.*" ${_DATA}/vcard/*vcf - ;; - zip) - egrep -xil "(ADR)(;.+)*:([^;]*;){5}${_GET[filter]}.*" ${_DATA}/vcard/*vcf - ;; - telephone) - egrep -xil "(TEL)(;.+)*:.*${_GET[filter]}.*" ${_DATA}/vcard/*vcf - ;; - birth) - egrep -xil "(BDAY)(;.+)*:${_GET[filter]}.*" ${_DATA}/vcard/*vcf - ;; - course) - ;; - *) ls -1 ${_DATA}/vcard/*vcf 2>/dev/null - ;; - esac |case "${_GET[order]}" in - firstname) - while read file; do - fn=$(sed -rn 's:^N(;.+)*\:([^;]*;){1} *([^;]*).*$:\3:p' "$file") - echo "$fn\t$file" - done - ;; - lastname) - while read file; do - ln=$(sed -rn 's:^N(;.+)*\:([^;]*;){0} *([^;]*).*$:\3:p' "$file") - echo "$ln\t$file" - done - ;; - bdate) - while read file; do - bd=$(sed -rn 's:^BDAY(;.+)*\:(.*)$:\2:p' "$file") - echo "$bd\t$file" - done - ;; - *) - sed -r 's:^.*$:x\t&:' - ;; - esac |sort |sed -r 's:^.*\t(.*/)([^/]+)$:\2:' + filterex='s;^([^\n]+)\n.*$;\1;p' + printf '%s\n' "${_GET[filter]}" |tr '^' '\n' \ + | sed -r 's;[]\/\(\)\\\^\$\?\.\+\*\;\[\{\}];\\\\&;g' \ + | while read each; do + case $each in + name:*) expr='(FN|NICKNAME|N)(\;[^\n]+)*:[^\n]*'"(${each#*:})";; + street:*) expr='ADR(\;[^\n]+)*:([^\;]*;){2}[^\;\n]*'"(${each#*:})";; + zip:*) expr='ADR(\;[^\n]+)*:([^\;]*;){5}[^\;\n]*'"(${each#*:})";; + any:*|:*) expr="[^\n]*"'(\;[^\n]+)*:[^\n]*'"(${each#*:})";; + *:*) expr="${each%%:*}"'(\;[^\n]+)*:[^\n]*'"(${each#*:})";; + *) expr="(${each})";; + esac + filterex='/(^|\n)'"${expr}"'/{'"${filterex}"'}' + done + + for file in "${_DATA}/vcard/"*.vcf; do + case "${_GET[order]}" in + firstname) + printf '%s\t%s\n' "$(sed -rn 's:^N(;.+)*\:([^;]*;){1} *([^;]*).*$:\3:p' "$file")" "$file" + ;; + lastname) + printf '%s\t%s\n' "$(sed -rn 's:^N(;.+)*\:([^;]*;){0} *([^;]*).*$:\3:p' "$file")" "$file" + ;; + bdate) + printf '%s\t%s\n' "$(sed -rn 's:^BDAY(;.+)*\:(.*)$:\2:p' "$file")" "$file" + ;; + *) printf 'x\t%s\n' "$file" + ;; + esac + done \ + | sort -u |sed -r 's;^.*\t;;' \ + | while read n; do + { printf '%s\n' "$n"; cat "$n"; } \ + | sed -rn ':X;N;$!bX; {'"$filterex"'}' + done \ + | sed -r 's;^(.*/)*;;;' } vcf_parse() { diff --git a/templates/cards.html.sh b/templates/cards.html.sh index 2eca4d1..377ccf8 100755 --- a/templates/cards.html.sh +++ b/templates/cards.html.sh @@ -16,7 +16,8 @@ # along with Confetti. If not, see . check_type(){ - [ "${_GET[filtertype]}" = "$1" ] && echo 'checked="checked"' + #[ "${_GET[filtertype]}" = "$1" ] && echo 'checked="checked"' + [ "${_GET[filter]%%:*}" = "$1" ] && echo 'checked="checked"' } check_order(){ [ "${_GET[order]}" = "$1" ] && echo 'checked="checked"' @@ -40,18 +41,20 @@ cat < - + - + + - +