]> git.plutz.net Git - serve0/blob - widgets.sh
various -a flags for grep
[serve0] / widgets.sh
1 #!/bin/sh
2
3 [ -n "$include_widgets" ] && return 0
4 include_widgets="$0"
5
6 . "$_EXEC/cgilite/storage.sh"
7
8 w_refuri="$(HTML "$REQUEST_URI")"
9
10 w_tags="$(find "$_DATA/" -path '*/.index/meta' -print0 \
11         | xargs -r0 sed -r '
12           s;^.*\t.*\t.*\ttags=(.*)\tcomment=.*\t.*\r$;\1;;
13           s;,;\n;g;'"$UNSTRING" \
14         | sort -u |HTML |sed 's;&#58\;;:;g; s;&#10\;;\n;g;')"
15 w_tagcategories="$(printf %s "$w_tags" | cut -sd: -f1 | uniq)"
16
17 [ "$ORDER" = Name   ] && w_coname=checked
18 [ "$ORDER" = Date   ] && w_codate=checked
19 [ "$ORDER" = Length ] && w_colength=checked
20
21 w_search(){
22   printf '
23   [form #search method=GET action=?
24     [select name=o size=1 
25       [option disabled=disabled Order By]
26       [option value=Name %s Name]
27       [option value=Date %s Date]
28       [option value=Length %s Length]
29     ]
30     [input name=s placeholder=Search value="%s"]
31   ]
32   ' \
33   "$w_coname" "$w_codate" "$w_colength" \
34   "$(HTML "$SEARCH")"
35 }
36
37 w_prefs(){
38   local tm tf
39
40   tm=''; [ "$(COOKIE mode)" = index ] && tm=' '
41   tf=''; [ "$(COOKIE fakemp4)" = yes ] && tf=checked
42
43   printf '
44   [form #prefs method="POST" action="?a=setprefs"
45     [a href="#" x]
46     [hidden "ref" "%s"]
47     [label for=prefs_ps Pagesize]
48     [input #prefs_ps type=number name=pagesize value="%s"][br]
49     [radio "mode" "browse" %s #prefs_modebrowse] [label for=prefs_modebrowse Browse Folders][br]
50     [radio "mode" "index"  %s #prefs_modeindex ] [label for=prefs_modeindex View Full Index][br]
51     [checkbox "fakemp4" "yes" %s #prefs_fmp4] [label for=prefs_fmp4 Fake .MP4 file ending][br]
52     [submit "store" "store" Set Cookie]
53   ]
54   ' \
55   "$w_refuri" "$LISTSIZE" \
56   "${tm:-checked}" "${tm:+checked}" "$tf"
57 }
58
59 w_index(){
60   [ -d "$_DATA/$ITEM/.index" ] || printf '
61   [form #index method="POST" action="?a=spawnindex"
62     [hidden "ref" "%s"]
63     [label Set up for Index view: ]
64     [checkbox "recursive" "yes" #spawn_recursive] [label for=spawn_recursive Include subdirectories]
65     [submit "spawn" "spawn" Set up]
66   ]
67   ' "$w_refuri"
68 }
69
70 w_advsearch(){
71   local n lbid tag category filter f t
72   filter="$(HTML "${FILTER}^" |sed 's;&#126\;;~;g; s;&#94\;;^;g; s;&#124\;;|;g; s;&#58\;;:;g;')"
73
74   printf '[form #advsearch action=?a=advsearch method=POST
75             [a href="#" Hide]
76             [p .help Select multiple tags from each category by holding down the [strong Ctrl] key on your keyboard.[br]
77             Refine the search further by setting additional search tags using the [strong "+and"] button.]'
78
79   for n in 1 2 3 4 5 6 7 8 9 10; do
80     f="${filter%%^*}"; filter="${filter#*^}"
81
82     t=''; [ "$f" -a ! "${f%%~*}" ] && t=" "
83
84     lbid="cat_${n}_(none)"
85     printf '[input .and type=checkbox name=and id="and_%i" %s][label for="and_%i" +and
86             ][fieldset .select
87             [radio "pol_%i" "pos" .pol %s #pol_pos_%i"][label for=pol_pos_%i Any]
88             [radio "pol_%i" "neg" .pol %s #pol_neg_%i"][label for=pol_neg_%i None]
89             [label .head Category:]' \
90             $n "${f:+checked}" $n \
91             $n "${t:-checked}" $n $n \
92             $n "${t:+checked}" $n $n
93
94     f="|${f#~}|"
95     printf '*\n%s\n' "$w_tagcategories" \
96     | while read -r category; do
97       lbid="cat_${n}_${category}"
98
99       t=''
100       [ "$category"  = '*' -a   "${f%%|${category}:*}" ] && t=checked
101       [ "$category" != '*' -a ! "${f%%|${category}:*}" ] && t=checked
102
103       printf '[radio "cat_%i" "%s" .cat %s id="%s"][label for="%s" %s]
104               [select name=tag_%s size=10 multiple' \
105               $n "$category" "$t" "$lbid" "$lbid" "$category" $n
106
107       printf '%s\n' "$w_tags" \
108       | { [ "$category" = '*' ] && grep -avF ':' |grep -avxF '' || grep -awF "${category}"; } \
109       | while read -r tag; do
110         t=''; [ ! "${f%%*|${tag}|*}" ] && t=checked
111         printf '[option %s value="%s"\n%s]' "$t" "$tag" "${tag#*:}"
112       done
113       printf '\n]'
114     done
115     printf ']'
116   done
117
118   printf '[fieldset .submit [select name=order
119             [option disabled=disabled Order By]
120             [option value=Name %s Name]
121             [option value=Date %s Date]
122             [option value=Length %s Length]
123           ][button type=submit Apply Filter]]
124           ]' \
125           "$w_coname" \
126           "$w_codate" \
127           "$w_colength"
128 }
129
130 w_tagging(){
131   local tag category
132   printf '[div #multitag [input type="hidden" name="ref" value="%s"]' "$w_refuri"
133   printf '[a href="#" Hide][br]'
134
135   printf 'Tags\n%s\n' "$w_tagcategories" \
136   | while read -r category; do
137     printf '[fieldset [legend %s:][select name=tag size=4 multiple' "$category"
138     printf %s "$w_tags" \
139     | { [ "$category" = 'Tags' ] && grep -avF ':' | grep -avxF '' || grep -awF "${category}"; } \
140     | while read -r tag; do
141       printf '[option value="%s"\n%s]' "$tag" "${tag#*:}"
142     done
143     printf ']]'
144   done
145
146   printf '[fieldset [legend New:][textarea name=newtag\n][button type=Submit Add Tags]]]'
147 }