***美香りんご vol.2***

このエントリーをはてなブックマークに追加
45無名モデル
#!/usr/bin/perl

#--------------------------------------------------------------------------------------------------
# 自由レイアウト日記帳 ver1.01.00
#
# ※再配布不可/改造可です。
#
# date: 2001/07
# by : megumi.sano
# mail: [email protected]
# url : http://www.ace-cgi.jp/
#--------------------------------------------------------------------------------------------------

require './jcode.pl';

########## 固定項目 ##########
$cgif= "./diaryj.cgi";#このファイル
$dataf= "./data/";#データフォルダ
$formf= "./form.html";#レイアウトフォームファイル
@week1=('SUN','MON','TUE','WED','THU','FRI','SAT');
@week2=('日','月','火','水','木','金','土');

########## 設定項目 ##########
$pass= "mikapple";#管理者パスワード
$back_text= "[前の月へ]";#前月へのリンク
$next_text= "[次の月へ]";#後月へのリンク

########## 処理はここから ##########
&form_get;#フォーム解析
&form_ana;#レイアウトフォーム解析
&day_get;#表示付き設定
$fnam = &fnam_get;#ファイル名作成

if($FORM{'mode'} eq "master"){ &master_in; }
elsif($FORM{'mode'} eq "form"){ &form_disp($fnam); }
elsif($FORM{'mode'} eq "read"){ &form_disp($fnam); }
elsif($FORM{'mode'} eq "msg"){ &data_save($fnam); }

#----表示
&head_disp;
&cont_disp($fnam);
&foot_disp;
exit;
46無名モデル:2005/05/02(月) 20:18:54 ID:???
#------------#
# 表示月設定 #
#------------#
sub day_get
{
$ENV{'TZ'} = "JST-9";
local($sec,$min,$hour,$mday,$mon,$year,$wday) = localtime();
if($FORM{'mon'} < 1){
$FORM{'year'} = $year+1900;
$FORM{'mon'} = $mon+1;
$FORM{'day'} = $mday;
}
}

#----------------#
# ファイル名作成 #
#----------------#
sub fnam_get
{
local($fnam) = "$dataf" . "$FORM{'year'}" . "_" . "$FORM{'mon'}" . ".dat";
return $fnam;
}

#------------------------#
# レイアウトファイル解析 #
#------------------------#
sub form_ana
{
if(!open(IN,"$formf")){ &error("レイアウトフォームファイルが読み込めません"); }
local(@lines)=<IN>;
close(IN);

@head_lines=();
@foot_lines=();
@cont_lines=();

local($flg)=0;

foreach $line (@lines){
if(index($line,"JIYUDIARY KUGIRI1") >= 0){ $flg=1; next; }
if(index($line,"JIYUDIARY KUGIRI2") >= 0){ $flg=2; next; }

if($flg == 0){ push(@head_lines, $line); }
elsif($flg == 1){ push(@cont_lines, $line); }
else{ push(@foot_lines, $line); }
}

if(!@head_lines || !@foot_lines || !@cont_lines){ &error("レイアウトフォームが未完成です"); }

47無名モデル:2005/05/02(月) 20:23:04 ID:???
}

#--------------------#
# ヘッダ部分書き出し #
#--------------------#
sub head_disp
{
print "Content-type: text/html\n\n";
foreach $line (@head_lines){
$line =~ s/<!-- YEAR -->/$FORM{'year'}/g;
$line =~ s/<!-- MON -->/$FORM{'mon'}/g;
print "$line";
}
}
sub head_disp2
{
print "Content-type: text/html\n\n";
print <<EOM;
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<style type="text/css">
<!--
body,tr,td,th{font-size:10pt;}
-->
</style>
<title></title>
</head>
<body bgcolor=#FFFFFF text=#000000>
<center>
EOM

}

