3 . "$_EXEC/indexmeta.sh"
7 local meta type length width height tags comment name display link
8 meta="${1}"; type="${meta%% *}"; meta="${meta#* }"
10 if [ "$type" = dir ]; then
12 display="$(HTML "$name")"; link="$(URL "$ITEM/$name")"
13 printf '[a .list .dir href="%s" %s]' "${link}?${w_refuri#*\?}" "$name"
17 length="${meta%% *}"; meta="${meta#* }"
18 width="${meta%% *}"; meta="${meta#* }"
19 height="${meta%% *}"; meta="${meta#* }"
20 tags="${meta%% *}"; meta="${meta#* }"
21 comment="${meta%% *}"; meta="${meta#* }"
22 name="${meta%% *}"; meta="${meta#* }"
24 if [ "$type" = metashort ]; then
25 name="$(list_fullname "$(UNSTRING "${name%${CR}}")")"
27 if [ -f "$_DATA/$ITEM/$name" ]; then
28 link="$(URL "$ITEM/$name")"
29 name="$(HTML "$ITEM/$name")"
30 printf '[div .list .file
31 [a href="%s" [img src="%s?a=thumbnail"]][label %s]
32 [span .time %i:%02imin] [span .dim %ix%i] %s
33 [checkbox "select" "%s" id="select_%s"][label for="select_%s" +]
35 "$link" "$link" "${name##*/}" \
36 "$((length / 60))" "$((length % 60))" \
38 "$(printf '%s\n' "${tags#tags=}" \
39 | sed -r "$UNSTRING"' s;^;,;; s;,+;,;g; s;,$;;;
40 :X s;,-?([^,]+)(,|$); [span .tag\n \1]\2;; tX;'
41 )" "$name" "$link" "$link"
43 printf 'Canning record for nonexist file: %s\n' "$name" >&2
44 meta_purge "$_DATA/$ITEM/$name"
49 [ "$FILTER" ] && list_fex="$(
52 | sed -r 's;\^;\n;g; s;[]\/\(\)\\\^\$\?\.\+\*\;\[\{\}];\\&;g' \
54 [ ! "${f#~}" ] && continue
56 && fex="/(\ttags=([^\t]*,)?)(${f})((,[^\t]*)?\t)/{${fex}}" \
57 || fex="/(\ttags=([^\t]*,)?)(${f#~})((,[^\t]*)?\t)/d; ${fex}"
58 printf '%s\n' "${fex}"
65 [ ! "${sn%%*/*}" ] && base="${sn%/*}" || base=.
66 file="$(printf '%s' "$_DATA/$ITEM/$sn".*)"
68 [ -e "$_DATA/$ITEM/$base/${file}" ] \
69 && printf '%s\n' "${base}/${file}"
73 if [ "$FILTER" ]; then
75 elif [ "${SEARCH#!}" != "${SEARCH}" ]; then
76 grep -aviEe "$(STRING "${SEARCH}" \
77 | sed -r ':x s;((^|[^\\])(\\\\)*)\+;\1 ;g; tx;
78 s;((^|[^\\])(\\\\)*)\\\+;\1+;g;
80 elif [ "${SEARCH}" ]; then
81 grep -aiEe "$(STRING "${SEARCH}" \
82 | sed -r ':x s;((^|[^\\])(\\\\)*)\+;\1 ;g; tx;
83 s;((^|[^\\])(\\\\)*)\\\+;\1+;g;
91 if [ ${#1} -gt ${#2} ]; then
96 com="$(expr substr "$long" 1 $((${#long} * 3 / 4)))"
98 if [ ${#cut} -lt ${#short} ]; then
106 local fm fn fn al length ln h w t c name buffer l
108 if [ $ORDER = Name ]; then
109 sort -k6 |sed 's;^;metashort\t;;'
110 elif [ $ORDER = Group ]; then
111 { sort -k6; echo '0 0 0 tags= comment= _'; } \
112 | while read -r length h w t c name; do
113 if groupmatch "$ln" "$name"; then
115 buffer="${buffer}${BR}$length $h $w $t $c $name"
117 printf %s\\n "$buffer" |while read -r l; do
118 [ "$l" ] && printf '%s %s\n' "$al" "$l"
121 buffer="$length $h $w $t $c $name"
125 | sort -sn -k1 |sed -r 's;^[0-9]+\t;metashort\t;;'
126 elif [ $ORDER = Length ]; then
127 sort -sn -k1 |sed 's;^;metashort\t;;'
128 elif [ $ORDER = Date ]; then
131 fn="$(list_fullname "$(UNSTRING "${sn%${CR}}")")"
132 printf '%i %s %s\n' \
133 "$(stat -c %Y "$fn")" "${fm% *}" "$fn"
135 | sort -srn -k1 |sed -r 's;^[0-9]+\t;metalong\t;;'
140 local meta base cbase fm cachename
142 meta="$_DATA/$ITEM/$base/.index/meta"
143 meta_dir "$_DATA/$ITEM/$base"
145 cachename="$(printf '%s\n' "$mode" "$FILTER" "$SEARCH" "$ORDER" |sha1sum)"
146 cachename="$_DATA/$ITEM/.index/${cachename% -}.cache"
148 if [ "$cachename" -nt "$meta" ] 2>&-; then
151 cbase="$(STRING "$base")"
152 grep -axE '[0-9]+ [0-9]+ [0-9]+ tags=[^ ]* comment=[^ ]* .+' "$meta" \
153 | while read -r fm; do
154 printf '%s %s/%s\n' "${fm% *}" "$cbase" "${fm##* }"
158 | { [ -d "${meta%meta}" ] && tee "$cachename" || cat; }
164 mode="$(COOKIE mode |grep -m1 -axE 'index|browse' || printf browse )"
166 if [ "$mode" = browse ]; then
167 [ "$ITEM" ] && printf 'dir\t..\n'
169 find ./ -type d \! -name .index -mindepth 1 -maxdepth 1 \
170 ) | cut -d/ -f2- | sort |sed 's;^;dir\t;;'
172 elif [ "$mode" = index ]; then
174 find ./ -path '*/.index/meta'
175 ) | while read -r meta; do
176 list_filemeta "${meta%/.index/meta}"
182 local page i c n end qry
183 page="$(GET p |grep -axE '[0-9]+' || printf 1)"; c=1
184 end=$((page + LISTSIZE))
185 qry="${w_refuri#*\?}"; qry="${qry#p=*&}"
187 printf '[div .itemlist '
190 [ $c -gt $page -a $c -le $end ] && list_item "$i"
194 [ $(( c % LISTSIZE )) -gt 0 ] \
195 && end=$((c / LISTSIZE + 1)) \
196 || end=$((c / LISTSIZE))
198 printf '[div .pagination'
199 for n in $( seq 1 $end ); do
200 c=$(( (n - 1) * LISTSIZE + 1 ))
202 && printf '[a .page .current href="%s" %s]' "?p=${c}&${qry}" "$n" \
203 || printf '[a .page href="%s" %s]' "?p=${c}&${qry}" "$n"
208 printf 'Content-Type: text/html;charset=utf-8\r\n\r\n'
212 [html [head [title Listing]
213 [meta name="viewport" content="width=device-width"]
214 [link rel=stylesheet href="/style.css" ]
217 [a #t_bookmarks href="#bookmarks" ★]'
220 [a #t_avsearch href="#advsearch" Advanced]
221 [a #t_prefs href="#prefs" ⚙]
227 [form method=POST action="?a=multitag"'
230 [ -d "$_DATA/$ITEM/.index" ] && { printf '
237 [ ! -d "$_DATA/$ITEM/.index" ] && { printf '
244 '; } | "$_EXEC/cgilite/html-sh.sed"