]> git.plutz.net Git - serve0/blobdiff - actions/meta.sh
styling for pagination links
[serve0] / actions / meta.sh
index 5824d8f0947560cb5d312d263f6e9b9efa241bc7..ab46894708aa192a655a95af982f8f9f3f9402de 100755 (executable)
@@ -1,54 +1,58 @@
 #!/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/>.
 
-info="$_GET[\"i\"]"
-file="{$DATA}/meta/$info.meta"
+cgi_refdata
 
-if [ -n "${CONTENT_LENGTH}" -a "${CONTENT_LENGTH}" -gt 0 ]; then
-(head -c "${CONTENT_LENGTH}"; echo)|sed 's/&/\n/g' |while read line; do
-  if (egrep -xq 'length=[0-9]{1,5}' <<<"${line}"); then
-    length="$(cut -d= -f2 <<<"${line}")"
-  elif (egrep -xq 'width=[0-9]{1,5}' <<<"${line}"); then
-    width="$(cut -d= -f2 <<<"${line}")"
-  elif (egrep -xq 'height=[0-9]{1,5}' <<<"${line}"); then
-    height="$(cut -d= -f2 <<<"${line}")"
-  elif (egrep -xq 'tag=.+' <<<"${line}"); then
-    tag="$(sed -r 's:^tag=(.*)$:\1:;s:\+:_:g;s:%:\\x:g' <<<"$line")"
-    tag="$(echo -e "${tag}" |sed -r 's:\t| :_:g;s:^!|\r|\$|\^::g;s:\\:\\\\:g;s/</\&lt\;/g;s/>/\&gt\;/g')"
-    tagacc="$tag|$tagacc"
-  elif (egrep -xq 'tags=.+' <<<"${line}"); then
-    tags="$(sed -r 's:^tags=(.*)$:\1:;s:\+:_:g;s:%:\\x:g' <<<"$line")"
-    tags="$(echo -e "${tags}" |sed -r 's:\t| :_:g;s:^!|\r|\$|\^::g;s:\\:\\\\:g;s/</\&lt\;/g;s/>/\&gt\;/g')"
-  elif (egrep -xq 'description=.+' <<<"${line}"); then
-    description="$(cut -d= -f2- <<<"${line}" |sed 's/+/ /g;s/%/\\x/g')"
-    description="$(echo -e "${description}" |sed 's/\r//g;s/\\/\\\\/g;s/</\&lt\;/g;s/>/\&gt\;/g')"
-  elif (egrep -xq 'trash=.+' <<<"${line}"); then
-    trash="true"
-  elif (egrep -xq 'cancel=.+' <<<"${line}"); then
-    cancel="true"
-  elif (egrep -xq 'f=.+' <<<"${line}"); then
-    filter="$(cut -d= -f2- <<<"${line}")"
-  elif (egrep -xq 's=.+' <<<"${line}"); then
-    search="$(cut -d= -f2- <<<"${line}")"
-  elif (egrep -xq 'p=.+' <<<"${line}"); then
-    page="$(cut -d= -f2- <<<"${line}")"
-  elif (egrep -xq 'o=.+' <<<"${line}"); then
-    order="$(cut -d= -f2- <<<"${line}")"
-  fi
+  info="${_GET[i]:-$_REF[i]}"
+ order="${_GET[o]}"
+search="${_GET[s]}"
+filter="${_GET[f]}"
+  page="${_GET[pn]}"
+file="${_DATA}/meta/$info.meta"
+
+length="${_POST[length]}"
+ width="${_POST[width]}"
+height="${_POST[height]}"
+ trash="${_POST[trash]}"
+cancel="${_POST[cancel]}"
+tagacc="${_POST[tag]}"
+tags="$(htmlsafe "${_POST[tags]}" |sed -r 's:\t: :g;s:^!|[\r\$\^\|]::g;' |tr '\n' '|')"
+description="$(htmlsafe "${_POST[description]}")"
+
+n=0; while [ -n "${_POST[tag$n]}" ]; do
+  tagacc="$(htmlsafe ${_POST[tag$n]} |sed -r '2,$d;s:\t| :_:g;s:^!|\r|\$|\^::g;')|$tagacc"
+  n=$(($n + 1))
 done
-fi
 
-[ -z "$cancel" ] && if [ "$trash" = "true" ]; then
+[ -z "$cancel" -a -n "$info" ] && if [ -n "$trash" ]; then
   rm "${_DATA}/thumbs/$info.jpg" 2>/dev/null
   mv "${_DATA}/videos/$info" "${_DATA}/meta/$info.meta" "${_DATA}/trash/" 2>/dev/null
   rm "${_DATA}/cache/$info.cache" 2>/dev/null
   rm ${_DATA}/cache/\?* 2>/dev/null
 else
-  echo -e "$length\t$width\t$height\t$info" > "$file"
-  echo -e "${tagacc}${tags}" |tr '\n' '|' >> "$file"
-  echo >>"$file"
-  echo -e "${description}" >> "$file"
+  cat >$file <<EOF
+${length}      ${width}        ${height}       ${info}
+${tagacc}|${tags}
+${description}
+EOF
   rm "${_DATA}/cache/$info.cache" 2>/dev/null
   rm ${_DATA}/cache/\?* 2>/dev/null
+  rm ${_DATA}/cache/taglist_set ${_DATA}/cache/taglist_filter 2>/dev/null
 fi
 
-echo -n "Location: ?i=&p=${page}&s=${search}&f=${filter}&o=${order}#$info\n\n"
+redirect "${_POST[referrer]:-?i=&pn=${page}&s=${search}&f=${filter}&o=${order}#${info}}"