X-Git-Url: http://git.plutz.net/?a=blobdiff_plain;f=actions%2Fmultitag.sh;h=b38b204ea0688bb21592d02d32d09c7bae1ca212;hb=d716f2ce1fe64cf87f777490315bc51906001c72;hp=127a64e8db11aab678bb10ea0caf070b370557e5;hpb=c7e6e63b567cd68f0a9c1f12dd92b175d2f6a2a0;p=serve0 diff --git a/actions/multitag.sh b/actions/multitag.sh index 127a64e..b38b204 100755 --- a/actions/multitag.sh +++ b/actions/multitag.sh @@ -1,4 +1,22 @@ #!/bin/zsh +# Copyright 2014 - 2017 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 . + +backlink="${_POST[page]}" addtag(){ meta="$1" @@ -20,30 +38,27 @@ $description EOF } -n=0 -if [ -n "${CONTENT_LENGTH}" -a "${CONTENT_LENGTH}" -gt 0 ]; then -(head -c "${CONTENT_LENGTH}"; echo)|sed 's/&/\n/g' |while read line; do - if expr "$line" : "tagsel=" >/dev/null; then - n=$(($n + 1)) - tagsel[$n]="$(echo -e "$(sed -nr 's:(^|&)tagsel=(.*)(&|$):\2:;s:&.*$::;s:\+: :g;s:%:\\x:g;p' <<<"$line" )")" - elif expr "$line" : "ctag=" >/dev/null; then - tag="$(sed -r 's:^ctag=(.*)$:\1:;s:\+:_:g;s:%:\\x:g' <<<"$line")" - tag="$(echo -e "${tag}" |sed -r 's:\t| :_:g;s:^!|\r|\$|\^::g;s:\\:\\\\:g;s//\>\;/g')" - for i in {1..$n}; do - addtag "${_DATA}/meta/$tagsel[$i].meta" "$tag" - rm "${_DATA}/cache/$tagsel[$i].cache" 2>/dev/null +n='' +while [ -n "${_POST[tagsel$n]}" ]; do + tagsel="${_POST[tagsel$n]}" + ( t='' + while [ -n "${_POST[ctag$t]}" ]; do + htmlsafe "${_POST[ctag$t]}" + printf \\n + [ -z "$t" ] && t=0 || t=$(($t + 1)) done - elif expr "$line" : 'tags=.\+' >/dev/null; 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//\>\;/g')" - for i in {1..$n}; do echo "$tags" |while read tag; do - addtag "${_DATA}/meta/$tagsel[$i].meta" "$tag" - rm "${_DATA}/cache/$tagsel[$i].cache" 2>/dev/null - done; done - fi + htmlsafe "${_POST[tags]}" + printf \\n + ) | sed -r 's:\t: :g;s:^!|[\r\$\^\|]::g;' \ + | while read tag; do + addtag "${_DATA}/meta/$tagsel.meta" "$tag" + done + rm "${_DATA}/cache/$tagsel.cache" 2>/dev/null + + n=$((${n:--1} + 1)) done -fi -rm ${_DATA}/cache/\?* 2>/dev/null +rm "${_DATA}"/cache/\?* 2>/dev/null +[ -n "${_POST[tags]}" ] && rm "${_DATA}"/cache/taglist_set "${_DATA}"/cache/taglist_filter 2>/dev/null -echo -n "Location: index.cgi?${QUERY_STRING}#$info\n\n" +redirect "$backlink#$tagsel"