]> git.plutz.net Git - serve0/blob - actions/multitag.sh
send reference to return page for various actions
[serve0] / actions / multitag.sh
1 #!/bin/zsh
2 # Copyright 2014 - 2016 Paul Hänsch
3 #
4 # This file is part of Serve0
5 #
6 # Serve0 is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU Affero General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # Serve0 is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU Affero General Public License for more details.
15 #
16 # You should have received a copy of the GNU Affero General Public License
17 # along with Serve0  If not, see <http://www.gnu.org/licenses/>.
18
19 filter="${_POST[f]}"
20 search="${_POST[s]}"
21 order=$(validate "${_POST[o]}" 'Name|Date|Length' Name)
22 page=$(validate "${_POST[pn]}" '[0-9]+' 1)
23
24 addtag(){
25   meta="$1"
26   tag="$2"
27   
28   length=0; width=0; height=0;
29   if [ -r "$meta" ]; then
30     head -n1 "$meta" |read length width height info
31     tags="$(sed -n 2p "$meta" |sed -r 's:^\|(.*)$:\1:')"
32     description="$(sed -n '3,$p' "$meta")"
33   fi
34   
35   egrep -q "(^|.*\|)$tag(\|.*|$)" <<<"$tags" || tags="$tag|$tags"
36   
37   cat <<EOF >"$meta"
38 $length $width  $height $info
39 $tags
40 $description
41 EOF
42 }
43
44 n=''
45 while [ -n "${_POST[tagsel$n]}" ]; do
46   tagsel="${_POST[tagsel$n]}"
47   ( t=''
48     while [ -n "${_POST[ctag$t]}" ]; do
49       htmlsafe "${_POST[ctag$t]}"
50       printf \\n
51       [ -z "$t" ] && t=0 || t=$(($t + 1))
52     done
53     htmlsafe "${_POST[tags]}"
54     printf \\n
55   ) | sed -r 's:\t: :g;s:^!|[\r\$\^\|]::g;' \
56   | while read tag; do
57     addtag "${_DATA}/meta/$tagsel.meta" "$tag"
58   done
59   rm "${_DATA}/cache/$tagsel.cache" 2>/dev/null
60
61   [ -z "$n" ] && n=0 || n=$(($n + 1))
62 done
63
64 rm "${_DATA}"/cache/\?* 2>/dev/null
65 [ -n "${_POST[tags]}" ] && rm "${_DATA}"/cache/taglist_set "${_DATA}"/cache/taglist_filter 2>/dev/null
66
67 #redirect "?o=$order&s=$search&f=$filter&pn=$page"
68 redirect "${_POST[page]}"