#============================================================ # PictureGalleryObject #============================================================ package PictureGalleryObject; use CGI::BrowseFilesObject; @ISA = qw(BrowseFilesObject); #公開したいサブルーチン #@EXPORT = qw(erfc tan); @EXPORT_OK = qw(); use strict; use Template; use Archive::Zip qw( :ERROR_CODES :CONSTANTS ); use Cwd; #========================================== # 大域変数 #========================================== my $ShowDirTreeLinkPrivilege = 'ShowDirTreeLink'; my $ImageFilesRegExp = "\\.(jpe?g|tiff?|bmp)\$"; my $DownloadAccountKey = 'UserPictureGalleryAccount'; my $MakePDFFirstPageImage = 1; my $MakeThumbnail = 1; my $TempPDFName = 'first_page_only.pdf'; my $TempCopyFile = "CopiedTemp.pdf"; my $ImageFileDensity = 192; #my $ghostscriptPath = "D:\\Programs\\gnu\\gs\\gs9.00\\bin"; my $ghostscriptPath = "D:\\Programs\\gnu\\gs\\gs9.05\\bin"; #============================================================ # コンストラクタ、デストラクタ #============================================================ sub new { my ($module) = @_; my $this = {}; bless $this,$module; # $this->SUPER::new(@_); return $this; } sub DESTROY { my $this = shift; $this->SUPER::DESTROY(@_); } sub Configure { my ($this, $modulename, $privilege, $privilegemakephotoalbum, $rootpath, $keyword, $picturemask, $picturethumbnailwidth, #$imagesourcetemplate, $thumbnaillinktemplate, $pPermittedDirs, $pBrowseFiles, $pDenyFiles, $pSubstitutionSource, $pSubstitutionTarget, $pURLSubstitutionList, $pURLReverseSubstitutionList, $showdate, $showdirectory, $showparentdirectory, $showfilesize, $targetpage, %hash) = @_; #Utils::InitHTML(); #print("PictureGalleryObject::Configure
\n"); $ShowDirTreeLinkPrivilege = $this->{ShowDirTreeLinkPrivilege} = $hash{ShowDirTreeLinkPrivilege} if($hash{ShowDirTreeLinkPrivilege} ne ''); $this->SUPER::Configure($modulename, $privilege, $rootpath, $keyword, $pPermittedDirs, $pBrowseFiles, $pDenyFiles, $pSubstitutionSource, $pSubstitutionTarget, $pURLSubstitutionList, $pURLReverseSubstitutionList, $showdate, $showdirectory, $showparentdirectory, $showfilesize, $targetpage, %hash); $this->{ModuleName} = $modulename if(defined $modulename); $this->{Privilege} = $privilege if(defined $privilege); $this->{PrivilegeMakePhotoAlbum} = $privilegemakephotoalbum if(defined $privilegemakephotoalbum); $ImageFilesRegExp = $this->{ImageFilesRegExp} = $hash{ImageFilesRegExp} if($hash{ImageFilesRegExp} ne ''); $ImageFilesRegExp = $this->{ImageFilesRegExp} = $hash{ImageFilesRegExp} if($hash{ImageFilesRegExp} ne ''); #Utils::InitHTML(); #print("args[$keyword][$picturemask]
\n"); #print("r[$this->{RootPath}][$rootpath]
\n"); $rootpath =~ s/\\/\//g; $rootpath =~ s/\/\/+/\//g; $this->{RootPath} = $rootpath if(defined $rootpath); $this->{Keyword} = $keyword if(defined $keyword); $this->{pPermittedDirs} = $pPermittedDirs if(defined $pPermittedDirs); #print("f[$this->{RootPath}]"); #my $p = $this->{pPermittedDirs}; #print("P: ", join(',', @$p), "\n"); $this->{pBrowseFiles} = $pBrowseFiles if(defined $pBrowseFiles); $this->{pDenyFiles} = $pDenyFiles if(defined $pDenyFiles); $this->{pSubstitutionSource} = $pSubstitutionSource if(defined $pSubstitutionSource); $this->{pSubstitutionTarget} = $pSubstitutionTarget if(defined $pSubstitutionTarget); $this->{pURLSubstitutionList} = $pURLSubstitutionList if(defined $pURLSubstitutionList); $this->{pURLReverseSubstitutionList} = $pURLReverseSubstitutionList if(defined $pURLReverseSubstitutionList); $this->{PictureMask} = $picturemask if(defined $picturemask); $this->{PictureThumbnailWidth} = $picturethumbnailwidth if(defined $picturethumbnailwidth); # $this->{ImageSourceTemplate} = $imagesourcetemplate if(defined $imagesourcetemplate); # $this->{ThumbnailLinkTemplate} = $thumbnaillinktemplate if(defined $thumbnaillinktemplate); #print("
d: [" , @{$this->{pPermittedDirs}}, "]
\n"); if($hash{App}) { my $App = $hash{App}; my $pParams = $App->pParams(); my @DownloadDirs = Utils::MergeList(@{$this->{pPermittedDirs}}, @{$pParams->{pDownloadDirs}}); #$App->print("dirs [", join(',', @DownloadDirs), "]\n"); $pParams->{pDownloadDirs} = \@DownloadDirs; my @DownloadDirsRegExp = $App->ConvertAllowedDirArrayToRegExp(\@DownloadDirs); $pParams->{pDownloadDirsRegExp} = \@DownloadDirsRegExp; } $this->{ShowDate} = $showdate if(defined $showdate); $this->{ShowDirectory} = $showdirectory if(defined $showdirectory); $this->{ShowParentDirectory} = $showparentdirectory if(defined $showparentdirectory); $this->{ShowFileSize} = $showfilesize if(defined $showfilesize); $this->{TargetPage} = $targetpage if(defined $targetpage); $this->{ThumbnailDisplayWidth} = 150 if(!$this->{ThumbnailDisplayWidth}); $this->{nColumns} = 5 if(!$this->{nColumns}); $this->{MakeAlbumPDF} = 1 if(!defined $this->{MakeAlbumPDF}); $this->{MakeAlbumZIP} = 1 if(!defined $this->{MakeAlbumZIP}); foreach my $key (keys %hash) { $this->{$key} = $hash{$key}; } } sub ShowFileList { my ($this, $App, $pParams, %args) = @_; Utils::MergeHash($this, \%args); my $RootPath = $args{RootPath}; my $Path = $args{Path}; my $pPermittedDirs = ($args{pPermittedDirs})? $args{pPermittedDirs} : ["^$RootPath(/[^_].*)?\$"]; my $pBrowseFiles = ($args{pBrowseFiles})? $args{pBrowseFiles} : []; my $pDenyFiles = ($args{pDenyFiles})? $args{pDenyFiles} : []; my $pSubstitutionSource = ($args{pSubstitutionSource})? $args{pSubstitutionSource} : []; my $pSubstitutionTarget = ($args{pSubstitutionTarget})? $args{pSubstitutionTarget} : []; my $pURLSubstitutionList = ($args{pURLSubstitutionList})? $args{pURLSubstitutionList} : []; my $pURLReverseSubstitutionList = ($args{pURLReverseSubstitutionList})? $args{pURLReverseSubstitutionList} : []; # @PermittedDirs = @$pPermittedDirs; #$App->H2("f[$RootPath][$Path][$this->{RootPath}]"); #$App->H2("P: ", join(',', @$pPermittedDirs), "\n"); my $ModuleName = $args{ModuleName}; my $Privilege = ($args{Privilege})? $args{Privilege} : 'PictureGallery'; my $PrivilegeMakePhotoAlbum = ($args{PrivilegeMakePhotoAlbum})? $args{PrivilegeMakePhotoAlbum} : 'MakePhotoAlbum'; my $Keyword = (defined $args{Keyword})? $args{Keyword} : 'Keyword'; my $PictureMask = (defined $args{PictureMask})? $args{PictureMask} : "\\.(jpg|jpeg|bmp|dib|tga|gif|tif|tiff|png)\$"; my $ThumbnailWidth = (defined $args{ThumbnailWidth})? $args{ThumbnailWidth} : 300; my $ShowDate = (defined $args{ShowDate})? $args{ShowDate} : 1; my $ShowDirectory = (defined $args{ShowDirectory})? $args{ShowDirectory} : 1; my $ShowParentDirectory = (defined $args{ShowParentDirectory})? $args{ShowParentDirectory} : 1; my $ShowFileSize = (defined $args{ShowDate})? $args{ShowFileSize} : 1; my $TargetPage = (defined $args{TargetPage})? $args{TargetPage} : '_blank'; my $pPrevFunc = $args{pPrevFunc}; my $pPostFunc = $args{pPostFunc}; my $Script = $args{Script} if(defined $args{Script}); my $MultiFunctionTableJScript = $args{MultiFunctionTableJScript} if(defined $args{MultiFunctionTableJScript}); my $pMultiFunctionTableConfig = $args{pMultiFunctionTableConfig} if(defined $args{pMultiFunctionTableConfig}); my ($DivClass, $HrefClass, $HrefGroup, $ImgClass, $FirstStringInBody) = JSParams->new()->GetPictureGalleryString($Script); my $MultiFunctionTableJScript = JSParams->new()->GetMultiFunctionalTableString('.TableTest3', sortList => '[[1,0]]', excludeColumns => '[2,3]'); my %MultiFunctionTableConfigByClass = ( class => 'tablesorter' ); $DivClass = $args{DivClass} if(defined $args{DivClass}); $HrefClass = $args{HrefClass} if(defined $args{HrefClass}); $HrefGroup = $args{HrefGroup} if(defined $args{HrefGroup}); $ImgClass = $args{ImgClass} if(defined $args{ImgClass}); $FirstStringInBody = $args{FirstStringInBody} if(defined $args{FirstStringInBody}); $pParams->{NextAction} = ($args{NextAction})? $args{NextAction} : "$ModuleName::ShowPage"; $pParams->{SubMenuFunction} = $args{SubMenuFunction}; $this->Configure($ModuleName, $Privilege, $PrivilegeMakePhotoAlbum, $RootPath, $Keyword, $PictureMask, $ThumbnailWidth, $pPermittedDirs, $pBrowseFiles, $pDenyFiles, $pSubstitutionSource, $pSubstitutionTarget, $pURLSubstitutionList, $pURLReverseSubstitutionList, $ShowDate, $ShowDirectory, $ShowParentDirectory, $ShowFileSize, $TargetPage, ); $this->ShowPage($App, $pParams, $RootPath, $pPrevFunc, $pPostFunc, Script => $Script, DivClass => $DivClass, HrefClass => $HrefClass, HrefGroup => $HrefGroup, ImgClass => $ImgClass, FirstStringInBody => $FirstStringInBody, MultiFunctionTableJScript => $MultiFunctionTableJScript, pMultiFunctionTableConfig => \%MultiFunctionTableConfigByClass, ); } #============================================================ # メンバー関数 #============================================================ sub GetParameterHash { my ($this, $App, $pParams) = @_; return {}; } sub IsOpen { my ($this, $App, $pParams, $IsPrint) = @_; return if($this->{RootPath} eq ''); my $ret = $App->HasPrivilege($this->{Privilege}, $IsPrint); return $ret; } sub ShowMenu { my ($this, $App, $pParams, $ProgramPath, $BaseOption) = @_; return 0; } sub ShowPage { my ($this, $App, $pParams, $Path, $pPrevFunc, $pPostFunc, %args) = @_; return if(!$this->IsOpen($App, $pParams, 0)); $this->{ShowPictureList} = 1 if(!defined $this->{ShowPictureList}); $this->{ShowFileList} = 1 if(!defined $this->{ShowFileList}); $this->{ShowPageTitle} = 1 if(!defined $this->{ShowPageTitle}); $this->{ShowMakeArchiveLinks} = 1 if(!defined $this->{ShowMakeArchiveLinks}); $MakeThumbnail = $this->{MakeThumbnail} if(defined $this->{MakeThumbnail}); my $CanShowDirTreeLinkPrivilege = $App->HasPrivilege($ShowDirTreeLinkPrivilege, 0); $this->{RootPath} = Template->new()->ReplaceByHash($this->{RootPath}, $pParams, '{', '}', 0, $pParams->{WebCharSet}, 0, 1, 0); $pParams->{Path} = $Path if(defined $Path); $pParams->{Path} = Utils::MakePath($this->{RootPath}, $pParams->{Path}, '/', 0) if($pParams->{Path} =~ /^\./); $pParams->{Path} = $this->{RootPath} if(!defined $pParams->{Path}); $pParams->{Path} = $pParams->{RootPath} if(!defined $pParams->{Path}); $pParams->{Path} = Template->new()->ReplaceByHash($pParams->{Path}, $pParams, '{', '}', 0, $pParams->{WebCharCode}, 0, 1, 0); # $pParams->{Path} = Template->new()->ReplaceByHash($pParams->{Path}, $pParams, '{', '}', 0, $pParams->{FileSystemCharCode}, 0, 1, 0); Jcode::convert(\$pParams->{Path}, $pParams->{FileSystemCharCode}); #$App->print("Path[$pParams->{Path}] RootPath[$this->{RootPath}]\n"); $pParams->{Path} = Utils::ReduceDirectory($pParams->{Path}, undef, $App); # $Path = $pParams->{Path}; $Path = $pParams->{Path}; #$App->print("Path[$pParams->{Path}]\n"); my ($IsPermitted, $BrowseDir, $FileRegExp, $DirRegExp, $ss, $st) = $this->IsPermitted($App, $pParams, $Path); if(!$IsPermitted) { $App->H2("Error in PictureGallerObject::ShowPage: Browsing $Path is not permitted."); return; } &$pPrevFunc($App, $pParams) if($pPrevFunc); my $fmask = Utils::MakePath($pParams->{Path}, '*', '/', 0); #$App->print("fmask[$fmask]\n"); my @files = $App->GetFileList($pParams, $fmask, 1); #$App->print("nFiles: ", scalar @files, "\n"); my $MultiFunctionTableJScript = JSParams->new()->GetMultiFunctionalTableString('#TableTest3', sortList => '[[1,1]]', excludeColumns => '[2,3]'); my %MultiFunctionTableConfigByClass = ( id => 'TestTable3', class => 'tablesorter' ); # $pParams->{NextAction} = ''; # $pParams->{SubMenuFunction} = ''; #"ManageDownload::ShowSubMenu" if($pParams->{SubMenuFunction} ne ''); if($this->{ShowPageTitle} and $CanShowDirTreeLinkPrivilege) { #$App->print("Path[$pParams->{Path}] RootPath[$this->{RootPath}]\n"); my $link = $this->MakeDirTreeLink($App, $pParams, $pParams->{Path}); #$App->print("link[$link]\n"); Jcode::convert(\$link, $pParams->{WebCharCode}); $App->mlPrintRawHTML('en' => "

