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