From 555fafa2e76b5c1a146e13529d398ee6c3e50287 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Sun, 21 May 2023 00:15:50 +0200 Subject: [PATCH] URL rewriting for translation pages --- handlers/10_translations.sh | 59 +++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100755 handlers/10_translations.sh diff --git a/handlers/10_translations.sh b/handlers/10_translations.sh new file mode 100755 index 0000000..e666408 --- /dev/null +++ b/handlers/10_translations.sh @@ -0,0 +1,59 @@ +#!/bin/sh + +export LANGUAGE_DEFAULT="${LANGUAGE_DEFAULT:-en}" +export HTTP_REFERER="${HTTP_REFERER:-$(HEADER Referer)}" + +case ${HTTP_REFERER} in + */:*/*):;; + */:*) + LANGUAGE_REFERRED="${HTTP_REFERER##*/:}" + ;; +esac + +export LANGUAGE="${LANGUAGE_REFERRED:-${LANGUAGE_DEFAULT}}" + +case ${PATH_INFO} in + */:?*/\[attachment\]/?*) + export LANGUAGE="${PATH_INFO#*/:}" + LANGUAGE="${LANGUAGE%%/*}" + PATH_INFO="${PATH_INFO%%:?*/*}${PATH_INFO#*/:?*/}" + ;; + */:?*/\[attachment\]) + export LANGUAGE="${PATH_INFO#*/:}" + LANGUAGE="${LANGUAGE%%/*}" + PATH_INFO="${PATH_INFO%:?*/\[attachment\]}[attachment]" + ;; + */:*/?*) # Never occurs + :;; + */:?*/) # Faulty URL build + REDIRECT "${_BASE}${PATH_INFO%/}" + ;; +# */:"${LANGUAGE_DEFAULT}") +# REDIRECT "${_BASE}${PATH_INFO%:*}" +# ;; + */:?*) + export LANGUAGE="${PATH_INFO##*/:}" + if mdfile "${PATH_INFO}/"; then + PATH_INFO="${PATH_INFO}/" + elif [ "$LANGUAGE" = "$LANGUAGE_DEFAULT" ]; then + PATH_INFO="${PATH_INFO%:*}" + else + export ERROR_MSG="TRANSLATION NOT FOUND" + PATH_INFO="${PATH_INFO%:*}" + fi + ;; + /|*/*/) + if [ "$LANGUAGE_REFERRED" -a "$LANGUAGE_REFERRED" != "$LANGUAGE_DEFAULT" ]; then + REDIRECT "${_BASE}${PATH_INFO}:${LANGUAGE_REFERRED}" + fi + ;; + */:*/\[*\]) # Considered valid in most cases + :;; + */\[*\]) + if [ "$LANGUAGE_REFERRED" -a "$LANGUAGE_REFERRED" != "$LANGUAGE_DEFAULT" ]; then + REDIRECT "${_BASE}${PATH_INFO%\[*\]}:${LANGUAGE_REFERRED}/[${PATH_INFO##*/\[}" + fi + ;; +esac + +return 1 -- 2.39.2