Added WebGUI::Asset::File::GalleryFile

Changed Photo to subclass WebGUI::Asset::File::GalleryFile
This commit is contained in:
Doug Bell 2008-03-05 23:06:58 +00:00
parent 9695b704c5
commit 3842ebf6fa
23 changed files with 360 additions and 115 deletions

View file

@ -0,0 +1,142 @@
package WebGUI::Asset::File::GalleryFile;
=head1 LEGAL
-------------------------------------------------------------------
WebGUI is Copyright 2001-2008 Plain Black Corporation.
-------------------------------------------------------------------
Please read the legal notices (docs/legal.txt) and the license
(docs/license.txt) that came with this distribution before using
this software.
-------------------------------------------------------------------
http://www.plainblack.com info@plainblack.com
-------------------------------------------------------------------
=cut
use strict;
use base 'WebGUI::Asset::File';
=head1 NAME
WebGUI::Asset::File::GalleryFile - Superclass to create files for the Gallery
=head1 SYNOPSIS
=head1 DESCRIPTION
=head1 METHODS
These methods are available from this class
=cut
#----------------------------------------------------------------------------
=head2 getThumbnailUrl ( )
Gets the URL to the thumbnail for this GalleryFile. This should probably be
overridded by your child class.
=cut
sub getThumbnailUrl {
my $self = shift;
}
#----------------------------------------------------------------------------
=head2 getTemplateVars ( )
Gets the template vars for this GalleryFile. You should probably extend this
method.
=cut
sub getTemplateVars {
my $self = shift;
my $var = $self->get;
$var->{ fileUrl } = $self->getFileUrl;
$var->{ thumbnailUrl } = $self->getThumbnailUrl;
return $var;
}
#----------------------------------------------------------------------------
=head2 processStyle ( html )
Returns the HTML from the Gallery's style.
=cut
sub processStyle {
my $self = shift;
return $self->getGallery->processStyle( @_ );
}
#----------------------------------------------------------------------------
=head2 www_demote
Override the default demote page to send the user back to the GalleryAlbum
edit screen.
=cut
sub www_demote {
my $self = shift;
return $self->session->privilege->insufficient unless $self->canEdit;
$self->demote;
return $self->session->asset( $self->getParent )->www_edit;
}
#----------------------------------------------------------------------------
=head2 www_promote
Override the default promote page to send the user back to the GalleryAlbum
edit screen.
=cut
sub www_promote {
my $self = shift;
return $self->session->privilege->insufficient unless $self->canEdit;
$self->promote;
return $self->session->asset( $self->getParent )->www_edit;
}
#----------------------------------------------------------------------------
=head2 www_view ( )
Show the default view, with content chunking.
=cut
sub www_view {
my $self = shift;
$self->session->http->setLastModified($self->getContentLastModified);
$self->session->http->sendHeader;
$self->prepareView;
my $style = $self->processStyle("~~~");
my ($head, $foot) = split("~~~",$style);
$self->session->output->print($head, 1);
$self->session->output->print($self->view);
$self->session->output->print($foot, 1);
return "chunked";
}
1; # Who knew the truth would be so obvious?

View file

