]> git.plutz.net Git - serve0/blob - multitag.sh
Merge commit 'c1c97928352f0ac36034432f5bbba708c4146ff0'
[serve0] / multitag.sh
1 #!/bin/sh
2
3 . "$_EXEC/db_meta.sh"
4 . "$_EXEC/cgilite/session.sh" nocookie
5 . "$_EXEC/widgets.sh"
6
7 newtags=''
8 for tn in $(seq 1 $(POST_COUNT tag)); do
9   newtags="$(POST tag $tn)${BR}${newtags}"
10 done
11 newtags="$(POST newtagn |tr -d '\r' |tr , '\n')${BR}${newtags}"
12
13 if [ "$(POST makegroup)" = true ]; then
14   group="$(timeid)"
15 fi
16
17 while [ "${newtags#${BR}}" != "${newtags}" ]; do newtags="${newtags#${BR}}"; done
18 while [ "${newtags%${BR}}" != "${newtags}" ]; do newtags="${newtags%${BR}}"; done
19
20 [ "$(POST op)" = del ] && deltags="$newtags"
21
22 for select in $(seq 1 $(POST_COUNT select)); do
23   file="$(POST select $select)"
24
25   read_meta "${file%.*}" || continue
26   tags="$(printf %s\\n "$META_TAGS" |tr , \\n)"
27
28   if [ ! "$deltags" ]; then
29     extags="$(printf '%s' "${newtags}" |grep -e "^-" |cut -d: -f1 )"
30     [ "$extags" ] && tags="$(printf %s\\n "$tags" |grep -vwFe "$extags")"
31     if printf %s "${newtags}" |grep -e "^-" |grep -qEe "^-[^:]+$"; then
32       tags="$(printf %s\\n "$tags" |grep -vEe '^-[^:]+$')"
33     fi
34     tags="$(printf '%s\n' "${tags},${newtags}" \
35             | tr , '\n' |sort -u |tr '\n' ,)"
36   else
37     detag="${deltags}${BR}"; while [ "$detag" ]; do
38       tags="$(printf '%s\n' "$tags" |grep -vxFe "${detag%%${BR}*}")"
39       detag="${detag#*${BR}}"
40     done
41     tags="$(printf '%s\n' "$tags" |sort -u |tr '\n' ,)"
42   fi
43   tags="${tags#,}"; tags="${tags%,}"
44
45   if [ "$group" ]; then
46     update_meta "$META_NAME" tags="${tags}" group="${group}"
47   else
48     update_meta "$META_NAME" tags="${tags}"
49   fi
50 done
51
52 ( if [ $(POST_COUNT select) -gt 0 ]; then
53     taglist >"$c_tags.$$"
54     mv -- "$c_tags.$$" "$c_tags"
55   fi &
56 ) &