comparison s4-blog.sh @ 898:411ce55c0dae

AJAX posting and PJAX file-viewer initially introduced.
author HIROSE Yuuji <yuuji@gentei.org>
date Sat, 02 Jan 2021 15:15:03 +0900
parents bc52f605f41d
children 1fa8b4440f8f
comparison
equal deleted inserted replaced
897:3d437261edca 898:411ce55c0dae
176 return 176 return
177 fi 177 fi
178 fi 178 fi
179 fi 179 fi
180 fi 180 fi
181 err "blog_showentry Entered: `gdate +%S.%03N` blogrowid=$rowid"
181 blog_notify=`getvalbyid blog notify "$rowid"` 182 blog_notify=`getvalbyid blog notify "$rowid"`
182 blog_team=`blog_getteam "$rowid"` 183 blog_team=`blog_getteam "$rowid"`
183 blog_mode=`getvalbyid blog mode "$rowid"` 184 blog_mode=`getvalbyid blog mode "$rowid"`
184 case "$blog_notify" in # "all", "admin" or "no" (or NULL) 185 case "$blog_notify" in # "all", "admin" or "no" (or NULL)
185 admin) notifyto=adm ;; 186 admin) notifyto=adm ;;
199 THEN '' 200 THEN ''
200 WHEN author = '$user' 201 WHEN author = '$user'
201 THEN '' 202 THEN ''
202 ELSE 'Unreadable' 203 ELSE 'Unreadable'
203 END" 204 END"
205 elif [ x"$blog_mode" = x"report-closed" ]; then
206 F_UNREADABLE="CASE
207 WHEN author = '$user'
208 THEN ''
209 ELSE 'Unreadable'
210 END"
204 else 211 else
205 F_UNREADABLE="'Unreadable'" 212 F_UNREADABLE="'Unreadable'"
206 fi 213 fi
207 fi 214 fi
208 else # User blog 215 else # User blog
224 # err "SELECT id from $tbl where rowid=$rowid" 231 # err "SELECT id from $tbl where rowid=$rowid"
225 id=`query "select id from $tbl where rowid=$rowid;"` 232 id=`query "select id from $tbl where rowid=$rowid;"`
226 #err id=$id 233 #err id=$id
227 #err "select val from $ts where key='title' and id='$id';" 234 #err "select val from $ts where key='title' and id='$id';"
228 235
236 ## Parse control sequence
237 nlimit=$listartlimit
238 case "$control" in
239 n:[Aa][Ll][Ll])
240 unset nlimit ;;
241 n:*)
242 nlimit=${control##*:}
243 nlimit=${nlimit%%[!A-Z0-9a-z_]*}
244 ;;
245 f:[Aa][Ll][Ll]) ;;
246 f:2???-??-??*) # f:2020-12-27T08:02:43
247 fetch=${control#f:}
248 fetch_ajax=`echo "'$fetch'"|tr T ' '`
249 esac
250 err control=$control fetch_ajax=$fetch_ajax
229 #(1)Display root article 251 #(1)Display root article
230 cat<<EOF 252 cat<<EOF
231 <form class="replyblog" action="$myname?replyblog+${rowid}#bottom" method="POST" enctype="multipart/form-data"> 253 <form class="replyblog" action="$myname?replyblog+${rowid}#bottom" method="POST" enctype="multipart/form-data">
232 <table class="bloghead"> 254 <table class="bloghead">
233 EOF 255 EOF
269 END 291 END
270 FROM $ts WHERE id='$id' GROUP BY id; 292 FROM $ts WHERE id='$id' GROUP BY id;
271 EOF 293 EOF
272 if test -s $midfile && IFS='|' read edit ctime hexhead blogtype < $midfile 294 if test -s $midfile && IFS='|' read edit ctime hexhead blogtype < $midfile
273 then 295 then
274 cat<<-EOF 296 if [ -z "$fetch_ajax" ]; then # UUUUU
297
298 cat<<-EOF
275 <tr><td>${edit:+$href }$ctime $blogtype $href2${edit:+$href3} $href4 $href5</td></tr> 299 <tr><td>${edit:+$href }$ctime $blogtype $href2${edit:+$href3} $href4 $href5</td></tr>
276 <tr class="preface${frozen_class:+ }$frozen_class"> 300 <tr class="preface${frozen_class:+ }$frozen_class">
277 <td>`echo "$hexhead"|unhexize|htmlescape|hreflink|minitbl`</td></tr> 301 <td>`echo "$hexhead"|unhexize|htmlescape|hreflink|minitbl`</td></tr>
278 </table> 302 </table>
279 EOF 303 EOF
280 case "$blogtype" in 304 case "$blogtype" in
281 "クイズ"|"XXXX集計") 305 "クイズ"|"XXXX集計")
282 echo "${blogtype}モードは本人と管理者の書き込みのみが表示されます。" 306 echo "${blogtype}モードは本人と管理者の書き込みのみが表示されます。"
283 ;; 307 ;;
284 esac | html p 'class="warn"' 308 esac | html p 'class="warn"'
285 309
310 fi # UUUUU
286 if [ x"$blogtype" = x"クイズ" -o x"$blogtype" = x"XXXX集計" ]; then 311 if [ x"$blogtype" = x"クイズ" -o x"$blogtype" = x"XXXX集計" ]; then
287 if $isgroup; then 312 if $isgroup; then
288 # Failsafe to query timeout 313 # Failsafe to query timeout
289 qgrp=`sqlquote "$blogowner"` 314 qgrp=`sqlquote "$blogowner"`
290 cat<<-EOF > $quizmodefile 315 cat<<-EOF > $quizmodefile
305 fi 330 fi
306 else # Cannot read SQL output 331 else # Cannot read SQL output
307 echo "時間をおいて繋いでください(Please visit later)." | html p 332 echo "時間をおいて繋いでください(Please visit later)." | html p
308 return 333 return
309 fi 334 fi
310 ## Parse control sequence 335
311 nlimit=$listartlimit
312 case "$control" in
313 n:[Aa][Ll][Ll])
314 unset nlimit ;;
315 n:*)
316 nlimit=${control##*:}
317 nlimit=${nlimit%%[!A-Z0-9a-z_]*}
318 ;;
319 esac
320 lkhome="<a href=\"$myname?home" lke='">' 336 lkhome="<a href=\"$myname?home" lke='">'
321 lkedit="<a href=\"$myname?editart" 337 lkedit="<a href=\"$myname?editart"
322 hlink="$myname?home" elink="$myname?editart" 338 hlink="$myname?home" elink="$myname?editart"
323 catlink="$myname?showattc+article_m" 339 catlink="$myname?showattc+article_m"
324 deficon="img/file-icon.png" 340 deficon="img/file-icon.png"
390 where blogid in 406 where blogid in
391 (select id from blog where rowid=$rowid) 407 (select id from blog where rowid=$rowid)
392 $cond_qz) a 408 $cond_qz) a
393 LEFT JOIN 409 LEFT JOIN
394 a_s s 410 a_s s
395 ON a.id=s.id; 411 ON a.id=s.id
412 ${fetch_ajax:+WHERE s.TIME > $fetch_ajax};
396 EOF 413 EOF
397 if [ $? -ne 0 -a ! -s $midfile ]; then 414 if [ $? -ne 0 -a ! -s $midfile ]; then
398 echo "時間をおいてください(Visit later please)." | html p 415 echo "時間をおいてください(Visit later please)." | html p
399 return 416 return
400 fi 417 fi
424 <th>$showalllink</td></th> 441 <th>$showalllink</td></th>
425 EOF 442 EOF
426 else 443 else
427 CAT=cat 444 CAT=cat
428 fi 445 fi
446 err "blog_showentry Started: `gdate +%S.%03N` ${fetch_ajax:+ajax}"
429 # Start blog_replies table 447 # Start blog_replies table
430 $CAT $midfile | 448 $CAT $midfile |
431 while IFS='|' read id edit notify uid author uname icon aid \ 449 while IFS='|' read id edit notify uid author uname icon aid \
432 tm reki new hte fa imgids 450 tm reki new hte fa imgids
433 do 451 do
485 echo -n "<td id=\"$aid\" class=\"repl\">" 503 echo -n "<td id=\"$aid\" class=\"repl\">"
486 echo "$hte"|unhexize|htmlescape|hreflink|minitbl 504 echo "$hte"|unhexize|htmlescape|hreflink|minitbl
487 usecache='' tsfile=$td/$id.stamp 505 usecache='' tsfile=$td/$id.stamp
488 for i in $imgids; do 506 for i in $imgids; do
489 mrid=${i%%:*}; i=${i#*:}; sz=`size_h ${i%%:*}` 507 mrid=${i%%:*}; i=${i#*:}; sz=`size_h ${i%%:*}`
508 _href="href=\"$catlink+$mrid\""
490 fn=`echo "${i#*:}"|unhexize` 509 fn=`echo "${i#*:}"|unhexize`
491 fnb=$fn"(${sz})" 510 fnb=$fn"(${sz})"
492 case "$fn" in 511 case "$fn" in
493 *.[Pp][Nn][Gg]|*.[Jj][Pp][Gg]|*.[Jj][Pp][Ee][Gg]|*.[GgTt][Ii][Ff]) 512 *.[Pp][Nn][Gg]|*.[Jj][Pp][Gg]|*.[Jj][Pp][Ee][Gg]|*.[GgTt][Ii][Ff])
494 # fmt=${fn##*.} # convert - jpg:- is slow...why 513 # fmt=${fn##*.} # convert - jpg:- is slow...why
506 { [ "$usecache" ] || # And usecache flag is true, or... 525 { [ "$usecache" ] || # And usecache flag is true, or...
507 { [ -s "$tsfile" ] && [ x"`cat $tsfile`" = x"$tm" ] 526 { [ -s "$tsfile" ] && [ x"`cat $tsfile`" = x"$tm" ]
508 };}; then 527 };}; then
509 usecache=1 # Set usecache flag on 528 usecache=1 # Set usecache flag on
510 cat<<-EOF 529 cat<<-EOF
511 <a href="$catlink+$mrid"><img src="$outfile"> 530 <__UNCLICKABLE__><a $_href><img src="$outfile">
512 $fnb</a> 531 $fnb</a>
513 EOF 532 EOF
514 # !!NOTE!! Create row stamp ONLY WHEN imgcache is active 533 # !!NOTE!! Create row stamp ONLY WHEN imgcache is active
515 else 534 else
516 query "SELECT hex(bin) FROM article_m WHERE rowid=$mrid;" \ 535 query "SELECT hex(bin) FROM article_m WHERE rowid=$mrid;" \
520 - ${fmt}:- > $outfile 539 - ${fmt}:- > $outfile
521 then 540 then
522 cat "$outfile" \ 541 cat "$outfile" \
523 | hexize \ 542 | hexize \
524 | sed -e 's/\(..\)/%\1/g' \ 543 | sed -e 's/\(..\)/%\1/g' \
525 -e "s|^|<a href=\"$catlink+$mrid\"><img src=\"data:image/$fmt,|" \ 544 -e "s|^|<__UNCLICKABLE__><a $_href><img src=\"data:image/$fmt,|" \
526 -e "s|\$|\">$fnb</a>|" 545 -e "s|\$|\">$fnb</a>|"
527 unset stampfile # img data stream is not suitable to cache 546 unset stampfile # img data stream is not suitable to cache
528 echo $tm > $tsfile 547 echo $tm > $tsfile
529 else # Failed to convert 548 else # Failed to convert
530 rm -f $outfile 549 rm -f $outfile
531 echo "<a href=\"$catlink+$mrid\">$fnb</a>" 550 echo "<__UNCLICKABLE__><a $_href>$fnb</a>"
532 fi 551 fi
533 fi 552 fi
534 ;; 553 ;;
535 *) 554 *)
536 echo "<__UNREADABLE__><a href=\"$catlink+$mrid\"><img src=\"$deficon\">$fnb</a>" 555 echo "<__UNCLICKABLE__><a $_href><img src=\"$deficon\">$fnb</a>"
537 ;; 556 ;;
538 esac 557 esac
539 done 558 done
540 echo "</td></tr>" 559 echo "</td></tr>"
541 } > "$cachefile.$$" ######## New ROW Creation Ends here ######## 560 } > "$cachefile.$$" ######## New ROW Creation Ends here ########
546 else 565 else
547 mv -f $cachefile.$$ $cachefile 566 mv -f $cachefile.$$ $cachefile
548 fi 567 fi
549 test -n "$stampfile" && date "+%F %T" > $stampfile 568 test -n "$stampfile" && date "+%F %T" > $stampfile
550 fi 569 fi
570 if [ -n "$fa" ]; then
571 replhref="s/a href=[^>]*>/a>/"
572 else
573 replhref=""
574 fi
551 # Printing a cached row 575 # Printing a cached row
552 sed -e "/^<td class=/s/__NEWCLS__/$new${new:+ }/" \ 576 sed -e "/^<td class=/s/__NEWCLS__/$new${new:+ }/" \
553 -e "/^<td class=/s,__EDIT__,$editlink," \ 577 -e "/^<td class=/s,__EDIT__,$editlink," \
554 -e "/^<__NOTIFY__>/s,,${notify:+$nt}," \ 578 -e "/^<__NOTIFY__>/s,,${notify:+$nt}," \
579 ${replhref:+-e "/^<__UNCLICKABLE__>/$replhref"} \
580 ${replhref:+-e "/^<__UNREADABLE__>/$replhref"} \
581 -e "/<__UNCLICKABLE__>/s///" \
555 -e "/<__UNREADABLE__>/s,,${fa:+$cannotread}," \ 582 -e "/<__UNREADABLE__>/s,,${fa:+$cannotread}," \
556 $cachefile 583 $cachefile
557 done 584 done
558 585
559 help="=== コメントに使用できる特殊記法(記号は全て半角) === 586 help="=== コメントに使用できる特殊記法(記号は全て半角) ===
587 </textarea>$touchhelp</td></tr> 614 </textarea>$touchhelp</td></tr>
588 <tr><td>添付ファイル(${filesize_max_MB}以下): 615 <tr><td>添付ファイル(${filesize_max_MB}以下):
589 `cgi_file image "" "$file_accept title=\"$filehelp\" multiple"` 616 `cgi_file image "" "$file_accept title=\"$filehelp\" multiple"`
590 </td></tr> 617 </td></tr>
591 </table> 618 </table>
592 <input type="submit" value="送信" class="$blog_notify" title="$ntmode"> 619 <input type="hidden" name="fetchtime" value="`date +%FT%T`">
620 <input type="hidden" name="filesize_max" value="$filesize_max">
621 <input type="submit" id="c" value="送信" class="$blog_notify" title="$ntmode">
593 <input type="reset" value="リセット"></div></div> 622 <input type="reset" value="リセット"></div></div>
594 EOF 623 EOF
595 ) 624 )
596 cat<<-EOF 625 cat<<-EOF
597 </table> <!-- end of s4-blog:blog_showentry() main table --> 626 </table> <!-- end of s4-blog:blog_showentry() main table -->
598 <p class="update_link"><a 627 <p class="update_link"><a
599 href="?reload/$rowid" accesskey="r" 628 href="?reload/$rowid" accesskey="r"
600 title="Shortcut: R${nl}Reload">再読込</a> / <a 629 title="Shortcut: R${nl}Reload">再読込</a> / <a
613 EOF 642 EOF
614 # Clean up orphaned icon cache 643 # Clean up orphaned icon cache
615 [ -s $iconcleaner ] && query ".read '$iconcleaner'" 644 [ -s $iconcleaner ] && query ".read '$iconcleaner'"
616 # Record access log 645 # Record access log
617 acclog blog $rowid 646 acclog blog $rowid
647 err "blog_showentry Finished: `gdate +%S.%03N` ${fetch_ajax:+ajax}"
618 } 648 }
619 649
620 lshandout() { 650 lshandout() {
621 # $1=rowid of blog (numericalized in s4.cgi) 651 # $1=rowid of blog (numericalized in s4.cgi)
622 blog_writable $1 $user 652 blog_writable $1 $user
1520 -D_DUMPTABLE_="syscmd(cat)" -D_DUMPHEAD_="" \ 1550 -D_DUMPTABLE_="syscmd(cat)" -D_DUMPHEAD_="" \
1521 $layout/html.m4.html $layout/form+dump-whead.m4.html 1551 $layout/html.m4.html $layout/form+dump-whead.m4.html
1522 err "blog_reply Finished: `gdate +%S.%03N` user=$user owner=[$owner] title=[$title]" 1552 err "blog_reply Finished: `gdate +%S.%03N` user=$user owner=[$owner] title=[$title]"
1523 } 1553 }
1524 1554
1555 blog_fetch() {
1556 contenttype "text/plain; charset=utf-8"; echo
1557 err blog_fetch: blog "$@"
1558 blog_reply "$@"
1559 # blog_showentry blog "$@"
1560 }
1561
1525 blog_reply_article() { # Direct link to article in some blog 1562 blog_reply_article() { # Direct link to article in some blog
1526 arid=${1:-0} # Already sanitized to digits 1563 arid=${1:-0} # Already sanitized to digits
1527 brid=`query "SELECT rowid FROM blog WHERE \ 1564 brid=`query "SELECT rowid FROM blog WHERE \
1528 id=(SELECT blogid FROM article WHERE rowid=$arid);"` 1565 id=(SELECT blogid FROM article WHERE rowid=$arid);"`
1529 if [ -n "$brid" ]; then 1566 if [ -n "$brid" ]; then

yatex.org