]> git.plutz.net Git - serve0/blobdiff - actions/multitag.sh
allow additional characters in tags
[serve0] / actions / multitag.sh
index 7c5b252601ce97566f165d5a295ef124aad1d9ab..242db282559fdb5d8c9c6a69d4e1d40eabc4487e 100755 (executable)
@@ -1,9 +1,25 @@
 #!/bin/zsh
+# Copyright 2014 - 2016 Paul Hänsch
+#
+# This file is part of Serve0
+#
+# Serve0 is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Serve0 is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with Serve0  If not, see <http://www.gnu.org/licenses/>.
 
-filter="$_GET[\"f\"]"
-search="$_GET[\"s\"]"
-order=$(echo "$_GET[\"o\"]" |egrep '^(Name|Date|Length)$')
-page=$(echo "$_GET[\"p\"]" |egrep '^[0-9]+$')
+filter="${_GET[f]}"
+search="${_GET[s]}"
+order=$(validate "${_GET[o]}" 'Name|Date|Length' Name)
+page=$(validate "${_GET[pn]}" '[0-9]+' 1)
 
 addtag(){
   meta="$1"
@@ -27,15 +43,17 @@ EOF
 
 cgi_post
 n=''
-while [ -n "$_POST[\"tagsel$n\"]" ]; do
-  tagsel="$_POST[\"tagsel$n\"]"
+while [ -n "${_POST[tagsel$n]}" ]; do
+  tagsel="${_POST[tagsel$n]}"
   ( t=''
-    while [ -n "$_POST[\"ctag$t\"]" ]; do
-      echo "$_POST[\"ctag$t\"]"
+    while [ -n "${_POST[ctag$t]}" ]; do
+      htmlsafe "${_POST[ctag$t]}"
+      printf \\n
       [ -z "$t" ] && t=0 || t=$(($t + 1))
     done
-    echo "$_POST[\"tags\"]"
-  ) |sed -r 's:\t| :_:g;s:^!|\r|\$|\^::g;s:\\:\\\\:g;s/</\&lt\;/g;s/>/\&gt\;/g' \
+    htmlsafe "${_POST[tags]}"
+    printf \\n
+  ) | sed -r 's:\t: :g;s:^!|[\r\$\^\|]::g;' \
   | while read tag; do
     addtag "${_DATA}/meta/$tagsel.meta" "$tag"
   done
@@ -44,7 +62,7 @@ while [ -n "$_POST[\"tagsel$n\"]" ]; do
   [ -z "$n" ] && n=0 || n=$(($n + 1))
 done
 
-rm "${_DATA}"/cache/\?* 2>/dev/null
-[ -n "$_POST[\"tags\"]" ] && rm "${_DATA}"/cache/taglist 2>/dev/null
+rm "${_DATA}"/cache/*[0-9]\?* 2>/dev/null
+[ -n "${_POST[tags]}" ] && rm "${_DATA}"/cache/taglist 2>/dev/null
 
-echo -n "Location: ?o=$order&s=$search&f=$filter&p=$page\n\n"
+redirect "?o=$order&s=$search&f=$filter&pn=$page"