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 wrap: on
line diff
--- a/examples/common/default/default.css	Mon Oct 17 09:54:21 2016 +0859
+++ b/examples/common/default/default.css	Thu Oct 20 17:20:58 2016 +0859
@@ -79,11 +79,15 @@
     border: 1px solid black; border-collapse: collapse;
     white-space: pre-wrap;
 }
+table.blog_replies p.proficon {
+    float: right; margin: 0 1ex 0 0;
+}
 table.blog_replies+p.update_link {margin-top: 0; margin-bottom: 14em;}
 .blog_replies td.repl {
     vertical-align: top; min-width: 30em; height: 3em;
     max-width: 50em;
 }
+.blog_replies td:first-child {width: 14em;}
 .blog_replies iframe {
     width: 400px; height: 300px; max-width: 50em; max-height: 20em;
     padding: 0; border: 0;
@@ -106,6 +110,7 @@
 div.noprofimg tr.profimg:hover, div.noprofimg tr.profimg:active {
     visibility: visible; display: table-row;}
 
+/* Used in user's home page */
 p.profimg {float: left; max-width: 50%; max-height: 400px;
 	   overflow: hidden; margin: 0 1em 1ex;
 	   padding: 0; border: white 1px solid; box-shadow: 2px 3px 4px
--- a/s4-blog.sh	Mon Oct 17 09:54:21 2016 +0859
+++ b/s4-blog.sh	Thu Oct 20 17:20:58 2016 +0859
@@ -172,6 +172,8 @@
 	coalesce((SELECT val FROM user_s
 			 WHERE name=author AND key='gecos'),
 			author) uname,
+	(SELECT val FROM user_s WHERE name=author AND key='$iconcachekey')
+	icon,
 	a.rowid,
 	s.TIME,
         CASE WHEN s.TIME > '$atime' THEN 'new' ELSE '' END newer,
@@ -185,12 +187,20 @@
      a_s s
   ON a.id=s.id;
 EOF
-  while IFS='|' read id edit notify uid uname aid tm new hte imgids; do
+  while IFS='|' read id edit notify uid uname icon aid tm new hte imgids; do
     nt="<label style=\"font-size: 70%;\"><input type=\"checkbox\"
 	 name=\"notifyto\" value=\"$uid\">返信通知送信</label>"
+    tdcls="repatt${new:+ new}"
+    imgdir=`getcachedir home/"$uid"`/main
+    if [ -n "$icon" -a -s "$icon" ]; then
+      picon="<p class=\"proficon\"><img src=\"$icon\"></p>"
+    else
+      picon=""
+    fi
+    
     cat<<EOF
 <tr id="$id">
-<td${new:+ class="new"}>${edit:+<a href="$elink+$edit">編集</a> }#$aid
+<td class="$tdcls">$picon${edit:+<a href="$elink+$edit">編集</a> }#$aid
 <a href="$hlink+$uid">$uname</a>
 $tm
 ${notify:+$nt}</td>
--- a/s4-funcs.sh	Mon Oct 17 09:54:21 2016 +0859
+++ b/s4-funcs.sh	Thu Oct 20 17:20:58 2016 +0859
@@ -25,7 +25,8 @@
 dumpcollen=22
 #thumbxy=120x120
 thumbxy=96x96
-maxiconxy=400x400
+iconxy_S=80x80
+iconxy_M=400x400
 maximagexy=1600x1600
 ### maximagexy=400x400
 file_accept='accept="image/*,text/*,audio/*,application/vnd.oasis.*,application/pdf,application/x-*"'
@@ -36,6 +37,7 @@
 conftbl=_tblconf
 nl="
 "
+iconcachekey="profimgcache_S"
 . ./s4-cgi.sh
 
 : <<EOF
@@ -755,6 +757,16 @@
   fi
   $sha1 "$@" | cut -d' ' -f1
 }
+enjpeg() {
+  if [ -z "$cjpeg" ]; then
+    if type cjpeg >/dev/null 2>&1; then
+      cjpeg="cjpeg"
+    else
+      cjpeg="convert - jpeg:-"
+    fi
+  fi
+  $cjpeg "$@"
+}
 mycrypt() (
   key=$1 salt=$2
 err \$2=$2
@@ -1481,33 +1493,71 @@
 
 imgsrc_cache() (
   # $1 = directory for cache'ing
-  # $2 = table
-  # $3 = condition for choosingowner
-  dir="$1" tbl="$2" whos="$3 ORDER BY rowid LIMIT 1"
+  # $2 = table (user_m or grp_m)
+  # $3 = keycond (was: condition for choosingowner)
+  # $4 = size : S = Small, M = Medium, O = Original
+  dir="$1" tbl="$2"
+  keycond="$3"
+  whos="$keycond AND key='profimg' AND type LIKE 'file:image%'
+	 ORDER BY rowid LIMIT 1"
   [ -d "$dir" ] || mkdir $dir
+  case "$4" in
+    [Ss]) size=S ;;
+    [Oo]) size=O ;;
+    *)    size=M ;;
+  esac
+  # ImageCache filename storing schema:
+  # <table_s>.{key, val}={"profimgcache_S", "$cacheimg_S"}
   sql0="SELECT val || '//' || type FROM $tbl WHERE $whos;"
   sql1="SELECT hex(bin) FROM $tbl WHERE $whos;"
   valtype=`query "$sql0"`
   filename=${valtype%%//*}
   filetype=${valtype##*//file:}
-  cacheimg=$dir/$filename
-  sumfile="$cacheimg.sum"
+  cacheimg_S=$dir/S_$filename
+  cacheimg_M=$dir/M_$filename
+  cacheimg_O=$dir/$filename
+  cacheimg=$dir/${size}_$filename
+  sumfile="$dir/$filename.sum"
   tmpf=$tmpd/imgsrc_cache.$$
   sum=`query "$sql1" | tee $tmpf | encode`	# encode() is maybe sha1
-  if [ x"`cat $sumfile`" = x"$sum" ]; then
+  if test -s "$sumfile" && [ x"`cat $sumfile`" = x"$sum" ]; then
     # if cache is fresh,
     echo "<img src=\"$cacheimg\">"
   else
+    fifo=$tmpd/fifo; mkfifo $fifo
     fmt=${filename##*.}
+    ## [[ NOTE ]]
+    ## a. convert oldimage newimage
+    ## b. convert oldimage fmt:- | convert - newimage
+    ## b is much smaller than a
     cat $tmpf | unhexize \
-	| convert -define ${fmt}:size=${maxiconxy}x${maxiconxy} \
-		  -resize ${maxiconxy}x${maxiconxy}'>' - $cacheimg &
+	| tee $fifo \
+	| convert -define ${fmt}:size=${iconxy_M}x${iconxy_M} \
+		  -resize ${iconxy_M}x${iconxy_M}'>' - pnm:- \
+	| convert - $cacheimg_M &
+    cat $fifo | convert -define ${fmt}:size=${iconxy_S}x${iconxy_S} \
+			-resize ${iconxy_S}x${iconxy_S}'>' - pnm:- \
+	| convert - $cacheimg_S &
     printf '%s' "<img src=\"data:${filetype},"
     cat $tmpf | sed 's/\(..\)/%\1/g'
     echo '">'
     echo "$sum" > $sumfile
   fi
+  ## Now preparing cache image, done.
+  ## Store this information to DB
+  stbl=${tbl%_m}_s		# user_s or grp_s
+  pkey=${keycond%%=*}		# Primary Key name
+  pval=${keycond#*=}		# Primary Key value
+  query <<-EOF
+	REPLACE INTO $stbl($pkey, key, type, val)
+	VALUES($pval, '$iconcachekey', 'string', `sqlquote "$cacheimg_S"`);
+	EOF
 )
+imgsrc_cache_clear() {
+  # $1=table
+  # $2=keycond
+  query "DELETE FROM $1 WHERE $2 AND key='$iconcachekey';"
+}    
 
 showhome() {
   # $1=userRowIdToShow
@@ -1553,8 +1603,8 @@
   if [ -n "$img" ]; then
     if true; then
       tbl=user_m
-      enticond="name='$uname' AND key='profimg' AND type LIKE 'file:image%'"
-      imgsrc_cache "$td/main" user_m "$enticond"
+      enticond="name='$uname'"
+      imgsrc_cache "$td/main" user_m "$enticond" M
     else
     { printf '%s' "<IMG src=\"data:${img#file:},"
       query "SELECT hex(bin) FROM user_m $sqcond ORDER BY rowid LIMIT 1;" \
@@ -1933,12 +1983,12 @@
     return
   fi
   val=`getvalbyid grp profimg $rowid $tmpd`
-  enticond="gname=$qgrp AND key='profimg' AND type LIKE 'file:image%'"
+  enticond="gname=$qgrp"
   img=`query "SELECT type FROM grp_m WHERE $enticond LIMIT 1;"`
   if [ -n "$img" ]; then
     cat<<-EOF
 	<p class="groupimg">
-	`imgsrc_cache $td/main grp_m "$enticond"`</p>
+	`imgsrc_cache $td/main grp_m "$enticond" M`</p>
 	EOF
   fi
   echo "<div class=\"noprofimg\">"
@@ -2849,7 +2899,6 @@
 	## XX: DIRTY Hack Ends here
 	## We should keep blog's owner as a single column which has
 	## foreign key constraint with primary key of grp/user.
-	aa
        else
 	 query "$sql"
        fi
@@ -2917,11 +2966,11 @@
 		  file=$tmpd/`getparfilename $v`
 		  err type=file=$file
 		  [ -z "$file" ] && continue
-		  bn=${file##*/}
+		  bn=`sqlquotestr "${file##*/}"`
 		  bin="X'"$(hexize $file)"'"
 		  ct=`file --mime-type $file|cut -d' ' -f2`
 		  type=\"file:$ct\"
-		  newsql="update $tb2 set val='$bn', type=$type, bin=$bin"
+		  newsql="update $tb2 set val=$bn, type=$type, bin=$bin"
 		  cachedir=`getcachedir "$tbl/$rowid"`
 		  err getcache tbl/rowid=$tbl/$rowid, rm -r $cachedir
 		  rm -r $cachedir
@@ -3067,7 +3116,8 @@
     form="" val=""
     if [ -n "$rowid" ]; then
       # err genform2a: Seeking for "$2.$name, type=$type"
-      val=`getvalbyid $2 $name $rowid $td|htmlescape`
+      rawval=`getvalbyid $2 $name $rowid $td`
+      val=`echo "$rawval"|htmlescape`
 err genform3a: getvalbyid $2 $name $rowid $td
 err genform3b: val="[$val]"
     fi
@@ -3114,7 +3164,7 @@
 	  form=`cgi_multi_file $name $td "$args"`
 	  if [ -n "$val" ]; then
 	    hrfb="$myname?showattc+$2_m"
-	    val=$(echo "$val" \
+	    val=$(echo "$rawval" \
 		       | while read fn; do
 			   data=`percenthex $td/$fn`
 			   #ct=`cat $td/$fn.content-type`

yatex.org