changeset 311:121b91ee87c1

User/Group home icon cache'ing and group icon displaying added
author HIROSE Yuuji <yuuji@gentei.org>
date Sun, 16 Oct 2016 21:59:43 +0859
parents e8f1847eebca
children b8a8e627b376
files examples/common/default/default.css s4-funcs.sh
diffstat 2 files changed, 68 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/examples/common/default/default.css	Sat Oct 15 18:32:51 2016 +0859
+++ b/examples/common/default/default.css	Sun Oct 16 21:59:43 2016 +0859
@@ -100,12 +100,18 @@
 table.mini td, table.mini th {padding: 1px 1ex; min-width: 1em;}
 table.mini {margin-left: 1em; border-left: 2px solid #686;}
 
-p.profimg {float: left; max-width: 400px; max-height: 400px;
-	   overflow: hidden; margin-right: 1em;
+tr.profimg {visibility: collapse;}
+tr:hover + tr.profimg, tr:active + tr.profimg {visibility: visible;}
+
+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
 	  }
 p.profimg img {max-width: 400px;}
 div.home+* {clear: both;}
+body.grouphome p.groupimg {
+    float: right; max-width: 380px; max-height: 380px; margin: 0 1em 1ex;
+    overflow: hidden;}
 
 div.fold {margin-top: 1em; border-top: 1px solid black; padding-top: 1em;}
 div.noborder {border: 0px; margin: 0;}
--- a/s4-funcs.sh	Sat Oct 15 18:32:51 2016 +0859
+++ b/s4-funcs.sh	Sun Oct 16 21:59:43 2016 +0859
@@ -1478,6 +1478,42 @@
 	EOF
 }
 
+imgsrc_cache() (
+  # $1 = directory for cache'ing
+  # $2 = table
+  # $3 = condition for choosingowner
+  MAXSIZE=400
+  dir="$1" tbl="$2" whos="$3"
+  [ -d "$dir" ] || mkdir $dir
+  sql0="SELECT val || '//' || type FROM $tbl WHERE $whos ORDER BY rowid LIMIT 1;"
+  sql1="SELECT hex(bin) FROM $tbl WHERE $whos ORDER BY rowid LIMIT 1;"
+  valtype=`query "$sql0"`
+  filename=${valtype%%//*}
+  filetype=${valtype##*//file:}
+  err valtype="$valtype" n="$filename" type="$filetype"
+  cacheimg=$dir/$filename
+  sumfile="$cacheimg.sum"
+  tmpf=$tmpd/imgsrc_cache.$$
+  sum=`query "$sql1" | tee $tmpf | encode`	# encode() is maybe sha1
+  err cacheimg=$cacheimg
+  err tmpf=$tmpf
+  err sumfile=$sumfile
+  if [ x"`cat $sumfile`" = x"$sum" ]; then
+    # cache is fresh
+    echo "<img src=\"$cacheimg\">"
+  else
+    fmt=${filename##*.}
+    cat $tmpf | unhexize \
+	| convert -define ${fmt}:size=${MAXSIZE}x${MAXSIZE} \
+		  -resize ${MAXSIZE}x${MAXSIZE}'>' - $cacheimg &
+    printf '%s' "<img src=\"data:${filetype},"
+    cat $tmpf | sed 's/\(..\)/%\1/g'
+    echo '">'
+    echo "$sum" > $sumfile
+  fi
+  # "$td" "SELECT hex(bin) FROM user_m $sqcond LIMIT 1;"
+)
+
 showhome() {
   # $1=userRowIdToShow
   err showhome \$1=$1
@@ -1486,6 +1522,7 @@
     *)   uname=`getvalbyid user name $1` ;;
   esac
   err ShowHome: uname=$uname
+  td=`getcachedir home/"$1"`
   gecos=`gecos "$uname"`
   err SH:gecos=$gecos
   GF_VIEWONLY=1
@@ -1516,11 +1553,17 @@
   img=`query "SELECT type FROM user_m $sqcond LIMIT 1;"`
   imf=$tmpd/profimg.$$; touch $imf
   if [ -n "$img" ]; then
-    { printf '%s' "<img src=\"data:${img#file:},"
-      query "SELECT hex(bin) FROM user_m $sqcond LIMIT 1;" \
-	  | sed 's/\(..\)/%\1/g'
+    if true; then
+      tbl=user_m
+      enticond="name='$uname' AND key='profimg' AND type LIKE 'file:image%'"
+      imgsrc_cache "$td/main" user_m "$enticond"
+    else
+    { printf '%s' "<IMG src=\"data:${img#file:},"
+      query "SELECT hex(bin) FROM user_m $sqcond ORDER BY rowid LIMIT 1;" \
+    	  | sed 's/\(..\)/%\1/g'
       echo '">'
-    } > $imf
+    }
+    fi    > $imf
   fi
   nblog=`query "SELECT count(id) FROM blog_s WHERE key='owner' AND \
 		val='$uname';"`
@@ -1864,6 +1907,7 @@
     else
       ismember="" # bodyclass="group"
     fi
+    bodyclass="$bodyclass grouphome"
     echo "グループ $grp" > $tf
     showgroupsub $formdir/grp.def "$grid" | \
 	_m4 -D_TITLE_="spaste(\`$tf')" \
@@ -1882,6 +1926,7 @@
   rowid=$2
   grp=`getgroupbyid $2`
   qgrp=`sqlquote $grp`
+  td=`getcachedir grp/"$2"`
   #rowid=`sq $db "select rowid from grp where gname=$qgrp"`
   if [ -z "$rowid" ]; then
     #rowid=`sq $db "select rowid from grp where rowid=$grp"`
@@ -1890,7 +1935,15 @@
     return
   fi
   val=`getvalbyid grp profimg $rowid $tmpd`
-  # 6/14の次グループのHOMEで出す情報を作る Done
+  enticond="gname=$qgrp AND key='profimg' AND type LIKE 'file:image%'"
+  img=`query "SELECT type FROM grp_m WHERE $enticond LIMIT 1;"`
+  err iiiiiiiiiimg=$img enticond="$enticond"
+  if [ -n "$img" ]; then
+    cat<<-EOF
+	<p class="groupimg">
+	`imgsrc_cache $td/main grp_m "$enticond"`</p>
+	EOF
+  fi
   viewtable $1 grp $rowid
   if isgrpowner "$user" "$grp"; then
     echo "<p><a href=\"?groupconf+$rowid\">グループ情報の編集</a>"
@@ -1902,7 +1955,7 @@
 # div.fold input[type="checkbox"]:checked ~ div {display: block;}
     cat<<EOF
 <form action="?send2mem" method="POST" enctype="multipart/form-data">
-<div class="fold">
+<div class="fold clear">
 `cgi_checkbox send yes id="send"`<label
  for="send">グループ全員にメッセージ送信</label>
 <div>
@@ -1928,7 +1981,7 @@
 	and key='email';"
 err email=$eml
   cat <<EOF
-<div class="fold">
+<div class="fold clear">
 `cgi_checkbox reg yes id="reg"`<label
  for="reg">自身の加入状態を操作する</label>$state
 <div>

yatex.org