export HTTP_REFERER="${HTTP_REFERER:-$(HEADER Referer)}"
export LANGUAGE ERROR_MSG
-mdfile(){
- # Override mdfile Selection from tools.sh
- local page="$(PATH "$1")"
- page="${page%/}"
-
- # Additional part:
- # if PAGE Address is LANGUAGE Page, jump to regular processing
- # else if LANGUAGE Page exists, add language tag
- # Also the reason why `mdfile` should not be used in `acl.sh`
- if [ "${page%/:${LANGUAGE}}" != "$page" ]; then
- :
- elif [ -f "$_DATA/pages/$page/:$LANGUAGE/#page.md" ]; then
- printf %s\\n "$_DATA/pages/$page/:$LANGUAGE/#page.md"
- return 0
- elif [ -f "$_EXEC/pages/$page/:$LANGUAGE/#page.md" ]; then
- printf %s\\n "$_EXEC/pages/$page/:$LANGUAGE/#page.md"
- return 0
- fi 2>&-
-
- # Regular processing, keep in sync with tools.sh
- if [ -f "$_DATA/pages/$page/#page.md" ]; then
- printf %s\\n "$_DATA/pages/$page/#page.md"
- return 0
- elif [ -f "$_EXEC/pages/$page/#page.md" ]; then
- printf %s\\n "$_EXEC/pages/$page/#page.md"
- return 0
- else
- return 1
- fi 2>&-
- # ^^ suppress error messages produced
- # by printf when stdout was closed
-}
-
-# UGLY! UGLY! UGLY!
-# Override markdown processor from `tools.sh` to add link suffixes
-# -> better implement a parser stack, i.e. pipeline markdown + other parser plugins
-if [ "$(which awk)" ]; then
- md() {
- awk -f "$_EXEC/md_macros.awk" -f "$_EXEC/cgilite/markdown.awk" \
- | sed -E 's;(<[^>]+ )href="((/[^"/]+|[^"/]+[^:/]|)/([^"/]+/)*)"([^>]*>);\1href="\2:'"${LANGUAGE}"'"\5;g'
- }
-elif [ "$(which busybox)" ]; then
- md() {
- busybox awk -f "$_EXEC/md_macros.awk" -f "$_EXEC/cgilite/markdown.awk" \
- | sed -E 's;(<[^>]+ )href="((/[^"/]+|[^"/]+[^:/]|)/([^"/]+/)*)"([^>]*>);\1href="\2:'"${LANGUAGE}"'"\5;g'
- }
-else
- md() { cat; }
-fi
-
case ${HTTP_REFERER} in
*/:*/*):;;
*/:*)
# ;;
*/:?*)
LANGUAGE="${PATH_INFO##*/:}"
+ PATH_INFO="${PATH_INFO%:*}"
- if mdfile "${PATH_INFO}/"; then
- # Pretend to deliver Language Page, if Language Tag is valid
- PATH_INFO="${PATH_INFO}/"
- elif [ "$LANGUAGE" = "$LANGUAGE_DEFAULT" ]; then
- # Pretend Language Tag was omitted for default Language
- PATH_INFO="${PATH_INFO%:*}"
- else
- # Deliver default Page if Language is not found
- ERROR_MSG="TRANSLATION NOT FOUND"
- PATH_INFO="${PATH_INFO%:*}"
- fi
+ [ "$LANGUAGE" != "$LANGUAGE_DEFAULT" ] \
+ && case "$(mdfile "${PATH_INFO}")" in
+ *"/:$LANGUAGE/#page.md")
+ :;;
+ '')
+ :;;
+ *)ERROR_MSG="TRANSLATION NOT FOUND"
+ ;;
+ esac
;;
/|*/*/) # Keep Language from Referer
if [ "$LANGUAGE_REFERRED" -a "$LANGUAGE_REFERRED" != "$LANGUAGE_DEFAULT" ]; then
include_tools="$0"
if [ "$(which awk)" ]; then
- md() { awk -f "$_EXEC/md_macros.awk" -f "$_EXEC/cgilite/markdown.awk"; }
+ md() {
+ awk -f "$_EXEC/md_macros.awk" -f "$_EXEC/cgilite/markdown.awk" \
+ | sed -E 's;(<[^>]+ )href="((/[^"/]+|[^"/]+[^:/]|)/([^"/]+/)*)"([^>]*>);\1href="\2:'"${LANGUAGE}"'"\5;g'
+ }
elif [ "$(which busybox)" ]; then
- md() { busybox awk -f "$_EXEC/md_macros.awk" -f "$_EXEC/cgilite/markdown.awk"; }
+ md() {
+ busybox awk -f "$_EXEC/md_macros.awk" -f "$_EXEC/cgilite/markdown.awk" \
+ | sed -E 's;(<[^>]+ )href="((/[^"/]+|[^"/]+[^:/]|)/([^"/]+/)*)"([^>]*>);\1href="\2:'"${LANGUAGE}"'"\5;g'
+ }
else
md() { cat; }
fi
# Check if page exists, if possible fall
# back to default page from installation
local page="$(PATH "$1")"
+ page="${page%/}"
- # IMPORTANT: A Copy of this function exists
- # in `handlers/10_translations.sh`
- # Look into it now!
- # Keep it synchronized, when changing anything
-
- if [ -f "$_DATA/pages/$page/#page.md" ]; then
+ # Regular processing, keep in sync with tools.sh
+ if [ -f "$_DATA/pages/$page/:$LANGUAGE/#page.md" ]; then
+ printf %s\\n "$_DATA/pages/$page/:$LANGUAGE/#page.md"
+ elif [ -f "$_DATA/pages/$page/#page.md" ]; then
printf %s\\n "$_DATA/pages/$page/#page.md"
- return 0
+ elif [ -f "$_EXEC/pages/$page/:$LANGUAGE/#page.md" ]; then
+ printf %s\\n "$_EXEC/pages/$page/:$LANGUAGE/#page.md"
elif [ -f "$_EXEC/pages/$page/#page.md" ]; then
printf %s\\n "$_EXEC/pages/$page/#page.md"
- return 0
else
return 1
fi 2>&-
# ^^ suppress error messages produced
# by printf when stdout was closed
+
+ return 0
}
size_human(){
fi
}
+attachment_glob(){
+ local pattern="${1%/}" IFS=''
+ local glob page pagedir
+
+ page="${pattern%/*}"
+ [ "$page" = "$pattern" ] && page=.
+ [ ! "$page" ] && page=/
+ pattern="${pattern##*/}"
+ [ ! "$pattern" ] && pattern="*"
+
+ case $page in
+ /*)
+ for glob in "$_DATA/pages/$page/#attachments"/$pattern; do printf '%s\n' "${glob#"$_DATA/pages"}"; done
+ for glob in "$_EXEC/pages/$page/#attachments"/$pattern; do printf '%s\n' "${glob#"$_EXEC/pages"}"; done
+ ;;
+ *)
+ for glob in "$_DATA/pages/$PATH_INFO/$page/#attachments"/$pattern; do printf '%s\n' "${glob#"$_DATA/pages/$PATH_INFO/"}"; done
+ for glob in "$_EXEC/pages/$PATH_INFO/$page/#attachments"/$pattern; do printf '%s\n' "${glob#"$_EXEC/pages/$PATH_INFO/"}"; done
+ ;;
+ esac \
+ | sort -u \
+ | while read -r glob; do
+ pagedir="$(page_abs "${glob%%/#attachments/*}/")"
+ [ -d "$_DATA/pages/$pagedir" -o -d "$_EXEC/pages/$pagedir" ] \
+ && printf '%s\n' "${glob%%/#attachments/*}/${glob#*/#attachments/}"
+ done
+}
+
page_glob(){
local pattern="${1%/}/" IFS=''
local glob page pagedir