#--------------------#
# フッタ部分書き出し # #著作権の表示です。書き換えないで下さい。
#--------------------#
sub foot_disp
{
48無名モデル:2005/05/02(月) 20:25:40 ID:???
local($y,$m);
$y=$FORM{'year'};
$m=$FORM{'mon'};
$m--;
if($m < 1){ $m=12; $y--; }
local($back)="<a href=\"$cgif?year=$y&mon=$m\">$back_text</a>";
$y=$FORM{'year'};
$m=$FORM{'mon'};
$m++;
if($m > 12){ $m=1; $y++; }
local($next)="<a href=\"$cgif?year=$y&mon=$m\">$next_text</a>";

foreach $line (@foot_lines){
$line =~ s/<!-- YEAR -->/$FORM{'year'}/g;
$line =~ s/<!-- MON -->/$FORM{'mon'}/g;
$line =~ s/<!-- BACK -->/$back/g;
$line =~ s/<!-- NEXT -->/$next/g;
if(index($line,"</body>") >= 0 || index($line, "</BODY>") >= 0){
print "<div align=center><small><a href=\"http://www.ace-cgi.jp/\" target='_blank'>エース</a></small></div>\n";
}
print "$line";
}
}
sub foot_disp2
{
print <<EOM;
<small><a href="http://www.ace-cgi.jp" target='_blank'>エース</a></small>
</center>
</body></html>
EOM

exit;
}

#----------#
# 内容表示 #
#----------#
sub cont_disp
{
local($fnam)=$_[0];
local(@lines)=();

if(-e $fnam){
if(!open(IN,"$fnam")){ &error("データファイルが読み込めません"); }
@lines=<IN>;
close(IN);
}
49無名モデル:2005/05/02(月) 20:30:30 ID:???
foreach $line (@lines){
local($day,$comment,$item1,$item2,$item3,$item4,$item5,$tim)=split(/<>/,$line);
if($comment eq ""){ next; }
local($t)=&time_set($tim);
$weekno = &get_start($FORM{'year'},$FORM{'mon'},$day);
$we1 = $week1[$weekno];
$we2 = $week2[$weekno];

foreach $line (@cont_lines){
$line2 = $line;
$line2 =~ s/<!-- YEAR -->/$FORM{'year'}/g;
$line2 =~ s/<!-- MON -->/$FORM{'mon'}/g;
$line2 =~ s/<!-- DAY -->/$day/g;
$line2 =~ s/<!-- WEEK1 -->/$we1/g;
$line2 =~ s/<!-- WEEK2 -->/$we2/g;
$line2 =~ s/<!-- TIME -->/$t/g;
$line2 =~ s/<!-- COMMENT -->/$comment/g;
print "$line2";
}

}
}

