#! /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が開けません
管理用から画像ファイルをアップロードするか、
リストファイルが見つからないのでリストファイルを作成し、
そのファイルを指定し、設定を有効にしてください。"); @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 = ; close(FILE); chomp(@filelist); @filelist = grep !/^\s*$/, @filelist; @filelist = grep !/^\s*,/, @filelist; @filelist = grep !/^\s*#/, @filelist; if ($random_mode){ $line = $filelist[rand $#filelist+1]; ($image,$title,$comment)=split(/,/,$line); } else { if ($in{image} eq '') { $line = $filelist[0]; ($image,$title,$comment)=split(/,/,$line); $line = $filelist[1]; ($nextimage,$nexttitle,$nextcomment)=split(/,/,$line); } else { my $i=0; foreach (@filelist){ ($image,$title,$comment)=split(/,/); if ($image eq $in{image}){ ($nextimage,$nexttitle,$nextcomment)=split(/,/,$filelist[$i+1]); ($previmage,$prevtitle,$prevcomment)=split(/,/,$filelist[$i-1]) unless ($i == 0); last; } $i++; } } } } $title = $image if ($title eq ''); $nexttitle = $nextimage if ($nexttitle eq ''); $prevtitle = $previmage if ($prevtitle eq ''); my $imagefile = "$imagedir/$image"; if ((! -e $imagefile) and $listfile_en == 0){ &error("${imagefile}が見つかりません。
管理用からセットアップ、またはリストファイルを修正してください。"); } &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 "
$title

\n"; } if ($back_en){ print "

$back_name

\n"; } if ($slideshow_en == 1){ print "

\n"; if ($in{slideshow} eq 'on' and $nextimage){ print "

\n"; } else { print ""; print "秒間隔で"; print "

\n"; print "\n"; } print "\n"; print "

