#! /usr/bin/perl # # album3.cgi # 写真タイトルのリストとそれぞれをコメント付きで表示。 # album2.cgiより追加された機能 # - スライドショーモード # - ランダム表示モード # - 写真メニューオフモード # - 写真枠固定モード # - リストファイル作成ページ # - 写真アップロードページ # - リストファイル無効モード # # 3.013 : 6/17/07 : BODY内挿入に「
の前」を追加。 # 3.012 : 12/29/06 : head_insert_enを修正 # 3.011 : 11/20/06 : リストファイル作成ページエントリーの処理を修正 # 3.010 : 11/19/06 : イメージディレクトリにhttpからのパスを使えるように変更。body内挿入分を追加。 # 3.009 : 6/28/06 : ページ内のヘッダにCharsetを挿入 # 3.008 : 6/26/06 : コメントの位置を指定するオプションを追加 # 3.007 : 6/25/06 : レイアウトを修正 # 3.006 : 6/18/06 : タイプミスを修正 # 3.005 : 5/12/06 : 画像アップロード時のエラーを修正 # 3.004 : 10/20/05 : 更にフルパスを避けるコードを追加 # 3.003 : 10/19/05 : ファイルをアップロードした時にファイル名がフルパスになるのを修正 # 3.002 : 10/1/05 : Copyrightにリンクを追加 # 3.001 : 9/10/05 : タイトル表示と戻るリンク表示オプションを追加 # 3.0 : 9/6/05 : Created # # http://www.hidekik.com/ # # $Id: album3.cgi,v 1.33 2007/06/16 20:30:08 Hideki Kanayama Exp $ # Copyright(c) 2005-2007 Hideki Kanayama All rights reserved use strict; use CGI qw(:cgi-lib); use CGI::Carp qw(fatalsToBrowser); use GD; use File::Basename; use File::Copy; my $setupfile = "album_setup.pl"; my $adminpwd="albumadmin.txt"; # このスクリプト名 my $script = basename($0); my $version='3.013'; my $lastupdatedyear='2007'; my $charset = 'Shift_JIS'; my $lang = 0; #### 環境設定 ここから ############## # 画像があるディレクトリ(album3.cgiからみた相対パス、リストファイルを使う場合はhttp://からのパスでも可) our $imagedir = "."; # アルバムのリストファイル。写真のファイル名、タイトル、コメントをこの中に書く # 1:有効 0:無効 our $listfile_en = 1; our $listfile = "album.lst"; # 戻り先のリンク。 (album3.cgiから見た相対パスとファイル名、絶対パス、httpからの指定でも可) our $back_en = 1; our $back = "../.."; our $back_name = '戻る'; # アルバムタイトルの設定 our $title_en = 1; our $title_color = "#000000"; our $title_size = '+2'; our $title_face = ''; # メニューの位置 0:右 1:左 2:無し our $menu_locate = 0; # メニューテキストエリアのサイズ our $menu_height = 18; # スライドショー 0:スライドショーボタン無し 1:スライドショーボタンあり 2:強制スライドショー our $slideshow_en = 0; our $slideshow_int = 3; #インターバル # ランダム表示 0:off 1:on # Only applicable in slide show mode our $random_mode = 0; # 写真枠固定モード 0:off 1:on our $frame_fix_mode = 0; our $frame_fix_width = 640; our $frame_fix_height = 480; # コメントの位置 0:写真の上 1:写真の下 our $comment_loc = 0; # 管理人リンク 0:off 1:on our $adminlink_en = 1; # background our $bgimage_en=0; our $bgcolor="#ffffff"; our $bgimagefile=""; # 表示幅 our $body_width = 100; #スタイルシート 1:on 0:off our $style_sheet_en = 0; our $style_sheet = ' A:link {text-decoration: none} A:visited {text-decoration: none} A:active {text-decoration: none} '; #
〜内に挿入できる構文 1:on, 0:off
our $head_insert_en = 0;
our $head_insert = '';
#ページ内に表示させる文 0:常に非表示、1:常に表示、2:スライドショー時に非表示
our $body_insert1_en = 0;
our $body_insert1 = '';
our $bottomdisp1 = '';
#### 環境設定 ここまで ##############
require "$setupfile" if (-e "$setupfile");
my $q = new CGI;
my $cgierror = $q->cgi_error;
&error($cgierror) if ($cgierror);
my %in = $q->Vars;
%in=&postprocess(%in);
if (! -e "$adminpwd"){
if ($in{mode} eq 'wradminpwd'){
&wradminpwd;
} else {
&setadminpwd;
}
}
if ($in{mode} eq 'setup'){
&setupform;
} elsif ($in{mode} eq 'makesetup'){
&makesetup;
} elsif ($in{mode} eq 'listfileform'){
&listfileform;
} elsif ($in{mode} eq 'makelistfile'){
&makelistfile;
} else {
&dispphoto;
}
exit;
sub dispphoto {
my @filelist;
my @newlist;
my $image;
my $previmage;
my $nextimage;
my $title;
my $line;
my $comment;
my $nexttitle;
my $prevtitle;
my $prevcomment;
my $photoimage;
my $phototitle;
my $photocomment;
my $flag;
my $nextcomment;
my $nextlink1;
my $nextlink2;
my $prevlink;
my $nextlink;
my $caller = 'dispphoto';
if (!open(FILE,"< $listfile") or $listfile_en == 0){
opendir(IMGDIR,"$imagedir") or &error("ディレクトリ$imagedirが開けません \n";
}
if ($back_en){
print " \n";
}
if ($slideshow_en == 1){
print "
管理用から画像ファイルをアップロードするか、
リストファイルが見つからないのでリストファイルを作成し、
そのファイルを指定し、設定を有効にしてください。");
@filelist = grep !/^\./, readdir IMGDIR;
closedir(IMGDIR);
@newlist = ( grep /\.jpe?g$/i, @filelist);
@newlist = (@newlist, grep /\.gif$/i, @filelist);
@newlist = (@newlist, grep /\.png$/i, @filelist);
@newlist = (@newlist, grep /\.bmp$/i, @filelist);
@newlist = (@newlist, grep /\.tiff?$/i, @filelist);
@newlist = (@newlist, grep /\.ief$/i, @filelist);
@newlist = (@newlist, grep /\.cgm$/i, @filelist);
@newlist = (@newlist, grep /\.pcx$/i, @filelist);
@newlist = (@newlist, grep /\.gd$/i, @filelist);
@newlist = (@newlist, grep /\.gd2$/i, @filelist);
@newlist = (@newlist, grep /\.xbm$/i, @filelist);
@newlist = (@newlist, grep /\.xpm$/i, @filelist);
@filelist = sort @newlist;
&error("画像ファイルが${imagedir}にありません。
画像ファイルを${imagedir}に置くか、管理用から画像ファイルをアップロードするか、
リストファイルを作成し、設定を正しくしてください。") if ($#filelist == -1);
if ($random_mode){
$image = $filelist[rand $#filelist+1];
} else {
if ($in{image} eq ''){
$image = $filelist[0];
$previmage = '';
$nextimage = $filelist[1];
} else {
$image = $in{image};
my $hitnum;
foreach (@filelist){
last if (/^$in{image}$/);
$hitnum++;
}
$previmage = $filelist[$hitnum-1] unless ($hitnum == 0);
$nextimage = $filelist[$hitnum+1] unless ($hitnum >= $#filelist);
}
}
$title = $image;
} else {
flock FILE, 2;
@filelist =
管理用からセットアップ、またはリストファイルを修正してください。");
}
&htmlhead($title,'dispphoto',$nextimage);
if ($body_insert1_en == 1 or
$body_insert1_en ==2 and ($in{slideshow} ne 'on' or $nextimage eq '')){
print "$body_insert1";
}
$flag = 0;
foreach (@filelist){
($photoimage,$phototitle,$photocomment)=split(/,/);
if ($flag == 1) {$nextimage = $photoimage;last;}
if ($image eq $photoimage){$flag = 1;}
}
if ($title_en){
print "\n";
if ($comment_loc == 0) {
&comment_disp("$menu_locate","$comment");
}
print "
\n";
if ($previmage eq '') {
$prevlink="$back";
$prevtitle = "トップへ";
} else {
$prevlink = "$script?image=$previmage";
}
if ($nextimage eq '') {
$nextlink="$back";
$nexttitle = "トップへ";
} else {
$nextlink = "$script?image=$nextimage";
}
if ($random_mode == 0){
print qq(\n";
if ($menu_locate == 1){
&listform($image,\@filelist);
}
my ($set_width, $set_height);
my $td_width;
if ($frame_fix_mode){
my $im;
$image =~ /\.jpe?g$/i and $im = GD::Image->newFromJpeg($imagefile);
$image =~ /\.gif$/i and $im = GD::Image->newFromGif($imagefile);
$image =~ /\.png$/i and $im = GD::Image->newFromPng($imagefile);
$image =~ /\.xbm$/i and $im = GD::Image->newFromxbm($imagefile);
$image =~ /\.gd$/i and $im = GD::Image->newFromgd($imagefile);
$image =~ /\.gd2$/i and $im = GD::Image->newFromgd2($imagefile);
$image =~ /\.xpm$/i and $im = GD::Image->newFromxpm($imagefile);
my ($width, $height) = $im->getBounds();
my $actual_width;
my $actual_height;
if ($width > $frame_fix_width or $height > $frame_fix_height){
my $width_shrink = $frame_fix_width / $width;
my $height_shrink = $frame_fix_height / $height;
my $shrink_ratio;
if ($width_shrink < $height_shrink){
$shrink_ratio = $width_shrink;
} else {
$shrink_ratio = $height_shrink;
}
$actual_width = int($width * $shrink_ratio);
$actual_height = int($height * $shrink_ratio);
} else {
$actual_width = $width;
$actual_height = $height;
}
$set_width = "width=$actual_width";
$set_height = "height=$actual_height";
$td_width = "width=\"$frame_fix_width\"";
} else {
$set_width = '';
$set_height = '';
$td_width = '';
}
if ($nextimage ne ''){
if ($random_mode){
$nextlink1 = "";
} else {
$nextlink1 = "";
}
$nextlink2 = "";
} else {
$nextlink1 = '';
$nextlink2 = '';
}
print " \n";
if ($comment_loc == 1) {
&comment_disp("$menu_locate","$comment");
}
print "";
print "$nextlink1 \n";
if ($menu_locate == 0){
&listform($image,\@filelist);
}
print "$nextlink2";
print "
\n);
print qq{
\n};
} else {
print qq{\n};
print qq{ };
print qq{←$prevtitle};
print qq{ \n};
print qq{};
print qq{$nexttitle→};
print qq{ \n};
print qq{
};
}
if ($adminlink_en) {
print qq{\n";
if ($menu_locate == 0){
print " \n";
}
sub listform {
my $image = shift;
my $filelist = shift;
my %default_image;
my $align;
if ($menu_locate == 0){
$align = 'align=left';
} else {
$align = 'align=right';
}
print "$comment \n";
print " \n";
} elsif ($menu_locate == 1) {
print " \n";
print "$comment \n";
} elsif ($menu_locate == 2) {
print "$comment \n";
}
print "\n";
print "\n";
print "\n";
print " \n";
}
sub postprocess {
my (%in) = @_;
my $key;
my $value;
while (($key,$value)=each %in){
next if ($key =~ /^upfile/);
my $br = "
";
if ($key !~ /^comment/){
$value =~ s/</g;
$value =~ s/>/>/g;
}
if ($value =~ /\r\n/) { $value =~ s/\r\n/$br/g; }
if ($value =~ /\n/) { $value =~ s/\n/$br/g; }
if ($value =~ /\r/) { $value =~ s/\r/$br/g; }
if ($value =~ /,/) { $value =~ s/,/&\#44;/g; }
$in{"$key"}=$value;
}
return(%in);
}
sub makecrypt {
my $plain = shift;
my $salt = join "", ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64];
my $result = crypt($plain,$salt) or crypt($plain,'$1$'.$salt.'$');
return $result;
}
sub checkcrypt {
my ($pwd,$encpwd)=@_;
return(crypt($pwd,$encpwd) eq "$encpwd" or &checkadmin($pwd));
}
sub checkadmin {
my $pwd = shift;
if (open(FILE,"< $adminpwd")){
my $filepwd =
/\n/g;
$in{$_} =~ s/,/,/g;
$in{$_} =~ s/<//g;
}
open(SETUP,"> $setupfile");
print SETUP <
\n";
print "$bottomdisp1";
print "\n";
}
sub htmltail {
undef $q;
my $mysite = ('http://www.hidekik.com/','http://www.hidekik.com/en/')[$lang];
print "