-list_item(){
- name="$(HTML "$1")"
- path="$(HTML "$ITEM/$1")"
- meta="$_DATA/$ITEM/.index/meta"
-
- if [ -d "$_DATA/$ITEM/$1" ]; then
- printf '[a .list .dir href="%s" %s]' \
- "$path" "$name"
- elif [ -f "$meta" ]; then
- read -r length width height tags comment n <<-EOF
- $(grep -m1 -F " $1" "$meta")
- EOF
- printf '[div .list .file
- [a href="%s" [img src="%s?a=thumbnail"] %s]
- [span .time %i:%imin] [span .dim %ix%i] %s
- ]' \
- "$path" "$path" "$name" \
- "$((length / 60))" "$((length % 60))" \
- "$width" "$height" \
- "$(printf %s\\n "${tags#tags=}" |tr , ' ' |xargs printf '[span .tag %s]')"
+. "$_EXEC/indexmeta.sh"
+. "$_EXEC/widgets.sh"
+
+list_item() {
+ local meta type length width height tags comment name display link
+ meta="${1}"; type="${meta%% *}"; meta="${meta#* }"
+
+ if [ "$type" = dir ]; then
+ name="${meta%% *}";
+ display="$(HTML "$name")"; link="$(URL "$ITEM/$name")"
+ printf '[a .list .dir href="%s" %s]' "${link}?${w_refuri#*\?}" "$name"
+ return 0
+ fi
+
+ length="${meta%% *}"; meta="${meta#* }"
+ width="${meta%% *}"; meta="${meta#* }"
+ height="${meta%% *}"; meta="${meta#* }"
+ tags="${meta%% *}"; meta="${meta#* }"
+ comment="${meta%% *}"; meta="${meta#* }"
+ name="${meta%% *}"; meta="${meta#* }"
+
+ if [ "$type" = metashort ]; then
+ name="$(list_fullname "$(UNSTRING "${name%${CR}}")")"
+ fi
+ if [ -f "$_DATA/$ITEM/$name" ]; then
+ link="$(URL "$ITEM/$name")"
+ name="$(HTML "$ITEM/$name")"
+ printf '[div .list .file
+ [a href="%s" [img src="%s?a=thumbnail"]][label %s]
+ [span .time %i:%imin] [span .dim %ix%i] %s
+ [checkbox "select" "%s" id="select_%s"][label for="select_%s" +]
+ ]' \
+ "$link" "$link" "${name##*/}" \
+ "$((length / 60))" "$((length % 60))" \
+ "$width" "$height" \
+ "$(printf '%s\n' "${tags#tags=}" \
+ | sed -r "$UNSTRING"' s;^;,;; s;,+;,;g; s;,$;;;
+ :X s;,([^,]+)(,|$); [span .tag \1]\2;; tX;'
+ )" "$name" "$link" "$link"
+ else
+ printf 'Canning record for nonexist file: %s\n' "$name" >&2
+ # meta_purge "$_DATA/$ITEM/$name"
+ fi
+}
+
+
+[ "$FILTER" ] && list_fex="$(
+ fex='p'
+ STRING "$FILTER^" \
+ | sed -r 's;\^;\n;g; s;[]\/\(\)\\\^\$\?\.\+\*\;\[\{\}];\\&;g' \
+ | while read -r f; do
+ [ ! "${f#~}" ] && continue
+ [ "${f#~}" = "$f" ] \
+ && fex="/(\ttags=([^\t]*,)?)(${f})((,[^\t]*)?\t)/{${fex}}" \
+ || fex="/(\ttags=([^\t]*,)?)(${f#~})((,[^\t]*)?\t)/d; ${fex}"
+ printf '%s\n' "${fex}"
+ done \
+ | tail -n1
+)"
+
+list_fullname(){
+ sn="$1"
+ [ ! "${sn%%*/*}" ] && base="${sn%/*}" || base=.
+ file="$(printf '%s' "$_DATA/$ITEM/$sn".*)"
+ file="${file##*/}"
+ [ -e "$_DATA/$ITEM/$base/${file}" ] \
+ && printf '%s\n' "${base}/${file}"
+}
+
+list_filter(){
+ if [ "$FILTER" ]; then
+ sed -nr "$list_fex"
+ elif [ "${SEARCH#!}" != "${SEARCH}" ]; then
+ grep -aviEe "$(STRING "${SEARCH}" \
+ | sed -r ':x s;((^|[^\\])(\\\\)*)\+;\1 ;g; tx;
+ s;((^|[^\\])(\\\\)*)\\\+;\1+;g;
+ s; ;\\+;g;')"
+ elif [ "${SEARCH}" ]; then
+ grep -aiEe "$(STRING "${SEARCH}" \
+ | sed -r ':x s;((^|[^\\])(\\\\)*)\+;\1 ;g; tx;
+ s;((^|[^\\])(\\\\)*)\\\+;\1+;g;
+ s; ;\\+;g;')"