s4

annotate s4-blog.sh @ 55:7f9f7e898986

Do not send notification to the person-self
author HIROSE Yuuji <yuuji@gentei.org>
date Thu, 23 Jul 2015 11:07:24 +0900
parents d08e556f3462
children 7c61a80051f5
rev   line source
yuuji@0 1 #
yuuji@17 2 type cgiinit >/dev/null 2>&1 || . ./s4-funcs.sh
yuuji@0 3
yuuji@0 4 blog_genform() {
yuuji@0 5 #
yuuji@0 6 t=$1
yuuji@0 7 }
yuuji@0 8
yuuji@0 9 blog_writable() (
yuuji@0 10 # $1=articleid $2=user
yuuji@0 11 blogowner=`getvalbyid blog owner "$1"`
yuuji@0 12 [ x"$blogowner" = x"$2" ] || isuser "$blogowner" || ismember "$2" "$blogowner"
yuuji@0 13 )
yuuji@50 14 blog_notify_reply() (
yuuji@0 15 # $1=articleid $2=ReplyingUser $3=WrittenText
yuuji@0 16 blogowner=`getvalbyid blog owner "$1"`
yuuji@28 17 [ x"$2" = x"$blogowner" ] && return # If author=blogowner, unnecessary
yuuji@0 18 blogtitle=`getvalbyid blog title "$1"`
yuuji@0 19 blogurl="$urlbase?replyblog+$1"
yuuji@50 20 mode=`getvalbyid blog notify "$1"`
yuuji@50 21 case $mode in
yuuji@48 22 admin)
yuuji@55 23 if isgroup "$blogowner"; then
yuuji@55 24 emails=`for i in $(getgroupadmins $blogowner); do\
yuuji@55 25 [ x"$i" = x"$user" ] && continue;\
yuuji@55 26 email4group "$i" "$blogowner";\
yuuji@55 27 done`
yuuji@48 28 else
yuuji@48 29 emails=`collectemail $blogowner`
yuuji@48 30 fi
yuuji@48 31 ;;
yuuji@48 32 no) return ;;
yuuji@48 33 *) emails=`collectemail $blogowner` ;;
yuuji@48 34 esac
yuuji@55 35 ## err notify: user=$user Admins=`getgroupadmins $blogowner` Mode=$mode Emails="[$emails]"
yuuji@0 36 smail "$emails" "書込通知 $urlbase"<<EOF
yuuji@48 37 [$blogtitle]板に書き込みがありました。
yuuji@0 38 場所: $blogurl
yuuji@0 39 題目: $blogtitle
yuuji@0 40 筆者: `gecos $2`
yuuji@0 41 内容:
yuuji@0 42 `echo "$3"|sed 's/^/> /'`
yuuji@0 43 EOF
yuuji@50 44 )
yuuji@0 45 blog_showentry() {
yuuji@0 46 # $1=table $2=rowid
yuuji@0 47 if [ -n "$2" ]; then
yuuji@0 48 if [ -n "$imgcached" ]; then
yuuji@42 49 bstmpdir=$tmpdir/$imgcached/$thumbxy
yuuji@0 50 else
yuuji@42 51 bstmpdir=$tmpd
yuuji@42 52 # tmpd=`mktempd`
yuuji@42 53 # tmpfiles=$tmpfiles" $tmpd"
yuuji@0 54 fi
yuuji@0 55 fi
yuuji@0 56 tbl=${1%%[!A-Z0-9a-z_]*} rowid=${2%%[!A-Z0-9a-z_]*}
yuuji@0 57 err rowid=$rowid, '$2'=$2
yuuji@0 58 ts=${tbl}_s tm=${tbl}_m
yuuji@0 59 at=article as=article_s am=article_m
yuuji@0 60 serial=$(($(date +%s)-1420038000))s$$
yuuji@0 61 # This function grasps blog entry definiton directly.
yuuji@0 62 # blog: id
yuuji@0 63 # blog_s: title,ctime,heading
yuuji@0 64 # blog_m: *article
yuuji@0 65
yuuji@0 66 err "SELECT id from $tbl where rowid=$rowid"
yuuji@2 67 id=`query "select id from $tbl where rowid=$rowid;"`
yuuji@0 68 err id=$id
yuuji@0 69 err "select val from $ts where key='title' and id='$id';"
yuuji@0 70
yuuji@0 71
yuuji@0 72 #(1)Display root article
yuuji@0 73 cat<<EOF
yuuji@0 74 <form class="replyblog" action="$myname?replyblog+$rowid" method="POST" enctype="multipart/form-data">
yuuji@0 75 <table class="bloghead">
yuuji@0 76 EOF
yuuji@0 77
yuuji@0 78 href="<a href=\"?editheading+$rowid\"> 編集 </a>"
yuuji@0 79 href2="<a href=\"?lshandout+$rowid\"> 提出状況 </a>"
yuuji@2 80 href3="(<a href=\"?gethandout+$rowid\">ファイル取得</a>)"
yuuji@0 81 cat<<EOF | sq -html $db \
yuuji@0 82 | sed -e "s|\(<TR><TD>\),e,|\1 $href |" \
yuuji@2 83 -e "s|,s,\(</TD>\)|$href2$href3\1|"
yuuji@0 84 -- select val from $ts where key="title" and id="$id";
yuuji@2 85 select
yuuji@2 86 coalesce((select ",e," from blog where rowid=$rowid and author='$user'),'')
yuuji@2 87 ||val||" "
yuuji@0 88 ||case (select val from $ts where key="mode" and id="$id")
yuuji@0 89 when 'report-closed' then "レポート提出用(自身のファイルのみ参照可),s,"
yuuji@0 90 when 'report-open' then "レポート提出用,s,"
yuuji@0 91 else ""
yuuji@0 92 end
yuuji@0 93 from $ts where key="ctime" and id="$id";
yuuji@0 94 select val from $ts where key="heading" and id="$id";
yuuji@0 95 EOF
yuuji@0 96 cat<<EOF
yuuji@0 97 </table>
yuuji@0 98 <table class="blog_replies">
yuuji@0 99 EOF
yuuji@0 100
yuuji@0 101 #(2)Display following articles
yuuji@0 102 textform='<div><table class="b">
yuuji@0 103 <tr><td><textarea name="text" cols="40" rows="4"></textarea></td></tr>
yuuji@0 104 <tr><td>添付ファイル: <input type="file" name="image" multiple></td></tr>
yuuji@0 105 </table>
yuuji@0 106 <input type="submit" value="送信">
yuuji@0 107 <input type="reset" value="リセット"></div>
yuuji@0 108 '
yuuji@0 109 ## 6/11の次: articleを出して行く
yuuji@0 110 : <<EOF
yuuji@0 111 シリアル:id:p:serial:
yuuji@0 112 blogID:blogid:f:blog(id):
yuuji@0 113 筆者:author:s:owner
yuuji@0 114 時刻:ctime:s:stamp:
yuuji@0 115 参照元:parent:s:parent:
yuuji@0 116 パス:path:s:path:
yuuji@0 117 本文:text:s:textarea:cols="60" rows="8"
yuuji@0 118 画像:image:m:image:
yuuji@0 119 stage:stage:x:hidden:value="replyblog"
yuuji@0 120
yuuji@0 121 article(id, blogid, author)
yuuji@0 122 article_s: Visible = ctime, text Invisible = parent, path
yuuji@0 123 article_m: image
yuuji@0 124
yuuji@0 125 article = hoge|1433812374x20849|yuuji@gentei.org
yuuji@0 126 article_s = hoge|ctime|string|2015-06-13 12:27:34|
yuuji@0 127 hoge|text|string|Shall we dance?|
yuuji@0 128 EOF
yuuji@0 129 ##
yuuji@0 130 ##
yuuji@0 131 err "select id from $at where blogid='$id';"
yuuji@0 132 # arts=`sq $db "select a.rowid,a.id,
yuuji@0 133 #-- coalesce(b.gecos, a.author)
yuuji@0 134 # a.author from $at a
yuuji@0 135 # LEFT JOIN (select name,val as gecos from user_s where key='gecos') b
yuuji@0 136 # on a.author=b.name where blogid='$id'";`
yuuji@0 137 arts=`query "select rowid,id,author from $at where blogid='$id';"`
yuuji@34 138 # err arts="[$arts]"
yuuji@0 139 number=0
yuuji@2 140 hrefhome0="<a href=\"?home"
yuuji@0 141 for a in $arts; do
yuuji@0 142 arid=${a%%|*} aid=`echo "$a"|cut -d'|' -f2` author=${a##*|} imgs=""
yuuji@41 143 err a=$a, aid=$aid, author=$author
yuuji@0 144 # name='' # Get gecos??
yuuji@42 145 td=$(echo $bstmpdir/`echo $a|md5`)
yuuji@0 146 val=`getvalbyid article image $arid $td`
yuuji@41 147 err val="[$val]" and td as follows:
yuuji@0 148
yuuji@0 149 if true; then
yuuji@0 150 if [ -n "$val" ]; then
yuuji@0 151 hrfb="$myname?showattc+article_m"
yuuji@0 152 imgs="<br>"$(echo "$val"\
yuuji@0 153 |while read fn; do
yuuji@0 154
yuuji@0 155 #data=`percenthex $td/$fn`
yuuji@0 156 #ct=`cat $td/$fn.content-type`
yuuji@0 157 ri=`cat $td/$fn.rowid`
yuuji@41 158 err fn=$fn ct=$ct ri=$ri; ls -lF $td/ 1>&3
yuuji@0 159 #case $ct in
yuuji@0 160 # [Ii]mage*) anch="<img src=\"data:$ct,$data\">$fn" ;;
yuuji@0 161 # *) anch=$fn ;;
yuuji@0 162 # esac
yuuji@0 163 # Should not contain newlines for sed argument
yuuji@0 164 # echo -n "<a href=\"$hrfb+$ri\">$anch</a>"
yuuji@0 165 iconhref $td/$fn "$hrfb+$ri" "$fn" "$fn"
yuuji@0 166 done)
yuuji@41 167 imgs=`echo "$imgs"|tr -d '\n'` # kill newlines for sed
yuuji@0 168 fi
yuuji@0 169 fi
yuuji@0 170
yuuji@0 171 ### number=$((number+1))
yuuji@0 172 # reply="<input type=\"radio\" name=\"parent\" class=\"replybtn\" \
yuuji@0 173 # value=\"$number\">"
yuuji@2 174 getgecos="(select rowid from user where name='$author')||':'||\
yuuji@2 175 coalesce((select val from user_s \
yuuji@2 176 where name='$author' and key='gecos'), '$author')||',[/a],'"
yuuji@0 177 href="$myname?editart+$arid+$rowid"
yuuji@0 178 link="<a href=\"$href\">編集</a>"
yuuji@0 179 cat<<EOF | sq -html $db \
yuuji@2 180 | sed -e "s|,n,\([0-9]*\):|,n,$hrefhome0+\1\">|" \
yuuji@2 181 -e 's|,\[/a\],|</a>|' \
yuuji@2 182 -e 's/,n,/<br>/g' -e "s|,i,|$imgs|" \
yuuji@0 183 -e "s|<TR>\(<TD>\)|<TR id=\"$aid\">\1|" \
yuuji@35 184 -e "s|^href=\([-A-Za-z0-9,.:/~_%#&+?]*\)|<a &>\1</a>|" \
yuuji@2 185 -e "s|\(<TR.*>\)\(<TD>\),e,|\1\2$link|"
yuuji@0 186 select
yuuji@0 187 coalesce((select ",e," from article where id='$aid' and author='$user'),"")
yuuji@0 188 ||
yuuji@0 189 max(case key when 'ctime' then ",n,"||val||
yuuji@0 190 ",n,"||$getgecos end) as TIME,
yuuji@0 191 -- max(case key when 'parent' then val||"への返信" end) as REPLYTO,
yuuji@0 192 max(case key when 'text' then val||",i," end) as TEXT
yuuji@0 193 from article_s where id = '$aid'
yuuji@0 194 group by id order by TIME;
yuuji@0 195 EOF
yuuji@0 196 done
yuuji@0 197 echo "</table>"
yuuji@0 198
yuuji@0 199
yuuji@0 200 blog_writable $rowid $user && cat<<EOF
yuuji@0 201 <div class="blogcomment">
yuuji@0 202 <p>コメント記入</p>
yuuji@0 203 <input type="hidden" name="blogid" value="$id">
yuuji@0 204 <input type="hidden" name="stage" value="replyblog">
yuuji@0 205 <input type="hidden" name="serial" value="$serial">
yuuji@0 206 $textform
yuuji@0 207 </div>
yuuji@0 208 EOF
yuuji@0 209 echo "</form>"
yuuji@0 210
yuuji@0 211 # Record access log
yuuji@0 212 acclog blog $rowid
yuuji@0 213 }
yuuji@0 214
yuuji@0 215 lshandout() {
yuuji@0 216 # $1=rowid of blog
yuuji@0 217 time=`getvalbyid blog ctime $1|colrm 11`
yuuji@0 218 owner=`getvalbyid blog owner $1`
yuuji@0 219 title=`getvalbyid blog title $1`
yuuji@2 220 ge=`gecos $owner`
yuuji@0 221 lshandoutsub $owner "$@" \
yuuji@0 222 |m4 -D_TITLE_="提出状況" \
yuuji@2 223 -D_SUBTITLE_="$time [$title]@${ge:-$owner}" -D_DIARY_="" \
yuuji@2 224 -D_FORM_="syscmd(cat)" -D_BLOGS_= -D_DUMPTABLE_= \
yuuji@0 225 $layout/html.m4.html $layout/diary.m4.html
yuuji@0 226 }
yuuji@0 227 lshandoutsub() {
yuuji@0 228 # $1=owner $2=rowid of blog
yuuji@2 229 if isgroup $1; then
yuuji@2 230 sample="(select user from grp_mem where gname='$1')"
yuuji@2 231 else
yuuji@2 232 sample="(select distinct author as user from arts)"
yuuji@2 233 echo "<p>(集計は板への投稿者のみ)</p>"
yuuji@2 234 fi
yuuji@2 235 sql="with arts as (select id,author from article \
yuuji@0 236 where blogid=(select id from blog where rowid=$2))\
yuuji@0 237 select (select rowid from user where name=c0.user)||' '|| \
yuuji@0 238 coalesce((select val from user_s where name=c0.user \
yuuji@0 239 and key='gecos'),\
yuuji@0 240 c0.user) as 'メンバー',\
yuuji@0 241 sum(case when c1.key is not null then 1 else 0 end)\
yuuji@0 242 as 'コメント記入',\
yuuji@0 243 sum(case when c2.key is not null then 1 else 0 end)\
yuuji@0 244 as 'ファイルの提出'\
yuuji@2 245 from $sample c0 \
yuuji@0 246 left join (select id,author from arts) a\
yuuji@0 247 on c0.user=a.author\
yuuji@0 248 left join (select id,key from article_s where key='text') c1\
yuuji@0 249 on a.id=c1.id left join (select id,key from article_m ) c2\
yuuji@0 250 on c1.id=c2.id group by c0.user order by c0.user;"
yuuji@0 251 err ishandoutsub: sql="$sql"
yuuji@0 252 echo '<table class="b td2r td3r">'
yuuji@0 253 hrb="<a href=\"?home+"
yuuji@0 254 echo "$sql" | sq -header -html $db \
yuuji@0 255 | sed -e "s,\(<TR><TD>\)\([^ ]*\) \(.*\)</TD>,\1$hrb\2\">\3</TD>," -e 's,<TD>0</TD>,<TD class="warn">0</TD>,'
yuuji@0 256 echo '</table>'
yuuji@0 257 }
yuuji@2 258 gethandout() {
yuuji@2 259 # $1=rowid of blog
yuuji@2 260 i=0
yuuji@2 261 bd=$tmpd/archive.$$
yuuji@2 262 mkdir $bd
yuuji@2 263 query "select m.rowid,author,m.val from article a join article_m m\
yuuji@2 264 on a.id=m.id where blogid=(select id from blog where rowid=$1)\
yuuji@2 265 and m.key in ('image', 'document', 'binary');" \
yuuji@2 266 | while IFS='|' read rowid author filename; do
yuuji@2 267 # err isfilereadable $user article_m $1
yuuji@2 268 isfilereadable $user article_m $1 || continue
yuuji@2 269 err ok
yuuji@2 270 i=$((i+1))
yuuji@2 271 dir=`printf $bd/%03d $i`
yuuji@2 272 mkdir $dir
yuuji@2 273 query "select quote(bin) from article_m where rowid=$rowid;" \
yuuji@8 274 | unhexize > $dir/$filename
yuuji@2 275 done
yuuji@2 276 if [ ! -d $bd/001 ]; then
yuuji@2 277 contenttype; echo
yuuji@2 278 echo "<p>取得できるファイルがありませんでした。</p>"
yuuji@2 279 return
yuuji@2 280 fi
yuuji@2 281 (cd $bd
yuuji@2 282 err cdto$bd; (pwd; ls -lFa) 1>&3
yuuji@2 283 tar zcf .archive.tar.gz * && mv .archive.tar.gz archive.tar.gz
yuuji@2 284 )
yuuji@2 285 arc=$bd/archive.tar.gz
yuuji@2 286 echo "Content-type: application/x-gzip"
yuuji@2 287 echo "Content-Length: `cat $arc|wc -c`"
yuuji@2 288 echo "Content-Disposition: filename=\"archive.tar.gz\""
yuuji@2 289 echo
yuuji@2 290 cat $arc
yuuji@2 291 }
yuuji@0 292
yuuji@0 293 listblog() (
yuuji@0 294 # $1=user
yuuji@0 295 cond="where a.id in (select id from blog_s where key='owner' and val='$1') order by ctime desc"
yuuji@0 296 DT_CHLD=article:blogid
yuuji@0 297 cgi_form searchart<<EOF
yuuji@0 298 <label>`cgi_text kwd`という語を含む記事を検索</label>
yuuji@0 299 `cgi_hidden owner $user`
yuuji@0 300 EOF
yuuji@0 301 dumptable html blog 'ctime title heading' "$cond"
yuuji@0 302 )
yuuji@0 303
yuuji@0 304 blog_addentry() {
yuuji@0 305 # $1=GRPname(if it is a group)
yuuji@16 306 grprowid=$1
yuuji@0 307 rowid=`getpar rowid`
yuuji@0 308 err ba: rowid=$rowid
yuuji@0 309 #if [ -z "$rowid" ]; then
yuuji@0 310 # When rowid is SET, it is updation of existing entry
yuuji@0 311 if [ -z "$1" ]; then
yuuji@0 312 listing=$user guide="[個人]"
yuuji@0 313 #listing代入は rowid 時でもするべき
yuuji@0 314 else
yuuji@16 315 grp=`getgroupbyid $grprowid`
yuuji@16 316 if [ -n "$grp" ]; then
yuuji@16 317 listing=$1 guide="[${grp}]" GF_OWNER=$grp
yuuji@0 318 else
yuuji@0 319 echo "<p>無効なグループ指定です。</p>"
yuuji@0 320 return
yuuji@0 321 fi
yuuji@0 322 fi
yuuji@0 323 #fi
yuuji@0 324 if [ -n "`getpar title`" ]; then
yuuji@0 325 owner=`getpar owner`
yuuji@0 326 if isuser $owner; then
yuuji@0 327 if [ x"$user" != x"$owner" ]; then
yuuji@0 328 echo "<p>他人の日記は書けません</p>"
yuuji@0 329 return
yuuji@0 330 fi
yuuji@0 331 elif isgroup $owner; then # if write to group log
yuuji@0 332 grp=$owner #\`getpar grp\`
yuuji@0 333 err ismember: $user $grp
yuuji@0 334 if ! ismember "$user" "$grp"; then
yuuji@0 335 echo "<p>(話題作成はこのグループに加入してから)</p>"
yuuji@0 336 return
yuuji@0 337 fi
yuuji@0 338 fi
yuuji@0 339 par2table $formdir/blog.def
yuuji@0 340 serial=`getpar serial`
yuuji@0 341 err SERIAL: $serial ROWID=$rowid listing=$listing
yuuji@0 342 id=""
yuuji@0 343 if [ -n "$rowid" ]; then
yuuji@0 344 # Here, id becomes NULL when removal of entries at par2table
yuuji@0 345 id=`query "select rowid from blog where rowid=$rowid;"`
yuuji@0 346 elif [ -n "$serial" ]; then
yuuji@0 347 # If new blog leader created, traverse to its head.
yuuji@0 348 id=`query "select rowid from blog where id='$serial';"`
yuuji@0 349 fi
yuuji@0 350 if [ -n "$id" ]; then
yuuji@0 351 ## If new aritcle is entered, JUMP to blog_reply
yuuji@0 352 blog_reply $id
yuuji@0 353 return
yuuji@0 354 fi
yuuji@0 355 fi
yuuji@0 356 m4 -D_TITLE_="${guide}新規話題作成" -D_DIARY_="新規話題の記入" \
yuuji@0 357 -D_SUBTITLE_="序文は簡単に詳しくはコメントに" \
yuuji@0 358 -D_BLOGS_="これまでの蓄積" \
yuuji@0 359 -D_FORM_="`genform $formdir/blog.def`" \
yuuji@0 360 -D_DUMPTABLE_="`listblog $listing`" \
yuuji@0 361 $layout/html.m4.html \
yuuji@0 362 $layout/diary.m4.html
yuuji@0 363 }
yuuji@0 364
yuuji@0 365 blog_reply() {
yuuji@0 366 rowid=$1
yuuji@0 367 err rowid=$1
yuuji@0 368
yuuji@0 369 if [ -z "$rowid" ]; then
yuuji@0 370 echo "<p>表示する日記番号が未指定です。</p>"
yuuji@0 371 return
yuuji@0 372 fi
yuuji@0 373 title=`getvalbyid blog title $rowid`
yuuji@0 374 owner=`getvalbyid blog owner $rowid`
yuuji@0 375 if isuser "$owner"; then
yuuji@0 376 subtitle="`gecos $owner` さんの話題"
yuuji@0 377 else
yuuji@16 378 grprowid=`query "select rowid from grp where gname=\"$owner\";"`
yuuji@54 379 subtitle="グループ <a href=\"?grp+$grprowid\">$owner</a> での話題"
yuuji@0 380 fi
yuuji@0 381 if [ -z "$title" ]; then
yuuji@0 382 echo "<p>日記番号指定が無効です。</p>"
yuuji@0 383 return
yuuji@0 384 fi
yuuji@0 385
yuuji@0 386 text=`getpar text`
yuuji@0 387 if [ -n "$text" ]; then
yuuji@0 388 if blog_writable $rowid $user; then
yuuji@0 389 if par2table $formdir/article.def; then
yuuji@0 390 blog_notify_reply $rowid $user "$text"
yuuji@0 391 fi
yuuji@0 392 else
yuuji@0 393 title="$title(加入してないので書き込み不可)"
yuuji@0 394 fi
yuuji@0 395 fi
yuuji@0 396 def=$formdir/article.def
yuuji@0 397 cat $layout/html.m4.html $layout/diary.m4.html \
yuuji@0 398 | sed '/_DIARY_/q' \
yuuji@0 399 | m4 -D_TITLE_="$title" -D_DIARY_="" -D_BODYCLASS_=general \
yuuji@0 400 -D_SUBTITLE_="$subtitle"
yuuji@0 401 blog_showentry blog $rowid
yuuji@0 402 sed '1,/_DIARY_/d' $layout/diary.m4.html | m4 -D_FORM_= -D_DUMPTABLE_=
yuuji@0 403 }