add html
@@ -0,0 +1,13 @@ | ||
1 | +<?php | |
2 | +require_once('includes/config.php'); | |
3 | +require_once('includes/CounterManager.php'); | |
4 | + | |
5 | +function html_count() { | |
6 | + $db = new CounterManager(DB_HOST, DB_NAME, DB_USER, DB_PASSWORD); | |
7 | + if (! $db->connect()) { | |
8 | + // !!! エラーメッセージの表示 | |
9 | + return; | |
10 | + } | |
11 | + return $db->count(); | |
12 | +} | |
13 | +?> |
@@ -0,0 +1,82 @@ | ||
1 | +<?php | |
2 | +/*! | |
3 | + \file | |
4 | + \brief データベース操作 | |
5 | + | |
6 | + \author Satofumi KAMIMURA | |
7 | + | |
8 | + $Id$ | |
9 | + | |
10 | + \todo この、やりすぎなクラスをなんとかする | |
11 | +*/ | |
12 | + | |
13 | +class CounterManager { | |
14 | + var $db_; // コネクション | |
15 | + var $db_name_; | |
16 | + var $db_host_; | |
17 | + var $db_user_; | |
18 | + var $db_password_; | |
19 | + | |
20 | + // データベースの初期化 | |
21 | + function CounterManager($db_host, $db_name, $db_user, $db_password) | |
22 | + { | |
23 | + | |
24 | + $this->db_ = false; | |
25 | + | |
26 | + $this->db_name_ = $db_name; | |
27 | + $this->db_host_ = $db_host; | |
28 | + $this->db_user_ = $db_user; | |
29 | + $this->db_password_ = $db_password; | |
30 | + } | |
31 | + | |
32 | + // データベースへの接続 | |
33 | + function connect() | |
34 | + { | |
35 | + $db = mysql_connect($this->db_host_, $this->db_user_, $this->db_password_); | |
36 | + if (! $db) { | |
37 | + print 'Could not connect: '. mysql_error(); | |
38 | + return false; | |
39 | + } | |
40 | + $this->disconnect(); | |
41 | + $this->db_ = $db; | |
42 | + | |
43 | + if (! mysql_select_db($this->db_name_)) { | |
44 | + $this->disconnect(); | |
45 | + print 'Could not select: '. mysql_error(); | |
46 | + return false; | |
47 | + } | |
48 | + | |
49 | + return true; | |
50 | + } | |
51 | + | |
52 | + // データベースから切断 | |
53 | + function disconnect() | |
54 | + { | |
55 | + if ($this->db_ == false) { | |
56 | + return; | |
57 | + } | |
58 | + mysql_close($this->db_); | |
59 | + $this->db_ = false; | |
60 | + } | |
61 | + | |
62 | + // 投稿キーの取得 | |
63 | + function count() | |
64 | + { | |
65 | + // 値の取得 | |
66 | + $query = "SELECT counter FROM counter"; | |
67 | + $result = mysql_query($query); | |
68 | + if (! $result) { | |
69 | + return 0; | |
70 | + } | |
71 | + $record = mysql_fetch_array($result); | |
72 | + $value = intval($record['counter']) + 1; | |
73 | + mysql_free_result($result); | |
74 | + | |
75 | + // 値の更新 | |
76 | + $query = "UPDATE counter SET counter=$value"; | |
77 | + $result = mysql_query($query); | |
78 | + | |
79 | + return $value; | |
80 | + } | |
81 | +} | |
82 | +?> |
@@ -0,0 +1,179 @@ | ||
1 | +<?php | |
2 | +/*! | |
3 | + \file | |
4 | + \brief 共通処理 | |
5 | + | |
6 | + \author Satofumi KAMIMURA | |
7 | + | |
8 | + $Id$ | |
9 | +*/ | |
10 | + | |
11 | + | |
12 | +// 投稿フォームの表示 | |
13 | +function bbs_commitForm($commit_key, $default = array(), $valid = false, | |
14 | + $page = 0) | |
15 | +{ | |
16 | + // !!! 削除用パスワードの欄には、"英数字(8文字以内)" なんかのデフォルト表示をしたい | |
17 | + | |
18 | + $disabled = (! $valid) ? 'disabled' : ''; | |
19 | + | |
20 | + $tag_array = array('name', 'title', 'message', 'pass'); | |
21 | + $tag = array(); | |
22 | + foreach ($tag_array as $key) { | |
23 | + // 名前の取り出し | |
24 | + if (isset($default[$key])) { | |
25 | + $tag[$key] = htmlspecialchars($default[$key], ENT_QUOTES); | |
26 | + } else { | |
27 | + $tag[$key] = ''; | |
28 | + } | |
29 | + } | |
30 | + $name = $tag['name']; | |
31 | + $title = $tag['title']; | |
32 | + $message = $tag['message']; | |
33 | + $pass = $tag['pass']; | |
34 | + $commit_key = htmlspecialchars($commit_key, ENT_QUOTES); | |
35 | + $parent_id = isset($default['parent_id']) ? intval($default['parent_id']) : 0; | |
36 | + $page = intval($page); | |
37 | + | |
38 | + $output = <<<EOB | |
39 | +<div id="bbs_commit"> | |
40 | +<form method="post" action="#bbs_top?page=$page"> | |
41 | +<table> | |
42 | +<tr><th>Name</th><td><input type="text" name="name" value="$name" size="16"></input></td></tr> | |
43 | +<tr><th>Title</th><td><input type="text" name="title" value="$title" size="32"></input></td></tr> | |
44 | +<tr><th>Message</th><td><textarea name="message" rows="4" cols="53" value="$message">$message</textarea></td></tr> | |
45 | +<tr><th>Pass</th><td><input type="password" name="pass" value="$pass" size="8"></input> | |
46 | +<input type="submit" name="test" value="テスト"> | |
47 | +<input type="submit" name="submit" value="書き込む" $disabled> | |
48 | +</td></tr> | |
49 | +</table> | |
50 | +<input type="hidden" name="commit_key" value="$commit_key"> | |
51 | +<input type="hidden" name="parent_id" value="$parent_id"> | |
52 | +</form> | |
53 | +</div> | |
54 | +EOB; | |
55 | + | |
56 | + return $output; | |
57 | +} | |
58 | + | |
59 | + | |
60 | +function bbs_parseCommitted($post) | |
61 | +{ | |
62 | + $article = array(); | |
63 | + | |
64 | + if ((! isset($post['submit'])) && (! isset($post['test']))) { | |
65 | + // 投稿がない場合 | |
66 | + $article['error_message'] = 'O.K.'; | |
67 | + return $article; | |
68 | + } | |
69 | + | |
70 | + $error_message = ''; | |
71 | + | |
72 | + // !!! foreach でまわすべきか? | |
73 | + | |
74 | + // 名前の格納 | |
75 | + if (isset($post['name']) && strlen($post['name'])) { | |
76 | + $article['name'] = $post['name']; | |
77 | + } else { | |
78 | + $error_message .= "名前が入力されていません。"; | |
79 | + $article['name'] = ''; | |
80 | + } | |
81 | + | |
82 | + // タイトルの格納 | |
83 | + if (isset($post['title']) && strlen($post['title'])) { | |
84 | + $article['title'] = $post['title']; | |
85 | + } else { | |
86 | + $error_message .= "タイトルが入力されていません。"; | |
87 | + $article['title'] = ''; | |
88 | + } | |
89 | + | |
90 | + // メッセージの格納 | |
91 | + if (isset($post['message']) && strlen($post['message'])) { | |
92 | + $article['message'] = $post['message']; | |
93 | + } else { | |
94 | + $error_message .= "メッセージがありません。"; | |
95 | + $article['message'] = ''; | |
96 | + } | |
97 | + | |
98 | + // パスの格納 | |
99 | + if (isset($post['pass'])) { | |
100 | + $article['pass'] = $post['pass']; | |
101 | + } else { | |
102 | + // パスがなくても、投稿を許可する | |
103 | + } | |
104 | + | |
105 | + // キーの格納 | |
106 | + if (isset($post['commit_key'])) { | |
107 | + $article['commit_key'] = $post['commit_key']; | |
108 | + } else { | |
109 | + $error_message .= " "; | |
110 | + $article['commit_key'] = ''; | |
111 | + } | |
112 | + | |
113 | + // parend_id の格納 | |
114 | + if (isset($post['parent_id'])) { | |
115 | + $article['parent_id'] = $post['parent_id']; | |
116 | + } | |
117 | + | |
118 | + // エラーメッセージがあれば、追加する | |
119 | + if (strlen($error_message) > 0) { | |
120 | + $article['error_message'] = $error_message; | |
121 | + } | |
122 | + | |
123 | + return $article; | |
124 | +} | |
125 | + | |
126 | + | |
127 | +// 記事の表示テーブル作成 | |
128 | +function bbs_createArticleTable($article, $page = 0) | |
129 | +{ | |
130 | + foreach ($article as $key => $value) { | |
131 | + $article[$key] = htmlspecialchars($value, ENT_QUOTES); | |
132 | + } | |
133 | + | |
134 | + if (! isset($article['time'])) { | |
135 | + $article['time'] = time(); | |
136 | + } | |
137 | + $date = date("Y-m-d", $article['time']); | |
138 | + $time = date("H:i", $article['time']); | |
139 | + $title = $article['title']; | |
140 | + $message = str_replace("\n", "<br>\n", trim($article['message'])); | |
141 | + $name = $article['name']; | |
142 | + $id = isset($article['article_id']) ? $article['article_id'] : ' TEST '; | |
143 | + $page = intval($page); | |
144 | + | |
145 | + $output = <<<EOB | |
146 | +<a name="$id"></a> | |
147 | +<table> | |
148 | +<tr><th width="60%" align="left">$title</th><th class="reply" width="35%" align="center">$date $time</th><th class="reply" width="5%" align="center"><a href="bbs.php?id=$id&page=$page">Reply</a></th></tr> | |
149 | +<tr><td colspan="3"><b>$name</b><br>$message<br><br><div align="right">[$id]</a></td></tr> | |
150 | +</table> | |
151 | +EOB; | |
152 | + return $output; | |
153 | +} | |
154 | + | |
155 | +function bbs_createRemoveForm() { | |
156 | + $output = <<<EOB | |
157 | +<form method="POST" action=""> | |
158 | +<table> | |
159 | +<tr><th>Message ID</th><td><input type="text" name="article_id" size="4"></input></td></tr> | |
160 | +<tr><th>Pass</th><td><input type="password" name="delete_key" size="8"></input> | |
161 | +<input type="submit" name="remove" value="削除"></td></tr> | |
162 | +</table> | |
163 | +</form> | |
164 | +EOB; | |
165 | + | |
166 | + return $output; | |
167 | +} | |
168 | + | |
169 | +// ページリンクの作成 | |
170 | +function bbs_createPageLink($page_max) | |
171 | +{ | |
172 | + $output = '<div id="bbs_pagelink">Page. '; | |
173 | + for ($i = 0; $i <= $page_max; ++$i) { | |
174 | + $output .= '<a href="bbs.php?page='. $i. '">['. ($i + 1). ']</a> '; | |
175 | + } | |
176 | + $output .= '</div>'; | |
177 | + return $output; | |
178 | +} | |
179 | +?> |
@@ -0,0 +1,283 @@ | ||
1 | +<?php | |
2 | +/*! | |
3 | + \file | |
4 | + \brief データベース操作 | |
5 | + | |
6 | + \author Satofumi KAMIMURA | |
7 | + | |
8 | + $Id$ | |
9 | + | |
10 | + \todo 記事番号の指定で、記事のあるページに移動できるようにする | |
11 | +*/ | |
12 | + | |
13 | +class AccessDatabase { | |
14 | + var $db_; // コネクション | |
15 | + var $db_name_; | |
16 | + var $db_host_; | |
17 | + var $db_user_; | |
18 | + var $db_password_; | |
19 | + | |
20 | + // データベースの初期化 | |
21 | + function AccessDatabase($db_host, $db_name, $db_user, $db_password) | |
22 | + { | |
23 | + | |
24 | + $this->db_ = false; | |
25 | + | |
26 | + $this->db_name_ = $db_name; | |
27 | + $this->db_host_ = $db_host; | |
28 | + $this->db_user_ = $db_user; | |
29 | + $this->db_password_ = $db_password; | |
30 | + } | |
31 | + | |
32 | + // データベースへの接続 | |
33 | + function connect() | |
34 | + { | |
35 | + $db = mysql_connect($this->db_host_, $this->db_user_, $this->db_password_); | |
36 | + if (! $db) { | |
37 | + print 'Could not connect: '. mysql_error(); | |
38 | + return false; | |
39 | + } | |
40 | + $this->disconnect(); | |
41 | + $this->db_ = $db; | |
42 | + | |
43 | + if (! mysql_select_db($this->db_name_)) { | |
44 | + $this->disconnect(); | |
45 | + print 'Could not select: '. mysql_error(); | |
46 | + return false; | |
47 | + } | |
48 | + | |
49 | + return true; | |
50 | + } | |
51 | + | |
52 | + // データベースから切断 | |
53 | + function disconnect() | |
54 | + { | |
55 | + if ($this->db_ == false) { | |
56 | + return; | |
57 | + } | |
58 | + mysql_close($this->db_); | |
59 | + $this->db_ = false; | |
60 | + } | |
61 | + | |
62 | + // 投稿キーの取得 | |
63 | + function getCommitKey() | |
64 | + { | |
65 | + // 投稿キーの生成と登録 | |
66 | + $time = time(); | |
67 | + $key = mysql_escape_string(crypt($time, rand(0, 999))); | |
68 | + | |
69 | + $query = "INSERT INTO commit_key (access_time, access_key) VALUES ($time, '$key')"; | |
70 | + mysql_query($query); | |
71 | + | |
72 | + // 古くなった投稿キーを削除 | |
73 | + $compare_time = time() - (60 * 60); | |
74 | + $query = "DELETE from commit_key WHERE access_time<$compare_time"; | |
75 | + mysql_query($query); | |
76 | + | |
77 | + return $key; | |
78 | + } | |
79 | + | |
80 | + // スレッド情報の取得 | |
81 | + function getThreadList() | |
82 | + { | |
83 | + return array(); | |
84 | + } | |
85 | + | |
86 | + // 最大ページ数の取得 | |
87 | + function getPageMax() | |
88 | + { | |
89 | + return -1; | |
90 | + } | |
91 | + | |
92 | + // 指定範囲の記事を取得 | |
93 | + function getArticles($page, $view_articles) | |
94 | + { | |
95 | + $query = "SELECT thread_id FROM modified_thread ORDER BY modified_time DESC"; | |
96 | + $result = mysql_query($query); | |
97 | + if (! $result) { | |
98 | + return array(array(), 0); | |
99 | + } | |
100 | + | |
101 | + $threads = array(); | |
102 | + while ($record = mysql_fetch_array($result)) { | |
103 | + array_push($threads, intval($record['thread_id'])); | |
104 | + } | |
105 | + mysql_free_result($result); | |
106 | + | |
107 | + // 指定されたページの記事のみを返す | |
108 | + $page_counter = 0; | |
109 | + $article_counter = 0; | |
110 | + $articles = array(); | |
111 | + $have_article = false; | |
112 | + foreach ($threads as $thread_id) { | |
113 | + $thread_articles = $this->getThreadArticle($thread_id); | |
114 | + $article_counter += count($thread_articles); | |
115 | + | |
116 | + if ($page == $page_counter) { | |
117 | + // 記事の登録 | |
118 | + array_push($articles, $thread_articles); | |
119 | + $have_article = true; | |
120 | + } | |
121 | + | |
122 | + if ($article_counter >= $view_articles) { | |
123 | + if (count($thread_articles) > 0) { | |
124 | + ++$page_counter; | |
125 | + $article_counter = 0; | |
126 | + $have_article = false; | |
127 | + } | |
128 | + } | |
129 | + } | |
130 | + | |
131 | + // 最後のページが空だったら、ページの最大番号を1つ戻す | |
132 | + if (($page_counter > 0) && (! $have_article)) { | |
133 | + --$page_counter; | |
134 | + } | |
135 | + | |
136 | + return array($articles, $page_counter); | |
137 | + } | |
138 | + | |
139 | + // スレッド毎の記事の取得 | |
140 | + function getThreadArticle($thread_id) | |
141 | + { | |
142 | + $query = "SELECT article_id, user_name as name, article_pass as pass, article_title as title, article_text as message, commit_time as time FROM article WHERE active!=0 and (thread_id=$thread_id or article_id=$thread_id) ORDER BY article_id"; // DESC | |
143 | + $result = mysql_query($query); | |
144 | + if (! $result) { | |
145 | + return array(); | |
146 | + } | |
147 | + | |
148 | + $articles = array(); | |
149 | + | |
150 | + while ($record = mysql_fetch_array($result)) { | |
151 | + array_push($articles, $record); | |
152 | + } | |
153 | + mysql_free_result($result); | |
154 | + | |
155 | + return $articles; | |
156 | + } | |
157 | + | |
158 | + // 記事の登録処理 | |
159 | + function commitArticle($article) | |
160 | + { | |
161 | + // 登録キーの検索 | |
162 | + $commit_key = mysql_escape_string($article['commit_key']); | |
163 | + $query = "SELECT access_time FROM commit_key WHERE access_key='$commit_key'"; | |
164 | + $result = mysql_query($query); | |
165 | + if (! $result) { | |
166 | + // 0 で登録させてしまう | |
167 | + $access_time = '0'; | |
168 | + } else { | |
169 | + $record = mysql_fetch_array($result); | |
170 | + $access_time = $record['access_time']; | |
171 | + mysql_free_result($result); | |
172 | + | |
173 | + // 登録キーの削除 | |
174 | + $query = "DELETE from commit_key WHERE commit_key='$commit_key'"; | |
175 | + mysql_query($query); | |
176 | + } | |
177 | + | |
178 | + // 登録年月日 | |
179 | + $commit_time = time(); | |
180 | + $user_name = mysql_escape_string($article['name']); | |
181 | + $article_pass = mysql_escape_string($article['pass']); | |
182 | + $article_title = mysql_escape_string($article['title']); | |
183 | + $article_text = mysql_escape_string($article['message']); | |
184 | + | |
185 | + $query = "INSERT INTO article (active, commit_time, access_time, user_name, article_pass, article_title, article_text) VALUES (1, $commit_time, $access_time, '$user_name', '$article_pass', '$article_title', '$article_text')"; | |
186 | + mysql_query($query); | |
187 | + | |
188 | + // スレッド情報の登録 | |
189 | + $article_id = mysql_insert_id(); | |
190 | + $parent_id = intval($article['parent_id']); | |
191 | + $query = "SELECT thread_id FROM article WHERE article_id=$parent_id"; | |
192 | + $result = mysql_query($query); | |
193 | + if (! $result) { | |
194 | + $parent_id = 0; | |
195 | + return; | |
196 | + } | |
197 | + if (mysql_num_rows($result) == 1) { | |
198 | + // 返信の場合、親の thread_id と同じ thread_id で登録する | |
199 | + $record = mysql_fetch_array($result); | |
200 | + $thread_id = intval($record['thread_id']); | |
201 | + } else { | |
202 | + $parent_id = 0; | |
203 | + // そうでなければ、thread_id は article_id として登録する | |
204 | + $thread_id = $article_id; | |
205 | + } | |
206 | + $query = "UPDATE article SET thread_id=$thread_id, parent_id=$parent_id WHERE article_id=$article_id"; | |
207 | + mysql_query($query); | |
208 | + | |
209 | + // スレッド情報の更新 | |
210 | + $now = time(); | |
211 | + $query = "UPDATE modified_thread SET thread_id=$thread_id, modified_time=$now WHERE thread_id=$thread_id"; | |
212 | + if (mysql_query($query)) { | |
213 | + if (mysql_num_rows($result) == 0) { | |
214 | + $query = "INSERT INTO modified_thread (thread_id, modified_time) VALUES ($thread_id, $now)"; | |
215 | + mysql_query($query); | |
216 | + } | |
217 | + } | |
218 | + } | |
219 | + | |
220 | + // 記事の削除 | |
221 | + function deleteArticle($id, $key) | |
222 | + { | |
223 | + $article_id = mysql_escape_string($id); | |
224 | + $article_pass = mysql_escape_string($key); | |
225 | + | |
226 | + $query = "UPDATE article SET active=0 WHERE article_id=$article_id and article_pass='$article_pass'"; | |
227 | + mysql_query($query); | |
228 | + } | |
229 | + | |
230 | + // 返信用のフォームを作る | |
231 | + function getReplyArticle($id, $post) | |
232 | + { | |
233 | + $query = "SELECT article_title as title, article_text as message FROM article WHERE article_id=$id"; | |
234 | + $result = mysql_query($query); | |
235 | + if (! $result) { | |
236 | + return array(); | |
237 | + } | |
238 | + $parent_article = mysql_fetch_array($result); | |
239 | + mysql_free_result($result); | |
240 | + | |
241 | + $article = array(); | |
242 | + $name = isset($_POST['name']) ? $_POST['name'] : ''; | |
243 | + $pass = isset($_POST['pass']) ? $_POST['pass'] : ''; | |
244 | + | |
245 | + $article['name'] = htmlspecialchars($name, ENT_QUOTES); | |
246 | + $article['pass'] = htmlspecialchars($pass, ENT_QUOTES); | |
247 | + $article['title'] = 'Re: '. $parent_article['title']; | |
248 | + //$article['message'] = | |
249 | + //'> '. str_replace("\n", "\n> ", trim($parent_article['message'])); | |
250 | + $article['message'] = ''; | |
251 | + $article['parent_id'] = $id; | |
252 | + $article['error_message'] = '名前、記事、pass の入力をお願いします。'; | |
253 | + | |
254 | + return $article; | |
255 | + } | |
256 | + | |
257 | + // 最近の記事の取得 | |
258 | + function getRecentArticlesAbst($limit) { | |
259 | + $query = "SELECT article_title as title, access_time, user_name, article_id FROM article WHERE active=1 ORDER BY access_time DESC LIMIT $limit"; | |
260 | + $result = mysql_query($query); | |
261 | + if (! $result) { | |
262 | + return array(); | |
263 | + } | |
264 | + | |
265 | + $articles = array(); | |
266 | + while ($record = mysql_fetch_array($result)) { | |
267 | + $title = htmlspecialchars($record['title'], ENT_QUOTES); | |
268 | + $name = htmlspecialchars($record['user_name'], ENT_QUOTES); | |
269 | + $date = date("Y-m-d", $record['access_time']); | |
270 | + $time = date("H:i", $record['access_time']); | |
271 | + $id = intval($record['article_id']); | |
272 | + | |
273 | + array_push($articles, array('title' => $title, | |
274 | + 'name' => $name, | |
275 | + 'datetime' => $date. ' '. $time, | |
276 | + 'id' => $id)); | |
277 | + } | |
278 | + mysql_free_result($result); | |
279 | + | |
280 | + return $articles; | |
281 | + } | |
282 | +}; | |
283 | +?> |
@@ -0,0 +1,209 @@ | ||
1 | +<?php | |
2 | +/*! | |
3 | + \file | |
4 | + \brief 記事の閲覧 | |
5 | + | |
6 | + \author Satofumi KAMIMURA | |
7 | + | |
8 | + $Id$ | |
9 | + | |
10 | + \todo Reply の記事対応を適切にし、インデントを行う | |
11 | + \todo 記事部分を完全に独立させて、使いやすいようにする | |
12 | +*/ | |
13 | + | |
14 | +require_once('includes/config.php'); | |
15 | +require_once('includes/bbs_functions.php'); | |
16 | +require_once('includes/AccessBbsData.php'); | |
17 | + | |
18 | +define('PAGE_ARTICLE_NUM', 6); | |
19 | + | |
20 | + | |
21 | +// スレッド情報の作成 | |
22 | +function echoThreadText($thread) | |
23 | +{ | |
24 | + if (count($thread) <= 0) { | |
25 | + print <<<EOB | |
26 | +<div id="bbs_thread"> | |
27 | +<ul> | |
28 | +<li>スレッドなし</li> | |
29 | +</ul> | |
30 | +</div> | |
31 | +EOB; | |
32 | + } else { | |
33 | + // !!! | |
34 | + } | |
35 | +} | |
36 | + | |
37 | + | |
38 | +// 記事を整形して表示 | |
39 | +function echoArticles($articles) | |
40 | +{ | |
41 | + if (count($articles) <= 0) { | |
42 | + print <<<EOB | |
43 | +<div id="bbs_article"> | |
44 | +<ul> | |
45 | +<li>投稿なし</li> | |
46 | +</ul> | |
47 | +</div> | |
48 | +EOB; | |
49 | + } else { | |
50 | + print '<div id="bbs_article">'; | |
51 | + foreach ($articles as $each_thread) { | |
52 | + // !!! 汚いな... | |
53 | + $i = 0; | |
54 | + $n = count($each_thread); | |
55 | + if ($n > 1) { | |
56 | + print '<table><tr><td>'; | |
57 | + } | |
58 | + foreach ($each_thread as $each_article) { | |
59 | + echo bbs_createArticleTable($each_article); | |
60 | + if ($i != ($n - 1)) { | |
61 | + echo '<br>'; | |
62 | + } | |
63 | + ++$i; | |
64 | + } | |
65 | + if ($n > 1) { | |
66 | + print '</td></tr></table>'; | |
67 | + } | |
68 | + print '<br>'; | |
69 | + } | |
70 | + print '</div>'; | |
71 | + } | |
72 | +} | |
73 | + | |
74 | +// メイン処理 //////////////////////////////////////// | |
75 | + | |
76 | +// データベースに接続 | |
77 | +$db = new AccessDatabase(DB_HOST, DB_NAME, DB_USER, DB_PASSWORD); | |
78 | +if (! $db->connect()) { | |
79 | + // !!! エラーメッセージの表示 | |
80 | + return; | |
81 | +} | |
82 | + | |
83 | + | |
84 | +// 表示するページの取得 | |
85 | +$page = 0; | |
86 | +if (isset($_GET['page'])) { | |
87 | + $page = intval($_GET['page']); | |
88 | +} | |
89 | + | |
90 | +// 記事の削除 | |
91 | +if (isset($_POST['remove']) && | |
92 | + isset($_POST['article_id']) && | |
93 | + isset($_POST['delete_key'])) { | |
94 | + $delete_key = $_POST['delete_key']; | |
95 | + $article_id = intval($_POST['article_id']); | |
96 | + $db->deleteArticle($article_id, $delete_key); | |
97 | + | |
98 | + header('Location: bbs.php'); | |
99 | +} | |
100 | + | |
101 | +$test_article = bbs_parseCommitted($_POST); | |
102 | + | |
103 | +if (isset($_POST['test'])) { | |
104 | + // テスト投稿の場合、その情報を取得 | |
105 | + $commit_key = $test_article['commit_key']; | |
106 | + | |
107 | +} else if (isset($_POST['submit']) && | |
108 | + (! isset($test_article['error_message']))) { | |
109 | + // 投稿の場合、登録処理 | |
110 | + $db->commitArticle($test_article); | |
111 | + header('Location: bbs.php'); | |
112 | + | |
113 | +} else if (isset($_GET['id'])) { | |
114 | + // Reply の場合、その記事を引用した入力フォームを作る | |
115 | + $commit_key = $db->getCommitKey(); | |
116 | + $id = intval($_GET['id']); | |
117 | + $test_article = $db->getReplyArticle($id, $_POST); | |
118 | + | |
119 | +} else { | |
120 | + // 通常の閲覧 | |
121 | + $test_article = array(); | |
122 | + $test_article['error_message'] = ''; | |
123 | + | |
124 | + // システムからキーを取得 | |
125 | + $commit_key = $db->getCommitKey(); | |
126 | +} | |
127 | + | |
128 | + | |
129 | +// スレッド情報の取得 | |
130 | +$threads = $db->getThreadList(); | |
131 | + | |
132 | +// ページ情報の取得 | |
133 | +$page_max = $db->getPageMax(); | |
134 | + | |
135 | +// 記事の取得 | |
136 | +list($articles, $page_max) = $db->getArticles($page, PAGE_ARTICLE_NUM); | |
137 | + | |
138 | + | |
139 | +// 表示処理 //////////////////////////////////////// | |
140 | +?> | |
141 | +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | |
142 | +<html xmlns="http://www.w3/org/1999/xhtml" xml:lang="ja" lang="ja"> | |
143 | +<head> | |
144 | +<meta http-equiv="Content-Type" content="text/html; charset=euc-jp"> | |
145 | +<title>漢字対戦: 掲示板</title> | |
146 | +<link rel="stylesheet" type="text/css" href="kanjiwar.css" title="kanjiwar" media="screen,tv"/> | |
147 | +<link rel="SHORTCUT ICON" href="favicon.ico"> | |
148 | +</head> | |
149 | +<body> | |
150 | + | |
151 | +<h2>掲示板<a name="bbs_top"></a></h2> | |
152 | +<?php | |
153 | +// _GET[], _POST[] が空の場合のみ、最近の書き込みを表示する | |
154 | +if ((count($_POST) == 0) && (count($_GET) == 0)) { | |
155 | + $recent_articles = $db->getRecentArticlesAbst(3); | |
156 | + if (count($recent_articles) > 0) { | |
157 | + print '最近の書き込み'; | |
158 | + print '<ul>'; | |
159 | + | |
160 | + foreach ($recent_articles as $article) { | |
161 | + $id = $article['id']; | |
162 | + print '<li>'. $article['datetime']. | |
163 | + ' <b>'. $article['name']. '</b> <a href="#'. $id. '">「'. $article['title']. '」</a></li>'; | |
164 | + } | |
165 | + | |
166 | + print '</ul>'; | |
167 | + } | |
168 | +} | |
169 | +?> | |
170 | +</div> | |
171 | +<?php | |
172 | +// テスト投稿の内容と、エラーメッセージを表示 | |
173 | +if (isset($_POST['test']) || isset($_GET['id'])) { | |
174 | + print '<div">'; | |
175 | + echo bbs_createArticleTable($test_article); | |
176 | + print '<br></div>'; | |
177 | + | |
178 | + if (isset($test_article['error_message'])) { | |
179 | + echo htmlspecialchars($test_article['error_message'], ENT_QUOTES); | |
180 | + } | |
181 | +} | |
182 | + | |
183 | +// 投稿フォームの表示 | |
184 | +$valid = isset($test_article['error_message']) ? false : true; | |
185 | +echo bbs_commitForm($commit_key, $test_article, $valid, $page); | |
186 | + | |
187 | +echo '<br>'; | |
188 | + | |
189 | +// 記事の表示 | |
190 | +echoArticles($articles); | |
191 | + | |
192 | +// ページ用リンクの表示 | |
193 | +echo bbs_createPageLink($page_max); | |
194 | +echo '<br>'; | |
195 | + | |
196 | +echo '<hr>'; | |
197 | +echo bbs_createRemoveForm(); | |
198 | +?> | |
199 | +<!-- | |
200 | +<div> | |
201 | +<p>!!! 最近のコメント</p> --> | |
202 | +<?php | |
203 | +// スレッド情報の表示 | |
204 | +//echoThreadText($threads); | |
205 | +?> | |
206 | +<div id="footer"> | |
207 | +</div> | |
208 | +</body> | |
209 | +</html> |
@@ -0,0 +1,36 @@ | ||
1 | +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | |
2 | +<html xmlns="http://www.w3/org/1999/xhtml" xml:lang="ja" lang="ja"> | |
3 | +<head> | |
4 | +<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | |
5 | +<title>kanjiwar: 漢字対戦</title> | |
6 | +<link rel="stylesheet" type="text/css" href="kanjiwar.css" title="kanjiwar" media="screen,tv"/> | |
7 | +<link rel="SHORTCUT ICON" href="favicon.ico"> | |
8 | +</head> | |
9 | +<body> | |
10 | + | |
11 | +<div id="wrapper"> | |
12 | + | |
13 | +<div id="sourceforge"> | |
14 | +<a href="http://sourceforge.jp/"><img src="http://sourceforge.jp/sflogo.php?group_id=3542" width="96" height="31" border="0" alt="SourceForge.JP"></a> | |
15 | +<?php | |
16 | +require_once('counter.php'); | |
17 | +$counter_text = sprintf("%08d", html_count()); | |
18 | +print '<table width="120px"><tr><td>'; | |
19 | +for ($i = 0; $i < strlen($counter_text); ++$i) { | |
20 | + $number = $counter_text[$i]; | |
21 | + print '<img src="img/'. $number. '.gif">'; | |
22 | +} | |
23 | +print '</td></tr></table>'; | |
24 | +?> | |
25 | +</div> | |
26 | + | |
27 | +<p>!!! タイトルロゴ</p> | |
28 | + | |
29 | +<p> | |
30 | +!!! これはなにか | |
31 | +</p> | |
32 | +<p></p> | |
33 | + | |
34 | +<a href="bbs.php">掲示板</a> | |
35 | +</body> | |
36 | +</html> |
@@ -0,0 +1,27 @@ | ||
1 | +# Makefile for kanjiwar | |
2 | +# Satofumi KAMIMURA | |
3 | +# $Id$ | |
4 | + | |
5 | +all : | |
6 | + | |
7 | +clean : | |
8 | + ${RM} -rf output_html/* | |
9 | + | |
10 | +depend : | |
11 | + | |
12 | +upload : html | |
13 | + rsync -avz -e ssh --delete output_html/* shell.sourceforge.jp:/home/groups/k/ka/kanjiwar/htdocs/ | |
14 | + | |
15 | +html : html_copy | |
16 | + | |
17 | +html_copy : | |
18 | + if ! test -d output_html/includes; then mkdir output_html/includes; fi | |
19 | + cp html/*.php html/*.css output_html/ | |
20 | + -cp html/includes/.htaccess html/includes/AccessBbsData.php html/includes/bbs_functions.php html/includes/CounterManager.php output_html/includes/ | |
21 | + -cp ~/sourceforge/kanjiwar/config.php output_html/includes/ | |
22 | + if ! test -d output_html/img; then mkdir output_html/img; fi | |
23 | + cp html/img/*.gif output_html/img/ | |
24 | + | |
25 | + | |
26 | +.PHONY : all clean depend upload html html_copy | |
27 | +###################################################################### |