s4

view s4-blog.sh @ 583:ae420aaa8f4f

Horizontal padding of table.mini td changed from 1ex to 0.5ex
author HIROSE Yuuji <yuuji@gentei.org>
date Sat, 27 Jul 2019 08:43:40 +0900
parents e4e207222ee9
children dfa90fbc05bd
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 rid=`numericalize "$1"`
653 blog_writable $rid $user
654 rc=$? # =0: writable, $BLOG_NOTMEM bit set => not member
655 if [ $((rc & $BLOG_NOTMEM)) -gt 0 ] ; then
656 echo "メンバー以外は利用できません。" | html p; return
657 fi
658 i=0
659 bd=$tmpd/archive.$$
660 mkdir $bd
661 query "select m.rowid,author,m.val from article a join article_m m\
662 on a.id=m.id where blogid=(select id from blog where rowid=$rid)\
663 and m.key in ('image', 'document', 'binary');" \
664 | while IFS='|' read rowid author filename; do
665 err isfilereadable $user article_m $rowid
666 isfilereadable $user article_m $rowid || continue
667 err ok
668 i=$((i+1))
669 dir=`printf $bd/%03d $i`
670 mkdir $dir
671 query "select quote(bin) from article_m where rowid=$rowid;" \
672 | unhexize > $dir/$filename
673 done
674 if [ ! -d $bd/001 ]; then
675 contenttype; echo
676 echo "取得できるファイルがありませんでした。" | html p
677 return
678 fi
679 (cd $bd
680 ## err cdto$bd; (pwd; ls -lFa) 1>&3
681 tar zcf .archive.tar.gz * && mv .archive.tar.gz archive.tar.gz
682 err Creating tar archive "`ls -l archive.tar.gz`"
683 )
684 arc=$bd/archive.tar.gz
685 echo "Content-type: application/x-gzip"
686 echo "Content-Length: `cat $arc|wc -c`"
687 echo "Content-Disposition: filename=\"archive.tar.gz\""
688 echo
689 cat $arc
690 }
691 blogseen() { # $1 = blogid
692 blogid=${1%%[!0-9]*}
693 if [ -z "$blogid" ]; then
694 echo "Invalid blog id" | html p; exit
695 fi
696 blog_writable "$blogid" "$user"
697 rc=$? # =0: writable, $BLOG_NOTMEM bit set => not member
698 if [ $((rc & $BLOG_NOTMEM)) -gt 0 ] ; then
699 echo "メンバー以外は利用できません。" | html p; return
700 fi
701 owner=`getvalbyid blog owner $rowid`
702 qowner=`sqlquotestr "$owner"`
703 grprowid=`query "SELECT rowid FROM grp WHERE gname=$qowner;"`
704 ge=`gecos "$owner" | htmlescape`
705 title=`getvalbyid blog title $rowid | htmlescape`
706 h1="アクセス時刻"
707 link2board="<a href=\"?replyblog+$rowid\">$title</a>"
708 link2group="<a href=\"?grp+$grprowid\">$ge</a>"
709 _m4 -D_TITLE_="$h1" $layout/html.m4.html
710 echo "$h1" | html h1
711 echo "[$link2board]@$link2group" | html h2
712 warn=' class="warn"'
713 cat <<-EOF
714 <table class="b">
715 <tr><th>メンバー</th><th>uname</th><th>最終閲覧時刻</th></tr>
716 EOF
717 query <<-EOF |
718 WITH grpmem as (
719 SELECT user, (SELECT gecos FROM gecoses WHERE name=user) gecos
720 FROM grp_mem
721 WHERE gname=(SELECT val FROM blog_s
722 WHERE id=(select id from blog where rowid=$blogid)
723 AND key='owner')
724 ), acctime AS (
725 SELECT user, max(time) atime
726 FROM tblaccesses
727 WHERE tbl='blog' AND tblrowid=$blogid
728 GROUP BY user
729 )
730 SELECT g.user,
731 (SELECT rowid FROM user u WHERE u.name=g.user),
732 hex(gecos),
733 atime
734 FROM grpmem g LEFT JOIN acctime t
735 ON g.user = t.user
736 GROUP BY g.user
737 ORDER BY atime DESC;
738 EOF
739 while IFS='|' read u uid hexge time; do
740 td=${time:+"<td>"} # If the variable time is set, td=<td>
741 td=${td:-"<td$warn>"} # else td=<td class="warn">
742 cat <<-EOF
743 <tr>
744 <td><a href="?home+$uid">`echo "$hexge"|unhexize|htmlescape`</a></td>
745 <td>`echo ${u%%@*}|htmlescape`</td>
746 $td${time:----}</td></tr>
747 EOF
748 done
749 cat <<-EOF
750 </table>
751 <p><a href="?replyblog+$rowid">[$title]に戻る</a></p>
752 </html>
753 EOF
754 }
755 lsmyfile() { # $1(optional)=SortBy
756 case "$1" in
757 ""|CTIME-DESC)
758 by="CTIME" ord="DESC" ;;
759 CTIME*) by="CTIME" ;;
760 FILE*) by="FILE" ;;
761 OWNER*) by="OWNER" ;;
762 TITLE*) by="TITLE" ;;
763 esac
764 case "$1" in
765 *DESC) ord="DESC" ;;
766 esac
767 case "$ord" in
768 DESC) lkod="" jord="降順" ;;
769 *) lkod="-DESC" jord="昇順" ;;
770 esac
771 sql="select m.val||'/'||m.rowid FILE,
772 coalesce(
773 case when (select name from user where name=bs.owner)
774 is not null
775 then (select val from user_s where name=bs.owner
776 and key='gecos')
777 when (select gname from grp where gname=bs.owner)
778 is not null
779 then (select val from grp_s where gname=bs.owner
780 and key='gecos')
781 else
782 null
783 end,
784 bs.owner
785 ) OWNER,
786 a_s.val CTIME,
787 ',t,'||bs.title||':'||b.rowid||'#'||a.id TITLE
788 from (select rowid,id,val from article_m where id
789 in (select id from article where author='$user')
790 and type like 'file:%')
791 m left join article a on m.id=a.id
792 left join article_s a_s on a.id=a_s.id and a_s.key='ctime'
793 left join (select id,
794 max(case key when 'owner' then val end) as owner,
795 max(case key when 'title' then val end) as title
796 from blog_s group by id)
797 bs on a.blogid=bs.id
798 left join blog b on bs.id=b.id
799 where m.val is not null order by $by $ord;"
800 err lshandoutbyauthor: sql=`echo "$sql"`
801 title="個人提出ファイル"
802 _m4 -D_TITLE_=$title $layout/html.m4.html
803 hra="<a href=\"?lsmyfile+"
804 hrb="<a href=\"?showattc+article_m+"
805 hrc="<a href=\"?replyblog+"
806 (echo '<table class="b">'
807 echo "$sql"|sq -html -header $db ) \
808 | sed -e "s|\(<TR><TD>\)\([^/]*\)/\([0-9]*\)|\1$hrb\3\">\2</a>|" \
809 -e "s|,t,\(.*\):\([^<]*\)\(</TD>\)|$hrc\2\">\1</a>\3|" \
810 -e "s|\(<TH>\)\([A-Z]*\)\(</TH>\)|\1$hra\2$lkod\">\2</a>|" \
811 | _m4 -D_TITLE_=$title -D_FORM_="<p>($by$jord)</p>" \
812 -D_DUMPTABLE_="syscmd(cat)" $layout/form+dump.m4.html
813 echo '</table>'
814 }
815 searchart() {
816 kwd=`getpar kwd|nkf -wZ1` # Convert Zenkaku-SPC to ASCII-SPC
817 bloglist=`getpar bloglist|sed 's/[^0-9,]//g'`
818 kwdgrp=""
819 authcond=""
820 if [ -z "$kwd" ]; then
821 echo "検索語を指定してください" | html p; return
822 fi
823 if logstart "$searchlog"; then
824 { echo "kwd=$kwd"
825 test -n "$bloglist" && echo "bloglist=$bloglist"
826 } >> $searchlog
827 logend "$searchlog"
828 fi
829 if expr x"$kwd" : 'x#[1-9][0-9]*$' >/dev/null 1>&2; then
830 # Like '#1234', assume as artID
831 rowid=$((${kwd#\#} + 0)) # Force to be a number
832 kc="ar.rowid = $rowid"
833 else
834 for k in `echo "$kwd" | sed "s/'/''/g"`; do # With wrap quotes
835 ctime=""
836 if expr x"$k" : 'x@[><= ]*[1-9][][0-9]*-[][0-9:-]*$' >/dev/null >&2; then
837 # '@<2016-10-10' -> ctime < '2016-10-10'
838 # '@>=2016-10-10' -> ctime >= '2016-10-10'
839 # '@2016-10-10' -> ctime GLOB '@2016-10-10'
840 k=${k#@}
841 case "$k" in
842 [\<\>]*) op=${k%%[!<>=]*}; ctime=${k##*[><= ]} ;;
843 *) op='GLOB'; ctime="${k##*[><= ]}*" ;;
844 esac
845 kc=$kc${kc:+" AND "}"ctime $op '${ctime}'"
846 # Not sure GROUP BY a.blogid is comfortable for searchers...?
847 ##### kwdgrp=" GROUP BY a.blogid" ## Add this to lessen results
848 elif [ x"$k" = x"@today" -o x"$k" = x"@今日" ]; then
849 ctime=`date +%F`
850 elif n=`expr x"$k" : 'x@\([0-9]*\)days*'` >/dev/null >&2; then
851 ctime=`query "SELECT datetime('now', 'localtime', '-$n days');"`
852 elif [ x"$k" = x"@week" ]; then
853 ctime=`query "SELECT datetime('now', 'localtime', '-7 days');"`
854 elif n=`expr x"$k" : 'x@\([0-9]*\)weeks*'` >/dev/null >&2; then
855 n=$((n * 7))
856 ctime=`query "SELECT datetime('now', 'localtime', '-$n days');"`
857 elif [ x"$k" = x"@month" ]; then
858 ctime=`query "SELECT datetime('now', 'localtime', '-1 month');"`
859 elif n=`expr x"$k" : 'x@\([0-9]*\)months*'` >/dev/null >&2; then
860 ctime=`query "SELECT datetime('now', 'localtime', '-$n month');"`
861 elif [ x"$k" = x"@year" ]; then
862 ctime=`query "SELECT datetime('now', 'localtime', '-1 year');"`
863 elif n=`expr x"$k" : 'x@\([0-9]*\)years*'` >/dev/null >&2; then
864 ctime=`query "SELECT datetime('now', 'localtime', '-$n year');"`
865 fi
866 if [ -n "$ctime" ]; then
867 kc=$kc${kc:+" AND "}"ctime > '${ctime}'"
868 else
869 e=""
870 case "$k" in
871 *${likeesc}*) e="" ;; # Giving up char-escaping
872 *%*|*_*) k=`echo "$k"|sed "s/\([%_]\)/${likeesc}\1/g"`
873 e=" ESCAPE '$likeesc'" ;;
874 esac
875 kc=$kc${kc:+" AND "}"content LIKE '%$k%'$e"
876 fi
877 done
878 fi
879 kwd=`echo "$kwd"|htmlescape`
880 owner=`getpar owner`
881 owner=${owner:-$1}
882 msg=""
883 if [ -n "$owner" ]; then
884 cond="where key='owner' and val='$owner'"
885 if isuser $owner; then
886 msg="(`linkhome $owner` さんの記録から)"
887 else
888 linkhome $owner 1>&3
889 msg="(`linkhome $owner` グループから)"
890 fi
891 elif { author=`getpar author`; test -n "$author"; }; then
892 atptn=`sqlquotestr $author`
893 #kc="$kc${kc:+ AND }author=$atptn"
894 authcond="WHERE author=$atptn"
895 if isuser $author; then
896 msg="(`linkhome $author` さんの書き込みから)"
897 fi
898 fi
899 if [ -n "$bloglist" ]; then
900 blogcond="AND bl.rid IN ($bloglist)"
901 fi
903 sf=`search_form "$search_form_args" "$kwd" | sed '1d;$d'` # rm <div></div>
904 echo "$sf" | sed -e "/POST SENTENCE/s/.*/__PS__/" -e "/EOF/q" \
905 | _m4 -D__PS__="による検索結果$msg"
906 echo "(上記入力窓で再検索すると下記の掲示板のみに絞って再検索します)" \
907 | html p 'class="small"'
908 # article_s: id=article-id, key='text', val='TEXT'
909 # article: id=article-id, blogid=blogkd
910 # blog: id=blog-id, author=LeaderAuthor
911 # blog_s: id=blog-id, key='title', val='BLOG-TITLE'
912 # WANT: blog-ROWid,article-id,val(TEXT)
913 sql2="`sql4readableblogs` -- Extract user-readable blogs
914 -- 0.3sec
915 WITH artsm AS (
916 SELECT a.id,ctime, text || ' ' || coalesce(files, '') content
917 FROM article a
918 LEFT JOIN
919 (SELECT ars.id, ctime, text, coalesce(files, '') files
920 FROM (SELECT id,
921 max(CASE key WHEN 'ctime' THEN val END) ctime,
922 max(CASE key WHEN 'text' THEN val END) text
923 FROM article_s
924 GROUP BY id) ars
925 LEFT JOIN
926 (SELECT id, group_concat(val) files
927 FROM article_m
928 WHERE type LIKE 'file:%'
929 GROUP BY id) arm
930 ON ars.id=arm.id
931 ) ar
932 ON a.id=ar.id
933 ), ar AS (
934 SELECT a.rowid, a.blogid, a.id, a.author, ctime, content
935 FROM article a JOIN artsm ON a.id=artsm.id
936 $authcond
937 ), bl AS (
938 SELECT blg.rid, blg.*, blog_s.val TITLE
939 FROM readableblogs blg JOIN blog_s ON blg.id=blog_s.id AND blog_s.key='title'
940 )
941 SELECT bl.rid||'#'||ar.id '',
942 bl.title TITLE,
943 (SELECT gecos FROM gecoses WHERE name=ar.author) AUTHOR,
944 substr(ctime, 0, 11) DATE,
945 substr(content, 0, 78) TEXT
946 FROM ar JOIN bl
947 ON ar.blogid=bl.id
948 WHERE $kc AND bl.id IN (SELECT id FROM blog_s $cond) $blogcond
949 ORDER by DATE DESC, TITLE, ctime;"
950 sedopt="s,<TR><TD>\([^<]*\)</TD>,<TR><TD><a\
951 href=\"?replyblog+\1\">VIEW</a></TD>,"
952 # echo "$sql2" > tmp/sql.out
953 result=$tmpd/result.$$
954 cat<<EOF
955 <table class="b searchart">
956 `sq -header -html $db "$sql2"|sed "$sedopt"|tee $result`
957 </table>
958 EOF
959 if [ -s "$result" ]; then
960 found=$((`grep "^<TR><TD>" $result | wc -l` + 0)) # Cast to INT
961 one=${found%1}
962 echo "$found match${one:+es} found"
963 # <a href="?replyblog+39#12345">VIEW</a>
964 # -> 39,49,55, -> 39,49,55
965 # -> <input type="hidden" name="bloglist" value="39,49,55">
966 sed -n "/.*href=.*replyblog\+\([0-9][0-9]*\).*/s//\1/p" "$result" \
967 | sort | uniq | tr '\n' ',' \
968 | sed -e 's/,$//' \
969 -e 's/^/<input type="hidden" name="bloglist" value="/' \
970 -e 's/$/">/'
971 else
972 echo orz...
973 fi
974 echo "$sf" | sed "1,/-- EOF/d" # Close <form>
975 }
976 listblog() (
977 # $1={user,group}
978 qow=`sqlquote $1`
979 cond="where a.id in (select id from blog_s where key='owner' and val=$qow) order by ctime desc"
980 cgi_form searchart<<EOF
981 <label>`cgi_text kwd`という語を含む記事をこの一覧から検索</label>
982 `cgi_hidden owner $user`
983 EOF
984 DT_CHLD=article:blogid DT_QOWNER=$qow \
985 dumptable html blog 'ctime title heading' "$cond"
986 )
988 blog_addentry() {
989 # $1=GRPname(if it is a group)
990 grprowid=`numericalize $1`
991 rowid=`getpar rowid`
992 ## err blog_addentry0: rowid=$rowid
993 if [ -n "$grprowid" ]; then
994 owner=`getgroupbyid $grprowid`
995 else
996 owner=`getpar owner`
997 fi
998 err blog-add: \$1=$grprowid rowid=$rowid owner=$owner
999 if isgroup "$owner"; then
1000 groupmode=1 listing=$owner guide="[${owner}]" GF_OWNER=$owner
1001 else
1002 usermode=1 listing=$user guide="[個人]"
1003 fi
1005 if [ -n "`getpar title`" ]; then
1006 if [ "$usermode" ]; then
1007 err usermode: user=$user owner=$owner
1008 if [ x"$user" != x"$owner" ]; then
1009 echo "他人の日記は書けません" | html p
1010 return 2
1011 fi
1012 elif [ "$groupmode" ]; then # if write to group log
1013 grp=$owner #\`getpar grp\`
1014 err ismember: $user $grp
1015 if ! ismember "$user" "$grp"; then
1016 echo "(話題作成はこのグループに加入してから)" | html p
1017 return 3
1018 fi
1019 fi
1020 par2table $formdir/blog.def
1021 serial=`getpar serial`
1022 ## err SERIAL: $serial ROWID=$rowid listing=$listing
1023 id=""
1024 if [ -n "$rowid" ]; then
1025 # Here, id becomes NULL when removal of entries at par2table
1026 id=`query "select rowid from blog where rowid=$rowid;"`
1027 elif [ -n "$serial" ]; then
1028 # If new blog leader created, traverse to its head.
1029 id=`query "select rowid from blog where id='$serial';"`
1030 ## err new-Leader: "select rowid from blog where id='$serial';" id=$id
1031 fi
1032 if [ -n "$id" ]; then
1033 ## If new aritcle is entered, JUMP to blog_reply
1034 blog_reply $id
1035 return
1036 fi
1037 fi
1038 echo "${guide}新規話題作成" > $tmpd/title.$$
1039 listblog $listing > $tmpd/listblog.$$
1040 genform $formdir/blog.def \
1041 | _m4 -D_TITLE_="spaste(\`$tmpd/title.$$')" \
1042 -D_FORMHEAD_="序文は簡単に詳しくはコメントに" \
1043 -D_DUMPHEAD_="これまでの蓄積" \
1044 -D_FORM_="syscmd(\`cat')" \
1045 -D_DUMPTABLE_="spaste(\`$tmpd/listblog.$$')" \
1046 $layout/html.m4.html \
1047 $layout/form+dump-whead.m4.html
1050 blog_reply() { # Posting to blog article
1051 rowid=`numericalize $1` # Ensure (already purified in s4.cgi)
1053 if [ -z "$rowid" ]; then
1054 echo "表示する日記番号が未指定です。" | html p
1055 return
1056 fi
1057 title=`getvalbyid blog title $rowid`
1058 owner=`getvalbyid blog owner $rowid`
1059 qowner=`sqlquotestr "$owner"`
1060 if [ -z "$title" ]; then
1061 echo "日記番号指定が無効です。" | html p
1062 return
1063 fi
1064 blog_writable $rowid $user; rc=$?
1065 if [ $rc = 0 ]; then
1066 iswritable=true
1067 else
1068 iswritable=false
1069 if [ $((rc & $BLOG_FROZEN)) -gt 0 ]; then
1070 isfrozen=true
1071 frozen_class='frozen"'
1072 frozen_flag=$FROZEN_TAG
1073 fi
1074 fi
1075 if isuser "$owner"; then
1076 subtitle="`gecos $owner` さんの話題"
1077 else
1078 grprowid=`query "select rowid from grp where gname=$qowner;"`
1079 subtitle="グループ
1080 <a href=\"?grp+$grprowid\" accesskey=\"h\" title=\"H\">$owner</a> での話題
1081 `query \"SELECT printf('(チーム:%s)', val)\
1082 FROM blog_s
1083 WHERE id=(SELECT id FROM blog WHERE rowid=$rowid)
1084 AND key='team';
1085 \"|htmlescape`"
1086 memclass=`grp_getbodyclass "$owner"`
1087 fi
1089 text=`getpar text`
1090 if [ -n "$text" ]; then
1091 if $iswritable; then
1092 par2table $formdir/article.def
1093 st=$?
1094 case $st in
1095 0|4)
1096 [ "$st" = "4" ] && act="書込削除"
1097 blog_notify_reply $rowid $user "$text" $act
1098 if [ -n "$grprowid" ]; then
1099 qgrp=$(sqlquote "$owner")
1100 dbsetbyid grp $owner wtime "`date '+%F %T'`"
1101 else
1102 dbsetbyid user "$user" wtime "`date '+%F %T'`"
1103 fi
1104 ;;
1105 esac
1106 else
1107 if $isfrozen; then
1108 title="$title(凍結板につき書き込み不可)"
1109 else
1110 title="$title(加入してないので書き込み不可)"
1111 fi
1112 fi
1113 fi
1114 def=$formdir/article.def
1115 echo "$title" > $tmpd/title.$$
1116 echo "$subtitle$frozen_flag" > $tmpd/subtitle.$$
1117 ${BLOG_SHOW:-blog_showentry} blog $rowid \
1118 | _m4 -D_TITLE_="spaste(\`$tmpd/title.$$')" \
1119 -D_BODYCLASS_=general"${memclass:+ $memclass}" \
1120 -D_FORMHEAD_="spaste(\`$tmpd/subtitle.$$')" \
1121 -D_FORM_='' \
1122 -D_DUMPTABLE_="syscmd(cat)" -D_DUMPHEAD_="" \
1123 $layout/html.m4.html $layout/form+dump-whead.m4.html
1126 blog_reply_article() { # Direct link to article in some blog
1127 arid=${1:-0} # Already sanitized to digits
1128 brid=`query "SELECT rowid FROM blog WHERE \
1129 id=(SELECT blogid FROM article WHERE rowid=$arid);"`
1130 if [ -n "$brid" ]; then
1131 newurl="?replyblog+$brid#$arid"
1132 echo "Refresh: 0; $newurl"; echo
1133 exit 0
1134 else
1135 contenttype; echo
1136 echo "無効な記事番号です." | html p
1137 fi