rfe #12093: Remotely stored photos for Story assets

This commit is contained in:
Paul Driver 2011-04-05 15:14:57 -05:00
parent e3ec56c3c1
commit f8021c3d3d
7 changed files with 92 additions and 28 deletions

View file

@ -467,6 +467,10 @@ sub getEditForm {
imgThumb => $filename ? $storage->getThumbnailUrl($filename) : '',
imgUrl => $filename ? $storage->getUrl($filename) : '',
imgFilename => $filename ? $filename : '',
imgRemoteUrlForm => WebGUI::Form::text($session, {
name => 'imgRemoteUrl'.$photoIndex,
value => $photo->{remoteUrl},
}),
newUploadForm => WebGUI::Form::file($session, {
name => 'newPhoto' . $photoIndex,
maxAttachments => 1,
@ -498,6 +502,9 @@ sub getEditForm {
};
}
push @{ $var->{ photo_form_loop } }, {
imgRemoteUrlForm => WebGUI::Form::text($session, {
name => 'imgRemoteUrl',
}),
newUploadForm => WebGUI::Form::image($session, {
name => 'newPhoto',
maxAttachments => 1,
@ -635,16 +642,20 @@ sub processPropertiesFromFormPost {
PHOTO: foreach my $photoIndex (1..$numberOfPhotos) {
##TODO: Deletion check and storage cleanup
my $storageId = $photoData->[$photoIndex-1]->{storageId};
my $storage = $storageId && WebGUI::Storage->get($session, $storageId);
my $remote = $form->process("imgRemoteUrl$photoIndex");
if ($form->process('deletePhoto'.$photoIndex, 'yesNo')) {
my $storage = WebGUI::Storage->get($session, $storageId);
$storage->delete if $storage;
splice @{ $photoData }, $photoIndex-1, 1;
next PHOTO;
}
##Process photos with urls that replace existing photos
if ($remote) {
$storage->delete() if $storage;
}
##Process uploads that replace existing photos
if (my $uploadId = $form->process('newPhoto'.$photoIndex,'File')) {
elsif (my $uploadId = $form->process('newPhoto'.$photoIndex,'File')) {
my $upload = WebGUI::Storage->get($session, $uploadId);
my $storage = WebGUI::Storage->get($session, $storageId);
$storage->clear;
my $filename = $upload->getFiles->[0];
$storage->addFileFromFilesystem($upload->getPath($filename));
@ -655,31 +666,43 @@ sub processPropertiesFromFormPost {
$upload->delete;
}
my $newPhoto = {
storageId => $storageId,
caption => $form->process('imgCaption'.$photoIndex, 'text'),
alt => $form->process('imgAlt' .$photoIndex, 'text'),
title => $form->process('imgTitle' .$photoIndex, 'text'),
byLine => $form->process('imgByline' .$photoIndex, 'text'),
url => $form->process('imgUrl' .$photoIndex, 'url' ),
};
if ($remote) {
$newPhoto->{remoteUrl} = $remote;
}
else {
$newPhoto->{storageId} = $storageId;
}
splice @{ $photoData }, $photoIndex-1, 1, $newPhoto;
}
my $newStorageId = $form->process('newPhoto', 'image');
if ($newStorageId) {
my $newStorage = WebGUI::Storage->get($session, $newStorageId);
my $photoName = $newStorage->getFiles->[0];
my ($width, $height) = $newStorage->getSizeInPixels($photoName);
if ($width > $self->getArchive->get('photoWidth')) {
$newStorage->resize($photoName, $self->getArchive->get('photoWidth'));
}
push @{ $photoData }, {
my $newRemote = $form->process('imgRemoteUrl');
if ($newStorageId || $newRemote) {
my $newPhoto = {
caption => $form->process('newImgCaption', 'text'),
alt => $form->process('newImgAlt', 'text'),
title => $form->process('newImgTitle', 'text'),
byLine => $form->process('newImgByline', 'text'),
url => $form->process('newImgUrl', 'url'),
storageId => $newStorageId,
};
if ($newRemote) {
$newPhoto->{remoteUrl} = $newRemote;
}
else {
my $newStorage = WebGUI::Storage->get($session, $newStorageId);
my $photoName = $newStorage->getFiles->[0];
my ($width, $height) = $newStorage->getSizeInPixels($photoName);
if ($width > $self->getArchive->get('photoWidth')) {
$newStorage->resize($photoName, $self->getArchive->get('photoWidth'));
}
$newPhoto->{storageId} = $newStorageId;
}
push @{ $photoData }, $newPhoto;
}
$self->setPhotoData($photoData);
$self->{_parent} = $archive; ##Restore archive, for URL and other calculations
@ -721,8 +744,9 @@ Remove the storage locations for this revision of the Asset.
sub purgeRevision {
my $self = shift;
my $session = $self->session;
foreach my $photo ( @{ $self->getPhotoData} ) {
my $storage = WebGUI::Storage->get($session, $self-$photo->{storageId});
PHOTO: foreach my $photo ( @{ $self->getPhotoData} ) {
my $id = $photo->{storageId} or next PHOTO;
my $storage = WebGUI::Storage->get($session, $id);
$storage->delete if $storage;
}
return $self->next::method;
@ -934,11 +958,19 @@ sub viewTemplateVariables {
$var->{photo_loop} = [];
my $photoCounter = 0;
PHOTO: foreach my $photo (@{ $photoData }) {
next PHOTO unless $photo->{storageId};
my $storage = WebGUI::Storage->get($session, $photo->{storageId});
my $file = $storage->getFiles->[0];
next PHOTO unless $file;
my $imageUrl = $storage->getUrl($file);
my $imageUrl;
if (my $remote = $photo->{remoteUrl}) {
$imageUrl = $remote;
}
elsif (my $id = $photo->{storageId}) {
my $storage = WebGUI::Storage->get($session, $photo->{storageId});
my $file = $storage->getFiles->[0];
next PHOTO unless $file;
$imageUrl = $storage->getUrl($file);
}
else {
next PHOTO;
}
push @{ $var->{photo_loop} }, {
imageUrl => $imageUrl,
imageCaption => $photo->{caption},