s4

view s4-blog.sh @ 166:32557aa9af94

$SMAIL_TO controls To: header value.
author HIROSE Yuuji <yuuji@gentei.org>
date Fri, 29 Jan 2016 10:59:01 +0859
parents 1ec02d6f9bf3
children fdc8008c236c
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=articleid $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 case $mode in
27 admin)
28 if isgroup "$blogowner"; then
29 emails=`getgroupadminmails $blogowner`
30 else
31 emails=`collectemail $blogowner`
32 fi
33 ;;
34 no) return ;;
35 *) emails=`collectemail $blogowner` ;;
36 esac
37 err notify: user=$user Admins=`getgroupadmins $blogowner` Mode=$mode Emails="[$emails]"
38 SMAIL_TO="$blogowner readers <$admin>" \
39 smail "$emails" "${action}通知 $urlbase"<<EOF
40 [$blogtitle]板に${action}がありました。
41 場所: $blogurl
42 題目: $blogtitle
43 筆者: `gecos $2`
44 内容:
45 `echo "$3"|sed 's/^/> /'`
46 EOF
47 )
48 blog_showentry() {
49 # $1=table $2=rowid
50 # if [ -n "$2" ]; then
51 # if [ -n "$imgcached" ]; then
52 # bstmpdir=$tmpdir/$imgcached/$thumbxy
53 # else
54 # bstmpdir=$tmpd
55 # # tmpd=`mktempd`
56 # # tmpfiles=$tmpfiles" $tmpd"
57 # fi
58 # fi
59 td=`getcachedir "article/$2"`
60 tbl=${1%%[!A-Z0-9a-z_]*} rowid=${2%%[!A-Z0-9a-z_]*}
61 err rowid=$rowid, '$2'=$2
62 ts=${tbl}_s tm=${tbl}_m
63 at=article as=article_s am=article_m
64 serial=$(($(date +%s)-1420038000))s$$
65 blog_writable $rowid $user && iswritable=true || iswritable=false
66 # This function grasps blog entry definiton directly.
67 # blog: id
68 # blog_s: title,ctime,heading
69 # blog_m: *article
71 # 2015-10-05 check readable
72 if ! $iswritable; then
73 blogowner=`getvalbyid blog owner "$2"`
74 # err blogowner=$blogowner
75 if isgroup $blogowner; then
76 regmode=`getgroupattr $blogowner regmode`
77 # err regmode=$regmode
78 if [ x"$regmode" = x"moderated" ]; then
79 if ! ismember $user $blogowner; then
80 echo "加入してからどうぞ" | html p
81 return
82 fi
83 fi
84 fi
85 fi
87 err "SELECT id from $tbl where rowid=$rowid"
88 id=`query "select id from $tbl where rowid=$rowid;"`
89 err id=$id
90 err "select val from $ts where key='title' and id='$id';"
93 #(1)Display root article
94 cat<<EOF
95 <form class="replyblog" action="$myname?replyblog+${rowid}#bottom" method="POST" enctype="multipart/form-data">
96 <table class="bloghead">
97 EOF
99 href="<a href=\"?editheading+$rowid\"> 編集 </a>"
100 if $iswritable; then
101 href2="<a href=\"?lshandout+$rowid\"> 提出状況 </a>"
102 href3="(<a href=\"?gethandout+$rowid\">ファイル取得</a>)"
103 fi
104 cat<<EOF | sq -html $db \
105 | sed -e "s|\(<TR><TD>\),e,|\1 $href |" \
106 -e "s|,s,\(</TD>\)|$href2$href3\1|"
107 -- select val from $ts where key="title" and id="$id";
108 select
109 coalesce((select ",e," from blog where rowid=$rowid and author='$user'),'')
110 ||val||" "
111 ||case (select val from $ts where key="mode" and id="$id")
112 when 'report-closed' then "レポート提出用(自身のファイルのみ参照可),s,"
113 when 'report-open' then "レポート提出用,s,"
114 else ""
115 end
116 from $ts where key="ctime" and id="$id";
117 select val from $ts where key="heading" and id="$id";
118 EOF
119 cat<<EOF
120 </table>
121 <table class="blog_replies">
122 EOF
124 #(2)Display following articles
125 textform='<div><table class="b">
126 <tr><td><textarea name="text" cols="40" rows="4"></textarea></td></tr>
127 <tr><td>添付ファイル: <input type="file" name="image" multiple></td></tr>
128 </table>
129 <input type="submit" value="送信">
130 <input type="reset" value="リセット"></div>
131 '
132 ## 6/11の次: articleを出して行く
133 : <<EOF
134 シリアル:id:p:serial:
135 blogID:blogid:f:blog(id):
136 筆者:author:s:owner
137 時刻:ctime:s:stamp:
138 参照元:parent:s:parent:
139 パス:path:s:path:
140 本文:text:s:textarea:cols="60" rows="8"
141 画像:image:m:image:
142 stage:stage:x:hidden:value="replyblog"
144 article(id, blogid, author)
145 article_s: Visible = ctime, text Invisible = parent, path
146 article_m: image
148 article = hoge|1433812374x20849|yuuji@gentei.org
149 article_s = hoge|ctime|string|2015-06-13 12:27:34|
150 hoge|text|string|Shall we dance?|
151 EOF
152 ##
153 ##
154 err "select id from $at where blogid='$id';"
155 # arts=`sq $db "select a.rowid,a.id,
156 #-- coalesce(b.gecos, a.author)
157 # a.author from $at a
158 # LEFT JOIN (select name,val as gecos from user_s where key='gecos') b
159 # on a.author=b.name where blogid='$id'";`
160 arts=`query "select rowid,id,author from $at where blogid='$id';"`
161 # err arts="[$arts]"
162 number=0
163 hrefhome0="<a href=\"?home"
164 for a in $arts; do
165 arid=${a%%\|*} aid=`echo "$a"|cut -d'|' -f2` author=${a##*\|} imgs=""
166 ## err a=$a, aid=$aid, author=$author
167 ## err td=$td
168 val=`getvalbyid article image "$arid" "$td"`
169 ## err val="[$val]" and td as follows:
171 if [ -n "$val" ]; then
172 hrfb="$myname?showattc+article_m"
173 imgs="<br>"$(echo "$val"\
174 |while read fn; do
176 #data=`percenthex $td/$fn`
177 #ct=`cat $td/$fn.content-type`
178 sz=`cat $td/$fn.size`
179 ri=`cat $td/$fn.rowid`
180 ## err fn=$fn ct=$ct ri=$ri ls::: "`ls -lF $td/`"
181 iconhref2 $td/$fn "$hrfb+$ri" "$fn" "$fn($sz)"
182 echo "<br>"
183 done)
184 imgs=`echo "$imgs"|tr -d '\n'` # kill newlines for sed
185 fi
187 ### number=$((number+1))
188 # reply="<input type=\"radio\" name=\"parent\" class=\"replybtn\" \
189 # value=\"$number\">"
190 getgecos="(select rowid from user where name='$author')||':'||\
191 coalesce((select val from user_s \
192 where name='$author' and key='gecos'), '$author')||',[/a],'"
193 href="$myname?editart+$arid+$rowid"
194 link="<a href=\"$href\">編集</a>"
195 cat<<EOF | sq -html $db \
196 | sed -e "s|,n,\([0-9]*\):|,n,$hrefhome0+\1\">|" \
197 -e 's|,\[/a\],|</a>|' \
198 -e 's/,n,/<br>/g' -e "s|,i,|$imgs|" \
199 -e "s|<TR>\(<TD>\)|<TR id=\"$aid\">\1|" \
200 -e "s|^href=\([-A-Za-z0-9,.:/~_%#&+?]*\)|<a &>\1</a>|" \
201 -e "s|\(<TR.*>\)\(<TD>\),e,|\1\2$link|"
202 select
203 coalesce((select ",e," from article where id='$aid' and author='$user'),"")
204 ||
205 max(case key when 'ctime' then ",n,"||val||
206 ",n,"||$getgecos end) as TIME,
207 -- max(case key when 'parent' then val||"への返信" end) as REPLYTO,
208 max(case key when 'text' then val||",i," end) as TEXT
209 from article_s where id = '$aid'
210 group by id order by TIME;
211 EOF
212 done
213 echo "</table>"
216 $iswritable && cat<<EOF
217 <div class="blogcomment">
218 <p>コメント記入</p>
219 <input type="hidden" name="blogid" value="$id">
220 <input type="hidden" name="stage" value="replyblog">
221 <input type="hidden" name="serial" value="$serial">
222 $textform
223 </div>
224 EOF
225 echo "</form><p id=\"bottom\"></p>"
226 # Record access log
227 acclog blog $rowid
228 }
230 blog_showentry2() {
231 # $1=table $2=rowid
232 # if [ -n "$2" ]; then
233 # if [ -n "$imgcached" ]; then
234 # bstmpdir=$tmpdir/$imgcached/$thumbxy
235 # else
236 # bstmpdir=$tmpd
237 # # tmpd=`mktempd`
238 # # tmpfiles=$tmpfiles" $tmpd"
239 # fi
240 # fi
241 td=`getcachedir "article/$2"`
242 tbl=${1%%[!A-Z0-9a-z_]*} rowid=${2%%[!A-Z0-9a-z_]*}
243 err rowid=$rowid, '$2'=$2
244 ts=${tbl}_s tm=${tbl}_m
245 at=article as=article_s am=article_m
246 serial=$(($(date +%s)-1420038000))s$$
247 blog_writable $rowid $user && iswritable=true || iswritable=false
248 # This function grasps blog entry definiton directly.
249 # blog: id
250 # blog_s: title,ctime,heading
251 # blog_m: *article
253 # 2015-10-05 check readable
254 if ! $iswritable; then
255 blogowner=`getvalbyid blog owner "$2"`
256 # err blogowner=$blogowner
257 if isgroup $blogowner; then
258 regmode=`getgroupattr $blogowner regmode`
259 # err regmode=$regmode
260 if [ x"$regmode" = x"moderated" ]; then
261 if ! ismember $user $blogowner; then
262 echo "加入してからどうぞ" | html p
263 return
264 fi
265 fi
266 fi
267 fi
269 err "SELECT id from $tbl where rowid=$rowid"
270 id=`query "select id from $tbl where rowid=$rowid;"`
271 err id=$id
272 err "select val from $ts where key='title' and id='$id';"
275 #(1)Display root article
276 cat<<EOF
277 <form class="replyblog" action="$myname?replyblog+${rowid}#bottom" method="POST" enctype="multipart/form-data">
278 <table class="bloghead">
279 EOF
281 href="<a href=\"?editheading+$rowid\"> 編集 </a>"
282 if $iswritable; then
283 href2="<a href=\"?lshandout+$rowid\"> 提出状況 </a>"
284 href3="(<a href=\"?gethandout+$rowid\">ファイル取得</a>)"
285 fi
286 href4='<a href="#bottom"> 末尾へ</a>'
287 cat<<EOF | sq -html $db \
288 | sed -e "s|\(<TR><TD>\),e,|\1 $href |" \
289 -e "s|,s,|$href2$href3|" \
290 -e "s|,t,\(</TD\)>|$href4\1|"
291 -- select val from $ts where key="title" and id="$id";
292 select
293 coalesce((select ",e," from blog where rowid=$rowid and author='$user'),'')
294 ||val||" "
295 ||case (select val from $ts where key="mode" and id="$id")
296 when 'report-closed' then "レポート提出用(自身のファイルのみ参照可),s,"
297 when 'report-open' then "レポート提出用,s,"
298 else ""
299 end || ',t,'
300 from $ts where key="ctime" and id="$id";
301 select val from $ts where key="heading" and id="$id";
302 EOF
303 cat<<EOF
304 </table>
305 <table class="blog_replies">
306 EOF
308 lkhome="<a href=\"$myname?home" lke='">'
309 lkedit="<a href=\"$myname?editart"
310 if false; then
311 sq -html $db<<EOF |
312 WITH a_s AS (
313 SELECT id,
314 max(CASE key WHEN 'ctime' THEN val END) TIME,
315 max(CASE key WHEN 'text' THEN val END) TEXT
316 FROM article_s
317 GROUP by id
318 )
319 SELECT 'id:'||a.id,
320 CASE author
321 WHEN '$user' THEN 'ed:'||a.rowid||':'||$rowid
322 ELSE 'e0:'
323 END edit,
324 'at:'||(SELECT rowid FROM user WHERE name=author)||':'
325 ||coalesce((SELECT val FROM user_s
326 WHERE name=author AND key='gecos'),
327 author),
328 'ti:'||s.TIME,
329 'te:'||s.TEXT,
330 'im:'||(SELECT group_concat(hex(bin)
331 FROM (select rowid,id,author from article where blogid in
332 (select id from blog where rowid=$rowid)) a
333 LEFT JOIN
334 a_s s
335 ON a.id=s.id;
336 EOF
337 sed -e "s|^<TR><TD>id:\(.*\)</TD>|<TR id=\"\1\"><TD>|" \
338 -e "/^<TR/N" -e 's/\n//' \
339 -e "s|<TD>ed:\([0-9]*\):\(.*\)</TD>|$lkedit+\1+\2${lke}編集</a>|" \
340 -e "s|<TD>e0:</TD>||" \
341 -e "s|^<TD>at:\([0-9]*\):\(.*\)</TD>|$lkhome+\1$lke\2</a>|" \
342 -e "s|^<TD>ti:\(.*\)</TD>|\1</TD>|" \
343 -e "s|^<TD>te:\(.*\)|<TD>\1|"
344 else
345 hlink="$myname?home" elink="$myname?editart"
346 catlink="$myname?showattc+article_m"
347 deficon="img/file-icon.png"
348 sq $db<<EOF |
349 WITH a_s AS (
350 SELECT id,
351 max(CASE key WHEN 'ctime' THEN val END) TIME,
352 max(CASE key WHEN 'text' THEN val END) TEXT
353 FROM article_s
354 GROUP by id
355 )
356 SELECT a.id,
357 CASE author
358 WHEN '$user' THEN a.rowid||'+'||$rowid
359 ELSE ''
360 END edit,
361 (SELECT rowid FROM user WHERE name=author) user_rid,
362 coalesce((SELECT val FROM user_s
363 WHERE name=author AND key='gecos'),
364 author) uname,
365 s.TIME,
366 hex(s.TEXT),
367 (SELECT group_concat(rowid||':'||length(bin)||':'||hex(val), ' ')
368 FROM article_m
369 WHERE id=a.id AND key='image') imxgids
370 FROM (select rowid,id,author from article where blogid in
371 (select id from blog where rowid=$rowid)) a
372 LEFT JOIN
373 a_s s
374 ON a.id=s.id;
375 EOF
376 while IFS='|' read id edit uid uname tm hte imgids; do
377 cat<<EOF |
378 <tr id="$id">
379 <td>${edit:+<a href="$elink+$edit">編集</a>}
380 <a href="$hlink+$uid">$uname</a>
381 $tm</td><td>`echo "$hte"|unhexize|htmlescape`
382 EOF
383 sed -e "s|^href=\([-A-Za-z0-9,.:/~_%#&+?]*\)|<a &>\1</a>|"
384 for i in $imgids; do
385 mrid=${i%%:*}; i=${i#*:}; sz=`size_h ${i%%:*}`
386 fn=`echo "${i#*:}"|unhexize`
387 fnb=$fn"(${sz})"
388 # echo r=$mrid fn=$fn
389 case "$fn" in
390 *.[Pp][Nn][Gg]|*.[Jj][Pp][Gg]|*.[Jj][Pp][Ee][Gg])
391 sq $db "SELECT hex(bin) FROM article_m WHERE rowid=$mrid" \
392 | unhexize \
393 | convert -define jpeg:size=100x100 -resize 100x100'>' - jpeg:- \
394 | hexize \
395 | sed -e 's/\(..\)/%\1/g' \
396 -e "s|^|<a href=\"$catlink+$mrid\"><img src=\"data:image/jpeg,|" \
397 -e "s|\$|\">$fnb</a>|"
398 ;;
399 *)
400 echo "<a href=\"$catlink+$mrid\"><img src=\"$deficon\">$fnb</a>"
401 ;;
402 esac
403 done
404 done
405 fi
407 textform='<div><table class="b">
408 <tr><td><textarea name="text" cols="40" rows="4"></textarea></td></tr>
409 <tr><td>添付ファイル: <input type="file" name="image" multiple></td></tr>
410 </table>
411 <input type="submit" value="送信">
412 <input type="reset" value="リセット"></div>
413 '
414 echo '</table>'
416 $iswritable && cat<<EOF
417 <div class="blogcomment">
418 <p>コメント記入</p>
419 <input type="hidden" name="blogid" value="$id">
420 <input type="hidden" name="stage" value="replyblog">
421 <input type="hidden" name="serial" value="$serial">
422 $textform
423 </div>
424 EOF
425 echo "</form><p id=\"bottom\"></p>"
426 # Record access log
427 acclog blog $rowid
428 }
430 lshandout() {
431 # $1=rowid of blog
432 if ! blog_writable $1 $user; then
433 echo "メンバー以外は利用できません。" | html p; return
434 fi
435 time=`getvalbyid blog ctime $1|colrm 11`
436 owner=`getvalbyid blog owner $1`
437 title=`getvalbyid blog title $1`
438 ge=`gecos $owner`
439 lshandoutsub $owner "$@" \
440 |m4 -D_TITLE_="提出状況" \
441 -D_FORMHEAD_="$time [$title]@${ge:-$owner}" \
442 -D_FORM_="syscmd(cat)" -D_DUMPHEAD_= -D_DUMPTABLE_= \
443 $layout/html.m4.html $layout/form+dump-whead.m4.html
444 }
445 lshandoutsub() {
446 # $1=owner $2=rowid of blog
447 if isgroup $1; then
448 sample="(select user from grp_mem where gname='$1')"
449 else
450 sample="(select distinct author as user from arts)"
451 echo "(集計は板への投稿者のみ)" | html p
452 fi
453 sql="with arts as (select id,author from article \
454 where blogid=(select id from blog where rowid=$2))\
455 select (select rowid from user where name=c0.user)||' '|| \
456 coalesce((select val from user_s where name=c0.user \
457 and key='gecos'),\
458 c0.user) as 'メンバー',\
459 sum(case when c1.key is not null then 1 else 0 end)\
460 as 'コメント記入',\
461 sum(case when c2.key is not null then 1 else 0 end)\
462 as 'ファイルの提出'\
463 from $sample c0 \
464 left join (select id,author from arts) a\
465 on c0.user=a.author\
466 left join (select id,key from article_s where key='text') c1\
467 on a.id=c1.id left join (select id,key from article_m ) c2\
468 on c1.id=c2.id group by c0.user order by c0.user;"
469 err ishandoutsub: sql="$sql"
470 echo '<table class="b td2r td3r">'
471 hrb="<a href=\"?home+"
472 echo "$sql" | sq -header -html $db \
473 | sed -e "s,\(<TR><TD>\)\([^ ]*\) \(.*\)</TD>,\1$hrb\2\">\3</TD>," -e 's,<TD>0</TD>,<TD class="warn">0</TD>,'
474 echo '</table>'
475 }
476 gethandout() {
477 # $1=rowid of blog
478 if ! blog_writable $1 $user; then
479 echo "メンバー以外は利用できません。" | html p; return
480 fi
481 i=0
482 bd=$tmpd/archive.$$
483 mkdir $bd
484 query "select m.rowid,author,m.val from article a join article_m m\
485 on a.id=m.id where blogid=(select id from blog where rowid=$1)\
486 and m.key in ('image', 'document', 'binary');" \
487 | while IFS='|' read rowid author filename; do
488 # err isfilereadable $user article_m $rowid
489 isfilereadable $user article_m $rowid || continue
490 # err ok
491 i=$((i+1))
492 dir=`printf $bd/%03d $i`
493 mkdir $dir
494 query "select quote(bin) from article_m where rowid=$rowid;" \
495 | unhexize > $dir/$filename
496 done
497 if [ ! -d $bd/001 ]; then
498 contenttype; echo
499 echo "取得できるファイルがありませんでした。" | html p
500 return
501 fi
502 (cd $bd
503 err cdto$bd; (pwd; ls -lFa) 1>&3
504 tar zcf .archive.tar.gz * && mv .archive.tar.gz archive.tar.gz
505 )
506 arc=$bd/archive.tar.gz
507 echo "Content-type: application/x-gzip"
508 echo "Content-Length: `cat $arc|wc -c`"
509 echo "Content-Disposition: filename=\"archive.tar.gz\""
510 echo
511 cat $arc
512 }
513 lsmyfile() { # $1(optional)=SortBy
514 case "$1" in
515 ""|CTIME-DESC)
516 by="CTIME" ord="DESC" ;;
517 CTIME*) by="CTIME" ;;
518 FILE*) by="FILE" ;;
519 OWNER*) by="OWNER" ;;
520 TITLE*) by="TITLE" ;;
521 esac
522 case "$1" in
523 *DESC) ord="DESC" ;;
524 esac
525 case "$ord" in
526 DESC) lkod="" jord="降順" ;;
527 *) lkod="-DESC" jord="昇順" ;;
528 esac
529 sql="select m.val||'/'||m.rowid FILE,
530 coalesce(
531 case when (select name from user where name=bs.owner)
532 is not null
533 then (select val from user_s where name=bs.owner
534 and key='gecos')
535 when (select gname from grp where gname=bs.owner)
536 is not null
537 then (select val from grp_s where gname=bs.owner
538 and key='gecos')
539 else
540 null
541 end,
542 bs.owner
543 ) OWNER,
544 a_s.val CTIME,
545 ',t,'||bs.title||':'||b.rowid||'#'||a.id TITLE
546 from (select rowid,id,val from article_m where id
547 in (select id from article where author='$user')
548 and type like 'file:%')
549 m left join article a on m.id=a.id
550 left join article_s a_s on a.id=a_s.id and a_s.key='ctime'
551 left join (select id,
552 max(case key when 'owner' then val end) as owner,
553 max(case key when 'title' then val end) as title
554 from blog_s group by id)
555 bs on a.blogid=bs.id
556 left join blog b on bs.id=b.id
557 where m.val is not null order by $by $ord;"
558 err lshandoutbyauthor: sql=`echo "$sql"`
559 title="個人提出ファイル"
560 m4 -D_TITLE_=$title $layout/html.m4.html
561 hra="<a href=\"?lsmyfile+"
562 hrb="<a href=\"?showattc+article_m+"
563 hrc="<a href=\"?replyblog+"
564 (echo '<table class="b">'
565 echo "$sql"|sq -html -header $db ) \
566 | sed -e "s|\(<TR><TD>\)\([^/]*\)/\([0-9]*\)|\1$hrb\3\">\2</a>|" \
567 -e "s|,t,\(.*\):\([^<]*\)\(</TD>\)|$hrc\2\">\1</a>\3|" \
568 -e "s|\(<TH>\)\([A-Z]*\)\(</TH>\)|\1$hra\2$lkod\">\2</a>|" \
569 | m4 -D_TITLE_=$title -D_FORM_="<p>($by$jord)</p>" \
570 -D_DUMPTABLE_="syscmd(cat)" $layout/form+dump.m4.html
571 echo '</table>'
572 }
573 searchart() {
574 kwd=`getpar kwd`
575 if [ -z "$kwd" ]; then
576 echo "検索語を指定してください" | html p; return
577 fi
578 for k in `echo "$kwd" | sed "s/'/''/g"`; do
579 kc=$kc${kc:+" AND "}"s.val LIKE '%$k%'"
580 done
581 kwd=`echo "$kwd"|htmlescape`
582 owner=`getpar owner`
583 owner=${owner:-$1}
584 echo "「$kwd」による検索結果" | html p
585 if [ -n "$owner" ]; then
586 cond="where key='owner' and val='$owner'"
587 if isuser $owner; then
588 echo "(`linkhome $owner` さんの記録からの検索)" | html p
589 else
590 linkhome $owner 1>&3
591 echo "(`linkhome $owner` グループからの検索)" | html p
592 fi
593 fi
594 # article_s: id=article-id, key='text', val='TEXT'
595 # article: id=article-id, blogid=blogkd
596 # blog: id=blog-id, author=LeaderAuthor
597 # blog_s: id=blog-id, key='title', val='BLOG-TITLE'
598 # WANT: blog-ROWid,article-id,val(TEXT)
599 sql="select b.rowid||'#'||x.id as '',
600 b.title as TITLE,
601 substr(x.val, 0, 80) as TEXT
602 from (select blog.rowid,blog.*,bs.val as title from blog join blog_s bs
603 on blog.id=bs.id and bs.key='title') b
604 join
605 (select a.id,a.blogid,s.val from article a join article_s s
606 on a.id=s.id where $kc)
607 x on b.id=x.blogid
608 where b.id in (select id from blog_s
609 $cond);"
610 sedopt="s,<TR><TD>\([^<]*\)</TD>,<TR><TD><a\
611 href=\"?replyblog+\1\">VIEW</a></TD>,"
612 cat<<EOF
613 <table class="b searchart">
614 `sq -header -html $db "$sql"|sed "$sedopt"`
615 </table>
616 EOF
617 }
618 listblog() (
619 # $1={user,group}
620 qow=`sqlquote $1`
621 cond="where a.id in (select id from blog_s where key='owner' and val=$qow) order by ctime desc"
622 DT_CHLD=article:blogid
623 cgi_form searchart<<EOF
624 <label>`cgi_text kwd`という語を含む記事をこの一覧から検索</label>
625 `cgi_hidden owner $user`
626 EOF
627 dumptable html blog 'ctime title heading' "$cond"
628 )
630 blog_addentry() {
631 # $1=GRPname(if it is a group)
632 grprowid=$1
633 rowid=`getpar rowid`
634 err blog_addentry0: rowid=$rowid
635 if [ -n "$grprowid" ]; then
636 owner=`getgroupbyid $grprowid`
637 else
638 owner=`getpar owner`
639 fi
640 err blog-add: \$1=$1 rowid=$rowid owner=$owner
641 if isgroup $owner; then
642 groupmode=1 listing=$owner guide="[${owner}]" GF_OWNER=$owner
643 else
644 usermode=1 listing=$user guide="[個人]"
645 fi
647 if [ -n "`getpar title`" ]; then
648 if [ "$usermode" ]; then
649 err usermode: user=$user owner=$owner
650 if [ x"$user" != x"$owner" ]; then
651 echo "他人の日記は書けません" | html p
652 return 2
653 fi
654 elif [ "$groupmode" ]; then # if write to group log
655 grp=$owner #\`getpar grp\`
656 err ismember: $user $grp
657 if ! ismember "$user" "$grp"; then
658 echo "(話題作成はこのグループに加入してから)" | html p
659 return 3
660 fi
661 fi
662 par2table $formdir/blog.def
663 serial=`getpar serial`
664 err SERIAL: $serial ROWID=$rowid listing=$listing
665 id=""
666 if [ -n "$rowid" ]; then
667 # Here, id becomes NULL when removal of entries at par2table
668 id=`query "select rowid from blog where rowid=$rowid;"`
669 elif [ -n "$serial" ]; then
670 # If new blog leader created, traverse to its head.
671 id=`query "select rowid from blog where id='$serial';"`
672 err new-Leader: "select rowid from blog where id='$serial';" id=$id
673 fi
674 if [ -n "$id" ]; then
675 ## If new aritcle is entered, JUMP to blog_reply
676 blog_reply $id
677 return
678 fi
679 fi
680 echo "${guide}新規話題作成" > $tmpd/title.$$
681 listblog $listing > $tmpd/listblog.$$
682 genform $formdir/blog.def \
683 | m4 -D_TITLE_="spaste(\`$tmpd/title.$$')" \
684 -D_FORMHEAD_="序文は簡単に詳しくはコメントに" \
685 -D_DUMPHEAD_="これまでの蓄積" \
686 -D_FORM_="syscmd(\`cat')" \
687 -D_DUMPTABLE_="spaste(\`$tmpd/listblog.$$')" \
688 $layout/html.m4.html \
689 $layout/form+dump-whead.m4.html
690 }
692 blog_reply() {
693 rowid=$1
694 err rowid=$1
696 if [ -z "$rowid" ]; then
697 echo "表示する日記番号が未指定です。" | html p
698 return
699 fi
700 title=`getvalbyid blog title $rowid`
701 owner=`getvalbyid blog owner $rowid`
702 if isuser "$owner"; then
703 subtitle="`gecos $owner` さんの話題"
704 else
705 grprowid=`query "select rowid from grp where gname=\"$owner\";"`
706 subtitle="グループ <a href=\"?grp+$grprowid\">$owner</a> での話題"
707 fi
708 if [ -z "$title" ]; then
709 echo "日記番号指定が無効です。" | html p
710 return
711 fi
713 text=`getpar text`
714 if [ -n "$text" ]; then
715 if blog_writable $rowid $user; then
716 par2table $formdir/article.def
717 st=$? # ; err par2t-st=$st
718 case $st in
719 0|4)
720 [ "$st" = "4" ] && act="書込削除"
721 blog_notify_reply $rowid $user "$text" $act ;;
722 esac
723 else
724 title="$title(加入してないので書き込み不可)"
725 fi
726 fi
727 def=$formdir/article.def
728 echo "$title" > $tmpd/title.$$
729 echo "$subtitle" > $tmpd/subtitle.$$
730 ${BLOG_SHOW:-blog_showentry} blog $rowid \
731 | m4 -D_TITLE_="spaste(\`$tmpd/title.$$')" -D_BODYCLASS_=general \
732 -D_FORMHEAD_="spaste(\`$tmpd/subtitle.$$')" \
733 -D_FORM_='' \
734 -D_DUMPTABLE_="syscmd(cat)" -D_DUMPHEAD_="" \
735 $layout/html.m4.html $layout/form+dump-whead.m4.html
736 }