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:%imin] [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 \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;
93 if [ $ORDER = Name ]; then
94 sort -k6 |sed 's;^;metashort\t;;'
95 elif [ $ORDER = Length ]; then
96 sort -n -k1 |sed 's;^;metashort\t;;'
97 elif [ $ORDER = Date ]; then
100 fn="$(list_fullname "$(UNSTRING "${sn%${CR}}")")"
101 printf '%i %s %s\n' \
102 "$(stat -c %Y "$fn")" "${fm% *}" "$fn"
104 | sort -rn -k1 |cut -f2- |sed 's;^;metalong\t;;'
109 local meta base cbase fm cachename
111 meta="$_DATA/$ITEM/$base/.index/meta"
112 meta_dir "$_DATA/$ITEM/$base"
114 cachename="$(printf '%s\n' "$mode" "$FILTER" "$SEARCH" "$ORDER" |sha1sum)"
115 cachename="$_DATA/$ITEM/.index/${cachename% -}.cache"
117 if [ "$cachename" -nt "$meta" ] 2>&-; then
120 cbase="$(STRING "$base")"
121 grep -axE '[0-9]+ [0-9]+ [0-9]+ tags=[^ ]* comment=[^ ]* .+' "$meta" \
122 | while read -r fm; do
123 printf '%s %s/%s\n' "${fm% *}" "$cbase" "${fm##* }"
127 | { [ -d "${meta%meta}" ] && tee "$cachename" || cat; }
133 mode="$(COOKIE mode |grep -m1 -axE 'index|browse' || printf browse )"
135 if [ "$mode" = browse ]; then
136 [ "$ITEM" ] && printf 'dir\t..\n'
138 find ./ -type d \! -name .index -mindepth 1 -maxdepth 1 \
139 ) | cut -d/ -f2- | sort |sed 's;^;dir\t;;'
141 elif [ "$mode" = index ]; then
143 find ./ -path '*/.index/meta'
144 ) | while read -r meta; do
145 list_filemeta "${meta%/.index/meta}"
151 local page i c n end qry
152 page="$(GET p |grep -axE '[0-9]+' || printf 1)"; c=1
153 end=$((page + LISTSIZE))
154 qry="${w_refuri#*\?}"; qry="${qry#p=*&}"
156 printf '[div .itemlist '
159 [ $c -gt $page -a $c -le $end ] && list_item "$i"
163 printf '[div .pagination'
164 for n in $( seq 1 $((c / LISTSIZE + 1)) ); do
165 printf '[a .page href="%s" %s]' \
166 "?p=$(( (n - 1) * LISTSIZE + 1))&${qry}" "$n"
171 printf 'Content-Type: text/html;charset=utf-8\r\n\r\n'
175 [html [head [title Listing]
176 [meta name="viewport" content="width=device-width"]
177 [link rel=stylesheet href="/style.css" ]
180 [a #t_bookmarks href="#bookmarks" ★]'
183 [a #t_avsearch href="#advsearch" Advanced]
184 [a #t_prefs href="#prefs" ⚙]
190 [form method=POST action="?a=multitag"'
195 [a href="#multitag" Add Tags]'
202 '; } | "$_EXEC/cgilite/html-sh.sed"