]> git.plutz.net Git - serve0/blob - actions/multitag.sh
styling for pagination links
[serve0] / actions / multitag.sh
1 #!/bin/zsh
2 # Copyright 2014 - 2017 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 backlink="${_POST[page]}"
20
21 addtag(){
22   meta="$1"
23   tag="$2"
24   
25   length=0; width=0; height=0;
26   if [ -r "$meta" ]; then
27     head -n1 "$meta" |read length width height info
28     tags="$(sed -n 2p "$meta" |sed -r 's:^\|(.*)$:\1:')"
29     description="$(sed -n '3,$p' "$meta")"
30   fi
31   
32   egrep -q "(^|.*\|)$tag(\|.*|$)" <<<"$tags" || tags="$tag|$tags"
33   
34   cat <<EOF >"$meta"
35 $length $width  $height $info
36 $tags
37 $description
38 EOF
39 }
40
41 n=''
42 while [ -n "${_POST[tagsel$n]}" ]; do
43   tagsel="${_POST[tagsel$n]}"
44   ( t=''
45     while [ -n "${_POST[ctag$t]}" ]; do
46       htmlsafe "${_POST[ctag$t]}"
47       printf \\n
48       [ -z "$t" ] && t=0 || t=$(($t + 1))
49     done
50     htmlsafe "${_POST[tags]}"
51     printf \\n
52   ) | sed -r 's:\t: :g;s:^!|[\r\$\^\|]::g;' \
53   | while read tag; do
54     addtag "${_DATA}/meta/$tagsel.meta" "$tag"
55   done
56   rm "${_DATA}/cache/$tagsel.cache" 2>/dev/null
57
58   n=$((${n:--1} + 1))
59 done
60
61 rm "${_DATA}"/cache/\?* 2>/dev/null
62 [ -n "${_POST[tags]}" ] && rm "${_DATA}"/cache/taglist_set "${_DATA}"/cache/taglist_filter 2>/dev/null
63
64 redirect "$backlink#$tagsel"