<?php
//===================初始设置=====================
$title = "留言板"; // 头部文字
$data_max = 100; // 页面最大值
$page_view = 5; // 最大页数
$data_file = "./bbs.log"; // 数据文件
$now = date("Y/m/d H:i"); // 时间设置
//================================================
if(!isset($HTTP_USER_AGENT)){
$http_user_agent = $_SERVER['HTTP_USER_AGENT'];
}else{
$http_user_agent = $HTTP_USER_AGENT;
}
if(!isset($PHP_SELF)){ $PHP_SELF = $_SERVER["PHP_SELF"]; }
if(!isset($flag)){ $flag = $_GET['flag']; }
if(!isset($re_sub)){ $re_sub = $_POST['re_sub']; }
if(!isset($code)){
if($_POST['code']){
$code = $_POST['code'];
}else{
$code = $_GET['code'];
}
}
if(!isset($action)){
if($_POST['action']){
$action = $_POST['action'];
}else{
$action = $_GET['action'];
}
}
if(!isset($ress)){ $ress = $_POST['ress']; }
if(!isset($name)){ $name = $_POST['name']; }
if (!$name) $name = "匿名";
if(!isset($comment)){ $comment = $_POST['comment']; }
if(!isset($view_code)){ $view_code = $_GET['view_code']; }
if(!isset($pline)){ $pline = $_GET['pline']; }
$name = stripslashes($name);
$comment = stripslashes($comment);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="ja">
<head>
<title>留言板</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<link rel="stylesheet" href="bbs.css" type="text/css" media="all">
</head>
<body>
<?php
function inline_link($link){
$link = ereg_replace("(https?|ftp|news)(://[[:alnum:]\+\$\;\?\.%,!#~*/:@&=_-]+)","<a href=\"\\1\\2\" target=\"_blank\">\\1\\2</a>",$link);
return $link;
}
if($action == "regist"){
if($name){
$code = time();
$host = getenv("REMOTE_HOST");
$addr = getenv("REMOTE_ADDR");
if($host == "" || $host ==$addr){
$host = gethostbyaddr($addr);
}
if($keitai_flag){
$name = urldecode($name);
$comment = urldecode($comment);
}
$name = htmlspecialchars($name);
$comment = htmlspecialchars($comment);
$comment = nl2br($comment);
$comment = str_replace("\r", "", $comment);
$comment = str_replace("\n", "", $comment);
$ress = str_replace(",", ",",$ress);
$name = str_replace(",", ",",$name);
$comment = str_replace(",", ",",$comment);
$comment = inline_link($comment);
$message = file($data_file);
$fname = str_replace(",", ",",$fname);
$input_msg = implode(",", array($code,$ress,$name,$comment,$now,$host));
$fp = fopen($data_file, "w");
rewind($fp);
fputs($fp, "$input_msg\n");
if(($data_max * 1.2) < sizeof($message)){
$msg_num = $data_max - 1;
}else{
$msg_num = sizeof($message);
}
for($i = 0; $i < $msg_num; $i++){
fputs($fp, $message[$i]);
}
fclose($fp);
unset($message);
}
if($keitai_flag){
echo "<a href=$PHP_SELF>返回</a><br>\n";
}else{
echo "<META HTTP-EQUIV=refresh CONTENT=0;URL=$PHP_SELF>\n";
}
}elseif($action == "toroku"){
echo "
<div id=\"wrapper\">
<div id=\"inner\">
<h1>$title</h1>
<div class=\"blue\"><a href=$PHP_SELF> ←返回</a></div><BR>
<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"700\" align=\"center\">
<tr>
<td valign=\"top\">
<FORM ACTION=$PHP_SELF METHOD=POST>\n";
echo "<input type=hidden name=action value=regist>";
echo "<INPUT TYPE=TEXT NAME=name>标题<BR><BR>\n";
echo "<TEXTAREA NAME=comment ROWS=10 COLS=60></TEXTAREA><BR><BR>\n";
if($flag == 'return'){
echo "<div class=\"click\"><input type=\"image\" src=\"img/next.gif\" ></div><br><br><br><br>\n";
echo "<input type=hidden name=ress value=$code>
</td>
</tr>
</table>
<br>
\n";
}else{
echo "<div class=\"click\"><input type=\"image\" src=\"img/next.gif\" ></div>
<br>
</td>
</tr>
</table>
<br>
</div><!--//#inner-->
</div><!--//#wrapper-->
\n";
}
}elseif($action == "view"){
$message = file($data_file);
for($i=0; $i<sizeof($message); $i++){
list($code,$ress,$name,$email,$hp,$subject,$comment,$pass,$now,$host,$agent) = split(",", $message[$i]);
if($code == $view_code){
if($ress == ""){
echo "<a href=$PHP_SELF?action=toroku&code=$code&flag=return>回复</a><br>\n";
}
echo "<a href=$PHP_SELF>返回</a>\n";
}
}
unset($message);
}else{
echo "
<div id=\"wrapper\">
<div id=\"inner\">
<h1>$title</h1>
<form method=POST action=$PHP_SELF>\n";
echo " <div class=\"click\"><input type=\"image\" src=\"img/comment.gif\" ></div><hr>\n";
echo "<input type=hidden name=action value=toroku>\n";
echo "</form>\n";
$message = file($data_file);
for($i=0; $i<sizeof($message); $i++){
list($code,$ress,$name,$comment,$now,$host) = split(",", $message[$i]);
if($ress == ""){
$PARENT[] = $message[$i];
}
}
$msg_count = count($PARENT);
if($pline == ""){
$p_line = 0;
}else{
$p_line = $pline;
}
$end_data = $msg_count - 1;
$page_end = $p_line + ($page_view - 1);
if($page_end >= $end_data){
$page_end = $end_data;
}
for($i=$p_line; $i<=$page_end; $i++){
list($code2,$ress2,$name2,$comment2,$now2,$host2) = split(",", $PARENT[$i]);
echo "
<br><br>
<table class=\"bl\"><tr><td><div class=\"a\"><div class=\"b\"><div class=\"c\"><div class=\"d\">
<a href=$PHP_SELF?action=toroku&code=$code2&flag=return><b>回复</b></a> <b>$name2</b><br><br>\n";
echo $comment2 . "<br><br>\n";
echo "$now2<br></div></div></div></div></td></tr></table>\n";
for($j=0; $j<sizeof($message); $j++){
list($code3,$ress3,$name3,$comment3,$now3,$host3) = split(",", $message[$j]);
if($code2 == $ress3){
echo "
<table class=\"gr\"><tr><td><div class=\"a\"><div class=\"b\"><div class=\"c\"><div class=\"d\">
<b>$name3</b><br><br>\n";
echo $comment3 . "<br><br>\n";
echo "$now3<br></div></div></div></div></td></tr></table>\n";
}
}
}
if($page_end >= $page_view){
$page_count = floor($page_end / $page_view);
$prev_line = ($page_count - 1) * $page_view;
echo "<div class=\"foot\"><a href=$PHP_SELF?pline=$prev_line>← 上一页</a></div><br>\n";
}
$next_line = $page_end + 1;
if($page_end != $end_data){
echo "<div class=\"foot\"><a href=$PHP_SELF?pline=$next_line>→ 下一页</a></div><br>\n";
//=====================前台不显示=================
echo "<div class=\"copyright\"><a href=\"http://www.mycodes.net/\">源码之家</a></div><br>\n";
//================================================
}
unset($message);
}
?>
</div><!--//#inner-->
</div><!--//#wrapper-->
</body>
</html>