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