s4

view s4-blog.sh @ 170:45d6954af516

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