]> git.plutz.net Git - serve0/commitdiff
cleaner filter builder
authorpaul <paul@plutz.net>
Mon, 3 Aug 2015 00:56:28 +0000 (00:56 +0000)
committerpaul <paul@plutz.net>
Mon, 3 Aug 2015 00:56:28 +0000 (00:56 +0000)
svn path=/trunk/; revision=74

actions/filter.sh
constants.sh
pages/list.sh

index 957b1e7af2906fa3617c13df644ccd7231cea26f..c7f4d87fd8aba5e3125866735a397d07fc33f6b0 100755 (executable)
@@ -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
 
index 8dcccd5864aa052a161f6f78db800d407b4e1a1d..266f73430d6d636fc706368aeafd3dbd878e649f 100755 (executable)
@@ -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)
index a86f04c0a701d2b8bbf184fd251e7ac1cd2416ce..cc5a7d2945ba49f1a85228cb1baf95c646b3f861 100755 (executable)
@@ -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(){