comparison s4-funcs.sh @ 942:5d70fa029f8d draft

Support MathJax rendering
author HIROSE Yuuji <yuuji@gentei.org>
date Mon, 25 Oct 2021 18:39:44 +0900
parents 79c7e64884c4
children 420ad90116e6
comparison
equal deleted inserted replaced
941:79c7e64884c4 942:5d70fa029f8d
76 blogcutoffflagrowid=-1 76 blogcutoffflagrowid=-1
77 nonewgroupworld=${NONEWGROUPWORLD:-*archive*} 77 nonewgroupworld=${NONEWGROUPWORLD:-*archive*}
78 whatsnewdays=${WHATS_NEW_DAYS:-14} 78 whatsnewdays=${WHATS_NEW_DAYS:-14}
79 main_session=`date +%F-$$` 79 main_session=`date +%F-$$`
80 session=$main_session 80 session=$main_session
81 mathjax=${MATHJAX:-'<script>MathJax = {tex: {tags: "ams"}};</script>
82 <script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script><script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>'}
81 83
82 tconfs="" 84 tconfs=""
83 imgcached=cache/${S4WORLD:+$S4WORLD/}img.`date +%Y/%m` 85 imgcached=cache/${S4WORLD:+$S4WORLD/}img.`date +%Y/%m`
84 conftbl=_tblconf 86 conftbl=_tblconf
85 nl=" 87 nl="
90 92
91 # Start debug logging 93 # Start debug logging
92 logtag="($$)${S4WORLD:+{$S4WORLD\}}" 94 logtag="($$)${S4WORLD:+{$S4WORLD\}}"
93 exec 3>> $logdir/debug.out 95 exec 3>> $logdir/debug.out
94 err() { 96 err() {
95 echo "[`date +%F-%T%z`]$logtag $@" 1>&3 97 # echo "[`date +%F-%T%z`]$logtag $@" 1>&3
98 # Avoid backslash escape sequences
99 cat<<EOF 1>&3
100 [`date +%F-%T%z`]$logtag $@
101 EOF
96 } 102 }
97 case "$HTTP_USER_AGENT" in 103 case "$HTTP_USER_AGENT" in
98 *i[Pp]hone*|*[Aa]ndroid*) touchpanel=1 ;; 104 *i[Pp]hone*|*[Aa]ndroid*) touchpanel=1 ;;
99 *) touchpanel="" ;; 105 *) touchpanel="" ;;
100 esac 106 esac
452 echo ".output $sqo" >&5 458 echo ".output $sqo" >&5
453 logstart 459 logstart
454 if [ -z "$1" ]; then 460 if [ -z "$1" ]; then
455 tee -a $querylog 461 tee -a $querylog
456 else 462 else
457 echo "$@" >> $querylog 463 printf '%s\n' "$@" >> $querylog
458 echo "$@" 464 printf '%s\n' "$@"
459 fi >&5 465 fi >&5
460 echo ".output stdout" >&5 466 echo ".output stdout" >&5
461 cat $sqo 467 cat $sqo
462 rc=$? 468 rc=$?
463 logend 469 logend
799 case "$var" in 805 case "$var" in
800 owner) 806 owner)
801 if [ x"$user" = x"$val" ]; then 807 if [ x"$user" = x"$val" ]; then
802 echo $user; return 808 echo $user; return
803 elif ismember $user $val; then 809 elif ismember $user $val; then
804 echo $val; return 810 printf '%s' "$val"; return
805 fi ;; 811 fi ;;
806 esac 812 esac
807 ## err getpar/ret: "val=[$val]" 813 ## err getpar/ret: "val=[$val]"
808 echo "$val" 814 printf '%s' "$val"
809 } 815 }
810 setskey() { 816 setskey() {
811 # For quick response...(?) 817 # For quick response...(?)
812 query "REPLACE INTO $sesstb VALUES('$1', '$2', datetime('now', 'localtime', '$timeout'));" 818 query "REPLACE INTO $sesstb VALUES('$1', '$2', datetime('now', 'localtime', '$timeout'));"
813 } 819 }
843 case "$v" in 849 case "$v" in
844 "") return ;; # null 850 "") return ;; # null
845 "X'"*) # quoted hex string 851 "X'"*) # quoted hex string
846 echo $1 ;; 852 echo $1 ;;
847 *\"*) # string including dbl-quote" 853 *\"*) # string including dbl-quote"
848 v=`echo "$v"|sed -e 's/\"/\"\"/g'` 854 v=`printf '%s' "$v"|sed -e 's/\"/\"\"/g'`
849 echo "\"$v\"" 855 printf '%s' "\"$v\""
850 return ;; 856 return ;;
851 *.*.*|*-*-*|*[Ee]*[Ee]*|[Ee]*|*[\ -,:-df-~]*) # string 857 *.*.*|*-*-*|*[Ee]*[Ee]*|[Ee]*|*[\ -,:-df-~]*) # string
852 echo "\"$v\"" 858 printf '%s' "\"$v\""
853 return ;; 859 return ;;
854 *) 860 *)
855 if expr "$v" : '[-0-9.Ee][-0-9.Ee]*$' >/dev/null 2>&1; then 861 if expr "$v" : '[-0-9.Ee][-0-9.Ee]*$' >/dev/null 2>&1; then
856 echo $v # MAYBE numeric, maybe... 862 printf '%s' $v # MAYBE numeric, maybe...
857 else 863 else
858 echo "\"$v\"" 864 printf '%s' "\"$v\""
859 fi ;; 865 fi ;;
860 esac) 866 esac)
861 } 867 }
862 sqlquotestr() ( 868 sqlquotestr() (
863 case "$1" in 869 case "$1" in
864 *\'*) v=`echo "$1"| sed "s/'/''/g"` 870 *\'*) v=`printf '%s' "$1"| sed "s/'/''/g"`
865 echo "'$v'" ;; 871 printf '%s' "'$v'" ;;
866 *) echo "'$1'" ;; 872 *) printf '%s' "'$1'" ;;
867 esac 873 esac
868 ) 874 )
869 mktempd() { 875 mktempd() {
870 TMPDIR=$tmpd mktemp -d -t $session 876 TMPDIR=$tmpd mktemp -d -t $session
871 } 877 }
1000 done 1006 done
1001 else 1007 else
1002 rm -f $td/$c.count 1008 rm -f $td/$c.count
1003 case $type in 1009 case $type in
1004 file:*) 1010 file:*)
1005 echo "$val" \ 1011 printf '%s\n' "$val" \
1006 | while read fn; do 1012 | while read fn; do
1007 file=$td/$fn 1013 file=$td/$fn
1008 if [ ! -s "$file" ]; then 1014 if [ ! -s "$file" ]; then
1009 ## sq $db "select quote(bin) from $cond and val=\"$fn\"" \ 1015 ## sq $db "select quote(bin) from $cond and val=\"$fn\"" \
1010 query "select quote(bin) from $cond and val=\"$fn\";" \ 1016 query "select quote(bin) from $cond and val=\"$fn\";" \
1019 fi 1025 fi
1020 done 1026 done
1021 ;; 1027 ;;
1022 esac 1028 esac
1023 fi 1029 fi
1024 echo "$val" # Keep newlines by "" 1030 printf '%s' "$val"
1025 return 1031 return
1026 fi 1032 fi
1027 done 1033 done
1028 done) 1034 done)
1029 } 1035 }
1563 do 1569 do
1564 k=${us%%\=*} 1570 k=${us%%\=*}
1565 #echo u=$us 1571 #echo u=$us
1566 #v="`echo ${us#*=}|nkf -Ww -mQ|sed -e 's/\"/\"\"/g'`" 1572 #v="`echo ${us#*=}|nkf -Ww -mQ|sed -e 's/\"/\"\"/g'`"
1567 v="`echo ${us#*=}|unhexize|sed -e 's/\"/\"\"/g'`" 1573 v="`echo ${us#*=}|unhexize|sed -e 's/\"/\"\"/g'`"
1568 # err k=$k v=$v
1569 case "$k" in 1574 case "$k" in
1570 *:filename) 1575 *:filename)
1571 mimetype=`file --mime-type - < "$tmpd/$v"|cut -d' ' -f2` 1576 mimetype=`file --mime-type - < "$tmpd/$v"|cut -d' ' -f2`
1572 type='file'; k=${k%:filename} 1577 type='file'; k=${k%:filename}
1573 # DO NOT ALLOW Space and '|' in file names 1578 # DO NOT ALLOW Space and '|' in file names
4216 fi 4221 fi
4217 else 4222 else
4218 # Binary update line is TOO LONG to pipelining 4223 # Binary update line is TOO LONG to pipelining
4219 sqlfile="$tmpd/sqlf.$$" 4224 sqlfile="$tmpd/sqlf.$$"
4220 if [ -n "$transaction" ]; then 4225 if [ -n "$transaction" ]; then
4221 echo "$sql" >> $transaction 4226 printf '%s' "$sql" >> $transaction
4222 else 4227 else
4223 echo "$sql" > $sqlfile 4228 printf '%s' "$sql" > $sqlfile
4224 query ".read $sqlfile" 4229 query ".read $sqlfile"
4225 fi 4230 fi
4226 fi 4231 fi
4227 # Rest of kt==m: set multiple mode 4232 # Rest of kt==m: set multiple mode
4228 nr=`getparcount $col` 4233 nr=`getparcount $col`
4233 i=0 4238 i=0
4234 while [ $i -lt $nr ]; do 4239 while [ $i -lt $nr ]; do
4235 limit="limit 1 offset $i" 4240 limit="limit 1 offset $i"
4236 i=$((i+1)) # increase beforehand against continue 4241 i=$((i+1)) # increase beforehand against continue
4237 val=`getvalquote $tbl $col "$limit"` 4242 val=`getvalquote $tbl $col "$limit"`
4238 [ -z "$val" -o x"$val" = x'""' -o x"$val" = x"NULL" ] && continue 4243 ##XXX [ -z "$val" -o x"$val" = x'""' -o x"$val" = x"NULL" ] && continue
4244 [ -z "$val" -o x"$val" = x'""' ] && continue
4239 ## err $col=$val 4245 ## err $col=$val
4240 bin=NULL 4246 bin=NULL
4241 ## err partype$col=`getpartype $col "$limit"` 4247 ## err partype$col=`getpartype $col "$limit"`
4242 ptype=`getpartype $col "$limit"` # partype should be obtained each time 4248 ptype=`getpartype $col "$limit"` # partype should be obtained each time
4243 case $ptype in 4249 case $ptype in
4249 type=\"file:$ct\" ;; 4255 type=\"file:$ct\" ;;
4250 "*"*) continue ;; # foreign table 4256 "*"*) continue ;; # foreign table
4251 *) type=\"string\" ;; 4257 *) type=\"string\" ;;
4252 esac 4258 esac
4253 case `gettbl_coltype $tbl/$col` in 4259 case `gettbl_coltype $tbl/$col` in
4260 [Cc][Hh][Ee][Cc][Kk][Bb][Oo][Xx]|[Tt][Ee][Xx][Tt])
4261 test x"$val" = x"NULL" && val="''"
4262 ;;
4254 password) # special care for password 4263 password) # special care for password
4255 # name={password,pswd1,pswd2} 4264 # name={password,pswd1,pswd2}
4256 p1=`getpar pswd1 "$limit"` 4265 p1=`getpar pswd1 "$limit"`
4257 if [ -z "$p1" ]; then 4266 if [ -z "$p1" ]; then
4258 continue # SKIP password setting, if p1 is empty 4267 continue # SKIP password setting, if p1 is empty
4282 #query "replace into $tb2 values($pval, \"$col\", $type, $val, $bin);" 4291 #query "replace into $tb2 values($pval, \"$col\", $type, $val, $bin);"
4283 sql="replace into $tb2 values($pval, \"$col\", $type, $val, $bin);" 4292 sql="replace into $tb2 values($pval, \"$col\", $type, $val, $bin);"
4284 if [ x"$bin" = x"NULL" ]; then 4293 if [ x"$bin" = x"NULL" ]; then
4285 ## err Normal-query: `echo $sql` 4294 ## err Normal-query: `echo $sql`
4286 if [ -n "$transaction" ]; then 4295 if [ -n "$transaction" ]; then
4287 echo "$sql" >> $transaction 4296 printf '%s' "$sql" >> $transaction
4288 else 4297 else
4289 query "$sql" 4298 query "$sql"
4290 fi 4299 fi
4291 else 4300 else
4292 sqlfile="$tmpd/query.$$" 4301 sqlfile="$tmpd/query.$$"
4293 ## err sqlfile=`ls -lF $sqlfile` 4302 ## err sqlfile=`ls -lF $sqlfile`
4294 if [ -n "$transaction" ]; then 4303 if [ -n "$transaction" ]; then
4295 echo "$sql" >> $transaction 4304 printf '%s' "$sql" >> $transaction
4296 else 4305 else
4297 echo "$sql" > $sqlfile 4306 printf '%s' "$sql" > $sqlfile
4298 query ".read $sqlfile" 4307 query ".read $sqlfile"
4299 fi 4308 fi
4300 fi 4309 fi
4301 ## err p2t done 4310 ## err p2t done
4302 done 4311 done
4345 <input name="confirm" type=checkbox value="yes">はい</span>' 4354 <input name="confirm" type=checkbox value="yes">はい</span>'
4346 fi 4355 fi
4347 # Image Cache dir 4356 # Image Cache dir
4348 ## err genform: getcache=$2/$rowid 4357 ## err genform: getcache=$2/$rowid
4349 td=`getcachedir "$2/$rowid"` 4358 td=`getcachedir "$2/$rowid"`
4350 while IFS=: read prompt name keytype type args; do 4359 while IFS=: read -r prompt name keytype type args; do
4351 [ -z "${prompt%%\#*}" ] && continue # skip comment line(#) 4360 [ -z "${prompt%%\#*}" ] && continue # skip comment line(#)
4352 sp="${args:+ }" 4361 sp="${args:+ }"
4353 form="" val="" 4362 form="" val=""
4354 if [ -n "$rowid" ]; then 4363 if [ -n "$rowid" ]; then
4355 # err genform2a: Seeking for "$2.$name, type=$type" 4364 # err genform2a: Seeking for "$2.$name, type=$type"
4356 rawval=`getvalbyid $2 $name $rowid $td` 4365 rawval=`getvalbyid $2 $name $rowid $td`
4357 val=`echo "$rawval"|htmlescape` 4366 val=`printf '%s\n' "$rawval"|htmlescape`
4358 ## err genform3a: getvalbyid $2 $name $rowid $td 4367 ## err genform3a: getvalbyid $2 $name $rowid $td
4359 ## err genform3b: val="[$val]" type="$type" 4368 ## err genform3b: val="[$val]" type="$type"
4360 fi 4369 fi
4361 if [ -n "$GF_VIEWONLY" ]; then 4370 if [ -n "$GF_VIEWONLY" ]; then
4362 is_hidden "$2" "$name" && continue 4371 is_hidden "$2" "$name" && continue
4364 case "$type" in 4373 case "$type" in
4365 text*) 4374 text*)
4366 cgiform=cgi_multi_$type 4375 cgiform=cgi_multi_$type
4367 if [ -s $td/$name.count -a -n "$val" ]; then 4376 if [ -s $td/$name.count -a -n "$val" ]; then
4368 form=`$cgiform $name $td` 4377 form=`$cgiform $name $td`
4369 val=$(echo "$val"| 4378 val=$(printf '%s\n' "$val"|
4370 while read fn; do 4379 while read fn; do
4371 echo "<tr><td>`cat $td/$fn|htmlescape|hreflink` 4380 echo "<tr><td>`cat $td/$fn|htmlescape|hreflink`
4372 </td></tr>$nl" 4381 </td></tr>$nl"
4373 done) 4382 done)
4374 val="<table>$nl$val$nl</table>" 4383 val="<table>$nl$val$nl</table>"
4375 else 4384 else
4376 #form="<input name=\"$name\" value=\"$val\" type=\"$type\"$sp$args>$nl" 4385 #form="<input name=\"$name\" value=\"$val\" type=\"$type\"$sp$args>$nl"
4386
4377 form=`cgi_$type $name "$rawval" "$args"` 4387 form=`cgi_$type $name "$rawval" "$args"`
4378 fi 4388 fi
4379 ;; 4389 ;;
4380 [Rr][Aa][Dd][Ii][Oo]) 4390 [Rr][Aa][Dd][Ii][Oo])
4381 fh="<label><input type=\"radio\" name=\"$name\"" 4391 fh="<label><input type=\"radio\" name=\"$name\""
4382 form="`echo $args|sed -e \ 4392 form="`echo $args|sed -e \
4383 \"s,\([^ =][^=]*\)=\([^= ][^= ]*\),$fh value=\\"\2\\">\1</label>,g\"`" 4393 \"s,\([^ =][^=]*\)=\([^= ][^= ]*\),$fh value=\\"\2\\">\1</label>,g\"`"
4384 ;; 4394 ;;
4385 [Cc][Hh][Ee][Cc][Kk][Bb][Oo][Xx]) 4395 [Cc][Hh][Ee][Cc][Kk][Bb][Oo][Xx])
4386 form="<label><input type=\"checkbox\" name=\"$name\" value=\"${args#*=}\">${args%=*}</label>" 4396 checked=${val:+ checked}
4397 form="<label><input type=\"checkbox\" name=\"$name\" value=\"${args#*=}\"$checked>${args%=*}</label>"
4387 ;; 4398 ;;
4388 [Ss][Ee][Ll][Ee][Cc][Tt]) 4399 [Ss][Ee][Ll][Ee][Cc][Tt])
4389 fh="<select name=\"$name\">$nl" 4400 fh="<select name=\"$name\">$nl"
4390 form=$(for l in $args; do 4401 form=$(for l in $args; do
4391 echo "<option value=\"${l#*=}\">${l%=*}</option>" 4402 echo "<option value=\"${l#*=}\">${l%=*}</option>"
4482 else 4493 else
4483 hiddens=$hiddens$nl"$form" 4494 hiddens=$hiddens$nl"$form"
4484 fi 4495 fi
4485 done < $1 4496 done < $1
4486 # enctype="multipart/form-data" 4497 # enctype="multipart/form-data"
4498 cat<<-EOF
4499 <form action="${GF_ACTION:-$myname}" method="POST" enctype="multipart/form-data">
4500 EOF
4501 test -n "$rowid" && printf '%s\n' "$rm" # Workaround for utf8 buggy NetBSD sh
4487 cat<<EOF 4502 cat<<EOF
4488 <form action="${GF_ACTION:-$myname}" method="POST" enctype="multipart/form-data">
4489 ${rowid:+$rm}
4490 <table class="b $2"> 4503 <table class="b $2">
4491 $forms 4504 $forms
4492 </table>$hiddens 4505 </table>$hiddens
4493 ${GF_STAGE:+`cgi_hidden stage $GF_STAGE`} 4506 ${GF_STAGE:+`cgi_hidden stage $GF_STAGE`}
4494 ${rowid:+<input type="hidden" name="rowid" value="$rowid">} 4507 ${rowid:+<input type="hidden" name="rowid" value="$rowid">}

yatex.org