From 76af039ece14f3407e9187f7b2003e68a07d0076 Mon Sep 17 00:00:00 2001 From: paul Date: Mon, 3 Aug 2015 00:56:28 +0000 Subject: [PATCH] cleaner filter builder svn path=/trunk/; revision=74 --- actions/filter.sh | 29 ++++++++++++++--------------- constants.sh | 4 ++-- pages/list.sh | 2 +- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/actions/filter.sh b/actions/filter.sh index 957b1e7..c7f4d87 100755 --- a/actions/filter.sh +++ b/actions/filter.sh @@ -1,25 +1,24 @@ #!/bin/zsh cgi_post -order="${_POST[o]}" +order=$(validate "${_POST[o]}" 'Name|Length|Date' Name) for fn in {0..9}; do - type="${_POST[type$fn]}" - category="$(echo "${_POST[category$fn]}" |sed 's/\t/ /g;s/\r//g;s/\\/\\\\/g' |head -n1)" + category="$(validate "${_POST[category$fn]}" '[[:alnum:]_-]+' none)" - if [ "$type" = "neg" ]; then - [ -z "$filters" ] && filters="!" - [ -n "$filters" ] && egrep -q '(^|\^|\||!)$' <<<"$filters" || filters="${filters}^!" - elif [ "$type" = "pos" ]; then - egrep -q '(^|\^|\||!)$' <<<"$filters" || filters="${filters}^" - fi + n=''; while [ -n "${_POST[cfilter${fn}_$n]}" ]; do + cfilter="$(validate "${_POST[cfilter${fn}_$n]}" '[[:alnum:]\?!\._=\(\)+-]+' '#')" - n='' - while [ -n "${_POST[cfilter${fn}_$n]}" ]; do - cfilter="$(echo "${_POST[cfilter${fn}_$n]}" |sed 's/\t/ /g;s/\r//g;s/\\/\\\\/g' |head -n1)" - egrep -q '(^|\^|\||!)$' <<<"${filters}" || filters="${filters}|" - [ "$category" = "none" ] && filters="${filters}${cfilter}" || filters="${filters}${category}:${cfilter}" - [ -z "$n" ] && n=0 || n=$(($n + 1)) + if [ -z "$n" ]; then + [ -n "$filters" ] && filters="${filters}^" + [ "${_POST[type$fn]}" = 'neg' ] && filters="${filters}!" + n=0 + else + filters="${filters}|" + n=$(($n + 1)) + fi + [ "$category" = "none" ] && filters="${filters}${cfilter}" \ + || filters="${filters}${category}:${cfilter}" done done diff --git a/constants.sh b/constants.sh index 8dcccd5..266f734 100755 --- a/constants.sh +++ b/constants.sh @@ -24,9 +24,9 @@ file_pattern='^.*(mov|ts|mpg|mpeg|mp4|m4v|avi|mkv|flv|sfv|wmv|ogm|webm|iso|rmvb) data_dirs cache meta mp4 videos thumbs trash by_length transcoded cgi_cookie -validate(){ printf '%s\n' "$1" |sed -rn '2q;/^'"$2"'$/{p;q};a'"$3"; } +validate(){ printf '%s\n' "$1" |sed -rn '2q;/^('"$2"')$/{p;q};a'"$3"; } -_GET[o]=$( validate "${_GET[o]}" '(Name|Date|Length)' Name) +_GET[o]=$( validate "${_GET[o]}" 'Name|Date|Length' Name) _GET[pn]=$(validate "${_GET[pn]}" '[1-9][0-9]*' 1) _COOKIE[pagesize]=$(validate "${_COOKIE[pagesize]}" '[1-9][0-9]*' 50) diff --git a/pages/list.sh b/pages/list.sh index a86f04c..cc5a7d2 100755 --- a/pages/list.sh +++ b/pages/list.sh @@ -19,7 +19,7 @@ . $_EXEC/pages/common.sh -filters="$(printf %s "${_GET[f]}" |sed -r 's;^!*\^*;;; s;\^*!*$;;; s;!+;!;g; s;\^+;^;g')" +filters="${_GET[f]}" debug "FILTERS: $filters" quicklinks(){ -- 2.39.2