#--------#
# 投稿欄 #
#--------#
sub form_disp
{
if($FORM{'pass'} ne $pass){ &error("パスワードが違います"); }

local($fnam)=$_[0];
local($comment)="";
if(-e $fnam){
if(!open(IN,"$fnam")){ &error("データファイルが読み込めません"); }
local(@lines)=<IN>;
close(IN);
foreach $line (@lines){
local($day,$com,$item1,$item2,$item3,$item4,$item5,$tim)=split(/<>/,$line);
if($day eq $FORM{'day'}){ $comment=$com; last; }
}
$comment =~ s/<BR>/\n/g;
}
50無名モデル:2005/05/02(月) 20:31:31 ID:???
local($ua) = $ENV{'HTTP_USER_AGENT'};
local($a) = ($ua =~ /MSIE/i) ? 1.5 : 1.0;
local($w) = 38*$a;
local($i);

&head_disp2;

print "<center>\n";
print "<form action=$cgif method=post>\n";
print "<input type=hidden name=mode value=read>\n";
print "<input type=hidden name=pass value=$FORM{'pass'}>\n";

print "修正したい場合は、その日付のデータを読み込んで下さい\n";
print "<table cellpadding=2 cellspacing=0 border=0>\n";
print "<tr><td>\n";
print "<input type=text size=10 name=year value=\"$FORM{'year'}\">年 \n";
print "<select name=mon>\n";
for($i=1; $i<13; $i++){
if($FORM{'mon'} eq $i){ print "<option value=\"$i\" selected>$i\n"; }
else{ print "<option value=\"$i\">$i\n"; }
}
print "</select>月\n";
print "<select name=day>\n";
for($i=1; $i<32; $i++){
if($FORM{'day'} eq $i){ print "<option value=\"$i\" selected>$i\n"; }
else{ print "<option value=\"$i\">$i\n"; }
}
print "</select>日\n";
print "<input type=submit value=\"この日付のデータを読み込む\">\n";
print "</td></tr>\n";
print "</table>\n";
print "</form>\n";

print "<hr width=70% size=1 noshade>\n";

print "<form action=$cgif method=post>\n";
print "<input type=hidden name=mode value=msg>\n";
print "<input type=hidden name=pass value=$FORM{'pass'}>\n";

print "削除したい場合は、カラで書き込みボタンを押して下さい\n";
print "<table cellpadding=2 cellspacing=0 border=0>\n";
print "<tr><td>\n";
print "<input type=text size=10 name=year value=\"$FORM{'year'}\">年 \n";
print "<select name=mon>\n";
for($i=1; $i<13; $i++){
if($FORM{'mon'} eq $i){ print "<option value=\"$i\" selected>$i\n"; }
else{ print "<option value=\"$i\">$i\n"; }
}
51無名モデル:2005/05/02(月) 20:32:59 ID:???
print "</select>月\n";
print "<select name=day>\n";
for($i=1; $i<32; $i++){
if($FORM{'day'} eq $i){ print "<option value=\"$i\" selected>$i\n"; }
else{ print "<option value=\"$i\">$i\n"; }
}
print "</select>日\n";
print "<input type=submit value=\"この日付のデータを書き込む\">\n";
print "</td></tr>\n";
print "<tr><td>\n";
print "<textarea name=comment rows=20 cols=$w wrap=soft>$comment</textarea>\n";
print "</td></tr>\n";
print "</table>\n";
print "</form>\n";

&foot_disp2;
}

#------------------#
# 投稿データを記録 #
#------------------#
sub data_save
{
52無名モデル:2005/05/02(月) 20:35:37 ID:???
if($FORM{'year'} == 0 || length($FORM{'year'}) != 4){ &error("年が不正です"); }
if($FORM{'mon'} == 0){ &error("月が不正です"); }
if($FORM{'day'} == 0){ &error("日が不正です"); }
local($fnam)=$_[0];
if(length($fnam) < 7 ){ &error("ファイル名が不正です"); }
local($t)=&time_get;
local($val)="$FORM{'day'}<>$FORM{'comment'}<><><><><><>$t<>\n";

local(@lines)=();
if(-e $fnam){
if(!open(IN,"$fnam")){ &error("ファイルが読み込めません"); }
@lines=<IN>;
close(IN);
}

local(@new)=();
foreach $line (@lines){
local($day,$com,$item1,$item2,$item3,$item4,$item5,$tim)=split(/<>/,$line);
if($day eq $FORM{'day'}){ next; }
push(@new, $line);
}
@lines=@new;
@new=();
local($flg)=0;

#foreach $line (@lines){
#local($day,$com,$item1,$item2,$item3,$item4,$item5,$tim)=split(/<>/,$line);
#if($day > $FORM{'day'} && $flg == 0){
#$flg = 1;
#push(@new, $val);
#}
#push(@new, $line);
#}
#if($flg == 0){ push(@new, $val); }

foreach $line (@lines){
local($day,$com,$item1,$item2,$item3,$item4,$item5,$tim)=split(/<>/,$line);
if($day < $FORM{'day'} && $flg == 0){
$flg = 1;
push(@new, $val);
}
push(@new, $line);
}
if($flg == 0){ push(@new, $val); }
53無名モデル:2005/05/02(月) 20:39:08 ID:???
if(!open(OUT,">$fnam")){ &error("ファイルがオープン出来ません"); }
print OUT @new;
close(OUT);
}

