<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html;CHARSET=x-sjis">
<TITLE>KOMOダイアリー</TITLE>
<STYLE TYPE="text/css">
<!--
:link {
Color : blue ;
Text-Decoration : None
}
:active {
Color : blue ;
Text-Decoration : None
}
:visited {
Color : blue ;
Text-Decoration : None
}
A:hover {
Color : blue ;
Text-Decoration : Underline
}
-->
</STYLE>
</HEAD>
<BODY>
<CENTER>
<P><IMG SRC="title.gif" WIDTH="415" HEIGHT="82" ALIGN="BOTTOM" BORDER="0"></P>
<P><FONT COLOR="#990066"><B>編集機能付きの日記帳スクリプトだよ!結構便利なので、使って見てね(^o^)丿</B></FONT><BR>
パスワードは「777」に設定しています。お試しあれ!(^o^)丿</P>
<?php
//====================初期設定======================
$data_file = './diary.dat'; //データログ用ファイル
$passwd = '777'; //管理者用パスワード
$data_max = 100; //データ最大記録数
$page_view = 10; //1ページの記事表示件数
$back_img = ''; //バック用画像
$now = date("Y/m/d(D)"); //時間の取得
$up_dir = '/img/';
$w_max = 200; //画像の横幅の最大値(ピクセル)
$h_max = 200; //画像の縦幅の最大値(ピクセル)
$w_limit = 600; //画像の横幅の制限値(ピクセル)
$h_limit = 400; //画像の縦幅の制限値(ピクセル)
$err_msg = "画像のサイズが大きすぎます。画像をアップロードし直して下さい。";
$tag_flag = 1; //タグを有効「1」、無効「0」。
//==================================================
//スーパーグローバル変数対策
if(!isset($PATH_TRANSLATED)){
$path = dirname($_SERVER["PATH_TRANSLATED"]).$up_dir;
}else{
$path = dirname($PATH_TRANSLATED).$up_dir;
}
if(!isset($PHP_SELF)){ $PHP_SELF = $_SERVER["PHP_SELF"]; }
if(!isset($action)){
if($_POST['action']){
$action = $_POST['action'];
}else{
$action = $_GET['action'];
}
}
if(!isset($code)){ $code = $_POST['code']; }
if(!isset($subject)){ $subject = $_POST['subject']; }
if(!isset($msg)){ $msg = $_POST['msg']; }
if(!isset($date)){ $date = $_POST['date']; }
if(!isset($button)){ $button = $_POST['button']; }
if(!isset($password)){
if($_POST['password']){
$password = $_POST['password'];
}else{
$password = $_GET['password'];
}
}
if(!isset($e_code)){ $e_code = $_POST['e_code']; }
if(!isset($upfile)){ $upfile = $_FILES['upfile']['tmp_name']; }
if(!isset($upfile_name)){ $upfile_name = $_FILES['upfile']['name']; }
if(!isset($pline)){
if($_POST['pline']){
$pline = $_POST['pline'];
}else{
$pline = $_GET['pline'];
}
}
if(!isset($sort_flag)){ $sort_flag = $_POST['sort_flag']; }
//エスケープ記号対策
$subject = stripslashes($subject);
$msg = stripslashes($msg);
//===============インライン関数===================
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($button == "修正/更新"){
//ここから書き込みデータの調整
$subject = htmlspecialchars($subject);
if(!$tag_flag){ $msg = htmlspecialchars($msg); } //タグの調整
$msg = nl2br($msg);
$msg = str_replace("\r", "", $msg);
$msg = str_replace("\n", "", $msg);
//ログファイルの区切文字(",")と区別するために文字コード(,)に書き換える。
$subject = str_replace(",", ",",$subject);
$msg = str_replace(",", ",",$msg);
//インラインリンクを実現(URLのみ)
$msg = inline_link($msg);
//画像のアップロード処理
if(is_uploaded_file($upfile)){
//画像の属性を取得
$imagesize = getimagesize($upfile);
//大きな画像のアップを制限
if(($imagesize[0] > $w_limit) || ($imagesize[1] > $h_limit)){
$err_flag = 1;
echo "<META HTTP-EQUIV=refresh content=0;URL=$PHP_SELF?err_flag=$err_flag>";
exit;
}else{
switch($imagesize[2]){
case 1:
$out = $code . ".gif";
break;
case 2:
$out = $code . ".jpg";
break;
case 3:
$out = $code . ".png";
break;
default:
unlink($upfile);
}
if($out){
$sendpath = $path.$out;
if(move_uploaded_file($upfile, $sendpath)){
chmod($sendpath,0666);
$fname = $out;
}
}
}
}
$repdata = file($data_file);
$fp = fopen($data_file, "w");
for($i=0; $i<count($repdata); $i++){
list($rcode,$rsubject,$rmsg,$rfname,$rdate) = split( ",", $repdata[$i]);
if ($code == $rcode) {
if(!$fname){ $fname = $rfname; }
$repdata[$i] = "$code,$subject,$msg,$fname,$date\n";
fputs($fp, $repdata[$i]);
} else {
fputs($fp, $repdata[$i]);
}
}
fclose($fp);
echo "<META HTTP-EQUIV=refresh CONTENT=0;URL=$PHP_SELF?action=edit&password=$passwd>\n";
exit;
}elseif($button == "削除"){
$deldata = file($data_file);
$fp = fopen($data_file, "w");
for($i=0; $i<count($deldata); $i++){
list($dcode,$dsubject,$dmsg,$dfname,$ddate) = split(",", $deldata[$i]);
if ($code == $dcode) {
$deldata[$i] = "";
if($dfname){
unlink(".".$up_dir.$dfname);
}
}
fputs($fp, $deldata[$i]);
}
fclose($fp);
}else{
if($msg){
$code = time(); //アクセス時の秒数
//ここから書き込みデータの調整
$subject = htmlspecialchars($subject);
$subject = nl2br($subject);
$subject = str_replace("\r", "", $subject);
$subject = str_replace("\n", "", $subject);
if(!$tag_flag){ $msg = htmlspecialchars($msg); } //タグの調整
$msg = nl2br($msg);
$msg = str_replace("\r", "", $msg);
$msg = str_replace("\n", "", $msg);
//ログファイルの区切文字(",")と区別するために文字コード(,)に書き換える。
$subject = str_replace(",", ",",$subject);
$msg = str_replace(",", ",",$msg);
//インラインリンクを実現(URLのみ)
$msg = inline_link($msg);
//画像のアップロード処理
if(is_uploaded_file($upfile)){
//画像の属性を取得
$imagesize = getimagesize($upfile);
//大きな画像のアップを制限
if(($imagesize[0] > $w_limit) || ($imagesize[1] > $h_limit)){
$err_flag = 1;
echo "<META HTTP-EQUIV=refresh content=0;URL=$PHP_SELF?err_flag=$err_flag>";
exit;
}else{
switch($imagesize[2]){
case 1:
$out = $code . ".gif";
break;
case 2:
$out = $code . ".jpg";
break;
case 3:
$out = $code . ".png";
break;
default:
unlink($upfile);
}
if($out){
$sendpath = $path.$out;
if(move_uploaded_file($upfile, $sendpath)){
chmod($sendpath,0666);
$fname = $out;
}
}
}
}
//ログファイルの区切文字(",")と区別するために文字コード(,)に書き換える。
$fname = str_replace(",", ",",$fname);
//配列要素を文字列により連結
$input_msg = implode(",", array($code,$subject,$msg,$fname,$date));
$message = file($data_file);
$fp = fopen($data_file, "w");
rewind($fp);
fputs($fp, "$input_msg\n");
//最大記録数の調整
if($data_max <= count($message)){
$msg_num = $data_max - 1;
}else{
$msg_num = count($message);
}
for($i = 0; $i < $msg_num; $i++){
fputs($fp, $message[$i]);
}
fclose($fp);
unset($message);
echo "<META HTTP-EQUIV=refresh CONTENT=0;URL=$PHP_SELF>\n";
}
}
}elseif(($action == "edit") && ($password == $passwd)){
$kanri_flag = 1;
echo "<form action=$PHP_SELF method=POST ENCTYPE=multipart/form-data>\n";
echo "<P><B>記事の並び:</B><SELECT NAME=sort_flag><OPTION VALUE=0" . (($sort_flag == 0) ? ' SELECTED' : '') . ">降順</OPTION><OPTION VALUE=1" . (($sort_flag == 1) ? ' SELECTED' : '') . ">昇順</OPTION></SELECT>\n";
if($e_code < 1) {
echo "<input type=hidden name=action value=regist>\n";
echo "<table border=0>\n";
echo "<tr><td align=right>日付:</td><td><input type=text size=20 name=date value=$now></td></tr>\n";
echo "<tr><td align=right>題名:</td><td><input type=text size=35 name=subject></td></tr>\n";
echo "<tr><td align=right>コメント:</td><td><textarea name=msg rows=6 cols=50></textarea></td></tr>\n";
echo "<tr><td align=right>添付画像:</td><td><INPUT TYPE=file NAME=upfile SIZE=35></td></tr>\n";
echo "</table>\n";
echo "<input type=submit name=button value=送信/更新> <input type=reset value=リセット></form>\n";
}else{
$comdata = file($data_file);
for($i=0; $i<count($comdata); $i++){
list($ccode,$csubject,$cmsg,$cfname,$cdate) = split(",", $comdata[$i]);
if ($e_code == $ccode) {
$e_subject = $csubject;
$e_msg = str_replace("<br />", "\n", $cmsg);
if(!$tag_flag){ $e_msg = strip_tags($e_msg); }
$e_date = $cdate;
$e_fname = $cfname;
break;
}
}
unset($comdata);
//echo "<form action=$PHP_SELF method=POST ENCTYPE=multipart/form-data>\n";
echo "<input type=hidden name=action value=regist>\n";
echo "<input type=hidden name=code value=\"$e_code\">\n";
echo "<input type=hidden name=fname value=\"$e_fname\">\n";
echo "<table border=0>\n";
echo "<tr><td align=right>日付:</td><td colspan=2><input type=text size=20 name=date value=\"$e_date\"></td></tr>\n";
echo "<tr><td align=right>題名:</td><td colspan=2><input type=text size=35 name=subject value=\"$e_subject\"></td></tr>\n";
echo "<tr><td align=right>コメント:</td><td colspan=2><textarea name=msg rows=6 cols=50>$e_msg</textarea></td></tr>\n";
echo "<tr><td align=right>添付画像:</td><td colspan=2><INPUT TYPE=file NAME=upfile SIZE=35></td></tr>\n";
echo "<tr><td></td><td>\n";
echo "<input type=submit name=button value=修正/更新> <input type=submit name=button value=削除></td></form>\n";
echo "<td><form action=$PHP_SELF method=POST><input type=submit value=ログアウト></td></tr>\n";
echo "</table></form>\n";
}
}
//エラー処理
if($err_flag){
echo $err_msg;
echo "<BR><BR><A HREF=$PHP_SELF onMouseOver=this.style.color='red' onMouseOut=this.style.color='blue'><やり直す></A>\n";
exit;
}
$message = file($data_file);
$msg_count = count($message);
if($sort_flag){
$log_max = $msg_count - 1;
for($i=$log_max; $i>=0; $i--){
$message2[] = $message[$i];
}
}
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++){
if($sort_flag){
list($vcode,$vsubject,$vmsg,$vfname,$vdate) = split( ",", $message2[$i]);
}else{
list($vcode,$vsubject,$vmsg,$vfname,$vdate) = split( ",", $message[$i]);
}
echo "<form action=$PHP_SELF method=POST>\n";
echo "<input type=hidden name=action value=edit>\n";
echo "<input type=hidden name=e_code value=$vcode>\n";
echo "<input type=hidden name=sort_flag value=$sort_flag>\n";
echo "<input type=hidden name=pline value=$pline>\n";
echo "<table border=0 cellspacing=1 width=750 bgcolor=#555555>\n";
echo "<tr><td BGCOLOR=#FFFBF0>■<b><FONT COLOR='green'>" . $vdate . "</FONT></B>\n";
echo " <font color='blue' size=4><b>$vsubject</b></font>\n";
if (($action == "edit") && ($password == $passwd)) {
echo "<input type=hidden name=password value=$passwd> <input type=submit value=訂正>\n";
}
echo "</td></tr><tr><td BGCOLOR=#FFFFFF><blockquote>\n";
if($vfname && file_exists("$path$vfname")){
$size = getimagesize("$path$vfname");
$img_w=$size[0];
$img_h=$size[1];
if($img_w > $w_max || $img_h > $h_max){
$w_ritu = $w_max / $img_w;
$h_ritu = $h_max / $img_h;
($w_ritu < $h_ritu) ? $key = $w_ritu : $key = $h_ritu;
$width = (int) $img_w * $key;
$height = (int) $img_h * $key;
echo "<A HREF=.$up_dir$vfname TARGET=_blank><img src=.$up_dir$vfname WIDTH=" . $width . " HEIGHT=" . $height . " ALIGN=LEFT></A>";
}else{
echo "<img src=.$up_dir$vfname ALIGN=LEFT>";
}
}
echo "$vmsg</blockquote></td></tr></table></form>\n";
}
?>
<P>
<TABLE BORDER="0" WIDTH="750">
<TR>
<TD WIDTH="50%">
<?php
if($page_end >= $page_view){
$page_count = floor($page_end / $page_view);
$prev_line = ($page_count - 1) * $page_view;
echo "<form method=Post action=$PHP_SELF>\n";
if (($action == 'edit') && ($password == $passwd)){
echo "<input type=hidden name=action value=edit>\n";
echo "<input type=hidden name=password value=$passwd>\n";
}
echo "<input type=hidden name=pline value=$prev_line>\n";
echo "<input type=hidden name=sort_flag value=$sort_flag>\n";
echo "<input type=submit value=前のページ>\n";
echo "</form>\n";
}else{
echo " \n";
}
?>
</TD>
<TD WIDTH="50%"><P ALIGN="RIGHT">
<?php
$next_line = $page_end + 1;
if($page_end != $end_data){
echo "<form method=Post action=$PHP_SELF>\n";
if (($action == 'edit') && ($password == $passwd)){
echo "<input type=hidden name=action value=edit>\n";
echo "<input type=hidden name=password value=$passwd>\n";
}
echo "<input type=hidden name=pline value=$next_line>\n";
echo "<input type=hidden name=sort_flag value=$sort_flag>\n";
echo "<input type=submit value=次のページ>\n";
echo "</form>\n";
}else{
echo " \n";
}
?>
</TD>
</TR>
</TABLE>
<HR>
<?php
if($kanri_flag < 1){
echo "<div align=left>\n";
echo "<form action=$PHP_SELF method=POST>\n";
echo "<input type=hidden name=action value=edit>\n";
echo "<input type=password size=10 name=password>\n";
echo "<input type=hidden name=sort_flag value=$sort_flag>\n";
echo "<input type=hidden name=pline value=$pline>\n";
echo " <input type=submit value=管理><br>\n";
echo "</form></div>\n";
}
?>
<div align="right"><font size="-1">Powered by <a href="http://www.komonet.ne.jp/" onMouseOver="this.style.color='red'" onMouseOut="this.style.color='blue'">KOMONET</a></font></div>
</BODY>
</HTML>