#============================================================ # EditTemplateObject #============================================================ package EditTemplateObject; use Common; @ISA = qw(Common); #公開したいサブルーチン #@EXPORT = qw(erfc tan); @EXPORT_OK = qw(); use strict; use CGI::TkWiki; use JSParams; use JFile; use Template; use MyMail; #========================================== # 大域変数 #========================================== my $ModuleName = "EditTemplate"; my $ModuleExplanation = "EditTemplate"; sub Name { return $ModuleName; } sub Explanation { return $ModuleExplanation; } #============================================================ # コンストラクタ、デストラクタ #============================================================ sub new { my ($module) = @_; my $this = {}; bless $this; # $this->SUPER::new(@_); $this->{TkWiki} = new CGI::TkWiki; # $this->{TkWiki}->SetWikiDir($WikiDir); $this->{TkWiki}->SetModuleName($ModuleName); # $TemplateDir = $pParams->{ORLPath}; # $WikiDir = $pParams->{ORLWikiDir}; # my $HTMLTemplatePath = Utils::MakePath($TemplateDir, "html.Template", '/', 0); # my $WikiTemplatePath = Utils::MakePath($TemplateDir, "wiki.Template", '/', 0); # $this->{TkWiki}->SetTemplatePaths($HTMLTemplatePath, $WikiTemplatePath); return $this; } sub DESTROY { my $this = shift; $this->SUPER::DESTROY(@_); } #============================================================ # メンバー関数 #============================================================ sub GetParameterHash { my ($this, $App, $pParams) = @_; $pParams->{TemplatePath} = $pParams->{ORLPath} if(!defined $pParams->{TemplatePath}); return {}; } sub IsOpen { my ($this, $App, $pParams, $IsPrint) = @_; #return 0; return $App->HasPrivilege("EditTemplate", $IsPrint); } sub ShowMenu { my ($this, $App, $pParams, $ProgramPath, $BaseOption) = @_; return 0; return 0 if(defined $App->{pAdminOption}); return 0 if(!$this->IsOpen($App, $pParams, 0)); my $Option = $App->BuildCGIOption( { Action => "${ModuleName}::ShowFilesPage", PrevAction => $pParams->{Action}, }, [qw(+Action)], ); $App->PrintRawHTML("{ScriptPath}?$Option\" target=\"_self\">" . $App->mlText('en' => 'Edit Templates', 'jp' => 'テンプレートの編集') . " "); } sub UpdatePage { my ($this, $App, $pParams) = @_; return if(!$this->IsOpen($App, $pParams)); $this->{TkWiki}->SetWikiDir($pParams->{TemplatePath}); $this->{TkWiki}->UpdatePage($App, $pParams); $App->HR(); $this->EditPage($App, $pParams); } sub EditPage { my ($this, $App, $pParams) = @_; return if(!$this->IsOpen($App, $pParams)); $this->{TkWiki}->SetWikiDir($pParams->{TemplatePath}); $this->{TkWiki}->SetTemplatePaths($pParams->{HTMLTemplatePath}, $pParams->{WikiTemplatePath}); $this->{TkWiki}->EditPage($App, $pParams); $App->HR(); $this->ShowFilesPage($App, $pParams); } sub ViewPage { my ($this, $App, $pParams) = @_; return if(!$this->IsOpen($App, $pParams)); $App->print("Templates in [$pParams->{TemplatePath}]\n"); $this->{TkWiki}->SetWikiDir($pParams->{TemplatePath}); return $this->{TkWiki}->ViewPage($App, $pParams); } sub CreatePage { my ($this, $App, $pParams) = @_; return if(!$this->IsOpen($App, $pParams)); $this->{TkWiki}->SetWikiDir($pParams->{TemplatePath}); $this->{TkWiki}->CreatePage($App, $pParams); $this->EditPage($App, $pParams); } sub ShowPage { my ($this, $App, $pParams) = @_; if($App->{pAdminOption}) { $App->{pAdminOption}->ShowSubMenu($App, $pParams); } $this->ViewPage($App, $pParams); } sub ShowFilesPage { my ($this, $App, $pParams) = @_; return if(!$this->IsOpen($App, $pParams)); #$App->print("Templates in [$pParams->{TemplatePath}]\n"); $this->{TkWiki}->SetWikiDir($pParams->{TemplatePath}); return $this->{TkWiki}->ShowFilesPage($App, $pParams); } sub UpdateFile { my ($this, $App, $pParams, $Privilege, $IsPrint) = @_; $App->SendNotificationForPrivilegedAccessMail($App, $pParams); $Privilege = $pParams->{EditTemplatePrivilege} if($Privilege eq ''); $Privilege = 'EditTemplate' if($Privilege eq ''); $IsPrint = 1 if(!defined $IsPrint); if(!$App->HasPrivilege($Privilege, 1)) { $App->HR(); $pParams->{Action} = $pParams->{NextAction}; $App->Execute($App, $pParams); return; } my $path = Utils::URLDecode($pParams->{Path}); #Utils::MakePath(); my ($drive, $directory, $filename, $ext1, $lastdir, $filebody) = Deps::SplitFilePath($path); my $s = Utils::BuildDateString(time(), undef, '{year}{monthZero}{dayZero}{hourZero}{minZero}'); my $BackupPath = Utils::MakePath("$drive$directory", "$s$filename", '/', 0); $App->H3("Backup to [$BackupPath]\n"); $App->H3("Save to [$path]\n"); #$App->print("$pParams->{FileContent}\n"); if(Utils::MoveFile($path, $BackupPath) < 1) { $App->H2("Error in ${ModuleName}::UpdateFile: Can not move [$path] to [$BackupPath]\n"); $App->HR(); $pParams->{Action} = $pParams->{PrevAction}; $App->Execute($App, $pParams); } my $out = new JFile; if($out->Open($path, 'wb')) { my $IsHTML = ($path =~ /\.html?$/i)? 1 : 0; if($IsHTML) { $out->print("\n"); $out->print("
\n"); } $out->print($pParams->{FileContent}); if($IsHTML) { $out->print("\n"); $out->print("\n"); $out->print("\n"); } $out->Close(); } else { $App->H2("Error in ${ModuleName}::UpdateFile: Can not write to [$path]\n"); $App->H2(" Try to get backup back...\n"); if(Utils::MoveFile($BackupPath, $path) < 1) { $App->H2("Error in ${ModuleName}::UpdateFile: Can not move [$BackupPath] back to [$path]\n"); } } $App->HR(); $pParams->{Action} = $pParams->{PrevAction}; $App->Execute($App, $pParams); } sub EditFile { my ($this, $App, $pParams, $Privilege, $IsPrint) = @_; $App->SendNotificationForPrivilegedAccessMail($App, $pParams); $Privilege = $pParams->{EditTemplatePrivilege} if($Privilege eq ''); $Privilege = 'EditTemplate' if($Privilege eq ''); $IsPrint = 1 if(!defined $IsPrint); $pParams->{EditTemplateTextAreaWidth} = 80 if($pParams->{EditTemplateTextAreaWidth} eq ''); $pParams->{EditTemplateTextAreaHeight} = 30 if($pParams->{EditTemplateTextAreaHeight} eq ''); if(!$App->HasPrivilege($Privilege, 1)) { $App->HR(); $pParams->{Action} = $pParams->{NextAction}; $App->Execute($App, $pParams); return; } my $path = Utils::URLDecode($pParams->{Path}); #Utils::MakePath(); $App->H3("Edit [$path]\n"); my $content = JFile->new()->ReadFile($path); if(!defined $content) { $App->H2("Error in ${ModuleName}::EditFile: Can not read [$path]\n"); $App->HR(); $pParams->{Action} = $pParams->{PrevAction}; $App->Execute($App, $pParams); return; } my $JS = new JSParams; my $Debug = 0; if($path !~ /\.html?$/i) { $App->print("not html\n") if($Debug); my $s = $JS->GetJSResizableString('.TextAreaText'); $App->PrintRawHTML("$s\n"); } elsif($content =~ /\