s4

view s4-blog.sh @ 301:ba0730073d6f

Add (1)article-ID search, (2)DATE search
author HIROSE Yuuji <yuuji@gentei.org>
date Thu, 13 Oct 2016 09:35:26 +0859
parents 6c281c9899e5
children 170fd6b81a95
line source
1 #
2 type cgiinit >/dev/null 2>&1 || . ./s4-funcs.sh
4 blog_genform() {
5 #
6 t=$1
7 }
9 blog_writable() (
10 # $1=articleid $2=user
11 blogowner=`getvalbyid blog owner "$1"`
12 [ x"$blogowner" = x"$2" ] || isuser "$blogowner" || ismember "$2" "$blogowner"
13 )
14 blog_readable() {
15 # $1=articleid $2=user
16 mode=`getgroupattr $grp regmode`
17 }
18 blog_notify_reply() (
19 # $1=blogid $2=ReplyingUser $3=WrittenText $4(optional)=Action
20 blogowner=`getvalbyid blog owner "$1"`
21 [ x"$2" = x"$blogowner" ] && return # If author=blogowner, unnecessary
22 blogtitle=`getvalbyid blog title "$1"`
23 blogurl="$urlbase?replyblog+$1"
24 action=${4:-書き込み}
25 mode=`getvalbyid blog notify "$1"`
26 ### EXCEPT=`sqlquote "$user"` ## User should receive to feal some annoyance
27 case $mode in
28 admin)
29 if isgroup "$blogowner"; then
30 emails=`getgroupadminmails $blogowner`
31 else
32 emails=`collectemail $blogowner`
33 fi
34 notifyto=`getpar notifyto`
35 if [ -n "$notifyto" ]; then
36 emails=$emails" `email4groupbyuid \"$blogowner\" $notifyto`"
37 fi
38 ;;
39 no) return ;;
40 *) team=`query "SELECT val FROM blog_s
41 WHERE id=(SELECT id FROM blog WHERE rowid=$1)
42 AND key='team';"`
43 # team cannot get `getvalbyid blog team "$1"` because it's not
44 # defined in blog.def. Yes, it is Illegal USE!!
45 emails=`TEAM=$team collectemail $blogowner` ;;
46 esac
47 err notify: user=$user Admins=`getgroupadmins $blogowner` Mode=$mode Emails="[$emails]"
48 SMAIL_TO="`echo "$blogowner" | nkf -jM | tr -d '\n'` readers <$admin>" \
49 smail "$emails" "${action}通知 $urlbase"<<EOF
50 [$blogtitle]板に${action}がありました。
51 場所: $blogurl
52 題目: $blogtitle
53 筆者: `gecos $2`
54 内容:
55 `echo "$3"|sed 's/^/> /'`
56 EOF
57 )
59 blog_showentry() {
60 # $1=table $2=rowid
61 # if [ -n "$2" ]; then
62 # if [ -n "$imgcached" ]; then
63 # bstmpdir=$tmpdir/$imgcached/$thumbxy
64 # else
65 # bstmpdir=$tmpd
66 # # tmpd=`mktempd`
67 # # tmpfiles=$tmpfiles" $tmpd"
68 # fi
69 # fi
70 td=`getcachedir "article/$2"`
71 [ -d "$td" ] || mkdir -p $td
72 tbl=${1%%[!A-Z0-9a-z_]*} rowid=${2%%[!A-Z0-9a-z_]*}
73 err rowid=$rowid, '$2'=$2
74 ts=${tbl}_s tm=${tbl}_m
75 at=article as=article_s am=article_m
76 serial=$(($(date +%s)-1420038000))s$$
77 blog_writable $rowid $user && iswritable=true || iswritable=false
78 # This function grasps blog entry definiton directly.
79 # blog: id
80 # blog_s: title,ctime,heading
81 # blog_m: *article
83 # 2015-10-05 check readable
84 if ! $iswritable; then
85 blogowner=`getvalbyid blog owner "$2"`
86 # err blogowner=$blogowner
87 if isgroup $blogowner; then
88 regmode=`getgroupattr $blogowner regmode`
89 # err regmode=$regmode
90 if [ x"$regmode" = x"moderated" ]; then
91 if ! ismember $user $blogowner; then
92 echo "加入してからどうぞ" | html p
93 return
94 fi
95 fi
96 fi
97 fi
98 case `getvalbyid blog notify "$2"` in # "all", "admin" or "no" (or NULL)
99 admin) notifyto=1 ;;
100 *) notifyto="" ;;
101 esac
103 err "SELECT id from $tbl where rowid=$rowid"
104 id=`query "select id from $tbl where rowid=$rowid;"`
105 err id=$id
106 err "select val from $ts where key='title' and id='$id';"
109 #(1)Display root article
110 cat<<EOF
111 <form class="replyblog" action="$myname?replyblog+${rowid}#bottom" method="POST" enctype="multipart/form-data">
112 <table class="bloghead">
113 EOF
115 href="<a href=\"?editheading+$rowid\"> 編集 </a>"
116 if $iswritable; then
117 href2="<a href=\"?lshandout+$rowid\"> 提出状況 </a>"
118 href3="(<a href=\"?gethandout+$rowid\">ファイル取得</a>)"
119 fi
120 href4='<a href="#bottom"> 末尾へ</a>'
122 query<<-EOF |
123 SELECT coalesce((SELECT "yes" FROM blog
124 WHERE rowid=$rowid AND author='$user'),
125 ''),
126 max(CASE key WHEN 'ctime' THEN val END) ctime,
127 max(CASE key WHEN 'heading' THEN hex(val) END) heading,
128 CASE (SELECT val FROM $ts WHERE key="mode" AND id="$id")
129 WHEN 'report-closed' THEN 'レポート提出用(closed)'
130 WHEN 'report-open' THEN 'レポート提出用(open)'
131 ELSE ''
132 END
133 FROM $ts WHERE id='$id' GROUP BY id;
134 EOF
135 { IFS='|' read edit ctime hexhead blogtype
136 cat<<-EOF
137 <tr><td>${edit:+$href }$ctime $blogtype $href2$href3 $href4</td></tr>
138 <tr class="preface">
139 <td>`echo "$hexhead"|unhexize|hreflink|minitbl`</td></tr>
140 </table>
142 <table class="blog_replies">
143 EOF
144 }
145 lkhome="<a href=\"$myname?home" lke='">'
146 lkedit="<a href=\"$myname?editart"
147 hlink="$myname?home" elink="$myname?editart"
148 catlink="$myname?showattc+article_m"
149 deficon="img/file-icon.png"
150 # 2016-08-15 Newer flag introduced
151 atime=`query "SELECT time FROM acclog
152 WHERE tbl='blog' AND tblrowid=$rowid AND user='$user';"`
153 sq $db<<EOF |
154 WITH a_s AS (
155 SELECT id,
156 max(CASE key WHEN 'ctime' THEN val END) TIME,
157 max(CASE key WHEN 'text' THEN val END) TEXT
158 FROM article_s
159 GROUP by id
160 )
161 SELECT a.id,
162 CASE author
163 WHEN '$user' THEN a.rowid||'+'||$rowid
164 ELSE ''
165 END edit,
166 CASE -- 「通知送信」ボタンの有無
167 WHEN '$notifyto' = '' THEN '' -- 不要モードならなし
168 WHEN '$user' = author THEN '' -- 筆者自身ならなし
169 ELSE "yes"
170 END notify,
171 (SELECT rowid FROM user WHERE name=author) user_rid,
172 coalesce((SELECT val FROM user_s
173 WHERE name=author AND key='gecos'),
174 author) uname,
175 a.rowid,
176 s.TIME,
177 CASE WHEN s.TIME > '$atime' THEN 'new' ELSE '' END newer,
178 hex(s.TEXT),
179 (SELECT group_concat(rowid||':'||length(bin)||':'||hex(val), ' ')
180 FROM article_m
181 WHERE id=a.id AND key='image') imxgids
182 FROM (select rowid,id,author from article where blogid in
183 (select id from blog where rowid=$rowid)) a
184 LEFT JOIN
185 a_s s
186 ON a.id=s.id;
187 EOF
188 while IFS='|' read id edit notify uid uname aid tm new hte imgids; do
189 nt="<label style=\"font-size: 70%;\"><input type=\"checkbox\"
190 name=\"notifyto\" value=\"$uid\">返信通知送信</label>"
191 cat<<EOF
192 <tr id="$id">
193 <td${new:+ class="new"}>${edit:+<a href="$elink+$edit">編集</a> }#$aid
194 <a href="$hlink+$uid">$uname</a>
195 $tm
196 ${notify:+$nt}</td>
197 EOF
198 echo -n "<td id=\"$aid\" class=\"repl\">"
199 echo "$hte"|unhexize|htmlescape|hreflink|minitbl
200 usecache='' tsfile=$td/$id.stamp
201 for i in $imgids; do
202 mrid=${i%%:*}; i=${i#*:}; sz=`size_h ${i%%:*}`
203 fn=`echo "${i#*:}"|unhexize`
204 fnb=$fn"(${sz})"
205 # echo r=$mrid fn=$fn
206 case "$fn" in
207 *.[Pp][Nn][Gg]|*.[Jj][Pp][Gg]|*.[Jj][Pp][Ee][Gg]|*.[Gg][Ii][Ff])
208 # fmt=${fn##*.} # convert - jpg:- is slow...why
209 case "$fn" in
210 *.[Pp][Nn][Gg]) fmt=png ;;
211 *.[Gg][Ii][Ff]) fmt=gif ;;
212 *) fmt=jpeg ;;
213 esac
214 outfile=$td/$mrid-${fn%.*}.$fmt
215 #err fn=$fn outfile=$outfile
216 #err "usecache=$usecache `ls -l $outfile`"
217 #err tm=$tm
218 #err tsfile=$tsfile=`cat $tsfile`
219 if [ -s $outfile ] && # $outfile should be > 0
220 { [ "$usecache" ] || # And usecache flag is true, or...
221 { [ -s "$tsfile" ] && [ x"`cat $tsfile`" = x"$tm" ]
222 };}; then
223 # err Set usecache=1
224 usecache=1 # Set usecache flag on
225 cat<<-EOF
226 <a href="$catlink+$mrid"><img src="$outfile">
227 $fnb</a>
228 EOF
229 else
230 query "SELECT hex(bin) FROM article_m WHERE rowid=$mrid;" \
231 | unhexize \
232 | convert -define ${fmt}:size=100x100 -resize 100x100'>' \
233 - ${fmt}:- \
234 | tee "$outfile" \
235 | hexize \
236 | sed -e 's/\(..\)/%\1/g' \
237 -e "s|^|<a href=\"$catlink+$mrid\"><img src=\"data:image/$fmt,|" \
238 -e "s|\$|\">$fnb</a>|"
239 # [ -d $td ] || mkdir -p "$td"
240 echo $tm > $tsfile
241 fi
242 ;;
243 *)
244 echo "<a href=\"$catlink+$mrid\"><img src=\"$deficon\">$fnb</a>"
245 ;;
246 esac
247 done
248 echo "</td></tr>"
249 done
251 textform='<div class="fold">
252 <input type="checkbox" id="cmt" checked><label for="cmt"
253 >コメントする</label><div>
254 <table class="b">
255 <tr><td><textarea name="text" cols="72" rows="4"></textarea></td></tr>
256 <tr><td>添付ファイル:
257 <input type="file" name="image"'" $file_accept multiple></td></tr>"'
258 </table>
259 <input type="submit" value="送信">
260 <input type="reset" value="リセット"></div></div>
261 '
262 cat<<-EOF
263 </table> <!-- end of s4-blog:blog_showentry() main table -->
264 <p class="update_link"><a
265 href="?reload/$rowid">再読込</a></p>
266 EOF
267 query<<-EOF
268 WITH mrt AS (
269 SELECT max(val) maxtime FROM article_s
270 WHERE key='ctime' AND id IN
271 (SELECT id FROM article
272 WHERE blogid=(select id from blog where rowid=$id))
273 )
274 SELECT 'A:'||
275 (SELECT count(*) FROM tblaccesses
276 WHERE tbl='blog' AND tblrowid=$id) access,
277 'C:'||
278 (SELECT count(distinct user) FROM acclog
279 WHERE tbl='blog' AND tblrowid=$id
280 AND time > (SELECT maxtime from mrt)
281 AND user IN
282 (SELECT user FROM grp_mem
283 WHERE gname = $(sqlquote "$blogowner")))
284 ;
285 EOF
286 $iswritable && cat<<-EOF
287 <div class="blogcomment">
288 <input type="hidden" name="blogid" value="$id">
289 <input type="hidden" name="id" value="`genserial`">
290 <input type="hidden" name="stage" value="replyblog">
291 $textform
292 </div>
293 </form> <!-- End of s4-blog:blog_showentry() main form -->
294 <p id="bottom"> </p>
295 EOF
296 # Record access log
297 acclog blog $rowid
298 }
300 lshandout() {
301 # $1=rowid of blog
302 if ! blog_writable $1 $user; then
303 echo "メンバー以外は利用できません。" | html p; return
304 fi
305 time=`getvalbyid blog ctime $1|colrm 11`
306 owner=`getvalbyid blog owner $1`
307 title=`getvalbyid blog title $1`
308 ge=`gecos $owner`
309 lshandoutsub $owner "$@" \
310 |_m4 -D_TITLE_="提出状況" \
311 -D_FORMHEAD_="$time [$title]@${ge:-$owner}" \
312 -D_FORM_="syscmd(cat)" -D_DUMPHEAD_= -D_DUMPTABLE_= \
313 $layout/html.m4.html $layout/form+dump-whead.m4.html
314 }
315 lshandoutsub() {
316 # $1=owner $2=rowid of blog
317 if isgroup $1; then
318 sample="(select user from grp_mem where gname='$1')"
319 else
320 sample="(select distinct author as user from arts)"
321 echo "(集計は板への投稿者のみ)" | html p
322 fi
323 sql="with arts as (select id,author from article \
324 where blogid=(select id from blog where rowid=$2))\
325 select (select rowid from user where name=c0.user)||' '|| \
326 coalesce((select val from user_s where name=c0.user \
327 and key='gecos'),\
328 c0.user) as 'メンバー',\
329 sum(case when c1.key is not null then 1 else 0 end)\
330 as 'コメント記入',\
331 sum(case when c2.key is not null then 1 else 0 end)\
332 as 'ファイルの提出'\
333 from $sample c0 \
334 left join (select id,author from arts) a\
335 on c0.user=a.author\
336 left join (select id,key from article_s where key='text') c1\
337 on a.id=c1.id left join (select id,key from article_m ) c2\
338 on c1.id=c2.id group by c0.user order by c0.user;"
339 err ishandoutsub: sql="$sql"
340 echo '<table class="b td2r td3r">'
341 hrb="<a href=\"?home+"
342 echo "$sql" | sq -header -html $db \
343 | sed -e "s,\(<TR><TD>\)\([^ ]*\) \(.*\)</TD>,\1$hrb\2\">\3</TD>," -e 's,<TD>0</TD>,<TD class="warn">0</TD>,'
344 echo '</table>'
345 }
346 gethandout() {
347 # $1=rowid of blog
348 if ! blog_writable $1 $user; then
349 echo "メンバー以外は利用できません。" | html p; return
350 fi
351 i=0
352 bd=$tmpd/archive.$$
353 mkdir $bd
354 query "select m.rowid,author,m.val from article a join article_m m\
355 on a.id=m.id where blogid=(select id from blog where rowid=$1)\
356 and m.key in ('image', 'document', 'binary');" \
357 | while IFS='|' read rowid author filename; do
358 # err isfilereadable $user article_m $rowid
359 isfilereadable $user article_m $rowid || continue
360 # err ok
361 i=$((i+1))
362 dir=`printf $bd/%03d $i`
363 mkdir $dir
364 query "select quote(bin) from article_m where rowid=$rowid;" \
365 | unhexize > $dir/$filename
366 done
367 if [ ! -d $bd/001 ]; then
368 contenttype; echo
369 echo "取得できるファイルがありませんでした。" | html p
370 return
371 fi
372 (cd $bd
373 err cdto$bd; (pwd; ls -lFa) 1>&3
374 tar zcf .archive.tar.gz * && mv .archive.tar.gz archive.tar.gz
375 )
376 arc=$bd/archive.tar.gz
377 echo "Content-type: application/x-gzip"
378 echo "Content-Length: `cat $arc|wc -c`"
379 echo "Content-Disposition: filename=\"archive.tar.gz\""
380 echo
381 cat $arc
382 }
383 lsmyfile() { # $1(optional)=SortBy
384 case "$1" in
385 ""|CTIME-DESC)
386 by="CTIME" ord="DESC" ;;
387 CTIME*) by="CTIME" ;;
388 FILE*) by="FILE" ;;
389 OWNER*) by="OWNER" ;;
390 TITLE*) by="TITLE" ;;
391 esac
392 case "$1" in
393 *DESC) ord="DESC" ;;
394 esac
395 case "$ord" in
396 DESC) lkod="" jord="降順" ;;
397 *) lkod="-DESC" jord="昇順" ;;
398 esac
399 sql="select m.val||'/'||m.rowid FILE,
400 coalesce(
401 case when (select name from user where name=bs.owner)
402 is not null
403 then (select val from user_s where name=bs.owner
404 and key='gecos')
405 when (select gname from grp where gname=bs.owner)
406 is not null
407 then (select val from grp_s where gname=bs.owner
408 and key='gecos')
409 else
410 null
411 end,
412 bs.owner
413 ) OWNER,
414 a_s.val CTIME,
415 ',t,'||bs.title||':'||b.rowid||'#'||a.id TITLE
416 from (select rowid,id,val from article_m where id
417 in (select id from article where author='$user')
418 and type like 'file:%')
419 m left join article a on m.id=a.id
420 left join article_s a_s on a.id=a_s.id and a_s.key='ctime'
421 left join (select id,
422 max(case key when 'owner' then val end) as owner,
423 max(case key when 'title' then val end) as title
424 from blog_s group by id)
425 bs on a.blogid=bs.id
426 left join blog b on bs.id=b.id
427 where m.val is not null order by $by $ord;"
428 err lshandoutbyauthor: sql=`echo "$sql"`
429 title="個人提出ファイル"
430 _m4 -D_TITLE_=$title $layout/html.m4.html
431 hra="<a href=\"?lsmyfile+"
432 hrb="<a href=\"?showattc+article_m+"
433 hrc="<a href=\"?replyblog+"
434 (echo '<table class="b">'
435 echo "$sql"|sq -html -header $db ) \
436 | sed -e "s|\(<TR><TD>\)\([^/]*\)/\([0-9]*\)|\1$hrb\3\">\2</a>|" \
437 -e "s|,t,\(.*\):\([^<]*\)\(</TD>\)|$hrc\2\">\1</a>\3|" \
438 -e "s|\(<TH>\)\([A-Z]*\)\(</TH>\)|\1$hra\2$lkod\">\2</a>|" \
439 | _m4 -D_TITLE_=$title -D_FORM_="<p>($by$jord)</p>" \
440 -D_DUMPTABLE_="syscmd(cat)" $layout/form+dump.m4.html
441 echo '</table>'
442 }
443 searchart() {
444 kwd=`getpar kwd|nkf -wZ1` # Convert Zenkaku-SPC to ASCII-SPC
445 kwdgrp=""
446 if [ -z "$kwd" ]; then
447 echo "検索語を指定してください" | html p; return
448 fi
449 if expr x"$kwd" : 'x#[1-9][0-9]*$' >/dev/null 1>&2; then
450 # Like '#1234', assume as artID
451 rowid=$((${kwd#\#} + 0)) # Force to be a number
452 kc="a.rowid = $rowid"
453 else
454 for k in `echo "$kwd" | sed "s/'/''/g"`; do
455 if expr x"$k" : 'x@[1-9][][0-9]*-[][0-9:-]*$' >/dev/null 1>&2; then
456 # Like '@2016-10-10', expands to "s.ctime GLOB '@2016-10-10'"
457 ctime=${k#@}
458 # Not sure GROUP BY a.blogid is comfortable for searchers...?
459 kc=$kc${kc:+" AND "}"s.ctime GLOB '${ctime}*'"
460 ##### kwdgrp=" GROUP BY a.blogid"
461 else
462 kc=$kc${kc:+" AND "}"s.text LIKE '%$k%'"
463 fi
464 done
465 fi
466 echo kc=$kc
467 kwd=`echo "$kwd"|htmlescape`
468 owner=`getpar owner`
469 owner=${owner:-$1}
470 echo "「$kwd」による検索結果" | html p
471 if [ -n "$owner" ]; then
472 cond="where key='owner' and val='$owner'"
473 if isuser $owner; then
474 echo "(`linkhome $owner` さんの記録からの検索)" | html p
475 else
476 linkhome $owner 1>&3
477 echo "(`linkhome $owner` グループからの検索)" | html p
478 fi
479 fi
480 # article_s: id=article-id, key='text', val='TEXT'
481 # article: id=article-id, blogid=blogkd
482 # blog: id=blog-id, author=LeaderAuthor
483 # blog_s: id=blog-id, key='title', val='BLOG-TITLE'
484 # WANT: blog-ROWid,article-id,val(TEXT)
485 sql="`sql4readableblogs` -- Extract user-readable blogs
486 SELECT b.rid||'#'||x.id as '',
487 b.title as TITLE,
488 substr(x.ctime, 0, 11) as DATE,
489 substr(x.text, 0, 78) as TEXT
490 FROM (SELECT blg.rid,blg.*,bs.val as title
491 FROM readableblogs blg JOIN blog_s bs
492 ON blg.id=bs.id AND bs.key='title') b
493 JOIN
494 (SELECT a.id,
495 a.blogid,
496 s.ctime,
497 s.text
498 FROM article a
499 JOIN
500 (SELECT id, /* Create [id, ctime, text] from article_s */
501 max(CASE key WHEN 'ctime' THEN val END) ctime,
502 max(CASE key WHEN 'text' THEN val END) text
503 FROM article_s GROUP BY id) s
504 ON a.id=s.id WHERE $kc$kwdgrp)
505 x ON b.id=x.blogid
506 WHERE b.id IN (SELECT id FROM blog_s $cond)
507 ORDER by x.ctime DESC;"
508 sedopt="s,<TR><TD>\([^<]*\)</TD>,<TR><TD><a\
509 href=\"?replyblog+\1\">VIEW</a></TD>,"
511 cat<<EOF
512 <table class="b searchart">
513 `sq -header -html $db "$sql"|sed "$sedopt"`
514 </table>
515 EOF
516 }
517 listblog() (
518 # $1={user,group}
519 qow=`sqlquote $1`
520 cond="where a.id in (select id from blog_s where key='owner' and val=$qow) order by ctime desc"
521 DT_CHLD=article:blogid
522 cgi_form searchart<<EOF
523 <label>`cgi_text kwd`という語を含む記事をこの一覧から検索</label>
524 `cgi_hidden owner $user`
525 EOF
526 dumptable html blog 'ctime title heading' "$cond"
527 )
529 blog_addentry() {
530 # $1=GRPname(if it is a group)
531 grprowid=$1
532 rowid=`getpar rowid`
533 err blog_addentry0: rowid=$rowid
534 if [ -n "$grprowid" ]; then
535 owner=`getgroupbyid $grprowid`
536 else
537 owner=`getpar owner`
538 fi
539 err blog-add: \$1=$1 rowid=$rowid owner=$owner
540 if isgroup $owner; then
541 groupmode=1 listing=$owner guide="[${owner}]" GF_OWNER=$owner
542 else
543 usermode=1 listing=$user guide="[個人]"
544 fi
546 if [ -n "`getpar title`" ]; then
547 if [ "$usermode" ]; then
548 err usermode: user=$user owner=$owner
549 if [ x"$user" != x"$owner" ]; then
550 echo "他人の日記は書けません" | html p
551 return 2
552 fi
553 elif [ "$groupmode" ]; then # if write to group log
554 grp=$owner #\`getpar grp\`
555 err ismember: $user $grp
556 if ! ismember "$user" "$grp"; then
557 echo "(話題作成はこのグループに加入してから)" | html p
558 return 3
559 fi
560 fi
561 par2table $formdir/blog.def
562 serial=`getpar serial`
563 err SERIAL: $serial ROWID=$rowid listing=$listing
564 id=""
565 if [ -n "$rowid" ]; then
566 # Here, id becomes NULL when removal of entries at par2table
567 id=`query "select rowid from blog where rowid=$rowid;"`
568 elif [ -n "$serial" ]; then
569 # If new blog leader created, traverse to its head.
570 id=`query "select rowid from blog where id='$serial';"`
571 err new-Leader: "select rowid from blog where id='$serial';" id=$id
572 fi
573 if [ -n "$id" ]; then
574 ## If new aritcle is entered, JUMP to blog_reply
575 blog_reply $id
576 return
577 fi
578 fi
579 echo "${guide}新規話題作成" > $tmpd/title.$$
580 listblog $listing > $tmpd/listblog.$$
581 genform $formdir/blog.def \
582 | _m4 -D_TITLE_="spaste(\`$tmpd/title.$$')" \
583 -D_FORMHEAD_="序文は簡単に詳しくはコメントに" \
584 -D_DUMPHEAD_="これまでの蓄積" \
585 -D_FORM_="syscmd(\`cat')" \
586 -D_DUMPTABLE_="spaste(\`$tmpd/listblog.$$')" \
587 $layout/html.m4.html \
588 $layout/form+dump-whead.m4.html
589 }
591 blog_reply() {
592 rowid=$1
593 err rowid=$1
595 if [ -z "$rowid" ]; then
596 echo "表示する日記番号が未指定です。" | html p
597 return
598 fi
599 title=`getvalbyid blog title $rowid`
600 owner=`getvalbyid blog owner $rowid`
601 if isuser "$owner"; then
602 subtitle="`gecos $owner` さんの話題"
603 else
604 grprowid=`query "select rowid from grp where gname=\"$owner\";"`
605 subtitle="グループ <a href=\"?grp+$grprowid\">$owner</a> での話題
606 `query \"SELECT printf('(チーム:%s)', val)\
607 FROM blog_s
608 WHERE id=(SELECT id FROM blog WHERE rowid=$rowid)
609 AND key='team';
610 \"|htmlescape`"
611 memclass=`grp_getbodyclass "$owner"`
612 fi
613 if [ -z "$title" ]; then
614 echo "日記番号指定が無効です。" | html p
615 return
616 fi
618 text=`getpar text`
619 if [ -n "$text" ]; then
620 if blog_writable $rowid $user; then
621 par2table $formdir/article.def
622 st=$? # ; err par2t-st=$st
623 case $st in
624 0|4)
625 [ "$st" = "4" ] && act="書込削除"
626 blog_notify_reply $rowid $user "$text" $act ;;
627 esac
628 else
629 title="$title(加入してないので書き込み不可)"
630 fi
631 fi
632 def=$formdir/article.def
633 echo "$title" > $tmpd/title.$$
634 echo "$subtitle" > $tmpd/subtitle.$$
635 ${BLOG_SHOW:-blog_showentry} blog $rowid \
636 | _m4 -D_TITLE_="spaste(\`$tmpd/title.$$')" \
637 -D_BODYCLASS_=general"${memclass:+ $memclass}" \
638 -D_FORMHEAD_="spaste(\`$tmpd/subtitle.$$')" \
639 -D_FORM_='' \
640 -D_DUMPTABLE_="syscmd(cat)" -D_DUMPHEAD_="" \
641 $layout/html.m4.html $layout/form+dump-whead.m4.html
642 }