s4
changeset 322:18be0c210dc8
First implementation of icon display in blog_replies.
author | HIROSE Yuuji <yuuji@gentei.org> |
---|---|
date | Thu, 20 Oct 2016 17:20:58 +0859 |
parents | d8656d4c210e |
children | db840ea6e347 |
files | examples/common/default/default.css s4-blog.sh s4-funcs.sh |
diffstat | 3 files changed, 85 insertions(+), 20 deletions(-) [+] |
line diff
1.1 --- a/examples/common/default/default.css Mon Oct 17 09:54:21 2016 +0859 1.2 +++ b/examples/common/default/default.css Thu Oct 20 17:20:58 2016 +0859 1.3 @@ -79,11 +79,15 @@ 1.4 border: 1px solid black; border-collapse: collapse; 1.5 white-space: pre-wrap; 1.6 } 1.7 +table.blog_replies p.proficon { 1.8 + float: right; margin: 0 1ex 0 0; 1.9 +} 1.10 table.blog_replies+p.update_link {margin-top: 0; margin-bottom: 14em;} 1.11 .blog_replies td.repl { 1.12 vertical-align: top; min-width: 30em; height: 3em; 1.13 max-width: 50em; 1.14 } 1.15 +.blog_replies td:first-child {width: 14em;} 1.16 .blog_replies iframe { 1.17 width: 400px; height: 300px; max-width: 50em; max-height: 20em; 1.18 padding: 0; border: 0; 1.19 @@ -106,6 +110,7 @@ 1.20 div.noprofimg tr.profimg:hover, div.noprofimg tr.profimg:active { 1.21 visibility: visible; display: table-row;} 1.22 1.23 +/* Used in user's home page */ 1.24 p.profimg {float: left; max-width: 50%; max-height: 400px; 1.25 overflow: hidden; margin: 0 1em 1ex; 1.26 padding: 0; border: white 1px solid; box-shadow: 2px 3px 4px
2.1 --- a/s4-blog.sh Mon Oct 17 09:54:21 2016 +0859 2.2 +++ b/s4-blog.sh Thu Oct 20 17:20:58 2016 +0859 2.3 @@ -172,6 +172,8 @@ 2.4 coalesce((SELECT val FROM user_s 2.5 WHERE name=author AND key='gecos'), 2.6 author) uname, 2.7 + (SELECT val FROM user_s WHERE name=author AND key='$iconcachekey') 2.8 + icon, 2.9 a.rowid, 2.10 s.TIME, 2.11 CASE WHEN s.TIME > '$atime' THEN 'new' ELSE '' END newer, 2.12 @@ -185,12 +187,20 @@ 2.13 a_s s 2.14 ON a.id=s.id; 2.15 EOF 2.16 - while IFS='|' read id edit notify uid uname aid tm new hte imgids; do 2.17 + while IFS='|' read id edit notify uid uname icon aid tm new hte imgids; do 2.18 nt="<label style=\"font-size: 70%;\"><input type=\"checkbox\" 2.19 name=\"notifyto\" value=\"$uid\">返信通知送信</label>" 2.20 + tdcls="repatt${new:+ new}" 2.21 + imgdir=`getcachedir home/"$uid"`/main 2.22 + if [ -n "$icon" -a -s "$icon" ]; then 2.23 + picon="<p class=\"proficon\"><img src=\"$icon\"></p>" 2.24 + else 2.25 + picon="" 2.26 + fi 2.27 + 2.28 cat<<EOF 2.29 <tr id="$id"> 2.30 -<td${new:+ class="new"}>${edit:+<a href="$elink+$edit">編集</a> }#$aid 2.31 +<td class="$tdcls">$picon${edit:+<a href="$elink+$edit">編集</a> }#$aid 2.32 <a href="$hlink+$uid">$uname</a> 2.33 $tm 2.34 ${notify:+$nt}</td>
3.1 --- a/s4-funcs.sh Mon Oct 17 09:54:21 2016 +0859 3.2 +++ b/s4-funcs.sh Thu Oct 20 17:20:58 2016 +0859 3.3 @@ -25,7 +25,8 @@ 3.4 dumpcollen=22 3.5 #thumbxy=120x120 3.6 thumbxy=96x96 3.7 -maxiconxy=400x400 3.8 +iconxy_S=80x80 3.9 +iconxy_M=400x400 3.10 maximagexy=1600x1600 3.11 ### maximagexy=400x400 3.12 file_accept='accept="image/*,text/*,audio/*,application/vnd.oasis.*,application/pdf,application/x-*"' 3.13 @@ -36,6 +37,7 @@ 3.14 conftbl=_tblconf 3.15 nl=" 3.16 " 3.17 +iconcachekey="profimgcache_S" 3.18 . ./s4-cgi.sh 3.19 3.20 : <<EOF 3.21 @@ -755,6 +757,16 @@ 3.22 fi 3.23 $sha1 "$@" | cut -d' ' -f1 3.24 } 3.25 +enjpeg() { 3.26 + if [ -z "$cjpeg" ]; then 3.27 + if type cjpeg >/dev/null 2>&1; then 3.28 + cjpeg="cjpeg" 3.29 + else 3.30 + cjpeg="convert - jpeg:-" 3.31 + fi 3.32 + fi 3.33 + $cjpeg "$@" 3.34 +} 3.35 mycrypt() ( 3.36 key=$1 salt=$2 3.37 err \$2=$2 3.38 @@ -1481,33 +1493,71 @@ 3.39 3.40 imgsrc_cache() ( 3.41 # $1 = directory for cache'ing 3.42 - # $2 = table 3.43 - # $3 = condition for choosingowner 3.44 - dir="$1" tbl="$2" whos="$3 ORDER BY rowid LIMIT 1" 3.45 + # $2 = table (user_m or grp_m) 3.46 + # $3 = keycond (was: condition for choosingowner) 3.47 + # $4 = size : S = Small, M = Medium, O = Original 3.48 + dir="$1" tbl="$2" 3.49 + keycond="$3" 3.50 + whos="$keycond AND key='profimg' AND type LIKE 'file:image%' 3.51 + ORDER BY rowid LIMIT 1" 3.52 [ -d "$dir" ] || mkdir $dir 3.53 + case "$4" in 3.54 + [Ss]) size=S ;; 3.55 + [Oo]) size=O ;; 3.56 + *) size=M ;; 3.57 + esac 3.58 + # ImageCache filename storing schema: 3.59 + # <table_s>.{key, val}={"profimgcache_S", "$cacheimg_S"} 3.60 sql0="SELECT val || '//' || type FROM $tbl WHERE $whos;" 3.61 sql1="SELECT hex(bin) FROM $tbl WHERE $whos;" 3.62 valtype=`query "$sql0"` 3.63 filename=${valtype%%//*} 3.64 filetype=${valtype##*//file:} 3.65 - cacheimg=$dir/$filename 3.66 - sumfile="$cacheimg.sum" 3.67 + cacheimg_S=$dir/S_$filename 3.68 + cacheimg_M=$dir/M_$filename 3.69 + cacheimg_O=$dir/$filename 3.70 + cacheimg=$dir/${size}_$filename 3.71 + sumfile="$dir/$filename.sum" 3.72 tmpf=$tmpd/imgsrc_cache.$$ 3.73 sum=`query "$sql1" | tee $tmpf | encode` # encode() is maybe sha1 3.74 - if [ x"`cat $sumfile`" = x"$sum" ]; then 3.75 + if test -s "$sumfile" && [ x"`cat $sumfile`" = x"$sum" ]; then 3.76 # if cache is fresh, 3.77 echo "<img src=\"$cacheimg\">" 3.78 else 3.79 + fifo=$tmpd/fifo; mkfifo $fifo 3.80 fmt=${filename##*.} 3.81 + ## [[ NOTE ]] 3.82 + ## a. convert oldimage newimage 3.83 + ## b. convert oldimage fmt:- | convert - newimage 3.84 + ## b is much smaller than a 3.85 cat $tmpf | unhexize \ 3.86 - | convert -define ${fmt}:size=${maxiconxy}x${maxiconxy} \ 3.87 - -resize ${maxiconxy}x${maxiconxy}'>' - $cacheimg & 3.88 + | tee $fifo \ 3.89 + | convert -define ${fmt}:size=${iconxy_M}x${iconxy_M} \ 3.90 + -resize ${iconxy_M}x${iconxy_M}'>' - pnm:- \ 3.91 + | convert - $cacheimg_M & 3.92 + cat $fifo | convert -define ${fmt}:size=${iconxy_S}x${iconxy_S} \ 3.93 + -resize ${iconxy_S}x${iconxy_S}'>' - pnm:- \ 3.94 + | convert - $cacheimg_S & 3.95 printf '%s' "<img src=\"data:${filetype}," 3.96 cat $tmpf | sed 's/\(..\)/%\1/g' 3.97 echo '">' 3.98 echo "$sum" > $sumfile 3.99 fi 3.100 + ## Now preparing cache image, done. 3.101 + ## Store this information to DB 3.102 + stbl=${tbl%_m}_s # user_s or grp_s 3.103 + pkey=${keycond%%=*} # Primary Key name 3.104 + pval=${keycond#*=} # Primary Key value 3.105 + query <<-EOF 3.106 + REPLACE INTO $stbl($pkey, key, type, val) 3.107 + VALUES($pval, '$iconcachekey', 'string', `sqlquote "$cacheimg_S"`); 3.108 + EOF 3.109 ) 3.110 +imgsrc_cache_clear() { 3.111 + # $1=table 3.112 + # $2=keycond 3.113 + query "DELETE FROM $1 WHERE $2 AND key='$iconcachekey';" 3.114 +} 3.115 3.116 showhome() { 3.117 # $1=userRowIdToShow 3.118 @@ -1553,8 +1603,8 @@ 3.119 if [ -n "$img" ]; then 3.120 if true; then 3.121 tbl=user_m 3.122 - enticond="name='$uname' AND key='profimg' AND type LIKE 'file:image%'" 3.123 - imgsrc_cache "$td/main" user_m "$enticond" 3.124 + enticond="name='$uname'" 3.125 + imgsrc_cache "$td/main" user_m "$enticond" M 3.126 else 3.127 { printf '%s' "<IMG src=\"data:${img#file:}," 3.128 query "SELECT hex(bin) FROM user_m $sqcond ORDER BY rowid LIMIT 1;" \ 3.129 @@ -1933,12 +1983,12 @@ 3.130 return 3.131 fi 3.132 val=`getvalbyid grp profimg $rowid $tmpd` 3.133 - enticond="gname=$qgrp AND key='profimg' AND type LIKE 'file:image%'" 3.134 + enticond="gname=$qgrp" 3.135 img=`query "SELECT type FROM grp_m WHERE $enticond LIMIT 1;"` 3.136 if [ -n "$img" ]; then 3.137 cat<<-EOF 3.138 <p class="groupimg"> 3.139 - `imgsrc_cache $td/main grp_m "$enticond"`</p> 3.140 + `imgsrc_cache $td/main grp_m "$enticond" M`</p> 3.141 EOF 3.142 fi 3.143 echo "<div class=\"noprofimg\">" 3.144 @@ -2849,7 +2899,6 @@ 3.145 ## XX: DIRTY Hack Ends here 3.146 ## We should keep blog's owner as a single column which has 3.147 ## foreign key constraint with primary key of grp/user. 3.148 - aa 3.149 else 3.150 query "$sql" 3.151 fi 3.152 @@ -2917,11 +2966,11 @@ 3.153 file=$tmpd/`getparfilename $v` 3.154 err type=file=$file 3.155 [ -z "$file" ] && continue 3.156 - bn=${file##*/} 3.157 + bn=`sqlquotestr "${file##*/}"` 3.158 bin="X'"$(hexize $file)"'" 3.159 ct=`file --mime-type $file|cut -d' ' -f2` 3.160 type=\"file:$ct\" 3.161 - newsql="update $tb2 set val='$bn', type=$type, bin=$bin" 3.162 + newsql="update $tb2 set val=$bn, type=$type, bin=$bin" 3.163 cachedir=`getcachedir "$tbl/$rowid"` 3.164 err getcache tbl/rowid=$tbl/$rowid, rm -r $cachedir 3.165 rm -r $cachedir 3.166 @@ -3067,7 +3116,8 @@ 3.167 form="" val="" 3.168 if [ -n "$rowid" ]; then 3.169 # err genform2a: Seeking for "$2.$name, type=$type" 3.170 - val=`getvalbyid $2 $name $rowid $td|htmlescape` 3.171 + rawval=`getvalbyid $2 $name $rowid $td` 3.172 + val=`echo "$rawval"|htmlescape` 3.173 err genform3a: getvalbyid $2 $name $rowid $td 3.174 err genform3b: val="[$val]" 3.175 fi 3.176 @@ -3114,7 +3164,7 @@ 3.177 form=`cgi_multi_file $name $td "$args"` 3.178 if [ -n "$val" ]; then 3.179 hrfb="$myname?showattc+$2_m" 3.180 - val=$(echo "$val" \ 3.181 + val=$(echo "$rawval" \ 3.182 | while read fn; do 3.183 data=`percenthex $td/$fn` 3.184 #ct=`cat $td/$fn.content-type`