added export and rich edit page tree picker, and started on image picker

This commit is contained in:
JT Smith 2005-01-10 03:52:08 +00:00
parent a096a753ba
commit 28b6653e2a
7 changed files with 254 additions and 14 deletions

View file

@ -23,6 +23,7 @@ use WebGUI::ErrorHandler;
use WebGUI::Form;
use WebGUI::FormProcessor;
use WebGUI::Grouping;
use WebGUI::HTMLForm;
use WebGUI::HTTP;
use WebGUI::Icon;
use WebGUI::Id;
@ -251,6 +252,29 @@ sub cascadeLineage {
where lineage like ".quote($oldLineage.'%'));
}
#-------------------------------------------------------------------
sub checkExportPath {
my $error;
if(defined $session{config}{exportPath}) {
if(-d $session{config}{exportPath}) {
unless (-w $session{config}{exportPath}) {
$error .= 'Error: The export path '.$session{config}{exportPath}.' is not writable.<br>
Make sure that the webserver has permissions to write to that directory';
}
} else {
$error .= 'Error: The export path '.$session{config}{exportPath}.' does not exists.';
}
} else {
$error.= 'Error: The export path is not configured. Please set the exportPath variable in the WebGUI config file';
}
$error = '<p><b>'.$error.'</b></p>' if $error;
return $error;
}
#-------------------------------------------------------------------
=head2 cut ( )
@ -451,6 +475,91 @@ sub duplicateTree {
return $newAsset;
}
#-------------------------------------------------------------------
=head2 exportAsHtml ( hashref )
Executes the export and returns html content.
=head3 hashref
A hashref containing one of the following properties:
=head4 extrasUrl
The URL where the page will be able to find the WebGUI extras folder. Defaults to the extrasURL in the config file.
=head4 stripHtml
A boolean indicating whether the resulting output should be stripped of HTML tags.
=head4 uploadsUrl
The URL where the page will be able to find the files uploaded to WebGUI. Defaults to the uploadsURL in the config file.
=head4 userId
The unique id of the user to become when exporting this page. Defaults to '1' (Visitor).
=cut
sub exportAsHtml {
my $self = shift;
my $params = shift;
my $uploadsUrl = $params->{uploadsUrl} || $session{config}{uploadsUrl};
my $extrasUrl = $params->{extrasUrl} || $session{config}{extrasUrl};
my $userId = $params->{userId} || 1;
my $stripHtml = $params->{stripHtml} || undef;
# Save current session information because we need to restore current session after the export has finished.
my %oldSession = %session;
# Change the stuff we need to change to do the export
WebGUI::Session::refreshUserInfo($userId) unless ($userId == $session{user}{userId});
delete $session{form};
$session{var}{adminOn} = $self->get('adminOn');
WebGUI::Session::refreshPageInfo($self->get('pageId'));
$self->{_properties}{cacheTimeout} = $self->{_properties}{cacheTimeoutVisitor} = 1;
$session{config}{uploadsURL} = $uploadsUrl;
$session{config}{extrasURL} = $extrasUrl;
# Generate the page
my $content = $self->www_view;
if($stripHtml) {
$content = WebGUI::HTML::html2text($content);
}
# Restore session
%session = %oldSession;
delete $session{page}{noHttpHeader};
return $content;
}
#-------------------------------------------------------------------
=head2 new ( [ options ] )
Constructor.
Options can be set when a new Export object is constructed, or
afterwards with the set method. None of the options is required.
=head3 pageId
Sets the page to be generated. Defaults to current page.
=head3 styleId
Use this to override the default styleId.
Defaults to the page styleId.
=head3 userId
Runs the export as this user. Defaults to 1 (Visitor).
#-------------------------------------------------------------------
=head2 fixUrl ( string )
@ -2496,6 +2605,144 @@ sub www_emptyTrash {
return $self->www_manageTrash();
}
#-------------------------------------------------------------------
=head2 www_export
Displays the export page administrative interface
=cut
sub www_export {
my $self = shift;
return $self->getAdminConsole->render(WebGUI::Privilege::insufficient()) unless (WebGUI::Grouping::isInGroup(13));
$self->getAdminConsole->setHelp("page export");
my $f = WebGUI::HTMLForm->new(-action=>$self->getUrl);
$f->hidden("func","exportStatus");
$f->integer(
-label=>WebGUI::International::get('Depth'),
-name=>"depth",
-value=>99,
);
$f->selectList(
-label=>WebGUI::International::get('Export as user'),
-name=>"userId",
-options=>WebGUI::SQL->buildHashRef("select userId, username from users"),
-value=>[1],
);
$f->text(
-label=>"Directory Index",
-name=>"index",
-value=>"index.html"
);
$f->text(
-label=>WebGUI::International::get('Extras URL'),
-name=>"extrasURL",
-value=>$session{config}{extrasURL}
);
$f->text(
-label=>WebGUI::International::get('Uploads URL'),
-name=>"uploadsURL",
-value=>$session{config}{uploadsURL}
);
$f->submit;
$self->getAdminConsole->render($self->checkExportPath.$f->print,WebGUI::International::get('Export Page'));
}
#-------------------------------------------------------------------
=head2 www_exportStatus
Displays the export status page
=cut
sub www_exportStatus {
my $self = shift;
return $self->getAdminConsole->render(WebGUI::Privilege::insufficient()) unless (WebGUI::Grouping::isInGroup(13));
my $iframeUrl = $self->getUrl('func=exportGenerate');
$iframeUrl = WebGUI::URL::append($iframeUrl, 'index='.$session{form}{index});
$iframeUrl = WebGUI::URL::append($iframeUrl, 'depth='.$session{form}{depth});
$iframeUrl = WebGUI::URL::append($iframeUrl, 'userId='.$session{form}{userId});
$iframeUrl = WebGUI::URL::append($iframeUrl, 'extrasURL='.$session{form}{extrasURL});
$iframeUrl = WebGUI::URL::append($iframeUrl, 'uploadsURL='.$session{form}{uploadsURL});
my $output = '<IFRAME SRC="'.$iframeUrl.'" TITLE="'.WebGUI::International::get('Page Export Status').'" WIDTH="410" HEIGHT="200"></IFRAME>';
$self->getAdminConsole->render($output,WebGUI::International::get('Page Export Status'));
}
#-------------------------------------------------------------------
=head2 www_exportPageGenerate
Executes the export process and displays real time status. This operation is displayed by exportPageStatus in an IFRAME.
=cut
sub www_exportGenerate {
my $self = shift;
return $self->getAdminConsole->render(WebGUI::Privilege::insufficient()) unless (WebGUI::Grouping::isInGroup(13));
# This routine is called in an IFRAME and prints status output directly to the browser.
$|++; # Unbuffered data output
$session{page}{empty} = 1; # Write directly to the browser
print WebGUI::HTTP::getHeader();
my $startTime = time();
my $error = $self->checkExportPath();
if ($error) {
print $error;
return;
}
my $userId = $session{form}{userId};
my $extrasURL = $session{form}{extrasURL};
my $uploadsURL = $session{form}{uploadsURL};
my $index = $session{form}{index};
my $assets = $self->getLineage(["self","descendants"],{returnObjects=>1,endingLineageLength=>$self->getLineageLength+$session{form}{depth}});
foreach my $asset (@{$assets}) {
my $url = $asset->get("url");
print "Exporting page ".$url."......";
unless ($asset->canView($userId)) {
print "User has no privileges to view.<br />\n";
next;
}
my $path;
my $filename;
if ($url =~ /\./) {
$url =~ /^(.*)\/(.*)$/;
$path = $1;
$filename = $2;
if ($filename eq "") {
$filename = $path;
$path = undef;
}
} else {
$path = $url;
$filename = $index;
}
if($path) {
$path = $session{config}{exportPath} . $session{os}{slash} . $path;
eval { mkpath($path) };
if($@) {
print "Couldn't create $path because $@ <br />\n";
print "This most likely means that you have a page with the same name as folder that you're trying to create.<br />\n";
return;
}
}
$path .= $session{os}{slash}.$filename;
eval { open(FILE, "> $path") or die "$!" };
if ($@) {
print "Couldn't open $path because $@ <br />\n";
return;
} else {
print FILE $self->exportAsHtml({userId=>$userId,extrasUrl=>$extrasURL,uploadsUrl=>$uploadsURL});
close(FILE);
}
print "DONE<br />";
}
print "<p>Exported ".scalar(@{$assets})." pages in ".(time()-$startTime)." seconds.</p>";
print '<a target="_parent" href="'.$self->getUrl.'">'.WebGUI::International::get(493).'</a>';
return;
}
#-------------------------------------------------------------------
@ -2678,6 +2925,7 @@ sub www_promote {
return "";
}
#-------------------------------------------------------------------
=head2 www_setParent ( )

View file

@ -95,6 +95,8 @@ sub getOperations {
'editDatabaseLink' => 'WebGUI::Operation::DatabaseLink',
'editDatabaseLinkSave' => 'WebGUI::Operation::DatabaseLink',
'listDatabaseLinks' => 'WebGUI::Operation::DatabaseLink',
'richEditPageTree' => 'WebGUI::Operation::RichEdit',
'richEditImage' => 'WebGUI::Operation::RichEdit',
'manageUsersInGroup' => 'WebGUI::Operation::Group',
'deleteGroup' => 'WebGUI::Operation::Group',
'deleteGroupConfirm' => 'WebGUI::Operation::Group',

View file

@ -5979,11 +5979,6 @@ A randomly generated number. This is often used on images (such as banner ads) t
lastUpdated => 1089039511,
context => q|Field label for the Export Page operation|
},
'Alternate style' => {
message => q|Alternate style|,
lastUpdated => 1089039511,
context => q|Field label for the Export Page operation|
},
'Page Export Status' => {
message => q|Page Export Status|,
lastUpdated => 1089039511,