@ -1,4 +1,4 @@
package WebGUI::Asset::File::Image::Photo;
package WebGUI::Asset::File::GalleryFile::Photo;
=head1 LEGAL
@ -15,7 +15,7 @@ package WebGUI::Asset::File::Image::Photo;
=cut
use strict;
use base 'WebGUI::Asset::File::Image';
use base 'WebGUI::Asset::File::GalleryFile';
use Carp qw( carp croak );
use Image::ExifTool qw( :Public );
@ -26,18 +26,19 @@ use Tie::IxHash;
use WebGUI::DateTime;
use WebGUI::Friends;
use WebGUI::Utility;
use WebGUI::Storage::Image;
=head1 NAME
WebGUI::Asset::File::Image::Photo
WebGUI::Asset::File::GalleryFile::Photo
=head1 DESCRIPTION
=head1 SYNOPSIS
use WebGUI::Asset::File::Image::Photo
use WebGUI::Asset::File::GalleryFile::Photo
=head1 DIAGNOSTICS
@ -101,7 +102,7 @@ sub definition {
autoGenerateForms => 0,
icon => 'photo.gif',
tableName => 'Photo',
className => 'WebGUI::Asset::File::Image::Photo',
className => 'WebGUI::Asset::File::GalleryFile::Photo',
i18n => 'Asset_Photo',
properties => \%properties,
};
@ -196,13 +197,18 @@ sub applyConstraints {
my $gallery = $self->getGallery;
# Update the asset's size and make a thumbnail
$self->SUPER::applyConstraints({
maxImageSize => $self->getGallery->get("imageViewSize"),
thumbnailSize => $self->getGallery->get("imageThumbnailSize"),
});
$self->makeResolutions();
$self->updateExifDataFromFile();
my $maxImageSize = $self->getGallery->get("imageViewSize")
|| $self->session->setting->get("maxImageSize");
my $thumbnailSize = $self->getGallery->get("imageThumbnailSize")
|| $self->session->setting->get("thumbnailSize");
my $parameters = $self->get("parameters");
my $storage = $self->getStorageLocation;
my $file = $self->get("filename");
$storage->adjustMaxImageSize($file);
$self->generateThumbnail;
$self->setSize;
$self->makeResolutions;
$self->updateExifDataFromFile;
}
#----------------------------------------------------------------------------
@ -311,6 +317,23 @@ sub deleteComment {
);
}
#-------------------------------------------------------------------
=head2 generateThumbnail ( )
Generates a thumbnail for this image.
=cut
sub generateThumbnail {
my $self = shift;
$self->getStorageLocation->generateThumbnail(
$self->get("filename"),
$self->getGallery->get("imageThumbnailSize"),
);
return;
}
#----------------------------------------------------------------------------
=head2 getAutoCommitWorkflowId ( )
@ -453,6 +476,19 @@ sub getResolutions {
#----------------------------------------------------------------------------
=head2 getStorageClass ( )
Get the WebGUI::Storage subclass name for this file. This file uses the
Image class.
=cut
sub getStorageClass {
return 'WebGUI::Storage::Image';
}
#----------------------------------------------------------------------------
=head2 getTemplateVars ( )
Get a hash reference of template variables shared by all views of this asset.
@ -462,7 +498,7 @@ Get a hash reference of template variables shared by all views of this asset.
sub getTemplateVars {
my $self = shift;
my $session = $self->session;
my $var = $self->get;
my $var = $self->SUPER::getTemplateVars;
my $owner = WebGUI::User->new( $session, $self->get("ownerUserId") );
# Fix 'undef' vars since HTML::Template does inheritence on them
@ -487,9 +523,6 @@ sub getTemplateVars {
= $self->getGallery->getUrl('func=listFilesForUser;userId=' . $self->get("ownerUserId"));
$var->{ url_promote } = $self->getUrl('func=promote');
$var->{ fileUrl } = $self->getFileUrl;
$var->{ thumbnailUrl } = $self->getThumbnailUrl;
### Download resolutions
for my $resolution ( $self->getResolutions ) {
push @{ $var->{ resolutions_loop } }, {
@ -512,6 +545,21 @@ sub getTemplateVars {
#----------------------------------------------------------------------------
=head2 getThumbnailUrl ( )
Get the URL to the thumbnail for this Photo.
=cut
sub getThumbnailUrl {
my $self = shift;
return $self->getStorageLocation->getThumbnailUrl(
$self->get("filename")
);
}
#----------------------------------------------------------------------------
=head2 i18n ( [ session ] )
Get a WebGUI::International object for this class.
@ -704,19 +752,6 @@ sub processPropertiesFromFormPost {
#----------------------------------------------------------------------------
=head2 processStyle ( html )
Returns the HTML from the Gallery's style.
=cut
sub processStyle {
my $self = shift;
return $self->getGallery->processStyle( @_ );
}
#----------------------------------------------------------------------------
=head2 purge ( )
Purge the asset. Remove all comments on the photo.
@ -771,6 +806,20 @@ sub setComment {
#----------------------------------------------------------------------------
=head2 setFile ( filename )
Extend the superclass setFile to automatically generate thumbnails.
=cut
sub setFile {
my $self = shift;
$self->SUPER::setFile(@_);
$self->generateThumbnail;
}
#----------------------------------------------------------------------------
=head2 updateExifDataFromFile ( )
Gets the EXIF data from the uploaded image and store it in the database.
@ -917,25 +966,6 @@ sub www_deleteConfirm {
#----------------------------------------------------------------------------
=head2 www_demote
Override the default demote page to send the user back to the GalleryAlbum
edit screen.
=cut
sub www_demote {
my $self = shift;
return $self->session->privilege->insufficient unless $self->canEdit;
$self->demote;
return $self->session->asset( $self->getParent )->www_edit;
}
#----------------------------------------------------------------------------
=head2 www_download
Download the Photo with the specified resolution. If no resolution specified,
@ -1211,25 +1241,6 @@ sub www_makeShortcutSave {
#----------------------------------------------------------------------------
=head2 www_promote
Override the default promote page to send the user back to the GalleryAlbum
edit screen.
=cut
sub www_promote {
my $self = shift;
return $self->session->privilege->insufficient unless $self->canEdit;
$self->promote;
return $self->session->asset( $self->getParent )->www_edit;
}
#----------------------------------------------------------------------------
=head2 www_showConfirmation ( )
Shows the confirmation message after adding / editing a gallery album.
@ -1266,15 +1277,7 @@ sub www_view {
# Add to views
$self->update({ views => $self->get('views') + 1 });
$self->session->http->setLastModified($self->getContentLastModified);
$self->session->http->sendHeader;
$self->prepareView;
my $style = $self->processStyle("~~~");
my ($head, $foot) = split("~~~",$style);
$self->session->output->print($head, 1);
$self->session->output->print($self->view);
$self->session->output->print($foot, 1);
return "chunked";
return $self->SUPER::www_view;
}
1;