【keywiki.cgi】

更新 新規 編集 設定 一覧
#!/usr/bin/perl -w
#------------------------------------------------------------------------------#
# 機能名 : KeyWiki
# 機能概要 : Wiki的Perlプログラム(YukiWiki参考)
# 作成者 : Ryota Sasabe
# 作成履歴 : Ver0.01 2004.06.09 新規作成
# Ver0.51 2004.09.01 テンプレートキーワード概念を削除
# Ver0.52 2004.09.02 BracketName機能拡張
# Ver0.54 2004.09.03 BracketName不具合修正,EUC-JP対応等
# Ver0.60 2004.09.21 Backup機能追加
# Ver0.60 2004.09.22 Backup復元機能追加
# Ver0.61 2004.09.24 ファイル添付機能追加,キーワード内容最大文字数拡張
# Ver0.62 2004.09.27 スタイルシート,整形ルール等修正
# Ver0.63 2004.09.30 ロジック見直し
# Ver0.64 2004.11.04 ディレクトリ概念廃止
# Ver0.65 2004.11.05 目次自動作成機能追加
# Ver0.66 2004.11.10 ディレクトリ概念復活(簡易版)
# Ver0.67 2004.11.11 html文字コードをShift-JISに変更
# Ver0.68 2004.11.12 キーワード一覧階層化
# Ver0.69 2004.12.08 ソース整理,整形ルール拡張
# Ver0.70 2004.12.20 フレーム導入等
# Ver0.75 2005.03.07 ファイルインポート機能追加
# Ver0.76 2005.03.10 KeyWiki用関数をライブラリに切り離す
# Ver0.77 2005.03.17 ロジックが煩雑になる為KeyNo概念を廃止
# Ver0.78 2005.04.01 オートリンク機能に相対パス概念を導入
# Ver0.79 2005.04.22 整形ルール拡張
#------------------------------------------------------------------------------#
require "cgi-bin/lib/system.pl";
&main::init('ScriptCharCode' => 'euc', 'HtmlCharCode' => 'sjis', 'FormInput' => 1);
################################################################################
#◆引数調整
$in{'cmd'} = 'read' if (!$in{'cmd'});
$in{'key'} = "$in{'dir'}//$in{'key'}" if ($in{'dir'});
################################################################################
#◆初期情報設定
my $SoftName = 'KeyWiki';
my $ScriptName = &get_scriptname();
my $SaveDir = "$BaseDir/cgi-files/" . &remove_extension($ScriptName);
my $HtmlName = join('-', $in{'cmd'}, &encode($in{'key'}), $browser{'type'});
############################################################
my %html = &get_html_style('KeyWiki');
my %G_ID;
my %info;
my %cmd; # command
my %trs; # temporary replacement string
my $randmin = 10000;
my $randmax = 99999;
############################################################
my $delimiter = '\/\/';
my $bracket_name = '\[\[(\S+?)\]\]';
my $upload_file = '(F[0-9]{11})';
my $not_convert = '(.*?)';
############################################################
my %cmd_name = (
'list' => '一覧',
'recent' => '新順',
'search' => '検索',
'backup' => '履歴',
'newkey' => '新規',
'edit' => '編集',
'rename' => '改名',
'setup' => '設定',
'reload' => '更新'
);
################################################################################
#◆ライブラリ設定
require "cgi-bin/lib/keywiki.pl";
&keywiki::init('SaveDir' => $SaveDir);
################################################################################
#◆キーワード関連設定
foreach my $keyname ('key', 'afk') {
next unless $in{$keyname};
#□特殊文字変換
$in{$keyname} =~ s/__NOW__/&get_time('LocalTime', 'Format' => 1)/ego;
$in{$keyname} =~ s/__TODAY__/&get_time('LocalTime', 'Length' => 8, 'Format' => 1)/ego;
#□書式変換と変数設定
&convert_jcode(\$in{$keyname}, $ScriptCharCode, $ScriptCharCode, 'z'); # 全角変換
$in{$keyname} =~ s/\r?\n//g; # 改行除去
$in{$keyname} = &trim($in{$keyname}, '/'); # 両端記号除去
@{$keyname} = split(/$delimiter/, $in{$keyname}); # ディレクトリ分割
#□書式チェック
if (not &is_editable($in{$keyname})) {
&error($resource{'InvalidKeyword'});
} elsif (length($in{$keyname}) < 2) {
&error($resource{'TooShortKeyword'});
} elsif (length($in{$keyname}) > 100) {
&error($resource{'TooLongKeyword'});
}
}
################################################################################
#◆処理区分関連設定
if ($in{'cmd'} eq 'read' ){ %cmd = ('G_ID' => '0', 'ExistCheck' => '1', 'Html' => '1', 'Title' => "$key[$#key]" ); @Menu = ('reload', 'newkey', 'edit', 'setup', 'list'); }
elsif ($in{'cmd'} eq 'list' ){ %cmd = ('G_ID' => '0', 'ExistCheck' => '0', 'Html' => '1', 'Title' => "$key[$#key]キーワード一覧" ); @Menu = ('reload', 'newkey', 'recent'); }
elsif ($in{'cmd'} eq 'recent' ){ %cmd = ('G_ID' => '0', 'ExistCheck' => '0', 'Html' => '1', 'Title' => "$key[$#key]キーワード更新順"); @Menu = ('reload', 'newkey', 'list'); }
elsif ($in{'cmd'} eq 'search' ){ %cmd = ('G_ID' => '0', 'ExistCheck' => '0', 'Html' => '1', 'Title' => "キーワード検索" ); }
elsif ($in{'cmd'} eq 'backup' ){ %cmd = ('G_ID' => '0', 'ExistCheck' => '1', 'Html' => '0', 'Title' => "$key[$#key]の編集履歴" ); @Menu = ('reload'); }
elsif ($in{'cmd'} eq 'newkey' ){ %cmd = ('G_ID' => '0', 'ExistCheck' => '0', 'Html' => '0', 'Title' => "キーワード新規作成" ); }
elsif ($in{'cmd'} eq 'edit' ){ %cmd = ('G_ID' => '0', 'ExistCheck' => '0', 'Html' => '0', 'Title' => "$key[$#key]の編集" ); @Menu = ('setup', 'rename', 'backup'); }
elsif ($in{'cmd'} eq 'preview'){ %cmd = ('G_ID' => '0', 'ExistCheck' => '1', 'Html' => '0', 'Title' => "$key[$#key]のプレビュー" ); }
elsif ($in{'cmd'} eq 'setup' ){ %cmd = ('G_ID' => '0', 'ExistCheck' => '1', 'Html' => '0', 'Title' => "$key[$#key]の設定" ); @Menu = ('reload'); }
elsif ($in{'cmd'} eq 'rename' ){ %cmd = ('G_ID' => '1', 'ExistCheck' => '1', 'Html' => '0', 'Title' => "$key[$#key]の改名" ); }
elsif ($in{'cmd'} eq 'comment'){ %cmd = ('G_ID' => '2', 'ExistCheck' => '1') }
elsif ($in{'cmd'} eq 'write' ){ %cmd = ('G_ID' => '2', 'ExistCheck' => '0') }
elsif ($in{'cmd'} eq 'delete' ){ %cmd = ('G_ID' => '2', 'ExistCheck' => '1') }
elsif ($in{'cmd'} eq 'reflect'){ %cmd = ('G_ID' => '2', 'ExistCheck' => '1') }
else { &error("処理区分が不正です(cmd = $in{'cmd'})"); }
#□処理区分個別処理
unless ( &keywiki::exists_keyword($in{'key'}) ) {
if ($cmd{'ExistCheck'}) {
&error($resource{'NotFoundKeyword'});
}
if ($in{'cmd'} eq 'edit') {
$cmd{'Title'} = "$key[$#key]の作成";
undef @Menu;
}
}
################################################################################
#◆html更新チェック
if ($cmd{'Html'} && $in{'cmd'} =~ /(read|list|recent)/) {
my $WikiPath = "$SaveDir/wiki/@{[&encode($in{'key'})]}.dat";
my $InfoPath = "$SaveDir/info/@{[&encode($in{'key'})]}.dat";
my $HtmlPath = "$SaveDir/html/$HtmlName.html";
#□更新対象外の場合、既存html表示
if(-e $HtmlPath){
unless( &get_time('LastUpdateTime', 'FilePath' => $HtmlPath, 'Length' => 10) ne &get_time('LocalTime', 'Length' => 10) ||
&get_time('LastUpdateTime', 'FilePath' => $HtmlPath) lt &get_time('LastUpdateTime', 'FilePath' => $WikiPath) ||
&get_time('LastUpdateTime', 'FilePath' => $HtmlPath) lt &get_time('LastUpdateTime', 'FilePath' => $InfoPath) ){
# &print_html( scalar( &read_file($HtmlPath) ), 'no_convert'); exit;
}
}
}
################################################################################
#◆キーワード設定情報取得
if ( &keywiki::exists_keyword($in{'key'}) ) { # keyinfofile
%info = &read_infofile("$SaveDir/info/@{[&encode($in{'key'})]}.dat");
} elsif ( &keywiki::get_node_keyword($in{'key'}) ) { # keyinfofile(node)
%info = &read_infofile("$SaveDir/info/@{[&encode(&keywiki::get_node_keyword($in{'key'}))]}.dat");
}
################################################################################
#◆G-ID認証
if ($cmd{'G_ID'} eq '2' || ($cmd{'G_ID'} eq '1' && $in{'G_ID'}) ) {
#□認証と情報取得
%G_ID = &get_userinfo( &check_gid($in{'G_ID'}) );
#□キーワード編集権限チェック
unless (
($AdminUser{$G_ID{'UserNo'}} >= 3) ||
($AdminUser{$G_ID{'UserNo'}} >= 1 && $in{'cmd'} ne 'delete') ||
($G_ID{'UserNo'} eq $info{'CreatedUserNo'}) ||
($in{'cmd'} =~ /(write|comment)/)
) {
&error($resource{'CantChangeKeyword'});
}
} elsif ($cmd{'G_ID'} && !($in{'G_ID'}) ) {
&show_gid_input_form($ScriptName, %html);
}
################################################################################
#◆htmlヘッダー設定
$HTML .= &get_html_header("$cmd{'Title'} - $SoftName", %html);
#$HTML .= "<base target='right'>";
$HTML .= &get_html_menu($in{'key'}, @Menu); # Command Menu
$HTML .= "<div class='menu'>";
$HTML .= " <hr color='$html{'BodyHrColor'}'>";
$HTML .= &keywiki::get_html_keyword_directory($in{'key'}); # Keyword Directory
$HTML .= " <hr color='$html{'BodyHrColor'}'>";
$HTML .= "</div>";
################################################################################
#◆キーワード表示
if ($in{'cmd'} eq 'read') {
my ($keycode) = &encode($in{'key'});
my (@html, $html);
push(@html, "<div class='keybody'>");
$html = &read_file("$SaveDir/wiki/$keycode.dat");
push(@html, &convert_html($html, 'toc' => 1));
if ($info{'ShowCommentForm'}) {
push(@html, " <form action='$ScriptName' method='post'>");
push(@html, " <input type='text' name='G_ID' value='(G-ID)' maxlength='12' size='16'>");
push(@html, " <input type='text' name='KEY_NY' value='(コメント内容)' maxlength='$html{'CommentMaxlength'}' size='$html{'CommentSize'}' class='text_comment'>");
push(@html, " <input type='hidden' name='cmd' value='comment'>");
push(@html, " <input type='hidden' name='key' value='$in{'key'}'>");
push(@html, " <input type='submit' value='書込'>");
push(@html, "</form>");
}
$CreatedTime = &format_time($info{'CreatedTime'});
$LastUpdateTime = &format_time($info{'LastUpdateTime'});
push(@html, " <hr color='$html{'BodyHrColor'}'>");
push(@html, " <div class='keybody_info'>");
push(@html, " 更新者:<a href='b.cgi?n=$info{'LastUpdateUserNo'}'>$info{'LastUpdateUserName'}</a> $LastUpdateTime<br>");
push(@html, " 作成者:<a href='b.cgi?n=$info{'CreatedUserNo'}'>$info{'CreatedUserName'}</a> $CreatedTime<br>");
push(@html, " </div>");
push(@html, "</div>");
$HTML .= join("\n", @html) . "\n";
}
################################################################################
#◆キーワード一覧表示
if ($in{'cmd'} eq 'list') {
my ($dirpos);
my (@keydir, @toc);
foreach my $keyword ( &keywiki::get_keyword_list('charcode', $in{'key'}, 'middle') ) {
$dirpos = 0;
@split_keyword = split(/$delimiter/, $keyword);
foreach my $split_keyword (@split_keyword) {
if ($keydir[$dirpos] ne $split_keyword) {
@keydir = splice(@keydir, 0, $dirpos);
push(@keydir, $split_keyword);
if ($dirpos == $#split_keyword) {
push(@toc, '-' x ($dirpos + 1) . "<a href='$ScriptName?key=@{[&encode_url($keyword)]}'>$split_keyword</a>");
} else {
push(@toc, '-' x ($dirpos + 1) . "$split_keyword");
}
}
$dirpos++;
}
}
$HTML .= join("\n", &convert_toc(@toc)) . "\n";
}
################################################################################
#◆キーワード更新順
if ($in{'cmd'} eq 'recent') {
my ($keyword, $keyupdatetime);
foreach my $keylist ( &keywiki::get_keyword_list('recent', $in{'key'}, 'middle') ) {
($keyword, $keyupdatetime) = split(/\t/, $keylist);
$keyupdatetime = &format_time($keyupdatetime);
$HTML .= "<li>$keyupdatetime <a href='$ScriptName?key=@{[&encode_url($keyword)]}'>$keyword</a></li>";
}
}
################################################################################
#◆キーワード検索
if ($in{'cmd'} eq 'search') {
}
################################################################################
#◆キーワード編集履歴(バックアップ)
if ($in{'cmd'} eq 'backup') {
my (%bk);
my (@bkrec) = &read_file("$SaveDir/backup/@{[&encode($in{'key'})]}.dat");
## 履歴一覧
if ( !(defined $in{'age'}) ) {
for (my $age = 0; $age <= $#bkrec; $age++) {
($bk{'KEY_WD'}, $bk{'UPD_YS'}, $bk{'USR_NO'}, $bk{'USR_NA'}, $bk{'KEY_NY'}) = &split_record($bkrec[$age]);
$HTML .= "<li><a href='$ScriptName?cmd=backup&key=@{[&encode_url($bk{'KEY_WD'})]}&age=$age'>@{[&format_time($bk{'UPD_YS'})]}</a>"
. " by <a href='b.cgi?n=$bk{'USR_NO'}'>$bk{'USR_NA'}</a> (@{[length($bk{'KEY_NY'})]}byte)</li><br>";
}
## 履歴明細
} else {
($bk{'KEY_WD'}, $bk{'UPD_YS'}, $bk{'USR_NO'}, $bk{'USR_NA'}, $bk{'KEY_NY'}) = &split_record($bkrec[$in{'age'}]);
$HTML .= "<form action='$ScriptName' method='post'>";
$HTML .= "■キーワード内容<br>";
$HTML .= "<textarea name='KEY_NY' rows='8' cols='40'>@{[&escape_tag($bk{'KEY_NY'})]}</textarea><br>";
$HTML .= "<br>";
$HTML .= "■G-ID<br>";
$HTML .= "<input type='text' name='G_ID' maxlength='12' size='16'><br>";
$HTML .= "<input type='hidden' name='cmd' value='write'>";
$HTML .= "<input type='hidden' name='key' value='$in{'key'}'>";
$HTML .= "<input type='submit' value='復元'>";
$HTML .= "</form>";
}
}
################################################################################
#◆キーワード新規作成
if ($in{'cmd'} eq 'newkey') {
$HTML .= "<form action='$ScriptName' method='post'>";
$HTML .= "■新規キーワード<br>";
$HTML .= "<input type='text' name='key' value='' maxlength='$html{'KeywordMaxlength'}' size='$html{'KeywordSize'}' class='text_keyword'><br>";
$HTML .= "<input type='hidden' name='cmd' value='edit'>";
$HTML .= "<input type='hidden' name='dir' value='$in{'key'}'>";
$HTML .= "<input type='submit' value='作成'>";
$HTML .= "</form>";
}
################################################################################
#◆キーワード編集
if ($in{'cmd'} eq 'edit') {
#□キーワードが空の場合、新規キーワード画面へ
if ( !$in{'key'}) {
print "Location: $BaseURL/$ScriptName?cmd=newkey\n\n"; exit;
}
if ( &keywiki::exists_keyword($in{'key'}) ) { # read wikifile
$text{'KEY_NY'} = &read_file("$SaveDir/wiki/@{[&encode($in{'key'})]}.dat");
} elsif ( &keywiki::exists_keyword($in{'mod'}) ) {
$text{'KEY_NY'} = &read_file("$SaveDir/wiki/@{[&encode($in{'mod'})]}.dat");
}
$HTML .= "<form action='$ScriptName' method='post'>";
$HTML .= "■キーワード内容<br>";
$HTML .= "<textarea name='KEY_NY' rows='8' cols='40'>@{[&escape_tag($text{'KEY_NY'})]}</textarea><br>";
$HTML .= "<br>";
$HTML .= "■G-ID<br>";
$HTML .= "<input type='text' name='G_ID' maxlength='12' size='16'><br>";
$HTML .= "<input type='hidden' name='cmd' value='write'>";
$HTML .= "<input type='hidden' name='key' value='$in{'key'}'>";
$HTML .= "<input type='hidden' name='LastUpdateTime' value='$info{'LastUpdateTime'}'>";
# $HTML .= "<input type='submit' name='preview' value='確認'>";
$HTML .= "<input type='submit' name='write' value='保存'>";
$HTML .= "</form>";
$HTML .= "<hr color='$html{'BodyHrColor'}'>";
$HTML .= "<form action='attach.cgi' enctype='multipart/form-data' method='post' target='_blank'>";
$HTML .= "■添付ファイルアップロード<br>";
$HTML .= "<input type='file' name='UploadFile' size='60' class='file'><br>";
$HTML .= "<input type='submit' value='アップロード'><br>";
$HTML .= "</form>";
}
################################################################################
#◆キーワードプレビュー
if ($in{'cmd'} eq 'preview') {
}
################################################################################
#◆キーワード更新
if ($in{'cmd'} eq 'write') {
## キーワード内容が未入力の場合
unless ($in{'KEY_NY'}) {
if ( &keywiki::exists_keyword($in{'key'}) ) { # to delete
print "Location: $BaseURL/$ScriptName?cmd=delete&key=@{[&encode_url($in{'key'})]}&G_ID=$in{'G_ID'}\n\n"; exit;
} else { # to edit
print "Location: $BaseURL/$ScriptName?cmd=edit&key=@{[&encode_url($in{'key'})]}&G_ID=$in{'G_ID'}\n\n"; exit;
}
}
## 既存キーワードの場合、更新衝突チェック
if (&keywiki::exists_keyword($in{'key'})) {
if ($in{'LastUpdateTime'} ne $info{'LastUpdateTime'} && $G_ID{'UserNo'} ne $info{'LastUpdateUserNo'}) {
&error($resource{'ConflictNotice'});
}
}
## キーワードファイル書込み
&keywiki::write_keyword($in{'key'}, $in{'KEY_NY'}, %G_ID);
## 保存ファイルパスが指定されている場合 かつ 管理者bフ場合、書込み
if ($info{'SaveFileLocalPath'} && $AdminUser{$G_ID{'UserNo'}} >= 3) {
&convert_jcode(\$in{'KEY_NY'}, $info{'SaveFileCharCode'}, $ScriptCharCode);
&write_file("$BaseDir/$info{'SaveFileLocalPath'}", $in{'KEY_NY'});
}
#□キーワード表示
print "Location: $BaseURL/$ScriptName?key=@{[&encode_url($in{'key'})]}\n\n"; exit;
}
################################################################################
#◆キーワード削除
if ($in{'cmd'} eq 'delete') {
my ($keyurl);
&keywiki::delete_keyword($in{'key'});
$keyurl = &encode_url( &keywiki::get_node_keyword($in{'key'}) );
print "Location: $BaseURL/$ScriptName?cmd=list&key=$keyurl\n\n"; exit;
}
################################################################################
#◆キーワード名変更
if ($in{'cmd'} eq 'rename') {
#□改名後キーワードが未入力、または同一キーワードの場合
if ( !$in{'afk'} || $in{'afk'} eq $in{'key'}) {
$HTML .= "<form action='$ScriptName' method='post'>";
$HTML .= "■改名後キーワード<br>";
$HTML .= "<input type='text' name='afk' value='$in{'key'}' maxlength='$html{'KeywordMaxlength'}' size='$html{'KeywordSize'}' class='text_keyword'><br>";
$HTML .= "<input type='hidden' name='G_ID' value='$in{'G_ID'}'>";
$HTML .= "<input type='hidden' name='cmd' value='rename'>";
$HTML .= "<input type='hidden' name='key' value='$in{'key'}'>";
$HTML .= "<input type='submit' value='改名'>";
$HTML .= "</form>";
#□改名後キーワードが入力済の場合
}else{
if ( &keywiki::exists_keyword($in{'afk'}) ) {
&error($resource{'SameKeywordExists'});
}else{
&keywiki::rename_keyword($in{'key'}, $in{'afk'});
print "Location: $BaseURL/$ScriptName?cmd=read&key=@{[&encode_url($in{'afk'})]}\n\n"; exit;
}
}
}
################################################################################
#◆コメント書込み
if ($in{'cmd'} eq 'comment') {
my ($keyword, $keytext) = ($in{'key'}, &remove_linefeed($in{'KEY_NY'}));
my $keycode = &encode($keyword);
my $date = &get_time('LocalTime', 'Length' => 12, 'Format' => 1);
if ($keytext && $keytext !~ /コメント内容/) {
$keytext = "\n" . "・$keytext $date -- $G_ID{'UserName'}";
if ( &read_file("$SaveDir/wiki/$keycode.dat") !~ /\Q$keytext\E$/ ) {
&keywiki::append_keytext($keyword, $keytext);
&keywiki::write_keyinfo($keyword, %G_ID);
}
}
print "Location: $BaseURL/$ScriptName?key=@{[&encode_url($keyword)]}\n\n"; exit;
}
################################################################################
#◆キーワード情報編集
if ($in{'cmd'} eq 'setup') {
#□ラジオボタン状態設定
foreach my $name (keys %info) {
next if !($name =~ /(ShowCommentForm|SaveFileCharCode)/);
$checked{"$name = $info{$name}"} = 'checked';
}
#□html生成
$HTML .= "<form action='$ScriptName' method='post'>";
$HTML .= "■コメント書込欄表示<br>";
$HTML .= "<input type='radio' name='ShowCommentForm' value='1' $checked{'ShowCommentForm = 1'}>する ";
$HTML .= "<input type='radio' name='ShowCommentForm' value='0' $checked{'ShowCommentForm = 0'}>しない<br>";
$HTML .= "<br>";
$HTML .= "■保存ファイル情報(管理者のみ設定可)<br>";
$HTML .= "<input type='text' name='SaveFileLocalPath' value='$info{'SaveFileLocalPath'}' maxlength='80' size='50'><br>";
$HTML .= "<input type='radio' name='SaveFileCharCode' value='sjis' $checked{'SaveFileCharCode = sjis'}>SJIS ";
$HTML .= "<input type='radio' name='SaveFileCharCode' value='euc' $checked{'SaveFileCharCode = euc'}>EUC<br>";
$HTML .= "<br>";
$HTML .= "<hr color='$html{'BodyHrColor'}'>";
$HTML .= "■G-ID<br>";
$HTML .= "<input type='text' name='G_ID' maxlength='12' size='16'><br>";
$HTML .= "<input type='hidden' name='cmd' value='reflect'>";
$HTML .= "<input type='hidden' name='key' value='$in{'key'}'>";
$HTML .= "<input type='submit' value='設定'>";
$HTML .= "</form>";
}
################################################################################
#◆キーワード設定情報書込み
if($in{'cmd'} eq 'reflect'){
my ($keyword) = ($in{'key'});
my (%info);
$info{'ShowCommentForm'} = $in{'ShowCommentForm'};
$info{'SaveFileLocalPath'} = $in{'SaveFileLocalPath'} if ($AdminUser{$G_ID{'UserNo'}} >= 3);
$info{'SaveFileCharCode'} = $in{'SaveFileCharCode'} if ($AdminUser{$G_ID{'UserNo'}} >= 3);
&keywiki::write_keyinfo($keyword, %info, %G_ID);
print "Location: $BaseURL/$ScriptName?key=@{[&encode_url($keyword)]}\n\n"; exit;
}
################################################################################
#◆htmlフッター設定
if ($cmd{'Html'}) {
$HTML .= "<hr color='$html{'BodyHrColor'}'>";
$HTML .= "<form action='$ScriptName' method='post'>";
$HTML .= "■キーワード検索<br>";
$HTML .= "<input type='text' name='key' value='' maxlength='$html{'KeywordMaxlength'}' size='$html{'KeywordSize'}' class='text_keyword'><br>";
$HTML .= "<input type='hidden' name='cmd' value='list'>";
$HTML .= "<input type='submit' value='検索'>";
$HTML .= "</form>";
}
$HTML .= &get_html_footer($SoftName, %html);
################################################################################
#◆html表示後終了
&write_html("$SaveDir/html/$HtmlName.html", $HTML) if ($cmd{'Html'});
&print_html($HTML);
exit;
sub get_html_menu {
my ($keyword, @cmd) = @_;
my (@html, $query);
foreach my $cmd (@cmd) {
if ($cmd eq 'reload') {
push(@html, "<a href='$ScriptName?cmd=$in{'cmd'}&key=@{[&encode_url($keyword)]}'>$cmd_name{$cmd}</a>");
} else {
$query = "cmd=$cmd&key=@{[&encode_url($keyword)]}";
$query .= "&age=$in{'age'}" if ($in{'cmd'} eq 'backup');
push(@html, "<a href='$ScriptName?$query'>$cmd_name{$cmd}</a>");
}
}
return join(' ', @html) . "\n";
}
sub convert_html {
my ($text, %option) = @_;
my (@html, @tag, @toc, $hn);
my $tocnum = 0; # toc number
## import textfile (file://***.***)
$text =~ s/file:\/\/(.+?)\.(\w{3,4})/&import_file("$1.$2", $2)/egio;
## not convert
$text =~ s/$not_convert/&trs($1)/egio;
## text to html
foreach ( split(/\r?\n/, &escape_tag($text)) ) {
if ( !($_) ) { # close tag
push(@html, "</" . pop(@tag) . ">") if (@tag);
} elsif (/^(/)(.*)/) { # comment
} elsif ($tag[$#tag] =~ /^(pre)$/) { # now pre
s/^(|)//;
push(@html, $_);
} elsif ($tag[$#tag] =~ /^(dl)$/) { # now dl
/^(:)(.*)(:)(.*)/;
push(@html, "<dt>$2</dt>", "<dd>$4</dd>");
} elsif ($tag[$#tag] =~ /^(blockquote)$/) { # now blockquote
s/^(>)//;
push(@html, "> $_<br>");
} elsif (/^(■|◆|●|▼)(.*)/) { # h2-4
$tag = ($1 eq '▼') ? 'ol' : 'ul';
$hn = int(@tag) + 2;
push(@toc, '-' x ($hn-1) . "<a href='#$tocnum'>$2</a>");
push(@html, "<a name='$tocnum'></a><h$hn>$1$2</h$hn>", "<$tag>");
push(@tag, $tag);
$tocnum++;
} elsif (/^(・)(.*)/) { # li
push(@html, "<li>" . &inline($2) . "</li>");
push(@html, "<br>") if ($browser{'kind'} eq 'pc');
} elsif (/^( )(.*)/) { # p
push(@html, "<p>" . &inline($2) . "</p>");
} elsif (/^(|)(.*)/) { # pre
push(@html, "<pre>");
push(@tag, 'pre');
redo;
} elsif (/^(>)(.*)/) { # blockquote
push(@html, "<blockquote>");
push(@tag, 'blockquote');
redo;
} elsif (/^(:)(.*)(:)(.*)/) { # dl,dt,dd
push(@html, "<dl>");
push(@tag, 'dl');
redo;
} elsif (/^([-]{4,})/) { # hr
push(@html, "<hr color='$html{'BodyHrColor'}'>");
} else {
push(@html, &inline($_) . "<br>");
}
}
## close tag
push(@html, map { "</$_>" } reverse @tag);
## autolink
my $html = &autolink( join("\n", @html) );
map { $html =~ s/$_/$trs{$_}/ } keys %trs;
@html = split("\n", $html);
## table of contents
if ($option{'toc'} && @toc) {
@toc = &convert_toc(@toc);
unshift(@toc, "<h2>■目次</h2>", "<div class='toc'>");
push(@toc, "</div>", "<br>");
return join("\n", @toc, @html);
} else {
return join("\n", @html);
}
}
sub back_push { # from YukiWiki
my ($tag, $level, $savedref, $resultref, $attr) = @_;
while (@$savedref > $level) {
push(@$resultref, shift(@$savedref));
}
if ($savedref->[0] ne "</$tag>") {
push(@$resultref, splice(@$savedref));
}
while (@$savedref < $level) {
unshift(@$savedref, "</$tag>");
push(@$resultref, "<$tag$attr>");
}
}
sub inline {
my ($text) = @_;
$text =~ s!
(
((mailto|http|https|ftp):([^\x00-\x20()<>\x7F-\xFF])*)
|
($upload_file)
|
($bracket_name)
)
!
&make_link($1)
!gex;
return $text;
}
sub make_link {
my ($text) = @_;
my ($rand) = &get_random($randmin, $randmax);
if ($text =~ /^(http|https|ftp):/) {
if ($text =~ /\.(gif|png|jpeg|jpg)$/) {
$trs{$rand} = "<a href='$text'><img src='$text'></a>";
} else {
$trs{$rand} = "<a href='$text'>$text</a>";
}
} elsif ($text =~ /^(mailto):(.*)/) {
$trs{$rand} = "<a href='$1:$2'>$2</a>";
} elsif ($text =~ /^$upload_file$/) {
my $filepath = "$BaseDir/cgi-files/attach/$1.dat";
if (-e $filepath) {
my (%info) = &read_infofile($filepath);
if ($info{'Extension'} =~ /(jpg|jpeg|gif|png)/) {
$trs{$rand} = "<img src='$BaseURL/cgi-files/attach/$info{'FileID'}.$info{'Extension'}'>";
} else {
$trs{$rand} = "<a href='$BaseURL/cgi-files/attach/$info{'FileID'}.$info{'Extension'}'>$info{'LocalFileName'}</a> ($info{'FileSize'} Byte)";
}
}
} elsif ($text =~ /^$bracket_name$/) {
my ($bracket_keyword) = $1;
if ( &keywiki::exists_keyword($bracket_keyword) ) { # read link
$trs{$rand} = "<a href='$ScriptName?key=@{[&encode_url($bracket_keyword)]}'>$bracket_keyword</a>";
} else { # edit link
$trs{$rand} = "<u>$bracket_keyword</u><a href='$ScriptName?cmd=edit&key=@{[&encode_url($bracket_keyword)]}'>?</a>";
}
}
return $rand;
}
sub autolink {
my $html = shift;
my $nowkey = quotemeta($in{'key'});
my $nodekey = quotemeta(&keywiki::get_node_keyword($in{'key'}));
my ($match, $title, $link);
foreach my $keyword ( &keywiki::get_keyword_list('mojisu') ) {
$match = ($keyword =~ /^($nowkey|$nodekey)$delimiter(.+)/) ? $2 : $keyword;
while ($html =~ /(\Q$match\E)/i) {
$title = &read_file("$SaveDir/wiki/@{[&encode($keyword)]}.dat", 'no_error', 1);
$link = "<a href='$ScriptName?key=@{[&encode_url($keyword)]}' title='@{[&escape_tag($title)]}'>$1</a>";
$html =~ s/\Q$1\E/&trs($link)/eo || &error("$match : $1");
}
}
return $html;
}
sub convert_toc {
my (@toc) = @_;
my (@tocsaved, @tocresult);
foreach (@toc) {
if (/^(-{1,3})(.*)/) {
&back_push('ul', length($1), \@tocsaved, \@tocresult);
push(@tocresult, '<li>' . $2 . '</li>');
}
}
push(@tocresult, @tocsaved);
return @tocresult;
}
sub is_bracket_name {
my ($name) = @_;
if ($name =~ /^$bracket_name$/) {
return 1;
} else {
return 0;
}
}
sub is_editable {
my ($keyword) = @_;
if (&is_bracket_name($keyword)) {
return 0;
} elsif ($keyword =~ /[\"\'\&\%\=\~\<\>\|\\]/) {
return 0;
} elsif ($keyword =~ /[\/]{3,}/) {
return 0;
} elsif (not $keyword) {
return 0;
} else {
return 1;
}
}
sub import_file {
my ($filepath, $extension) = @_;
my ($file, @result, @saved);
return $filepath if ($extension !~ /^(asp|txt|inc|frm|mod|scp)$/i);
return "Can't Open $filepath" if !(-e $filepath);
$file = &read_file($filepath);
&convert_jcode(\$file, 'euc', 'sjis') if ( &get_jcode($file) eq 'sjis' );
if ($extension eq 'frm') {
foreach my $line ( split("\n", $file) ) {
$line =~ s/\nPrivate Sub/\n\n■Private Sub/gi;
push(@result, $line);
}
} elsif ($extension eq 'txt') {
$file =~ s/(\_)(\s*)(\n)/$2/gs; # "_\n" => ""
foreach my $line ( split("\n", $file) ) {
$line = &trim($line);
if ($line =~ /^(\s*)(\')/) { # comment
next;
} elsif ($line =~ /^(Public|Private) (Sub|Function) (.*)\((.*)\)/) {
push(@result, "$1 $2 $3($4)");
}
# push(@result, $line);
}
} elsif ($extension eq 'asp') {
$file =~ s/(\_)(\s*?)(\n)/$2/gs; # "_\n" => ""
$file =~ s/(\n{2,})/\n/gs; # "\n\n" => "\n"
$file = "|$file";
foreach my $line ( split("\n", $file) ) {
push(@result, $line);
}
}
return join("\n", @result) . "\n";
}
sub trs {
my $str = shift;
my $rand = &get_random($randmin, $randmax);
redo if (defined $trs{$rand});
$trs{$rand} = $str;
return $rand;
}
__END__

更新者:りょうた 2005-04-25 (月) 10:01:02
作成者:りょうた 2005-04-25 (月) 10:00:46

■キーワード検索


KeyWiki Ver 0.6.9
(c) 2004 Ryota