re-integrated photogallery branch

This commit is contained in:
Doug Bell 2007-12-18 13:05:41 +00:00
commit 4c70aa4c71
75 changed files with 10806 additions and 473 deletions

View file

@ -1140,21 +1140,23 @@ sub getRecurrenceFromForm {
=head2 getRelatedLinks
Gets the related links.
Gets an array of hashrefs of related links.
=cut
sub getRelatedLinks {
my $self = shift;
return () unless $self->get("relatedLinks");
return split /\n+/, $self->get("relatedLinks");
}
#-------------------------------------------------------------------
=head2 getStorageLocation ( )
Get the storage location associated with this Event.
=cut
sub getStorageLocation {
my $self = shift;
unless (exists $self->{_storageLocation}) {
@ -1189,6 +1191,7 @@ sub getTemplateVars {
$var{"isPublic"} = 1
if $self->get("groupIdView") eq "7";
$var{"groupToView"} = $self->get("groupIdView");
$var{"timeZone"} = $self->get('timeZone');
# Start date/time
my $dtStart = $self->getDateTimeStart;
@ -1271,39 +1274,39 @@ sub getTemplateVars {
$var{ "urlParent" } = $self->getParent->getUrl;
$var{ "urlSearch" } = $self->getParent->getSearchUrl;
$var{"timeZone"} = $self->get('timeZone');
# Related links
$var{ "relatedLinks" } = [];
push @{$var{"relatedLinks"}}, { "linkUrl" => $_ }
for ($self->getRelatedLinks);
# Attachments
my $gotImage;
my $gotAttachment;
@{$var{'attachment_loop'}} = ();
$var{'attachment_loop'} = [];
unless ($self->get("storageId") eq "") {
my $storage = $self->getStorageLocation;
foreach my $filename (@{$storage->getFiles}) {
# Set top-level template vars for the first image and first non-image
if (!$gotImage && $storage->isImage($filename)) {
$var{"image.url"} = $storage->getUrl($filename);
$var{"image.thumbnail"} = $storage->getThumbnailUrl($filename);
$var{ "image.url" } = $storage->getUrl($filename);
$var{ "image.thumbnail" } = $storage->getThumbnailUrl($filename);
$gotImage = 1;
}
if (!$gotAttachment && !$storage->isImage($filename)) {
$var{"attachment.url"} = $storage->getUrl($filename);
$var{"attachment.icon"} = $storage->getFileIconUrl($filename);
$var{"attachment.name"} = $filename;
$var{ "attachment.url" } = $storage->getUrl($filename);
$var{ "attachment.icon" } = $storage->getFileIconUrl($filename);
$var{ "attachment.name" } = $filename;
$gotAttachment = 1;
}
push(@{$var{"attachment_loop"}}, {
url=>$storage->getUrl($filename),
icon=>$storage->getFileIconUrl($filename),
filename=>$filename,
thumbnail=>$storage->getThumbnailUrl($filename),
isImage=>$storage->isImage($filename)
});
}
# All attachments get added to the loop
push @{$var{"attachment_loop"}}, {
url => $storage->getUrl($filename),
icon => $storage->getFileIconUrl($filename),
filename => $filename,
thumbnail => $storage->getThumbnailUrl($filename),
isImage => $storage->isImage($filename),
};
}
}
@ -1456,8 +1459,8 @@ sub processPropertiesFromFormPost {
# All day events have no time
if ($form->param("allday")) {
$self->update({
startTime => '',
endTime => '',
startTime => undef,
endTime => undef,
});
}
# Non-allday events need timezone conversion
@ -1563,24 +1566,25 @@ sub processPropertiesFromFormPost {
return;
}
#-------------------------------------------------------------------
sub purge {
my $self = shift;
my $sth = $self->session->db->read("select storageId from Event where assetId=?",[$self->getId]);
while (my ($storageId) = $sth->array) {
my $self = shift;
my $sth = $self->session->db->read("select storageId from Event where assetId=?",[$self->getId]);
while (my ($storageId) = $sth->array) {
my $storage = WebGUI::Storage::Image->get($self->session,$storageId);
$storage->delete if defined $storage;
}
$sth->finish;
return $self->SUPER::purge;
$storage->delete if defined $storage;
}
$sth->finish;
return $self->SUPER::purge;
}
#-------------------------------------------------------------------
sub purgeRevision {
my $self = shift;
$self->getStorageLocation->delete;
return $self->SUPER::purgeRevision;
my $self = shift;
$self->getStorageLocation->delete;
return $self->SUPER::purgeRevision;
}
####################################################################
@ -1677,7 +1681,7 @@ sub setRelatedLinks {
$self->update({
relatedLinks => join("\n", @links),
});
});
}
####################################################################

View file

@ -16,6 +16,7 @@ package WebGUI::Asset::File;
use strict;
use base 'WebGUI::Asset';
use Carp;
use WebGUI::Cache;
use WebGUI::Storage;
use WebGUI::SQL;
@ -54,17 +55,17 @@ Override the default method in order to deal with attachments.
=cut
sub addRevision {
my $self = shift;
my $properties = shift;
if ($self->get("storageId") ne "") {
my $newStorage = WebGUI::Storage->get($self->session,$self->get("storageId"))->copy;
$properties->{storageId} = $newStorage->getId;
}
my $newSelf = $self->SUPER::addRevision($properties);
return $newSelf;
my $self = shift;
my $properties = shift;
if ($self->get("storageId") ne "") {
my $newStorage = $self->getStorageClass->get($self->session,$self->get("storageId"))->copy;
$properties->{storageId} = $newStorage->getId;
}
my $newSelf = $self->SUPER::addRevision($properties, @_);
return $newSelf;
}
#-------------------------------------------------------------------
@ -172,23 +173,50 @@ Returns the TabForm object that will be used in generating the edit page for thi
=cut
sub getEditForm {
my $self = shift;
my $tabform = $self->SUPER::getEditForm();
my $i18n = WebGUI::International->new($self->session, 'Asset_File');
if ($self->get("filename") ne "") {
$tabform->getTab("properties")->readOnly(
-label=>$i18n->get('current file'),
-hoverHelp=>$i18n->get('current file description', 'Asset_File'),
-value=>'<p style="display:inline;vertical-align:middle;"><a href="'.$self->getFileUrl.'"><img src="'.$self->getFileIconUrl.'" alt="'.$self->get("filename").'" style="border-style:none;vertical-align:middle;" /> '.$self->get("filename").'</a></p>'
);
my $self = shift;
my $tabform = $self->SUPER::getEditForm();
my $i18n = WebGUI::International->new($self->session, 'Asset_File');
}
$tabform->getTab("properties")->file(
-name => 'newFile',
-label => $i18n->get('new file'),
-hoverHelp => $i18n->get('new file description'),
);
return $tabform;
$tabform->getTab("properties")->raw(
'<tr><td>'.$i18n->get('new file').'<td colspan="2">'
. $self->getEditFormUploadControl
. '</td></tr>'
);
return $tabform;
}
#----------------------------------------------------------------------------
=head2 getEditFormUploadControl
Returns the HTML to render the upload box and link to delete the existing
file, if necessary.
=cut
sub getEditFormUploadControl {
my $self = shift;
my $session = $self->session;
my $i18n = WebGUI::International->new($session, 'Asset_File');
my $html = '';
if ($self->get("filename") ne "") {
$html .= WebGUI::Form::readOnly( $session, {
label => $i18n->get('current file'),
hoverHelp => $i18n->get('current file description', 'Asset_File'),
value => '<p style="display:inline;vertical-align:middle;"><a href="'.$self->getFileUrl.'"><img src="'.$self->getFileIconUrl.'" alt="'.$self->get("filename").'" style="border-style:none;vertical-align:middle;" /> '.$self->get("filename").'</a></p>'
});
}
# Control to upload a new file
$html .= WebGUI::Form::file( $session, {
name => 'newFile',
label => $i18n->get('new file'),
hoverHelp => $i18n->get('new file description'),
});
return $html;
}
@ -199,10 +227,10 @@ sub getFileUrl {
return $self->getStorageLocation->getUrl($self->get("filename"));
}
#-------------------------------------------------------------------
sub getFileIconUrl {
my $self = shift;
return unless $self->get("filename"); ## Why do I have to do this when creating new Files?
return $self->getStorageLocation->getFileIconUrl($self->get("filename"));
}
@ -221,20 +249,32 @@ sub getIcon {
}
#----------------------------------------------------------------------------
=head2 getStorageClass
Get the full classname of the WebGUI::Storage we should use for this asset.
=cut
sub getStorageClass {
return 'WebGUI::Storage';
}
#-------------------------------------------------------------------
=head2 getStorageFromPost
We have to wrap this operation because WebGUI::Asset::File::Image calls SUPER processPropertiesFormFormPost,
which gives it the wrong type of Storage object.
Get the storage location created by the form post.
=cut
sub getStorageFromPost {
my $self = shift;
my $self = shift;
my $storageId = shift;
my $fileStorageId = WebGUI::Form::File->new($self->session, {name => 'newFile', value=>$storageId })->getValueFromPost;
return WebGUI::Storage->get($self->session, $fileStorageId);
$self->session->errorHandler->info( "File Storage Id: $fileStorageId" );
return $self->getStorageClass->get($self->session, $fileStorageId);
}
@ -283,41 +323,21 @@ sub prepareView {
#-------------------------------------------------------------------
sub processPropertiesFromFormPost {
my $self = shift;
my $session = $self->session;
$self->SUPER::processPropertiesFromFormPost;
#Get the storage location out of memory. If you call getStorageLocation you risk creating another one.
my $storageLocation = $self->{_storageLocation};
my $storageId = undef;
$storageId = $storageLocation->getId if(defined $storageLocation);
#Now remove the storage location to prevent wierd caching stuff.
delete $self->{_storageLocation};
#Clear the storage location if a file was uploaded.
if($session->form->get("newFile_file") ne "") {
$storageLocation->clear();
my $self = shift;
my $session = $self->session;
my $errors = $self->SUPER::processPropertiesFromFormPost;
return $errors if $errors;
if (my $storageId = $session->form->get('newFile','File')) {
$session->errorHandler->info("Got a new file for asset " . $self->getId);
my $storage = $self->getStorageClass->get( $session, $storageId);
my $filePath = $storage->getPath( $storage->getFiles->[0] );
$self->setFile( $filePath );
$storage->delete;
}
#Pass in the storage Id to prevent another one from being created.
my $storage = $self->getStorageFromPost($storageId);
if (defined $storage) {
my $filename = $storage->getFiles()->[0];
if (defined $filename) {
my %data;
$data{filename} = $filename;
$data{storageId} = $storage->getId;
$data{title} = $filename unless ($session->form->process("title"));
$data{menuTitle} = $filename unless ($session->form->process("menuTitle"));
$data{url} = $self->getParent->get('url').'/'.$filename unless ($session->form->process("url"));
$self->setStorageLocation($storage);
$self->update(\%data);
}
}
$self->applyConstraints;
return;
}
@ -327,7 +347,7 @@ sub purge {
my $self = shift;
my $sth = $self->session->db->read("select storageId from FileAsset where assetId=".$self->session->db->quote($self->getId));
while (my ($storageId) = $sth->array) {
WebGUI::Storage->get($self->session,$storageId)->delete;
$self->getStorageClass->get($self->session,$storageId)->delete;
}
$sth->finish;
return $self->SUPER::purge;
@ -355,34 +375,68 @@ sub purgeRevision {
return $self->SUPER::purgeRevision;
}
#----------------------------------------------------------------------------
=head2 setFile ( filename )
Set the file being handled by this storage location with a file from the
system.
=cut
sub setFile {
my $self = shift;
my $filename = shift;
my $storage = $self->getStorageLocation;
# Clear the old file if any
$storage->clear;
$storage->addFileFromFilesystem($filename)
|| croak "Couldn't setFile: " . join(", ",@{ $storage->getErrors });
# NOTE: We should not croak here, the WebGUI::Storage should croak for us.
$self->updatePropertiesFromStorage;
$self->applyConstraints;
}
#-------------------------------------------------------------------
=head2 setSize ( fileSize )
Set the size of this asset by including all the files in its storage
location. C<fileSize> is an integer of additional bytes to include in
the asset size.
=cut
sub setSize {
my $self = shift;
my $fileSize = shift || 0;
my $storage = $self->getStorageLocation;
if (defined $storage) {
foreach my $file (@{$storage->getFiles}) {
$fileSize += $storage->getFileSize($file);
}
}
return $self->SUPER::setSize($fileSize);
my $self = shift;
my $fileSize = shift || 0;
my $storage = $self->getStorageLocation;
if (defined $storage) {
foreach my $file (@{$storage->getFiles}) {
$fileSize += $storage->getFileSize($file);
}
}
return $self->SUPER::setSize($fileSize);
}
#-------------------------------------------------------------------
sub setStorageLocation {
my $self = shift;
my $self = shift;
my $storage = shift;
if (defined $storage) {
if (defined $storage) {
$self->{_storageLocation} = $storage;
}
elsif ($self->get("storageId") eq "") {
$self->{_storageLocation} = WebGUI::Storage->create($self->session);
$self->update({storageId=>$self->{_storageLocation}->getId});
}
}
elsif ($self->get("storageId") eq "") {
$self->{_storageLocation} = $self->getStorageClass->create($self->session);
$self->update({storageId=>$self->{_storageLocation}->getId});
}
else {
$self->{_storageLocation} = WebGUI::Storage->get($self->session,$self->get("storageId"));
}
$self->{_storageLocation} = $self->getStorageClass->get($self->session,$self->get("storageId"));
}
}
#-------------------------------------------------------------------
@ -411,6 +465,27 @@ sub update {
}
}
#----------------------------------------------------------------------------
=head2 updatePropertiesFromStorage ( )
Updates the asset properties from the file tracked by this asset. Should be
called every time the file is changed to ensure the correct filename is
in the asset properties.
=cut
sub updatePropertiesFromStorage {
my $self = shift;
my $storage = $self->getStorageLocation;
my $filename = $storage->getFiles->[0];
$self->session->errorHandler->info("Updating file asset filename to $filename");
$self->update({
filename => $filename,
});
return;
}
#-------------------------------------------------------------------
sub view {
my $self = shift;

View file

@ -15,16 +15,12 @@ package WebGUI::Asset::File::Image;
=cut
use strict;
use WebGUI::Asset::File;
use base 'WebGUI::Asset::File';
use WebGUI::Storage::Image;
use WebGUI::HTMLForm;
use WebGUI::Utility;
use WebGUI::Form::Image;
our @ISA = qw(WebGUI::Asset::File);
=head1 NAME
Package WebGUI::Asset::File::Image
@ -98,27 +94,27 @@ A hash reference passed in from a subclass definition.
=cut
sub definition {
my $class = shift;
my $session = shift;
my $definition = shift;
my $i18n = WebGUI::International->new($session,"Asset_Image");
push(@{$definition}, {
assetName=>$i18n->get('assetName'),
tableName=>'ImageAsset',
className=>'WebGUI::Asset::File::Image',
icon=>'image.gif',
properties=>{
thumbnailSize=>{
fieldType=>'integer',
defaultValue=>$session->setting->get("thumbnailSize")
},
parameters=>{
fieldType=>'textarea',
defaultValue=>'style="border-style:none;"'
}
}
});
return $class->SUPER::definition($session,$definition);
my $class = shift;
my $session = shift;
my $definition = shift;
my $i18n = WebGUI::International->new($session,"Asset_Image");
push @{$definition}, {
assetName => $i18n->get('assetName'),
tableName => 'ImageAsset',
className => 'WebGUI::Asset::File::Image',
icon => 'image.gif',
properties => {
thumbnailSize => {
fieldType => 'integer',
defaultValue => $session->setting->get("thumbnailSize"),
},
parameters => {
fieldType => 'textarea',
defaultValue => 'style="border-style:none;"',
},
},
};
return $class->SUPER::definition($session,$definition);
}
@ -184,37 +180,16 @@ sub getEditForm {
return $tabform;
}
#----------------------------------------------------------------------------
=head2 getStorageClass
#-------------------------------------------------------------------
=head2 getStorageFromPost
Sub class this method from WebGUI::Asset::File so the storage object is the correct type.
Returns the class name of the WebGUI::Storage we should use for this asset.
=cut
sub getStorageFromPost {
my $self = shift;
my $storageId = shift;
my $fileStorageId = WebGUI::Form::Image->new($self->session, {name => 'newFile', value=>$storageId })->getValueFromPost;
return WebGUI::Storage::Image->get($self->session, $fileStorageId);
}
#-------------------------------------------------------------------
sub getStorageLocation {
my $self = shift;
unless (exists $self->{_storageLocation}) {
if ($self->get("storageId") eq "") {
$self->{_storageLocation} = WebGUI::Storage::Image->create($self->session);
$self->update({storageId=>$self->{_storageLocation}->getId});
} else {
$self->{_storageLocation} = WebGUI::Storage::Image->get($self->session,$self->get("storageId"));
}
}
return $self->{_storageLocation};
sub getStorageClass {
return 'WebGUI::Storage::Image';
}
#-------------------------------------------------------------------
@ -253,31 +228,6 @@ sub prepareView {
$self->{_viewTemplate} = $template;
}
#-------------------------------------------------------------------
sub processPropertiesFromFormPost {
my $self = shift;
$self->SUPER::processPropertiesFromFormPost;
$self->applyConstraints;
}
#-------------------------------------------------------------------
sub setStorageLocation {
my $self = shift;
my $storage = shift;
if (defined $storage) {
$self->{_storageLocation} = $storage;
}
elsif ($self->get("storageId") eq "") {
$self->{_storageLocation} = WebGUI::Storage::Image->create($self->session);
$self->update({storageId=>$self->{_storageLocation}->getId});
}
else {
$self->{_storageLocation} = WebGUI::Storage::Image->get($self->session,$self->get("storageId"));
}
}
#-------------------------------------------------------------------
sub view {
my $self = shift;
@ -297,6 +247,20 @@ sub view {
return $out;
}
#----------------------------------------------------------------------------
=head2 setFile ( filename )
Extend the superclass setFile to automatically generate thumbnails.
=cut
sub setFile {
my $self = shift;
$self->SUPER::setFile(@_);
$self->generateThumbnail;
}
#-------------------------------------------------------------------
sub www_edit {
my $self = shift;

File diff suppressed because it is too large Load diff

View file

@ -11,6 +11,7 @@ package WebGUI::Asset::Shortcut;
#-------------------------------------------------------------------
use strict;
use Carp;
use Tie::IxHash;
use WebGUI::Asset;
use WebGUI::International;
@ -605,6 +606,26 @@ sub getPrefFieldsToImport {
return split("\n",$self->getValue("prefFieldsToImport"));
}
#----------------------------------------------------------------------------
=head2 getTemplateVars
Gets the template vars for this shortcut.
=cut
sub getTemplateVars {
my $self = shift;
my $shortcut = $self->getShortcut;
if ( $shortcut->can('getTemplateVars') ) {
return $shortcut->getTemplateVars;
}
else {
return $shortcut->get;
}
}
#-------------------------------------------------------------------
sub isDashlet {
my $self = shift;
@ -648,6 +669,34 @@ sub processPropertiesFromFormPost {
$self->uncacheOverrides;
}
#----------------------------------------------------------------------------
=head2 setOverride ( overrides )
Set this shortcut's overrides. C<overrides> is a hash reference of overrides
to set.
=cut
sub setOverride {
my $self = shift;
my $override = shift;
croak "Shortcut->setOverride - first argument must be hash reference"
unless $override && ref $override eq "HASH";
for my $key ( %$override ) {
$self->session->db->write(
"DELETE FROM Shortcut_overrides WHERE assetId=? AND fieldName=?",
[$self->getId, $key],
);
$self->session->db->write(
"INSERT INTO Shortcut_overrides VALUES (?,?,?)",
[$self->getId, $key, $override->{$key}],
);
}
}
#-------------------------------------------------------------------
sub purge {
my $self = shift;
@ -880,23 +929,23 @@ sub www_editOverride {
#-------------------------------------------------------------------
sub www_saveOverride {
my $self = shift;
return $self->session->privilege->insufficient() unless $self->canEdit;
my $fieldName = $self->session->form->process("overrideFieldName");
my %overrides = $self->getOverrides;
my $output = '';
my %props;
foreach my $def (@{$self->getShortcutOriginal->definition($self->session)}) {
%props = (%props,%{$def->{properties}});
}
my $fieldType = $props{$fieldName}{fieldType};
my $value = $self->session->form->process($fieldName,$fieldType);
$value = $self->session->form->process("newOverrideValueText") || $value;
$self->session->db->write("delete from Shortcut_overrides where assetId=".$self->session->db->quote($self->getId)." and fieldName=".$self->session->db->quote($fieldName));
$self->session->db->write("insert into Shortcut_overrides values (".$self->session->db->quote($self->getId).",".$self->session->db->quote($fieldName).",".$self->session->db->quote($value).")");
$self->uncacheOverrides;
$self->getShortcutOriginal->purgeCache();
return $self->www_manageOverrides;
my $self = shift;
return $self->session->privilege->insufficient() unless $self->canEdit;
my $fieldName = $self->session->form->process("overrideFieldName");
my %overrides = $self->getOverrides;
my $output = '';
my %props;
foreach my $def (@{$self->getShortcutOriginal->definition($self->session)}) {
%props = (%props,%{$def->{properties}});
}
my $fieldType = $props{$fieldName}{fieldType};
my $value = $self->session->form->process($fieldName,$fieldType);
$value = $self->session->form->process("newOverrideValueText") || $value;
$self->session->db->write("delete from Shortcut_overrides where assetId=".$self->session->db->quote($self->getId)." and fieldName=".$self->session->db->quote($fieldName));
$self->session->db->write("insert into Shortcut_overrides values (".$self->session->db->quote($self->getId).",".$self->session->db->quote($fieldName).",".$self->session->db->quote($value).")");
$self->uncacheOverrides;
$self->getShortcutOriginal->purgeCache();
return $self->www_manageOverrides;
}
#-------------------------------------------------------------------
@ -928,5 +977,43 @@ sub www_view {
return $output;
}
#----------------------------------------------------------------------------
=head1 STATIC METHODS
These methods are called using CLASS->method
#----------------------------------------------------------------------------
=head2 getShortcutsForAssetId ( session, assetId [, properties] )
Get an arrayref of assetIds of all the shortcuts for the passed-in assetId.
"properties" is a hash reference of properties to give to getLineage.
Probably the only useful key will be "returnObjects".
=cut
sub getShortcutsForAssetId {
my $class = shift;
my $session = shift;
my $assetId = shift;
my $properties = shift || {};
croak "First argument to getShortcutsForAssetId must be WebGUI::Session"
unless $session && $session->isa("WebGUI::Session");
croak "Second argument to getShortcutsForAssetId must be assetId"
unless $assetId;
croak "Third argument to getShortcutsForAssetId must be hash reference"
if $properties && !ref $properties eq "HASH";
my $db = $session->db;
$properties->{ joinClass } = 'WebGUI::Asset::Shortcut';
$properties->{ whereClause } = 'Shortcut.shortcutToAssetId = ' . $db->quote($assetId);
return WebGUI::Asset->getRoot($session)->getLineage(['descendants'], $properties);
}
1;

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,882 @@
package WebGUI::Asset::Wobject::GalleryAlbum;
$VERSION = "1.0.0";
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2006 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
use strict;
use base 'WebGUI::Asset::Wobject';
use Carp qw( croak );
use File::Find;
use File::Spec;
use File::Temp qw{ tempdir };
use Tie::IxHash;
use WebGUI::International;
use WebGUI::Utility;
use Archive::Any;
=head1 NAME
=head1 DESCRIPTION
=head1 SYNOPSIS
=head1 DIAGNOSTICS
=head1 METHODS
#-------------------------------------------------------------------
=head2 definition ( )
Define wobject properties for new GalleryAlbum wobjects.
=cut
sub definition {
my $class = shift;
my $session = shift;
my $definition = shift;
my $i18n = __PACKAGE__->i18n($session);
tie my %properties, 'Tie::IxHash', (
allowComments => {
fieldType => "yesNo",
defaultValue => 1,
},
othersCanAdd => {
fieldType => "yesNo",
defaultValue => 0,
},
assetIdThumbnail => {
fieldType => "asset",
defaultValue => undef,
},
);
push @{$definition}, {
assetName => $i18n->get('assetName'),
autoGenerateForms => 0,
icon => 'newWobject.gif',
tableName => 'GalleryAlbum',
className => __PACKAGE__,
properties => \%properties,
};
return $class->SUPER::definition($session, $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 $gallery = $self->getParent;
my $archive = Archive::Any->new( $filename );
croak "Archive will extract to directory outside of storage location!"
if $archive->is_naughty;
my $tempdirName = tempdir( "WebGUI-Gallery-XXXXXXXX", TMPDIR => 1, CLEANUP => 1);
$archive->extract( $tempdirName );
# Get all the files in the archive
my @files;
my $wanted = sub { push @files, $File::Find::name };
find( {
wanted => $wanted,
}, $tempdirName );
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!" );
$properties->{ className } = $class;
$properties->{ menuTitle } = $filename;
$properties->{ title } = $filename;
$properties->{ url } = $self->getUrl . "/" . $filename;
my $asset = $self->addChild( $properties, undef, undef, { skipAutoCommitWorkflows => 1 } );
$asset->setFile( $filePath );
}
my $versionTag = WebGUI::VersionTag->getWorking( $self->session );
$versionTag->set({
"workflowId" => $self->getParent->get("workflowIdCommit"),
});
$versionTag->requestCommit;
return;
}
#----------------------------------------------------------------------------
=head2 appendTemplateVarsFileLoop ( vars, assetIds )
Append template vars for a file loop for the specified assetIds. C<vars> is
a hash reference to add the file loop to. C<assetIds> is an array reference
of assetIds for the loop.
Returns the hash reference for convenience.
=cut
sub appendTemplateVarsFileLoop {
my $self = shift;
my $var = shift;
my $assetIds = shift;
my $session = $self->session;
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;
my $gallery = $self->getParent;
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] )
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 GalleryAlbum if they are the owner, or if they can edit
the Gallery parent.
Also handles adding of child assets by calling C<canAddFile>.
=cut
sub canEdit {
my $self = shift;
my $userId = shift || $self->session->user->userId;
my $gallery = $self->getParent;
my $form = $self->session->form;
# Handle adding a photo
if ( $form->get("func") eq "add" ) {
return $self->canAddFile;
}
elsif ( $form->get("func") eq "editSave" && $form->get("className") eq __PACKAGE__ ) {
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.
Users can view this album if they can view the containing Gallery.
NOTE: It may be possible to view a GalleryAlbum that has no public files. In
such cases, the GalleryAlbum will appear empty to unprivileged users. This is
not a bug.
=cut
sub canView {
my $self = shift;
my $userId = shift || $self->session->user->userId;
return $self->getParent->canView($userId);
}
#----------------------------------------------------------------------------
=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 getAutoCommitWorkflowId ( )
Returns the workflowId of the Gallery's approval workflow.
=cut
sub getAutoCommitWorkflowId {
my $self = shift;
return $self->getParent->get("workflowIdCommit");
}
#----------------------------------------------------------------------------
=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->getLineage( ['descendants'], { } );
}
#----------------------------------------------------------------------------
=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 || $self->getUrl;
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 $session = $self->session;
my $gallery = $self->getParent;
my $var = $self->get;
my $owner = WebGUI::User->new( $session, $self->get("ownerUserId") );
# Permissions
$var->{ canAddFile } = $self->canAddFile;
$var->{ canEdit } = $self->canEdit;
# Add some common template vars from Gallery
$gallery->appendTemplateVarsSearchForm( $var );
$var->{ url_listAlbums } = $gallery->getUrl('func=listAlbums');
$var->{ url_listAlbumsRss } = $gallery->getUrl('func=listAlbumsRss');
$var->{ url_listFilesForCurrentUser } = $gallery->getUrl('func=listFilesForUser');
$var->{ url_search } = $gallery->getUrl('func=search');
# Friendly URLs
$var->{ url } = $self->getUrl;
$var->{ url_addArchive } = $self->getUrl('func=addArchive');
$var->{ url_addPhoto } = $self->getUrl("func=add;class=WebGUI::Asset::File::Image::Photo");
$var->{ url_addNoClass } = $self->getUrl("func=add");
$var->{ url_delete } = $self->getUrl("func=delete");
$var->{ url_edit } = $self->getUrl("func=edit");
$var->{ url_listFilesForOwner } = $gallery->getUrl("func=listFilesForUser;userId=".$var->{ownerUserId});
$var->{ url_viewRss } = $self->getUrl("func=viewRss");
$var->{ url_slideshow } = $self->getUrl("func=slideshow");
$var->{ url_thumbnails } = $self->getUrl("func=thumbnails");
$var->{ fileCount } = $self->getChildCount;
$var->{ ownerUsername } = $owner->username;
$var->{ thumbnailUrl } = $self->getThumbnailUrl;
return $var;
}
#----------------------------------------------------------------------------
=head2 getThumbnailUrl ( )
Gets the URL for the thumbnail for this asset. If no asset is set, gets the
first child.
NOTE: If the asset does not have a getThumbnailUrl method, this method will
return undef.
=cut
sub getThumbnailUrl {
my $self = shift;
my $asset = undef;
if ( $self->get("assetIdThumbnail") ) {
$asset = WebGUI::Asset->newByDynamicClass( $self->session, $self->get("assetIdThumbnail") );
}
elsif ( $self->getFirstChild ) {
$asset = $self->getFirstChild;
}
else {
return undef;
}
if ( $asset->can("getThumbnailUrl") ) {
return $asset->getThumbnailUrl;
}
else {
return undef;
}
}
#----------------------------------------------------------------------------
=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 ( )
See WebGUI::Asset::prepareView() for details.
=cut
sub prepareView {
my $self = shift;
$self->SUPER::prepareView();
my $templateId = $self->getParent->get("templateIdViewAlbum");
my $template
= WebGUI::Asset::Template->new($self->session, $templateId);
$template->prepare;
$self->{_viewTemplate} = $template;
}
#----------------------------------------------------------------------------
=head2 processStyle ( )
Gets the parent Gallery's style template
=cut
sub processStyle {
my $self = shift;
return $self->getParent->processStyle(@_);
}
#----------------------------------------------------------------------------
=head2 processPropertiesFromFormPost ( )
Process the form to save the asset. Request approval from the Gallery's
approval workflow.
=cut
sub processPropertiesFromFormPost {
my $self = shift;
my $errors = $self->SUPER::processPropertiesFromFormPost || [];
# Return if error
return $errors if @$errors;
# Passes all checks
$self->requestAutoCommit;
}
#----------------------------------------------------------------------------
=head2 view ( )
method called by the www_view method. Returns a processed template
to be displayed within the page style.
=cut
sub view {
my $self = shift;
my $session = $self->session;
my $var = $self->getTemplateVars;
my $p = $self->getFilePaginator;
$p->appendTemplateVars( $var );
$self->appendTemplateVarsFileLoop( $var, $p->getPageData );
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.
Show a slideshow of the GalleryAlbum's files.
=cut
sub view_slideshow {
my $self = shift;
my $session = $self->session;
my $var = $self->getTemplateVars;
$self->appendTemplateVarsFileLoop( $var, $self->getFileIds );
return $self->processTemplate($var, $self->getParent->get("templateIdViewSlideshow"));
}
#----------------------------------------------------------------------------
=head2 view_thumbnails ( )
method called by the www_thumbnails method. Returns a processed template to be
displayed within the page style.
Shows all the thumbnails for this GalleryAlbum. In addition, shows details
about a specific thumbnail.
=cut
sub view_thumbnails {
my $self = shift;
my $session = $self->session;
my $var = $self->getTemplateVars;
my $fileId = $session->form->get("fileId");
$self->appendTemplateVarsFileLoop( $var, $self->getFileIds );
# Process the file loop to add an additional URL
for my $file ( @{ $var->{file_loop} } ) {
$file->{ url_albumViewThumbnails }
= $self->getUrl('func=thumbnails;fileId=' . $file->{assetId});
}
# Add direct vars for the requested file
my $asset;
if ($fileId) {
$asset = WebGUI::Asset->newByDynamicClass( $session, $fileId );
}
# If no fileId given or fileId does not exist
if (!$asset) {
$asset = $self->getFirstChild;
}
my %assetVars = %{ $asset->getTemplateVars };
for my $key ( keys %assetVars ) {
$var->{ 'file_' . $key } = $assetVars{ $key };
}
return $self->processTemplate($var, $self->getParent->get("templateIdViewThumbnails"));
}
#----------------------------------------------------------------------------
=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 $session = $self->session;
my $form = $self->session->form;
my $var = $self->getTemplateVars;
$var->{ form_start }
= WebGUI::Form::formHeader( $session, {
action => $self->getUrl('func=addArchiveSave'),
});
$var->{ form_end }
= WebGUI::Form::formFooter( $session );
$var->{ form_submit }
= WebGUI::Form::submit( $session, {
name => "submit",
value => "Submit",
});
$var->{ form_archive }
= WebGUI::Form::File( $session, {
name => "archive",
maxAttachments => 1,
value => ( $form->get("archive") ),
});
$var->{ form_keywords }
= WebGUI::Form::text( $session, {
name => "keywords",
value => ( $form->get("keywords") ),
});
$var->{ form_friendsOnly }
= WebGUI::Form::yesNo( $session, {
name => "friendsOnly",
value => ( $form->get("friendsOnly") ),
});
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 $session = $self->session;
my $form = $self->session->form;
my $i18n = __PACKAGE__->i18n( $session );
my $properties = {
keywords => $form->get("keywords"),
friendsOnly => $form->get("friendsOnly"),
};
my $storageId = $form->get("archive", "File");
my $storage = WebGUI::Storage->get( $session, $storageId );
my $filename = $storage->getPath( $storage->getFiles->[0] );
$self->addArchive( $filename, $properties );
$storage->delete;
return $self->processStyle(
sprintf $i18n->get('addArchive message'), $self->getUrl,
);
}
#-----------------------------------------------------------------------------
=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;
my $gallery = $self->getParent;
$self->purge;
return $gallery->www_view;
}
#----------------------------------------------------------------------------
=head2 www_edit ( )
Show the form to add / edit a GalleryAlbum asset.
=cut
sub www_edit {
my $self = shift;
my $session = $self->session;
my $form = $self->session->form;
my $var = $self->getTemplateVars;
my $i18n = __PACKAGE__->i18n($session);
# Generate the form
if ($form->get("func") eq "add") {
$var->{ form_start }
= WebGUI::Form::formHeader( $session, {
action => $self->getParent->getUrl('func=editSave;assetId=new;class='.__PACKAGE__),
});
}
else {
$var->{ form_start }
= WebGUI::Form::formHeader( $session, {
action => $self->getUrl('func=editSave'),
});
}
$var->{ form_start }
.= WebGUI::Form::hidden( $session, {
name => "proceed",
value => "showConfirmation",
});
$var->{ form_end }
= WebGUI::Form::formFooter( $session );
$var->{ form_cancel }
= WebGUI::Form::button( $session, {
name => "cancel",
value => $i18n->get("cancel"),
extras => 'onclick="history.go(-1)"',
});
$var->{ form_submit }
= WebGUI::Form::submit( $session, {
name => "save",
value => $i18n->get("save"),
});
$var->{ form_title }
= WebGUI::Form::text( $session, {
name => "title",
value => $form->get("title") || $self->get("title"),
});
$var->{ form_description }
= WebGUI::Form::HTMLArea( $session, {
name => "description",
value => $form->get("description") || $self->get("description"),
});
# Generate the file loop
my $thumbnailUrl = $self->getThumbnailUrl;
$self->appendTemplateVarsFileLoop( $var, $self->getFileIds );
for my $file ( @{ $var->{file_loop} } ) {
if ( $thumbnailUrl eq $file->{thumbnailUrl} ) {
$file->{ isAlbumThumbnail } = 1;
}
}
return $self->processStyle(
$self->processTemplate( $var, $self->getParent->get("templateIdEditAlbum") )
);
}
#-----------------------------------------------------------------------------
=head2 www_editSave ( )
Save the asset edit form. Overridden to give a nice message when a photo or
album is added
=cut
sub www_editSave {
my $self = shift;
my $form = $self->session->form;
my $i18n = __PACKAGE__->i18n($self->session);
$self->SUPER::www_editSave;
if ( $form->get("assetId") eq "new" ) {
return sprintf $i18n->get("addFile message"), $self->getUrl,
}
else {
return sprintf $i18n->get("save message"), $self->getUrl,
}
}
#----------------------------------------------------------------------------
=head2 www_showConfirmation ( )
Shows the confirmation message after adding / editing a gallery album.
Provides links to view the album.
=cut
sub www_showConfirmation {
my $self = shift;
my $i18n = __PACKAGE__->i18n( $self->session );
my $output = sprintf $i18n->get('save message'), $self->getUrl;
return $self->processStyle(
$output
);
}
#-----------------------------------------------------------------------------
=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;
my $var = $self->getTemplateVars;
$self->appendTemplateVarsFileLoop( $var, $self->getFileIds );
# Fix URLs to be full URLs
for my $key ( qw( url url_viewRss ) ) {
$var->{ $key } = $self->session->url->getSiteURL . $var->{ $key };
}
# Process the file loop to add additional params
for my $file ( @{ $var->{file_loop} } ) {
# Fix URLs to be full URLs
for my $key ( qw( url ) ) {
$file->{ $key } = $self->session->url->getSiteURL . $file->{$key};
}
$file->{ rssDate }
= $self->session->datetime->epochToMail( $file->{creationDate} );
}
$self->session->http->setMimeType('text/xml');
return $self->processTemplate( $var, $self->getParent->get('templateIdViewAlbumRss') );
}
1;