exit 0
fi
-vcf_escape(){
- for each in "$@"; do
- printf %s\\n "$each" \
- | sed -E ':X;$!{N;bX}; s;\r\n;\n;g; s;([;,\\]);\\\1;g; s;\n;\\n;g;'
- done \
- | sed -E ':X;$!{N;bX}; s;\n;\;;g'
-}
-
# [ "${_POST[hi_select]}" = "list" ] || _POST[hi_company]="${_POST[hi_other]}"
# [ -n "${_POST[hi_company]}${_POST[hi_number]}${_POST[hi_status]}" ] \
-# && _POST[X-HEALTH-INSURANCE]="$(vcf_escape "${_POST[hi_company]}" "${_POST[hi_number]}" "${_POST[hi_status]}")"
+# && _POST[X-HEALTH-INSURANCE]="$(pdi_escape "${_POST[hi_company]}" "${_POST[hi_number]}" "${_POST[hi_status]}")"
# vcf="$(pdi_load "$cardfile")"
vcf="$(pdi_load "$tempfile")"
-vcf="$(pdi_update_value "$vcf" N 1 "$(vcf_escape "$(POST 1N)" "$(POST 2N)" "$(POST 3N)" "$(POST 4N)" "$(POST 5N)")")"
-vcf="$(pdi_update_value "$vcf" FN 1 "$(vcf_escape "$(POST 4N) $(POST 2N) $(POST 3N) $(POST 1N) $(POST 5N)" \
+vcf="$(pdi_update_value "$vcf" N 1 "$(pdi_escape "$(POST 1N)" "$(POST 2N)" "$(POST 3N)" "$(POST 4N)" "$(POST 5N)")")"
+vcf="$(pdi_update_value "$vcf" FN 1 "$(pdi_escape "$(POST 4N) $(POST 2N) $(POST 3N) $(POST 1N) $(POST 5N)" \
| sed -E 's;^ +;;; s; +$;;; s; +; ;g;')" )"
for field in $(POST_KEYS |grep -xE '[A-Z][A-Z0-9-]*'); do
for cnt in $(seq 1 $(POST_COUNT "$field")); do
case "$field" in
# (TEL)
- # printf '%s;TYPE=%s:%s\r\n' "${field}" "${_POST[phonetype${key#TEL}]}" "$(vcf_escape "$(POST "$field" "$cnt")")"
+ # printf '%s;TYPE=%s:%s\r\n' "${field}" "${_POST[phonetype${key#TEL}]}" "$(pdi_escape "$(POST "$field" "$cnt")")"
# ;;
X-HEALTH-INSURANCE)
hi_select="$(POST "$field" "$cnt")"
if [ "$hi_select" = list ]; then
- vcf="$(pdi_update_value "$vcf" "$field" "$cnt" "$(vcf_escape "$(POST "hi_company" "$cnt")" \
+ vcf="$(pdi_update_value "$vcf" "$field" "$cnt" "$(pdi_escape "$(POST "hi_company" "$cnt")" \
"$(POST "hi_number" "$cnt")" \
"$(POST "hi_status" "$cnt")" \
)")"
elif [ "$hi_select" = other ]; then
- vcf="$(pdi_update_value "$vcf" "$field" "$cnt" "$(vcf_escape "$(POST "hi_other" "$cnt")" \
+ vcf="$(pdi_update_value "$vcf" "$field" "$cnt" "$(pdi_escape "$(POST "hi_other" "$cnt")" \
"$(POST "hi_number" "$cnt")" \
"$(POST "hi_status" "$cnt")" \
)")"
;;
TEL)
vcf="$(pdi_update_attrib "$vcf" TEL $cnt TYPE="$(POST teltype $cnt |grep -Exm1 'HOME|WORK|CELL|FAX')")"
- vcf="$(pdi_update_value "$vcf" "$field" "$cnt" "$(vcf_escape "$(POST "$field" "$cnt")")")"
+ vcf="$(pdi_update_value "$vcf" "$field" "$cnt" "$(pdi_escape "$(POST "$field" "$cnt")")")"
;;
*)
- vcf="$(pdi_update_value "$vcf" "$field" "$cnt" "$(vcf_escape "$(POST "$field" "$cnt")")")"
+ vcf="$(pdi_update_value "$vcf" "$field" "$cnt" "$(pdi_escape "$(POST "$field" "$cnt")")")"
;;
esac
done; done
cnt="$(pdi_count "$card" "$item")"
case $item in
- FN) printf '[h2 .item .FN . %s]' "$(pdi_value "$card" FN |unescape |HTML)"
+ FN) printf '[h2 .item .FN . %s]' "$(pdi_value "$card" FN |pdi_unescape |HTML)"
;;
GENDER) printf '[span .item .GENDER . %s]' "$(pdi_value "$card" GENDER |l10n)"
;;
NICKNAME) seq 1 $cnt |while read c; do
printf '[span .item .NICKNAME aka. "%s"]' \
- "$(pdi_value "$card" NICKNAME $c |unescape |HTML)"
+ "$(pdi_value "$card" NICKNAME $c |pdi_unescape |HTML)"
done
;;
X-ZACK-JOINDATE|X-ZACK-LEAVEDATE) if [ $cnt -gt 0 ]; then
[ $cnt -gt 0 ] && printf '[h3 %s]' "$(l10n EMAIL)"
seq 1 $cnt |while read c; do
printf '[a .item .EMAIL href="mailto:%s" . %s]' \
- "$(pdi_value "$card" EMAIL $c |unescape |HTML)" \
- "$(pdi_value "$card" EMAIL $c |unescape |HTML)"
+ "$(pdi_value "$card" EMAIL $c |pdi_unescape |HTML)" \
+ "$(pdi_value "$card" EMAIL $c |pdi_unescape |HTML)"
done
;;
TEL)
[ "$teltype" ] \
&& printf '[span .item .TEL [span .type . %s:] %s]' \
"$(l10n "TYPE=$teltype" |HTML)" \
- "$(pdi_value "$card" TEL $c |unescape |HTML)" \
+ "$(pdi_value "$card" TEL $c |pdi_unescape |HTML)" \
|| printf '[span .item .TEL . %s]' \
- "$(pdi_value "$card" TEL $c |unescape |HTML)"
+ "$(pdi_value "$card" TEL $c |pdi_unescape |HTML)"
done
;;
X-HEALTH-INSURANCE)
printf '[span .item .hi_company . %s]
[span .item .hi_number [label %s:] %s]
[span .item .hi_status [label %s:] %s]
- ' "$(unescape "$hi_name" |HTML)" \
- "$(l10n hi_number)" "$(unescape "$hi_number" |HTML)" \
- "$(l10n hi_status)" "$(unescape "$hi_status" |HTML)"
+ ' "$(pdi_unescape "$hi_name" |HTML)" \
+ "$(l10n hi_number)" "$(pdi_unescape "$hi_number" |HTML)" \
+ "$(l10n hi_status)" "$(pdi_unescape "$hi_status" |HTML)"
done
;;
therapies)
shy="$(printf '\302\255')"
seq 1 $cnt |while read c; do
printf '[span .item .%s . %s]' "$item" \
- "$(pdi_value "$card" "$item" $c |sed -r "s;(straße|weg|damm|allee|ufer);${shy}\1;g" |unescape |HTML)"
+ "$(pdi_value "$card" "$item" $c |sed -r "s;(straße|weg|damm|allee|ufer);${shy}\1;g" |pdi_unescape |HTML)"
done
;;
esac
$N
EOF
else
- N="$(pdi_value "$card" FN |unescape)"
+ N="$(pdi_value "$card" FN |pdi_unescape)"
n1="${N%%[a-z]*}" n1="${N#$n1}"
[ "$n1" ] || n1="${N##* }"
n2="${N%$n1}"
printf '[checkbox "%s_delete_%i" "true" .delete #%s_delete_%i][label for="%s_delete_%i" %s]' \
"$item" $c "$item" $c "$item" $c "$(l10n delete)"
printf '<textarea class="item %s" name="%s">%s</textarea>' \
- "$item" "$item" "$(pdi_value "$card" "$item" $c |unescape |HTML)"
+ "$item" "$item" "$(pdi_value "$card" "$item" $c |pdi_unescape |HTML)"
done
printf '[button type="submit" name="action" value="addfield %s" %s ]' "$item" "$(l10n edit_addfield)"
;;
"$([ "$teltype" = 'FAX' ] && printf 'selected="selected"')" "$(l10n TYPE=FAX)"
printf '[input .item .%s name="%s" value="%s" placeholder="%s"]' \
- "$item" "$item" "$(pdi_value "$card" "$item" $c |unescape |HTML)" "$(l10n "$item")"
+ "$item" "$item" "$(pdi_value "$card" "$item" $c |pdi_unescape |HTML)" "$(l10n "$item")"
done
printf '[button type="submit" name="action" value="addfield %s" %s ]' "$item" "$(l10n edit_addfield)"
;;
-->[select class="item" name="hi_company"
[option value="" disabled="disabled" $(selected "${hi_name}" "") . $(l10n hi_company)]
$(list_hi_companies |while read f; do
- printf '[option value="%s" %s . %s]' "$(unescape "$f" |HTML)" \
+ printf '[option value="%s" %s . %s]' "$(pdi_unescape "$f" |HTML)" \
"$(selected "$f" "$hi_name")" \
- "$(unescape "$f" |HTML)"
+ "$(pdi_unescape "$f" |HTML)"
done)
]
[input type="text" name="hi_other" value="$hi_name" placeholder="$(l10n hi_company)"]
- [input name="hi_number" value="$(unescape "$hi_number" |HTML)" placeholder="$(l10n hi_number)"]
- [input name="hi_status" value="$(unescape "$hi_status" |HTML)" placeholder="$(l10n hi_status)"]
+ [input name="hi_number" value="$(pdi_unescape "$hi_number" |HTML)" placeholder="$(l10n hi_number)"]
+ [input name="hi_status" value="$(pdi_unescape "$hi_status" |HTML)" placeholder="$(l10n hi_status)"]
EOF
done
;;
printf '[checkbox "%s_delete_%i" "true" .delete #%s_delete_%i][label for="%s_delete_%i" %s]' \
"$item" $c "$item" $c "$item" $c "$(l10n delete)"
printf '[input .item .%s name="%s" value="%s" placeholder="%s"]' \
- "$item" "$item" "$(pdi_value "$card" "$item" $c |unescape |HTML)" "$(l10n "$item")"
+ "$item" "$item" "$(pdi_value "$card" "$item" $c |pdi_unescape |HTML)" "$(l10n "$item")"
done
printf '[button type="submit" name="action" value="addfield %s" %s ]' "$item" "$(l10n edit_addfield)"
;;
p;' "$1"
}
+pdi_escape(){
+ local in out=''
+ for in in "$@"; do
+ out="${out}${out:+;}"
+ while [ "$in" ]; do case $in in
+ \\*) out="${out}\\\\"; in="${in#\\}" ;;
+ ,*) out="${out}\\,"; in="${in#,}" ;;
+ \;*) out="${out}\\;"; in="${in#;}" ;;
+ "$BR"*) out="${out}\\n"; in="${in#${BR}}" ;;
+ *) out="${out}${in%%[\\,;${BR}]*}"; in="${in#${in%%[\\,;${BR}]*}}" ;;
+ esac; done
+ done
+ printf '%s\n' "$out"
+}
+
+pdi_unescape(){
+ local in out=''
+ [ $# -gt 0 ] && in="$*" || in="$(cat)"
+ while [ "$in" ]; do case $in in
+ \\\\*) out="${out}\\"; in="${in#\\\\}" ;;
+ \\n*) out="${out}${BR}"; in="${in#\\n}" ;;
+ \\*) in="${in#\\}" ;;
+ *) out="${out}${in%%\\*}"; in="${in#${in%%\\*}}" ;;
+ esac; done
+ printf '%s\n' "$out"
+}
+
pdi_count(){
local card="$1" name="$2" rc='' cnt=0
while rc="${card#*${BR}${name};}"; do