- moved Gallery utility methods to WebGUI::Utility::Gallery
- Added tests for GalleryAlbum RSS - More tests for comments - Test International Macro sprintf as third+ arguments - Add Gallery search limiting by user ID - Remaining i18n for Gallery templates - Fix: Search form now visible in Photo assets Moved a lot of stuff from Photo to GalleryFile
This commit is contained in:
parent
38256af5f6
commit
ab6f4defe3
25 changed files with 1386 additions and 905 deletions
|
|
@ -17,6 +17,8 @@ package WebGUI::Asset::File::GalleryFile;
|
|||
use strict;
|
||||
use base 'WebGUI::Asset::File';
|
||||
|
||||
use Carp qw( croak confess );
|
||||
|
||||
|
||||
|
||||
=head1 NAME
|
||||
|
|
@ -34,6 +36,311 @@ These methods are available from this class
|
|||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 definition ( session, definition )
|
||||
|
||||
Define the properties of all GalleryFile assets.
|
||||
|
||||
=cut
|
||||
|
||||
sub definition {
|
||||
my $class = shift;
|
||||
my $session = shift;
|
||||
my $definition = shift;
|
||||
my $i18n = __PACKAGE__->i18n($session);
|
||||
|
||||
tie my %properties, 'Tie::IxHash', (
|
||||
views => {
|
||||
defaultValue => 0,
|
||||
},
|
||||
friendsOnly => {
|
||||
defaultValue => 0,
|
||||
},
|
||||
rating => {
|
||||
defaultValue => 0,
|
||||
},
|
||||
);
|
||||
|
||||
# UserDefined Fields
|
||||
for my $i (1 .. 5) {
|
||||
$properties{"userDefined".$i} = {
|
||||
defaultValue => undef,
|
||||
};
|
||||
}
|
||||
|
||||
push @{$definition}, {
|
||||
assetName => $i18n->get('assetName'),
|
||||
autoGenerateForms => 0,
|
||||
tableName => 'GalleryFile',
|
||||
className => 'WebGUI::Asset::File::GalleryFile',
|
||||
properties => \%properties,
|
||||
};
|
||||
|
||||
return $class->SUPER::definition($session, $definition);
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 appendTemplateVarsCommentForm ( var [, comment ] )
|
||||
|
||||
Add the template variables necessary for the comment form to the given hash
|
||||
reference. Returns the hash reference for convenience. C<comment> is a hash
|
||||
reference of values to populate the form with.
|
||||
|
||||
=cut
|
||||
|
||||
sub appendTemplateVarsCommentForm {
|
||||
my $self = shift;
|
||||
my $var = shift;
|
||||
my $comment = shift || {};
|
||||
my $session = $self->session;
|
||||
|
||||
# Default comment
|
||||
$comment->{ commentId } ||= "new";
|
||||
|
||||
$var->{ commentForm_start }
|
||||
= WebGUI::Form::formHeader( $session )
|
||||
. WebGUI::Form::hidden( $session, {
|
||||
name => "func",
|
||||
value => "editCommentSave"
|
||||
} )
|
||||
. WebGUI::Form::hidden( $session, {
|
||||
name => "commentId",
|
||||
value => $comment->{ commentId }
|
||||
} )
|
||||
;
|
||||
|
||||
# Add hidden fields for editing a comment
|
||||
if ( $comment->{ commentId } ne "new" ) {
|
||||
$var->{ commentForm_start }
|
||||
.= WebGUI::Form::hidden( $session, {
|
||||
name => "userId",
|
||||
value => $comment->{ userId }
|
||||
} )
|
||||
. WebGUI::Form::hidden( $session, {
|
||||
name => "visitorIp",
|
||||
value => $comment->{ visitorIp }
|
||||
} )
|
||||
. WebGUI::Form::hidden( $session, {
|
||||
name => "creationDate",
|
||||
value => $comment->{ creationDate }
|
||||
} )
|
||||
;
|
||||
}
|
||||
|
||||
$var->{ commentForm_end }
|
||||
= WebGUI::Form::formFooter( $session );
|
||||
|
||||
$var->{ commentForm_bodyText }
|
||||
= WebGUI::Form::HTMLArea( $session, {
|
||||
name => "bodyText",
|
||||
richEditId => $self->getGallery->get("richEditIdComment"),
|
||||
value => $comment->{ bodyText },
|
||||
});
|
||||
|
||||
$var->{ commentForm_submit }
|
||||
= WebGUI::Form::submit( $session, {
|
||||
name => "submit",
|
||||
value => "Save Comment",
|
||||
});
|
||||
|
||||
return $var;
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 canAdd ( )
|
||||
|
||||
Override canAdd to ignore its permissions check. Permissions are handled
|
||||
by the parent Gallery and other permissions methods.
|
||||
|
||||
=cut
|
||||
|
||||
sub canAdd {
|
||||
return 1;
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=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 GalleryFile 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] )
|
||||
|
||||
Returns true if the user can edit this asset. C<userId> is a WebGUI user ID.
|
||||
If no userId is passed, check the current user.
|
||||
|
||||
Users can edit this GalleryFile if they are the owner or if they are able to edit
|
||||
the parent Album asset.
|
||||
|
||||
=cut
|
||||
|
||||
sub canEdit {
|
||||
my $self = shift;
|
||||
my $userId = shift || $self->session->user->userId;
|
||||
my $album = $self->getParent;
|
||||
|
||||
return 1 if $userId eq $self->get("ownerUserId");
|
||||
return $album->canEdit($userId);
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 canView ( [userId] )
|
||||
|
||||
Returns true if the user can view this asset. C<userId> is a WebGUI user ID.
|
||||
If no user is passed, checks the current user.
|
||||
|
||||
Users can view this GalleryFile if they can view the parent asset. If this is a
|
||||
C<friendsOnly> GalleryFile, then they must also be in the owners friends list.
|
||||
|
||||
=cut
|
||||
|
||||
sub canView {
|
||||
my $self = shift;
|
||||
my $userId = shift || $self->session->user->userId;
|
||||
|
||||
my $album = $self->getParent;
|
||||
return 0 unless $album->canView($userId);
|
||||
|
||||
if ($self->isFriendsOnly && $userId != $self->get("ownerUserId") ) {
|
||||
my $owner = WebGUI::User->new( $self->session, $self->get("ownerUserId") );
|
||||
return 0
|
||||
unless WebGUI::Friends->new($self->session, $owner)->isFriend($userId);
|
||||
}
|
||||
|
||||
# Passed all checks
|
||||
return 1;
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 deleteComment ( commentId )
|
||||
|
||||
Delete a comment from this asset. C<id> is the ID of the comment to delete.
|
||||
|
||||
=cut
|
||||
|
||||
sub deleteComment {
|
||||
my $self = shift;
|
||||
my $commentId = shift;
|
||||
|
||||
croak "GalleryFile->deleteComment: No commentId specified."
|
||||
unless $commentId;
|
||||
|
||||
return $self->session->db->write(
|
||||
"DELETE FROM GalleryFile_comment WHERE assetId=? AND commentId=?",
|
||||
[$self->getId, $commentId],
|
||||
);
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 getAutoCommitWorkflowId ( )
|
||||
|
||||
Returns the workflowId of the Gallery's approval workflow.
|
||||
|
||||
=cut
|
||||
|
||||
sub getAutoCommitWorkflowId {
|
||||
my $self = shift;
|
||||
return $self->getGallery->get("workflowIdCommit");
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 getComment ( commentId )
|
||||
|
||||
Get a comment from this asset. C<id> is the ID of the comment to get. Returns
|
||||
a hash reference of comment information.
|
||||
|
||||
=cut
|
||||
|
||||
sub getComment {
|
||||
my $self = shift;
|
||||
my $commentId = shift;
|
||||
|
||||
return $self->session->db->getRow(
|
||||
"GalleryFile_comment", "commentId", $commentId,
|
||||
);
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 getCommentIds ( )
|
||||
|
||||
Get an array reference of comment IDs for this GalleryFile, in chronological order.
|
||||
|
||||
=cut
|
||||
|
||||
sub getCommentIds {
|
||||
my $self = shift;
|
||||
|
||||
return [
|
||||
$self->session->db->buildArray(
|
||||
"SELECT commentId FROM GalleryFile_comment WHERE assetId=?",
|
||||
[$self->getId],
|
||||
)
|
||||
];
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 getCommentPaginator ( )
|
||||
|
||||
Get a WebGUI::Paginator for the comments for this GalleryFile.
|
||||
|
||||
=cut
|
||||
|
||||
sub getCommentPaginator {
|
||||
my $self = shift;
|
||||
my $session = $self->session;
|
||||
|
||||
my $p = WebGUI::Paginator->new($session, $self->getUrl);
|
||||
$p->setDataByQuery(
|
||||
"SELECT * FROM GalleryFile_comment WHERE assetId=? ORDER BY creationDate DESC",
|
||||
undef, undef,
|
||||
[$self->getId],
|
||||
);
|
||||
|
||||
return $p;
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 getGallery ( )
|
||||
|
||||
Gets the Gallery asset this GalleryFile is a member of.
|
||||
|
||||
=cut
|
||||
|
||||
sub getGallery {
|
||||
my $self = shift;
|
||||
my $gallery = $self->getParent->getParent;
|
||||
return $gallery if $gallery->isa("WebGUI::Asset::Wobject::Gallery");
|
||||
return undef;
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 getThumbnailUrl ( )
|
||||
|
|
@ -46,6 +353,7 @@ overridded by your child class.
|
|||
sub getThumbnailUrl {
|
||||
my $self = shift;
|
||||
|
||||
# TODO: Make a "default" thumbnail
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
|
@ -59,14 +367,200 @@ method.
|
|||
|
||||
sub getTemplateVars {
|
||||
my $self = shift;
|
||||
my $session = $self->session;
|
||||
my $var = $self->get;
|
||||
my $owner = WebGUI::User->new( $session, $self->get("ownerUserId") );
|
||||
|
||||
$var->{ fileUrl } = $self->getFileUrl;
|
||||
$var->{ thumbnailUrl } = $self->getThumbnailUrl;
|
||||
|
||||
# Fix 'undef' vars since HTML::Template does inheritence on them
|
||||
for my $key ( qw( synopsis ) ) {
|
||||
unless ( defined $var->{$key} ) {
|
||||
$var->{ $key } = '';
|
||||
}
|
||||
}
|
||||
|
||||
# Add some things from Gallery
|
||||
my $galleryVar = $self->getGallery->getTemplateVars;
|
||||
for my $key ( qw{ url_listFilesForCurrentUser url_search } ) {
|
||||
$var->{ $key } = $galleryVar->{ $key };
|
||||
}
|
||||
|
||||
# Add the search form
|
||||
$self->getGallery->appendTemplateVarsSearchForm( $var );
|
||||
|
||||
$var->{ canComment } = $self->canComment;
|
||||
$var->{ canEdit } = $self->canEdit;
|
||||
$var->{ numberOfComments } = scalar @{ $self->getCommentIds };
|
||||
$var->{ ownerUsername } = $owner->profileField("alias") || $owner->username;
|
||||
$var->{ url } = $self->getUrl;
|
||||
$var->{ url_addArchive } = $self->getParent->getUrl('func=addArchive'),
|
||||
$var->{ url_delete } = $self->getUrl('func=delete');
|
||||
$var->{ url_demote } = $self->getUrl('func=demote');
|
||||
$var->{ url_edit } = $self->getUrl('func=edit');
|
||||
$var->{ url_gallery } = $self->getGallery->getUrl;
|
||||
$var->{ url_makeShortcut } = $self->getUrl('func=makeShortcut');
|
||||
$var->{ url_listFilesForOwner }
|
||||
= $self->getGallery->getUrl('func=listFilesForUser;userId=' . $self->get("ownerUserId"));
|
||||
$var->{ url_promote } = $self->getUrl('func=promote');
|
||||
|
||||
return $var;
|
||||
}
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 i18n ( session )
|
||||
|
||||
Get the i18n object for this class. This sub must not be inherited, so always
|
||||
call it using C<__PACKAGE__>, not C<$self>.
|
||||
|
||||
=cut
|
||||
|
||||
sub i18n {
|
||||
my $self = shift;
|
||||
my $session = shift;
|
||||
# TODO: Make a migration script to move the appropriate parts from
|
||||
# Asset_Photo to Asset_GalleryFile
|
||||
return WebGUI::International->new( $session, "Asset_Photo" );
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 isFriendsOnly ( )
|
||||
|
||||
Returns true if this GalleryFile is friends only. Returns false otherwise.
|
||||
|
||||
=cut
|
||||
|
||||
sub isFriendsOnly {
|
||||
my $self = shift;
|
||||
return $self->get("friendsOnly");
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 makeShortcut ( parentId [, overrides ] )
|
||||
|
||||
Make a shortcut to this asset under the specified parent, optionally adding
|
||||
the specified hash reference of C<overrides>.
|
||||
|
||||
Returns the created shortcut asset.
|
||||
|
||||
=cut
|
||||
|
||||
sub makeShortcut {
|
||||
my $self = shift;
|
||||
my $parentId = shift;
|
||||
my $overrides = shift;
|
||||
my $session = $self->session;
|
||||
|
||||
croak "GalleryFile->makeShortcut: parentId must be defined"
|
||||
unless $parentId;
|
||||
|
||||
my $parent = WebGUI::Asset->newByDynamicClass($session, $parentId)
|
||||
|| croak "GalleryFile->makeShortcut: Could not instanciate asset '$parentId'";
|
||||
|
||||
my $shortcut
|
||||
= $parent->addChild({
|
||||
className => "WebGUI::Asset::Shortcut",
|
||||
shortcutToAssetId => $self->getId,
|
||||
});
|
||||
|
||||
if ($overrides) {
|
||||
$shortcut->setOverride( $overrides );
|
||||
}
|
||||
|
||||
return $shortcut;
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 prepareView ( )
|
||||
|
||||
Prepare the template to be used for the C<view> method.
|
||||
|
||||
=cut
|
||||
|
||||
sub prepareView {
|
||||
my $self = shift;
|
||||
$self->SUPER::prepareView();
|
||||
|
||||
my $template
|
||||
= WebGUI::Asset::Template->new($self->session, $self->getGallery->get("templateIdViewFile"));
|
||||
$template->prepare;
|
||||
|
||||
$self->{_viewTemplate} = $template;
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 processCommentEditForm ( )
|
||||
|
||||
Process the Comment Add / Edit Form. Returns a hash reference of properties
|
||||
that can be passed to C<setComment>.
|
||||
|
||||
Will die with an i18n-friendly error message if something is missing or
|
||||
wrong.
|
||||
|
||||
=cut
|
||||
|
||||
sub processCommentEditForm {
|
||||
my $self = shift;
|
||||
my $session = $self->session;
|
||||
my $form = $self->session->form;
|
||||
my $now = WebGUI::DateTime->new( $session, time );
|
||||
my $i18n = __PACKAGE__->i18n( $session );
|
||||
|
||||
# Using die here to suppress line number and file path info
|
||||
die $i18n->get("commentForm error no commentId") . "\n"
|
||||
unless $form->get("commentId");
|
||||
die $i18n->get("commentForm error no bodyText") . "\n"
|
||||
unless $form->get("bodyText");
|
||||
|
||||
my $new = $form->get('commentId') eq "new"
|
||||
? 1
|
||||
: 0
|
||||
;
|
||||
|
||||
my $visitorIp = $session->user->userId eq "1"
|
||||
? $session->env->get("REMOTE_ADDR")
|
||||
: undef
|
||||
;
|
||||
|
||||
my $properties = {
|
||||
commentId => $form->get("commentId"),
|
||||
assetId => $self->getId,
|
||||
bodyText => $form->get("bodyText"),
|
||||
creationDate => ( $new ? $now->toDatabaseDate : $form->get("creationDate") ),
|
||||
userId => ( $new ? $session->user->userId : $form->get("userId") ),
|
||||
visitorIp => ( $new ? $visitorIp : $form->get("visitorIp") ),
|
||||
};
|
||||
|
||||
return $properties;
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 processPropertiesFromFormPost ( )
|
||||
|
||||
|
||||
=cut
|
||||
|
||||
sub processPropertiesFromFormPost {
|
||||
my $self = shift;
|
||||
my $form = $self->session->form;
|
||||
my $errors = $self->SUPER::processPropertiesFromFormPost || [];
|
||||
|
||||
# Return if errors
|
||||
return $errors if @$errors;
|
||||
|
||||
### Passes all checks
|
||||
|
||||
$self->requestAutoCommit;
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 processStyle ( html )
|
||||
|
|
@ -82,6 +576,186 @@ sub processStyle {
|
|||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 purge ( )
|
||||
|
||||
Purge the asset. Remove all comments on the GalleryFile.
|
||||
|
||||
=cut
|
||||
|
||||
sub purge {
|
||||
my $self = shift;
|
||||
|
||||
for my $commentId ( @{ $self->getCommentIds } ) {
|
||||
$self->deleteComment( $commentId );
|
||||
}
|
||||
|
||||
return $self->SUPER::purge;
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 setComment ( properties )
|
||||
|
||||
Set a comment. C<properties> is a hash reference of comment information with
|
||||
the following keys:
|
||||
|
||||
assetId - The assetId of the asset this comment is for
|
||||
commentId - The ID of the comment. If "new", will make a new comment.
|
||||
bodyText - The body of the comment
|
||||
userId - The userId of the user who made the comment
|
||||
visitorIp - If the user was a visitor, the IP address of the user
|
||||
creationDate - A MySQL-formatted date/time when the comment was posted
|
||||
|
||||
=cut
|
||||
|
||||
sub setComment {
|
||||
my $self = shift;
|
||||
my $properties = shift;
|
||||
|
||||
croak "GalleryFile->setComment: properties must be a hash reference"
|
||||
unless $properties && ref $properties eq "HASH";
|
||||
croak "GalleryFile->setComment: commentId must be defined"
|
||||
unless $properties->{ commentId };
|
||||
croak "GalleryFile->setComment: properties must contain a bodyText key"
|
||||
unless $properties->{ bodyText };
|
||||
|
||||
$properties->{ creationDate } ||= WebGUI::DateTime->new($self->session, time)->toDatabase;
|
||||
$properties->{ assetId } = $self->getId;
|
||||
|
||||
return $self->session->db->setRow(
|
||||
"GalleryFile_comment", "commentId",
|
||||
$properties,
|
||||
);
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 view ( )
|
||||
|
||||
method called by the container www_view method.
|
||||
|
||||
=cut
|
||||
|
||||
sub view {
|
||||
my $self = shift;
|
||||
my $session = $self->session;
|
||||
my $var = $self->getTemplateVars;
|
||||
|
||||
$self->appendTemplateVarsCommentForm( $var );
|
||||
|
||||
# Keywords
|
||||
my $k = WebGUI::Keyword->new( $session );
|
||||
my $keywords = $k->getKeywordsForAsset( { asArrayRef => 1, asset => $self } );
|
||||
for my $keyword ( @{ $keywords } ) {
|
||||
push @{ $var->{keywords} }, {
|
||||
keyword => $keyword,
|
||||
url_searchKeyword
|
||||
=> $self->getGallery->getUrl(
|
||||
"func=search;submit=1;keywords=" . uri_escape($keyword)
|
||||
),
|
||||
url_searchKeywordUser
|
||||
=> $self->getGallery->getUrl(
|
||||
"func=search;submit=1;"
|
||||
. "userId=" . $self->get("ownerUserId") . ';'
|
||||
. 'keywords=' . uri_escape( $keyword )
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
# Comments
|
||||
my $p = $self->getCommentPaginator;
|
||||
for my $comment ( @{ $p->getPageData } ) {
|
||||
$comment->{ url_deleteComment }
|
||||
= $self->getUrl('func=deleteComment;commentId=' . $comment->{commentId} );
|
||||
$comment->{ url_editComment }
|
||||
= $self->getUrl('func=editComment;commentId=' . $comment->{commentId} );
|
||||
|
||||
my $user = WebGUI::User->new( $session, $comment->{userId} );
|
||||
$comment->{ username } = $user->username;
|
||||
|
||||
my $dt = WebGUI::DateTime->new( $session, $comment->{ creationDate } );
|
||||
$comment->{ creationDate } = $dt->toUserTimeZone;
|
||||
|
||||
push @{ $var->{commentLoop} }, $comment;
|
||||
}
|
||||
$var->{ commentLoop_pageBar } = $p->getBarAdvanced;
|
||||
|
||||
return $self->processTemplate($var, undef, $self->{_viewTemplate});
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 www_delete ( )
|
||||
|
||||
Show the page to confirm the deletion of this GalleryFile. Show a list of albums
|
||||
this GalleryFile exists in.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_delete {
|
||||
my $self = shift;
|
||||
my $session = $self->session;
|
||||
|
||||
return $self->session->privilege->insufficient unless $self->canEdit;
|
||||
|
||||
my $var = $self->getTemplateVars;
|
||||
$var->{ url_yes } = $self->getUrl("func=deleteConfirm");
|
||||
|
||||
# TODO Get albums with shortcuts to this asset
|
||||
|
||||
return $self->processStyle(
|
||||
$self->processTemplate( $var, $self->getGallery->get("templateIdDeleteFile") )
|
||||
);
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 www_deleteComment ( )
|
||||
|
||||
Delete a comment immediately. Only those who can edit this GalleryFile can delete
|
||||
comments on it.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_deleteComment {
|
||||
my $self = shift;
|
||||
my $session = $self->session;
|
||||
|
||||
return $session->privilege->insufficient unless $self->canEdit;
|
||||
|
||||
my $i18n = __PACKAGE__->i18n( $session );
|
||||
my $commentId = $session->form->get('commentId');
|
||||
|
||||
$self->deleteComment( $commentId );
|
||||
|
||||
return $self->www_view;
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 www_deleteConfirm ( )
|
||||
|
||||
Confirm the deletion of this GalleryFile. Show a message and a link back to the
|
||||
album.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_deleteConfirm {
|
||||
my $self = shift;
|
||||
|
||||
return $self->session->privilege->insufficient unless $self->canEdit;
|
||||
|
||||
my $i18n = __PACKAGE__->i18n( $self->session );
|
||||
|
||||
$self->purge;
|
||||
|
||||
return $self->processStyle(
|
||||
sprintf $i18n->get("delete message"), $self->getParent->getUrl,
|
||||
);
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 www_demote
|
||||
|
||||
Override the default demote page to send the user back to the GalleryAlbum
|
||||
|
|
@ -101,6 +775,151 @@ sub www_demote {
|
|||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 www_editComment ( params )
|
||||
|
||||
Form to edit a comment. C<params> is a hash reference of parameters
|
||||
with the following keys:
|
||||
|
||||
errors = An array reference of errors to show the user.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_editComment {
|
||||
my $self = shift;
|
||||
my $params = shift;
|
||||
my $session = $self->session;
|
||||
|
||||
return $session->privilege->insufficient unless $self->canEdit;
|
||||
|
||||
my $var = $self->getTemplateVars;
|
||||
|
||||
if ( $params->{ errors } ) {
|
||||
$var->{ errors } = [ map { { "error" => $_ } } @{ $params->{errors} } ];
|
||||
}
|
||||
|
||||
my $commentId = $session->form->get( "commentId" );
|
||||
my $comment = $commentId ne "new"
|
||||
? $self->getComment( $commentId )
|
||||
: {}
|
||||
;
|
||||
$self->appendTemplateVarsCommentForm( $var, $comment );
|
||||
|
||||
$var->{ isNew } = $commentId eq "new";
|
||||
|
||||
return $self->processStyle(
|
||||
$self->processTemplate( $var, $self->getGallery->get("templateIdEditComment") )
|
||||
);
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 www_editCommentSave ( )
|
||||
|
||||
Save a comment being edited
|
||||
|
||||
=cut
|
||||
|
||||
sub www_editCommentSave {
|
||||
my $self = shift;
|
||||
my $session = $self->session;
|
||||
|
||||
return $session->privilege->insufficient unless $self->canEdit;
|
||||
|
||||
my $i18n = __PACKAGE__->i18n( $session );
|
||||
|
||||
my $comment = eval { $self->processCommentEditForm };
|
||||
if ( $@ ) {
|
||||
return $self->www_editComment( { errors => [ $@ ] } );
|
||||
}
|
||||
|
||||
# setComment changes commentId, so keep track if we're adding a new comment
|
||||
my $isNew = $comment->{commentId} eq "new";
|
||||
|
||||
$self->setComment( $comment );
|
||||
|
||||
# Return different message for adding and editing
|
||||
if ( $isNew ) {
|
||||
return $self->processStyle(
|
||||
sprintf $i18n->get('comment message'), $self->getUrl
|
||||
);
|
||||
}
|
||||
else {
|
||||
return $self->processStyle(
|
||||
sprintf $i18n->get('editCommentSave message'), $self->getUrl
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 www_makeShortcut ( )
|
||||
|
||||
Display the form to make a shortcut.
|
||||
|
||||
This page is only available to those who can edit this GalleryFile.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_makeShortcut {
|
||||
my $self = shift;
|
||||
my $session = $self->session;
|
||||
|
||||
return $self->session->privilege->insufficient unless $self->canEdit;
|
||||
|
||||
# Create the form to make a shortcut
|
||||
my $var = $self->getTemplateVars;
|
||||
|
||||
$var->{ form_start }
|
||||
= WebGUI::Form::formHeader( $session )
|
||||
. WebGUI::Form::hidden( $session, { name => "func", value => "makeShortcutSave" });
|
||||
$var->{ form_end }
|
||||
= WebGUI::Form::formFooter( $session );
|
||||
|
||||
# Albums under this Gallery
|
||||
my $albums = $self->getGallery->getAlbumIds;
|
||||
my %albumOptions;
|
||||
for my $assetId ( @$albums ) {
|
||||
my $asset = WebGUI::Asset->newByDynamicClass($session, $assetId);
|
||||
if ($asset->canAddFile) {
|
||||
$albumOptions{ $assetId } = $asset->get("title");
|
||||
}
|
||||
}
|
||||
$var->{ form_parentId }
|
||||
= WebGUI::Form::selectBox( $session, {
|
||||
name => "parentId",
|
||||
value => $self->getParent->getId,
|
||||
options => \%albumOptions,
|
||||
});
|
||||
|
||||
return $self->processStyle(
|
||||
$self->processTemplate($var, $self->getGallery->get("templateIdMakeShortcut"))
|
||||
);
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 www_makeShortcutSave ( )
|
||||
|
||||
Make the shortcut.
|
||||
|
||||
This page is only available to those who can edit this GalleryFile.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_makeShortcutSave {
|
||||
my $self = shift;
|
||||
my $form = $self->session->form;
|
||||
|
||||
return $self->session->privilege->insufficient unless $self->canEdit;
|
||||
|
||||
my $parentId = $form->get('parentId');
|
||||
my $shortcut = $self->makeShortcut( $parentId );
|
||||
|
||||
return $shortcut->www_view;
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 www_promote
|
||||
|
||||
Override the default promote page to send the user back to the GalleryAlbum
|
||||
|
|
@ -122,12 +941,19 @@ sub www_promote {
|
|||
|
||||
=head2 www_view ( )
|
||||
|
||||
Show the default view, with content chunking.
|
||||
Shows the output of L<view> inside of the style provided by the gallery this
|
||||
GalleryFile is in.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_view {
|
||||
my $self = shift;
|
||||
my $self = shift;
|
||||
|
||||
return $self->session->privilege->insufficient unless $self->canView;
|
||||
|
||||
# Add to views
|
||||
$self->update({ views => $self->get('views') + 1 });
|
||||
|
||||
$self->session->http->setLastModified($self->getContentLastModified);
|
||||
$self->session->http->sendHeader;
|
||||
$self->prepareView;
|
||||
|
|
@ -139,4 +965,5 @@ sub www_view {
|
|||
return "chunked";
|
||||
}
|
||||
|
||||
|
||||
1; # Who knew the truth would be so obvious?
|
||||
|
|
|
|||
|
|
@ -73,37 +73,20 @@ sub definition {
|
|||
my $i18n = __PACKAGE__->i18n($session);
|
||||
|
||||
tie my %properties, 'Tie::IxHash', (
|
||||
views => {
|
||||
defaultValue => 0,
|
||||
},
|
||||
exifData => {
|
||||
defaultValue => undef,
|
||||
},
|
||||
friendsOnly => {
|
||||
defaultValue => 0,
|
||||
},
|
||||
location => {
|
||||
defaultValue => undef,
|
||||
},
|
||||
rating => {
|
||||
defaultValue => 0,
|
||||
},
|
||||
);
|
||||
|
||||
# UserDefined Fields
|
||||
for my $i (1 .. 5) {
|
||||
$properties{"userDefined".$i} = {
|
||||
defaultValue => undef,
|
||||
};
|
||||
}
|
||||
|
||||
push @{$definition}, {
|
||||
assetName => $i18n->get('assetName'),
|
||||
autoGenerateForms => 0,
|
||||
icon => 'photo.gif',
|
||||
tableName => 'Photo',
|
||||
className => 'WebGUI::Asset::File::GalleryFile::Photo',
|
||||
i18n => 'Asset_Photo',
|
||||
properties => \%properties,
|
||||
};
|
||||
|
||||
|
|
@ -112,74 +95,6 @@ sub definition {
|
|||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 appendTemplateVarsCommentForm ( var [, comment ] )
|
||||
|
||||
Add the template variables necessary for the comment form to the given hash
|
||||
reference. Returns the hash reference for convenience. C<comment> is a hash
|
||||
reference of values to populate the form with.
|
||||
|
||||
=cut
|
||||
|
||||
sub appendTemplateVarsCommentForm {
|
||||
my $self = shift;
|
||||
my $var = shift;
|
||||
my $comment = shift || {};
|
||||
my $session = $self->session;
|
||||
|
||||
# Default comment
|
||||
$comment->{ commentId } ||= "new";
|
||||
|
||||
$var->{ commentForm_start }
|
||||
= WebGUI::Form::formHeader( $session )
|
||||
. WebGUI::Form::hidden( $session, {
|
||||
name => "func",
|
||||
value => "editCommentSave"
|
||||
} )
|
||||
. WebGUI::Form::hidden( $session, {
|
||||
name => "commentId",
|
||||
value => $comment->{ commentId }
|
||||
} )
|
||||
;
|
||||
|
||||
# Add hidden fields for editing a comment
|
||||
if ( $comment->{ commentId } ne "new" ) {
|
||||
$var->{ commentForm_start }
|
||||
.= WebGUI::Form::hidden( $session, {
|
||||
name => "userId",
|
||||
value => $comment->{ userId }
|
||||
} )
|
||||
. WebGUI::Form::hidden( $session, {
|
||||
name => "visitorIp",
|
||||
value => $comment->{ visitorIp }
|
||||
} )
|
||||
. WebGUI::Form::hidden( $session, {
|
||||
name => "creationDate",
|
||||
value => $comment->{ creationDate }
|
||||
} )
|
||||
;
|
||||
}
|
||||
|
||||
$var->{ commentForm_end }
|
||||
= WebGUI::Form::formFooter( $session );
|
||||
|
||||
$var->{ commentForm_bodyText }
|
||||
= WebGUI::Form::HTMLArea( $session, {
|
||||
name => "bodyText",
|
||||
richEditId => $self->getGallery->get("richEditIdComment"),
|
||||
value => $comment->{ bodyText },
|
||||
});
|
||||
|
||||
$var->{ commentForm_submit }
|
||||
= WebGUI::Form::submit( $session, {
|
||||
name => "submit",
|
||||
value => "Save Comment",
|
||||
});
|
||||
|
||||
return $var;
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 applyConstraints ( options )
|
||||
|
||||
Apply the constraints to the original file. Called automatically by C<setFile>
|
||||
|
|
@ -211,112 +126,6 @@ sub applyConstraints {
|
|||
$self->updateExifDataFromFile;
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 canAdd ( )
|
||||
|
||||
Override canAdd to ignore its permissions check. Permissions are handled
|
||||
by the parent Gallery and other permissions methods.
|
||||
|
||||
=cut
|
||||
|
||||
sub canAdd {
|
||||
return 1;
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=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] )
|
||||
|
||||
Returns true if the user can edit this asset. C<userId> is a WebGUI user ID.
|
||||
If no userId is passed, check the current user.
|
||||
|
||||
Users can edit this Photo if they are the owner or if they are able to edit
|
||||
the parent Album asset.
|
||||
|
||||
=cut
|
||||
|
||||
sub canEdit {
|
||||
my $self = shift;
|
||||
my $userId = shift || $self->session->user->userId;
|
||||
my $album = $self->getParent;
|
||||
|
||||
return 1 if $userId eq $self->get("ownerUserId");
|
||||
return $album->canEdit($userId);
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 canView ( [userId] )
|
||||
|
||||
Returns true if the user can view this asset. C<userId> is a WebGUI user ID.
|
||||
If no user is passed, checks the current user.
|
||||
|
||||
Users can view this photo if they can view the parent asset. If this is a
|
||||
C<friendsOnly> photo, then they must also be in the owners friends list.
|
||||
|
||||
=cut
|
||||
|
||||
sub canView {
|
||||
my $self = shift;
|
||||
my $userId = shift || $self->session->user->userId;
|
||||
|
||||
my $album = $self->getParent;
|
||||
return 0 unless $album->canView($userId);
|
||||
|
||||
if ($self->isFriendsOnly && $userId != $self->get("ownerUserId") ) {
|
||||
my $owner = WebGUI::User->new( $self->session, $self->get("ownerUserId") );
|
||||
return 0
|
||||
unless WebGUI::Friends->new($self->session, $owner)->isFriend($userId);
|
||||
}
|
||||
|
||||
# Passed all checks
|
||||
return 1;
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 deleteComment ( commentId )
|
||||
|
||||
Delete a comment from this asset. C<id> is the ID of the comment to delete.
|
||||
|
||||
=cut
|
||||
|
||||
sub deleteComment {
|
||||
my $self = shift;
|
||||
my $commentId = shift;
|
||||
|
||||
croak "Photo->deleteComment: No commentId specified."
|
||||
unless $commentId;
|
||||
|
||||
return $self->session->db->write(
|
||||
"DELETE FROM Photo_comment WHERE assetId=? AND commentId=?",
|
||||
[$self->getId, $commentId],
|
||||
);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 generateThumbnail ( )
|
||||
|
|
@ -336,78 +145,6 @@ sub generateThumbnail {
|
|||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 getAutoCommitWorkflowId ( )
|
||||
|
||||
Returns the workflowId of the Gallery's approval workflow.
|
||||
|
||||
=cut
|
||||
|
||||
sub getAutoCommitWorkflowId {
|
||||
my $self = shift;
|
||||
return $self->getGallery->get("workflowIdCommit");
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 getComment ( commentId )
|
||||
|
||||
Get a comment from this asset. C<id> is the ID of the comment to get. Returns
|
||||
a hash reference of comment information.
|
||||
|
||||
=cut
|
||||
|
||||
sub getComment {
|
||||
my $self = shift;
|
||||
my $commentId = shift;
|
||||
|
||||
return $self->session->db->getRow(
|
||||
"Photo_comment", "commentId", $commentId,
|
||||
);
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 getCommentIds ( )
|
||||
|
||||
Get an array reference of comment IDs for this Photo, in chronological order.
|
||||
|
||||
=cut
|
||||
|
||||
sub getCommentIds {
|
||||
my $self = shift;
|
||||
|
||||
return [
|
||||
$self->session->db->buildArray(
|
||||
"SELECT commentId FROM Photo_comment WHERE assetId=?",
|
||||
[$self->getId],
|
||||
)
|
||||
];
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 getCommentPaginator ( )
|
||||
|
||||
Get a WebGUI::Paginator for the comments for this Photo.
|
||||
|
||||
=cut
|
||||
|
||||
sub getCommentPaginator {
|
||||
my $self = shift;
|
||||
my $session = $self->session;
|
||||
|
||||
my $p = WebGUI::Paginator->new($session, $self->getUrl);
|
||||
$p->setDataByQuery(
|
||||
"SELECT * FROM Photo_comment WHERE assetId=? ORDER BY creationDate DESC",
|
||||
undef, undef,
|
||||
[$self->getId],
|
||||
);
|
||||
|
||||
return $p;
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 getDownloadFileUrl ( resolution )
|
||||
|
||||
Get the absolute URL to download the requested resolution. Will croak if the
|
||||
|
|
@ -424,7 +161,7 @@ sub getDownloadFileUrl {
|
|||
croak "Photo->getDownloadFileUrl: resolution doesn't exist for this Photo"
|
||||
unless grep /$resolution/, @{ $self->getResolutions };
|
||||
|
||||
return $self->getStorageLocation->getFileUrl( $resolution . ".jpg" );
|
||||
return $self->getStorageLocation->getUrl( $resolution . ".jpg" );
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
|
@ -444,21 +181,6 @@ sub getExifData {
|
|||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 getGallery ( )
|
||||
|
||||
Gets the Gallery asset this Photo is a member of.
|
||||
|
||||
=cut
|
||||
|
||||
sub getGallery {
|
||||
my $self = shift;
|
||||
my $gallery = $self->getParent->getParent;
|
||||
return $gallery if $gallery->isa("WebGUI::Asset::Wobject::Gallery");
|
||||
return undef;
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 getResolutions ( )
|
||||
|
||||
Get an array reference of download resolutions that exist for this image.
|
||||
|
|
@ -471,7 +193,7 @@ sub getResolutions {
|
|||
my $storage = $self->getStorageLocation;
|
||||
|
||||
# Return a list not including the web view image.
|
||||
return grep { $_ ne $self->get("filename") } @{ $storage->getFiles };
|
||||
return [ grep { $_ ne $self->get("filename") } @{ $storage->getFiles } ];
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
|
@ -499,32 +221,9 @@ sub getTemplateVars {
|
|||
my $self = shift;
|
||||
my $session = $self->session;
|
||||
my $var = $self->SUPER::getTemplateVars;
|
||||
my $owner = WebGUI::User->new( $session, $self->get("ownerUserId") );
|
||||
|
||||
# Fix 'undef' vars since HTML::Template does inheritence on them
|
||||
for my $key ( qw( synopsis ) ) {
|
||||
unless ( defined $var->{$key} ) {
|
||||
$var->{ $key } = '';
|
||||
}
|
||||
}
|
||||
|
||||
$var->{ canComment } = $self->canComment;
|
||||
$var->{ canEdit } = $self->canEdit;
|
||||
$var->{ numberOfComments } = scalar @{ $self->getCommentIds };
|
||||
$var->{ ownerUsername } = $owner->username;
|
||||
$var->{ url } = $self->getUrl;
|
||||
$var->{ url_addArchive } = $self->getParent->getUrl('func=addArchive'),
|
||||
$var->{ url_delete } = $self->getUrl('func=delete');
|
||||
$var->{ url_demote } = $self->getUrl('func=demote');
|
||||
$var->{ url_edit } = $self->getUrl('func=edit');
|
||||
$var->{ url_gallery } = $self->getGallery->getUrl;
|
||||
$var->{ url_makeShortcut } = $self->getUrl('func=makeShortcut');
|
||||
$var->{ url_listFilesForOwner }
|
||||
= $self->getGallery->getUrl('func=listFilesForUser;userId=' . $self->get("ownerUserId"));
|
||||
$var->{ url_promote } = $self->getUrl('func=promote');
|
||||
|
||||
### Download resolutions
|
||||
for my $resolution ( $self->getResolutions ) {
|
||||
for my $resolution ( @{ $self->getResolutions } ) {
|
||||
push @{ $var->{ resolutions_loop } }, {
|
||||
url_download => $self->getStorageLocation->getPathFrag($resolution)
|
||||
};
|
||||
|
|
@ -581,19 +280,6 @@ sub i18n {
|
|||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 isFriendsOnly ( )
|
||||
|
||||
Returns true if this Photo is friends only. Returns false otherwise.
|
||||
|
||||
=cut
|
||||
|
||||
sub isFriendsOnly {
|
||||
my $self = shift;
|
||||
return $self->get("friendsOnly");
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 makeResolutions ( [resolutions] )
|
||||
|
||||
Create the specified resolutions for this Photo. If resolutions is not
|
||||
|
|
@ -630,182 +316,6 @@ sub makeResolutions {
|
|||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 makeShortcut ( parentId [, overrides ] )
|
||||
|
||||
Make a shortcut to this asset under the specified parent, optionally adding
|
||||
the specified hash reference of C<overrides>.
|
||||
|
||||
Returns the created shortcut asset.
|
||||
|
||||
=cut
|
||||
|
||||
sub makeShortcut {
|
||||
my $self = shift;
|
||||
my $parentId = shift;
|
||||
my $overrides = shift;
|
||||
my $session = $self->session;
|
||||
|
||||
croak "Photo->makeShortcut: parentId must be defined"
|
||||
unless $parentId;
|
||||
|
||||
my $parent = WebGUI::Asset->newByDynamicClass($session, $parentId)
|
||||
|| croak "Photo->makeShortcut: Could not instanciate asset '$parentId'";
|
||||
|
||||
my $shortcut
|
||||
= $parent->addChild({
|
||||
className => "WebGUI::Asset::Shortcut",
|
||||
shortcutToAssetId => $self->getId,
|
||||
});
|
||||
|
||||
if ($overrides) {
|
||||
$shortcut->setOverride( $overrides );
|
||||
}
|
||||
|
||||
return $shortcut;
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 prepareView ( )
|
||||
|
||||
Prepare the template to be used for the C<view> method.
|
||||
|
||||
=cut
|
||||
|
||||
sub prepareView {
|
||||
my $self = shift;
|
||||
$self->SUPER::prepareView();
|
||||
|
||||
my $template
|
||||
= WebGUI::Asset::Template->new($self->session, $self->getGallery->get("templateIdViewFile"));
|
||||
$template->prepare;
|
||||
|
||||
$self->{_viewTemplate} = $template;
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 processCommentEditForm ( )
|
||||
|
||||
Process the Comment Add / Edit Form. Returns a hash reference of properties
|
||||
that can be passed to C<setComment>.
|
||||
|
||||
Will die with an i18n-friendly error message if something is missing or
|
||||
wrong.
|
||||
|
||||
=cut
|
||||
|
||||
sub processCommentEditForm {
|
||||
my $self = shift;
|
||||
my $session = $self->session;
|
||||
my $form = $self->session->form;
|
||||
my $now = WebGUI::DateTime->new( $session, time );
|
||||
my $i18n = __PACKAGE__->i18n( $session );
|
||||
|
||||
# Using die here to suppress line number and file path info
|
||||
die $i18n->get("commentForm error no commentId") . "\n"
|
||||
unless $form->get("commentId");
|
||||
die $i18n->get("commentForm error no bodyText") . "\n"
|
||||
unless $form->get("bodyText");
|
||||
|
||||
my $new = $form->get('commentId') eq "new"
|
||||
? 1
|
||||
: 0
|
||||
;
|
||||
|
||||
my $visitorIp = $session->user->userId eq "1"
|
||||
? $session->env->get("REMOTE_ADDR")
|
||||
: undef
|
||||
;
|
||||
|
||||
my $properties = {
|
||||
commentId => $form->get("commentId"),
|
||||
assetId => $self->getId,
|
||||
bodyText => $form->get("bodyText"),
|
||||
creationDate => ( $new ? $now->toDatabaseDate : $form->get("creationDate") ),
|
||||
userId => ( $new ? $session->user->userId : $form->get("userId") ),
|
||||
visitorIp => ( $new ? $visitorIp : $form->get("visitorIp") ),
|
||||
};
|
||||
|
||||
return $properties;
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 processPropertiesFromFormPost ( )
|
||||
|
||||
|
||||
=cut
|
||||
|
||||
sub processPropertiesFromFormPost {
|
||||
my $self = shift;
|
||||
my $form = $self->session->form;
|
||||
my $errors = $self->SUPER::processPropertiesFromFormPost || [];
|
||||
|
||||
# Return if errors
|
||||
return $errors if @$errors;
|
||||
|
||||
### Passes all checks
|
||||
|
||||
$self->requestAutoCommit;
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 purge ( )
|
||||
|
||||
Purge the asset. Remove all comments on the photo.
|
||||
|
||||
=cut
|
||||
|
||||
sub purge {
|
||||
my $self = shift;
|
||||
|
||||
for my $commentId ( @{ $self->getCommentIds } ) {
|
||||
$self->deleteComment( $commentId );
|
||||
}
|
||||
|
||||
return $self->SUPER::purge;
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 setComment ( properties )
|
||||
|
||||
Set a comment. C<properties> is a hash reference of comment information with
|
||||
the following keys:
|
||||
|
||||
assetId - The assetId of the asset this comment is for
|
||||
commentId - The ID of the comment. If "new", will make a new comment.
|
||||
bodyText - The body of the comment
|
||||
userId - The userId of the user who made the comment
|
||||
visitorIp - If the user was a visitor, the IP address of the user
|
||||
creationDate - A MySQL-formatted date/time when the comment was posted
|
||||
|
||||
=cut
|
||||
|
||||
sub setComment {
|
||||
my $self = shift;
|
||||
my $properties = shift;
|
||||
|
||||
croak "Photo->setComment: properties must be a hash reference"
|
||||
unless $properties && ref $properties eq "HASH";
|
||||
croak "Photo->setComment: commentId must be defined"
|
||||
unless $properties->{ commentId };
|
||||
croak "Photo->setComment: properties must contain a bodyText key"
|
||||
unless $properties->{ bodyText };
|
||||
|
||||
$properties->{ creationDate } ||= WebGUI::DateTime->new($self->session, time)->toDatabase;
|
||||
$properties->{ assetId } = $self->getId;
|
||||
|
||||
return $self->session->db->setRow(
|
||||
"Photo_comment", "commentId",
|
||||
$properties,
|
||||
);
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 setFile ( filename )
|
||||
|
||||
Extend the superclass setFile to automatically generate thumbnails.
|
||||
|
|
@ -848,124 +358,6 @@ sub updateExifDataFromFile {
|
|||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 view ( )
|
||||
|
||||
method called by the container www_view method.
|
||||
|
||||
=cut
|
||||
|
||||
sub view {
|
||||
my $self = shift;
|
||||
my $session = $self->session;
|
||||
my $var = $self->getTemplateVars;
|
||||
|
||||
$self->appendTemplateVarsCommentForm( $var );
|
||||
|
||||
# Keywords
|
||||
my $k = WebGUI::Keyword->new( $session );
|
||||
my $keywords = $k->getKeywordsForAsset( { asArrayRef => 1, asset => $self } );
|
||||
for my $keyword ( @{ $keywords } ) {
|
||||
push @{ $var->{keywords} }, {
|
||||
url_searchKeyword
|
||||
=> $self->getGallery->getUrl("func=search;submit=1;keywords=" . uri_escape($keyword) ),
|
||||
keyword => $keyword,
|
||||
};
|
||||
}
|
||||
|
||||
# Comments
|
||||
my $p = $self->getCommentPaginator;
|
||||
for my $comment ( @{ $p->getPageData } ) {
|
||||
$comment->{ url_deleteComment }
|
||||
= $self->getUrl('func=deleteComment;commentId=' . $comment->{commentId} );
|
||||
$comment->{ url_editComment }
|
||||
= $self->getUrl('func=editComment;commentId=' . $comment->{commentId} );
|
||||
|
||||
my $user = WebGUI::User->new( $session, $comment->{userId} );
|
||||
$comment->{ username } = $user->username;
|
||||
|
||||
my $dt = WebGUI::DateTime->new( $session, $comment->{ creationDate } );
|
||||
$comment->{ creationDate } = $dt->toUserTimeZone;
|
||||
|
||||
push @{ $var->{commentLoop} }, $comment;
|
||||
}
|
||||
$var->{ commentLoop_pageBar } = $p->getBarAdvanced;
|
||||
|
||||
return $self->processTemplate($var, undef, $self->{_viewTemplate});
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 www_delete ( )
|
||||
|
||||
Show the page to confirm the deletion of this Photo. Show a list of albums
|
||||
this Photo exists in.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_delete {
|
||||
my $self = shift;
|
||||
my $session = $self->session;
|
||||
|
||||
return $self->session->privilege->insufficient unless $self->canEdit;
|
||||
|
||||
my $var = $self->getTemplateVars;
|
||||
$var->{ url_yes } = $self->getUrl("func=deleteConfirm");
|
||||
|
||||
# TODO Get albums with shortcuts to this asset
|
||||
|
||||
return $self->processStyle(
|
||||
$self->processTemplate( $var, $self->getGallery->get("templateIdDeleteFile") )
|
||||
);
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 www_deleteComment ( )
|
||||
|
||||
Delete a comment immediately. Only those who can edit this Photo can delete
|
||||
comments on it.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_deleteComment {
|
||||
my $self = shift;
|
||||
my $session = $self->session;
|
||||
|
||||
return $session->privilege->insufficient unless $self->canEdit;
|
||||
|
||||
my $i18n = __PACKAGE__->i18n( $session );
|
||||
my $commentId = $session->form->get('commentId');
|
||||
|
||||
$self->deleteComment( $commentId );
|
||||
|
||||
return $self->www_view;
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 www_deleteConfirm ( )
|
||||
|
||||
Confirm the deletion of this Photo. Show a message and a link back to the
|
||||
album.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_deleteConfirm {
|
||||
my $self = shift;
|
||||
|
||||
return $self->session->privilege->insufficient unless $self->canEdit;
|
||||
|
||||
my $i18n = __PACKAGE__->i18n( $self->session );
|
||||
|
||||
$self->purge;
|
||||
|
||||
return $self->processStyle(
|
||||
sprintf $i18n->get("delete message"), $self->getParent->getUrl,
|
||||
);
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 www_download
|
||||
|
||||
Download the Photo with the specified resolution. If no resolution specified,
|
||||
|
|
@ -1101,146 +493,6 @@ sub www_edit {
|
|||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 www_editComment ( params )
|
||||
|
||||
Form to edit a comment. C<params> is a hash reference of parameters
|
||||
with the following keys:
|
||||
|
||||
errors = An array reference of errors to show the user.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_editComment {
|
||||
my $self = shift;
|
||||
my $params = shift;
|
||||
my $session = $self->session;
|
||||
|
||||
return $session->privilege->insufficient unless $self->canEdit;
|
||||
|
||||
my $var = $self->getTemplateVars;
|
||||
|
||||
if ( $params->{ errors } ) {
|
||||
$var->{ errors } = [ map { { "error" => $_ } } @{ $params->{errors} } ];
|
||||
}
|
||||
|
||||
my $commentId = $session->form->get( "commentId" );
|
||||
my $comment = $self->getComment( $commentId );
|
||||
$self->appendTemplateVarsCommentForm( $var, $comment );
|
||||
|
||||
return $self->processStyle(
|
||||
$self->processTemplate( $var, $self->getGallery->get("templateIdEditComment") )
|
||||
);
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 www_editCommentSave ( )
|
||||
|
||||
Save a comment being edited
|
||||
|
||||
=cut
|
||||
|
||||
sub www_editCommentSave {
|
||||
my $self = shift;
|
||||
my $session = $self->session;
|
||||
|
||||
return $session->privilege->insufficient unless $self->canEdit;
|
||||
|
||||
my $i18n = __PACKAGE__->i18n( $session );
|
||||
|
||||
my $comment = eval { $self->processCommentEditForm };
|
||||
if ( $@ ) {
|
||||
return $self->www_editComment( { errors => [ $@ ] } );
|
||||
}
|
||||
|
||||
# setComment changes commentId, so keep track if we're adding a new comment
|
||||
my $isNew = $comment->{commentId} eq "new";
|
||||
|
||||
$self->setComment( $comment );
|
||||
|
||||
# Return different message for adding and editing
|
||||
if ( $isNew ) {
|
||||
return $self->processStyle(
|
||||
sprintf $i18n->get('comment message'), $self->getUrl
|
||||
);
|
||||
}
|
||||
else {
|
||||
return $self->processStyle(
|
||||
sprintf $i18n->get('editCommentSave message'), $self->getUrl
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 www_makeShortcut ( )
|
||||
|
||||
Display the form to make a shortcut.
|
||||
|
||||
This page is only available to those who can edit this Photo.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_makeShortcut {
|
||||
my $self = shift;
|
||||
my $session = $self->session;
|
||||
|
||||
return $self->session->privilege->insufficient unless $self->canEdit;
|
||||
|
||||
# Create the form to make a shortcut
|
||||
my $var = $self->getTemplateVars;
|
||||
|
||||
$var->{ form_start }
|
||||
= WebGUI::Form::formHeader( $session )
|
||||
. WebGUI::Form::hidden( $session, { name => "func", value => "makeShortcutSave" });
|
||||
$var->{ form_end }
|
||||
= WebGUI::Form::formFooter( $session );
|
||||
|
||||
# Albums under this Gallery
|
||||
my $albums = $self->getGallery->getAlbumIds;
|
||||
my %albumOptions;
|
||||
for my $assetId ( @$albums ) {
|
||||
my $asset = WebGUI::Asset->newByDynamicClass($session, $assetId);
|
||||
if ($asset->canAddFile) {
|
||||
$albumOptions{ $assetId } = $asset->get("title");
|
||||
}
|
||||
}
|
||||
$var->{ form_parentId }
|
||||
= WebGUI::Form::selectBox( $session, {
|
||||
name => "parentId",
|
||||
value => $self->getParent->getId,
|
||||
options => \%albumOptions,
|
||||
});
|
||||
|
||||
return $self->processStyle(
|
||||
$self->processTemplate($var, $self->getGallery->get("templateIdMakeShortcut"))
|
||||
);
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 www_makeShortcutSave ( )
|
||||
|
||||
Make the shortcut.
|
||||
|
||||
This page is only available to those who can edit this Photo.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_makeShortcutSave {
|
||||
my $self = shift;
|
||||
my $form = $self->session->form;
|
||||
|
||||
return $self->session->privilege->insufficient unless $self->canEdit;
|
||||
|
||||
my $parentId = $form->get('parentId');
|
||||
my $shortcut = $self->makeShortcut( $parentId );
|
||||
|
||||
return $shortcut->www_view;
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 www_showConfirmation ( )
|
||||
|
||||
Shows the confirmation message after adding / editing a gallery album.
|
||||
|
|
@ -1260,24 +512,4 @@ sub www_showConfirmation {
|
|||
);
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 www_view ( )
|
||||
|
||||
Shows the output of L<view> inside of the style provided by the gallery this
|
||||
photo is in.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_view {
|
||||
my $self = shift;
|
||||
|
||||
return $self->session->privilege->insufficient unless $self->canView;
|
||||
|
||||
# Add to views
|
||||
$self->update({ views => $self->get('views') + 1 });
|
||||
|
||||
return $self->SUPER::www_view;
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
|||
|
|
@ -82,13 +82,6 @@ sub definition {
|
|||
label => $i18n->get("groupIdAddFile label"),
|
||||
hoverHelp => $i18n->get("groupIdAddFile description"),
|
||||
},
|
||||
groupIdModerator => {
|
||||
tab => "security",
|
||||
fieldType => "group",
|
||||
defaultValue => 3, # Admins
|
||||
label => $i18n->get("groupIdModerator label"),
|
||||
hoverHelp => $i18n->get("groupIdModerator description"),
|
||||
},
|
||||
imageResolutions => {
|
||||
tab => "properties",
|
||||
fieldType => "checkList",
|
||||
|
|
@ -963,6 +956,11 @@ sub www_search {
|
|||
. $db->quote( '%' . $form->get("description") . '%' )
|
||||
;
|
||||
}
|
||||
if ( $form->get("userId") ) {
|
||||
$where .= q{ AND assetData.ownerUserId = }
|
||||
. $db->quote( $form->get("userId") )
|
||||
;
|
||||
}
|
||||
|
||||
my $joinClass = [
|
||||
'WebGUI::Asset::Wobject::GalleryAlbum',
|
||||
|
|
@ -983,6 +981,7 @@ sub www_search {
|
|||
. 'className=' . $form->get('className') . ';'
|
||||
. 'creationDate_after=' . $form->get('creationDate_after') . ';'
|
||||
. 'creationDate_before=' . $form->get('creationDate_before') . ';'
|
||||
. 'userId=' . $form->get("userId") . ';'
|
||||
);
|
||||
|
||||
my $p
|
||||
|
|
|
|||
|
|
@ -120,16 +120,18 @@ sub addArchive {
|
|||
|
||||
for my $filePath (@files) {
|
||||
my ($volume, $directory, $filename) = File::Spec->splitpath( $filePath );
|
||||
$self->session->errorHandler->info( "trying $filename" );
|
||||
next if $filename =~ m{^[.]};
|
||||
my $class = $gallery->getAssetClassForFile( $filePath );
|
||||
next unless $class; # class is undef for those files the Gallery can't handle
|
||||
|
||||
$self->session->errorHandler->info( "Adding $filename to album!" );
|
||||
# Remove the file extention
|
||||
$filename =~ s{\.[^.]+}{};
|
||||
|
||||
$properties->{ className } = $class;
|
||||
$properties->{ menuTitle } = $filename;
|
||||
$properties->{ title } = $filename;
|
||||
$properties->{ url } = $self->getUrl . "/" . $filename;
|
||||
$properties->{ url } = $self->session->url->urlize( $self->getUrl . "/" . $filename );
|
||||
|
||||
my $asset = $self->addChild( $properties, undef, undef, { skipAutoCommitWorkflows => 1 } );
|
||||
$asset->setFile( $filePath );
|
||||
|
|
|
|||
|
|
@ -257,6 +257,24 @@ our $HELP = {
|
|||
name => 'commentLoop_pageBar',
|
||||
description => 'helpvar commentLoop_pageBar',
|
||||
},
|
||||
{
|
||||
name => 'keywords',
|
||||
description => 'helpvar keywords',
|
||||
variables => [
|
||||
{
|
||||
name => 'keyword',
|
||||
description => 'helpvar keyword',
|
||||
},
|
||||
{
|
||||
name => 'url_searchKeyword',
|
||||
description => 'helpvar url_searchKeyword',
|
||||
},
|
||||
{
|
||||
name => 'url_searchKeywordUser',
|
||||
description => 'helpvar url_searchKeywordUser',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package WebGUI::Asset::Wobject::Gallery::Utility;
|
||||
package WebGUI::Utility::Gallery;
|
||||
|
||||
=head1 LEGAL
|
||||
|
||||
|
|
@ -26,7 +26,7 @@ use WebGUI::Storage::Image;
|
|||
|
||||
=head1 NAME
|
||||
|
||||
WebGUI::Asset::Wobject::Gallery::Utility -- Utility functions for working
|
||||
WebGUI::Utility::Gallery -- Utility functions for working
|
||||
with Gallery assets.
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
|
@ -38,8 +38,8 @@ This module is B<NOT> to be used by the Gallery asset itself!
|
|||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
use WebGUI::Asset::Wobject::Gallery::Utility;
|
||||
my $utility = "WebGUI::Asset::Wobject::Gallery::Utility" # <- not as cumbersome
|
||||
use WebGUI::Utility::Gallery;
|
||||
my $utility = "WebGUI::Utility::Gallery" # <- not as cumbersome
|
||||
|
||||
# Add albums from a collaboration system's threads
|
||||
my $gallery = WebGUI::Asset::Wobject::Gallery->new( ... );
|
||||
|
|
@ -442,6 +442,23 @@ our $I18N = {
|
|||
context => 'Body text explaining what kinds of archives can be submitted',
|
||||
},
|
||||
|
||||
'template delete message' => {
|
||||
message => q{Are you sure you wish to delete this gallery?},
|
||||
lastUpdated => 0,
|
||||
context => q{The message for the delete page},
|
||||
},
|
||||
|
||||
'template delete no' => {
|
||||
message => q{No},
|
||||
lastUpdated => 0,
|
||||
context => q{Label for button to cancel the delete},
|
||||
},
|
||||
|
||||
'template delete yes' => {
|
||||
message => q{Yes},
|
||||
lastUpdated => 0,
|
||||
context => q{Label for button to confirm the delete},
|
||||
},
|
||||
};
|
||||
|
||||
1;
|
||||
|
|
|
|||
|
|
@ -510,6 +510,60 @@ our $I18N = {
|
|||
lastUpdated => 0,
|
||||
context => q{Error message for Photo comments},
|
||||
},
|
||||
|
||||
'helpvar keywords' => {
|
||||
message => q{A loop over the keywords associated with this photo},
|
||||
lastUpdated => 0,
|
||||
context => q{Description of template loop},
|
||||
},
|
||||
|
||||
'helpvar keyword' => {
|
||||
message => q{The keyword},
|
||||
lastUpdated => 0,
|
||||
context => q{Description of template variable},
|
||||
},
|
||||
|
||||
'helpvar url_searchKeyword' => {
|
||||
message => q{A URL to the Gallery search page for this keyword},
|
||||
lastUpdated => 0,
|
||||
context => q{Description of template variable},
|
||||
},
|
||||
|
||||
'helpvar url_searchKeywordUser' => {
|
||||
message => q{A URL to the Gallery search page for this keyword. Limits the search to Photos by this user.},
|
||||
lastUpdated => 0,
|
||||
context => q{Description of template variable},
|
||||
},
|
||||
|
||||
'template makeShortcut title' => {
|
||||
message => q{Cross Publish},
|
||||
lastUpdated => 0,
|
||||
context => q{Title for the make shortcut page},
|
||||
},
|
||||
|
||||
'template makeShortcut file' => {
|
||||
message => q{File},
|
||||
lastUpdated => 0,
|
||||
context => q{Label for the file we're making a shortcut of},
|
||||
},
|
||||
|
||||
'template makeShortcut album' => {
|
||||
message => q{Album},
|
||||
lastUpdated => 0,
|
||||
context => q{Label for the album in which to make the shortcut},
|
||||
},
|
||||
|
||||
'template delete message' => {
|
||||
message => q{Are you sure you wish to delete this gallery?},
|
||||
lastUpdated => 0,
|
||||
context => q{The message for the delete page},
|
||||
},
|
||||
|
||||
'template delete albums' => {
|
||||
message => q{Photo is currently in these albums:},
|
||||
lastUpdated => 0,
|
||||
context => q{Label for the albums the photo will be removed from.},
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue