[# tag: ewok publish targets administration page #]
[!
use File::Path qw(mkpath);
use URI;
use Ewok::Util qw(loadSiteMap saveSiteMap);
use Ewok::Config qw($EWOK_HOME);
!][-
Execute({ inputfile => 'util.epl', import => 1 });
$req = shift;
$site = $fdat{site};
$step = lc($fdat{step});
$op = lc($fdat{op});
$op =~ s/ .*//;
$smap = loadSiteMap();
@errors = ();
-]
[# New #]
[$ if ($op eq 'new') $]
[$ if ($step eq 'create') $]
[-
$label = $fdat{label};
$dest_url = $fdat{dest_url};
$dest_fs_dir = $fdat{dest_fs_dir};
$dest_web_dir = $fdat{dest_web_dir};
$template = $fdat{template};
$default = $fdat{default} =~ m/^y/i ? 1 : 0;
push @errors, "Invalid label '$label'" if $label !~ m/^\w+$/;
push @errors, "Publish target '$label' already exists"
if ref $smap->{$site}->{publish} eq 'HASH' &&
exists $smap->{$site}->{publish}->{$label};
if ($dest_url) {
unless ($dest_url =~ m!^https?://\w!i) {
push @errors, "Invalid Publish URL - not an HTTP based URL";
}
}
else {
push @errors, "Publish URL is a required field";
}
if ($dest_fs_dir) {
push @errors, "Invalid publish directory '$dest_fs_dir' - must be a local absolute path" if $dest_fs_dir !~ m!^/!;
}
else {
push @errors, "Local Publish Directory is a required field";
}
if ($dest_web_dir) {
push @errors, "Invalid publish alias '$dest_web_dir' - must be an absolute path"
if $dest_web_dir !~ m!^/!;
}
-]
[$ if (! @errors) $]
[# Add entry to site map #]
[-
$entry = {
dest_url => $dest_url,
dest_fs_dir => $dest_fs_dir,
};
$entry->{dest_web_dir} = $dest_web_dir if $dest_web_dir;
$entry->{template} = $template if $template;
# Add new publish target to $site site map 'publish' section
$smap->{$site}->{publish} = {} unless ref $smap->{$site}->{publish} eq 'HASH';
$smap->{$site}->{publish}->{$label} = $entry;
$smap->{$site}->{default_target} = $label if $default;
$saved = saveSiteMap($smap);
errors "Save of site map failed!" unless $saved;
-]
[$ if ($saved) $]
New ewok publish target '[+ $label +]' created. You will need to restart Apache for it to pick up the new target.
Back to [+ $site +] publishing targets
Back to ewok administration page
[$ endif $][# $saved #]
[$ endif $][# ! @errors #]
[$ endif $][# $step eq 'create' #]
[$ if ($step eq 'next' || ($step eq 'create' && @errors)) $]
[$ if ($step eq 'next') $]
[-
$label = $fdat{label};
push @errors, "Invalid label '$label'" if $label !~ m/^\w+$/;
push @errors, "Site '$label' already exists"
if ref $smap->{$site}->{publish} eq 'HASH' &&
exists $smap->{$site}->{publish}->{$label};
-]
[$ endif $]
[$ if (! @errors || $step eq 'create') $]
New publishing target for '[+ $site +]' site
[-
$dest_fs_dir ||= "$EWOK_HOME/publish/" . lc($label);
$dest_web_dir ||= "/publ/" . lc($label);
errors \@errors, { h1 => '' };
-]
[$ endif $][# ! @errors #]
[$ endif $][# $step eq 'next' #]
[$ if (! $step || ($step eq 'next' && @errors)) $]
New publishing target for '[+ $site +]' site
[- errors \@errors, { h1 => '' } -]
[$ endif $]
[# Edit #]
[$ elsif ($op eq 'edit') $]
Edit not implemented yet.
[# Delete #]
[$ elsif ($op eq 'delete') $]
[-
$label = $fdat{label};
push @errors, "Invalid site '$site'" if $site eq 'ewok';
push @errors, "Invalid site '$site'"
unless ref $smap->{$site} eq 'HASH' &&
ref $smap->{$site}->{publish} eq 'HASH';
push @errors, "Invalid publishing target '$label'"
unless ref $smap->{$site}->{publish}->{$label} eq 'HASH';
-]
[$ if (@errors) $]
[- errors \@errors -]
[$ elsif ($step eq 'confirm') $]
[-
delete $smap->{$site}->{publish}->{$label};
delete $smap->{$site}->{default_target}
if $smap->{$site}->{default_target} eq $label;
$saved = saveSiteMap($smap);
errors "Save of site map failed!" unless $saved;
-]
[$ if ($saved) $]
'[+ $label +]' publishing target deleted for '[+ $site +]' site. You will need to restart Apache to have it pick up your changes.
Back to [+ $site +] publishing targets
Back to ewok administration page
Back to ewok file manager
[$ else $]
[- errors \@errors, { h1 => '' } -]
[$ endif $][# $saved #]
[$ elsif ($step eq 'cancel') $]
[- $http_headers_out{Location} = "publish.html?site=$site" -]
[$ else $]
Delete '[+ $label +]' publishing target for '[+ $site +]' site
[$ endif $][# @errors/$confirm #]
[$ else $][# $op ne 'new' / 'delete' #]
[-
push @errors, "Invalid '$site' site"
unless $smap->{$site} && ref $smap->{$site} eq 'HASH' &&
$site ne 'ewok';
push @errors, "No publishing targets found for '$site' site"
unless ref $smap->{$site}->{publish} eq 'HASH' &&
keys %{$smap->{$site}->{publish}};
-]
[$ if (@errors) $]
[- errors \@errors -]
[$ else $]
[-
$stripe = 1;
$pub = $smap->{$site}->{publish};
-]
Publishing targets for '[+ $site +]' site
Label | Publish URL | Local Publish Directory | Local Publish Alias | Template | Default | Edit | Delete |
[$ foreach $label (sort keys %$pub) $]
[+ $label +] |
[+ $pub->{$label}->{dest_url} +] |
[+ $pub->{$label}->{dest_fs_dir} +] |
[+ $pub->{$label}->{dest_web_dir} +] |
[+ $pub->{$label}->{template} +] |
[+ $smap->{$site}->{default_target} eq $label ? 'Yes' : '' +] |
edit |
delete |
[- $stripe = $stripe % 2 + 1 -]
[$ endforeach $]
Back to ewok administration page
[$ endif $][# @errors #]
[$ endif $][# $op new/delete #]