]> git.plutz.net Git - serve0/blob - actions/multitag.sh
tagging engine
[serve0] / actions / multitag.sh
1 #!/bin/zsh
2
3 addtag(){
4   meta="$1"
5   tag="$2"
6   
7   length=0; width=0; height=0;
8   if [ -r "$meta" ]; then
9     head -n1 "$meta" |read length width height info
10     tags="$(sed -n 2p "$meta" |sed -r 's:^\|(.*)$:\1:')"
11     description="$(sed -n '3,$p' "$meta")"
12   fi
13   
14   egrep -q "(^|.*\|)$tag(\|.*|$)" <<<"$tags" || tags="$tag|$tags"
15   
16   cat <<EOF >"$meta"
17 $length $width  $height $info
18 $tags
19 $description
20 EOF
21 }
22
23 n=0
24 if [ -n "${CONTENT_LENGTH}" -a "${CONTENT_LENGTH}" -gt 0 ]; then
25 (head -c "${CONTENT_LENGTH}"; echo)|sed 's/&/\n/g' |while read line; do
26   if expr "$line" : "tagsel=" >/dev/null; then
27     n=$(($n + 1))
28     tagsel[$n]="$(echo -e "$(sed -nr 's:(^|&)tagsel=(.*)(&|$):\2:;s:&.*$::;s:\+: :g;s:%:\\x:g;p' <<<"$line" )")"
29   elif expr "$line" : "ctag=" >/dev/null; then
30     tag="$(sed -r 's:^ctag=(.*)$:\1:;s:\+:_:g;s:%:\\x:g' <<<"$line")"
31     tag="$(echo -e "${tag}" |sed -r 's:\t| :_:g;s:^!|\r|\$|\^::g;s:\\:\\\\:g;s/</\&lt\;/g;s/>/\&gt\;/g')"
32     for i in {1..$n}; do
33       addtag "${_DATA}/meta/$tagsel[$i].meta" "$tag"
34       rm "${_DATA}/cache/$tagsel[$i].cache" 2>/dev/null
35     done
36   elif expr "$line" : 'tags=.\+' >/dev/null; then
37     tags="$(sed -r 's:^tags=(.*)$:\1:;s:\+:_:g;s:%:\\x:g' <<<"$line")"
38     tags="$(echo -e "${tags}" |sed -r 's:\t| :_:g;s:^!|\r|\$|\^::g;s:\\:\\\\:g;s/</\&lt\;/g;s/>/\&gt\;/g')"
39     for i in {1..$n}; do echo "$tags" |while read tag; do
40       addtag "${_DATA}/meta/$tagsel[$i].meta" "$tag"
41       rm "${_DATA}/cache/$tagsel[$i].cache" 2>/dev/null
42     done; done
43   fi
44 done
45 fi
46
47 rm ${_DATA}/cache/\?* 2>/dev/null
48
49 echo -n "Location: index.cgi?${QUERY_STRING}#$info\n\n"