]> git.plutz.net Git - serve0/blob - actions/filter.sh
do not forget newline when storing recent filters
[serve0] / actions / filter.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 cgi_post
20 order=$(validate "${_POST[o]}" 'Name|Length|Date' Name)
21
22 for fn in {0..9}; do
23   category="$(validate "${_POST[category$fn]}" '[[:alnum:]_-]+' none)"
24
25   n=''; while [ -n "${_POST[cfilter${fn}_$n]}" ]; do
26     #cfilter="$(validate "${_POST[cfilter${fn}_$n]}" '[[:alnum:]\?!\._=\(\)+-]+' '#')"
27     cfilter="${_POST[cfilter${fn}_$n]}"
28
29     if [ -z "$n" ]; then
30       [ -n "$filters" ] && filters="${filters}^"
31       [ "${_POST[type$fn]}" = 'neg' ] && filters="${filters}!"
32       n=0
33     else
34       filters="${filters}|"
35       n=$(($n + 1))
36     fi
37     [ "$category" = "none" ] && filters="${filters}${cfilter}" \
38                              || filters="${filters}${category}:${cfilter}"
39   done
40 done
41
42 printf %s\\n "?o=${order}&f=${filters}" >>${_DATA}/meta/recent
43 redirect  "?o=${order}&f=${filters}"