#!/usr/local/bin/perl
#-----------------------------------------------------------
#(C)A.Yukawa All right reversed.
# 2008.01.01 complete.
#-----------------------------------------------------------
### □DATA_FORMAT□ ###
# ライブラリ
require '../_config/jcode.pl';
#---- フォルダ ----
# イメージフォルダ
$folder_Img = '_db';
#---- CGIファイル ----
# 新着コメント表示用CGI
$file_CGI_Index = "index.cgi";
#---- DBファイル ----
# 書き込みログDB
$file_DB_Log = "_db/db.cgi";
#---- 各種データ ----
# DBフォーマット
$file_Format_Log = "_library/_format_log.csv";
# キャスト&カラー
$file_Data_Name = "_library/_cast.csv";
#---- その他 ----
# 生成用テンプレートファイル(スキンファイル)
$file_HTML = "index.html";
### ■MAIN_WORK■ ###
# 処理
&work_Decode; # DATA DECODE
&work_Search; # データ検索・整形
$html .= &html_Layout; # HTML化
# 表示領域
print "Content-type: text/html\n\n";
open (HTML, $file_HTML);
while () {
if ($_ =~ '') { print $html; }
else { print; }
} close (HTML);
exit;
#---- レイアウト
sub html_Layout {
local ($html);
$html .= "
\n";
$html .= &html_Log;
$html .= "
\n";
$html .= "\n";
$html .= &html_Thread;
$html .= "
\n";
return ($html);
}
#---- スレッド表示
sub html_Thread {
local ($html);
$html .= "アーカイブス
\n";
$html .= "\n";
foreach (sort {$b <=> $a} keys %day) {
# 日付フォーマット
local ($y, $m) = &work_Date($_);
$html .= "- $y年$m月($day{$_})
\n";
}
$html .= "
\n";
return ($html);
}
#---- ログ表示
sub html_Log {
local ($html, %l, $flag = 0);
foreach (@db) {
# フォーマットに割り振る
local (@d) = split(/,/);
for $n (0 .. @format_Log - 1) { $l{@format_Log[$n]} = @d[$n]; }
# キャスト選択
local ($name, $tag) = split(/,/, $cast{$l{'cast'}});
# 日付フォーマット
local ($y, $m, $d, $h) = &work_Date($l{'day'});
# 改行処理
$l{'comment'} =~ s/>/
/g;
# 改行処理
$l{'comment'} =~ s/>/>\n/g;
# 画像表示
$l{'comment'} =~ s/(<)([a-zA-Z\d\.\/\-+#_?~&%=^\@:;()]+.(jpg|gif))(>)/<\/div>/g;
# コメント付URL自動リンク
$l{'comment'} =~ s/(http:\/\/[a-zA-Z\d\.\/\-+#_?~&%=^\@:;()]+)(<){1}(.+)(>){1}/
$3<\/a>/g;
# URL自動リンク
$l{'comment'} =~ s/([^=^\"]|^)(http:\/\/[a-zA-Z\d\.\/\-+#_?~&%=^\@:;()]+)/$1$2<\/a>/g;
# 各種オリジナルタグ
$l{'comment'} =~ s/<(b\/)(.+)>/$2<\/b>/g;
$l{'comment'} =~ s/<(cl\/)(.+)>/$2<\/s>/g;
$l{'comment'} =~ s/<(s\/)(.+)>/$2<\/span>/g;
$l{'comment'} =~ s/<(l\/)(.+)>/$2<\/span>/g;
# 改行処理
$l{'comment'} =~ s/\n//g;
$html .= "$y年$m月$d日 $name
\n";
$html .= "$l{'title'}
\n";
$html .= "$l{'comment'}\n";
$html .= "
\n";
}
return ($html);
}
#---- データ検索・整形
sub work_Search {
# フォーマット読み込み -- <@format_Log>
local ($flag = 0);
open (in, $file_Format_Log);
while () {
$_ =~ s/(\r\n|\r|\n)//g;
local (@d) = split(/,/);
push @format_Log, @d[1];
@sort[0] = $flag + 1 if (@d[1] eq 'day');
@sort[1] = $flag + 1 if (@d[1] eq 'name');
$flag ++;
} close (in);
# キャストデータ読み込み -- <%cast>
open (in, $file_Data_Name);
while () {
$_ =~ s/(\r\n|\r|\n)//g;
local (@d) = split(/,/);
$cast{@d[0]} = "@d[1],@d[2],";
} close (in);
# ログDB 読み込み -- <@db>
local (%l, $flag = 0);
open (in, $file_DB_Log);
while () {
# フォーマットに割り振る
local (@d) = split(/,/);
for $n (0 .. @format_Log - 1) { $l{@format_Log[$n]} = @d[$n]; }
next if (!$l{'flag'});
# 日付アーカイブ
$day{substr($l{'day'}, 0, 4)} ++;
# 検索・振り分け ----
# $d{'d'} 日付指定がある場合 検索振り分け
next if ($d{'d'} && $d{'d'} != substr($l{'day'}, 0, 4));
# $d{'d'} 日付指定がない場合 10件表示
if (!$d{'d'} && $flag > 5) { next; } else { $flag ++; }
push @db, $_;
}
close (in);
# 日付指定がある場合は逆順にソート
@db = map {$_->[0]} sort {$a->[@sort[0]] <=> $b->[@sort[0]] or $a->[@sort[1]] <=> $b->[@sort[1]]} map {[$_, split /,/]} @db if ($d{'d'});
}
#---- 日付表示フォーマット年月日時分秒
sub work_Date {
local ($y, $m, $d, $h, $i, $s);
$y = int(substr($_[0], 0, 2));
$m = int(substr($_[0], 2, 2));
$d = int(substr($_[0], 4, 2));
$h = int(substr($_[0], 6, 2));
$i = int(substr($_[0], 8, 2));
$s = int(substr($_[0], 10, 2));
return($y + 2000, $m, $d, $h, $i, $s);
}
#---- DATA DECODE
sub work_Decode {
# 日付/時間を検出
$ENV{'TZ'} = "JST-9";
($setS, $setI, $setH, $setD, $setM, $setY) = (localtime(time))[0..5];
$setY += 1900;
$setM ++;
# 今日の日付・時間
$d{'date'} = sprintf("%02d%02d%02d%02d%02d%02d", $setY - 2000, $setM, $setD, $setH, $setI, $setS);
# 曜日の配列
@week = ("日", "月", "火", "水", "木", "金", "土");
# データ抽出
if ($ENV{'REQUEST_METHOD'} eq 'POST') { read(STDIN, $Buffer, $ENV{'CONTENT_LENGTH'}); }
else { $Buffer = $ENV{'QUERY_STRING'}; }
foreach (split (/&/, $Buffer)) {
local ($n, $v) = split(/=/);
$n =~ tr/+/ /; $n =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$v =~ tr/+/ /; $v =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
jcode::h2z_sjis(\$v);
jcode::tr(\$v, ',\\', ',¥');
jcode::convert(\$v, 'sjis');
$d{$n} = $v;
}
}
# EOF