s4

view s4-blog.sh @ 191:24e0f2b4d51b

Variable name mistake fixed
author HIROSE Yuuji <yuuji@gentei.org>
date Sat, 23 Apr 2016 21:10:55 +0859
parents 972cb5ab0c5f
children 50e6195130b3
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 "$notifyto" ]; 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 a.rowid,
379 s.TIME,
380 hex(s.TEXT),
381 (SELECT group_concat(rowid||':'||length(bin)||':'||hex(val), ' ')
382 FROM article_m
383 WHERE id=a.id AND key='image') imxgids
384 FROM (select rowid,id,author from article where blogid in
385 (select id from blog where rowid=$rowid)) a
386 LEFT JOIN
387 a_s s
388 ON a.id=s.id;
389 EOF
390 while IFS='|' read id edit notify uid uname aid tm hte imgids; do
391 nt="<label style=\"font-size: 70%;\"><input type=\"checkbox\"
392 name=\"notifyto\" value=\"$uid\">返信通知送信</label>"
393 cat<<EOF |
394 <tr id="$id">
395 <td>${edit:+<a href="$elink+$edit">編集</a> }#$aid
396 <a href="$hlink+$uid">$uname</a>
397 $tm
398 ${notify:+$nt}</td><td>`echo "$hte"|unhexize|htmlescape`
399 EOF
400 sed -e "s|^href=\([-A-Za-z0-9,.:/~_%#&+?]*\)|<a &>\1</a>|"
401 for i in $imgids; do
402 mrid=${i%%:*}; i=${i#*:}; sz=`size_h ${i%%:*}`
403 fn=`echo "${i#*:}"|unhexize`
404 fnb=$fn"(${sz})"
405 # echo r=$mrid fn=$fn
406 case "$fn" in
407 *.[Pp][Nn][Gg]|*.[Jj][Pp][Gg]|*.[Jj][Pp][Ee][Gg])
408 sq $db "SELECT hex(bin) FROM article_m WHERE rowid=$mrid" \
409 | unhexize \
410 | convert -define jpeg:size=100x100 -resize 100x100'>' - jpeg:- \
411 | hexize \
412 | sed -e 's/\(..\)/%\1/g' \
413 -e "s|^|<a href=\"$catlink+$mrid\"><img src=\"data:image/jpeg,|" \
414 -e "s|\$|\">$fnb</a>|"
415 ;;
416 *)
417 echo "<a href=\"$catlink+$mrid\"><img src=\"$deficon\">$fnb</a>"
418 ;;
419 esac
420 done
421 done
422 fi
424 textform='<div><table class="b">
425 <tr><td><textarea name="text" cols="40" rows="4"></textarea></td></tr>
426 <tr><td>添付ファイル: <input type="file" name="image" multiple></td></tr>
427 </table>
428 <input type="submit" value="送信">
429 <input type="reset" value="リセット"></div>
430 '
431 echo '</table>'
433 $iswritable && cat<<EOF
434 <div class="blogcomment">
435 <p>コメント記入</p>
436 <input type="hidden" name="blogid" value="$id">
437 <input type="hidden" name="stage" value="replyblog">
438 <input type="hidden" name="serial" value="$serial">
439 $textform
440 </div>
441 EOF
442 echo "</form><p id=\"bottom\"></p>"
443 # Record access log
444 acclog blog $rowid
445 }
447 lshandout() {
448 # $1=rowid of blog
449 if ! blog_writable $1 $user; then
450 echo "メンバー以外は利用できません。" | html p; return
451 fi
452 time=`getvalbyid blog ctime $1|colrm 11`
453 owner=`getvalbyid blog owner $1`
454 title=`getvalbyid blog title $1`
455 ge=`gecos $owner`
456 lshandoutsub $owner "$@" \
457 |_m4 -D_TITLE_="提出状況" \
458 -D_FORMHEAD_="$time [$title]@${ge:-$owner}" \
459 -D_FORM_="syscmd(cat)" -D_DUMPHEAD_= -D_DUMPTABLE_= \
460 $layout/html.m4.html $layout/form+dump-whead.m4.html
461 }
462 lshandoutsub() {
463 # $1=owner $2=rowid of blog
464 if isgroup $1; then
465 sample="(select user from grp_mem where gname='$1')"
466 else
467 sample="(select distinct author as user from arts)"
468 echo "(集計は板への投稿者のみ)" | html p
469 fi
470 sql="with arts as (select id,author from article \
471 where blogid=(select id from blog where rowid=$2))\
472 select (select rowid from user where name=c0.user)||' '|| \
473 coalesce((select val from user_s where name=c0.user \
474 and key='gecos'),\
475 c0.user) as 'メンバー',\
476 sum(case when c1.key is not null then 1 else 0 end)\
477 as 'コメント記入',\
478 sum(case when c2.key is not null then 1 else 0 end)\
479 as 'ファイルの提出'\
480 from $sample c0 \
481 left join (select id,author from arts) a\
482 on c0.user=a.author\
483 left join (select id,key from article_s where key='text') c1\
484 on a.id=c1.id left join (select id,key from article_m ) c2\
485 on c1.id=c2.id group by c0.user order by c0.user;"
486 err ishandoutsub: sql="$sql"
487 echo '<table class="b td2r td3r">'
488 hrb="<a href=\"?home+"
489 echo "$sql" | sq -header -html $db \
490 | sed -e "s,\(<TR><TD>\)\([^ ]*\) \(.*\)</TD>,\1$hrb\2\">\3</TD>," -e 's,<TD>0</TD>,<TD class="warn">0</TD>,'
491 echo '</table>'
492 }
493 gethandout() {
494 # $1=rowid of blog
495 if ! blog_writable $1 $user; then
496 echo "メンバー以外は利用できません。" | html p; return
497 fi
498 i=0
499 bd=$tmpd/archive.$$
500 mkdir $bd
501 query "select m.rowid,author,m.val from article a join article_m m\
502 on a.id=m.id where blogid=(select id from blog where rowid=$1)\
503 and m.key in ('image', 'document', 'binary');" \
504 | while IFS='|' read rowid author filename; do
505 # err isfilereadable $user article_m $rowid
506 isfilereadable $user article_m $rowid || continue
507 # err ok
508 i=$((i+1))
509 dir=`printf $bd/%03d $i`
510 mkdir $dir
511 query "select quote(bin) from article_m where rowid=$rowid;" \
512 | unhexize > $dir/$filename
513 done
514 if [ ! -d $bd/001 ]; then
515 contenttype; echo
516 echo "取得できるファイルがありませんでした。" | html p
517 return
518 fi
519 (cd $bd
520 err cdto$bd; (pwd; ls -lFa) 1>&3
521 tar zcf .archive.tar.gz * && mv .archive.tar.gz archive.tar.gz
522 )
523 arc=$bd/archive.tar.gz
524 echo "Content-type: application/x-gzip"
525 echo "Content-Length: `cat $arc|wc -c`"
526 echo "Content-Disposition: filename=\"archive.tar.gz\""
527 echo
528 cat $arc
529 }
530 lsmyfile() { # $1(optional)=SortBy
531 case "$1" in
532 ""|CTIME-DESC)
533 by="CTIME" ord="DESC" ;;
534 CTIME*) by="CTIME" ;;
535 FILE*) by="FILE" ;;
536 OWNER*) by="OWNER" ;;
537 TITLE*) by="TITLE" ;;
538 esac
539 case "$1" in
540 *DESC) ord="DESC" ;;
541 esac
542 case "$ord" in
543 DESC) lkod="" jord="降順" ;;
544 *) lkod="-DESC" jord="昇順" ;;
545 esac
546 sql="select m.val||'/'||m.rowid FILE,
547 coalesce(
548 case when (select name from user where name=bs.owner)
549 is not null
550 then (select val from user_s where name=bs.owner
551 and key='gecos')
552 when (select gname from grp where gname=bs.owner)
553 is not null
554 then (select val from grp_s where gname=bs.owner
555 and key='gecos')
556 else
557 null
558 end,
559 bs.owner
560 ) OWNER,
561 a_s.val CTIME,
562 ',t,'||bs.title||':'||b.rowid||'#'||a.id TITLE
563 from (select rowid,id,val from article_m where id
564 in (select id from article where author='$user')
565 and type like 'file:%')
566 m left join article a on m.id=a.id
567 left join article_s a_s on a.id=a_s.id and a_s.key='ctime'
568 left join (select id,
569 max(case key when 'owner' then val end) as owner,
570 max(case key when 'title' then val end) as title
571 from blog_s group by id)
572 bs on a.blogid=bs.id
573 left join blog b on bs.id=b.id
574 where m.val is not null order by $by $ord;"
575 err lshandoutbyauthor: sql=`echo "$sql"`
576 title="個人提出ファイル"
577 _m4 -D_TITLE_=$title $layout/html.m4.html
578 hra="<a href=\"?lsmyfile+"
579 hrb="<a href=\"?showattc+article_m+"
580 hrc="<a href=\"?replyblog+"
581 (echo '<table class="b">'
582 echo "$sql"|sq -html -header $db ) \
583 | sed -e "s|\(<TR><TD>\)\([^/]*\)/\([0-9]*\)|\1$hrb\3\">\2</a>|" \
584 -e "s|,t,\(.*\):\([^<]*\)\(</TD>\)|$hrc\2\">\1</a>\3|" \
585 -e "s|\(<TH>\)\([A-Z]*\)\(</TH>\)|\1$hra\2$lkod\">\2</a>|" \
586 | _m4 -D_TITLE_=$title -D_FORM_="<p>($by$jord)</p>" \
587 -D_DUMPTABLE_="syscmd(cat)" $layout/form+dump.m4.html
588 echo '</table>'
589 }
590 searchart() {
591 kwd=`getpar kwd`
592 if [ -z "$kwd" ]; then
593 echo "検索語を指定してください" | html p; return
594 fi
595 for k in `echo "$kwd" | sed "s/'/''/g"`; do
596 kc=$kc${kc:+" AND "}"s.val LIKE '%$k%'"
597 done
598 kwd=`echo "$kwd"|htmlescape`
599 owner=`getpar owner`
600 owner=${owner:-$1}
601 echo "「$kwd」による検索結果" | html p
602 if [ -n "$owner" ]; then
603 cond="where key='owner' and val='$owner'"
604 if isuser $owner; then
605 echo "(`linkhome $owner` さんの記録からの検索)" | html p
606 else
607 linkhome $owner 1>&3
608 echo "(`linkhome $owner` グループからの検索)" | html p
609 fi
610 fi
611 # article_s: id=article-id, key='text', val='TEXT'
612 # article: id=article-id, blogid=blogkd
613 # blog: id=blog-id, author=LeaderAuthor
614 # blog_s: id=blog-id, key='title', val='BLOG-TITLE'
615 # WANT: blog-ROWid,article-id,val(TEXT)
616 sql="select b.rowid||'#'||x.id as '',
617 b.title as TITLE,
618 substr(x.val, 0, 80) as TEXT
619 from (select blog.rowid,blog.*,bs.val as title from blog join blog_s bs
620 on blog.id=bs.id and bs.key='title') b
621 join
622 (select a.id,a.blogid,s.val from article a join article_s s
623 on a.id=s.id where $kc)
624 x on b.id=x.blogid
625 where b.id in (select id from blog_s
626 $cond);"
627 sedopt="s,<TR><TD>\([^<]*\)</TD>,<TR><TD><a\
628 href=\"?replyblog+\1\">VIEW</a></TD>,"
629 cat<<EOF
630 <table class="b searchart">
631 `sq -header -html $db "$sql"|sed "$sedopt"`
632 </table>
633 EOF
634 }
635 listblog() (
636 # $1={user,group}
637 qow=`sqlquote $1`
638 cond="where a.id in (select id from blog_s where key='owner' and val=$qow) order by ctime desc"
639 DT_CHLD=article:blogid
640 cgi_form searchart<<EOF
641 <label>`cgi_text kwd`という語を含む記事をこの一覧から検索</label>
642 `cgi_hidden owner $user`
643 EOF
644 dumptable html blog 'ctime title heading' "$cond"
645 )
647 blog_addentry() {
648 # $1=GRPname(if it is a group)
649 grprowid=$1
650 rowid=`getpar rowid`
651 err blog_addentry0: rowid=$rowid
652 if [ -n "$grprowid" ]; then
653 owner=`getgroupbyid $grprowid`
654 else
655 owner=`getpar owner`
656 fi
657 err blog-add: \$1=$1 rowid=$rowid owner=$owner
658 if isgroup $owner; then
659 groupmode=1 listing=$owner guide="[${owner}]" GF_OWNER=$owner
660 else
661 usermode=1 listing=$user guide="[個人]"
662 fi
664 if [ -n "`getpar title`" ]; then
665 if [ "$usermode" ]; then
666 err usermode: user=$user owner=$owner
667 if [ x"$user" != x"$owner" ]; then
668 echo "他人の日記は書けません" | html p
669 return 2
670 fi
671 elif [ "$groupmode" ]; then # if write to group log
672 grp=$owner #\`getpar grp\`
673 err ismember: $user $grp
674 if ! ismember "$user" "$grp"; then
675 echo "(話題作成はこのグループに加入してから)" | html p
676 return 3
677 fi
678 fi
679 par2table $formdir/blog.def
680 serial=`getpar serial`
681 err SERIAL: $serial ROWID=$rowid listing=$listing
682 id=""
683 if [ -n "$rowid" ]; then
684 # Here, id becomes NULL when removal of entries at par2table
685 id=`query "select rowid from blog where rowid=$rowid;"`
686 elif [ -n "$serial" ]; then
687 # If new blog leader created, traverse to its head.
688 id=`query "select rowid from blog where id='$serial';"`
689 err new-Leader: "select rowid from blog where id='$serial';" id=$id
690 fi
691 if [ -n "$id" ]; then
692 ## If new aritcle is entered, JUMP to blog_reply
693 blog_reply $id
694 return
695 fi
696 fi
697 echo "${guide}新規話題作成" > $tmpd/title.$$
698 listblog $listing > $tmpd/listblog.$$
699 genform $formdir/blog.def \
700 | _m4 -D_TITLE_="spaste(\`$tmpd/title.$$')" \
701 -D_FORMHEAD_="序文は簡単に詳しくはコメントに" \
702 -D_DUMPHEAD_="これまでの蓄積" \
703 -D_FORM_="syscmd(\`cat')" \
704 -D_DUMPTABLE_="spaste(\`$tmpd/listblog.$$')" \
705 $layout/html.m4.html \
706 $layout/form+dump-whead.m4.html
707 }
709 blog_reply() {
710 rowid=$1
711 err rowid=$1
713 if [ -z "$rowid" ]; then
714 echo "表示する日記番号が未指定です。" | html p
715 return
716 fi
717 title=`getvalbyid blog title $rowid`
718 owner=`getvalbyid blog owner $rowid`
719 if isuser "$owner"; then
720 subtitle="`gecos $owner` さんの話題"
721 else
722 grprowid=`query "select rowid from grp where gname=\"$owner\";"`
723 subtitle="グループ <a href=\"?grp+$grprowid\">$owner</a> での話題"
724 fi
725 if [ -z "$title" ]; then
726 echo "日記番号指定が無効です。" | html p
727 return
728 fi
730 text=`getpar text`
731 if [ -n "$text" ]; then
732 if blog_writable $rowid $user; then
733 par2table $formdir/article.def
734 st=$? # ; err par2t-st=$st
735 case $st in
736 0|4)
737 [ "$st" = "4" ] && act="書込削除"
738 blog_notify_reply $rowid $user "$text" $act ;;
739 esac
740 else
741 title="$title(加入してないので書き込み不可)"
742 fi
743 fi
744 def=$formdir/article.def
745 echo "$title" > $tmpd/title.$$
746 echo "$subtitle" > $tmpd/subtitle.$$
747 ${BLOG_SHOW:-blog_showentry} blog $rowid \
748 | _m4 -D_TITLE_="spaste(\`$tmpd/title.$$')" -D_BODYCLASS_=general \
749 -D_FORMHEAD_="spaste(\`$tmpd/subtitle.$$')" \
750 -D_FORM_='' \
751 -D_DUMPTABLE_="syscmd(cat)" -D_DUMPHEAD_="" \
752 $layout/html.m4.html $layout/form+dump-whead.m4.html
753 }