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;

View file

@ -125,6 +125,13 @@ sub definition {
label => $i18n->get("richEditIdAlbum label"),
hoverHelp => $i18n->get("richEditIdAlbum description"),
},
richEditIdFile => {
tab => "properties",
fieldType => "selectRichEditor",
defaultValue => "PBrichedit000000000002", # Forum Rich editor
label => $i18n->get("richEditIdFile label"),
hoverHelp => $i18n->get("richEditIdFile description"),
},
richEditIdComment => {
tab => "properties",
fieldType => "selectRichEditor",
@ -323,6 +330,34 @@ sub definition {
#----------------------------------------------------------------------------
=head2 addChild ( properties, [...] )
Add a child to this asset. See C<WebGUI::AssetLineage> for more info.
Overridden to ensure that only GalleryAlbums are added to Galleries.
=cut
sub addChild {
my $self = shift;
my $properties = shift;
my $albumClass = "WebGUI::Asset::Wobject::GalleryAlbum";
# Load the class
WebGUI::Pluggable::load( $properties->{className} );
if ( !$properties->{className}->isa( $albumClass ) ) {
$self->session->errorHandler->security(
"add a ".$properties->{className}." to a ".$self->get("className")
);
return undef;
}
return $self->SUPER::addChild( $properties, @_ );
}
#----------------------------------------------------------------------------
=head2 appendTemplateVarsSearchForm ( var )
Appends the template vars for the search form to the hash reference C<var>.
@ -372,9 +407,9 @@ sub appendTemplateVarsSearchForm {
# Search classes
tie my %searchClassOptions, 'Tie::IxHash', (
'WebGUI::Asset::File::Image::Photo' => $i18n->get("search class photo"),
'WebGUI::Asset::Wobject::GalleryAlbum' => $i18n->get("search class galleryalbum"),
'' => $i18n->get("search class any"),
'WebGUI::Asset::File::GalleryFile::Photo' => $i18n->get("search class photo"),
'WebGUI::Asset::Wobject::GalleryAlbum' => $i18n->get("search class galleryalbum"),
'' => $i18n->get("search class any"),
);
$var->{ searchForm_className }
= WebGUI::Form::radioList( $session, {
@ -580,7 +615,7 @@ sub getAssetClassForFile {
# Checks for Photo assets
if ( $filepath =~ /\.(jpe?g|gif|png)$/i ) {
return "WebGUI::Asset::File::Image::Photo";
return "WebGUI::Asset::File::GalleryFile::Photo";
}
# No class found
@ -931,7 +966,7 @@ sub www_search {
my $joinClass = [
'WebGUI::Asset::Wobject::GalleryAlbum',
'WebGUI::Asset::File::Image::Photo',
'WebGUI::Asset::File::GalleryFile::Photo',
];
if ( $form->get("className") ) {
$joinClass = [ $form->get('className') ];

View file

@ -146,6 +146,34 @@ sub addArchive {
#----------------------------------------------------------------------------
=head2 addChild ( properties [, ... ] )
Add a child to this GalleryAlbum. See C<WebGUI::AssetLineage> for more info.
Override to ensure only appropriate classes get added to GalleryAlbums.
=cut
sub addChild {
my $self = shift;
my $properties = shift;
my $fileClass = 'WebGUI::Asset::File::GalleryFile';
# Load the class
WebGUI::Pluggable::load( $properties->{className} );
if ( !$properties->{className}->isa( $fileClass ) ) {
$self->session->errorHandler->security(
"add a ".$properties->{className}." to a ".$self->get("className")
);
return undef;
}
return $self->SUPER::addChild( $properties, @_ );
}
#----------------------------------------------------------------------------
=head2 appendTemplateVarsFileLoop ( vars, assetIds )
Append template vars for a file loop for the specified assetIds. C<vars> is
@ -381,7 +409,7 @@ sub getTemplateVars {
# Friendly URLs
$var->{ url } = $self->getUrl;
$var->{ url_addArchive } = $self->getUrl('func=addArchive');
$var->{ url_addPhoto } = $self->getUrl("func=add;class=WebGUI::Asset::File::Image::Photo");
$var->{ url_addPhoto } = $self->getUrl("func=add;class=WebGUI::Asset::File::GalleryFile::Photo");
$var->{ url_addNoClass } = $self->getUrl("func=add");
$var->{ url_delete } = $self->getUrl("func=delete");
$var->{ url_edit } = $self->getUrl("func=edit");

View file

@ -87,6 +87,16 @@ our $I18N = {
lastUpdated => 0,
context => 'Asset property description',
},
"richEditIdFile label" => {
message => "Rich Editor for Files",
lastUpdated => 0,
context => 'Asset property label',
},
"richEditIdFile description" => {
message => "The Rich Text Editor to use for Files",
lastUpdated => 0,
context => 'Asset property description',
},
"richEditIdFileComment label" => {
message => "Rich Editor for Comments",
lastUpdated => 0,

View file

@ -79,7 +79,7 @@ our $I18N = {
},
'help thumbnails body' => {
message => 'These variables are available from the slideshow view of the Album',
message => 'These variables are available from the thumbnails view of the Album',
lastUpdated => 0,
},