Browse [$link]

", 'jp' => "

[$link]を表示

"); } # 写真表示 if($MakePDFFirstPageImage) { $this->MakePDFFirstPageImage( $App, $pParams, $Path, %args, pFiles => \@files); @files = $App->GetFileList($pParams, Utils::MakePath($pParams->{Path}, '*', '/', 0), 1); } if($this->{ShowPictureList} or $pParams->{ShowPictureList}) { $this->MakeThumbnail( $App, $pParams, $Path, %args, pFiles => \@files) if($MakeThumbnail); $this->ShowPictureList( $App, $pParams, $Path, %args, pFiles => \@files); $this->ShowMakeArchiveLinks($App, $pParams, $Path, %args) if($this->{ShowMakeArchiveLinks}); } # フォルダー・ファイルリスト表示 if($this->{ShowFileList}) { $this->SUPER::ShowPage($App, $pParams, $Path, $pPrevFunc, $pPostFunc, MultiFunctionTableJScript => $MultiFunctionTableJScript, pMultiFunctionTableConfig => \%MultiFunctionTableConfigByClass, ShowDirTreeLink => 0, pFilterFunc => sub { my ($this, $App, $pParams, $path) = @_; #$App->print("p[$path][$this->{ImageFilesRegExp}]\n"); # return 0 if($this->{ImageFilesRegExp} and $path =~ /$this->{ImageFilesRegExp}/i); return 1; }, ); $this->{DownloadAccountKey} = $DownloadAccountKey if($this->{DownloadAccountKey} eq ''); $this->ShowChangePasswordPage($App, $pParams); $this->ShowCreateHTAccessPage($App, $pParams, $Path); } &$pPostFunc($App, $pParams) if($pPrevFunc); } sub PrintFileFunc { my ($this, $App, $pParams, $path) = @_; my ($drive, $directory, $filename, $ext, $lastdir, $filebody) = Deps::SplitFilePath($path); my $link = $this->MakeFileLink($App, $pParams, $path, $filename); $App->PrintRawHTML(" \n"); $App->PrintRawHTML(" $link\n"); my $dir = "$drive$directory"; $dir =~ s/\\/\//g; $dir =~ s/\/$//; my $link = $this->MakeDirLink($App, $pParams, $dir, $dir); $App->PrintRawHTML(" $link\n"); $App->PrintRawHTML(" \n"); } sub ViewImage { my ($this, $App, $pParams) = @_; return if(!$this->IsOpen($App, $pParams, 0)); $this->{RootPath} = Template->new()->ReplaceByHash($this->{RootPath}, $pParams, '{', '}', 0, $pParams->{WebCharSet}, 0, 1, 0); my $path = Utils::MakePath($this->{RootPath}, Utils::DelQuote(Utils::URLDecode($pParams->{ImagePath})), '/', 0); # my $path = Utils::URLDecode($pParams->{ImagePath}); Jcode::convert(\$path, $pParams->{FileSystemCharCode}); $path = $this->URLSubstitution($App, $pParams, $path); $App->print("$path\n"); $App->PrintRawHTML("\n"); $App->HR(); $this->ShowPage($App, $pParams); } sub MakePhotoAlbum { my ($this, $App, $pParams) = @_; return if(!$this->IsOpen($App, $pParams, 0)); my $convert = $pParams->{convertPath}; $convert = "\"$convert\"" if($convert =~ / /); my $path = $pParams->{Path}; Jcode::convert(\$path, $pParams->{FileSystemCharCode}); my $AlbumFile = Utils::MakePath($path, "PhotoAlbum.pdf", '/', 0); unlink($AlbumFile); $App->print("Album: $AlbumFile\n") if($pParams->{MakeAlbumPDF}); my $ZIPFileName = "Photographs.zip"; my $ZIPFilePath = Utils::MakePath($path, $ZIPFileName, '/', 0); unlink($ZIPFilePath); $App->print("ZIP: $ZIPFilePath\n") if($pParams->{MakeAlbumZIP}); my $zip = Archive::Zip->new(); my $fmask = Utils::MakePath($path, "*", '/', 0); my @List; my @files = glob($fmask); foreach my $path (sort @files) { my ($drive, $directory, $fname, $ext, $lastdir, $filebody) = Deps::SplitFilePath($path); next if($fname =~ /^tiny-/i); next if($fname !~ /$this->{PictureMask}/i); #$App->print("p: $path\n"); @List = (@List, $path); if($pParams->{MakeAlbumZIP}) { $zip->addFile($path, $fname); } } if($pParams->{MakeAlbumZIP}) { if($zip->writeToFileNamed($ZIPFilePath) == AZ_OK) { $App->print("Photographs have been archived to [$ZIPFilePath].\n"); } else { $App->print("Photographs Archive file [$ZIPFilePath] could not been saved.\n"); } } if($pParams->{MakeAlbumPDF}) { for(my $i = 0 ; $i < @List ; $i++) { if($List[$i] =~ /\s/) { $List[$i] = "\"$List[$i]\""; } } my $cmd = "$convert -density 100 -quality 75 -page \"800x800\" -resize \"800x800\" " . join(' ', @List) . " $AlbumFile"; $App->print("Execute [$cmd]...\n"); system($cmd); if(-e $AlbumFile) { $App->print("Album file [$AlbumFile] has been created.\n"); } else { $App->print("Album file [$AlbumFile] could not been created.\n"); } } $App->HR(); $this->ShowPage($App, $pParams); } sub ShowMakeArchiveLinks { my ($this, $App, $pParams) = @_; # return if(!$this->IsOpen($App, $pParams, 0)); $this->{RootPath} = Template->new()->ReplaceByHash($this->{RootPath}, $pParams, '{', '}', 0, $pParams->{WebCharSet}, 0, 1, 0); $pParams->{Path} = $this->{RootPath} if(!defined $pParams->{Path}); my $Path = $pParams->{Path} = Utils::ReduceDirectory($pParams->{Path}); #ZIP/PDFファイル作成リンク #$App->print("p[$this->{PrivilegeMakePhotoAlbum}][$this->{MakeAlbumPDF}][$this->{MakeAlbumZIP}]\n"); if($App->HasPrivilege($this->{PrivilegeMakePhotoAlbum}, 0)) { my $Option = $App->BuildCGIOption( { PrevAction => $pParams->{Action}, }, [qw(+Path Key iRootDir)], ); if($this->{MakeAlbumPDF} and $this->{MakeAlbumZIP}) { $App->PrintRawHTML("

{ScriptPath}?Action=$this->{ModuleName}::MakePhotoAlbum&$Option\" target=\"_self\">" . $App->mlText('en' => 'Make PhotoAlbum', 'jp' => '写真集PDF/アーカイブZIPファイルを作る') . "

\n"); } elsif($this->{MakeAlbumPDF}) { $App->PrintRawHTML("

{ScriptPath}?Action=$this->{ModuleName}::MakePhotoAlbum&$Option\" target=\"_self\">" . $App->mlText('en' => 'Make PhotoAlbum', 'jp' => '写真集PDFファイルを作る') . "

\n"); } elsif($this->{MakeAlbumZIP}) { $App->PrintRawHTML("

{ScriptPath}?Action=$this->{ModuleName}::MakePhotoAlbum&$Option\" target=\"_self\">" . $App->mlText('en' => 'Make PhotoAlbum', 'jp' => '写真アーカイブZIPファイルを作る') . "

\n"); } } my $AlbumFile = Utils::MakePath($Path, "PhotoAlbum.pdf", '/', 0); #$App->print("Album: $AlbumFile\n"); if(-e $AlbumFile) { my $link = $this->MakeFileLink($App, $pParams, $AlbumFile, $App->mlText('en' => 'Album PDF File', 'jp' => "アルバムPDFファイル") ); $App->PrintRawHTML("

$link

\n"); } my $ZIPFileName = "Photographs.zip"; my $ZIPFilePath = Utils::MakePath($Path, $ZIPFileName, '/', 0); if(-e $ZIPFilePath) { my $WriteDateString = Utils::BuildDateString(Utils::GetWriteDate($ZIPFilePath)); my ($FileSize, $unit) = Utils::GetFileSize($ZIPFilePath, 'auto', "%4.1f"); my $link = $this->MakeFileLink($App, $pParams, $ZIPFilePath, $App->mlText('en' => 'Album ZIP File', 'jp' => "アーカイブZIPファイル") ); #$App->print("ZIP Path[$ZIPFilePath]\n"); #$App->print("link [$link]\n"); $App->PrintRawHTML("

$link $WriteDateString ($FileSize $unit)

\n"); } } sub IsThumbnailFile { my ($this, $fname) = @_; return 1 if($fname =~ /tiny-/i); return 1 if($fname =~ /small\.[a-z]+$/i); return 0; } sub ExecuteCommand { my ($this, $App, $pParams, $cmd, $UsePipe) = @_; if($^O eq 'MSWin32') { $cmd =~ s/\//\\/g; } if(!$UsePipe) { my $ret = system($cmd); #$App->print("ret=$ret\n"); if($ret >= 32) { $App->print("Error: Exec [$cmd] failed.\n"); return 0; } return 1; } else { if(open(IN, "$cmd |")) { while(1) { my $line = ; last if(!defined $line); Jcode::convert(\$line,'utf8', 'sjis'); $App->print("$line\n"); } close(IN); $App->print("Execute [$cmd \|] suceeded.\n"); return 1; } else { $App->print("Error: Open [$cmd \|] failed.\n"); return 0; } } return 1; } sub MakePDFFirstPageImage { my ($this, $App, $pParams, $Path, %args) = @_; return if(!$this->IsOpen($App, $pParams, 0)); my $IsPrint = 0; my $ChangeDir = 1; my $UsePipe = 0; my $Method = $pParams->{PDFtoImageMethod}; my $PDFtoPPMPATH = $pParams->{PDFtoPPMPATH}; #$App->print("PPM[$pParams->{PDFtoImageMethod}][$pParams->{PDFtoPPMPATH}]\n"); $this->{RootPath} = Template->new()->ReplaceByHash($this->{RootPath}, $pParams, '{', '}', 0, $pParams->{WebCharSet}, 0, 1, 0); $pParams->{Path} = $this->{RootPath} if(!defined $pParams->{Path}); $Path = $pParams->{Path} = Utils::ReduceDirectory($Path); my $RegExpPath = Utils::RegExpQuote($Path); my @files = ($args{pFiles})? @{$args{pFiles}} : $App->GetFileList($pParams, Utils::MakePath($pParams->{Path}, '*', '/', 0), 1); my $pwd = cwd(); if($ChangeDir) { if(chdir($pParams->{Path})) { $App->print("chdir from [$pwd] to [$pParams->{Path}] suceeded.\n") if($IsPrint); } else { $App->print("chdir from [$pwd] to [$pParams->{Path}] failed.\n") if($IsPrint); return; } } my ($IsPermitted, $BrowseDir, $FileRegExp, $DirRegExp, $ss, $st) = $this->IsPermitted($App, $pParams, $Path); if(!$IsPermitted) { $App->H2("Error: Browsing $Path is not permitted."); return; } if($^O eq 'MSWin32') { $ENV{PATH} = "$ghostscriptPath;$ENV{PATH}"; } my $OriginalFullPath; for my $f (@files) { if(-e $TempPDFName and !unlink($TempPDFName)) { $App->H3("Error in PictureGalleryObject::MakePDFFirstPageImage: Can not delete [$TempPDFName].\n"); return; } if(-e $TempCopyFile and !unlink($TempCopyFile)) { $App->H3("Error in PictureGalleryObject::MakePDFFirstPageImage: Can not delete [$TempCopyFile].\n"); return; } my ($IsPermitted, $pd, $bf, $bd, $ss, $st) = $this->IsPermitted($App, $pParams, $f); next if(!$IsPermitted); next if(-d $f); next if($f !~ /\.pdf$/i); my ($drive, $directory, $fname, $ext, $lastdir, $filebody) = Deps::SplitFilePath($f); next if(lc $fname eq lc $TempPDFName); #$App->print("f[$fname][$TempCopyFile]\n"); next if(lc $fname eq lc $TempCopyFile); ($drive, $directory, $fname, $ext, $lastdir, $filebody) = Deps::SplitFilePath($f); Jcode::convert(\$fname, $pParams->{FileSystemCharCode}); Jcode::convert(\$filebody, $pParams->{FileSystemCharCode}); my $JPEGFileName = "$filebody.jpg"; next if(-e $JPEGFileName and Utils::GetWriteDate($f) < Utils::GetWriteDate($JPEGFileName)); my $TempPDFName = ($ChangeDir)? $TempPDFName : Utils::MakePath("$drive$directory", $TempPDFName, '/', 0); if(-e $TempPDFName) { $App->H3("Error in PictureGalleryObject::MakePDFFirstPageImage: Temp file [$TempPDFName] exists.\n"); return; } if(!Utils::CopyFile($f, $TempCopyFile) or !-f $TempCopyFile) { $App->H3("Error in PictureGalleryObject::MakePDFFirstPageImage: Can not copy [$f] to [$TempCopyFile].\n"); next; } #$App->print("f[$f]\n"); my $path = ($ChangeDir)? $TempCopyFile : Utils::MakePath($pParams->{Path}, $TempCopyFile, '/', 0); $path = "\"$path\"" if($path =~ /\s/); my $cmd = "\"$pParams->{pdftkPath}\" A=$path cat A1 output $TempPDFName"; $App->print(" Extracting 1st PDF page for [$f] by [$cmd]\n"); if(!$this->ExecuteCommand($App, $pParams, $cmd, $UsePipe)) { unlink($TempPDFName); unlink($TempCopyFile); next; } next if(!-e $TempPDFName); $JPEGFileName = "\"$JPEGFileName\"" if($JPEGFileName =~ /\s/); if($Method eq 'pdftk') { $cmd = "\"$pParams->{convertPath}\" -density $ImageFileDensity $TempPDFName $JPEGFileName"; $App->print(" Converting to JPEG image for [$f] by [$cmd]\n"); if(!$this->ExecuteCommand($App, $pParams, $cmd, $UsePipe)) { unlink($TempPDFName); unlink($TempCopyFile); next; } } elsif($Method eq 'xpdf') { my $OutputImage = "$filebody"; $cmd = "\"$PDFtoPPMPATH\" $TempPDFName \"$OutputImage\""; $App->print(" Converting to PPM image for [$f] by [$cmd]\n"); if(!$this->ExecuteCommand($App, $pParams, $cmd, $UsePipe)) { unlink($TempPDFName); unlink($TempCopyFile); next; } $OutputImage = "$filebody-000001.ppm"; $cmd = "\"$pParams->{convertPath}\" -density $ImageFileDensity \"$OutputImage\" $JPEGFileName"; $App->print(" Converting PPM to JPEG image for [$f] by [$cmd]\n"); if(!$this->ExecuteCommand($App, $pParams, $cmd, $UsePipe)) { unlink($OutputImage); unlink($TempPDFName); unlink($TempCopyFile); next; } unlink($OutputImage); } unlink($TempPDFName); unlink($TempCopyFile); } } sub MakeThumbnail { my ($this, $App, $pParams, $Path, %args) = @_; return if(!$this->IsOpen($App, $pParams, 0)); my $IsPrint = 0; my $ChangeDir = 1; my $UsePipe = 0; $this->{RootPath} = Template->new()->ReplaceByHash($this->{RootPath}, $pParams, '{', '}', 0, $pParams->{WebCharSet}, 0, 1, 0); $pParams->{Path} = $this->{RootPath} if(!defined $pParams->{Path}); $Path = $pParams->{Path} = Utils::ReduceDirectory($Path); my $RegExpPath = Utils::RegExpQuote($Path); #$App->print("RegExpPath[$RegExpPath]\n"); my @files = ($args{pFiles})? @{$args{pFiles}} : $App->GetFileList($pParams, Utils::MakePath($pParams->{Path}, '*', '/', 0), 1); my $pwd = cwd(); if($ChangeDir) { if(chdir($pParams->{Path})) { $App->print("chdir from [$pwd] to [$pParams->{Path}] suceeded.\n") if($IsPrint); } else { $App->print("chdir from [$pwd] to [$pParams->{Path}] failed.\n") if($IsPrint); return; } } my ($IsPermitted, $BrowseDir, $FileRegExp, $DirRegExp, $ss, $st) = $this->IsPermitted($App, $pParams, $Path); if(!$IsPermitted) { $App->H2("Error: Browsing $Path is not permitted."); return; } my $OriginalFullPath; for my $f (@files) { my ($IsPermitted, $pd, $bf, $bd, $ss, $st) = $this->IsPermitted($App, $pParams, $f); next if(!$IsPermitted); next if(-d $f); next if($f =~ /\.(pdf|zip)$/i); my ($drive, $directory, $fname, $ext, $lastdir, $filebody) = Deps::SplitFilePath($f); next if($this->IsThumbnailFile($fname)); my $mdate = Utils::GetWriteDate($f); my $date = Utils::BuildDateString($mdate); $directory = "$drive$directory"; $directory =~ s/\\/\//g; my $OriginalPath = ($ChangeDir)? $fname : $f; my $ThumbnailFileName = "tiny-" . $fname; my $ThumbnailPath = ($ChangeDir)? $ThumbnailFileName : Utils::MakePath($directory, $ThumbnailFileName, '/', 0); #$App->print("TP[$ThumbnailFileName][$fname]\n"); if($fname =~ /$this->{PictureMask}/i and (!-e $ThumbnailPath or $mdate > Utils::GetWriteDate($ThumbnailPath)) ) { my $width = ($this->{PictureThumbnailWidth} > 0)? $this->{PictureThumbnailWidth} : $pParams->{PictureThumbnailWidth}; my $op = "\"$OriginalPath\""; my $tp = "\"$ThumbnailPath\""; my $cmd = "\"$pParams->{convertPath}\" -resize $width $op $tp"; #Jcode::convert(\$cmd, $pParams->{FileSystemCharCode}); if($^O eq 'MSWin32') { $cmd =~ s/\//\\/g; } $App->print(" Making thumbnail [$cmd]\n"); if(!$this->ExecuteCommand($App, $pParams, $cmd, $UsePipe)) { next; } } } if($ChangeDir) { if(chdir($pwd)) { $App->print("chdir to [$pwd] suceeded.\n") if($IsPrint); } else { $App->print("chdir to [$pwd] failed.\n") if($IsPrint); return; } } } sub ShowPictureList { my ($this, $App, $pParams, $Path, %args) = @_; return if(!$this->IsOpen($App, $pParams, 0)); my $IsPrint = 0; $this->{ShowPageTitle} = 1 if(!defined $this->{ShowPageTitle}); my $t = new Template; $this->{RootPath} = Template->new()->ReplaceByHash($this->{RootPath}, $pParams, '{', '}', 0, $pParams->{WebCharSet}, 0, 1, 0); # $this->{RootPath} = $pParams->{WebDocumentRoot} if($this->{RootPath} eq ''); # $this->{RootPath} = $pParams->{WebServerRoot} if($this->{RootPath} eq ''); $this->{RootPath} = Template->new()->ReplaceByHash($this->{RootPath}, $pParams, '{', '}', 0, $pParams->{WebCharSet}, 0, 1, 0); $Path = $pParams->{Path} = Utils::ReduceDirectory($pParams->{Path}); my $RegExpWebDocumentRootDir = Utils::RegExpQuote($pParams->{WebDocumentRoot}); my $RegExpRootDir = Utils::RegExpQuote($this->{RootPath}); my $RegExpPath = Utils::RegExpQuote($Path); my $ParentDirectory = $Path; $ParentDirectory =~ /^(.*)\/[^\/]+\/?$/; $ParentDirectory = $1; #$App->print("R[$this->{RootPath}][$RegExpWebDocumentRootDir]\n"); my $UseWebTree = ($this->{RootPath} =~ /^$RegExpWebDocumentRootDir/)? 1 : 0; my @files = ($args{pFiles})? @{$args{pFiles}} : $App->GetFileList($pParams, Utils::MakePath($pParams->{Path}, '*', '/', 0), 1); $App->H2("Pictures\n") if($this->{ShowPageTitle}); my $DivClass = $args{DivClass}; my $HrefClass = $args{HrefClass}; my $ImgClass = $args{ImgClass}; my $Script = $args{Script}; my $FirstStringInBody = ($args{FirstStringInBody})? $args{FirstStringInBody} : ''; $App->PrintRawHTML($FirstStringInBody); my ($IsPermitted, $BrowseDir, $FileRegExp, $DirRegExp, $ss, $st) = $this->IsPermitted($App, $pParams, $Path); if(!$IsPermitted) { $App->H2("Error: Browsing $Path is not permitted."); return; } #$App->print("m[$this->{PictureMask}]\n"); my $OriginalFullPath; $App->BeginTable(1, $this->{nColumns}) if($Script ne 'polaroid'); for my $f (@files) { next if($f !~ /$this->{ImageFilesRegExp}/i); my ($IsPermitted, $pd, $bf, $bd, $ss, $st) = $this->IsPermitted($App, $pParams, $f); next if(!$IsPermitted); next if(-d $f); my ($drive, $directory, $fname, $ext, $lastdir, $filebody) = Deps::SplitFilePath($f); next if($fname !~ /$this->{PictureMask}/i); next if($f =~ /\.(pdf|zip)$/i); my $OriginalPath = $f; ($drive, $directory, $fname, $ext, $lastdir, $filebody) = Deps::SplitFilePath($f); next if($this->IsThumbnailFile($fname)); my $mdate = Utils::GetWriteDate($f); my $date = Utils::BuildDateString($mdate); my $ThumbnailFileName = "tiny-" . $fname; my $ThumbnailPath = Deps::MakePath("$drive$directory", $ThumbnailFileName, 0); $ThumbnailPath =~ s/\\/\//g; if(!-e $ThumbnailPath) { $ThumbnailPath = $OriginalPath; } my $EncodedLocalPath; my $EncodedPath; my $LocalThumbnailPath; if((-f $f) and ($FileRegExp eq '' or $fname =~ /$FileRegExp/i) ) { $App->PrintRawHTML("
\n") if(defined $DivClass); $App->BeginTableItem() if($Script ne 'polaroid'); if($fname =~ /$this->{PictureMask}/i) { #$App->print("f: $OriginalPath [$this->{PictureMask}]\n"); my $LocalPath = $OriginalPath; #$LocalPath =~ s/$RegExpRootDir/$pParams->{PictureGalleryRootURL}/i; Jcode::convert(\$LocalPath, $pParams->{FileSystemCharCode}); # $LocalPath = $this->URLSubstitution($App, $pParams, $LocalPath); $LocalThumbnailPath = $ThumbnailPath; #$LocalThumbnailPath =~ s/$RegExpRootDir/$pParams->{PictureGalleryRootURL}/i; Jcode::convert(\$LocalThumbnailPath, $pParams->{FileSystemCharCode}); #$LocalThumbnailPath = $this->URLSubstitution($App, $pParams, $LocalThumbnailPath); $OriginalFullPath = $OriginalPath; $Path =~ s/^$RegExpWebDocumentRootDir\/?/\//; $LocalPath =~ s/^$RegExpWebDocumentRootDir\/?/\//; $OriginalPath =~ s/^$RegExpWebDocumentRootDir\/?/\//; $ThumbnailPath =~ s/^$RegExpWebDocumentRootDir\/?/\//; $LocalThumbnailPath =~ s/^$RegExpWebDocumentRootDir\/?/\//; $EncodedLocalPath = Utils::URLEncode($LocalPath); $EncodedPath = Utils::URLEncode($Path); my $width = ($this->{ThumbnailDisplayWidth} > 0)? $this->{ThumbnailDisplayWidth} : $pParams->{ThumbnailDisplayWidth}; my $ImageLink; #$App->print("LTP[$LocalThumbnailPath] LP[$LocalPath]\n"); if($UseWebTree) { my $ImageString = $App->MakeImageLinkString($pParams, $LocalThumbnailPath, 0, $width, class => $args{ImgClass}); $ImageLink = $App->MakeHRefLinkString ($pParams, $LocalPath, $ImageString, class => $args{HrefClass}, rel => $args{HrefGroup}); } else { #$App->print("f[$f]\n"); my ($f2, $label) = $App->MakeFileLinkURL($pParams, '', $f, '', undef, undef, $pParams->{WebCharCode}, $pParams->{FileSystemCharCode}); # my $f2 = $App->MakeFileLinkURL($pParams, $f, '', '', undef, undef, $pParams->{WebCharCode}, $pParams->{FileSystemCharCode}); #$App->print("f2[$f2]\n"); # my $ImageString = $App->MakeShowImageLink($pParams, $LocalThumbnailPath, '', $this->{ModuleName}, # border => 0, width => $width, class => $args{ImgClass}); # $ImageLink = $this->MakeShowImageLink($App, $pParams, $f2, $ImageString, class => $args{HrefClass}, rel => $args{HrefGroup}); my ($Option, $target) = $App->GetCGIParameters( { Action => "$this->{ModuleName}::ShowImage", Path => $LocalThumbnailPath, NoMenu => 1, OnlyLoadModules => $this->{ModuleName}, #'', #'ShowImage', }, [qw(DBConfigName EMail Password Action NoMenu OnlyLoadModules Path Key iRootDir)], "_blank", "_blank", 0); # [qw(+Action NoMenu OnlyLoadModules Path)], "_blank", "_blank", 0); my $ImageSrc = "$pParams->{ScriptPath}?$Option"; my $ImageString = $App->MakeImageLinkString($pParams, $ImageSrc, 0, $width, class => $args{ImgClass}); $ImageLink = $this->MakeShowImageLink($App, $pParams, $f, $ImageString, class => $args{HrefClass}, rel => $args{HrefGroup}); # $ImageLink = $this->MakeShowImageLink($App, $pParams, $f2, $ImageString, class => $args{HrefClass}, rel => $args{HrefGroup}); } # 画像によるリンク $App->PrintRawHTML("$ImageLink
\n"); } #next; # 文字列によるリンク my $f2 = $f; $f2 = Deps::ReplaceExtension($f2, '*'); my @files2; $files2[0] = $f; $files2[1] = Deps::ReplaceExtension($f, 'pdf'); #$App->print("f2-1[$files2[1]\n"); for(my $i = 0 ; $i < @files2 ; $i++) { my $f = $files2[$i]; $f =~ s/\\/\//g; #$App->print("f2a[$f]\n"); next if(!-e $f); my ($drive, $directory, $fname, $ext, $lastdir, $filebody) = Deps::SplitFilePath($f); $f =~ s/^$RegExpRootDir\///; #$this->URLSubstitution($App, $pParams, $f); #MakeFielLinkでEncodeしている # $f = Utils::URLEncode($f); $App->print("$date ") if($this->{ShowDate}); if($this->{ShowFileSize}) { my $unit = "Bytes"; my $path = Utils::MakePath($this->{RootPath}, $f, '/', 0); # my $size = Utils::GetFileSize($path); my ($size, $unit) = Utils::GetFileSize($path, 'auto', '%3.2f'); #$App->print("f[$f][$path][$size]\n"); # if($size > 10240) { # $size /= 1024; # $unit = "KB"; # } # if($size > 10240) { # $size /= 1024; # $unit = "MB"; # } # if($size > 10240) { # $size /= 1024; # $unit = "GB"; # } # $size = int($size); $App->PrintRawHTML("($size $unit)
"); } my $path = Utils::MakePath($this->{RootPath}, $f, '/', 0); my $link = $this->MakeFileLink($App, $pParams, $path, "$fname"); # my $link = $this->MakeFileLink($App, $pParams, $f, "$fname"); #$App->print("l:[$link]\n"); $App->PrintRawHTML(" $link
\n"); } $App->EndTableItem() if($Script ne 'polaroid'); $App->PrintRawHTML("
\n") if(defined $DivClass); } } $App->EndTable() if($Script ne 'polaroid'); } sub Download { my ($this, $App, $pParams, $Path) = @_; $this->BrowseFilesObject::Download2($App, $pParams, $Path); } sub MakeShowImageLink { my ($this, $App, $pParams, $path, $label, %args) = @_; $path =~ s/^file:\/\///i; Jcode::convert(\$path, $pParams->{FileSystemCharCode}); #$App->print("path: [$path]\n"); my $RegExpRootDir = Utils::RegExpQuote($pParams->{WebDocumentRootDir}); if($path =~ /^$RegExpRootDir/) { # if($path !~ /cgi-bin/i and $pParams->{WebDocumentRoot} ne '') { if($path =~ s/^$RegExpRootDir//i) { $path = "/$path" if($path !~ /^\//); Jcode::convert(\$label, $pParams->{FileSystemCharCode}); #$path = Utils::URLEncode($path, 1); #$App->print("p[$path]\n"); return "$label" } } $path = Utils::URLEncode($path); my $option = $App->BuildLinkOption(%args); my ($Option, $target) = $App->GetCGIParameters( { Action => "$this->{ModuleName}::ShowImageHTML", PrevAction => $pParams->{Action}, Path => $path, NoMenu => 1, OnlyLoadModules => $this->{ModuleName}, #'', #'ShowImage', # ShowParentDirectory => $this->{ShowParentDirectory}, # ShowDirectory => $this->{ShowDirectory}, # ShowDate => $this->{ShowDate}, # ShowFileSize => $this->{ShowFileSize}, }, [qw(DBConfigName EMail Password Action NoMenu OnlyLoadModules Path Key iRootDir)], # [qw(+Action NoMenu Path SubMenuFunction UserSN IsChildFrame FrameMode ShowParentDirectory ShowDirectory ShowDate ShowFileSize)], "_blank", "_blank", 0); my $link = "{ScriptPath}?$Option\" target=\"_blank\" $option>$label"; return $link; } sub ShowImageHTML { my ($this, $App, $pParams, $Path, $border, $width, %args) = @_; $Path = $pParams->{Path} if($Path eq ''); #$App->print("P[$Path][$this->{ModuleName}]\n"); $pParams->{NextAction} = "$this->{ModuleName}::ShowImage"; $pParams->{OnlyLoadModules} = $this->{ModuleName}; $App->ShowImageHTML($pParams, $Path, $border, $width, %args); } sub ShowImage { my ($this, $App, $pParams, $Path, $pDownloadDirsRegExp) = @_; # $App->SendNotificationForPrivilegedAccessMail($App, $pParams); # return if(!$this->IsOpen($App, $pParams, 0)); #$App->print("pPD[$this->{pPermittedDirs}]\n"); $pDownloadDirsRegExp = $this->{pPermittedDirs} if(!defined $pDownloadDirsRegExp); $Path = $pParams->{Path} if(!defined $Path and defined $pParams->{Path}); $Path = Utils::URLDecode($Path); $Path = Utils::DelQuote($Path); $Path =~ s/\\/\//g; Jcode::convert(\$Path, $pParams->{FileSystemCharCode}); if(!-e $Path) { $this->{RootPath} = Template->new()->ReplaceByHash($this->{RootPath}, $pParams, '{', '}', 0, $pParams->{WebCharSet}, 0, 1, 0); $Path = Utils::MakePath($this->{RootPath}, $Path, '/', 0); } $this->URLReverseSubstitution($App, $pParams, $Path); $App->ShowImage($pParams, $Path, $pDownloadDirsRegExp); } 1;