]> git.plutz.net Git - serve0/commitdiff
use new cgi engine for filter processing
authorpaul <paul@plutz.net>
Mon, 22 Sep 2014 00:31:07 +0000 (00:31 +0000)
committerpaul <paul@plutz.net>
Mon, 22 Sep 2014 00:31:07 +0000 (00:31 +0000)
svn path=/trunk/; revision=12

actions/filter.sh
templates/filterdiag.html.sh

index 94b87f2c7ce6036f54b4e5458cba35344bc6f313..32f867daf826ba1e4c72aff97b7c09a8560db66c 100755 (executable)
@@ -1,37 +1,35 @@
 #!/bin/zsh
 
-if [ -n "${CONTENT_LENGTH}" -a "${CONTENT_LENGTH}" -gt 0 ]; then
-(head -c "${CONTENT_LENGTH}"; echo)|sed 's:&:\n:g;s:\r::g' |while read line; do
-  case "$line" in
-    type[0-9]=neg)
-      [ -z "$filters" ] && filters="!"
-      [ -n "$filters" ] && egrep -q '(^|\^|\||!)$' <<<"$filters" || filters="${filters}^!"
-      ;;
-    type[0-9]=pos)
-      egrep -q '(^|\^|\||!)$' <<<"$filters" || filters="${filters}^"
-      ;;
-    category=*)
-      category="$(sed 's/^category=//;s/+/ /g;s/%/\\x/g' <<<"$line")"
-      category="$(echo -e "${category}" |sed 's/\t/ /g;s/\r//g;s/\\/\\\\/g' |head -n1)"
-      ;;
-    filter=*)
-      filter="$(sed 's/^filter=//;s/+/ /g;s/%/\\x/g' <<<"$line")"
-      filter="$(echo -e "${filter}" |sed 's/\t/ /g;s/\r//g;s/\\/\\\\/g' |head -n1)"
-      egrep -q '(^|\^|\||!)$' <<<"${filters}" || filters="${filters}|"
-      filters="${filters}${filter}"
-      ;;
-    cfilter=*)
-      cfilter="$(sed 's/^cfilter=//;s/+/ /g;s/%/\\x/g' <<<"$line")"
-      cfilter="$(echo -e "${cfilter}" |sed 's/\t/ /g;s/\r//g;s/\\/\\\\/g' |head -n1)"
-      egrep -q '(^|\^|\||!)$' <<<"${filters}" || filters="${filters}|"
-      [ -n "$cfilter" ] && filters="${filters}${category}:${cfilter}"
-      ;;
-    o=Name) order=Name;;
-    o=Date) order=Date;;
-    o=Length) order=Length;;
-  esac
+cgi_post
+order="$_POST[\"o\"]"
+
+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)"
+
+  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[\"filter${fn}_$n\"]" ]; do
+    filter="$(echo "$_POST[\"filter${fn}_$n\"]" |sed 's/\t/ /g;s/\r//g;s/\\/\\\\/g' |head -n1)"
+    egrep -q '(^|\^|\||!)$' <<<"${filters}" || filters="${filters}|"
+    filters="${filters}${filter}"
+    [ -z "$n" ] && n=0 || n=$(($n + 1))
+  done
+
+  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}|"
+    filters="${filters}${category}:${cfilter}"
+    [ -z "$n" ] && n=0 || n=$(($n + 1))
+  done
 done
-fi
 
 echo "?o=${order}&f=${filters}" >>${_DATA}/meta/recent
 echo -n "Location: ?o=${order}&f=${filters}\n\n"
index 2ebb22e3b452867281fd047429183826c4b99c8b..9a388887c9d294740e28b4ea84320ca857fb1e03 100755 (executable)
@@ -27,6 +27,12 @@ cat <<FilterEnd
   <form class="panel" id="advfilter" style="display: none;"
         action="?action=filter" method="post" accept-charset="UTF-8">
     <input disabled type="text" name="s" value="$search" placeholder="Search">
+    <span class="label order">Order by:</span>
+    <select disabled class="order" size="1" name="o">
+      <option>Name</option>
+      <option>Date</option>
+      <option>Length</option>
+    </select>
     <input disabled type="submit" name="submit" value="Find">
 
     <a class="panel clearsearch" href="?">Clear All</a>
@@ -46,16 +52,16 @@ cat <<FilterEnd
       <input type=\"radio\" name=\"type$n\" value=\"neg\"><span class=\"label conjunction\">None</span>
       <span class=\"help\">of the tags selected here:</span>
       <span class=\"label category\">Category:</span>
-      <select class=\"input category\" name=\"category\" size=\"1\" onchange=\"${hideall}show_block('${n}_'+this.options[this.options.selectedIndex].value)\">
+      <select class=\"input category\" name=\"category$n\" size=\"1\" onchange=\"${hideall}show_block('${n}_'+this.options[this.options.selectedIndex].value)\">
         <option>none</option>
         $(sed -rn 's;^([^:]+):.*$;<option>\1</option>;p' <<<"$taglist" |sort -u)
       </select>
-      <select class=\"input tagfilter\" name=\"filter\" size=\"12\" multiple id=\"${n}_none\"
+      <select class=\"input tagfilter\" name=\"filter${n}_\" size=\"12\" multiple id=\"${n}_none\"
               onchange=\"show_iblock('filter$((1+$n))')\">
          $(sed -rn 's;^([^:]+)$;<option>\1</option>;p' <<<"$taglist")
       </select>
       $(sed -rn 's;^([^:]+):.*$;\1;p' <<<"$taglist" |sort -u |while read cat; do echo "
-      <select class=\"input tagfilter\" name=\"cfilter\" size=\"12\" multiple id=\"${n}_$cat\" style=\"display:none;\"
+      <select class=\"input tagfilter\" name=\"cfilter${n}_\" size=\"12\" multiple id=\"${n}_$cat\" style=\"display:none;\"
               onchange=\"show_iblock('filter$((1+$n))')\">
          $(sed -rn "s;^$cat:(.*)$;<option>\\1</option>;p" <<<"$taglist")
       </select>"