#----------------#
# 投稿データ取得 #
#----------------#
sub form_get
{
local($pair,$buff);
if($ENV{'REQUEST_METHOD'} eq "POST"){
if($ENV{'CONTENT_LENGTH'} > 51200){ &error("サイズオーバー",""); }
read(STDIN, $buff, $ENV{'CONTENT_LENGTH'});
}
else{
$buff = $ENV{'QUERY_STRING'};
}

local(@pairs) = split(/&/,$buff);
foreach $pair(@pairs){
local($name,$value) = split(/=/,$pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
&jcode'convert(*value,'sjis');
&jcode'h2z_sjis(*value);

$value =~ s/<>/<>/g;

if($name eq "comment"){
$value =~ s/\r\n/<BR>/g;
$value =~ s/\r/<BR>/g;
$value =~ s/\n/<BR>/g;
}
else{
$value =~ s/\r//g;
$value =~ s/\n//g;
}

$FORM{$name} = $value;
}
}
54無名モデル:2005/05/02(月) 20:41:31 ID:???
#----------------#
# パスワード入力 #
#----------------#
sub master_in
{
&head_disp2;
print <<EOM;
<div align=center>
<B>ここは管理者用です</B><p>
<form action=$cgif method=post>
<input type=hidden name=mode value=form>
<B>パスワード</B> <input type=password name=pass size=10> <input type=submit value=" 実行 " class=button><BR>
</form>
</div>
EOM

&foot_disp2;
}

#------------#
# 自動リンク #
#------------#
sub auto_link
{
if(!($_[0] =~ /<\/a>/)){
$_[0] =~ s/([^=^\"]|^)(http\:[\w\.\~\-\/\?\&\+\=\:\@\%\;\#]+)/$1<a href=\"$2\" target='_blank'>$2<\/a>/g;
}
}
55無名モデル:2005/05/02(月) 20:42:55 ID:???
#----------#
# 現在時刻 #
#----------#
sub time_get
{
$ENV{'TZ'} = "JST-9";
return time();
}
sub time_set
{
$ENV{'TZ'} = "JST-9";
local($sec,$min,$hour,$mday,$mon,$year,$wday) = localtime($_[0]);
#$year = $year + 1900;
#$mon = $mon+1;
$sec = "0$sec" if $sec < 10;
$min = "0$min" if $min < 10;
$hour = "0$hour" if $hour < 10;
#$mday = "0$mday" if $mday < 10;
#$mon = "0$mon" if $mon < 10;
#$wday = ('sun','mon','tue','wed','thu','fri','sat')[$wday];
#local($date) = "$year/$mon/$mday $hour:$min:$sec";
local($date) = "$hour:$min:$sec";
return $date;
}

56無名モデル:2005/05/02(月) 20:43:21 ID:???
#----------#
# 曜日取得 #
#----------#
sub get_start
{
local($y,$m,$d) = @_;
if( $m < 3 ){
$y--;
$m+=12;
}
return(($y+int($y/4)-int($y/100)+int($y/400)+int((13*$m+8)/5)+$d)%7);
}

#------------#
# エラー処理 #
#------------#
sub error
{
print "Content-type: text/html\n\n";

print <<EOM;
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<style type="text/css">
<!--
body,tr,td,th{font-size:10pt;}
-->
</style>
<title>ERROR</title>
</head>
<body bgcolor=#FFFFFF text=#000000>
<center>
<B>$_[0]</B>
<p>
<small><a href="http://www.ace-cgi.jp" target='_blank'>エース</a></small>
</center>
</body></html>
EOM

exit;
}