\n"; } my $cols; if ($menu_locate == 2){ $cols = 1; } else { $cols = 2; } print "\n"; if ($comment_loc == 0) { &comment_disp("$menu_locate","$comment"); } print "\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 ($menu_locate == 0){ &listform($image,\@filelist); } print "\n"; if ($comment_loc == 1) { &comment_disp("$menu_locate","$comment"); } print "
"; print "$nextlink1$nextlink2"; 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); print qq{\n}; print qq{\n}; print qq{\n}; print qq{
}; print qq{←$prevtitle}; print qq{}; print qq{$nexttitle→}; print qq{
\n}; } else { print qq{
}; } if ($adminlink_en) { print qq{
管理用
}; } &htmltail; } sub comment_disp { my $menu_locate = shift; my $comment = shift; print "\n"; if ($menu_locate == 0){ print "$comment\n"; print " \n"; } elsif ($menu_locate == 1) { print " \n"; print "$comment\n"; } elsif ($menu_locate == 2) { print "$comment\n"; } 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 "\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; } 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 = ; close(FILE); my $inpwd = crypt($pwd,$filepwd); return ("$inpwd" eq "$filepwd"); } else { &error('パスワードファイルが存在しません'); } } sub setadminpwd { &htmlhead('管理者用パスワードを入力してください'); print "\n"; if ($in{mode} eq 'setup'){ print "
管理者用パスワードを入力してください。
\n"; print "\n"; print "
\n"; print "セットアップ\n"; print "リストファイル作成、画像アップロード\n"; } else { print "
管理者用パスワードを設定してください。
\n"; print "\n"; print "\n"; print "\n"; } print ""; &htmltail; } sub wradminpwd { my $plain = $q->param('pwd'); my $passwd = &makecrypt($plain); if (open(FILE,"> $adminpwd")){ print FILE "$passwd"; close(FILE); } else { &error('パスワードファイル作成に失敗しました'); } print "Location: $script\n\n"; } sub setupform { my $inpwd = $q->param('pwd'); &setadminpwd if ($inpwd eq ''); &error('管理用パスワードが違います。') unless &checkadmin($inpwd); my @title_check; my @back_check; my @menu_locate_check; my @bgimage_check; my @listfile_check; my @slideshow_check; my @random_check; my @frame_fix_check; my @adminlink_check; my @style_sheet_check; my @head_insert_check; my @comment_loc_check; my @body_insert1_check; $title_check[$title_en] = "checked"; $back_check[$back_en] = "checked"; $menu_locate_check[$menu_locate] = "checked"; $bgimage_check[$bgimage_en] = "checked"; $listfile_check[$listfile_en] = "checked"; $slideshow_check[$slideshow_en] = "checked"; $random_check[$random_mode] = "checked"; $frame_fix_check[$frame_fix_mode] = "checked"; $adminlink_check[$adminlink_en] = "checked"; $style_sheet_check[$style_sheet_en] = "checked"; $head_insert_check[$head_insert_en] = "checked"; $comment_loc_check[$comment_loc] = "checked"; $body_insert1_check[$body_insert1_en] = "checked"; &htmlhead('管理人セットアップ'); print "
\n"; print "\n"; print "\n"; print <
  • 管理用リンクを非表\示にしている場合は、$script?mode=setupからパスワードを入力してこのページに入ってください。
  • 数字やカラー指定は必ず半角で指定してください。全角やブランクだとCGIが起動しなくなります。万一間違って全角で書いてしまった場合は、$setupfileをエディタで開きその場所を半角に正しく修正してください。それで直ります。
画像ディレクトリ CGIディレクトリからみた相対パス。(album3.cgiからみた相対パス、リストファイルを使う場合はhttp://からのパスでも可)
リストファイル 有効 無効
アルバムのリストファイル。写真のファイル名、タイトル、コメントをこのファイルに書く。
アルバムタイトル 表\示 非表\示
色:color= サイズ:size= フォント:face= 「戻る」リンク 表\示 非表\示
戻り先のリンク($scriptからみた相対パスとファイル名、絶対パス、httpからの指定でも可)

リンク名 メニューの位置 無し メニューのテキストエリアサイズ スライドショー スライドショーボタン無し スライドショーボタンあり 強制スライドショー
強制スライドショーのインターバル秒 ランダム表\示 無効 有効
写真枠固定 無効 有効
高さ
写真枠固定できるファイルは、jpg, gif, png, gd, gd2, xbm, xpmファイルのみです。 コメントの位置 写真の上 写真の下 管理人リンク あり なし 壁紙 画像 カラー
画像ファイル
カラー
表\示幅 ブラウザ全体の
表\示幅を小さく設定しても写真の幅+メニューの幅以下にはなりません。 スタイルシート 有効 無効

<head>内挿入文 有効 無効
HTML書式
ポップアップ広告やJavascript、<META>を挿入したい場合にここに記述する。
以下の記述が<head>〜</head>内に挿入される。

<body>内挿入文 ページ上部に表\示される文をHTMLで記述。
常に表\示 常に非表\示 スライドショー時に非表\示

ページ下部(</body>タグのすぐ上)への表\示(常に表\示されます)

END print ""; print ""; &htmltail; } ########################################################################### # Setup files write ####################################################### ########################################################################### sub makesetup { my $inpwd = $q->param('pwd'); &setadminpwd if ($inpwd eq ''); &error('管理用パスワードが違います。') unless &checkadmin($inpwd); foreach (keys(%in)){ $in{$_} =~ s/
/\n/g; $in{$_} =~ s/,/,/g; $in{$_} =~ s/<//g; } open(SETUP,"> $setupfile"); print SETUP <〜内に挿入できる構\文 1:on, 0:off \$head_insert_en = $in{head_insert_en}; \$head_insert = '$in{head_insert}'; #ページ内に表\示させる文 0:常に非表\示 1:常に表\示 2:スライドショー時非表\示 \$body_insert1_en = $in{body_insert1_en}; \$body_insert1 = '$in{body_insert1}'; \$bottomdisp1 = '$in{bottomdisp1}'; #### 環境設定 ここまで ############## 1; END close(SETUP); print "Location: $script\n\n"; } sub error { my ($msg) = shift; &htmlhead($msg); print "
$msg
\n"; &htmltail; exit; } sub htmlhead { my $title = shift; my $caller = shift; my $nextimage = shift; my $bgimage; if ($bgimage_en == 1){ $bgimage = "background=\"$bgimagefile\""; } else { $bgimage = "bgcolor=\"$bgcolor\""; } print $q->header(-charset=>"$charset"); print "\n"; print "\n"; print "\n"; print "$title\n"; if ($head_insert_en == 1){ print "$head_insert\n"; } if ($style_sheet_en == 1){ print "\n"; } my $preload; if ($caller eq 'dispphoto'){ print < nextimage = new Image(); function preload(nextpic){ if (nextpic != ''){ nextimage.src = "$imagedir/" + nextpic; } } function showpic(picfile){ self.location="$script?image=" + picfile; } JAVASCRIPT $preload = "onLoad=\"preload(\'$nextimage\')\"" unless ($random_mode); if ($slideshow_en == 2 or $in{slideshow} eq 'on'){ my $interval; if ($in{slideshow_int}) { $slideshow_int = $in{slideshow_int}; $interval = "&slideshow_int=$slideshow_int"; } my $slideshow = '&slideshow=on'; my $next; if ($nextimage){ $next = "image=$nextimage"; } else { $slideshow =~ s/^&//; } if ($nextimage or $random_mode){ print "\n"; } } } print "\n"; print "\n"; print "
\n"; } sub htmltail { undef $q; my $mysite = ('http://www.hidekik.com/','http://www.hidekik.com/en/')[$lang]; print "
album3.cgi Ver. $version
\n"; print "
Copyright(C) 2005-$lastupdatedyear, hidekik.com
\n"; print "
\n"; print "$bottomdisp1"; print "\n"; exit; } sub listfileform { my $inpwd = $q->param('pwd'); &setadminpwd if ($inpwd eq '' and !-e "$adminpwd"); &error('管理用パスワードが違います。') unless &checkadmin($inpwd); &htmlhead('リストファイル作成'); print "
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; my $i = 0; if (open(LISTFILE, "< $listfile")){ while (){ chomp; my ($file,$title,$comment) = split /,/; &drawlistform($i,$file,$title,$comment); $i++; } close(LISTFILE); } my $j; for ($j=$i;$j<=$i+9;$j++){ &drawlistform($j); } $j--; print "\n"; print "\n"; print "\n"; print "\n"; $i = 0; foreach ($i .. $i+9){ my $upfile_name = "upfile_$_"; print "\n"; print "\n"; print "\n"; } print "\n"; print "\n"; print "\n"; print "
\n"; print "
  • 管理用リンクを非表\示にしている場合は、$script?mode=setupからパスワードを入力してこのページに入ってください。
  • \n"; print "
  • ファイルのアップロードはこの画面で必ずしも必要ではありません。FTP等別の方法でサーバーにアップしてもかまいません。
  • \n"; print "
  • リストファイルはこの画面で必ずしも設定する必要はありません。別にエディタで作成し、FTP等でサーバーにアップしてもかまいません。
  • \n"; print "
  • 既にリストファイルがある場合はこのページにそれが反映されます。
  • \n"; print "
  • リストを記入するフィールドが足りない場合は一度「作成」ボタンをクリックしてください。次にこのページを開いた時に追加のフィールドが表\示されます。
  • \n"; print "
  • リストファイルを無効に設定していてもこのページには存在するリストファイルの情報が表\示され、更新することができます。
  • \n"; print "
  • アップロードファイルと同じファイル名が既にサーバー上に存在する場合は上書きされます。
  • \n"; print "
  • アップロードは最大10ファイルまで一度にできます。
  • \n"; print "
  • リストファイルのファイル名をブランクにするとその行は登録されません。
  • \n"; print "
  • ファイル名に全角文字が含まれている場合の動作の保障はできません。半角でファイルをアップロードすることをお勧めします。
  • \n"; print "
  • コメントのみタグの使用が可能\です。
  • \n"; print "
    \n"; print "リストファイル作成"; print "
    ファイル名タイトルコメント
    "; print "画像ファイルアップロード"; print "
    "; print ""; print "
    \n"; print ""; print "
    \n"; print "
    \n"; &htmltail; } sub drawlistform { my ($i, $file, $title, $comment) = @_; my $file_name = "file_$i"; my $title_name = "title_$i"; my $comment_name = "comment_$i"; print "\n"; print ""; print ""; print "\n"; print ""; print ""; print "\n"; print ""; print ""; print "\n"; print "\n"; } sub makelistfile { my $inpwd = $q->param('pwd'); &setadminpwd if ($inpwd eq ''); &error('管理用パスワードが違います。') unless &checkadmin($inpwd); my $max_line = $q->param('max_line'); open (FILE, "+< $listfile") or open(FILE, "> $listfile") or &error("$listfileが開けません。"); flock FILE, 2; truncate FILE, 0; seek FILE, 0, 0; foreach (0 .. $max_line) { my $file_name = "file_$_"; my $title_name = "title_$_"; my $comment_name = "comment_$_"; next unless ($in{$file_name}); print FILE "$in{$file_name},$in{$title_name},$in{$comment_name}\n"; } close(FILE); unlink($listfile) if (-z $listfile); foreach (0 .. 9) { my $upfile = "upfile_$_"; if ("$in{$upfile}" ne '') { my $upname = basename($in{$upfile}); $upname =~ s/^.+[\/\\]([^\/\\]+)$/$1/; #just in case &error("画像ディレクトリ${imagedir}が存在しません。") if (! -d "$imagedir"); my $uphandle = $q->upload("$upfile"); my $cgierror = $q->cgi_error; &error("$cgierror") if (!$uphandle && $cgierror); my $outfile = "$imagedir/$upname"; copy($uphandle, "$outfile") or &error("アップロードに失敗しました。"); close $uphandle if ($uphandle); chmod (0666, "$outfile"); } } print "Location: $script\n\n"; }