s4

view s4-blog.sh @ 576:c81511a6b7e0

Add feature of "clone without team"
author HIROSE Yuuji <yuuji@gentei.org>
date Fri, 14 Jun 2019 09:01:51 +0900
parents 9a4504aef7ac
children 6e727ab07c98
line source
1 #
2 type cgiinit >/dev/null 2>&1 || . ./s4-funcs.sh
4 # Global error flags
5 BLOG_NOTMEM=1
6 BLOG_FROZEN=2
7 FROZEN_TAG='<span class="frozen">[凍結]</span>'
9 blog_genform() {
10 #
11 t=$1
12 }
14 blog_writable() (
15 # $1=articleid $2=user
16 # Return: $?=0 - Writable
17 # =1 - NOT Writable because user is not a member
18 # =2 - NOT Writable because blog is frozen
19 blogowner=`getvalbyid blog owner "$1"`
20 state=`getvalbyid blog state "$1"`
21 rc=0
22 [ x"$blogowner" = x"$2" ] || isuser "$blogowner" || ismember "$2" "$blogowner" || rc=$((rc+$BLOG_NOTMEM))
23 [ "$state" = "frozen" ] && rc=$((rc+$BLOG_FROZEN))
24 return $rc
25 )
26 blog_readable() {
27 # $1=articleid $2=user
28 mode=`getgroupattr $grp regmode`
29 }
30 blog_notify_reply() (
31 # $1=blogid $2=ReplyingUser $3=WrittenText $4(optional)=Action
32 blogid="${1%%[!A-Z0-9a-z_]*}"
33 blogowner=`getvalbyid blog owner "$blogid"`
34 blogtitle=`getvalbyid blog title "$blogid"`
35 blogurl="$urlbase?replyblog+$blogid"
36 action=${4:-書き込み}
37 mode=`getvalbyid blog notify "$blogid"`
38 isgroup "$blogowner" && _isgroup=true || _isgroup=false
39 ### EXCEPT=`sqlquote "$user"` ## User should receive to feal some annoyance
40 case $mode in
41 admin)
42 if $_isgroup; then
43 emails=`getgroupadminmails $blogowner`
44 else
45 emails=`collectemail $blogowner`
46 fi
47 notifyto=`getpar notifyto`
48 if [ -n "$notifyto" ]; then
49 emails=$emails" `email4groupbyuid \"$blogowner\" $notifyto`"
50 fi
51 ;;
52 no) emails="" ;;
53 *) team=`query "SELECT val FROM blog_s
54 WHERE id=(SELECT id FROM blog WHERE rowid=$blogid)
55 AND key='team';"`
56 # team cannot get `getvalbyid blog team "$blogid"` because it's not
57 # defined in blog.def. Yes, it is Illegal USE!!
58 emails=`TEAM=$team collectemail $blogowner` ;;
59 esac
60 ## 2017-0210 Respond to the direct reply mark such as: >#1234
61 replymark=`echo "$3"|nkf -w -Z0|grep '^ *>#'`
62 authgecos=`gecos $2`
63 if [ -z "$4" -a -n "$replymark" ]; then
64 # If the action is new subscription($4="") and has ">#123" marks...
65 ids=`echo "$replymark"|sed 's/[^#0-9]*#\([0-9]*\)[^#0-9]*/\1 /g'`
66 ids=`echo $ids|tr -dc '[0-9 ]'|tr ' ' ','`
67 # -> 123,345,347
68 unames=`query "SELECT distinct author FROM article \
69 WHERE rowid in ($ids)\
70 AND blogid=(SELECT id FROM blog WHERE rowid=$blogid);"`
71 if [ -n "$unames" ]; then
72 e4g=$(if $_isgroup; then
73 email4group "$blogowner" $unames
74 else
75 for u in $unames; do
76 collectemail $u
77 done
78 fi)
79 emails=$emails" $e4g"
80 for e in $unames; do
81 g=`gecos $e`
82 whom=$whom"${whom:+,}${g:-$e}さん"
83 done
84 action="${whom}への返信"
85 fi
86 else
87 [ x"$2" = x"$blogowner" ] && return # If author=blogowner, unnecessary
88 fi
89 test -z "$emails" && return
90 err notify: user=$user Admins=`getgroupadmins $blogowner` Mode=$mode Emails="[$emails]"
91 SMAIL_TO="`echo "$blogowner" | nkf -jM | tr -d '\n'` readers <$admin>" \
92 smail "$emails" "${action}通知 $urlbase"<<EOF
93 [$blogtitle]板に${action}がありました。
94 ※このメイルに返信しても通知者には伝わりません(管理者宛になる)。
95 場所: $blogurl (返信先)
96 所有: $blogowner
97 題目: $blogtitle
98 筆者: $authgecos
99 内容:
100 `echo "$3"|sed 's/^/> /'`
101 EOF
102 )
104 blog_showentry() {
105 # $1=table $2=rowid
106 # if [ -n "$2" ]; then
107 # if [ -n "$imgcached" ]; then
108 # bstmpdir=$tmpdir/$imgcached/$thumbxy
109 # else
110 # bstmpdir=$tmpd
111 # # tmpd=`mktempd`
112 # # tmpfiles=$tmpfiles" $tmpd"
113 # fi
114 # fi
115 td=`getcachedir "article/$2"`
116 [ -d "$td" ] || mkdir -p $td
117 tbl=${1%%[!A-Z0-9a-z_]*} rowid=${2%%[!A-Z0-9a-z_]*}
118 err blow_showentry: rowid=$rowid, '$2'=$2 user=$user
119 ts=${tbl}_s tm=${tbl}_m
120 at=article as=article_s am=article_m
121 serial=$(($(date +%s)-1420038000))s$$
122 cannotread='<div class="relative"><img class="overlap" src="img/key.png" alt="(読み取り不可)"></div>'
123 blog_writable $rowid $user
124 rc=$?
125 if [ $rc = 0 ]; then
126 iswritable=true
127 ismem=true
128 else
129 iswritable=false
130 if [ $((rc & $BLOG_NOTMEM)) -gt 0 ]; then
131 ismem=false
132 else
133 ismem=true
134 fi
135 fi
136 # This function grasps blog entry definiton directly.
137 # blog: id
138 # blog_s: title,ctime,heading
139 # blog_m: *article
141 blogowner=`getvalbyid blog owner "$2"`
142 isgroup "$blogowner" && isgroup=true || isgroup=false
143 isgrpadmin=false # Reversed later (*1)
145 # 2015-10-05 check readable
146 if ! $iswritable; then
147 # err blogowner=$blogowner
148 if $isgroup; then
149 regmode=`getgroupattr $blogowner regmode`
150 # err regmode=$regmode
151 if [ x"$regmode" = x"moderated" ]; then
152 # if ! ismember $user $blogowner; then
153 if ! $ismem; then
154 echo "加入してからどうぞ" | html p
155 return
156 fi
157 fi
158 fi
159 else # if writable
160 isgrpowner "$user" "$blogowner" && isgrpadmin=true # (*1)
161 fi
162 case `getvalbyid blog notify "$rowid"` in # "all", "admin" or "no" (or NULL)
163 admin) notifyto=1 ;;
164 *) notifyto="" ;;
165 esac
166 case `getvalbyid blog mode "$rowid"` in
167 *quiz*|*close*) f_exclusive=1 ;;
168 *) f_exclusive='' ;;
169 esac
171 # err "SELECT id from $tbl where rowid=$rowid"
172 id=`query "select id from $tbl where rowid=$rowid;"`
173 #err id=$id
174 #err "select val from $ts where key='title' and id='$id';"
176 #(1)Display root article
177 cat<<EOF
178 <form class="replyblog" action="$myname?replyblog+${rowid}#bottom" method="POST" enctype="multipart/form-data">
179 <table class="bloghead">
180 EOF
182 href="<a href=\"?editheading+$rowid\" accesskey=\"e\" title=\"E\"> 編集 </a>"
183 if $ismem; then
184 case `getvalbyid blog mode $rowid` in
185 *report*|*quiz*)
186 href2="<a href=\"?lshandout+$rowid\" accesskey=\"l\" title=\"L\"> 提出状況 </a>"
187 ;;
188 esac
189 href3="(<a href=\"?gethandout+$rowid\" accesskey=\"f\" title=\"F\">ファイル取得</a>)"
190 fi
191 href4='<a href="#bottom" accesskey="b" title="B"> 末尾へ</a>'
192 $isgrpadmin &&
193 href5="<a href=\"?blogseen+$rowid\" accesskey=\"s\" title=\"S\"> 読刻</a>"
194 quizmodefile=$td/quiz; rm -f "$quizmodefile" # XXX: Global state
196 query<<-EOF |
197 SELECT coalesce((SELECT "yes" FROM blog
198 WHERE rowid=$rowid AND author='$user'),
199 ''),
200 max(CASE key WHEN 'ctime' THEN val END) ctime,
201 max(CASE key WHEN 'heading' THEN hex(val) END) heading,
202 CASE (SELECT val FROM $ts WHERE key="mode" AND id="$id")
203 WHEN 'report-closed' THEN 'レポート提出用(closed)'
204 WHEN 'report-open' THEN 'レポート提出用(open)'
205 WHEN 'quiz' THEN 'クイズ'
206 ELSE ''
207 END
208 FROM $ts WHERE id='$id' GROUP BY id;
209 EOF
210 { IFS='|' read edit ctime hexhead blogtype
211 cat<<-EOF
212 <tr><td>${edit:+$href }$ctime $blogtype $href2$href3 $href4 $href5</td></tr>
213 <tr class="preface${frozen_class:+ }$frozen_class">
214 <td>`echo "$hexhead"|unhexize|hreflink|minitbl`</td></tr>
215 </table>
216 EOF
217 case "$blogtype" in
218 "クイズ")
219 echo "クイズモードは本人と管理者の書き込みのみが表示されます。"
220 ;;
221 esac | html p 'class="warn"'
222 echo '<table class="blog_replies">'
223 if [ x"$blogtype" = x"クイズ" ]; then
224 if $isgroup; then
225 if ! isgrpowner "$user" "$blogowner"; then
226 qgrp=`sqlquote "$blogowner"`
227 cat<<-EOF > $quizmodefile
228 AND (author IN (SELECT user FROM grp_adm WHERE gname=$qgrp)
229 OR
230 author='$user')
231 EOF
232 fi
233 else # if user's blog
234 if [ x"$user" != x"$blogowner" ]; then
235 cat<<-EOF > $quizmodefile
236 AND author IN ('$blogowner', '$user')
237 EOF
238 fi
239 fi
240 fi
241 }
242 lkhome="<a href=\"$myname?home" lke='">'
243 lkedit="<a href=\"$myname?editart"
244 hlink="$myname?home" elink="$myname?editart"
245 catlink="$myname?showattc+article_m"
246 deficon="img/file-icon.png"
247 # 2016-08-15 Newer flag introduced
248 atime=`query "SELECT time FROM acclog
249 WHERE tbl='blog' AND tblrowid=$rowid AND user='$user';"`
250 iconcleaner=$tmpd/iconcleaner.$$
251 [ -s $quizmodefile ] && cond_qz=`cat $quizmodefile`
252 # *** DO NOT USE query(), use "sq $db" instead here ***
253 # because the next block in pipe line uses query() repeatedly.
254 sq $db<<EOF |
255 WITH a_s AS (
256 SELECT id,
257 max(CASE key WHEN 'ctime' THEN val END) TIME,
258 max(CASE key WHEN 'text' THEN val END) TEXT
259 FROM article_s
260 GROUP by id
261 )
262 SELECT a.id,
263 CASE author
264 WHEN '$user' THEN a.rowid||'+'||$rowid
265 ELSE ''
266 END edit,
267 CASE -- 「通知送信」ボタンの有無
268 WHEN '$notifyto' = '' THEN '' -- 不要モードならなし
269 WHEN '$user' = author THEN '' -- 筆者自身ならなし
270 ELSE "yes"
271 END notify,
272 (SELECT rowid FROM user WHERE name=author) user_rid,
273 author,
274 coalesce((SELECT val FROM user_s
275 WHERE name=author AND key='gecos'),
276 author) uname,
277 (SELECT val FROM user_s WHERE name=author AND key='$iconcachekey')
278 icon,
279 a.rowid,
280 s.TIME,
281 CASE WHEN s.TIME < '2019-05'
282 THEN printf('平成%d年%d月%d日%s',
283 substr(s.TIME, 1, 4)-1988,
284 substr(s.TIME, 6, 2),
285 substr(s.TIME, 9, 2),
286 substr(s.TIME, 12)
287 )
288 WHEN s.TIME < '2020'
289 THEN printf('令和元年%d月%d日%s',
290 substr(s.TIME, 6, 2),
291 substr(s.TIME, 9, 2),
292 substr(s.TIME, 12))
293 WHEN s.TIME < '2050'
294 THEN printf('令和%d年%d月%d日%s',
295 substr(s.TIME, 1, 4)-2018,
296 substr(s.TIME, 6, 2),
297 substr(s.TIME, 9, 2),
298 substr(s.TIME, 12))
299 ELSE s.TIME
300 END reki,
301 CASE WHEN s.TIME > '$atime' THEN 'new' ELSE '' END newer,
302 hex(s.TEXT),
303 CASE -- File Accessibility to attached file
304 WHEN '$f_exclusive' = '' THEN ''
305 WHEN '$isgrpadmin' = 'true' THEN ''
306 WHEN '$user' = author THEN ''
307 ELSE 'Unreadable'
308 END cannotread,
309 (SELECT group_concat(rowid||':'||length(bin)||':'||hex(val), ' ')
310 FROM article_m
311 WHERE id=a.id AND key='image') imxgids
312 FROM (select rowid,id,author from article
313 where blogid in
314 (select id from blog where rowid=$rowid)
315 $cond_qz) a
316 LEFT JOIN
317 a_s s
318 ON a.id=s.id;
319 EOF
320 while IFS='|' read id edit notify uid author uname icon aid \
321 tm reki new hte fa imgids
322 do
323 cachefile="$td/$id.row.html"
324 stampfile="$td/$id.row.stamp"
325 editlink="${edit:+<a href="$elink+$edit">編集</a> }"
326 nt="<label style=\"font-size: 70%;\"><input type=\"checkbox\"\
327 name=\"notifyto\" value=\"$uid\">返信通知送信</label>"
328 # fa is file accessibility flag # err "----r=$aid fa=[$fa]----"
330 # First, check the availability of user-icon.
331 # If not existent, clear and reset row cache by rm $stampfile
332 if [ ! -s "$icon" ]; then
333 rm -f "$stampfile"; unset stampfile
334 fi
335 if test -s "$stampfile" &&
336 test -s "$cachefile" &&
337 { ts=`cat "$stampfile"`; test -n "$ts"; } &&
338 test "$ts" '>' "$tm" && # Cache timestamp is newer
339 test "$stampfile" -nt "$icon"; then # UserIcon is older
340 : Nothing to do
341 else
342 { ######## New ROW creation begins here ######## >$cachefile
343 tdcls="__NEWCLS__repatt"
344 if [ -s "$icon" ]; then
345 icfn=`echo "$icon"|htmlescape`
346 picon="<p class=\"proficon\"><a href=\"$hlink+$uid\" title=\"${author%@*}\"><img src=\"$icfn\"></a></p>"
347 else
348 echo "DELETE FROM user_s WHERE key='$iconcachekey' AND
349 val=`sqlquotestr \"$icon\"`;" >> $iconcleaner
350 picon=""
351 fi
353 cat<<EOF
354 <tr id="$id">
355 <td class="$tdcls">${picon}__EDIT__<a href="#$aid">#$aid</a>
356 <a href="$hlink+$uid" title="${author%@*}">$uname</a>
357 <span title="$tm">${reki:-$tm}</span>
358 <__NOTIFY__></td>
359 EOF
360 echo -n "<td id=\"$aid\" class=\"repl\">"
361 echo "$hte"|unhexize|htmlescape|hreflink|minitbl
362 usecache='' tsfile=$td/$id.stamp
363 for i in $imgids; do
364 mrid=${i%%:*}; i=${i#*:}; sz=`size_h ${i%%:*}`
365 fn=`echo "${i#*:}"|unhexize`
366 fnb=$fn"(${sz})"
367 case "$fn" in
368 *.[Pp][Nn][Gg]|*.[Jj][Pp][Gg]|*.[Jj][Pp][Ee][Gg]|*.[GgTt][Ii][Ff])
369 # fmt=${fn##*.} # convert - jpg:- is slow...why
370 case "$fn" in
371 *.[Pp][Nn][Gg]) fmt=png ;;
372 *.[Gg][Ii][Ff]) fmt=gif ;;
373 *) fmt=jpeg ;;
374 esac
375 outfile=$td/$mrid-${fn%.*}.$fmt
376 #err fn=$fn outfile=$outfile
377 #err "usecache=$usecache `ls -l $outfile`"
378 #err tm=$tm
379 #err tsfile=$tsfile=`cat $tsfile`
380 if [ -s "$outfile" ] && # $outfile should be > 0
381 { [ "$usecache" ] || # And usecache flag is true, or...
382 { [ -s "$tsfile" ] && [ x"`cat $tsfile`" = x"$tm" ]
383 };}; then
384 usecache=1 # Set usecache flag on
385 cat<<-EOF
386 <a href="$catlink+$mrid"><img src="$outfile">
387 $fnb</a>
388 EOF
389 # !!NOTE!! Create row stamp ONLY WHEN imgcache is active
390 else
391 query "SELECT hex(bin) FROM article_m WHERE rowid=$mrid;" \
392 | unhexize \
393 | convert -define ${fmt}:size=100x100 -resize 100x100'>' \
394 - ${fmt}:- \
395 | tee "$outfile" \
396 | hexize \
397 | sed -e 's/\(..\)/%\1/g' \
398 -e "s|^|<a href=\"$catlink+$mrid\"><img src=\"data:image/$fmt,|" \
399 -e "s|\$|\">$fnb</a>|"
400 unset stampfile # img data stream is not suitable to cache
401 echo $tm > $tsfile
402 fi
403 ;;
404 *)
405 echo "<__UNREADABLE__><a href=\"$catlink+$mrid\"><img src=\"$deficon\">$fnb</a>"
406 ;;
407 esac
408 done
409 echo "</td></tr>"
410 } > "$cachefile" ######## New ROW Creation Ends here ########
411 test -n "$stampfile" && date "+%F %T" > $stampfile
412 fi
413 # Printing a cached row
414 sed -e "/^<td class=/s/__NEWCLS__/$new${new:+ }/" \
415 -e "/^<td class=/s,__EDIT__,$editlink," \
416 -e "/^<__NOTIFY__>/s,,${notify:+$nt}," \
417 -e "/<__UNREADABLE__>/s,,${fa:+$cannotread}," \
418 $cachefile
419 done
421 help="=== コメントに使用できる特殊記法 ===
422 行頭に href=URL でURLへのリンク
423 行頭に iframe=URL でURL先を開く iframe
424 [[#記事番号]] でs4内の記事番号に飛ぶリンク
425 [[#検索キーワード]] でs4内の記事検索(記号はいくつか使えない)
426 [[URL]] でURLへのリンク、 [[URL|文字列]]でアンカー文字列指定
427 {{画像URL}} でインライン画像、 {{画像URL|幅}} でピクセル幅指定
428 {{{URL}}} でURL先を開く iframe、 {{{URL|高さ}}} ピクセル高さ指定
429 行頭: ## 大見出し, ### 中見出し, #### 小見出し
430 行末の2連続スペースで強制改行(<br>)
431 |*見出し列|列2|列3… と行頭から始まる縦棒区切り行を続けて表
432 ' *語群* ' で強調(両側の空白必要、** でもっと強調。*の代わりに _ でも可)
433 - [ ] と - [x] でチェックボックス"
434 touchhelp="${touchpanel:+<p class=\"help\">$help</p>}"
435 filehelp="《添付の注意》
436 $file_accept_help"
437 textform='<div class="fold">
438 <input type="checkbox" id="cmt" checked><label
439 accesskey="c" title="C" for="cmt">コメントする</label><div>
440 <table class="b">
441 <tr><td><textarea name="text" cols="72" rows="4" title="'"$help"'">
442 </textarea>'"$touchhelp</td></tr>
443 <tr><td>添付ファイル(${filesize_max_MB}以下):"'
444 <input type="file" name="image"'" $file_accept title=\"$filehelp\" multiple></td></tr>"'
445 </table>
446 <input type="submit" value="送信">
447 <input type="reset" value="リセット"></div></div>
448 '
449 cat<<-EOF
450 </table> <!-- end of s4-blog:blog_showentry() main table -->
451 <p class="update_link"><a
452 href="?reload/$rowid" accesskey="r" title="R">再読込</a> / <a
453 href="#title" id="bottom" accesskey="t" title="T">先頭へ</a></p>
454 EOF
455 $iswritable && cat<<-EOF
456 <div class="blogcomment">
457 <input type="hidden" name="blogid" value="$id">
458 <input type="hidden" name="id" value="`genserial`">
459 <input type="hidden" name="stage" value="replyblog">
460 $textform
461 </div>
462 </form> <!-- End of s4-blog:blog_showentry() main form -->
463 EOF
464 # Clean up orphaned icon cache
465 [ -s $iconcleaner ] && query ".read '$iconcleaner'"
466 # Record access log
467 acclog blog $rowid
468 }
470 lshandout() {
471 # $1=rowid of blog
472 blog_writable $1 $user
473 rc=$? # =0: writable, $BLOG_NOTMEM bit set => not member
474 if [ $((rc & $BLOG_NOTMEM)) -gt 0 ] ; then
475 echo "メンバー以外は利用できません。" | html p; return
476 fi
477 time=`getvalbyid blog ctime $1|colrm 11`
478 owner=`getvalbyid blog owner $1`
479 title=`getvalbyid blog title $1`
480 ge=`gecos $owner`
481 fh=$tmpd/formhead
482 echo "$time [$title]@${ge:-$owner}" > $fh
483 lshandoutsub $owner "$@" \
484 |_m4 -D_TITLE_="提出状況" \
485 -D_FORMHEAD_="syscmd(cat $fh)" \
486 -D_FORM_="syscmd(cat)" -D_DUMPHEAD_= -D_DUMPTABLE_= \
487 $layout/html.m4.html $layout/form+dump-whead.m4.html
488 gn=`echo $owner|htmlescape`
489 echo "<p><a href=\"?lshandoutall+$1\">グループ $gn すべてのレポート板集計</a></p>"
490 }
491 gethandoutcsv() {
492 # contenttype; echo
493 CATCSV=1 lshandoutall "$1"
494 }
495 gethandoutcsv2() {
496 # contenttype; echo
497 SQL=$(cat<<-EOF
498 WITH this_blog_articles AS (
499 SELECT rtb.id bid, rtb.brid, a.id aid, author, title, ctime
500 FROM report_type_blogs rtb JOIN article a ON rtb.id=a.blogid
501 ), text_or_file AS (
502 SELECT bid, author, title, ctime, 'text' shu, count(val) cnt
503 FROM this_blog_articles tba, article_s s
504 ON tba.aid=s.id
505 WHERE key='text'
506 GROUP by bid, author
507 UNION
508 SELECT bid, author, title, ctime, 'file' shu, count(val) cnt
509 FROM this_blog_articles tba, article_m m
510 ON tba.aid=m.id
511 WHERE key='image'
512 GROUP by bid, author
513 ), count_list AS (
514 SELECT author,
515 substr(ctime, 1, 10)||upper(substr(shu, 1, 1)) unit,
516 cnt
517 FROM text_or_file
518 )
519 SELECT gecos "名前",
520 substr(author, 1, instr(author, '@')-1) "uname",
521 unit,
522 cnt "post"
523 FROM count_list cl JOIN gecoses g ON cl.author=g.name;
524 EOF
525 ) gethandoutcsv "$1"
526 }
527 lshandout_ulink_table() {
528 # NO Args. Read stdin as SQL
529 echo '<table class="b td3rr td3evw">'
530 hrb="<a href=\"?home+"
531 # echo "$sql" | sq -header -html $db \ # Formerly, this is called via sq()
533 printf ".mode html\n.header ON\n" | query
534 cat | query \
535 | sed -e "s,\(<TR><TD>\)\([^ ]*\) \(.*\)</TD>,\1$hrb\2\">\3</TD>," -e 's,<TD>0</TD>,<TD class="warn">0</TD>,'
536 echo '</table>'
537 printf ".mode list\n.header OFF\n" | query
538 }
539 lshandoutall() {
540 # $1=rowid of blog
541 blog_writable $1 $user
542 rc=$? # =0: writable, $BLOG_NOTMEM bit set => not member
543 if [ $((rc & $BLOG_NOTMEM)) -gt 0 ] ; then
544 echo "メンバー以外は利用できません。" | html p; return
545 fi
546 rowid=$(($1 + 0))
547 owner=`getvalbyid blog owner $1`
548 qowner=`sqlquotestr "$owner"`
550 query<<-EOF
551 CREATE TEMPORARY TABLE IF NOT EXISTS report_type_blogs AS
552 WITH blog_owner_mode AS (
553 SELECT id,
554 blog.rowid brid,
555 max(CASE key WHEN 'owner' THEN val END) owner,
556 max(CASE key WHEN 'mode' THEN val END) mode,
557 max(CASE key WHEN 'title' THEN val END) title,
558 max(CASE key WHEN 'ctime' THEN val END) ctime
559 FROM blog NATURAL JOIN blog_s
560 GROUP BY id
561 )
562 SELECT id, brid, title, ctime FROM blog_owner_mode
563 /* WHERE owner=$qowner AND mode LIKE '%report%'; */
564 WHERE owner=$qowner
565 AND
566 (mode LIKE '%report%' OR mode LIKE '%quiz%');
567 /* ↑これでレポート形式の blogid 一覧を得る */
568 EOF
569 if [ -z "$CATCSV" ]; then
570 _m4 -D_TITLE_="提出状況" $layout/html.m4.html
571 ge=`gecos "$owner"`
572 tbls=""
573 grptxt=`echo "${ge:-$owner}"|htmlescape`
574 echo "<h1>$grptxt 書き込み状況一覧</h1>"
575 fi
576 if [ -z "$SQL" ]; then
577 bridlist=`query "SELECT brid FROM report_type_blogs;"`
578 for brid in $bridlist; do # Skip this loop if $SQL set
579 brid=$(($brid + 0)) # Ensure to be a number
580 [ $brid = 0 ] && continue
581 time=`getvalbyid blog ctime $brid|colrm 11`
582 title=`getvalbyid blog title $brid|htmlescape`
583 state=`getvalbyid blog state $brid|htmlescape`
584 tt="handout_$brid"
585 [ "$state" = "frozen" ] && frozen=" $FROZEN_TAG" || frozen=""
586 if [ -z "$CATCSV" ]; then
587 echo "<h2>$time - <a href=\"?replyblog+$brid\">$title</a>$frozen</h2>"
588 lshandoutsub "$owner" $brid "$tt"
589 else
590 lshandoutsub "$owner" $brid "$tt" >/dev/null # Only create temp.table
591 fi
592 tbls="$tbls${tbls:+ NATURAL JOIN }$tt"
593 done
594 fi
595 sql=${SQL:-"SELECT * FROM $tbls;"}
596 if [ -z "$CATCSV" ]; then
597 echo "<hr><h2>総合</h2>"
598 echo "$sql" | lshandout_ulink_table
599 echo "<h2>総合(<a href=\"?gethandoutcsv+$rowid\">CSV</a>)</h2>"
600 printf ".mode csv\n.header ON\n" | query
601 echo '<pre class="list">'
602 echo "$sql" | query | sed 's/^"[0-9]* /"/'
603 echo "</pre>"
604 echo "<pre><a href=\"?gethandoutcsv2+$rowid\">縦持ちCSV</a></pre>"
605 else
606 contenttype "Application/CSV"
607 printf ".mode csv\n.header ON\n" | query >/dev/null
608 fn=report-count.csv
609 printf 'Content-Disposition: filename="%s"\n' "$fn"
610 outfile=$tmpd/out-$$.csv
611 echo "$sql" | query | sed 's/^"[0-9]* /"/' > $outfile
612 echo "Content-Length: " `cat $outfile | wc -c`; echo
614 cat $outfile
615 exit 0
616 fi
617 printf ".mode list\n.header OFF\n.separator |\n" | query
618 }
619 lshandoutsub() {
620 # $1=owner $2=rowid of blog &optional $3=temp_table name
621 qgname=`sqlquote "$1"`
622 if isgroup "$1"; then
623 sample="(select user from grp_mem where gname=$qgname)"
624 else
625 sample="(select distinct author as user from arts)"
626 echo "(集計は板への投稿者のみ)" | html p
627 fi
628 tmpname="${3:-handout_$2}"
629 sql="CREATE TEMPORARY TABLE IF NOT EXISTS $tmpname AS
630 with arts as (select id,author from article \
631 where blogid=(select id from blog where rowid=$2))\
632 select (select rowid from user where name=c0.user)||' '|| \
633 (select gecos from gecoses where name=c0.user) as 'メンバー',\
634 substr(c0.user, 1, instr(c0.user, '@')-1) 'uname',\
635 sum(case when c1.key is not null then 1 else 0 end)\
636 as '[$title] コメント記入',\
637 sum(case when c2.key is not null then 1 else 0 end)\
638 as '[$title] ファイルの提出'\
639 from $sample c0 \
640 left join (select id,author from arts) a\
641 on c0.user=a.author\
642 left join (select id,key from article_s where key='text') c1\
643 on a.id=c1.id left join (select id,key from article_m ) c2\
644 on c1.id=c2.id group by c0.user order by c0.user;\
645 \
646 SELECT * FROM $tmpname;"
647 err ishandoutsub: sql="$sql"
648 echo "$sql" | lshandout_ulink_table
649 }
650 gethandout() {
651 # $1=rowid of blog
652 blog_writable $1 $user
653 rc=$? # =0: writable, $BLOG_NOTMEM bit set => not member
654 if [ $((rc & $BLOG_NOTMEM)) -gt 0 ] ; then
655 echo "メンバー以外は利用できません。" | html p; return
656 fi
657 i=0
658 bd=$tmpd/archive.$$
659 mkdir $bd
660 query "select m.rowid,author,m.val from article a join article_m m\
661 on a.id=m.id where blogid=(select id from blog where rowid=$1)\
662 and m.key in ('image', 'document', 'binary');" \
663 | while IFS='|' read rowid author filename; do
664 err isfilereadable $user article_m $rowid
665 isfilereadable $user article_m $rowid || continue
666 err ok
667 i=$((i+1))
668 dir=`printf $bd/%03d $i`
669 mkdir $dir
670 query "select quote(bin) from article_m where rowid=$rowid;" \
671 | unhexize > $dir/$filename
672 done
673 if [ ! -d $bd/001 ]; then
674 contenttype; echo
675 echo "取得できるファイルがありませんでした。" | html p
676 return
677 fi
678 (cd $bd
679 ## err cdto$bd; (pwd; ls -lFa) 1>&3
680 tar zcf .archive.tar.gz * && mv .archive.tar.gz archive.tar.gz
681 err Creating tar archive "`ls -l archive.tar.gz`"
682 )
683 arc=$bd/archive.tar.gz
684 echo "Content-type: application/x-gzip"
685 echo "Content-Length: `cat $arc|wc -c`"
686 echo "Content-Disposition: filename=\"archive.tar.gz\""
687 echo
688 cat $arc
689 }
690 blogseen() { # $1 = blogid
691 blogid=${1%%[!0-9]*}
692 if [ -z "$blogid" ]; then
693 echo "Invalid blog id" | html p; exit
694 fi
695 blog_writable "$blogid" "$user"
696 rc=$? # =0: writable, $BLOG_NOTMEM bit set => not member
697 if [ $((rc & $BLOG_NOTMEM)) -gt 0 ] ; then
698 echo "メンバー以外は利用できません。" | html p; return
699 fi
700 owner=`getvalbyid blog owner $rowid`
701 qowner=`sqlquotestr "$owner"`
702 grprowid=`query "SELECT rowid FROM grp WHERE gname=$qowner;"`
703 ge=`gecos "$owner" | htmlescape`
704 title=`getvalbyid blog title $rowid | htmlescape`
705 h1="アクセス時刻"
706 link2board="<a href=\"?replyblog+$rowid\">$title</a>"
707 link2group="<a href=\"?grp+$grprowid\">$ge</a>"
708 _m4 -D_TITLE_="$h1" $layout/html.m4.html
709 echo "$h1" | html h1
710 echo "[$link2board]@$link2group" | html h2
711 warn=' class="warn"'
712 cat <<-EOF
713 <table class="b">
714 <tr><th>メンバー</th><th>uname</th><th>最終閲覧時刻</th></tr>
715 EOF
716 query <<-EOF |
717 WITH grpmem as (
718 SELECT user, (SELECT gecos FROM gecoses WHERE name=user) gecos
719 FROM grp_mem
720 WHERE gname=(SELECT val FROM blog_s
721 WHERE id=(select id from blog where rowid=$blogid)
722 AND key='owner')
723 ), acctime AS (
724 SELECT user, max(time) atime
725 FROM tblaccesses
726 WHERE tbl='blog' AND tblrowid=$blogid
727 GROUP BY user
728 )
729 SELECT g.user,
730 (SELECT rowid FROM user u WHERE u.name=g.user),
731 hex(gecos),
732 atime
733 FROM grpmem g LEFT JOIN acctime t
734 ON g.user = t.user
735 GROUP BY g.user
736 ORDER BY atime DESC;
737 EOF
738 while IFS='|' read u uid hexge time; do
739 td=${time:+"<td>"} # If the variable time is set, td=<td>
740 td=${td:-"<td$warn>"} # else td=<td class="warn">
741 cat <<-EOF
742 <tr>
743 <td><a href="?home+$uid">`echo "$hexge"|unhexize|htmlescape`</a></td>
744 <td>`echo ${u%%@*}|htmlescape`</td>
745 $td${time:----}</td></tr>
746 EOF
747 done
748 cat <<-EOF
749 </table>
750 <p><a href="?replyblog+$rowid">[$title]に戻る</a></p>
751 </html>
752 EOF
753 }
754 lsmyfile() { # $1(optional)=SortBy
755 case "$1" in
756 ""|CTIME-DESC)
757 by="CTIME" ord="DESC" ;;
758 CTIME*) by="CTIME" ;;
759 FILE*) by="FILE" ;;
760 OWNER*) by="OWNER" ;;
761 TITLE*) by="TITLE" ;;
762 esac
763 case "$1" in
764 *DESC) ord="DESC" ;;
765 esac
766 case "$ord" in
767 DESC) lkod="" jord="降順" ;;
768 *) lkod="-DESC" jord="昇順" ;;
769 esac
770 sql="select m.val||'/'||m.rowid FILE,
771 coalesce(
772 case when (select name from user where name=bs.owner)
773 is not null
774 then (select val from user_s where name=bs.owner
775 and key='gecos')
776 when (select gname from grp where gname=bs.owner)
777 is not null
778 then (select val from grp_s where gname=bs.owner
779 and key='gecos')
780 else
781 null
782 end,
783 bs.owner
784 ) OWNER,
785 a_s.val CTIME,
786 ',t,'||bs.title||':'||b.rowid||'#'||a.id TITLE
787 from (select rowid,id,val from article_m where id
788 in (select id from article where author='$user')
789 and type like 'file:%')
790 m left join article a on m.id=a.id
791 left join article_s a_s on a.id=a_s.id and a_s.key='ctime'
792 left join (select id,
793 max(case key when 'owner' then val end) as owner,
794 max(case key when 'title' then val end) as title
795 from blog_s group by id)
796 bs on a.blogid=bs.id
797 left join blog b on bs.id=b.id
798 where m.val is not null order by $by $ord;"
799 err lshandoutbyauthor: sql=`echo "$sql"`
800 title="個人提出ファイル"
801 _m4 -D_TITLE_=$title $layout/html.m4.html
802 hra="<a href=\"?lsmyfile+"
803 hrb="<a href=\"?showattc+article_m+"
804 hrc="<a href=\"?replyblog+"
805 (echo '<table class="b">'
806 echo "$sql"|sq -html -header $db ) \
807 | sed -e "s|\(<TR><TD>\)\([^/]*\)/\([0-9]*\)|\1$hrb\3\">\2</a>|" \
808 -e "s|,t,\(.*\):\([^<]*\)\(</TD>\)|$hrc\2\">\1</a>\3|" \
809 -e "s|\(<TH>\)\([A-Z]*\)\(</TH>\)|\1$hra\2$lkod\">\2</a>|" \
810 | _m4 -D_TITLE_=$title -D_FORM_="<p>($by$jord)</p>" \
811 -D_DUMPTABLE_="syscmd(cat)" $layout/form+dump.m4.html
812 echo '</table>'
813 }
814 searchart() {
815 kwd=`getpar kwd|nkf -wZ1` # Convert Zenkaku-SPC to ASCII-SPC
816 bloglist=`getpar bloglist|sed 's/[^0-9,]//g'`
817 kwdgrp=""
818 authcond=""
819 if [ -z "$kwd" ]; then
820 echo "検索語を指定してください" | html p; return
821 fi
822 if logstart "$searchlog"; then
823 { echo "kwd=$kwd"
824 test -n "$bloglist" && echo "bloglist=$bloglist"
825 } >> $searchlog
826 logend "$searchlog"
827 fi
828 if expr x"$kwd" : 'x#[1-9][0-9]*$' >/dev/null 1>&2; then
829 # Like '#1234', assume as artID
830 rowid=$((${kwd#\#} + 0)) # Force to be a number
831 kc="ar.rowid = $rowid"
832 else
833 for k in `echo "$kwd" | sed "s/'/''/g"`; do # With wrap quotes
834 ctime=""
835 if expr x"$k" : 'x@[><= ]*[1-9][][0-9]*-[][0-9:-]*$' >/dev/null >&2; then
836 # '@<2016-10-10' -> ctime < '2016-10-10'
837 # '@>=2016-10-10' -> ctime >= '2016-10-10'
838 # '@2016-10-10' -> ctime GLOB '@2016-10-10'
839 k=${k#@}
840 case "$k" in
841 [\<\>]*) op=${k%%[!<>=]*}; ctime=${k##*[><= ]} ;;
842 *) op='GLOB'; ctime="${k##*[><= ]}*" ;;
843 esac
844 kc=$kc${kc:+" AND "}"ctime $op '${ctime}'"
845 # Not sure GROUP BY a.blogid is comfortable for searchers...?
846 ##### kwdgrp=" GROUP BY a.blogid" ## Add this to lessen results
847 elif [ x"$k" = x"@today" -o x"$k" = x"@今日" ]; then
848 ctime=`date +%F`
849 elif n=`expr x"$k" : 'x@\([0-9]*\)days*'` >/dev/null >&2; then
850 ctime=`query "SELECT datetime('now', 'localtime', '-$n days');"`
851 elif [ x"$k" = x"@week" ]; then
852 ctime=`query "SELECT datetime('now', 'localtime', '-7 days');"`
853 elif n=`expr x"$k" : 'x@\([0-9]*\)weeks*'` >/dev/null >&2; then
854 n=$((n * 7))
855 ctime=`query "SELECT datetime('now', 'localtime', '-$n days');"`
856 elif [ x"$k" = x"@month" ]; then
857 ctime=`query "SELECT datetime('now', 'localtime', '-1 month');"`
858 elif n=`expr x"$k" : 'x@\([0-9]*\)months*'` >/dev/null >&2; then
859 ctime=`query "SELECT datetime('now', 'localtime', '-$n month');"`
860 elif [ x"$k" = x"@year" ]; then
861 ctime=`query "SELECT datetime('now', 'localtime', '-1 year');"`
862 elif n=`expr x"$k" : 'x@\([0-9]*\)years*'` >/dev/null >&2; then
863 ctime=`query "SELECT datetime('now', 'localtime', '-$n year');"`
864 fi
865 if [ -n "$ctime" ]; then
866 kc=$kc${kc:+" AND "}"ctime > '${ctime}'"
867 else
868 e=""
869 case "$k" in
870 *${likeesc}*) e="" ;; # Giving up char-escaping
871 *%*|*_*) k=`echo "$k"|sed "s/\([%_]\)/${likeesc}\1/g"`
872 e=" ESCAPE '$likeesc'" ;;
873 esac
874 kc=$kc${kc:+" AND "}"content LIKE '%$k%'$e"
875 fi
876 done
877 fi
878 kwd=`echo "$kwd"|htmlescape`
879 owner=`getpar owner`
880 owner=${owner:-$1}
881 msg=""
882 if [ -n "$owner" ]; then
883 cond="where key='owner' and val='$owner'"
884 if isuser $owner; then
885 msg="(`linkhome $owner` さんの記録から)"
886 else
887 linkhome $owner 1>&3
888 msg="(`linkhome $owner` グループから)"
889 fi
890 elif { author=`getpar author`; test -n "$author"; }; then
891 atptn=`sqlquotestr $author`
892 #kc="$kc${kc:+ AND }author=$atptn"
893 authcond="WHERE author=$atptn"
894 if isuser $author; then
895 msg="(`linkhome $author` さんの書き込みから)"
896 fi
897 fi
898 if [ -n "$bloglist" ]; then
899 blogcond="AND bl.rid IN ($bloglist)"
900 fi
902 sf=`search_form "$search_form_args" "$kwd" | sed '1d;$d'` # rm <div></div>
903 echo "$sf" | sed -e "/POST SENTENCE/s/.*/__PS__/" -e "/EOF/q" \
904 | _m4 -D__PS__="による検索結果$msg"
905 echo "(上記入力窓で再検索すると下記の掲示板のみに絞って再検索します)" \
906 | html p 'class="small"'
907 # article_s: id=article-id, key='text', val='TEXT'
908 # article: id=article-id, blogid=blogkd
909 # blog: id=blog-id, author=LeaderAuthor
910 # blog_s: id=blog-id, key='title', val='BLOG-TITLE'
911 # WANT: blog-ROWid,article-id,val(TEXT)
912 sql2="`sql4readableblogs` -- Extract user-readable blogs
913 -- 0.3sec
914 WITH artsm AS (
915 SELECT a.id,ctime, text || ' ' || coalesce(files, '') content
916 FROM article a
917 LEFT JOIN
918 (SELECT ars.id, ctime, text, coalesce(files, '') files
919 FROM (SELECT id,
920 max(CASE key WHEN 'ctime' THEN val END) ctime,
921 max(CASE key WHEN 'text' THEN val END) text
922 FROM article_s
923 GROUP BY id) ars
924 LEFT JOIN
925 (SELECT id, group_concat(val) files
926 FROM article_m
927 WHERE type LIKE 'file:%'
928 GROUP BY id) arm
929 ON ars.id=arm.id
930 ) ar
931 ON a.id=ar.id
932 ), ar AS (
933 SELECT a.rowid, a.blogid, a.id, a.author, ctime, content
934 FROM article a JOIN artsm ON a.id=artsm.id
935 $authcond
936 ), bl AS (
937 SELECT blg.rid, blg.*, blog_s.val TITLE
938 FROM readableblogs blg JOIN blog_s ON blg.id=blog_s.id AND blog_s.key='title'
939 )
940 SELECT bl.rid||'#'||ar.id '',
941 bl.title TITLE,
942 (SELECT gecos FROM gecoses WHERE name=ar.author) AUTHOR,
943 substr(ctime, 0, 11) DATE,
944 substr(content, 0, 78) TEXT
945 FROM ar JOIN bl
946 ON ar.blogid=bl.id
947 WHERE $kc AND bl.id IN (SELECT id FROM blog_s $cond) $blogcond
948 ORDER by DATE DESC, TITLE, ctime;"
949 sedopt="s,<TR><TD>\([^<]*\)</TD>,<TR><TD><a\
950 href=\"?replyblog+\1\">VIEW</a></TD>,"
951 # echo "$sql2" > tmp/sql.out
952 result=$tmpd/result.$$
953 cat<<EOF
954 <table class="b searchart">
955 `sq -header -html $db "$sql2"|sed "$sedopt"|tee $result`
956 </table>
957 EOF
958 if [ -s "$result" ]; then
959 found=$((`grep "^<TR><TD>" $result | wc -l` + 0)) # Cast to INT
960 one=${found%1}
961 echo "$found match${one:+es} found"
962 # <a href="?replyblog+39#12345">VIEW</a>
963 # -> 39,49,55, -> 39,49,55
964 # -> <input type="hidden" name="bloglist" value="39,49,55">
965 sed -n "/.*href=.*replyblog\+\([0-9][0-9]*\).*/s//\1/p" "$result" \
966 | sort | uniq | tr '\n' ',' \
967 | sed -e 's/,$//' \
968 -e 's/^/<input type="hidden" name="bloglist" value="/' \
969 -e 's/$/">/'
970 else
971 echo orz...
972 fi
973 echo "$sf" | sed "1,/-- EOF/d" # Close <form>
974 }
975 listblog() (
976 # $1={user,group}
977 qow=`sqlquote $1`
978 cond="where a.id in (select id from blog_s where key='owner' and val=$qow) order by ctime desc"
979 cgi_form searchart<<EOF
980 <label>`cgi_text kwd`という語を含む記事をこの一覧から検索</label>
981 `cgi_hidden owner $user`
982 EOF
983 DT_CHLD=article:blogid DT_QOWNER=$qow \
984 dumptable html blog 'ctime title heading' "$cond"
985 )
987 blog_addentry() {
988 # $1=GRPname(if it is a group)
989 grprowid=$1
990 rowid=`getpar rowid`
991 ## err blog_addentry0: rowid=$rowid
992 if [ -n "$grprowid" ]; then
993 owner=`getgroupbyid $grprowid`
994 else
995 owner=`getpar owner`
996 fi
997 err blog-add: \$1=$1 rowid=$rowid owner=$owner
998 if isgroup "$owner"; then
999 groupmode=1 listing=$owner guide="[${owner}]" GF_OWNER=$owner
1000 else
1001 usermode=1 listing=$user guide="[個人]"
1002 fi
1004 if [ -n "`getpar title`" ]; then
1005 if [ "$usermode" ]; then
1006 err usermode: user=$user owner=$owner
1007 if [ x"$user" != x"$owner" ]; then
1008 echo "他人の日記は書けません" | html p
1009 return 2
1010 fi
1011 elif [ "$groupmode" ]; then # if write to group log
1012 grp=$owner #\`getpar grp\`
1013 err ismember: $user $grp
1014 if ! ismember "$user" "$grp"; then
1015 echo "(話題作成はこのグループに加入してから)" | html p
1016 return 3
1017 fi
1018 fi
1019 par2table $formdir/blog.def
1020 serial=`getpar serial`
1021 ## err SERIAL: $serial ROWID=$rowid listing=$listing
1022 id=""
1023 if [ -n "$rowid" ]; then
1024 # Here, id becomes NULL when removal of entries at par2table
1025 id=`query "select rowid from blog where rowid=$rowid;"`
1026 elif [ -n "$serial" ]; then
1027 # If new blog leader created, traverse to its head.
1028 id=`query "select rowid from blog where id='$serial';"`
1029 ## err new-Leader: "select rowid from blog where id='$serial';" id=$id
1030 fi
1031 if [ -n "$id" ]; then
1032 ## If new aritcle is entered, JUMP to blog_reply
1033 blog_reply $id
1034 return
1035 fi
1036 fi
1037 echo "${guide}新規話題作成" > $tmpd/title.$$
1038 listblog $listing > $tmpd/listblog.$$
1039 genform $formdir/blog.def \
1040 | _m4 -D_TITLE_="spaste(\`$tmpd/title.$$')" \
1041 -D_FORMHEAD_="序文は簡単に詳しくはコメントに" \
1042 -D_DUMPHEAD_="これまでの蓄積" \
1043 -D_FORM_="syscmd(\`cat')" \
1044 -D_DUMPTABLE_="spaste(\`$tmpd/listblog.$$')" \
1045 $layout/html.m4.html \
1046 $layout/form+dump-whead.m4.html
1049 blog_reply() { # Posting to blog article
1050 rowid=$1
1052 if [ -z "$rowid" ]; then
1053 echo "表示する日記番号が未指定です。" | html p
1054 return
1055 fi
1056 title=`getvalbyid blog title $rowid`
1057 owner=`getvalbyid blog owner $rowid`
1058 qowner=`sqlquotestr "$owner"`
1059 if [ -z "$title" ]; then
1060 echo "日記番号指定が無効です。" | html p
1061 return
1062 fi
1063 blog_writable $rowid $user; rc=$?
1064 if [ $rc = 0 ]; then
1065 iswritable=true
1066 else
1067 iswritable=false
1068 if [ $((rc & $BLOG_FROZEN)) -gt 0 ]; then
1069 isfrozen=true
1070 frozen_class='frozen"'
1071 frozen_flag=$FROZEN_TAG
1072 fi
1073 fi
1074 if isuser "$owner"; then
1075 subtitle="`gecos $owner` さんの話題"
1076 else
1077 grprowid=`query "select rowid from grp where gname=$qowner;"`
1078 subtitle="グループ
1079 <a href=\"?grp+$grprowid\" accesskey=\"h\" title=\"H\">$owner</a> での話題
1080 `query \"SELECT printf('(チーム:%s)', val)\
1081 FROM blog_s
1082 WHERE id=(SELECT id FROM blog WHERE rowid=$rowid)
1083 AND key='team';
1084 \"|htmlescape`"
1085 memclass=`grp_getbodyclass "$owner"`
1086 fi
1088 text=`getpar text`
1089 if [ -n "$text" ]; then
1090 if $iswritable; then
1091 par2table $formdir/article.def
1092 st=$?
1093 case $st in
1094 0|4)
1095 [ "$st" = "4" ] && act="書込削除"
1096 blog_notify_reply $rowid $user "$text" $act
1097 if [ -n "$grprowid" ]; then
1098 qgrp=$(sqlquote "$owner")
1099 dbsetbyid grp $owner wtime "`date '+%F %T'`"
1100 else
1101 dbsetbyid user "$user" wtime "`date '+%F %T'`"
1102 fi
1103 ;;
1104 esac
1105 else
1106 if $isfrozen; then
1107 title="$title(凍結板につき書き込み不可)"
1108 else
1109 title="$title(加入してないので書き込み不可)"
1110 fi
1111 fi
1112 fi
1113 def=$formdir/article.def
1114 echo "$title" > $tmpd/title.$$
1115 echo "$subtitle$frozen_flag" > $tmpd/subtitle.$$
1116 ${BLOG_SHOW:-blog_showentry} blog $rowid \
1117 | _m4 -D_TITLE_="spaste(\`$tmpd/title.$$')" \
1118 -D_BODYCLASS_=general"${memclass:+ $memclass}" \
1119 -D_FORMHEAD_="spaste(\`$tmpd/subtitle.$$')" \
1120 -D_FORM_='' \
1121 -D_DUMPTABLE_="syscmd(cat)" -D_DUMPHEAD_="" \
1122 $layout/html.m4.html $layout/form+dump-whead.m4.html
1125 blog_reply_article() { # Direct link to article in some blog
1126 arid=${1:-0} # Already sanitized to digits
1127 brid=`query "SELECT rowid FROM blog WHERE \
1128 id=(SELECT blogid FROM article WHERE rowid=$arid);"`
1129 if [ -n "$brid" ]; then
1130 newurl="?replyblog+$brid#$arid"
1131 echo "Refresh: 0; $newurl"; echo
1132 exit 0
1133 else
1134 contenttype; echo
1135 echo "無効な記事番号です." | html p
1136 fi