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

@ -1,5 +1,6 @@
7.10.14 7.10.14
- fixed #12094: Cannot enter in Macros in URLs inside TinyMCE. - fixed #12094: Cannot enter in Macros in URLs inside TinyMCE.
- rfe #12093: Remotely stored photos for Story assets
7.10.13 7.10.13
- added #12079: Carousel Auto Play - added #12079: Carousel Auto Play

View file

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

View file

@ -37,6 +37,7 @@ our $HELP = {
{ name => 'imgUrl', }, { name => 'imgUrl', },
{ name => 'imgFilename', }, { name => 'imgFilename', },
{ name => 'newUploadForm', }, { name => 'newUploadForm', },
{ name => 'imgRemoteUrlForm', },
{ name => 'imgCaptionForm', }, { name => 'imgCaptionForm', },
{ name => 'imgBylineForm', }, { name => 'imgBylineForm', },
{ name => 'imgAltForm', }, { name => 'imgAltForm', },

View file

@ -292,6 +292,12 @@ our $I18N = {
lastUpdated => 0, lastUpdated => 0,
}, },
'imgRemoteUrlForm' => {
message => q|A form field to specify a remote url for a photo.|,
context => q|Template variable for edit form.|,
lastUpdated => 0,
},
'newUploadForm' => { 'newUploadForm' => {
message => q|A form field to upload an image.|, message => q|A form field to upload an image.|,
context => q|Template variable for edit form.|, context => q|Template variable for edit form.|,
@ -334,6 +340,13 @@ our $I18N = {
lastUpdated => 0, lastUpdated => 0,
}, },
'photo remote url' => {
message => 'Photo Remote URL',
context => 'Label in the edit story form. Location of image (instead
of uploaded location)',
lastUpdated => 0,
},
'photo caption' => { 'photo caption' => {
message => q|Photo Caption|, message => q|Photo Caption|,
context => q|Label in the edit story form. Short for Photograph Caption.|, context => q|Label in the edit story form. Short for Photograph Caption.|,

View file

@ -290,6 +290,11 @@ our $I18N = {
lastUpdated => 1065356764 lastUpdated => 1065356764
}, },
'or' => {
message => q|or|,
lastUpdated => 1053804577,
},
'978' => { '978' => {
message => q|User added successfully.|, message => q|User added successfully.|,
lastUpdated => 1053804577 lastUpdated => 1053804577

View file

@ -332,6 +332,14 @@ $story->setPhotoData([
title => '', title => '',
url => 'http://www.lamp.com', url => 'http://www.lamp.com',
}, },
{
remoteUrl => 'http://www.plainblack.com/rockstar.jpg',
caption => 'Elvis',
byLine => 'The King',
alt => '(impersonator)',
title => 'Rockstar Support',
url => 'http://plainblack.com/services/support/rockstar-support',
},
]); ]);
@ -362,6 +370,15 @@ cmp_bag(
is ($viewVariables->{updatedTimeEpoch}, $story->get('revisionDate'), 'viewTemplateVariables: updatedTimeEpoch'); is ($viewVariables->{updatedTimeEpoch}, $story->get('revisionDate'), 'viewTemplateVariables: updatedTimeEpoch');
my $rockstarVar = {
imageUrl => 'http://www.plainblack.com/rockstar.jpg',
imageCaption => 'Elvis',
imageByline => 'The King',
imageAlt => '(impersonator)',
imageTitle => 'Rockstar Support',
imageLink => 'http://plainblack.com/services/support/rockstar-support',
};
cmp_deeply( cmp_deeply(
$viewVariables->{photo_loop}, $viewVariables->{photo_loop},
[ [
@ -381,6 +398,7 @@ cmp_deeply(
imageTitle => '', imageTitle => '',
imageLink => 'http://www.lamp.com', imageLink => 'http://www.lamp.com',
}, },
$rockstarVar,
], ],
'viewTemplateVariables: photo_loop is okay' 'viewTemplateVariables: photo_loop is okay'
); );
@ -389,20 +407,14 @@ ok(! $viewVariables->{singlePhoto}, 'viewVariables: singlePhoto: there is more t
ok( $viewVariables->{hasPhotos}, 'viewVariables: hasPhotos: it has photos'); ok( $viewVariables->{hasPhotos}, 'viewVariables: hasPhotos: it has photos');
##Simulate someone deleting the file stored in the storage object. ##Simulate someone deleting the file stored in the storage object.
$storage1->deleteFile('gooey.jpg');
$storage2->deleteFile('lamp.jpg'); $storage2->deleteFile('lamp.jpg');
$viewVariables = $story->viewTemplateVariables; $viewVariables = $story->viewTemplateVariables;
cmp_deeply( cmp_deeply(
$viewVariables->{photo_loop}, $viewVariables->{photo_loop},
[ [
{ $rockstarVar,
imageUrl => re('gooey.jpg'),
imageCaption => 'Mascot for a popular CMS',
imageByline => 'Darcy Gibson',
imageAlt => 'Gooey',
imageTitle => 'Mascot',
imageLink => 'http://www.webgui.org',
},
], ],
'viewTemplateVariables: photo_loop: if the storage has no files, it is not shown' 'viewTemplateVariables: photo_loop: if the storage has no files, it is not shown'
); );