s4

annotate s4-blog.sh @ 331:1a60dfc56bb0

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