+list_items() {
+ local mode meta cachename
+ mode="$(COOKIE mode |grep -m1 -axE 'index|browse' || printf index )"
+
+ cachename="$(printf '%s\n' "$mode" "$FILTER" "$SEARCH" "$ORDER" |sha1sum)"
+ cachename="$_DATA/$ITEM/.index/${cachename% -}.cache"
+ meta="$_DATA/$ITEM/.index/meta"
+ meta_dir "$_DATA/$ITEM/"
+
+ if [ "$mode" = browse ]; then
+ [ "$ITEM" ] && printf '0 0 0 \ \ ../\n'
+ (cd "$_DATA/$ITEM";
+ find ./ -type d \! -name .index -mindepth 1 -maxdepth 1 \
+ ) | sort |while read dir; do
+ printf '0 0 0 \\ \\ %s\n' "$(STRING "${dir#./}")"
+ done
+
+ if [ "$cachename" -nt "$meta" ]; then
+ cat "$cachename"
+ else
+ list_meta "$meta" \
+ | list_filter \
+ | list_order \
+ | { [ -d "${cachename%/*}" ] && tee "$cachename" || cat; }
+ fi
+
+ elif [ "$mode" = index ]; then
+ if [ -f "$cachename" -a ! "$(find "$_DATA" -path '*/.index/meta' -newer "$cachename")" ]; then
+ cat "$cachename"
+ else
+ list_meta \
+ | list_filter \
+ | list_order \
+ | { [ -d "${cachename%/*}" ] && tee "$cachename" || cat; }
+ fi
+ fi
+}
+
+list_paginate() {
+ local page i c n end qry
+ page="$(GET p |grep -axE '[0-9]+' || printf 1)"; c=1
+ end=$((page + LISTSIZE))
+ eval "$LOCAL_META" # localize vars from db_meta
+
+ printf '[div .itemlist '
+ while :; do
+ if [ $c -lt $page ]; then
+ read -r discard || break
+ elif [ $c -ge $end ]; then
+ c=$((c + $(wc -l) ))
+ break
+ else
+ read_meta || break
+ list_item
+ fi
+ c=$((c + 1))
+ done
+ printf ']'
+
+ [ $(( c % LISTSIZE )) -gt 0 ] \
+ && end=$((c / LISTSIZE + 1)) \
+ || end=$((c / LISTSIZE))
+
+ printf '[div .pagination'
+ for n in $( seq 1 $end ); do
+ c=$(( (n - 1) * LISTSIZE + 1 ))
+ [ $c = $page ] \
+ && printf '[a .page .current href="?p=%i&%s" %i]' "${c}" "${QUERY_STRING#p=*&}" "$n" \
+ || printf '[a .page href="?p=%i&%s" %i]' "${c}" "${QUERY_STRING#p=*&}" "$n"
+ done
+ printf ']'