simplebbs.html
simplebbs.html
できるだけシンプルにテンプレートとなるHTMLを作成しました。
<?xml version="1.0" encoding="euc-jp"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xml:lang="ja" dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=euc-jp" />
<title>SimpleBBS 0.1.0</title>
</head>
<body>
<h1>SimpleBBS 0.1.0</h1>
<h2>書き込みフォーム</h2>
<div>
( message )
<form action="simplebbs.cgi" method="post">
<div>
<dl>
<dt>Name</dt>
<dd><input type="text" name="name" value="( name )" /></dd>
<dt>Title</dt>
<dd><input type="text" name="title" value="( title )" /></dd>
<dt>Comment</dt>
<dd><textarea name="comment" cols="30" rows="5"></textarea></dd>
<dt>Write</dt>
<dd>
<input type="submit" value="OK" />
<input type="reset" value="Reset" />
</dd>
</dl>
<input type="hidden" name="mode" value="post" />
</div>
</form>
</div>
<h2>記事一覧</h2>
<div>
<dl>
<!-- noarticle_begin -->
<dt>
記事はありません。
</dt>
<!-- noarticle_end -->
<!-- article_begin -->
<dt>( article_title ) by ( article_name ) at ( article_date )</dt>
<dd>( article_comment )</dd>
<!-- article_end -->
</dl>
</div>
<div>
<a href="http://validator.w3.org/check/referer">XHTML 1.1 Valid!</a><br />
<a href="https://linux-life.net/program/ruby/cgidoc/bbs/simplebbs/">SimpleBBS</a>
<a href="https://linux-life.net/program/ruby/cgidoc/bbs/simplebbs/0.1.0/">0.1.0</a>
</div>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xml:lang="ja" dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=euc-jp" />
<title>SimpleBBS 0.1.0</title>
</head>
<body>
<h1>SimpleBBS 0.1.0</h1>
<h2>書き込みフォーム</h2>
<div>
( message )
<form action="simplebbs.cgi" method="post">
<div>
<dl>
<dt>Name</dt>
<dd><input type="text" name="name" value="( name )" /></dd>
<dt>Title</dt>
<dd><input type="text" name="title" value="( title )" /></dd>
<dt>Comment</dt>
<dd><textarea name="comment" cols="30" rows="5"></textarea></dd>
<dt>Write</dt>
<dd>
<input type="submit" value="OK" />
<input type="reset" value="Reset" />
</dd>
</dl>
<input type="hidden" name="mode" value="post" />
</div>
</form>
</div>
<h2>記事一覧</h2>
<div>
<dl>
<!-- noarticle_begin -->
<dt>
記事はありません。
</dt>
<!-- noarticle_end -->
<!-- article_begin -->
<dt>( article_title ) by ( article_name ) at ( article_date )</dt>
<dd>( article_comment )</dd>
<!-- article_end -->
</dl>
</div>
<div>
<a href="http://validator.w3.org/check/referer">XHTML 1.1 Valid!</a><br />
<a href="https://linux-life.net/program/ruby/cgidoc/bbs/simplebbs/">SimpleBBS</a>
<a href="https://linux-life.net/program/ruby/cgidoc/bbs/simplebbs/0.1.0/">0.1.0</a>
</div>
</body>
</html>
上のHTMLの太字の部分をスクリプトで加工していきます。
- ( message )
-
メッセージ部分です。
- 書き込み以外
- 「ご自由に書き込んで下さい。」
- 書き込み成功
- 「書き込みありがとうございました。」
- 書き込み失敗
- エラーメッセージ
- ( name )
- 入力された名前、クッキーに保存されているもの、空白の優先順で置換します。
- ( title )
- エラー時は入力されたもの、それ以外は空白で置換します。
- <!-- noarticle_begin --> 〜 <!-- noarticle_end -->
- 記事がまだ1つもないときに表示させます。
- <!-- article_begin --> 〜 <!-- article_end -->
-
記事用のブロックです。くり返し使います。
- ( article_name )
- 投稿者名です。
- ( article_title )
- タイトルです。
- ( article_date )
- 投稿日時です。
- ( article_comment )
- 投稿内容です。
「(」の右と「)」の左にはタブが入っています。 これによってユーザーが入力した文字列内に置換用の文字列が入ることを阻止できます。