s4

view s4-blog.sh @ 336:08165f6b7828

Searching into file names cause JOIN failure,... disabled.
author HIROSE Yuuji <yuuji@gentei.org>
date Sat, 22 Oct 2016 00:39:53 +0859
parents a120ba2d719b
children 48d0b6c4de65
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 iconcleaner=$tmpd/iconcleaner.$$
154 sq $db<<EOF |
155 WITH a_s AS (
156 SELECT id,
157 max(CASE key WHEN 'ctime' THEN val END) TIME,
158 max(CASE key WHEN 'text' THEN val END) TEXT
159 FROM article_s
160 GROUP by id
161 )
162 SELECT a.id,
163 CASE author
164 WHEN '$user' THEN a.rowid||'+'||$rowid
165 ELSE ''
166 END edit,
167 CASE -- 「通知送信」ボタンの有無
168 WHEN '$notifyto' = '' THEN '' -- 不要モードならなし
169 WHEN '$user' = author THEN '' -- 筆者自身ならなし
170 ELSE "yes"
171 END notify,
172 (SELECT rowid FROM user WHERE name=author) user_rid,
173 coalesce((SELECT val FROM user_s
174 WHERE name=author AND key='gecos'),
175 author) uname,
176 (SELECT val FROM user_s WHERE name=author AND key='$iconcachekey')
177 icon,
178 a.rowid,
179 s.TIME,
180 CASE WHEN s.TIME > '$atime' THEN 'new' ELSE '' END newer,
181 hex(s.TEXT),
182 (SELECT group_concat(rowid||':'||length(bin)||':'||hex(val), ' ')
183 FROM article_m
184 WHERE id=a.id AND key='image') imxgids
185 FROM (select rowid,id,author from article where blogid in
186 (select id from blog where rowid=$rowid)) a
187 LEFT JOIN
188 a_s s
189 ON a.id=s.id;
190 EOF
191 while IFS='|' read id edit notify uid uname icon aid tm new hte imgids; do
192 nt="<label style=\"font-size: 70%;\"><input type=\"checkbox\"
193 name=\"notifyto\" value=\"$uid\">返信通知送信</label>"
194 tdcls="repatt${new:+ new}"
195 imgdir=`getcachedir home/"$uid"`/main
196 if [ -n "$icon" -a -s "$icon" ]; then
197 icfn=`echo "$icon"|htmlescape`
198 picon="<p class=\"proficon\"><a href=\"$hlink+$uid\"><img src=\"$icfn\"></a></p>"
199 else
200 picon=""
201 if [ -n "$icon" ]; then
202 echo "DELETE FROM user_s WHERE key='$iconcachekey' AND
203 val=`sqlquotestr \"$icon\"`;" >> $iconcleaner
204 fi
205 fi
207 cat<<EOF
208 <tr id="$id">
209 <td class="$tdcls">$picon${edit:+<a href="$elink+$edit">編集</a> }#$aid
210 <a href="$hlink+$uid">$uname</a>
211 $tm
212 ${notify:+$nt}</td>
213 EOF
214 echo -n "<td id=\"$aid\" class=\"repl\">"
215 echo "$hte"|unhexize|htmlescape|hreflink|minitbl
216 usecache='' tsfile=$td/$id.stamp
217 for i in $imgids; do
218 mrid=${i%%:*}; i=${i#*:}; sz=`size_h ${i%%:*}`
219 fn=`echo "${i#*:}"|unhexize`
220 fnb=$fn"(${sz})"
221 # echo r=$mrid fn=$fn
222 case "$fn" in
223 *.[Pp][Nn][Gg]|*.[Jj][Pp][Gg]|*.[Jj][Pp][Ee][Gg]|*.[Gg][Ii][Ff])
224 # fmt=${fn##*.} # convert - jpg:- is slow...why
225 case "$fn" in
226 *.[Pp][Nn][Gg]) fmt=png ;;
227 *.[Gg][Ii][Ff]) fmt=gif ;;
228 *) fmt=jpeg ;;
229 esac
230 outfile=$td/$mrid-${fn%.*}.$fmt
231 #err fn=$fn outfile=$outfile
232 #err "usecache=$usecache `ls -l $outfile`"
233 #err tm=$tm
234 #err tsfile=$tsfile=`cat $tsfile`
235 if [ -s "$outfile" ] && # $outfile should be > 0
236 { [ "$usecache" ] || # And usecache flag is true, or...
237 { [ -s "$tsfile" ] && [ x"`cat $tsfile`" = x"$tm" ]
238 };}; then
239 # err Set usecache=1
240 usecache=1 # Set usecache flag on
241 cat<<-EOF
242 <a href="$catlink+$mrid"><img src="$outfile">
243 $fnb</a>
244 EOF
245 else
246 query "SELECT hex(bin) FROM article_m WHERE rowid=$mrid;" \
247 | unhexize \
248 | convert -define ${fmt}:size=100x100 -resize 100x100'>' \
249 - ${fmt}:- \
250 | tee "$outfile" \
251 | hexize \
252 | sed -e 's/\(..\)/%\1/g' \
253 -e "s|^|<a href=\"$catlink+$mrid\"><img src=\"data:image/$fmt,|" \
254 -e "s|\$|\">$fnb</a>|"
255 # [ -d $td ] || mkdir -p "$td"
256 echo $tm > $tsfile
257 fi
258 ;;
259 *)
260 echo "<a href=\"$catlink+$mrid\"><img src=\"$deficon\">$fnb</a>"
261 ;;
262 esac
263 done
264 echo "</td></tr>"
265 done
267 textform='<div class="fold">
268 <input type="checkbox" id="cmt" checked><label for="cmt"
269 >コメントする</label><div>
270 <table class="b">
271 <tr><td><textarea name="text" cols="72" rows="4"></textarea></td></tr>
272 <tr><td>添付ファイル:
273 <input type="file" name="image"'" $file_accept multiple></td></tr>"'
274 </table>
275 <input type="submit" value="送信">
276 <input type="reset" value="リセット"></div></div>
277 '
278 cat<<-EOF
279 </table> <!-- end of s4-blog:blog_showentry() main table -->
280 <p class="update_link"><a
281 href="?reload/$rowid">再読込</a> / <a
282 href="#title">先頭へ</a></p>
283 EOF
284 query<<-EOF
285 WITH mrt AS (
286 SELECT max(val) maxtime FROM article_s
287 WHERE key='ctime' AND id IN
288 (SELECT id FROM article
289 WHERE blogid=(select id from blog where rowid=$id))
290 )
291 SELECT 'A:'||
292 (SELECT count(*) FROM tblaccesses
293 WHERE tbl='blog' AND tblrowid=$id) access,
294 'C:'||
295 (SELECT count(distinct user) FROM acclog
296 WHERE tbl='blog' AND tblrowid=$id
297 AND time > (SELECT maxtime from mrt)
298 AND user IN
299 (SELECT user FROM grp_mem
300 WHERE gname = $(sqlquote "$blogowner")))
301 ;
302 EOF
303 $iswritable && cat<<-EOF
304 <div class="blogcomment">
305 <input type="hidden" name="blogid" value="$id">
306 <input type="hidden" name="id" value="`genserial`">
307 <input type="hidden" name="stage" value="replyblog">
308 $textform
309 </div>
310 </form> <!-- End of s4-blog:blog_showentry() main form -->
311 <p id="bottom"> </p>
312 EOF
313 # Clean up orphaned icon cache
314 [ -s $iconcleaner ] && query < $iconcleaner
315 # Record access log
316 acclog blog $rowid
317 }
319 lshandout() {
320 # $1=rowid of blog
321 if ! blog_writable $1 $user; then
322 echo "メンバー以外は利用できません。" | html p; return
323 fi
324 time=`getvalbyid blog ctime $1|colrm 11`
325 owner=`getvalbyid blog owner $1`
326 title=`getvalbyid blog title $1`
327 ge=`gecos $owner`
328 lshandoutsub $owner "$@" \
329 |_m4 -D_TITLE_="提出状況" \
330 -D_FORMHEAD_="$time [$title]@${ge:-$owner}" \
331 -D_FORM_="syscmd(cat)" -D_DUMPHEAD_= -D_DUMPTABLE_= \
332 $layout/html.m4.html $layout/form+dump-whead.m4.html
333 }
334 lshandoutsub() {
335 # $1=owner $2=rowid of blog
336 if isgroup $1; then
337 sample="(select user from grp_mem where gname='$1')"
338 else
339 sample="(select distinct author as user from arts)"
340 echo "(集計は板への投稿者のみ)" | html p
341 fi
342 sql="with arts as (select id,author from article \
343 where blogid=(select id from blog where rowid=$2))\
344 select (select rowid from user where name=c0.user)||' '|| \
345 coalesce((select val from user_s where name=c0.user \
346 and key='gecos'),\
347 c0.user) as 'メンバー',\
348 sum(case when c1.key is not null then 1 else 0 end)\
349 as 'コメント記入',\
350 sum(case when c2.key is not null then 1 else 0 end)\
351 as 'ファイルの提出'\
352 from $sample c0 \
353 left join (select id,author from arts) a\
354 on c0.user=a.author\
355 left join (select id,key from article_s where key='text') c1\
356 on a.id=c1.id left join (select id,key from article_m ) c2\
357 on c1.id=c2.id group by c0.user order by c0.user;"
358 err ishandoutsub: sql="$sql"
359 echo '<table class="b td2r td3r">'
360 hrb="<a href=\"?home+"
361 echo "$sql" | sq -header -html $db \
362 | sed -e "s,\(<TR><TD>\)\([^ ]*\) \(.*\)</TD>,\1$hrb\2\">\3</TD>," -e 's,<TD>0</TD>,<TD class="warn">0</TD>,'
363 echo '</table>'
364 }
365 gethandout() {
366 # $1=rowid of blog
367 if ! blog_writable $1 $user; then
368 echo "メンバー以外は利用できません。" | html p; return
369 fi
370 i=0
371 bd=$tmpd/archive.$$
372 mkdir $bd
373 query "select m.rowid,author,m.val from article a join article_m m\
374 on a.id=m.id where blogid=(select id from blog where rowid=$1)\
375 and m.key in ('image', 'document', 'binary');" \
376 | while IFS='|' read rowid author filename; do
377 # err isfilereadable $user article_m $rowid
378 isfilereadable $user article_m $rowid || continue
379 # err ok
380 i=$((i+1))
381 dir=`printf $bd/%03d $i`
382 mkdir $dir
383 query "select quote(bin) from article_m where rowid=$rowid;" \
384 | unhexize > $dir/$filename
385 done
386 if [ ! -d $bd/001 ]; then
387 contenttype; echo
388 echo "取得できるファイルがありませんでした。" | html p
389 return
390 fi
391 (cd $bd
392 err cdto$bd; (pwd; ls -lFa) 1>&3
393 tar zcf .archive.tar.gz * && mv .archive.tar.gz archive.tar.gz
394 )
395 arc=$bd/archive.tar.gz
396 echo "Content-type: application/x-gzip"
397 echo "Content-Length: `cat $arc|wc -c`"
398 echo "Content-Disposition: filename=\"archive.tar.gz\""
399 echo
400 cat $arc
401 }
402 lsmyfile() { # $1(optional)=SortBy
403 case "$1" in
404 ""|CTIME-DESC)
405 by="CTIME" ord="DESC" ;;
406 CTIME*) by="CTIME" ;;
407 FILE*) by="FILE" ;;
408 OWNER*) by="OWNER" ;;
409 TITLE*) by="TITLE" ;;
410 esac
411 case "$1" in
412 *DESC) ord="DESC" ;;
413 esac
414 case "$ord" in
415 DESC) lkod="" jord="降順" ;;
416 *) lkod="-DESC" jord="昇順" ;;
417 esac
418 sql="select m.val||'/'||m.rowid FILE,
419 coalesce(
420 case when (select name from user where name=bs.owner)
421 is not null
422 then (select val from user_s where name=bs.owner
423 and key='gecos')
424 when (select gname from grp where gname=bs.owner)
425 is not null
426 then (select val from grp_s where gname=bs.owner
427 and key='gecos')
428 else
429 null
430 end,
431 bs.owner
432 ) OWNER,
433 a_s.val CTIME,
434 ',t,'||bs.title||':'||b.rowid||'#'||a.id TITLE
435 from (select rowid,id,val from article_m where id
436 in (select id from article where author='$user')
437 and type like 'file:%')
438 m left join article a on m.id=a.id
439 left join article_s a_s on a.id=a_s.id and a_s.key='ctime'
440 left join (select id,
441 max(case key when 'owner' then val end) as owner,
442 max(case key when 'title' then val end) as title
443 from blog_s group by id)
444 bs on a.blogid=bs.id
445 left join blog b on bs.id=b.id
446 where m.val is not null order by $by $ord;"
447 err lshandoutbyauthor: sql=`echo "$sql"`
448 title="個人提出ファイル"
449 _m4 -D_TITLE_=$title $layout/html.m4.html
450 hra="<a href=\"?lsmyfile+"
451 hrb="<a href=\"?showattc+article_m+"
452 hrc="<a href=\"?replyblog+"
453 (echo '<table class="b">'
454 echo "$sql"|sq -html -header $db ) \
455 | sed -e "s|\(<TR><TD>\)\([^/]*\)/\([0-9]*\)|\1$hrb\3\">\2</a>|" \
456 -e "s|,t,\(.*\):\([^<]*\)\(</TD>\)|$hrc\2\">\1</a>\3|" \
457 -e "s|\(<TH>\)\([A-Z]*\)\(</TH>\)|\1$hra\2$lkod\">\2</a>|" \
458 | _m4 -D_TITLE_=$title -D_FORM_="<p>($by$jord)</p>" \
459 -D_DUMPTABLE_="syscmd(cat)" $layout/form+dump.m4.html
460 echo '</table>'
461 }
462 searchart() {
463 kwd=`getpar kwd|nkf -wZ1` # Convert Zenkaku-SPC to ASCII-SPC
464 kwdgrp=""
465 if [ -z "$kwd" ]; then
466 echo "検索語を指定してください" | html p; return
467 fi
468 if expr x"$kwd" : 'x#[1-9][0-9]*$' >/dev/null 1>&2; then
469 # Like '#1234', assume as artID
470 rowid=$((${kwd#\#} + 0)) # Force to be a number
471 kc="a.rowid = $rowid"
472 else
473 for k in `echo "$kwd" | sed "s/'/''/g"`; do
474 if expr x"$k" : 'x@[1-9][][0-9]*-[][0-9:-]*$' >/dev/null 1>&2; then
475 # Like '@2016-10-10', expands to "s.ctime GLOB '@2016-10-10'"
476 ctime=${k#@}
477 # Not sure GROUP BY a.blogid is comfortable for searchers...?
478 kc=$kc${kc:+" AND "}"s.ctime GLOB '${ctime}*'"
479 ##### kwdgrp=" GROUP BY a.blogid" ## Add this to lessen results
480 elif [ x"$k" = x"@today" -o x"$k" = x"@今日" ]; then
481 ctime=`date +%F`
482 kc=$kc${kc:+" AND "}"s.ctime GLOB '${ctime}*'"
483 else
484 kc=$kc${kc:+" AND "}"content LIKE '%$k%'"
485 fi
486 done
487 fi
488 kwd=`echo "$kwd"|htmlescape`
489 owner=`getpar owner`
490 owner=${owner:-$1}
491 echo "「$kwd」による検索結果" | html p
492 if [ -n "$owner" ]; then
493 cond="where key='owner' and val='$owner'"
494 if isuser $owner; then
495 echo "(`linkhome $owner` さんの記録からの検索)" | html p
496 else
497 linkhome $owner 1>&3
498 echo "(`linkhome $owner` グループからの検索)" | html p
499 fi
500 elif { author=`getpar author`; test -n "$author"; }; then
501 atptn=`sqlquotestr $author`
502 kc="$kc${kc:+ AND }author=$atptn"
503 if isuser $author; then
504 echo "(`linkhome $author` さんの書き込みからの検索)" | html p
505 fi
506 fi
507 # article_s: id=article-id, key='text', val='TEXT'
508 # article: id=article-id, blogid=blogkd
509 # blog: id=blog-id, author=LeaderAuthor
510 # blog_s: id=blog-id, key='title', val='BLOG-TITLE'
511 # WANT: blog-ROWid,article-id,val(TEXT)
512 sql="`sql4readableblogs` -- Extract user-readable blogs
513 SELECT b.rid||'#'||x.id as '',
514 b.title as TITLE,
515 substr(x.ctime, 0, 11) as DATE,
516 substr(x.content, 0, 78) as TEXT
517 FROM (SELECT blg.rid,blg.*,bs.val as title
518 FROM readableblogs blg JOIN blog_s bs
519 ON blg.id=bs.id AND bs.key='title') b
520 JOIN
521 (SELECT a.id,
522 a.blogid,
523 s.ctime,
524 s.text /* || ' ' || m.filenames */ content
525 FROM article a
526 JOIN
527 (SELECT id, /* Create [id, ctime, text] from article_s */
528 max(CASE key WHEN 'ctime' THEN val END) ctime,
529 max(CASE key WHEN 'text' THEN val END) text
530 FROM article_s GROUP BY id) s
531 /*
532 JOIN
533 (SELECT id, group_concat(val) filenames
534 FROM article_m
535 WHERE type LIKE 'file:%'
536 GROUP BY id) m */
537 ON a.id=s.id /* AND a.id=m.id */ WHERE $kc$kwdgrp) x
538 ON b.id=x.blogid
539 WHERE b.id IN (SELECT id FROM blog_s $cond)
540 ORDER by DATE DESC, TITLE, x.ctime;"
541 sedopt="s,<TR><TD>\([^<]*\)</TD>,<TR><TD><a\
542 href=\"?replyblog+\1\">VIEW</a></TD>,"
544 cat<<EOF
545 <table class="b searchart">
546 `sq -header -html $db "$sql"|sed "$sedopt"`
547 </table>
548 EOF
549 }
550 listblog() (
551 # $1={user,group}
552 qow=`sqlquote $1`
553 cond="where a.id in (select id from blog_s where key='owner' and val=$qow) order by ctime desc"
554 DT_CHLD=article:blogid
555 cgi_form searchart<<EOF
556 <label>`cgi_text kwd`という語を含む記事をこの一覧から検索</label>
557 `cgi_hidden owner $user`
558 EOF
559 dumptable html blog 'ctime title heading' "$cond"
560 )
562 blog_addentry() {
563 # $1=GRPname(if it is a group)
564 grprowid=$1
565 rowid=`getpar rowid`
566 err blog_addentry0: rowid=$rowid
567 if [ -n "$grprowid" ]; then
568 owner=`getgroupbyid $grprowid`
569 else
570 owner=`getpar owner`
571 fi
572 err blog-add: \$1=$1 rowid=$rowid owner=$owner
573 if isgroup $owner; then
574 groupmode=1 listing=$owner guide="[${owner}]" GF_OWNER=$owner
575 else
576 usermode=1 listing=$user guide="[個人]"
577 fi
579 if [ -n "`getpar title`" ]; then
580 if [ "$usermode" ]; then
581 err usermode: user=$user owner=$owner
582 if [ x"$user" != x"$owner" ]; then
583 echo "他人の日記は書けません" | html p
584 return 2
585 fi
586 elif [ "$groupmode" ]; then # if write to group log
587 grp=$owner #\`getpar grp\`
588 err ismember: $user $grp
589 if ! ismember "$user" "$grp"; then
590 echo "(話題作成はこのグループに加入してから)" | html p
591 return 3
592 fi
593 fi
594 par2table $formdir/blog.def
595 serial=`getpar serial`
596 err SERIAL: $serial ROWID=$rowid listing=$listing
597 id=""
598 if [ -n "$rowid" ]; then
599 # Here, id becomes NULL when removal of entries at par2table
600 id=`query "select rowid from blog where rowid=$rowid;"`
601 elif [ -n "$serial" ]; then
602 # If new blog leader created, traverse to its head.
603 id=`query "select rowid from blog where id='$serial';"`
604 err new-Leader: "select rowid from blog where id='$serial';" id=$id
605 fi
606 if [ -n "$id" ]; then
607 ## If new aritcle is entered, JUMP to blog_reply
608 blog_reply $id
609 return
610 fi
611 fi
612 echo "${guide}新規話題作成" > $tmpd/title.$$
613 listblog $listing > $tmpd/listblog.$$
614 genform $formdir/blog.def \
615 | _m4 -D_TITLE_="spaste(\`$tmpd/title.$$')" \
616 -D_FORMHEAD_="序文は簡単に詳しくはコメントに" \
617 -D_DUMPHEAD_="これまでの蓄積" \
618 -D_FORM_="syscmd(\`cat')" \
619 -D_DUMPTABLE_="spaste(\`$tmpd/listblog.$$')" \
620 $layout/html.m4.html \
621 $layout/form+dump-whead.m4.html
622 }
624 blog_reply() {
625 rowid=$1
626 err rowid=$1
628 if [ -z "$rowid" ]; then
629 echo "表示する日記番号が未指定です。" | html p
630 return
631 fi
632 title=`getvalbyid blog title $rowid`
633 owner=`getvalbyid blog owner $rowid`
634 if isuser "$owner"; then
635 subtitle="`gecos $owner` さんの話題"
636 else
637 grprowid=`query "select rowid from grp where gname=\"$owner\";"`
638 subtitle="グループ <a href=\"?grp+$grprowid\">$owner</a> での話題
639 `query \"SELECT printf('(チーム:%s)', val)\
640 FROM blog_s
641 WHERE id=(SELECT id FROM blog WHERE rowid=$rowid)
642 AND key='team';
643 \"|htmlescape`"
644 memclass=`grp_getbodyclass "$owner"`
645 fi
646 if [ -z "$title" ]; then
647 echo "日記番号指定が無効です。" | html p
648 return
649 fi
651 text=`getpar text`
652 if [ -n "$text" ]; then
653 if blog_writable $rowid $user; then
654 par2table $formdir/article.def
655 st=$? # ; err par2t-st=$st
656 case $st in
657 0|4)
658 [ "$st" = "4" ] && act="書込削除"
659 blog_notify_reply $rowid $user "$text" $act ;;
660 esac
661 else
662 title="$title(加入してないので書き込み不可)"
663 fi
664 fi
665 def=$formdir/article.def
666 echo "$title" > $tmpd/title.$$
667 echo "$subtitle" > $tmpd/subtitle.$$
668 ${BLOG_SHOW:-blog_showentry} blog $rowid \
669 | _m4 -D_TITLE_="spaste(\`$tmpd/title.$$')" \
670 -D_BODYCLASS_=general"${memclass:+ $memclass}" \
671 -D_FORMHEAD_="spaste(\`$tmpd/subtitle.$$')" \
672 -D_FORM_='' \
673 -D_DUMPTABLE_="syscmd(cat)" -D_DUMPHEAD_="" \
674 $layout/html.m4.html $layout/form+dump-whead.m4.html
675 }