more work. completed GalleryAlbum. started Gallery.
This commit is contained in:
parent
2570980fa5
commit
55135c8147
5 changed files with 825 additions and 32 deletions
|
|
@ -138,7 +138,7 @@ CREATE TABLE IF NOT EXISTS Gallery (
|
||||||
imageViewSize INT,
|
imageViewSize INT,
|
||||||
imageThumbnailSize INT,
|
imageThumbnailSize INT,
|
||||||
maxSpacePerUser VARCHAR(20),
|
maxSpacePerUser VARCHAR(20),
|
||||||
richEditIdFileComment VARCHAR(22) BINARY,
|
richEditIdComment VARCHAR(22) BINARY,
|
||||||
templateIdAddArchive VARCHAR(22) BINARY,
|
templateIdAddArchive VARCHAR(22) BINARY,
|
||||||
templateIdDeleteAlbum VARCHAR(22) BINARY,
|
templateIdDeleteAlbum VARCHAR(22) BINARY,
|
||||||
templateIdDeleteFile VARCHAR(22) BINARY,
|
templateIdDeleteFile VARCHAR(22) BINARY,
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,19 @@ use Image::ExifTool qw( :Public );
|
||||||
use JSON;
|
use JSON;
|
||||||
use Tie::IxHash;
|
use Tie::IxHash;
|
||||||
|
|
||||||
|
our $magick;
|
||||||
|
BEGIN {
|
||||||
|
if (eval { require Graphics::Magick; 1 }) {
|
||||||
|
$magick = 'Graphics::Magick';
|
||||||
|
}
|
||||||
|
elsif (eval { require Image::Magick; 1 }) {
|
||||||
|
$magick = 'Image::Magick';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
croak "You must have either Graphics::Magick or Image::Magick installed to run WebGUI.\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
use WebGUI::Friends;
|
use WebGUI::Friends;
|
||||||
use WebGUI::Utility;
|
use WebGUI::Utility;
|
||||||
|
|
||||||
|
|
@ -50,12 +63,6 @@ These methods are available from this class:
|
||||||
|
|
||||||
Define the properties of the Photo asset.
|
Define the properties of the Photo asset.
|
||||||
|
|
||||||
=head3 session
|
|
||||||
|
|
||||||
=head3 definition
|
|
||||||
|
|
||||||
A hash reference passed in from a subclass definition.
|
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub definition {
|
sub definition {
|
||||||
|
|
@ -91,6 +98,7 @@ sub definition {
|
||||||
i18n => 'Asset_Photo',
|
i18n => 'Asset_Photo',
|
||||||
properties => \%properties,
|
properties => \%properties,
|
||||||
};
|
};
|
||||||
|
|
||||||
return $class->SUPER::definition($session, $definition);
|
return $class->SUPER::definition($session, $definition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -107,7 +115,12 @@ sub appendTemplateVarsForCommentForm {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $var = shift;
|
my $var = shift;
|
||||||
|
|
||||||
# ...
|
$var->{commentForm_start}
|
||||||
|
= WebGUI::Form::formHeader( $session );
|
||||||
|
. WebGUI::Form::hidden( $session, { name => "func", value => "addCommentSave" } )
|
||||||
|
;
|
||||||
|
$var->{commentForm_end}
|
||||||
|
= WebGUI::Form::formFooter( $session );
|
||||||
|
|
||||||
return $var;
|
return $var;
|
||||||
}
|
}
|
||||||
|
|
@ -142,6 +155,28 @@ sub applyConstraints {
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 canComment ( [userId] )
|
||||||
|
|
||||||
|
Returns true if the user can comment on this asset. C<userId> is a WebGUI
|
||||||
|
user ID. If no userId is passed, check the current user.
|
||||||
|
|
||||||
|
Users can comment on this Photo if they are allowed to view and the album
|
||||||
|
allows comments.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub canComment {
|
||||||
|
my $self = shift;
|
||||||
|
my $userId = shift || $self->session->user->userId;
|
||||||
|
my $album = $self->getParent;
|
||||||
|
|
||||||
|
return 0 if !$self->canView($userId);
|
||||||
|
|
||||||
|
return $album->canComment($userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 canEdit ( [userId] )
|
=head2 canEdit ( [userId] )
|
||||||
|
|
||||||
Returns true if the user can edit this asset. C<userId> is a WebGUI user ID.
|
Returns true if the user can edit this asset. C<userId> is a WebGUI user ID.
|
||||||
|
|
@ -399,10 +434,16 @@ sub makeResolutions {
|
||||||
|
|
||||||
# Get default if necessary
|
# Get default if necessary
|
||||||
$resolutions ||= $self->getGallery->getImageResolutions;
|
$resolutions ||= $self->getGallery->getImageResolutions;
|
||||||
|
|
||||||
|
my $storage = $self->getStorageLocation;
|
||||||
|
my $photo = $magick->new;
|
||||||
|
$photo->Read( $storage->get( $self->get("filename") ) );
|
||||||
|
|
||||||
for my $res ( @$resolutions ) {
|
for my $res ( @$resolutions ) {
|
||||||
# carp if resolution is bad
|
# carp if resolution is bad
|
||||||
# ...
|
my $newPhoto = $photo->Clone;
|
||||||
|
$newPhoto->Resize( geometry => $res );
|
||||||
|
$newPhoto->Write( $storage->getFilePath( "$res.jpg" ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -546,7 +587,14 @@ sub view {
|
||||||
$var->{ controls } = $self->getToolbar;
|
$var->{ controls } = $self->getToolbar;
|
||||||
$var->{ fileUrl } = $self->getFileUrl;
|
$var->{ fileUrl } = $self->getFileUrl;
|
||||||
$var->{ fileIcon } = $self->getFileIconUrl;
|
$var->{ fileIcon } = $self->getFileIconUrl;
|
||||||
|
|
||||||
|
$self->appendTemplateVarsForCommentForm( $var );
|
||||||
|
|
||||||
|
my $p = $self->getCommentPaginator;
|
||||||
|
$var->{ commentLoop } = $p->getPageData;
|
||||||
|
$var->{ commentLoop_urlNext } = [$p->getNextPageLink]->[0];
|
||||||
|
$var->{ commentLoop_urlPrev } = [$p->getPrevPageLink]->[0];
|
||||||
|
$var->{ commentLoop_pageBar } = $p->getBarAdvanced;
|
||||||
|
|
||||||
return $self->processTemplate($var, undef, $self->{_viewTemplate});
|
return $self->processTemplate($var, undef, $self->{_viewTemplate});
|
||||||
}
|
}
|
||||||
|
|
@ -561,9 +609,22 @@ Save a new comment to the Photo.
|
||||||
|
|
||||||
sub www_addCommentSave {
|
sub www_addCommentSave {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
|
||||||
|
return $self->session->privilege->insufficient unless $self->canComment;
|
||||||
|
|
||||||
my $form = $self->session;
|
my $form = $self->session;
|
||||||
|
|
||||||
# ...
|
my $properties = {
|
||||||
|
assetId => $self->getId,
|
||||||
|
creationDate => time,
|
||||||
|
userId => $session->user->userId,
|
||||||
|
visitorIp => ( $session->user->userId eq "1" ? $session->env("REMOTE_ADDR") : undef ),
|
||||||
|
bodyText => $form->get("bodyText"),
|
||||||
|
};
|
||||||
|
|
||||||
|
$self->setComment( "new", $properties );
|
||||||
|
|
||||||
|
return $self->www_view;
|
||||||
}
|
}
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
@ -582,7 +643,6 @@ sub www_delete {
|
||||||
|
|
||||||
my $var = $self->getTemplateVar;
|
my $var = $self->getTemplateVar;
|
||||||
$var->{ url_yes } = $self->getUrl("func=deleteConfirm");
|
$var->{ url_yes } = $self->getUrl("func=deleteConfirm");
|
||||||
$var->{ url_no } = $self->getUrl();
|
|
||||||
|
|
||||||
return $self->processStyle(
|
return $self->processStyle(
|
||||||
$self->processTemplate( $var, $self->getGallery->get("templateIdDeletePhoto") )
|
$self->processTemplate( $var, $self->getGallery->get("templateIdDeletePhoto") )
|
||||||
|
|
@ -705,7 +765,7 @@ sub www_edit {
|
||||||
|
|
||||||
|
|
||||||
return $self->processStyle(
|
return $self->processStyle(
|
||||||
$self->processTemplate($var, $self->getGallery->get("templateIdEditFile"))
|
$self->processTemplate( $var, $self->getGallery->getTemplateIdEditFile )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,14 @@ use WebGUI::International;
|
||||||
use WebGUI::Utility;
|
use WebGUI::Utility;
|
||||||
use base 'WebGUI::Asset::Wobject';
|
use base 'WebGUI::Asset::Wobject';
|
||||||
|
|
||||||
|
=head1 NAME
|
||||||
|
|
||||||
|
=head1 DESCRIPTION
|
||||||
|
|
||||||
|
=head1 SYNOPSIS
|
||||||
|
|
||||||
|
=head1 METHODS
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 definition ( )
|
=head2 definition ( )
|
||||||
|
|
@ -69,7 +77,7 @@ sub definition {
|
||||||
imageResolutions => {
|
imageResolutions => {
|
||||||
tab => "properties",
|
tab => "properties",
|
||||||
fieldType => "checkList",
|
fieldType => "checkList",
|
||||||
defaultValue => ['800','1024','1200','1600'],
|
defaultValue => ['800', '1024', '1200', '1600', '2880'],
|
||||||
options => \%imageResolutionOptions,
|
options => \%imageResolutionOptions,
|
||||||
label => $i18n->get("imageResolutions label"),
|
label => $i18n->get("imageResolutions label"),
|
||||||
hoverHelp => $i18n->get("imageResolutions description"),
|
hoverHelp => $i18n->get("imageResolutions description"),
|
||||||
|
|
@ -95,7 +103,7 @@ sub definition {
|
||||||
label => $i18n->get("maxSpacePerUser label"),
|
label => $i18n->get("maxSpacePerUser label"),
|
||||||
hoverHelp => $i18n->get("maxSpacePerUser description"),
|
hoverHelp => $i18n->get("maxSpacePerUser description"),
|
||||||
},
|
},
|
||||||
richEditIdFileComment => {
|
richEditIdComment => {
|
||||||
tab => "properties",
|
tab => "properties",
|
||||||
fieldType => "selectRichEditor",
|
fieldType => "selectRichEditor",
|
||||||
defaultValue => undef, # Rich Editor for Posts
|
defaultValue => undef, # Rich Editor for Posts
|
||||||
|
|
@ -246,10 +254,197 @@ sub definition {
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 getTemplateEditFile ( )
|
=head2 canAddFile ( [userId] )
|
||||||
|
|
||||||
Returns an instance of a WebGUI::Asset::Template for the template to edit
|
Returns true if the user can add files to this Gallery. C<userId> is the
|
||||||
files in this gallery
|
userId to check. If no userId is passed, will check the current user.
|
||||||
|
|
||||||
|
Users can add files to this gallery if they are part of the C<groupIdAddFile>
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub canAddFile {
|
||||||
|
my $self = shift;
|
||||||
|
my $userId = shift;
|
||||||
|
|
||||||
|
my $user = $userId
|
||||||
|
? WebGUI::User->new( $self->session, $userId )
|
||||||
|
: $self->session->user
|
||||||
|
;
|
||||||
|
|
||||||
|
return $user->isInGroup( $self->get("groupIdAddFile") );
|
||||||
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 canComment ( [userId] )
|
||||||
|
|
||||||
|
Returns true if the user can comment on this Gallery. C<userId> is the userId
|
||||||
|
to check. If no userId is passed, will check the current user.
|
||||||
|
|
||||||
|
Users can comment on this gallery if they are part of the
|
||||||
|
C<groupIdAddComment> group.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub canComment {
|
||||||
|
my $self = shift;
|
||||||
|
my $userId = shift;
|
||||||
|
|
||||||
|
my $user = $userId
|
||||||
|
? WebGUI::User->new( $self->session, $userId )
|
||||||
|
: $self->session->user
|
||||||
|
;
|
||||||
|
|
||||||
|
return $user->isInGroup( $self->get("groupIdAddComment") );
|
||||||
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 canEdit ( [userId] )
|
||||||
|
|
||||||
|
Returns true if the user can edit this Gallery. C<userId> is the userId to
|
||||||
|
check. If no userId is passed, will check the current user.
|
||||||
|
|
||||||
|
Users can edit this gallery if they are part of the C<groupIdEdit> group.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub canEdit {
|
||||||
|
my $self = shift;
|
||||||
|
my $userId = shift;
|
||||||
|
|
||||||
|
my $user = $userId
|
||||||
|
? WebGUI::User->new( $self->session, $userId )
|
||||||
|
: $self->session->user
|
||||||
|
;
|
||||||
|
|
||||||
|
return $user->isInGroup( $self->get("groupIdEdit") );
|
||||||
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 canView ( [userId] )
|
||||||
|
|
||||||
|
Returns true if the user can view this Gallery. C<userId> is the userId to
|
||||||
|
check. If no userId is passed, will check the current user.
|
||||||
|
|
||||||
|
Users can view this gallery if they are part of the C<groupIdView> group.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub canView {
|
||||||
|
my $self = shift;
|
||||||
|
my $userId = shift;
|
||||||
|
|
||||||
|
my $user = $userId
|
||||||
|
? WebGUI::User->new( $self->session, $userId )
|
||||||
|
: $self->session->user
|
||||||
|
;
|
||||||
|
|
||||||
|
return $user->isInGroup( $self->get("groupIdView") );
|
||||||
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 getAlbumIds ( )
|
||||||
|
|
||||||
|
Gets an array reference of all the album IDs under this Gallery.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub getAlbumIds {
|
||||||
|
my $self = shift;
|
||||||
|
|
||||||
|
return $self->getLineage(['descendants'], {
|
||||||
|
includeOnlyClasses => ['WebGUI::Asset::Wobject::GalleryAlbum'],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 getAlbumPaginator ( )
|
||||||
|
|
||||||
|
Gets a WebGUI::Paginator for all the albums in this Gallery.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub getAlbumPaginator {
|
||||||
|
my $self = shift;
|
||||||
|
|
||||||
|
my $p = WebGUI::Paginator->new( $self->session, $self->getUrl );
|
||||||
|
$p->setDataByArrayRef( $self->getAlbumIds );
|
||||||
|
|
||||||
|
return $p;
|
||||||
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 getAssetClassForFile ( filepath )
|
||||||
|
|
||||||
|
Gets the WebGUI Asset class for the file at the given C<filepath>. Returns
|
||||||
|
undef if the file cannot be saved under this Gallery.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub getAssetClassForFile {
|
||||||
|
my $self = shift;
|
||||||
|
my $filepath = shift;
|
||||||
|
|
||||||
|
# Checks for Photo assets
|
||||||
|
if ( $filepath =~ /\.(jpe?g|gif|png)/i ) {
|
||||||
|
return "WebGUI::Asset::File::Image::Photo";
|
||||||
|
}
|
||||||
|
|
||||||
|
# No class found
|
||||||
|
return undef;
|
||||||
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 getImageResolutions ( )
|
||||||
|
|
||||||
|
Gets an array reference of the image resolutions to create for image-type
|
||||||
|
assets in this gallery.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub getImageResolutions {
|
||||||
|
my $self = shift;
|
||||||
|
return [ split /\n/, $self->get("imageResolutions") ];
|
||||||
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 getSearchPaginator ( options )
|
||||||
|
|
||||||
|
Gets a WebGUI::Paginator for a search. C<options> is a hash reference of
|
||||||
|
options with the following keys:
|
||||||
|
|
||||||
|
keywords => Keywords to search on
|
||||||
|
|
||||||
|
Other keys are valid, see C<WebGUI::Search::search()> for details.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub getSearchPaginator {
|
||||||
|
my $self = shift;
|
||||||
|
my $rules = shift;
|
||||||
|
|
||||||
|
$rules->{ lineage } = $self->get("lineage");
|
||||||
|
|
||||||
|
my $search = WebGUI::Search->new( $self->session );
|
||||||
|
$search->search( $rules );
|
||||||
|
my $paginator = $search->getPaginatorResultSet( $self->getUrl('func=search') );
|
||||||
|
|
||||||
|
return $paginator;
|
||||||
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 getTemplateIdEditFile ( )
|
||||||
|
|
||||||
|
Returns the ID for the template to edit a file.
|
||||||
|
|
||||||
NOTE: This may need to change in the future to take into account different
|
NOTE: This may need to change in the future to take into account different
|
||||||
classes of files inside of a Gallery.
|
classes of files inside of a Gallery.
|
||||||
|
|
@ -258,7 +453,72 @@ classes of files inside of a Gallery.
|
||||||
|
|
||||||
sub getTemplateEditFile {
|
sub getTemplateEditFile {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
return WebGUI::Asset::Template->new($self->session, $self->get("templateIdEditFile"));
|
return $self->get("templateIdEditFile");
|
||||||
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 getTemplateVars ( )
|
||||||
|
|
||||||
|
Gets a hash reference of vars common to all templates.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub getTemplateVars {
|
||||||
|
my $self = shift;
|
||||||
|
my $var = $self->get;
|
||||||
|
|
||||||
|
return $var;
|
||||||
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 getUserFileIds ( [userId] )
|
||||||
|
|
||||||
|
Gets an array reference of assetIds for the files in this Gallery owned by
|
||||||
|
the specified C<userId>. If userId is not defined, will use the current user.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub getUserFileIds {
|
||||||
|
my $self = shift;
|
||||||
|
my $userId = shift || $self->session->user->userId;
|
||||||
|
|
||||||
|
my $db = $self->session->db;
|
||||||
|
|
||||||
|
# Note: We use excludeClasses to avoid getting GalleryAlbum assets
|
||||||
|
my $assetIds
|
||||||
|
= $self->getLineage( ['descendants'], {
|
||||||
|
excludeClasses => [ 'WebGUI::Asset::Wobject::GalleryAlbum' ],
|
||||||
|
whereClause => "ownerUserId = " . $db->quote($userId),
|
||||||
|
});
|
||||||
|
|
||||||
|
return $assetIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 getUserAlbumIds ( [userId] )
|
||||||
|
|
||||||
|
Gets an array reference of assetIds for the GalleryAlbums in this Gallery
|
||||||
|
owned by the specified C<userId>. If userId is not defined, will use the
|
||||||
|
current user.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub getUserAlbumIds {
|
||||||
|
my $self = shift;
|
||||||
|
my $userId = shift || $self->session->user->userId;
|
||||||
|
|
||||||
|
my $db = $self->session->db;
|
||||||
|
|
||||||
|
my $assetIds
|
||||||
|
= $self->getLineage( ['descendants'], {
|
||||||
|
includeOnlyClasses => [ 'WebGUI::Asset::Wobject::GalleryAlbum' ],
|
||||||
|
whereClause => "ownerUserId = " . $db->quote($userId),
|
||||||
|
});
|
||||||
|
|
||||||
|
return $assetIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
@ -277,7 +537,7 @@ sub prepareView {
|
||||||
$self->{_viewTemplate} = $template;
|
$self->{_viewTemplate} = $template;
|
||||||
}
|
}
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 view ( )
|
=head2 view ( )
|
||||||
|
|
||||||
|
|
@ -294,4 +554,41 @@ sub view {
|
||||||
return $self->processTemplate($var, undef, $self->{_viewTemplate});
|
return $self->processTemplate($var, undef, $self->{_viewTemplate});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 www_listAlbums ( )
|
||||||
|
|
||||||
|
Show a paginated list of the albums in this gallery.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub www_listAlbums {
|
||||||
|
my $self = shift;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 www_listAlbumsRss ( )
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 www_search ( )
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 www_userGallery ( )
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 www_userGalleryRss ( )
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
||||||
|
|
@ -13,18 +13,28 @@ $VERSION = "1.0.0";
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
|
use base 'WebGUI::Asset::Wobject';
|
||||||
use Tie::IxHash;
|
use Tie::IxHash;
|
||||||
use WebGUI::International;
|
use WebGUI::International;
|
||||||
use WebGUI::Utility;
|
use WebGUI::Utility;
|
||||||
use base 'WebGUI::Asset::Wobject';
|
|
||||||
|
use Archive::Any;
|
||||||
|
|
||||||
|
=head1 NAME
|
||||||
|
|
||||||
|
=head1 DESCRIPTION
|
||||||
|
|
||||||
|
=head1 SYNOPSIS
|
||||||
|
|
||||||
|
=head1 DIAGNOSTICS
|
||||||
|
|
||||||
|
=head1 METHODS
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 definition ( )
|
=head2 definition ( )
|
||||||
|
|
||||||
defines wobject properties for New Wobject instances. You absolutely need
|
Define wobject properties for new GalleryAlbum wobjects.
|
||||||
this method in your new Wobjects. If you choose to "autoGenerateForms", the
|
|
||||||
getEditForm method is unnecessary/redundant/useless.
|
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
|
|
@ -32,7 +42,7 @@ sub definition {
|
||||||
my $class = shift;
|
my $class = shift;
|
||||||
my $session = shift;
|
my $session = shift;
|
||||||
my $definition = shift;
|
my $definition = shift;
|
||||||
my $i18n = WebGUI::International->new($session, 'Asset_GalleryAlbum');
|
my $i18n = __PACKAGE__->i18n($session);
|
||||||
|
|
||||||
tie my %properties, 'Tie::IxHash', (
|
tie my %properties, 'Tie::IxHash', (
|
||||||
allowComments => {
|
allowComments => {
|
||||||
|
|
@ -63,6 +73,131 @@ sub definition {
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 addArchive ( filename, properties )
|
||||||
|
|
||||||
|
Add an archive of Files to this Album. C<filename> is the full path of the
|
||||||
|
archive. C<properties> is a hash reference of properties to assign to the
|
||||||
|
photos in the archive.
|
||||||
|
|
||||||
|
Will croak if cannot read the archive or if the archive will extract itself to
|
||||||
|
a directory outside of the storage location.
|
||||||
|
|
||||||
|
Will only handle file types handled by the parent Gallery.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub addArchive {
|
||||||
|
my $self = shift;
|
||||||
|
my $filename = shift;
|
||||||
|
my $properties = shift;
|
||||||
|
|
||||||
|
my $archive = Archive::Any->new( $filename );
|
||||||
|
|
||||||
|
croak "Archive will extract to directory outside of storage location!"
|
||||||
|
if $archive->is_naughty;
|
||||||
|
|
||||||
|
use File::Temp qw{ tempdir };
|
||||||
|
my $tempdirName = tempdir( "WebGUI-Gallery-XXXXXXXX", TMPDIR => 1, CLEANUP => 1);
|
||||||
|
$archive->extract( $tempdir );
|
||||||
|
|
||||||
|
opendir my $dh, $tempdirName or die "Could not open temp dir $tempdirName: $!";
|
||||||
|
for my $file (readdir $dh) {
|
||||||
|
my $class = $gallery->getAssetClassForFile( $file );
|
||||||
|
next unless $class; # class is undef for those files the Gallery can't handle
|
||||||
|
|
||||||
|
$self->addChild({
|
||||||
|
className => $class,
|
||||||
|
title => $properties->{title},
|
||||||
|
menuTitle => $properties->{menuTitle} || $properties->{title},
|
||||||
|
synopsis => $properties->{synopsis},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
closedir $dh;
|
||||||
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 appendTemplateVarsFileLoop ( vars, options )
|
||||||
|
|
||||||
|
Append template vars for a file loop with the specified options. C<vars> is
|
||||||
|
a hash reference to add the file loop to. C<options> is a hash reference of
|
||||||
|
options with the following keys:
|
||||||
|
|
||||||
|
perpage => number | "all"
|
||||||
|
If "all", no pagination will be done.
|
||||||
|
url => url
|
||||||
|
The URL to the current page
|
||||||
|
|
||||||
|
Returns the hash reference for convenience.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub appendTemplateVarsFileLoop {
|
||||||
|
my $self = shift;
|
||||||
|
my $var = shift;
|
||||||
|
my $options = shift;
|
||||||
|
|
||||||
|
my @assetIds;
|
||||||
|
if ($options->{perpage} eq "all") {
|
||||||
|
@assetIds = @{ $self->getFileIds };
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
@assetIds = @{ $self->getFilePaginator($options->{url})->getPageData };
|
||||||
|
}
|
||||||
|
|
||||||
|
for my $assetId (@assetIds) {
|
||||||
|
push @{$var->{file_loop}},
|
||||||
|
WebGUI::Asset->newByDynamicClass($session, $assetId)->getTemplateVars;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $var;
|
||||||
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 canAddFile ( [userId] )
|
||||||
|
|
||||||
|
Returns true if the user can add a file to this album. C<userId> is a WebGUI
|
||||||
|
user ID. If no userId is passed, will check the current user.
|
||||||
|
|
||||||
|
Users can add files to this album if they are the owner, or if
|
||||||
|
C<othersCanAdd> is true and the Gallery allows them to add files.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub canAddFile {
|
||||||
|
my $self = shift;
|
||||||
|
my $userId = shift || $self->session->user->userId;
|
||||||
|
|
||||||
|
return 1 if $userId eq $self->get("ownerUserId");
|
||||||
|
return 1 if $self->get("othersCanAdd") && $gallery->canAddFile( $userId );
|
||||||
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 canComment ( [userId] )
|
||||||
|
|
||||||
|
Returns true if the user is allowed to comment on files in this Album.
|
||||||
|
C<userId> is a WebGUI user ID. If no userId is passed, will check the current
|
||||||
|
user.
|
||||||
|
|
||||||
|
Users can comment on files if C<allowComments> is true and the parent Gallery
|
||||||
|
allows comments.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub canComment {
|
||||||
|
my $self = shift;
|
||||||
|
my $userId = shift || $self->session->user->userId;
|
||||||
|
my $gallery = $self->getParent;
|
||||||
|
|
||||||
|
return 0 if !$self->get("allowComments");
|
||||||
|
|
||||||
|
return $gallery->canComment( $userId );
|
||||||
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 canEdit ( [userId] )
|
=head2 canEdit ( [userId] )
|
||||||
|
|
||||||
Returns true if the user can edit this asset. C<userId> is a WebGUI user ID.
|
Returns true if the user can edit this asset. C<userId> is a WebGUI user ID.
|
||||||
|
|
@ -71,6 +206,8 @@ If no userId is passed, check the current user.
|
||||||
Users can edit this GalleryAlbum if they are the owner, or if they can edit
|
Users can edit this GalleryAlbum if they are the owner, or if they can edit
|
||||||
the Gallery parent.
|
the Gallery parent.
|
||||||
|
|
||||||
|
Also handles adding of child assets by calling C<canAddFile>.
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub canEdit {
|
sub canEdit {
|
||||||
|
|
@ -78,11 +215,116 @@ sub canEdit {
|
||||||
my $userId = shift || $self->session->user->userId;
|
my $userId = shift || $self->session->user->userId;
|
||||||
my $gallery = $self->getParent;
|
my $gallery = $self->getParent;
|
||||||
|
|
||||||
return 1 if $userId eq $self->get("ownerUserId");
|
# Handle adding a photo
|
||||||
return $gallery->canEdit($userId);
|
if ( $form->get("func") eq "add" ) {
|
||||||
|
return $self->canAddFile;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return 1 if $userId eq $self->get("ownerUserId");
|
||||||
|
|
||||||
|
return $gallery->canEdit($userId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 canView ( [userId] )
|
||||||
|
|
||||||
|
Returns true if the user can view this asset. C<userId> is a WebGUI user ID.
|
||||||
|
If no userId is given, checks the current user.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
# Inherited from superclass
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 i18n ( [ session ] )
|
||||||
|
|
||||||
|
Get a WebGUI::International object for this class.
|
||||||
|
|
||||||
|
Can be called as a class method, in which case a WebGUI::Session object
|
||||||
|
must be passed in.
|
||||||
|
|
||||||
|
NOTE: This method can NOT be inherited, due to a current limitation
|
||||||
|
in the i18n system. You must ALWAYS call this with C<__PACKAGE__>
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub i18n {
|
||||||
|
my $self = shift;
|
||||||
|
my $session = shift;
|
||||||
|
|
||||||
|
return WebGUI::International->new($session, "Asset_GalleryAlbum");
|
||||||
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 getFileIds ( )
|
||||||
|
|
||||||
|
Gets an array reference of asset IDs for all the files in this album.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub getFileIds {
|
||||||
|
my $self = shift;
|
||||||
|
my $gallery = $self->getParent;
|
||||||
|
|
||||||
|
return $self->assetLineage( ['descendants'], {
|
||||||
|
includeOnlyClasses => $gallery->getAllAssetClassesForFile,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 getFilePaginator ( paginatorUrl )
|
||||||
|
|
||||||
|
Gets a WebGUI::Paginator for the files in this album. C<paginatorUrl> is the
|
||||||
|
url to the current page that will be given to the paginator.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub getFilePaginator {
|
||||||
|
my $self = shift;
|
||||||
|
my $url = shift;
|
||||||
|
|
||||||
|
my $p = WebGUI::Paginator->new( $self->session, $url );
|
||||||
|
$p->setDataByArrayRef( $self->getFileIds );
|
||||||
|
|
||||||
|
return $p;
|
||||||
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 getTemplateVars ( )
|
||||||
|
|
||||||
|
Gets template vars common to all views.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub getTemplateVars {
|
||||||
|
my $self = shift;
|
||||||
|
my $var = $self->get;
|
||||||
|
|
||||||
|
$var->{ url } = $self->getUrl;
|
||||||
|
|
||||||
|
return $var;
|
||||||
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 othersCanAdd ( )
|
||||||
|
|
||||||
|
Returns true if people other than the owner can add files to this album.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub othersCanAdd {
|
||||||
|
my $self = shift;
|
||||||
|
return $self->get("othersCanAdd");
|
||||||
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 prepareView ( )
|
=head2 prepareView ( )
|
||||||
|
|
||||||
|
|
@ -93,12 +335,30 @@ See WebGUI::Asset::prepareView() for details.
|
||||||
sub prepareView {
|
sub prepareView {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
$self->SUPER::prepareView();
|
$self->SUPER::prepareView();
|
||||||
my $template = WebGUI::Asset::Template->new($self->session, $self->get("templateId"));
|
|
||||||
|
my $templateId = $self->getParent->get("templateIdViewAlbum");
|
||||||
|
|
||||||
|
my $template
|
||||||
|
= WebGUI::Asset::Template->new($self->session, $templateId);
|
||||||
$template->prepare;
|
$template->prepare;
|
||||||
|
|
||||||
$self->{_viewTemplate} = $template;
|
$self->{_viewTemplate} = $template;
|
||||||
}
|
}
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 processStyle ( )
|
||||||
|
|
||||||
|
Gets the parent Gallery's style template
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub processStyle {
|
||||||
|
my $self = shift;
|
||||||
|
return $self->getParent->processStyle(@_);
|
||||||
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 view ( )
|
=head2 view ( )
|
||||||
|
|
||||||
|
|
@ -108,11 +368,186 @@ to be displayed within the page style.
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub view {
|
sub view {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $session = $self->session;
|
my $session = $self->session;
|
||||||
my $var = $self->get;
|
my $var = $self->getTemplateVars;
|
||||||
|
|
||||||
|
$self->appendTemplateVarsFileLoop( $var );
|
||||||
|
|
||||||
return $self->processTemplate($var, undef, $self->{_viewTemplate});
|
return $self->processTemplate($var, undef, $self->{_viewTemplate});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 view_slideshow ( )
|
||||||
|
|
||||||
|
method called by the www_slideshow method. Returns a processed template to be
|
||||||
|
displayed within the page style.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub view_slideshow {
|
||||||
|
my $self = shift;
|
||||||
|
my $session = $self->session;
|
||||||
|
my $var = $self->getTemplateVars;
|
||||||
|
|
||||||
|
$self->appendTemplateVarsFileLoop( $var, { perpage => "all" } );
|
||||||
|
|
||||||
|
return $self->processTemplate($var, $self->getParent->get("templateIdSlideshow"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 view_thumbnails ( )
|
||||||
|
|
||||||
|
method called by the www_thumbnails method. Returns a processed template to be
|
||||||
|
displayed within the page style.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub view_thumbnails {
|
||||||
|
my $self = shift;
|
||||||
|
my $session = $self->session;
|
||||||
|
my $var = $self->getTemplateVars;
|
||||||
|
|
||||||
|
$self->appendTemplateVarsFileLoop( $var, { perpage => "all" } );
|
||||||
|
|
||||||
|
return $self->processTemplate($var, $self->getParent->get("templateIdThumbnails"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 www_addArchive ( )
|
||||||
|
|
||||||
|
Show the form to add an archive of files to this gallery.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub www_addArchive {
|
||||||
|
my $self = shift;
|
||||||
|
|
||||||
|
return $self->session->privilege->insufficient unless $self->canAddFile;
|
||||||
|
|
||||||
|
my $var = $self->getTemplateVars;
|
||||||
|
|
||||||
|
return $self->processStyle(
|
||||||
|
$self->processTemplate($var, $self->getParent->get("templateIdAddArchive"))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 www_addArchiveSave ( )
|
||||||
|
|
||||||
|
Process the form for adding an archive.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub www_addArchiveSave {
|
||||||
|
my $self = shift;
|
||||||
|
|
||||||
|
return $self->session->privilege->insufficient unless $self->canAddfile;
|
||||||
|
|
||||||
|
my $form = $self->session->form;
|
||||||
|
my $properties = {
|
||||||
|
keywords => $form->get("keywords"),
|
||||||
|
friendsOnly => $form->get("friendsOnly"),
|
||||||
|
};
|
||||||
|
|
||||||
|
my $storage = $form->get("archive", "File");
|
||||||
|
my $filename = $storage->getFilePath( $storage->getFiles->[0] );
|
||||||
|
|
||||||
|
$self->addArchive( $filename, $properties );
|
||||||
|
|
||||||
|
return $self->www_view;
|
||||||
|
}
|
||||||
|
|
||||||
|
#-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 www_delete ( )
|
||||||
|
|
||||||
|
Show the form to confirm deleting this album and all files inside of it.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub www_delete {
|
||||||
|
my $self = shift;
|
||||||
|
|
||||||
|
return $self->session->privilege->insufficient unless $self->canEdit;
|
||||||
|
|
||||||
|
my $var = $self->getTemplateVars;
|
||||||
|
$var->{ url_yes } = $self->getUrl("?func=deleteConfirm");
|
||||||
|
|
||||||
|
return $self->processStyle(
|
||||||
|
$self->processTemplate( $var, $self->getParent->get("templateIdDeleteAlbum") )
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 www_deleteConfirm ( )
|
||||||
|
|
||||||
|
Confirm deleting this album and all files inside of it.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub www_deleteConfirm {
|
||||||
|
my $self = shift;
|
||||||
|
|
||||||
|
return $self->session->privilege->insufficient unless $self->canEdit;
|
||||||
|
|
||||||
|
$self->purge;
|
||||||
|
|
||||||
|
return $self->getParent->www_view;
|
||||||
|
}
|
||||||
|
|
||||||
|
#-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 www_slideshow ( )
|
||||||
|
|
||||||
|
Show a slideshow-type view of this album. The slideshow itself is powered by
|
||||||
|
a javascript application in the template.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub www_slideshow {
|
||||||
|
my $self = shift;
|
||||||
|
|
||||||
|
return $self->session->privilege->insufficient unless $self->canView;
|
||||||
|
|
||||||
|
return $self->processStyle( $self->view_slideshow );
|
||||||
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 www_thumbnails ( )
|
||||||
|
|
||||||
|
Show the thumbnails for the album.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub www_thumbnails {
|
||||||
|
my $self = shift;
|
||||||
|
|
||||||
|
return $self->session->privilege->insufficient unless $self->canView;
|
||||||
|
|
||||||
|
return $self->processStyle( $self->view_thumbnails );
|
||||||
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 www_viewRss ( )
|
||||||
|
|
||||||
|
Display an RSS feed for this album.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub www_viewRss {
|
||||||
|
my $self = shift;
|
||||||
|
|
||||||
|
return $self->session->privilege->insufficient unless $self->canView;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
||||||
|
|
@ -123,6 +123,7 @@ checkModule("Weather::Com::Finder","0.5.1");
|
||||||
checkModule("Class::InsideOut","1.06");
|
checkModule("Class::InsideOut","1.06");
|
||||||
checkModule("HTML::TagCloud","0.34");
|
checkModule("HTML::TagCloud","0.34");
|
||||||
checkModule("Image::ExifTool","7.00");
|
checkModule("Image::ExifTool","7.00");
|
||||||
|
checkModule("Archive::Any","0.093");
|
||||||
|
|
||||||
|
|
||||||
###################################
|
###################################
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue