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