diff --git a/docs/upgrades/_upgrade.skeleton b/docs/upgrades/_upgrade.skeleton index e13a7b7d9..7821157a7 100644 --- a/docs/upgrades/_upgrade.skeleton +++ b/docs/upgrades/_upgrade.skeleton @@ -12,6 +12,8 @@ use lib "../../lib"; use strict; use Getopt::Long; use WebGUI::Session; +use WebGUI::Storage; +use WebGUI::Asset; my $toVersion = "0.0.0"; # make this match what version you're going to @@ -33,8 +35,71 @@ finish($session); # this line required #} +# --------------- DO NOT EDIT BELOW THIS LINE -------------------------------- -# ---- DO NOT EDIT BELOW THIS LINE ---- +#---------------------------------------------------------------------------- +# Add a package to the import node +sub addPackage { + my $session = shift; + my $file = shift; + + # Make a storage location for the package + my $storage = WebGUI::Storage->createTemp( $session ); + $storage->addFileFromFilesystem( $file ); + + # Import the package into the import node + WebGUI::Asset->getImportNode($session)->importPackage( $storage ); + + # Make the package not a package anymore +} + +#---------------------------------------------------------------------------- +# Add a template from a file +sub addTemplate { + my $session = shift; + my $file = shift; + my $newFolder = shift; + + open(FILE,"<",$file); + my $first = 1; + my $create = 0; + my $head = 0; + my %properties = (className=>"WebGUI::Asset::Template"); + while (my $line = ) { + if ($first) { + $line =~ m/^\#(.*)$/; + $properties{id} = $1; + $first = 0; + } + elsif ($line =~ m/^\#create$/) { + $create = 1; + } + elsif ($line =~ m/^\#(.*):(.*)$/) { + $properties{$1} = $2; + } + elsif ($line =~ m/^~~~$/) { + $head = 1; + } + elsif ($head) { + $properties{headBlock} .= $line; + } + else { + $properties{template} .= $line; + } + } + close(FILE); + if ($create) { + $$newFolder = createNewTemplatesFolder(WebGUI::Asset->getImportNode($session)) + unless (defined $$newFolder); + my $template = $$newFolder->addChild(\%properties, $properties{id}); + } + else { + my $template = WebGUI::Asset->new($session,$properties{id}, "WebGUI::Asset::Template"); + if (defined $template) { + my $newRevision = $template->addRevision(\%properties); + } + } +} #------------------------------------------------- sub start { @@ -63,49 +128,24 @@ sub finish { #------------------------------------------------- sub updateTemplates { - my $session = shift; - return undef unless (-d "templates-".$toVersion); - print "\tUpdating templates.\n" unless ($quiet); - opendir(DIR,"templates-".$toVersion); - my @files = readdir(DIR); - closedir(DIR); - my $importNode = WebGUI::Asset->getImportNode($session); - my $newFolder = undef; - foreach my $file (@files) { - next unless ($file =~ /\.tmpl$/); - open(FILE,""WebGUI::Asset::Template"); - while (my $line = ) { - if ($first) { - $line =~ m/^\#(.*)$/; - $properties{id} = $1; - $first = 0; - } elsif ($line =~ m/^\#create$/) { - $create = 1; - } elsif ($line =~ m/^\#(.*):(.*)$/) { - $properties{$1} = $2; - } elsif ($line =~ m/^~~~$/) { - $head = 1; - } elsif ($head) { - $properties{headBlock} .= $line; - } else { - $properties{template} .= $line; - } - } - close(FILE); - if ($create) { - $newFolder = createNewTemplatesFolder($importNode) unless (defined $newFolder); - my $template = $newFolder->addChild(\%properties, $properties{id}); - } else { - my $template = WebGUI::Asset->new($session,$properties{id}, "WebGUI::Asset::Template"); - if (defined $template) { - my $newRevision = $template->addRevision(\%properties); - } - } - } + my $session = shift; + return undef unless (-d "templates-".$toVersion); + print "\tUpdating templates.\n" unless ($quiet); + opendir(DIR,"templates-".$toVersion); + my @files = readdir(DIR); + closedir(DIR); + my $newFolder = undef; + foreach my $file (@files) { + next unless ($file =~ /\.(tmpl|wgpkg)$/); + my $type = $1; + $file = "templates-" . $toVersion . "/" . $file; + if ($type eq "tmpl") { + addTemplate( $session, $file, \$newFolder ); + } + elsif ($type eq "wgpkg") { + addPackage( $session, $file ); + } + } } #------------------------------------------------- diff --git a/docs/upgrades/templates-7.5.0/root_import_gallery-templates-2.wgpkg b/docs/upgrades/templates-7.5.0/root_import_gallery-templates-2.wgpkg new file mode 100644 index 000000000..8b71ce9d9 Binary files /dev/null and b/docs/upgrades/templates-7.5.0/root_import_gallery-templates-2.wgpkg differ diff --git a/docs/upgrades/upgrade_7.4.10-7.5.0.pl b/docs/upgrades/upgrade_7.4.10-7.5.0.pl index 11518cb43..a26c629e9 100644 --- a/docs/upgrades/upgrade_7.4.10-7.5.0.pl +++ b/docs/upgrades/upgrade_7.4.10-7.5.0.pl @@ -112,8 +112,9 @@ sub installGalleryAlbumAsset { CREATE TABLE IF NOT EXISTS GalleryAlbum ( assetId VARCHAR(22) BINARY NOT NULL, revisionDate BIGINT NOT NULL, - othersCanAdd INT, allowComments INT, + assetIdThumbnail VARCHAR(22) BINARY, + othersCanAdd INT, PRIMARY KEY (assetId, revisionDate) ) ENDSQL @@ -142,24 +143,29 @@ CREATE TABLE IF NOT EXISTS Gallery ( templateIdAddArchive VARCHAR(22) BINARY, templateIdDeleteAlbum VARCHAR(22) BINARY, templateIdDeleteFile VARCHAR(22) BINARY, + templateIdEditAlbum VARCHAR(22) BINARY, templateIdEditFile VARCHAR(22) BINARY, templateIdListAlbums VARCHAR(22) BINARY, templateIdListAlbumsRss VARCHAR(22) BINARY, - templateIdListUserFiles VARCHAR(22) BINARY, - templateIdListUserFilesRss VARCHAR(22) BINARY, + templateIdListFilesForUser VARCHAR(22) BINARY, + templateIdListFilesForUserRss VARCHAR(22) BINARY, templateIdMakeShortcut VARCHAR(22) BINARY, templateIdSearch VARCHAR(22) BINARY, - templateIdSlideshow VARCHAR(22) BINARY, - templateIdThumbnails VARCHAR(22) BINARY, + templateIdViewSlideshow VARCHAR(22) BINARY, + templateIdViewThumbnails VARCHAR(22) BINARY, templateIdViewAlbum VARCHAR(22) BINARY, templateIdViewAlbumRss VARCHAR(22) BINARY, templateIdViewFile VARCHAR(22) BINARY, + viewAlbumAssetId VARCHAR(22), + viewDefault ENUM('album','list'), + viewListOrderBy VARCHAR(40), + viewListOrderDirection ENUM('ASC','DESC'), workflowIdCommit VARCHAR(22) BINARY, PRIMARY KEY (assetId, revisionDate) ) ENDSQL - + $session->config->addToArray("assets","WebGUI::Asset::Wobject::Gallery"); print "DONE!\n" unless $quiet; } @@ -177,8 +183,8 @@ CREATE TABLE IF NOT EXISTS Photo ( revisionDate BIGINT NOT NULL, exifData LONGTEXT, friendsOnly INT, + location VARCHAR(255), rating INT, - storageIdPhoto VARCHAR(22) BINARY, userDefined1 TEXT, userDefined2 TEXT, userDefined3 TEXT, @@ -215,7 +221,71 @@ ENDSQL } -# ---- DO NOT EDIT BELOW THIS LINE ---- +# --------------- DO NOT EDIT BELOW THIS LINE -------------------------------- + +#---------------------------------------------------------------------------- +# Add a package to the import node +sub addPackage { + my $session = shift; + my $file = shift; + + # Make a storage location for the package + my $storage = WebGUI::Storage->createTemp( $session ); + $storage->addFileFromFilesystem( $file ); + + # Import the package into the import node + WebGUI::Asset->getImportNode($session)->importPackage( $storage ); + + # Make the package not a package anymore +} + +#---------------------------------------------------------------------------- +# Add a template from a file +sub addTemplate { + my $session = shift; + my $file = shift; + my $newFolder = shift; + + open(FILE,"<",$file); + my $first = 1; + my $create = 0; + my $head = 0; + my %properties = (className=>"WebGUI::Asset::Template"); + while (my $line = ) { + if ($first) { + $line =~ m/^\#(.*)$/; + $properties{id} = $1; + $first = 0; + } + elsif ($line =~ m/^\#create$/) { + $create = 1; + } + elsif ($line =~ m/^\#(.*):(.*)$/) { + $properties{$1} = $2; + } + elsif ($line =~ m/^~~~$/) { + $head = 1; + } + elsif ($head) { + $properties{headBlock} .= $line; + } + else { + $properties{template} .= $line; + } + } + close(FILE); + if ($create) { + $$newFolder = createNewTemplatesFolder(WebGUI::Asset->getImportNode($session)) + unless (defined $$newFolder); + my $template = $$newFolder->addChild(\%properties, $properties{id}); + } + else { + my $template = WebGUI::Asset->new($session,$properties{id}, "WebGUI::Asset::Template"); + if (defined $template) { + my $newRevision = $template->addRevision(\%properties); + } + } +} #------------------------------------------------- sub start { @@ -244,49 +314,24 @@ sub finish { #------------------------------------------------- sub updateTemplates { - my $session = shift; - return undef unless (-d "templates-".$toVersion); - print "\tUpdating templates.\n" unless ($quiet); - opendir(DIR,"templates-".$toVersion); - my @files = readdir(DIR); - closedir(DIR); - my $importNode = WebGUI::Asset->getImportNode($session); - my $newFolder = undef; - foreach my $file (@files) { - next unless ($file =~ /\.tmpl$/); - open(FILE,""WebGUI::Asset::Template"); - while (my $line = ) { - if ($first) { - $line =~ m/^\#(.*)$/; - $properties{id} = $1; - $first = 0; - } elsif ($line =~ m/^\#create$/) { - $create = 1; - } elsif ($line =~ m/^\#(.*):(.*)$/) { - $properties{$1} = $2; - } elsif ($line =~ m/^~~~$/) { - $head = 1; - } elsif ($head) { - $properties{headBlock} .= $line; - } else { - $properties{template} .= $line; - } - } - close(FILE); - if ($create) { - $newFolder = createNewTemplatesFolder($importNode) unless (defined $newFolder); - my $template = $newFolder->addChild(\%properties, $properties{id}); - } else { - my $template = WebGUI::Asset->new($session,$properties{id}, "WebGUI::Asset::Template"); - if (defined $template) { - my $newRevision = $template->addRevision(\%properties); - } - } - } + my $session = shift; + return undef unless (-d "templates-".$toVersion); + print "\tUpdating templates.\n" unless ($quiet); + opendir(DIR,"templates-".$toVersion); + my @files = readdir(DIR); + closedir(DIR); + my $newFolder = undef; + foreach my $file (@files) { + next unless ($file =~ /\.(tmpl|wgpkg)$/); + my $type = $1; + $file = "templates-" . $toVersion . "/" . $file; + if ($type eq "tmpl") { + addTemplate( $session, $file, \$newFolder ); + } + elsif ($type eq "wgpkg") { + addPackage( $session, $file ); + } + } } #------------------------------------------------- diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index bddd26f20..3e9ffbe4e 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -14,6 +14,8 @@ package WebGUI::Asset; =cut +use Carp qw( croak confess ); + use WebGUI::AssetBranch; use WebGUI::AssetClipboard; use WebGUI::AssetExportHtml; @@ -1336,12 +1338,12 @@ Loads an asset module if it's not already in memory. This is a class method. Ret sub loadModule { my ($class, $session, $className) = @_; - (my $module = $className . '.pm') =~ s{::|'}{/}g; + (my $module = $className . '.pm') =~ s{::|'}{/}g; if (eval { require $module; 1 }) { return $className; } - $session->errorHandler->error("Couldn't compile asset package: ".$className.". Root cause: ".$@); - return; + $session->errorHandler->error("Couldn't compile asset package: ".$className.". Root cause: ".$@); + return; } #------------------------------------------------------------------- @@ -1752,6 +1754,7 @@ A specific revision date for the asset to retrieve. If not specified, the most r sub newByDynamicClass { my $class = shift; my $session = shift; + confess "newByDynamicClass requires WebGUI::Session" unless $session; my $assetId = shift; my $revisionDate = shift; return undef unless defined $assetId; @@ -1895,6 +1898,7 @@ sub processPropertiesFromFormPost { $self->session->db->beginTransaction; $self->update(\%data); $self->session->db->commit; + return; } @@ -2082,6 +2086,9 @@ Updates the properties of an existing revision. If you want to create a new revi Hash reference of properties and values to set. +NOTE: C is a special property that uses the WebGUI::Keyword API +to set the keywords for this asset. + =cut sub update { diff --git a/lib/WebGUI/Asset/File.pm b/lib/WebGUI/Asset/File.pm index f58f7472f..4926fd559 100644 --- a/lib/WebGUI/Asset/File.pm +++ b/lib/WebGUI/Asset/File.pm @@ -55,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 = $self->getStorageClass->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; } #------------------------------------------------------------------- @@ -173,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=>'

'.$self->get( '.$self->get("filename").'

' - ); + 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( + ''.$i18n->get('new file').'' + . $self->getEditFormUploadControl + . '' + ); + + 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 => '

'.$self->get( '.$self->get("filename").'

' + }); + } + + # 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; } @@ -200,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")); } @@ -246,6 +273,7 @@ sub getStorageFromPost { my $self = shift; my $storageId = shift; my $fileStorageId = WebGUI::Form::File->new($self->session, {name => 'newFile', value=>$storageId })->getValueFromPost; + $self->session->errorHandler->info( "File Storage Id: $fileStorageId" ); return $self->getStorageClass->get($self->session, $fileStorageId); } @@ -295,45 +323,21 @@ sub prepareView { #------------------------------------------------------------------- sub processPropertiesFromFormPost { - my $self = shift; - my $session = $self->session; + my $self = shift; + my $session = $self->session; - my $errors = $self->SUPER::processPropertiesFromFormPost; - return $errors if $errors; - - #Get the storage location out of memory. If you call getStorageLocation you risk creating another one. - # How can this EVER be true? - my $storageLocation = $self->{_storageLocation}; - $session->errorHandler->error("Storage Location set magically") if defined $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 $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; } @@ -421,18 +425,18 @@ sub setSize { #------------------------------------------------------------------- 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} = $self->getStorageClass->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} = $self->getStorageClass->get($self->session,$self->get("storageId")); - } + $self->{_storageLocation} = $self->getStorageClass->get($self->session,$self->get("storageId")); + } } #------------------------------------------------------------------- @@ -475,9 +479,11 @@ 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; } #------------------------------------------------------------------- diff --git a/lib/WebGUI/Asset/File/Image/Photo.pm b/lib/WebGUI/Asset/File/Image/Photo.pm index ccbf0dd44..568282979 100644 --- a/lib/WebGUI/Asset/File/Image/Photo.pm +++ b/lib/WebGUI/Asset/File/Image/Photo.pm @@ -22,19 +22,7 @@ use Image::ExifTool qw( :Public ); use JSON; use Tie::IxHash; -our $magick; -BEGIN { - if (eval { require Graphics::Magick; 1 }) { - $magick = 'Graphics::Magick'; - } - elsif (eval { require Image::Magick; 1 }) { - $magick = 'Image::Magick'; - } - else { - croak "You must have either Graphics::Magick or Image::Magick installed to run WebGUI.\n"; - } -} - +use WebGUI::DateTime; use WebGUI::Friends; use WebGUI::Utility; @@ -50,7 +38,6 @@ WebGUI::Asset::File::Image::Photo use WebGUI::Asset::File::Image::Photo - =head1 METHODS These methods are available from this class: @@ -72,15 +59,18 @@ sub definition { my $i18n = __PACKAGE__->i18n($session); tie my %properties, 'Tie::IxHash', ( + exifData => { + defaultValue => undef, + }, friendsOnly => { defaultValue => 0, }, + location => { + defaultValue => undef, + }, rating => { defaultValue => 0, }, - storageIdPhoto => { - defaultValue => undef, - }, ); # UserDefined Fields @@ -91,12 +81,13 @@ sub definition { } push @{$definition}, { - assetName => $i18n->get('assetName'), - icon => 'Image.gif', - tableName => 'Photo', - className => 'WebGUI::Asset::File::Image::Photo', - i18n => 'Asset_Photo', - properties => \%properties, + assetName => $i18n->get('assetName'), + autoGenerateForms => 0, + icon => 'Image.gif', + tableName => 'Photo', + className => 'WebGUI::Asset::File::Image::Photo', + i18n => 'Asset_Photo', + properties => \%properties, }; return $class->SUPER::definition($session, $definition); @@ -114,14 +105,27 @@ reference. Returns the hash reference for convenience. sub appendTemplateVarsForCommentForm { my $self = shift; my $var = shift; + my $session = $self->session; - $var->{commentForm_start} - = WebGUI::Form::formHeader( $session ); + $var->{ commentForm_start } + = WebGUI::Form::formHeader( $session ) . WebGUI::Form::hidden( $session, { name => "func", value => "addCommentSave" } ) ; - $var->{commentForm_end} + $var->{ commentForm_end } = WebGUI::Form::formFooter( $session ); + $var->{ commentForm_bodyText } + = WebGUI::Form::HTMLArea( $session, { + name => "bodyText", + richEditId => $self->getGallery->get("richEditIdComment"), + }); + + $var->{ commentForm_submit } + = WebGUI::Form::submit( $session, { + name => "submit", + value => "Save Comment", + }); + return $var; } @@ -143,14 +147,14 @@ sub applyConstraints { my $self = shift; my $gallery = $self->getGallery; - $self->makeResolutions(); - $self->updateExifDataFromFile(); - # Update the asset's size and make a thumbnail $self->SUPER::applyConstraints({ maxImageSize => $self->getGallery->get("imageViewSize"), thumbnailSize => $self->getGallery->get("imageThumbnailSize"), }); + + $self->makeResolutions(); + $self->updateExifDataFromFile(); } #---------------------------------------------------------------------------- @@ -247,6 +251,19 @@ sub deleteComment { #---------------------------------------------------------------------------- +=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 is the ID of the comment to get. Returns @@ -292,6 +309,7 @@ Get a WebGUI::Paginator for the comments for this Photo. sub getCommentPaginator { my $self = shift; + my $session = $self->session; my $p = WebGUI::Paginator->new($session, $self->getUrl); $p->setDataByQuery( @@ -366,10 +384,37 @@ Get a hash reference of template variables shared by all views of this asset. sub getTemplateVars { my $self = shift; + my $session = $self->session; my $var = $self->get; + my $owner = WebGUI::User->new( $session, $self->get("ownerUserId") ); + $var->{ canComment } = $self->canComment; + $var->{ canEdit } = $self->canEdit; + $var->{ numberOfComments } = scalar @{ $self->getCommentIds }; + $var->{ ownerUsername } = $owner->username; + $var->{ url } = $self->getUrl; + $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'); + + $var->{ fileUrl } = $self->getFileUrl; + $var->{ thumbnailUrl } = $self->getThumbnailUrl; + + ### Download resolutions + for my $resolution ( $self->getResolutions ) { + push @{ $var->{ resolutions_loop } }, { + url_download => $self->getStorageLocation->getPathFrag($resolution) + }; + } + ### Format exif vars my $exif = jsonToObj( delete $var->{exifData} ); + $exif = ImageInfo( $self->getStorageLocation->getPath( $self->get("filename") ) ); for my $tag ( keys %$exif ) { # Hash of exif_tag => value $var->{ "exif_" . $tag } = $exif->{$tag}; @@ -428,6 +473,7 @@ contained in. sub makeResolutions { my $self = shift; my $resolutions = shift; + my $error; croak "Photo->makeResolutions: resolutions must be an array reference" if $resolutions && ref $resolutions ne "ARRAY"; @@ -435,15 +481,14 @@ sub makeResolutions { # Get default if necessary $resolutions ||= $self->getGallery->getImageResolutions; - my $storage = $self->getStorageLocation; - my $photo = $magick->new; - $photo->Read( $storage->get( $self->get("filename") ) ); + my $storage = $self->getStorageLocation; + $self->session->errorHandler->info(" Making resolutions for '" . $self->get("filename") . q{'}); for my $res ( @$resolutions ) { # carp if resolution is bad - my $newPhoto = $photo->Clone; - $newPhoto->Resize( geometry => $res ); - $newPhoto->Write( $storage->getFilePath( "$res.jpg" ) ); + my $newFilename = $res . ".jpg"; + $storage->copyFile( $self->get("filename"), $newFilename ); + $storage->resize( $newFilename, $res ); } } @@ -512,8 +557,12 @@ sub prepareView { sub processPropertiesFromFormPost { my $self = shift; my $errors = $self->SUPER::processPropertiesFromFormPost || []; + + # Return if errors + return $errors if @$errors; - + # Passes all checks + $self->requestAutoCommit; } #---------------------------------------------------------------------------- @@ -566,7 +615,9 @@ sub updateExifDataFromFile { my $self = shift; my $storage = $self->getStorageLocation; - my $info = ImageInfo( $storage->getFilePath( $self->get('filename') ) ); + return; + my $info = ImageInfo( $storage->getPath( $self->get('filename') ) ); + use Data::Dumper; $self->session->errorHandler->info( Dumper $info ); $self->update({ exifData => objToJson( $info ), }); @@ -584,16 +635,19 @@ sub view { my $self = shift; my $session = $self->session; my $var = $self->getTemplateVars; - $var->{ controls } = $self->getToolbar; - $var->{ fileUrl } = $self->getFileUrl; - $var->{ fileIcon } = $self->getFileIconUrl; $self->appendTemplateVarsForCommentForm( $var ); my $p = $self->getCommentPaginator; - $var->{ commentLoop } = $p->getPageData; - $var->{ commentLoop_urlNext } = [$p->getNextPageLink]->[0]; - $var->{ commentLoop_urlPrev } = [$p->getPrevPageLink]->[0]; + for my $comment ( @{ $p->getPageData } ) { + 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}); @@ -609,14 +663,15 @@ Save a new comment to the Photo. sub www_addCommentSave { my $self = shift; + my $session = $self->session; - return $self->session->privilege->insufficient unless $self->canComment; + return $session->privilege->insufficient unless $self->canComment; - my $form = $self->session; + my $form = $self->session->form; my $properties = { assetId => $self->getId, - creationDate => time, + creationDate => WebGUI::DateTime->new( $session, time )->toDatabase, userId => $session->user->userId, visitorIp => ( $session->user->userId eq "1" ? $session->env("REMOTE_ADDR") : undef ), bodyText => $form->get("bodyText"), @@ -638,14 +693,17 @@ this Photo exists in. sub www_delete { my $self = shift; + my $session = $self->session; return $self->session->privilege->insufficient unless $self->canEdit; - my $var = $self->getTemplateVar; + 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("templateIdDeletePhoto") ) + $self->processTemplate( $var, $self->getGallery->get("templateIdDeleteFile") ) ); } @@ -663,7 +721,7 @@ sub www_deleteConfirm { return $self->session->privilege->insufficient unless $self->canEdit; - my $i18n = $self->i18n( $self->session ); + my $i18n = __PACKAGE__->i18n( $self->session ); $self->purge; @@ -674,6 +732,25 @@ sub www_deleteConfirm { #---------------------------------------------------------------------------- +=head2 www_demote + +Override the default demote page to send the user back to the GalleryAlbum +edit screen. + +=cut + +sub www_demote { + my $self = shift; + + return $self->session->privilege->insufficient unless $self->canEdit; + + $self->demote; + + return $self->session->asset( $self->getParent )->www_edit; +} + +#---------------------------------------------------------------------------- + =head2 www_download Download the Photo with the specified resolution. If no resolution specified, @@ -719,10 +796,36 @@ sub www_edit { return $self->session->privilege->locked unless $self->canEditIfLocked; # Prepare the template variables - my $var = $self->getTemplateVars; + my $var = { + url_addArchive => $self->getParent->getUrl('func=addArchive'), + }; - $var->{ form_header } = WebGUI::Form::formHeader( $session ); - $var->{ form_footer } = WebGUI::Form::formFooter( $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_submit } + = WebGUI::Form::submit( $session, { + name => "submit", + value => "Save", + }); $var->{ form_title } = WebGUI::Form::Text( $session, { @@ -737,12 +840,7 @@ sub www_edit { richEditId => $self->getGallery->get("assetIdRichEditFile"), }); - $var->{ form_storageIdPhoto } - = WebGUI::Form::Image( $session, { - name => "storageIdPhoto", - value => ( $form->get("storageIdPhoto") || $self->get("storageIdPhoto") ), - maxAttachments => 1, - }); + $var->{ form_photo } = $self->getEditFormUploadControl; $var->{ form_keywords } = WebGUI::Form::Text( $session, { @@ -771,6 +869,23 @@ sub www_edit { #---------------------------------------------------------------------------- +=head2 www_editSave ( ) + +Save the edit form. Overridden to display a confirm message to the user. + +=cut + +sub www_editSave { + my $self = shift; + $self->SUPER::www_editSave; + + my $i18n = __PACKAGE__->i18n( $self->session ); + + sprintf $i18n->get("save message"), $self->getUrl, +} + +#---------------------------------------------------------------------------- + =head2 www_makeShortcut ( ) Display the form to make a shortcut. @@ -781,24 +896,27 @@ This page is only available to those who can edit this Photo. 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_header } + $var->{ form_start } = WebGUI::Form::formHeader( $session ) . WebGUI::Form::hidden( $session, { name => "func", value => "makeShortcutSave" }); - $var->{ form_footer } + $var->{ form_end } = WebGUI::Form::formFooter( $session ); # Albums under this Gallery my $albums = $self->getGallery->getAlbumIds; my %albumOptions; for my $assetId ( @$albums ) { - $albumOptions{ $assetId } - = WebGUI::Asset->newByDynamicClass($session, $assetId)->get("title"); + my $asset = WebGUI::Asset->newByDynamicClass($session, $assetId); + if ($asset->canAddFile) { + $albumOptions{ $assetId } = $asset->get("title"); + } } $var->{ form_parentId } = WebGUI::Form::selectBox( $session, { @@ -827,7 +945,8 @@ sub www_makeShortcutSave { 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; @@ -835,6 +954,46 @@ sub www_makeShortcutSave { #---------------------------------------------------------------------------- +=head2 www_promote + +Override the default promote page to send the user back to the GalleryAlbum +edit screen. + +=cut + +sub www_promote { + my $self = shift; + + return $self->session->privilege->insufficient unless $self->canEdit; + + $self->promote; + + return $self->session->asset( $self->getParent )->www_edit; +} + +#---------------------------------------------------------------------------- + +=head2 www_showConfirmation ( ) + +Shows the confirmation message after adding / editing a gallery album. +Provides links to view the photo and add more photos. + +=cut + +sub www_showConfirmation { + my $self = shift; + my $i18n = __PACKAGE__->i18n( $self->session ); + + return $self->processStyle( + sprintf( $i18n->get('save message'), + $self->getUrl, + $self->getParent->getUrl('func=add;className='.__PACKAGE__), + ) + ); +} + +#---------------------------------------------------------------------------- + =head2 www_view ( ) Shows the output of L inside of the style provided by the gallery this @@ -857,6 +1016,5 @@ sub www_view { $self->session->output->print($foot, 1); return "chunked"; } -} 1; diff --git a/lib/WebGUI/Asset/Shortcut.pm b/lib/WebGUI/Asset/Shortcut.pm index 5d6410d88..f24e88126 100644 --- a/lib/WebGUI/Asset/Shortcut.pm +++ b/lib/WebGUI/Asset/Shortcut.pm @@ -593,6 +593,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; diff --git a/lib/WebGUI/Asset/Wobject/Gallery.pm b/lib/WebGUI/Asset/Wobject/Gallery.pm index 1133f0c6a..3bbbdb3cc 100644 --- a/lib/WebGUI/Asset/Wobject/Gallery.pm +++ b/lib/WebGUI/Asset/Wobject/Gallery.pm @@ -24,16 +24,14 @@ use base 'WebGUI::Asset::Wobject'; =head1 SYNOPSIS +=head1 DIAGNOSTICS + =head1 METHODS #------------------------------------------------------------------- =head2 definition ( ) -defines wobject properties for New Wobject instances. You absolutely need -this method in your new Wobjects. If you choose to "autoGenerateForms", the -getEditForm method is unnecessary/redundant/useless. - =cut sub definition { @@ -51,6 +49,23 @@ sub definition { '1600' => '1600', '2880' => '2880', ); + + tie my %viewDefaultOptions, 'Tie::IxHash', ( + list => $i18n->get("viewDefault option list"), + album => $i18n->get("viewDefault option album"), + ); + + tie my %viewListOrderByOptions, 'Tie::IxHash', ( + creationDate => $i18n->get("viewListOrderBy option creationDate"), + lineage => $i18n->get("viewListOrderBy option lineage"), + revisionDate => $i18n->get("viewListOrderBy option revisionDate"), + title => $i18n->get("viewListOrderBy option title"), + ); + + tie my %viewListOrderDirectionOptions, 'Tie::IxHash', ( + ASC => $i18n->get("viewListOrderDirection option asc"), + DESC => $i18n->get("viewListOrderDirection option desc"), + ); tie my %properties, 'Tie::IxHash', ( groupIdAddComment => { @@ -77,7 +92,7 @@ sub definition { imageResolutions => { tab => "properties", fieldType => "checkList", - defaultValue => ['800', '1024', '1200', '1600', '2880'], + defaultValue => join("\n", '800', '1024', '1200', '1600', '2880'), options => \%imageResolutionOptions, label => $i18n->get("imageResolutions label"), hoverHelp => $i18n->get("imageResolutions description"), @@ -85,14 +100,14 @@ sub definition { imageViewSize => { tab => "properties", fieldType => "integer", - defaultValue => 0, + defaultValue => 700, label => $i18n->get("imageViewSize label"), hoverHelp => $i18n->get("imageViewSize description"), }, imageThumbnailSize => { tab => "properties", fieldType => "integer", - defaultValue => 0, + defaultValue => 300, label => $i18n->get("imageThumbnailSize label"), hoverHelp => $i18n->get("imageThumbnailSize description"), }, @@ -106,7 +121,7 @@ sub definition { richEditIdComment => { tab => "properties", fieldType => "selectRichEditor", - defaultValue => undef, # Rich Editor for Posts + defaultValue => "PBrichedit000000000002", # Forum Rich Editor label => $i18n->get("richEditIdFileComment label"), hoverHelp => $i18n->get("richEditIdFileComment description"), }, @@ -134,6 +149,14 @@ sub definition { label => $i18n->get("templateIdDeleteFile label"), hoverHelp => $i18n->get("templateIdDeleteFile description"), }, + templateIdEditAlbum => { + tab => "display", + fieldType => "template", + defaultValue => "", + namespace => "GalleryAlbum/Edit", + label => $i18n->get("templateIdEditAlbum label"), + hoverHelp => $i18n->get("templateIdEditAlbum description"), + }, templateIdEditFile => { tab => "display", fieldType => "template", @@ -158,21 +181,21 @@ sub definition { label => $i18n->get("templateIdListAlbumsRss label"), hoverHelp => $i18n->get("templateIdListAlbumsRss description"), }, - templateIdListUserFiles => { + templateIdListFilesForUser => { tab => "display", fieldType => "template", defaultValue => "", - namespace => "Gallery/ListUserFiles", - label => $i18n->get("templateIdListUserFiles label"), - hoverHelp => $i18n->get("templateIdListUserFiles description"), + namespace => "Gallery/ListFilesForUser", + label => $i18n->get("templateIdListFilesForUser label"), + hoverHelp => $i18n->get("templateIdListFilesForUser description"), }, - templateIdListUserFilesRss => { + templateIdListFilesForUserRss => { tab => "display", fieldType => "template", defaultValue => "", - namespace => "Gallery/ListUserFilesRss", - label => $i18n->get("templateIdListUserFilesRss label"), - hoverHelp => $i18n->get("templateIdListUserFilesRss description"), + namespace => "Gallery/ListFilesForUserRss", + label => $i18n->get("templateIdListFilesForUserRss label"), + hoverHelp => $i18n->get("templateIdListFilesForUserRss description"), }, templateIdMakeShortcut => { tab => "display", @@ -190,21 +213,21 @@ sub definition { label => $i18n->get("templateIdSearch label"), hoverHelp => $i18n->get("templateIdSearch description"), }, - templateIdSlideshow => { + templateIdViewSlideshow => { tab => "display", fieldType => "template", defaultValue => "", - namespace => "GalleryAlbum/Slideshow", - label => $i18n->get("templateIdSlideshow label"), - hoverHelp => $i18n->get("templateIdSlideshow description"), + namespace => "GalleryAlbum/ViewSlideshow", + label => $i18n->get("templateIdViewSlideshow label"), + hoverHelp => $i18n->get("templateIdViewSlideshow description"), }, - templateIdThumbnails => { + templateIdViewThumbnails => { tab => "display", fieldType => "template", defaultValue => "", - namespace => "GalleryAlbum/Thumbnails", - label => $i18n->get("templateIdThumbnails label"), - hoverHelp => $i18n->get("templateIdThumbnails description"), + namespace => "GalleryAlbum/ViewThumbnails", + label => $i18n->get("templateIdViewThumbnails label"), + hoverHelp => $i18n->get("templateIdViewThumbnails description"), }, templateIdViewAlbum => { tab => "display", @@ -230,6 +253,37 @@ sub definition { label => $i18n->get("templateIdViewFile label"), hoverHelp => $i18n->get("templateIdViewFile description"), }, + viewDefault => { + tab => "display", + fieldType => "selectBox", + defaultValue => "list", + options => \%viewDefaultOptions, + label => $i18n->get("viewDefault label"), + hoverHelp => $i18n->get("viewDefault description"), + }, + viewAlbumAssetId => { + tab => "display", + fieldType => "asset", + class => "WebGUI::Asset::Wobject::GalleryAlbum", + label => $i18n->get("viewAlbumAssetId label"), + hoverHelp => $i18n->get("viewAlbumAssetId description"), + }, + viewListOrderBy => { + tab => "display", + fieldType => "selectBox", + defaultValue => "lineage", # "Sequence Number" + options => \%viewListOrderByOptions, + label => $i18n->get("viewListOrderBy label"), + hoverHelp => $i18n->get("viewListOrderBy description"), + }, + viewListOrderDirection => { + tab => "display", + fieldType => "selectBox", + defaultValue => "ASC", + options => \%viewListOrderDirectionOptions, + label => $i18n->get("viewListOrderDirection label"), + hoverHelp => $i18n->get("viewListOrderDirection description"), + }, workflowIdCommit => { tab => "security", fieldType => "workflow", @@ -254,6 +308,91 @@ sub definition { #---------------------------------------------------------------------------- +=head2 appendTemplateVarsSearchForm ( var ) + +Appends the template vars for the search form to the hash reference C. +Returns the hash reference for convenience. + +=cut + +sub appendTemplateVarsSearchForm { + my $self = shift; + my $var = shift; + my $session = $self->session; + my $form = $self->session->form; + my $i18n = WebGUI::International->new($session, 'Asset_Gallery'); + + $var->{ searchForm_start } + = WebGUI::Form::formHeader( $session, { + action => $self->getUrl('func=search'), + method => "GET", + }); + + $var->{ searchForm_end } + = WebGUI::Form::formFooter( $session ); + + $var->{ searchForm_basicSearch } + = WebGUI::Form::text( $session, { + name => "basicSearch", + value => $form->get("basicSearch"), + }); + + $var->{ searchForm_title } + = WebGUI::Form::text( $session, { + name => "title", + value => $form->get("title"), + }); + + $var->{ searchForm_description } + = WebGUI::Form::text( $session, { + name => "description", + value => $form->get("description"), + }); + + $var->{ searchForm_keywords } + = WebGUI::Form::text( $session, { + name => "keywords", + value => $form->get("keywords"), + }); + + # Search classes + tie my %searchClassOptions, 'Tie::IxHash', ( + 'WebGUI::Asset::File::Image::Photo' => $i18n->get("search class photo"), + 'WebGUI::Asset::Wobject::GalleryAlbum' => $i18n->get("search class galleryalbum"), + '' => $i18n->get("search class any"), + ); + $var->{ searchForm_className } + = WebGUI::Form::radioList( $session, { + name => "className", + value => $form->get("className"), + options => \%searchClassOptions, + }); + + # Search creationDate + my $oneYearAgo = WebGUI::DateTime->new( $session, time )->add( years => -1 )->epoch; + $var->{ searchForm_creationDate_after } + = WebGUI::Form::dateTime( $session, { + name => "creationDate_after", + value => $form->get("creationDate_after","dateTime") || $oneYearAgo, + }); + $var->{ searchForm_creationDate_before } + = WebGUI::Form::dateTime( $session, { + name => "creationDate_before", + value => $form->get("creationDate_before","dateTime"), + }); + + # Buttons + $var->{ searchForm_submit } + = WebGUI::Form::submit( $session, { + name => "submit", + value => $i18n->get("search submit"), + }); + + return $var; +} + +#---------------------------------------------------------------------------- + =head2 canAddFile ( [userId] ) Returns true if the user can add files to this Gallery. C is the @@ -356,23 +495,33 @@ Gets an array reference of all the album IDs under this Gallery. sub getAlbumIds { my $self = shift; - return $self->getLineage(['descendants'], { - includeOnlyClasses => ['WebGUI::Asset::Wobject::GalleryAlbum'], - }); + my $assets + = $self->getLineage(['descendants'], { + includeOnlyClasses => ['WebGUI::Asset::Wobject::GalleryAlbum'], + }); + + return $assets; } #---------------------------------------------------------------------------- -=head2 getAlbumPaginator ( ) +=head2 getAlbumPaginator ( options ) -Gets a WebGUI::Paginator for all the albums in this Gallery. +Gets a WebGUI::Paginator for all the albums in this Gallery. C is a +hash reference with the following keys. + + perpage => The number of results to show per page. Default: 20 =cut sub getAlbumPaginator { my $self = shift; + my $options = shift; + + my $perpage = $options->{ perpage } || 20; - my $p = WebGUI::Paginator->new( $self->session, $self->getUrl ); + my $p + = WebGUI::Paginator->new( $self->session, $self->getUrl, $perpage ); $p->setDataByArrayRef( $self->getAlbumIds ); return $p; @@ -392,7 +541,7 @@ sub getAssetClassForFile { my $filepath = shift; # Checks for Photo assets - if ( $filepath =~ /\.(jpe?g|gif|png)/i ) { + if ( $filepath =~ /\.(jpe?g|gif|png)$/i ) { return "WebGUI::Asset::File::Image::Photo"; } @@ -416,9 +565,9 @@ sub getImageResolutions { #---------------------------------------------------------------------------- -=head2 getSearchPaginator ( options ) +=head2 getSearchPaginator ( rules ) -Gets a WebGUI::Paginator for a search. C is a hash reference of +Gets a WebGUI::Paginator for a search. C is a hash reference of options with the following keys: keywords => Keywords to search on @@ -431,11 +580,11 @@ sub getSearchPaginator { my $self = shift; my $rules = shift; - $rules->{ lineage } = $self->get("lineage"); + $rules->{ lineage } = [ $self->get("lineage") ]; my $search = WebGUI::Search->new( $self->session ); $search->search( $rules ); - my $paginator = $search->getPaginatorResultSet( $self->getUrl('func=search') ); + my $paginator = $search->getPaginatorResultSet( $rules->{url} ); return $paginator; } @@ -451,7 +600,7 @@ classes of files inside of a Gallery. =cut -sub getTemplateEditFile { +sub getTemplateIdEditFile { my $self = shift; return $self->get("templateIdEditFile"); } @@ -467,37 +616,25 @@ Gets a hash reference of vars common to all templates. sub getTemplateVars { my $self = shift; my $var = $self->get; + + # Add the search form variables + $self->appendTemplateVarsSearchForm( $var ); + + $var->{ url } = $self->getUrl; + $var->{ url_addAlbum } = $self->getUrl('func=add;class=WebGUI::Asset::Wobject::GalleryAlbum'); + $var->{ url_listAlbums } = $self->getUrl('func=listAlbums'); + $var->{ url_listAlbumsRss } = $self->getUrl('func=listAlbumsRss'); + $var->{ url_listFilesForCurrentUser } = $self->getUrl('func=listFilesForUser'); + $var->{ url_search } = $self->getUrl('func=search'); + + $var->{ canEdit } = $self->canEdit; + $var->{ canAddFile } = $self->canAddFile; return $var; } #---------------------------------------------------------------------------- -=head2 getUserFileIds ( [userId] ) - -Gets an array reference of assetIds for the files in this Gallery owned by -the specified C. If userId is not defined, will use the current user. - -=cut - -sub getUserFileIds { - my $self = shift; - my $userId = shift || $self->session->user->userId; - - my $db = $self->session->db; - - # Note: We use excludeClasses to avoid getting GalleryAlbum assets - my $assetIds - = $self->getLineage( ['descendants'], { - excludeClasses => [ 'WebGUI::Asset::Wobject::GalleryAlbum' ], - whereClause => "ownerUserId = " . $db->quote($userId), - }); - - return $assetIds; -} - -#---------------------------------------------------------------------------- - =head2 getUserAlbumIds ( [userId] ) Gets an array reference of assetIds for the GalleryAlbums in this Gallery @@ -523,6 +660,55 @@ sub getUserAlbumIds { #---------------------------------------------------------------------------- +=head2 getUserFileIds ( [userId] ) + +Gets an array reference of assetIds for the files in this Gallery owned by +the specified C. If userId is not defined, will use the current user. + +=cut + +sub getUserFileIds { + my $self = shift; + my $userId = shift || $self->session->user->userId; + + my $db = $self->session->db; + + # Note: We use excludeClasses to avoid getting GalleryAlbum assets + my $assetIds + = $self->getLineage( ['descendants'], { + excludeClasses => [ 'WebGUI::Asset::Wobject::GalleryAlbum' ], + whereClause => "ownerUserId = " . $db->quote($userId), + }); + + return $assetIds; +} + +#---------------------------------------------------------------------------- + +=head2 getUserFilePaginator ( options ) + +Gets a WebGUI::Paginator for the files owned by a specific C. +C is a hash reference of options with the following keys: + + userId => The user who owns the asset. Defaults to the current user. + url => The URL to give to the paginator + +=cut + +sub getUserFilePaginator { + my $self = shift; + my $options = shift; + my $userId = delete $options->{userId}; + my $url = delete $options->{url}; + + my $p = WebGUI::Paginator->new( $self->session, $url ); + $p->setDataByArrayRef( $self->getUserFileIds( $userId ) ); + + return $p; +} + +#---------------------------------------------------------------------------- + =head2 prepareView ( ) See WebGUI::Asset::prepareView() for details. @@ -532,7 +718,30 @@ See WebGUI::Asset::prepareView() for details. sub prepareView { my $self = shift; $self->SUPER::prepareView(); - my $template = WebGUI::Asset::Template->new($self->session, $self->get("templateId")); + + if ( $self->get("viewDefault") eq "album" ) { + my $asset + = WebGUI::Asset->newByDynamicClass( $self->session, $self->get("viewAlbumAssetId") ); + $asset->prepareView; + $self->{_viewAsset} = $asset; + } + else { + $self->prepareViewListAlbums; + } +} + +#---------------------------------------------------------------------------- + +=head2 prepareViewListAlbums ( ) + +Prepare the template for listing multiple albums. + +=cut + +sub prepareViewListAlbums { + my $self = shift; + my $template + = WebGUI::Asset::Template->new($self->session, $self->get("templateIdListAlbums")); $template->prepare; $self->{_viewTemplate} = $template; } @@ -541,8 +750,7 @@ sub prepareView { =head2 view ( ) -method called by the www_view method. Returns a processed template -to be displayed within the page style. +Show the default view based on the Gallery settings. =cut @@ -551,7 +759,41 @@ sub view { my $session = $self->session; my $var = $self->get; - return $self->processTemplate($var, undef, $self->{_viewTemplate}); + if ( $self->get("viewDefault") eq "album" ) { + return $self->{_viewAsset}->view; + } + else { + return $self->view_listAlbums; + } +} + +#---------------------------------------------------------------------------- + +=head2 view_listAlbums ( ) + +Show a paginated list of the albums in this gallery. This method does the +actual work. + +=cut + +sub view_listAlbums { + my $self = shift; + my $session = $self->session; + my $var = $self->getTemplateVars; + my $form = $self->session->form; + + my $p + = $self->getAlbumPaginator( { + perpage => $form->get('perpage'), + } ); + $p->appendTemplateVars( $var ); + + for my $assetId ( @{ $p->getPageData } ) { + my $asset = WebGUI::Asset->newByDynamicClass( $session, $assetId ); + push @{ $var->{albums} }, $asset->getTemplateVars; + } + + return $self->processTemplate( $var, undef, $self->{_viewTemplate} ); } #---------------------------------------------------------------------------- @@ -565,30 +807,218 @@ Show a paginated list of the albums in this gallery. sub www_listAlbums { my $self = shift; + # Perform the prepareView ourselves + $self->prepareViewListAlbums; + + return $self->processStyle( + $self->view_listAlbums + ); } #---------------------------------------------------------------------------- =head2 www_listAlbumsRss ( ) +Show an RSS feed for the albums in this gallery. + =cut +sub www_listAlbumsRss { + my $self = shift; + my $session = $self->session; + my $var = $self->getTemplateVars; + + for my $assetId ( @{ $self->getAlbumIds } ) { + my $asset = WebGUI::Asset->newByDynamicClass( $session, $assetId ); + my $assetVar = $asset->getTemplateVars; + + # Fix URLs + for my $key ( qw( url ) ) { + $assetVar->{ $key } = $self->session->url->getSiteURL . $assetVar->{ $key }; + } + + # Additional vars for RSS + $assetVar->{ rssDate } + = $session->datetime->epochToMail( $assetVar->{ creationDate } ); + + push @{ $var->{albums} }, $assetVar; + } + + $self->session->http->setMimeType('text/xml'); + return $self->processTemplate( $var, $self->get("templateIdListAlbumsRss") ); +} + #---------------------------------------------------------------------------- =head2 www_search ( ) +Search through the GalleryAlbums and files in this gallery. Show the form to +search and display the results if necessary. + =cut +sub www_search { + my $self = shift; + my $form = $self->session->form; + my $db = $self->session->db; + + my $var = $self->getTemplateVars; + # NOTE: Search form is added as part of getTemplateVars() + + # Get search results, if necessary. + if ($form->get("submit")) { + # Keywords to search on + my $keywords = join " ", $form->get('basicSearch'), + $form->get('keywords'), + $form->get('title'), + $form->get('description') + ; + + # Build a where clause from the advanced options + # Lineage search can capture gallery + my $where = q{assetIndex.assetId <> '} . $self->getId . q{'}; + if ( $form->get("title") ) { + $where .= q{ AND assetData.title LIKE } + . $db->quote( '%' . $form->get("title") . '%' ) + ; + } + if ( $form->get("description") ) { + $where .= q{ AND assetData.synopsis LIKE } + . $db->quote( '%' . $form->get("description") . '%' ) + ; + } + if ( $form->get("className") ) { + $where .= q{ AND asset.className IN ('} + . $db->quoteAndJoin( [$form->get('className','checkList')] ) + . q{)} + ; + } + + # Build a URL for the pagination + my $url + = $self->getUrl( + 'func=search;submit=1;' + . 'basicSearch=' . $form->get('basicSearch') . ';' + . 'keywords=' . $form->get('keywords') . ';' + . 'title=' . $form->get('title') . ';' + . 'description=' . $form->get('description') . ';' + . 'className=' . $form->get('className') . ';' + . 'creationDate_after=' . $form->get('creationDate_after') . ';' + . 'creationDate_before=' . $form->get('creationDate_before') . ';' + ); + + my $p + = $self->getSearchPaginator( { + url => $url, + keywords => $keywords, + where => $where, + joinClass => ['WebGUI::Asset::Wobject::GalleryAlbum', 'WebGUI::Asset::File::Image::Photo'], + } ); + + $var->{ keywords } = $keywords; + + $p->appendTemplateVars( $var ); + for my $result ( @{ $p->getPageData } ) { + my $asset = WebGUI::Asset->newByDynamicClass( $self->session, $result->{assetId} ); + push @{ $var->{search_results} }, $asset->getTemplateVars; + } + } + + return $self->processStyle( + $self->processTemplate( $var, $self->get("templateIdSearch") ) + ); +} + #---------------------------------------------------------------------------- -=head2 www_userGallery ( ) +=head2 www_listFilesForUser ( ) + +Show all the GalleryAlbums and files owned by a given userId. If no userId is +given, will use the current user. =cut +sub www_listFilesForUser { + my $self = shift; + my $session = $self->session; + my $var = $self->getTemplateVars; + my $userId = $self->session->form->get("userId") || $self->session->user->userId; + my $user = WebGUI::User->new( $session, $userId ); + + $var->{ url_rss } = $self->getUrl('func=listFilesForUserRss;userId=' . $userId); + $var->{ userId } = $userId; + $var->{ username } = $user->username; + + # Get all the albums + my $albumIds = $self->getUserAlbumIds( $userId ); + for my $albumId ( @$albumIds ) { + my $asset = WebGUI::Asset->newByDynamicClass( $session, $albumId ); + push @{ $var->{user_albums} }, $asset->getTemplateVars; + } + + # Get a page of files + my $p + = $self->getUserFilePaginator({ + userId => $userId, + url => $self->getUrl("func=listFilesForUser") + }); + $p->appendTemplateVars( $var ); + + for my $fileId ( @{ $p->getPageData } ) { + my $asset = WebGUI::Asset->newByDynamicClass( $session, $fileId ); + push @{ $var->{user_files} }, $asset->getTemplateVars; + } + + return $self->processStyle( + $self->processTemplate( $var, $self->get("templateIdListFilesForUser") ) + ); +} + #---------------------------------------------------------------------------- -=head2 www_userGalleryRss ( ) +=head2 www_listFilesForUserRss ( ) =cut +sub www_listFilesForUserRss { + my $self = shift; + my $session = $self->session; + my $var = $self->getTemplateVars; + my $userId = $self->session->form("userId") || $self->session->user->userId; + + # Fix URLs for template vars + for my $key ( qw( url ) ) { + $var->{ $key } = $self->session->url->getSiteURL . $var->{ $key }; + } + + # Get all the albums + my $albumIds = $self->getUserAlbumIds( $userId ); + for my $albumId ( @$albumIds ) { + my $asset = WebGUI::Asset->newByDynamicClass( $session, $albumId ); + my $assetVar = $asset->getTemplateVars; + + for my $key ( qw( url ) ) { + $assetVar->{ $key } = $self->session->url->getSiteURL . $assetVar->{ $key }; + } + + push @{ $var->{user_albums} }, $assetVar; + } + + # Get all the files + my $fileIds = $self->getUserFileIds( $userId ); + for my $fileId ( @$fileIds ) { + my $asset = WebGUI::Asset->newByDynamicClass( $session, $fileId ); + my $assetVar = $asset->getTemplateVars; + + for my $key ( qw( url ) ) { + $assetVar->{ $key } = $self->session->url->getSiteURL . $assetVar->{ $key }; + } + + push @{ $var->{user_files} }, $assetVar; + } + + $self->session->http->setMimeType('text/xml'); + return $self->processTemplate( $var, $self->get("templateIdListFilesForUserRss") ); +} + 1; diff --git a/lib/WebGUI/Asset/Wobject/GalleryAlbum.pm b/lib/WebGUI/Asset/Wobject/GalleryAlbum.pm index 94ab45b36..2f62447e3 100644 --- a/lib/WebGUI/Asset/Wobject/GalleryAlbum.pm +++ b/lib/WebGUI/Asset/Wobject/GalleryAlbum.pm @@ -14,6 +14,10 @@ $VERSION = "1.0.0"; 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; @@ -47,22 +51,22 @@ sub definition { tie my %properties, 'Tie::IxHash', ( allowComments => { fieldType => "yesNo", - defaultValue => 0, - label => $i18n->get("allowComments label"), - hoverHelp => $i18n->get("allowComments description"), + defaultValue => 1, }, othersCanAdd => { fieldType => "yesNo", defaultValue => 0, - label => $i18n->get("othersCanAdd label"), - hoverHelp => $i18n->get("othersCanAdd description"), + }, + assetIdThumbnail => { + fieldType => "asset", + defaultValue => undef, }, ); push @{$definition}, { assetName => $i18n->get('assetName'), + autoGenerateForms => 0, icon => 'newWobject.gif', - autoGenerateForms => 1, tableName => 'GalleryAlbum', className => __PACKAGE__, properties => \%properties, @@ -90,43 +94,56 @@ 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; - use File::Temp qw{ tempdir }; my $tempdirName = tempdir( "WebGUI-Gallery-XXXXXXXX", TMPDIR => 1, CLEANUP => 1); - $archive->extract( $tempdir ); + $archive->extract( $tempdirName ); - opendir my $dh, $tempdirName or die "Could not open temp dir $tempdirName: $!"; - for my $file (readdir $dh) { - my $class = $gallery->getAssetClassForFile( $file ); + # 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->addChild({ - className => $class, - title => $properties->{title}, - menuTitle => $properties->{menuTitle} || $properties->{title}, - synopsis => $properties->{synopsis}, - }); + $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 ); } - closedir $dh; + + my $versionTag = WebGUI::VersionTag->getWorking( $self->session ); + $versionTag->set({ + "workflowId" => $self->getParent->get("workflowIdCommit"), + }); + $versionTag->requestCommit; + + return; } #---------------------------------------------------------------------------- -=head2 appendTemplateVarsFileLoop ( vars, options ) +=head2 appendTemplateVarsFileLoop ( vars, assetIds ) -Append template vars for a file loop with the specified options. C is -a hash reference to add the file loop to. C is a hash reference of -options with the following keys: - - perpage => number | "all" - If "all", no pagination will be done. - url => url - The URL to the current page +Append template vars for a file loop for the specified assetIds. C is +a hash reference to add the file loop to. C is an array reference +of assetIds for the loop. Returns the hash reference for convenience. @@ -135,17 +152,10 @@ Returns the hash reference for convenience. sub appendTemplateVarsFileLoop { my $self = shift; my $var = shift; - my $options = shift; + my $assetIds = shift; + my $session = $self->session; - my @assetIds; - if ($options->{perpage} eq "all") { - @assetIds = @{ $self->getFileIds }; - } - else { - @assetIds = @{ $self->getFilePaginator($options->{url})->getPageData }; - } - - for my $assetId (@assetIds) { + for my $assetId (@$assetIds) { push @{$var->{file_loop}}, WebGUI::Asset->newByDynamicClass($session, $assetId)->getTemplateVars; } @@ -168,6 +178,7 @@ C is true and the Gallery allows them to add files. 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 ); @@ -214,11 +225,15 @@ 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"); @@ -233,13 +248,23 @@ sub canEdit { Returns true if the user can view this asset. C 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 -# Inherited from superclass +sub canView { + my $self = shift; + my $userId = shift || $self->session->user->userId; + return $self->getParent->canView($userId); +} #---------------------------------------------------------------------------- -=head2 i18n ( [ session ] ) +=head2 i18n ( session ) Get a WebGUI::International object for this class. @@ -260,6 +285,19 @@ sub i18n { #---------------------------------------------------------------------------- +=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. @@ -270,9 +308,7 @@ sub getFileIds { my $self = shift; my $gallery = $self->getParent; - return $self->assetLineage( ['descendants'], { - includeOnlyClasses => $gallery->getAllAssetClassesForFile, - }); + return $self->getLineage( ['descendants'], { } ); } #---------------------------------------------------------------------------- @@ -286,7 +322,7 @@ url to the current page that will be given to the paginator. sub getFilePaginator { my $self = shift; - my $url = shift; + my $url = shift || $self->getUrl; my $p = WebGUI::Paginator->new( $self->session, $url ); $p->setDataByArrayRef( $self->getFileIds ); @@ -304,15 +340,77 @@ Gets template vars common to all views. 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'); - $var->{ url } = $self->getUrl; + # 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. @@ -360,6 +458,26 @@ sub 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 @@ -371,8 +489,10 @@ sub view { my $self = shift; my $session = $self->session; my $var = $self->getTemplateVars; - - $self->appendTemplateVarsFileLoop( $var ); + + my $p = $self->getFilePaginator; + $p->appendTemplateVars( $var ); + $self->appendTemplateVarsFileLoop( $var, $p->getPageData ); return $self->processTemplate($var, undef, $self->{_viewTemplate}); } @@ -384,6 +504,8 @@ sub view { 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 { @@ -391,9 +513,9 @@ sub view_slideshow { my $session = $self->session; my $var = $self->getTemplateVars; - $self->appendTemplateVarsFileLoop( $var, { perpage => "all" } ); + $self->appendTemplateVarsFileLoop( $var, $self->getFileIds ); - return $self->processTemplate($var, $self->getParent->get("templateIdSlideshow")); + return $self->processTemplate($var, $self->getParent->get("templateIdViewSlideshow")); } #---------------------------------------------------------------------------- @@ -403,6 +525,9 @@ sub view_slideshow { 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 { @@ -410,9 +535,31 @@ sub view_thumbnails { my $session = $self->session; my $var = $self->getTemplateVars; - $self->appendTemplateVarsFileLoop( $var, { perpage => "all" } ); + my $fileId = $session->form->get("fileId"); - return $self->processTemplate($var, $self->getParent->get("templateIdThumbnails")); + $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")); } #---------------------------------------------------------------------------- @@ -428,8 +575,42 @@ sub www_addArchive { 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")) ); @@ -446,20 +627,27 @@ Process the form for adding an archive. sub www_addArchiveSave { my $self = shift; - return $self->session->privilege->insufficient unless $self->canAddfile; + 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 $storage = $form->get("archive", "File"); - my $filename = $storage->getFilePath( $storage->getFiles->[0] ); + my $storageId = $form->get("archive", "File"); + my $storage = WebGUI::Storage->get( $session, $storageId ); + my $filename = $storage->getPath( $storage->getFiles->[0] ); $self->addArchive( $filename, $properties ); - return $self->www_view; + $storage->delete; + + return $self->processStyle( + sprintf $i18n->get('addArchive message'), $self->getUrl, + ); } #----------------------------------------------------------------------------- @@ -476,7 +664,7 @@ sub www_delete { return $self->session->privilege->insufficient unless $self->canEdit; my $var = $self->getTemplateVars; - $var->{ url_yes } = $self->getUrl("?func=deleteConfirm"); + $var->{ url_yes } = $self->getUrl("func=deleteConfirm"); return $self->processStyle( $self->processTemplate( $var, $self->getParent->get("templateIdDeleteAlbum") ) @@ -496,9 +684,130 @@ sub www_deleteConfirm { return $self->session->privilege->insufficient unless $self->canEdit; + my $gallery = $self->getParent; + $self->purge; - return $self->getParent->www_view; + 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 + ); } #----------------------------------------------------------------------------- @@ -547,7 +856,27 @@ sub www_viewRss { 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; diff --git a/lib/WebGUI/AssetLineage.pm b/lib/WebGUI/AssetLineage.pm index b5c37f4c1..373eef46e 100644 --- a/lib/WebGUI/AssetLineage.pm +++ b/lib/WebGUI/AssetLineage.pm @@ -15,6 +15,7 @@ package WebGUI::Asset; =cut use strict; +use Carp qw( croak ); =head1 NAME @@ -82,9 +83,9 @@ sub addChild { $self->session->db->commit; $properties->{assetId} = $id; $properties->{parentId} = $self->getId; - my $temp = WebGUI::Asset->newByPropertyHashRef($self->session,$properties); + my $temp = WebGUI::Asset->newByPropertyHashRef($self->session,$properties) || croak "Couldn't create a new $properties->{className} asset!"; $temp->{_parent} = $self; - my $newAsset = $temp->addRevision($properties,$now, {skipAutoCommitWorkflows=>$options->{skipAutoCommitWorkflows}}); + my $newAsset = $temp->addRevision($properties, $now, $options); $self->updateHistory("added child ".$id); $self->session->http->setStatus(201,"Asset Creation Successful"); return $newAsset; diff --git a/lib/WebGUI/AssetPackage.pm b/lib/WebGUI/AssetPackage.pm index 983acce7e..5c505b36a 100644 --- a/lib/WebGUI/AssetPackage.pm +++ b/lib/WebGUI/AssetPackage.pm @@ -125,18 +125,22 @@ A hash reference containing the exported data. =cut sub importAssetData { - my $self = shift; - my $data = shift; - my $error = $self->session->errorHandler; - my $id = $data->{properties}{assetId}; - my $class = $data->{properties}{className}; - my $version = $data->{properties}{revisionDate}; + my $self = shift; + my $data = shift; + my $error = $self->session->errorHandler; + my $id = $data->{properties}{assetId}; + my $class = $data->{properties}{className}; + my $version = $data->{properties}{revisionDate}; + + # Load the class + WebGUI::Asset->loadModule( $self->session, $class ); + my $asset; - my $assetExists = WebGUI::Asset->assetExists($self->session, $id, $class, $version); - if ($assetExists) { # update an existing revision + my $assetExists = WebGUI::Asset->assetExists($self->session, $id, $class, $version); + if ($assetExists) { # update an existing revision $asset = WebGUI::Asset->new($self->session, $id, $class, $version); - $error->info("Updating an existing revision of asset $id"); - $asset->update($data->{properties}); + $error->info("Updating an existing revision of asset $id"); + $asset->update($data->{properties}); ##Pending assets are assigned a new version tag if ($data->{properties}->{status} eq 'pending') { $self->session->db->write( @@ -144,19 +148,19 @@ sub importAssetData { [WebGUI::VersionTag->getWorking($self->session)->getId, $data->{properties}->{assetId}] ); } - } + } else { - $asset = WebGUI::Asset->new($self->session, $id, $class); - if (defined $asset) { # create a new revision of an existing asset - $error->info("Creating a new revision of asset $id"); - $asset = $asset->addRevision($data->{properties}, $version, {skipAutoCommitWorkflows => 1}); - } + $asset = WebGUI::Asset->new($self->session, $id, $class); + if (defined $asset) { # create a new revision of an existing asset + $error->info("Creating a new revision of asset $id"); + $asset = $asset->addRevision($data->{properties}, $version, {skipAutoCommitWorkflows => 1}); + } else { # add an entirely new asset - $error->info("Adding $id that didn't previously exist."); - $asset = $self->addChild($data->{properties}, $id, $version, {skipAutoCommitWorkflows => 1}); - } - } - return $asset; + $error->info("Adding $id that didn't previously exist."); + $asset = $self->addChild($data->{properties}, $id, $version, {skipAutoCommitWorkflows => 1}); + } + } + return $asset; } #------------------------------------------------------------------- @@ -188,40 +192,40 @@ A reference to a WebGUI::Storage object that contains a webgui package file. =cut sub importPackage { - my $self = shift; - my $storage = shift; - my $decompressed = $storage->untar($storage->getFiles->[0]); - my %assets = (); - my $error = $self->session->errorHandler; - $error->info("Importing package."); - foreach my $file (sort(@{$decompressed->getFiles})) { - next unless ($decompressed->getFileExtension($file) eq "json"); - $error->info("Found data file $file"); - my $data = eval{ + my $self = shift; + my $storage = shift; + my $decompressed = $storage->untar($storage->getFiles->[0]); + my %assets = (); + my $error = $self->session->errorHandler; + $error->info("Importing package."); + foreach my $file (sort(@{$decompressed->getFiles})) { + next unless ($decompressed->getFileExtension($file) eq "json"); + $error->info("Found data file $file"); + my $data = eval{ local $JSON::UnMapping = 1; JSON::jsonToObj($decompressed->getFileContentsAsScalar($file)) }; - if ($@ || $data->{properties}{assetId} eq "" || $data->{properties}{className} eq "" || $data->{properties}{revisionDate} eq "") { - $error->error("package corruption: ".$@) if ($@); - return "corrupt"; - } - $error->info("Data file $file is valid and represents asset ".$data->{properties}{assetId}); - foreach my $storageId (@{$data->{storage}}) { - my $assetStorage = WebGUI::Storage->get($self->session, $storageId); - $decompressed->untar($storageId.".storage", $assetStorage); - } - my $asset = $assets{$data->{properties}{parentId}} || $self; - my $newAsset = $asset->importAssetData($data); + if ($@ || $data->{properties}{assetId} eq "" || $data->{properties}{className} eq "" || $data->{properties}{revisionDate} eq "") { + $error->error("package corruption: ".$@) if ($@); + return "corrupt"; + } + $error->info("Data file $file is valid and represents asset ".$data->{properties}{assetId}); + foreach my $storageId (@{$data->{storage}}) { + my $assetStorage = WebGUI::Storage->get($self->session, $storageId); + $decompressed->untar($storageId.".storage", $assetStorage); + } + my $asset = $assets{$data->{properties}{parentId}} || $self; + my $newAsset = $asset->importAssetData($data); $newAsset->importAssetCollateralData($data); - $assets{$newAsset->getId} = $newAsset; - } - if ($self->session->setting->get("autoRequestCommit")) { + $assets{$newAsset->getId} = $newAsset; + } + if ($self->session->setting->get("autoRequestCommit")) { if ($self->session->setting->get("skipCommitComments")) { WebGUI::VersionTag->getWorking($self->session)->requestCommit; } else { - $self->session->http->setRedirect($self->getUrl("op=commitVersionTag;tagId=".WebGUI::VersionTag->getWorking($self->session)->getId)); + $self->session->http->setRedirect($self->getUrl("op=commitVersionTag;tagId=".WebGUI::VersionTag->getWorking($self->session)->getId)); } - } + } return undef; } diff --git a/lib/WebGUI/AssetVersioning.pm b/lib/WebGUI/AssetVersioning.pm index 023cc8ecd..ce3c5052e 100644 --- a/lib/WebGUI/AssetVersioning.pm +++ b/lib/WebGUI/AssetVersioning.pm @@ -79,12 +79,12 @@ If this is set to 1 then assets that normally send notifications will (like CS P sub addRevision { my $self = shift; my $properties = shift; - my $now = shift || $self->session->datetime->time(); - my $options = shift; - + my $now = shift || $self->session->datetime->time(); + my $options = shift; + my $autoCommitId = $self->getAutoCommitWorkflowId() unless ($options->{skipAutoCommitWorkflows}); - - my $workingTag + + my $workingTag = ($autoCommitId) ? WebGUI::VersionTag->create($self->session, {groupToUse=>'12', workflowId=>$autoCommitId}) : WebGUI::VersionTag->getWorking($self->session) @@ -104,8 +104,7 @@ sub addRevision { $self->session->user->userId, $workingTag->getId, $self->getId, - ] - ); + ]); foreach my $definition (@{$self->definition($self->session)}) { unless ($definition->{tableName} eq "assetData") { diff --git a/lib/WebGUI/Form.pm b/lib/WebGUI/Form.pm index b5b5291d6..ef552ed77 100644 --- a/lib/WebGUI/Form.pm +++ b/lib/WebGUI/Form.pm @@ -15,6 +15,8 @@ package WebGUI::Form; =cut use strict; +use Carp qw( croak ); +use Scalar::Util qw( blessed ); use Tie::IxHash; use WebGUI::Asset; use WebGUI::Asset::RichEdit; @@ -92,7 +94,7 @@ sub formFooter { #------------------------------------------------------------------- -=head2 formHeader ( session, hashRef ) +=head2 formHeader ( session, options ) Returns a form header. @@ -100,7 +102,7 @@ Returns a form header. A reference to the current session. -=head3 hashRef +=head3 options A hash reference that contains one or more of the following parameters. @@ -108,6 +110,9 @@ A hash reference that contains one or more of the following parameters. The form action. Defaults to the current page. +NOTE: If the C contains a query string (?param=value), C +will translate the parameters into hidden form elements automatically. + =head4 method The form method. Defaults to "post". @@ -118,28 +123,36 @@ The form enctype. Defaults to "multipart/form-data". =head4 extras -If you want to add anything special to the form header like javascript actions or stylesheet info, then use this. +If you want to add anything special to the form header like javascript +actions or stylesheet info, then use this. =cut sub formHeader { - my $session = shift; - my $params = shift; - my $action = $params->{action} || $session->url->page(); - my $hidden; - if ($action =~ /\?/) { - my ($path,$query) = split(/\?/,$action); - $action = $path; - my @params = split(/\;/,$query); - foreach my $param (@params) { - $param =~ s/amp;(.*)/$1/; - my ($name,$value) = split(/\=/,$param); - $hidden .= hidden($session,{name=>$name,value=>$value}); - } - } - my $method = $params->{method} || "post"; - my $enctype = $params->{enctype} || "multipart/form-data"; - return '
{extras}.'>
'.$hidden; + my $session = shift; + my $params = shift || {}; + + croak "First parameter must be WebGUI::Session object" + unless blessed $session && $session->isa( "WebGUI::Session" ); + croak "Second parameter must be hash reference" + if ref $params ne "HASH"; + + my $action = exists $params->{ action } ? $params->{ action } : $session->url->page(); + my $method = exists $params->{ method } ? $params->{ method } : "post"; + my $enctype = exists $params->{ enctype } ? $params->{ enctype } : "multipart/form-data"; + + # Fix a query string in the action URL + my $hidden; + if ($action =~ /\?/) { + ($action, my $query) = split /\?/, $action, 2; + my @params = split /[&;]/, $query; + foreach my $param ( @params ) { + my ($name, $value) = split /=/, $param; + $hidden .= hidden( $session, { name => $name, value => $value } ); + } + } + + return '{extras}.'>
'.$hidden; } diff --git a/lib/WebGUI/Form/SelectRichEditor.pm b/lib/WebGUI/Form/SelectRichEditor.pm new file mode 100644 index 000000000..1093dda31 --- /dev/null +++ b/lib/WebGUI/Form/SelectRichEditor.pm @@ -0,0 +1,101 @@ +package WebGUI::Form::SelectRichEditor; + +=head1 LEGAL + + ------------------------------------------------------------------- + WebGUI is Copyright 2001-2007 Plain Black Corporation. + ------------------------------------------------------------------- + Please read the legal notices (docs/legal.txt) and the license + (docs/license.txt) that came with this distribution before using + this software. + ------------------------------------------------------------------- + http://www.plainblack.com info@plainblack.com + ------------------------------------------------------------------- + +=cut + +use strict; +use base 'WebGUI::Form::SelectBox'; +use WebGUI::International; + +=head1 NAME + +WebGUI::Form::SelectRichEditor + +=head1 DESCRIPTION + +Creates a select box to choose a Rich Text Editor asset. + +=head1 SEE ALSO + +This is a subclass of WebGUI::Form::SelectBox. + +=head1 METHODS + +The following methods are specifically available from this class. Check the superclass for additional methods. + +=cut + +#---------------------------------------------------------------------------- + +=head2 definition ( [ additionalTerms ] ) + +See the super class for additional details. + +=head3 additionalTerms + +The following additional parameters have been added via this sub class. + +=head4 defaultValue + +Defaults to the Post Rich Editor, the least-featured Rich Text Editor and the +one most likely to be selected by users of this form control. + +=cut + +sub definition { + my $class = shift; + my $session = shift; + my $definition = shift || []; + my $i18n = WebGUI::International->new($session); + push @{$definition}, { + formName => { + defaultValue => $i18n->get("475"), + }, + defaultValue => { + defaultValue => '', + }, + }; + return $class->SUPER::definition($session, $definition); +} + +#---------------------------------------------------------------------------- + +=head2 new + +Create a new WebGUI::Form::SelectRichEditor object and populate it with all +the available Rich Text Editor assets. + +=cut + +sub new { + my $class = shift; + my $self = $class->SUPER::new(@_); + + # Get all the RTEs available to this site + my $options + = $self->session->db->buildHashRef( q{ + SELECT DISTINCT(assetData.assetId), assetData.title + FROM asset, assetData + WHERE asset.className='WebGUI::Asset::RichEdit' + AND asset.assetId=assetData.assetId + ORDER BY assetData.title + }); + + $self->set( "options", $options ); + + return $self; +} + +1; + diff --git a/lib/WebGUI/Help/Asset_Gallery.pm b/lib/WebGUI/Help/Asset_Gallery.pm new file mode 100644 index 000000000..d449681f2 --- /dev/null +++ b/lib/WebGUI/Help/Asset_Gallery.pm @@ -0,0 +1,229 @@ +package WebGUI::Help::Asset_Gallery; + +our $HELP = { + 'help searchForm' => { + title => 'help searchForm title', + body => 'help searchForm body', + variables => [ + { + name => 'searchForm_start', + description => 'helpvar searchForm_start', + }, + { + name => 'searchForm_end', + description => 'helpvar searchForm_end', + }, + { + name => 'searchForm_basicSearch', + description => 'helpvar searchForm_basicSearch', + }, + { + name => 'searchForm_title', + description => 'helpvar searchForm_title', + }, + { + name => 'searchForm_description', + description => 'helpvar searchForm_description', + }, + { + name => 'searchForm_keywords', + description => 'helpvar searchForm_keywords', + }, + { + name => 'searchForm_className', + description => 'helpvar searchForm_className', + }, + { + name => 'searchForm_creationDate_after', + description => 'helpvar searchForm_creationDate_after', + }, + { + name => 'searchForm_creationDate_before', + description => 'helpvar searchForm_creationDate_before', + }, + { + name => 'searchForm_submit', + description => 'helpvar searchForm_submit', + }, + ], + }, + + 'help common' => { + title => 'help common title', + body => 'help common body', + isa => [ + { + tag => 'help searchForm', + namespace => 'Asset_Gallery', + }, + ], + variables => [ + { + name => 'url_addAlbum', + description => 'helpvar url_addAlbum', + }, + { + name => 'url_listAlbums', + description => 'helpvar url_listAlbums', + }, + { + name => 'url_listAlbumsRss', + description => 'helpvar url_listAlbumsRss', + }, + { + name => 'url_listFilesForCurrentUser', + description => 'helpvar url_listFilesForCurrentUser', + }, + { + name => 'url_search', + description => 'helpvar url_search', + }, + { + name => 'canEdit', + description => 'helpvar canEdit', + }, + { + name => 'canAddFile', + description => 'helpvar canAddFile', + }, + ], + }, + + 'help listAlbums' => { + title => 'help listAlbums title', + body => 'help listAlbums body', + isa => [ + { + tag => 'help common', + namespace => 'Asset_Gallery', + }, + ], + variables => [ + { + name => 'albums', + description => 'helpvar albums', + }, + ], + related => [ + { + tag => 'help common', + namespace => 'Asset_GalleryAlbum', + }, + ], + }, + + 'help listAlbumsRss' => { + title => 'help listAlbumsRss title', + body => 'help listAlbumsRss body', + isa => [ + { + tag => 'help common', + namespace => 'Asset_Gallery', + }, + ], + variables => [ + { + name => 'albums', + description => 'helpvar albums rss', + variables => [ + { + name => 'rssDate', + description => 'helpvar rssDate', + }, + ], + }, + ], + related => [ + { + tag => 'help common', + namespace => 'Asset_GalleryAlbum', + }, + ], + }, + + 'help search' => { + title => 'help search title', + body => 'help search body', + isa => [ + { + tag => 'help common', + namespace => 'Asset_Gallery', + }, + ], + variables => [ + { + name => 'search_results', + description => 'helpvar search_results', + }, + ], + # All classes that can be found by a Gallery search go in here + related => [ + { + tag => 'help common', + namespace => 'Asset_GalleryAlbum', + }, + { + tag => 'help common', + namespace => 'Asset_Photo', + }, + ], + }, + + 'help listFilesForUser' => { + title => 'help listFilesForUser title', + body => 'help listFilesForUser body', + isa => [ + { + tag => 'help common', + namespace => 'Asset_Gallery', + }, + ], + variables => [ + { + name => 'user_albums', + description => 'helpvar user_albums', + }, + { + name => 'user_files', + description => 'helpvar user_files', + }, + { + name => 'userId', + description => 'helpvar userId', + }, + { + name => 'url_rss', + description => 'helpvar url_rss', + }, + { + name => 'username', + description => 'helpvar username', + }, + ], + # All classes that can be found by a Gallery search go in here + related => [ + { + tag => 'help common', + namespace => 'Asset_GalleryAlbum', + }, + { + tag => 'help common', + namespace => 'Asset_Photo', + }, + ], + }, + + 'help listFilesForUserRss' => { + title => 'help listFilesForUserRss title', + body => 'help listFilesForUserRss body', + isa => [ + { + tag => 'help listFilesForUser', + namespace => 'Asset_Gallery', + }, + ], + }, + +}; + +1; diff --git a/lib/WebGUI/Help/Asset_GalleryAlbum.pm b/lib/WebGUI/Help/Asset_GalleryAlbum.pm new file mode 100644 index 000000000..25cc4598a --- /dev/null +++ b/lib/WebGUI/Help/Asset_GalleryAlbum.pm @@ -0,0 +1,309 @@ +package WebGUI::Help::Asset_GalleryAlbum; + +our $HELP = { + + 'help common' => { + title => 'help common title', + body => 'help common body', + isa => [ + { + tag => 'help searchForm', + namespace => 'Asset_Gallery', + }, + ], + variables => [ + { + name => 'canAddFile', + description => 'helpvar canAddFile', + }, + { + name => 'canEdit', + description => 'helpvar canEdit', + }, + { + name => 'url_listAlbums', + description => 'helpvar url_listAlbums', + }, + { + name => 'url_listAlbumsRss', + description => 'helpvar url_listAlbumsRss', + }, + { + name => 'url_listFilesForCurrentUser', + description => 'helpvar url_listFilesForCurrentUser', + }, + { + name => 'url_search', + description => 'helpvar url_search', + }, + { + name => 'url_addArchive', + description => 'helpvar url_addArchive', + }, + { + name => 'url_addPhoto', + description => 'helpvar url_addPhoto', + }, + { + name => 'url_addNoClass', + description => 'helpvar url_addNoClass', + }, + { + name => 'url_delete', + description => 'helpvar url_delete', + }, + { + name => 'url_edit', + description => 'helpvar url_edit', + }, + { + name => 'url_listFilesForOwner', + description => 'helpvar url_listFilesForOwner', + }, + { + name => 'url_viewRss', + description => 'helpvar url_viewRss', + }, + { + name => 'url_slideshow', + description => 'helpvar url_slideshow', + }, + { + name => 'url_thumbnails', + description => 'helpvar url_thumbnails', + }, + { + name => 'fileCount', + description => 'helpvar fileCount', + }, + { + name => 'ownerUsername', + description => 'helpvar ownerUsername', + }, + { + name => 'thumbnailUrl', + description => 'helpvar thumbnailUrl', + }, + ], + }, + + 'help fileLoop' => { + title => 'help fileLoop title', + body => 'help fileLoop body', + variables => [ + { + name => 'file_loop', + description => 'helpvar file_loop', + }, + ], + + # ADD ALL GalleryAlbum FILE CLASSES HERE!!! + related => [ + { + tag => 'help common', + namespace => 'Asset_Photo', + }, + ], + }, + + 'help view' => { + title => 'help view title', + body => 'help view body', + isa => [ + { + tag => 'help common', + namespace => 'Asset_GalleryAlbum', + }, + { + tag => 'help fileLoop', + namespace => 'Asset_GalleryAlbum', + }, + ], + }, + + 'help slideshow' => { + title => 'help slideshow title', + body => 'help slideshow body', + isa => [ + { + tag => 'help common', + namespace => 'Asset_GalleryAlbum', + }, + { + tag => 'help fileLoop', + namespace => 'Asset_GalleryAlbum', + }, + ], + }, + + 'help thumbnails' => { + title => 'help thumbnails title', + body => 'help thumbnails body', + isa => [ + { + tag => 'help common', + namespace => 'Asset_GalleryAlbum', + }, + { + tag => 'help fileLoop', + namespace => 'Asset_GalleryAlbum', + }, + ], + + variables => [ + { + name => 'file_*', + description => 'helpvar file_*', + }, + ], + + # PUT ALL GalleryAlbum FILE CLASSES HERE ALSO!!! + related => [ + { + tag => 'help common', + namespace => 'Asset_Photo', + }, + ], + }, + + 'help addArchive' => { + title => 'help addArchive title', + body => 'help addArchive body', + isa => [ + { + tag => 'help common', + namespace => 'Asset_GalleryAlbum', + }, + ], + variables => { + { + name => 'form_start', + description => 'helpvar form_start', + required => 1, + }, + { + name => 'form_end', + description => 'helpvar form_end', + required => 1, + }, + { + name => 'form_submit', + description => 'helpvar form_submit', + }, + { + name => 'form_archive', + description => 'helpvar form_archive', + required => 1, + }, + { + name => 'form_keywords', + description => 'helpvar form_keywords', + }, + { + name => 'form_friendsOnly', + description => 'helpvar form_friendsOnly', + }, + }, + }, + + 'help delete' => { + title => 'help delete title', + body => 'help delete body', + isa => [ + { + tag => 'help common', + namespace => 'Asset_GalleryAlbum', + }, + ], + variables => [ + { + name => 'url_yes', + description => 'helpvar url_yes', + }, + ], + }, + + 'help edit' => { + title => 'help edit title', + body => 'help edit body', + isa => [ + { + tag => 'help common', + namespace => 'Asset_GalleryAlbum', + }, + { + tag => 'help fileLoop', + namespace => 'Asset_GalleryAlbum', + }, + ], + variables => [ + { + name => 'form_start', + description => 'helpvar form_start', + required => 1, + }, + { + name => 'form_end', + description => 'helpvar form_end', + required => 1, + }, + { + name => 'form_cancel', + description => 'helpvar form_cancel', + }, + { + name => 'form_submit', + description => 'helpvar form_submit', + }, + { + name => 'form_title', + description => 'helpvar form_title', + }, + { + name => 'form_description', + description => 'helpvar form_description', + required => 1, + }, + { + name => 'file_loop', + description => 'helpvar file_loop edit', + variables => [ + { + name => 'isAlbumThumbnail', + description => 'helpvar isAlbumThumbnail', + }, + ], + }, + ], + }, + + 'help viewRss' => { + title => 'help viewRss title', + body => 'help viewRss body', + isa => [ + { + tag => 'help common', + namespace => 'Asset_GalleryAlbum', + }, + { + tag => 'help fileLoop', + namespace => 'Asset_GalleryAlbum', + }, + ], + variables => [ + { + name => 'file_loop', + description => 'helpvar file_loop viewRss', + variables => [ + { + name => 'rssDate', + description => 'helpvar rssDate', + }, + ], + }, + ], + }, + +}; + +1; diff --git a/lib/WebGUI/Help/Asset_Photo.pm b/lib/WebGUI/Help/Asset_Photo.pm new file mode 100644 index 000000000..9a733ed42 --- /dev/null +++ b/lib/WebGUI/Help/Asset_Photo.pm @@ -0,0 +1,258 @@ +package WebGUI::Help::Asset_Photo; + +our $HELP = { + 'help commentForm' => { + title => 'help commentForm title', + body => 'help commentForm body', + variables => [ + { + name => 'commentForm_start', + description => 'helpvar commentForm_start', + }, + { + name => 'commentForm_end', + description => 'helpvar commentForm_end', + }, + { + name => 'commentForm_bodyText', + description => 'helpvar commentForm_bodyText', + }, + { + name => 'commentForm_submit', + description => 'helpvar commentForm_submit', + }, + ], + }, + + 'help common' => { + title => 'help common title', + body => 'help common body', + isa => [ + { + tag => 'help searchForm', + namespace => 'Asset_Gallery', + }, + { + tag => 'help commentForm', + namespace => 'Asset_Photo', + }, + ], + variables => [ + { + name => 'canComment', + description => 'helpvar canComment', + }, + { + name => 'canEdit', + description => 'helpvar canEdit', + }, + { + name => 'fileUrl', + description => 'helpvar fileUrl', + }, + { + name => 'numberOfComments', + description => 'helpvar numberOfComments', + }, + { + name => 'ownerUsername', + description => 'helpvar ownerUsername', + }, + { + name => 'thumbnailUrl', + description => 'helpvar thumbnailUrl', + }, + { + name => 'url_delete', + description => 'helpvar url_delete', + }, + { + name => 'url_demote', + description => 'helpvar url_demote', + }, + { + name => 'url_edit', + description => 'helpvar url_edit', + }, + { + name => 'url_gallery', + description => 'helpvar url_gallery', + }, + { + name => 'url_makeShortcut', + description => 'helpvar url_makeShortcut', + }, + { + name => 'url_listFilesForOwner', + description => 'helpvar url_listFilesForOwner', + }, + { + name => 'url_promote', + description => 'helpvar url_promote', + }, + { + name => 'resolutions_loop', + description => 'helpvar resolutions_loop', + variables => [ + { + name => 'url_download', + description => 'helpvar resolutions_loop url_download', + }, + ], + }, + { + name => 'exif_*', + description => 'helpvar exif_*', + }, + { + name => 'exifLoop', + description => 'helpvar exifLoop', + variables => [ + { + name => 'tag', + description => 'helpvar exifLoop tag', + }, + { + name => 'value', + description => 'helpvar exifLoop value', + }, + ], + }, + ], + }, + + 'help delete' => { + title => 'help delete title', + body => 'help delete body', + isa => [ + { + tag => 'help common', + namespace => 'Asset_Photo', + }, + ], + variables => [ + { + name => 'url_yes', + description => 'helpvar url_yes', + }, + ], + }, + + 'help edit' => { + title => 'help edit title', + body => 'htlp edit body', + variables => [ + { + name => 'url_addArchive', + description => 'helpvar url_addArchive', + }, + { + name => 'form_start', + description => 'helpvar form_start', + required => 1, + }, + { + name => 'form_end', + description => 'helpvar form_end', + required => 1, + }, + { + name => 'form_submit', + description => 'helpvar form_submit', + }, + { + name => 'form_title', + description => 'helpvar form_title', + }, + { + name => 'form_synopsis', + description => 'helpvar form_synopsis', + }, + { + name => 'form_photo', + description => 'helpvar form_photo', + }, + { + name => 'form_keywords', + description => 'helpvar form_keywords', + }, + { + name => 'form_location', + description => 'helpvar form_location', + }, + { + name => 'form_friendsOnly', + description => 'helpvar form_friendsOnly', + }, + ], + }, + + 'help makeShortcut' => { + title => 'help makeShortcut title', + body => 'htlp makeShortcut body', + variables => [ + { + name => 'form_start', + description => 'helpvar form_start', + required => 1, + }, + { + name => 'form_end', + description => 'helpvar form_end', + required => 1, + }, + { + name => 'form_parentId', + description => 'helpvar form_parentId', + required => 1, + }, + ], + } + 'help view' => { + title => 'help view title', + body => 'help view body', + isa => [ + { + tag => 'help common', + namespace => 'Asset_Photo', + }, + ], + variables => [ + { + name => 'commentLoop', + description => 'helpvar commentLoop', + variables => [ + { + name => 'userId', + description => 'helpvar commentLoop userId', + }, + { + name => 'visitorIp', + description => 'helpvar commentLoop visitorIp', + }, + { + name => 'creationDate', + description => 'helpvar commentLoop creationDate', + }, + { + name => 'bodyText', + description => 'helpvar commentLoop bodyText', + }, + { + name => 'username', + description => 'helpvar commentLoop username', + }, + ], + }, + { + name => 'commentLoop_pageBar', + description => 'helpvar commentLoop_pageBar', + }, + ], + }, + + +}; + +1; + diff --git a/lib/WebGUI/Keyword.pm b/lib/WebGUI/Keyword.pm index 3ae518bc7..a5fbc9adc 100644 --- a/lib/WebGUI/Keyword.pm +++ b/lib/WebGUI/Keyword.pm @@ -27,6 +27,9 @@ Package WebGUI::Keyword This package provides an API to create and modify keywords used by the asset sysetm. +Assets can use the C property to set keywords automatically. See +WebGUI::Asset::update() for more details. + =head1 SYNOPSIS use WebGUI::Keyword; diff --git a/lib/WebGUI/Search.pm b/lib/WebGUI/Search.pm index b19ec0316..138b9b80b 100644 --- a/lib/WebGUI/Search.pm +++ b/lib/WebGUI/Search.pm @@ -15,6 +15,7 @@ package WebGUI::Search; =cut use strict; +use Carp qw( croak ); use WebGUI::Asset; =head1 NAME @@ -329,6 +330,9 @@ This rule allows for an array reference of table join clauses. join => 'join assetData on assetId = assetData.assetId' +NOTE: This rule is deprecated and will be removed in a future release. Use +joinClass instead. + =head4 columns This rule allows for additional columns to be returned by getResultSet(). @@ -344,6 +348,11 @@ placeholders and parameters. sub search { my $self = shift; my $rules = shift; + + # Send the rules through some sanity checks + croak "'lineage' rule must be array reference" + if ( $rules->{lineage} && ref $rules->{lineage} ne "ARRAY" ); + my @params = (); my $query = ""; my @clauses = (); @@ -410,10 +419,31 @@ sub search { if ($rules->{where}) { push(@clauses, $rules->{where}); } - if ($rules->{join}) { # This join happens in _getQuery - $rules->{join} = [$rules->{join}] - unless (ref $rules->{join} eq "ARRAY"); - $self->{_join} = $rules->{join}; + # deal with custom joined tables if we must + if (exists $rules->{joinClass}) { + my $join = [ "left join assetData on assetIndex.assetId=assetData.assetId" ]; + for my $className ( @{ $rules->{ joinClass } } ) { + my $cmd = "use " . $className; + eval { $cmd }; + $self->session->errorHandler->fatal("Couldn't compile asset package: ".$className.". Root cause: ".$@) if ($@); + foreach my $definition (@{$className->definition($self->session)}) { + unless ($definition->{tableName} eq "asset") { + my $tableName = $definition->{tableName}; + push @$join, + "left join $tableName on assetData.assetId=".$tableName.".assetId and assetData.revisionDate=".$tableName.".revisionDate"; + } + last; + } + } + # Get only the latest revision + push @clauses, "assetData.revisionDate = (SELECT MAX(revisionDate) FROM assetData ad WHERE ad.assetId = assetData.assetId)"; + # Join happens in _getQuery + $self->{_join} = $join; + } + elsif ($rules->{join}) { # This join happens in _getQuery + $rules->{join} = [$rules->{join}] + unless (ref $rules->{join} eq "ARRAY"); + $self->{_join} = $rules->{join}; } if ($rules->{columns}) { $rules->{columns} = [$rules->{columns}] diff --git a/lib/WebGUI/Storage.pm b/lib/WebGUI/Storage.pm index 9291d0c79..5c7178c4c 100644 --- a/lib/WebGUI/Storage.pm +++ b/lib/WebGUI/Storage.pm @@ -15,6 +15,8 @@ package WebGUI::Storage; =cut use Archive::Tar; +use Carp qw( croak ); +use Cwd; use File::Copy qw(cp); use FileHandle; use File::Find; @@ -24,7 +26,6 @@ use Storable qw(nstore retrieve); use strict; use warnings; use WebGUI::Utility; -use Carp; =head1 NAME @@ -64,6 +65,7 @@ This package provides a mechanism for storing and retrieving files that are not $newstore = $store->untar($filename); + $store->copyFile($filename, $newFilename); $store->delete; $store->deleteFile($filename); $store->rename($filename, $newFilename); @@ -202,6 +204,7 @@ sub addFileFromFormPost { my $filename; my $attachmentCount = 1; foreach my $upload ($self->session->request->upload($formVariableName)) { + $self->session->errorHandler->info("Trying to get " . $upload->filename); return $filename if $attachmentCount > $attachmentLimit; my $tempFilename = $upload->filename(); next unless $tempFilename; @@ -225,6 +228,7 @@ sub addFileFromFormPost { print $file $buffer; } close($file); + $self->session->errorHandler->info("Got ".$upload->filename); } else { $self->_addError("Couldn't open file ".$self->getPath($filename)." for writing due to error: ".$!); return undef; @@ -343,6 +347,31 @@ sub copy { #------------------------------------------------------------------- +=head2 copyFile ( filename, newFilename ) + +Copy a file in this storage location. C is the file to copy. +C is the new file to create. + +=cut + +sub copyFile { + my $self = shift; + my $filename = shift; + my $newFilename = shift; + + croak "Can't find '$filename' in storage location " . $self->getId + unless -e $self->getPath($filename); + croak "Second argument must be a filename" + unless $newFilename; + + cp( $self->getPath($filename), $self->getPath($newFilename) ) + || croak "Couldn't copy '$filename' to '$newFilename': $!"; + + return; +} + +#------------------------------------------------------------------- + =head2 create ( session ) Creates a new storage location on the file system. @@ -354,9 +383,9 @@ A reference to the current session; =cut sub create { - my $class = shift; - my $session = shift; - my $id = $session->id->generate(); + my $class = shift; + my $session = shift; + my $id = $session->id->generate(); #Determine whether or not to use case insensitive files my $config = $session->config; @@ -365,14 +394,16 @@ sub create { #$session->errorHandler->warn($caseInsensitive.": $id\n".Carp::longmess()."\n"); #For case insensitive operating systems, convert guid to hex - if($caseInsensitive) { + if ($caseInsensitive) { my $hexId = $session->id->toHex($id); $db->write("insert into storageTranslation (guidValue,hexValue) values (?,?)",[$id,$hexId]); } my $self = $class->get($session,$id); - $self->_makePath; - return $self; + $self->_makePath; + + $session->errorHandler->info("Created storage location $id as a $class"); + return $self; } @@ -446,6 +477,7 @@ sub delete { $db->write("delete from storageTranslation where guidValue=?",[$self->getId]); } } + $self->session->errorHandler->info("Deleted storage ".$self->getId); return; } @@ -753,6 +785,8 @@ Returns a full path to this storage location. If specified, we'll return a path to the file rather than the storage location. +NOTE: Does not check if the file exists. This is a feature. + =cut sub getPath { @@ -898,21 +932,22 @@ Pass in a storage location object to create the tar file in, instead of having a =cut sub tar { - my $self = shift; - my $filename = shift; - my $temp = shift || WebGUI::Storage->createTemp($self->session); + my $self = shift; + my $filename = shift; + my $temp = shift || WebGUI::Storage->createTemp($self->session); chdir $self->getPath or croak 'Unable to chdir to ' . $self->getPath . ": $!"; - my @files = (); - find(sub { push(@files, $File::Find::name)}, "."); - if ($Archive::Tar::VERSION eq '0.072') { - my $tar = Archive::Tar->new(); - $tar->add_files(@files); - $tar->write($temp->getPath($filename),1); - - } else { - Archive::Tar->create_archive($temp->getPath($filename),1,@files); - } - return $temp; + my @files = (); + find(sub { push(@files, $File::Find::name)}, "."); + if ($Archive::Tar::VERSION eq '0.072') { + my $tar = Archive::Tar->new(); + $tar->add_files(@files); + $tar->write($temp->getPath($filename),1); + + } + else { + Archive::Tar->create_archive($temp->getPath($filename),1,@files); + } + return $temp; } #------------------------------------------------------------------- @@ -932,12 +967,17 @@ Pass in a storage location object to extract the contents to, instead of having =cut sub untar { - my $self = shift; - my $filename = shift; - my $temp = shift || WebGUI::Storage->createTemp($self->session); + my $self = shift; + my $filename = shift; + my $temp = shift || WebGUI::Storage->createTemp($self->session); + + my $originalDir = cwd; chdir $temp->getPath; + Archive::Tar->extract_archive($self->getPath($filename),1); $self->_addError(Archive::Tar->error) if (Archive::Tar->error); + + chdir $originalDir; return $temp; } diff --git a/lib/WebGUI/Storage/Image.pm b/lib/WebGUI/Storage/Image.pm index 008a6ed6c..241d1a783 100644 --- a/lib/WebGUI/Storage/Image.pm +++ b/lib/WebGUI/Storage/Image.pm @@ -52,11 +52,11 @@ use WebGUI::Storage::Image; These methods are available from this class: -my $boolean = $self->generateThumbnail($filename); -my $url = $self->getThumbnailUrl($filename); -my $boolean = $self->isImage($filename); -my ($captchaFile, $challenge) = $self->addFileFromCaptcha; -$self->resize($imageFile, $width, $height); + my $boolean = $self->generateThumbnail($filename); + my $url = $self->getThumbnailUrl($filename); + my $boolean = $self->isImage($filename); + my ($captchaFile, $challenge) = $self->addFileFromCaptcha; + $self->resize($imageFile, $width, $height); =cut @@ -284,7 +284,7 @@ sub getThumbnailUrl { return ''; } if (! isIn($filename, @{ $self->getFiles() })) { - $self->session->errorHandler->error("Can't make a thumbnail for a file that is not in my storage location."); + $self->session->errorHandler->error("Can't make a thumbnail for a file named '$filename' that is not in my storage location."); return ''; } return $self->getUrl("thumb-".$filename); @@ -331,41 +331,42 @@ The new height of the image in pixels. =cut sub resize { - my $self = shift; - my $filename = shift; - my $width = shift; - my $height = shift; - unless (defined $filename) { - $self->session->errorHandler->error("Can't resize when you haven't specified a file."); - return 0; - } - unless ($self->isImage($filename)) { - $self->session->errorHandler->error("Can't resize something that's not an image."); - return 0; - } - unless ($width || $height) { - $self->session->errorHandler->error("Can't resize with no resizing parameters."); - return 0; - } - my $image = $graphicsPackage->new; - my $error = $image->Read($self->getPath($filename)); - if ($error) { - $self->session->errorHandler->error("Couldn't read image for resizing: ".$error); - return 0; - } - my ($x, $y) = $image->Get('width','height'); - if ($width && !$height) { # proportional scale by width - $height = $width / $x * $y; - } elsif (!$width && $height) { # proportional scale by height - $width = $height * $x / $y; - } - $image->Scale(width=>$width, height=>$height); - $error = $image->Write($self->getPath($filename)); - if ($error) { - $self->session->errorHandler->error("Couldn't create thumbnail: ".$error); - return 0; - } - return 1; + my $self = shift; + my $filename = shift; + my $width = shift; + my $height = shift; + unless (defined $filename) { + $self->session->errorHandler->error("Can't resize when you haven't specified a file."); + return 0; + } + unless ($self->isImage($filename)) { + $self->session->errorHandler->error("Can't resize something that's not an image."); + return 0; + } + unless ($width || $height) { + $self->session->errorHandler->error("Can't resize with no resizing parameters."); + return 0; + } + my $image = $graphicsPackage->new; + my $error = $image->Read($self->getPath($filename)); + if ($error) { + $self->session->errorHandler->error("Couldn't read image for resizing: ".$error); + return 0; + } + my $geometry; + if (!$width || !$height) { + $geometry = $width || $height; + } + else { + $geometry = $width . "x" . $height; + } + $image->Resize( geometry => $geometry, filter => "lanczos" ); + $error = $image->Write($self->getPath($filename)); + if ($error) { + $self->session->errorHandler->error("Couldn't resize image: ".$error); + return 0; + } + return 1; } diff --git a/lib/WebGUI/i18n/English/Asset_Gallery.pm b/lib/WebGUI/i18n/English/Asset_Gallery.pm index 41bc3d843..a93676cf9 100644 --- a/lib/WebGUI/i18n/English/Asset_Gallery.pm +++ b/lib/WebGUI/i18n/English/Asset_Gallery.pm @@ -5,6 +5,554 @@ our $I18N = { message => 'Gallery', lastUpdated => 1131394072, }, + "groupIdAddComment label" => { + message => "Group to Add Comments", + lastUpdated => 0, + context => '', + }, + "groupIdAddComment description" => { + message => "The group that is allowed to add comments to files.", + lastUpdated => 0, + context => '', + }, + "groupIdAddFile label" => { + message => "Group to Add Files", + lastUpdated => 0, + context => '', + }, + "groupIdAddFile description" => { + message => "The group that is allowed to add files and albums to this gallery", + lastUpdated => 0, + context => '', + }, + "groupIdModerator label" => { + message => "Group to Moderate Comments", + lastUpdated => 0, + context => '', + }, + "groupIdModerator description" => { + message => "The group that is allowed to edit / delete comments in this gallery", + lastUpdated => 0, + context => '', + }, + "imageResolutions label" => { + message => "Image Resolutions", + lastUpdated => 0, + context => '', + }, + "imageResolutions description" => { + message => "The sizes of images available for download.", + lastUpdated => 0, + context => '', + }, + "imageViewSize label" => { + message => "Image View Size", + lastUpdated => 0, + context => '', + }, + "imageViewSize description" => { + message => "The size for images in the gallery. Will default to the Image Size + in the site settings.", + lastUpdated => 0, + context => '', + }, + "imageThumbnailSize label" => { + message => "Image Thumbnail Size", + lastUpdated => 0, + context => '', + }, + "imageThumbnailSize description" => { + message => "The size for thumbnails of images in the gallery. Will default to the + Thumbnail Size in the site settings.", + lastUpdated => 0, + context => '', + }, + "maxSpacePerUser label" => { + message => "Max Disk Space Per User", + lastUpdated => 0, + context => '', + }, + "maxSpacePerUser description" => { + message => "The maximum amount of disk space a user is allowed to use in this Gallery.", + lastUpdated => 0, + context => '', + }, + "richEditIdFileComment label" => { + message => "Rich Editor for Comments", + lastUpdated => 0, + context => '', + }, + "richEditIdFileComment description" => { + message => "The Rich Text Editor to use for comments", + lastUpdated => 0, + context => '', + }, + 'search class galleryalbum' => { + message => 'Album', + lastUpdated => 0, + context => 'Asset name for WebGUI::Asset::Wobject::GalleryAlbum', + }, + 'search class any' => { + message => 'Any', + lastUpdated => 0, + context => 'Label to not restrict gallery search by class', + }, + 'search class photo' => { + message => "Photo", + lastUpdated => 0, + context => 'Asset name for WebGUI::Asset::File::Image::Photo class', + }, + "search submit" => { + message => "Search", + lastUpdated => 0, + context => 'Label for button to submit search form', + }, + "templateIdAddArchive label" => { + message => "Template to Add Multiple", + lastUpdated => 0, + context => '', + }, + "templateIdAddArchive description" => { + message => "Display the form to add an archive of files to the gallery.", + lastUpdated => 0, + context => '', + }, + "templateIdDeleteAlbum label" => { + message => "Template to Delete Albums", + lastUpdated => 0, + context => '', + }, + "templateIdDeleteAlbum description" => { + message => "Display the confirmation to delete an album from the gallery.", + lastUpdated => 0, + context => '', + }, + "templateIdDeleteFile label" => { + message => "Template to Delete Files", + lastUpdated => 0, + context => '', + }, + "templateIdDeleteFile description" => { + message => "Display the confirmation to delete a file from the gallery.", + lastUpdated => 0, + context => '', + }, + "templateIdEditAlbum label" => { + message => "Template to Edit Albums", + lastUpdated => 0, + context => '', + }, + "templateIdEditAlbum description" => { + message => "The template to add / edit an album.", + lastUpdated => 0, + context => '', + }, + "templateIdEditFile label" => { + message => "Template to Edit Files", + lastUpdated => 0, + context => '', + }, + "templateIdEditFile description" => { + message => "The template to add / edit a file.", + lastUpdated => 0, + context => '', + }, + "templateIdListAlbums label" => { + message => "Template to List Albums", + lastUpdated => 0, + context => '', + }, + "templateIdListAlbums description" => { + message => "Template to show a list of albums in the gallery.", + lastUpdated => 0, + context => '', + }, + "templateIdListAlbumsRss label" => { + message => "Template to List Albums RSS", + lastUpdated => 0, + context => '', + }, + "templateIdListAlbumsRss description" => { + message => "Template to show an RSS feed of the albums in this gallery.", + lastUpdated => 0, + context => '', + }, + "templateIdMakeShortcut label" => { + message => "Template to Cross Post Files", + lastUpdated => 0, + context => '', + }, + "templateIdMakeShortcut description" => { + message => "Display the form to copy an image to another album.", + lastUpdated => 0, + context => '', + }, + "templateIdSearch label" => { + message => "Template to Search", + lastUpdated => 0, + context => '', + }, + "templateIdSearch description" => { + message => "Display the form to search the gallery. Display search results.", + lastUpdated => 0, + context => '', + }, + "templateIdViewSlideshow label" => { + message => "Template for Slideshow", + lastUpdated => 0, + context => '', + }, + "templateIdViewSlideshow description" => { + message => "Display all the images in an album as a slideshow.", + lastUpdated => 0, + context => '', + }, + "templateIdViewThumbnails label" => { + message => "Template for Thumbnails", + lastUpdated => 0, + context => '', + }, + "templateIdViewThumbnails description" => { + message => "Display all the images in an album as their thumbnails", + lastUpdated => 0, + context => '', + }, + "templateIdListFilesForUser label" => { + message => "Template to List Files for User", + lastUpdated => 0, + context => '', + }, + "templateIdListFilesForUser description" => { + message => "Display all the files and albums for a specific user.", + lastUpdated => 0, + context => '', + }, + "templateIdListFilesForUserRss label" => { + message => "Template to List Files for User RSS", + lastUpdated => 0, + context => '', + }, + "templateIdListFilesForUserRss description" => { + message => "RSS feed for all the files for a specific user.", + lastUpdated => 0, + context => '', + }, + "templateIdViewAlbum label" => { + message => "Template to View Album", + lastUpdated => 0, + context => '', + }, + "templateIdViewAlbum description" => { + message => "Default view for albums", + lastUpdated => 0, + context => '', + }, + "templateIdViewAlbumRss label" => { + message => "Template to View Album RSS", + lastUpdated => 0, + context => '', + }, + "templateIdViewAlbumRss description" => { + message => "RSS feed for a single album", + lastUpdated => 0, + context => '', + }, + "templateIdViewFile label" => { + message => "Template to View a File", + lastUpdated => 0, + context => '', + }, + "templateIdViewFile description" => { + message => "Show the details and comments for a specific file", + lastUpdated => 0, + context => '', + }, + "viewDefault label" => { + message => "Default View", + lastUpdated => 0, + context => '', + }, + "viewDefault description" => { + message => "Select the default view when a user enters the gallery.", + lastUpdated => 0, + context => '', + }, + "viewDefault option list" => { + message => "List Albums", + lastUpdated => 0, + context => '', + }, + "viewDefault option album" => { + message => "Single Album", + lastUpdated => 0, + context => '', + }, + "viewAlbumAssetId label" => { + message => "Default View Album", + lastUpdated => 0, + context => '', + }, + "viewAlbumAssetId description" => { + message => "The album to view when the default view is 'Album'", + lastUpdated => 0, + context => '', + }, + "viewListOrderBy label" => { + message => "List Albums Order By", + lastUpdated => 0, + context => '', + }, + "viewListOrderBy description" => { + message => "The field to order the album list by", + lastUpdated => 0, + context => '', + }, + "viewListOrderBy option creationDate" => { + message => "Creation Date", + lastUpdated => 0, + context => '', + }, + "viewListOrderBy option lineage" => { + message => "Sequence Number", + lastUpdated => 0, + context => 'Label to order by sequence (as in asset manager)', + }, + "viewListOrderBy option revisionDate" => { + message => "Revision Date", + lastUpdated => 0, + context => '', + }, + "viewListOrderBy option title" => { + message => "Title", + lastUpdated => 0, + context => '', + }, + "viewListOrderDirection label" => { + message => "List Albums Direction", + lastUpdated => 0, + context => '', + }, + "viewListOrderDirection description" => { + message => "The direction to order the album list", + lastUpdated => 0, + context => '', + }, + "viewListOrderDirection option asc" => { + message => "Ascending", + lastUpdated => 0, + context => 'Label for sorting in ascending order', + }, + "viewListOrderDirection option desc" => { + message => "Descending", + lastUpdated => 0, + context => 'Label for sorting in descending order', + }, + "workflowIdCommit label" => { + message => "Approval Workflow", + lastUpdated => 0, + context => '', + }, + "workflowIdCommit description" => { + message => "Workflow to approve new Files.", + lastUpdated => 0, + context => '', + }, + + 'helpvar searchForm_start' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar searchForm_end' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar searchForm_basicSearch' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar searchForm_title' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar searchForm_description' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar searchForm_keywords' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar searchForm_className' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar searchForm_creationDate_after' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar searchForm_creationDate_before' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar searchForm_submit' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar url_addAlbum' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar url_listAlbums' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar url_listAlbumsRss' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar url_listFilesForCurrentUser' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar url_search' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar canEdit' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar canAddFile' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar albums' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar albums rss' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar rssDate' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar search_results' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar user_albums' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar user_files' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar userId' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar url_rss' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar username' => { + message => '', + lastUpdated => 0, + }, + + 'help searchForm title' => { + message => '', + lastUpdated => 0, + }, + + 'help searchForm body' => { + message => '', + lastUpdated => 0, + }, + + 'help common title' => { + message => '', + lastUpdated => 0, + }, + + 'help common body' => { + message => '', + lastUpdated => 0, + }, + + 'help listAlbums title' => { + message => '', + lastUpdated => 0, + }, + + 'help listAlbums body' => { + message => '', + lastUpdated => 0, + }, + + 'help listAlbumsRss title' => { + message => '', + lastUpdated => 0, + }, + + 'help search body' => { + message => '', + lastUpdated => 0, + }, + + 'help search title' => { + message => '', + lastUpdated => 0, + }, + + 'help listFilesForUser title' => { + message => '', + lastUpdated => 0, + }, + + 'help listFilesForUser body' => { + message => '', + lastUpdated => 0, + }, + + 'help listFilesForUserRss title' => { + message => '', + lastUpdated => 0, + }, + + 'help listFilesForUserRss body' => { + message => '', + lastUpdated => 0, + }, + }; 1; diff --git a/lib/WebGUI/i18n/English/Asset_GalleryAlbum.pm b/lib/WebGUI/i18n/English/Asset_GalleryAlbum.pm index cff839973..7724c47fc 100644 --- a/lib/WebGUI/i18n/English/Asset_GalleryAlbum.pm +++ b/lib/WebGUI/i18n/English/Asset_GalleryAlbum.pm @@ -1,10 +1,299 @@ package WebGUI::i18n::English::Asset_GalleryAlbum; our $I18N = { + 'addArchive message' => { + message => 'Your files have been submitted for approval and commit. Return to Album', + lastUpdated => 0, + }, 'assetName' => { message => 'Gallery Album', lastUpdated => 1131394072, }, + 'cancel' => { + message => "Cancel", + lastUpdated => 0, + context => "Label for Cancel button", + }, + 'save' => { + message => "Save", + lastUpdated => 0, + context => "Label for Save button", + }, + 'save message' => { + message => 'Album settings saved. Return to Album', + lastUpdated => 0, + }, + + 'help common title' => { + message => '', + lastUpdated => 0, + }, + + 'help common body' => { + message => '', + lastUpdated => 0, + }, + + 'help fileLoop title' => { + message => '', + lastUpdated => 0, + }, + + 'help fileLoop body' => { + message => '', + lastUpdated => 0, + }, + + 'help view title' => { + message => '', + lastUpdated => 0, + }, + + 'help view body' => { + message => '', + lastUpdated => 0, + }, + + 'help slideshow title' => { + message => '', + lastUpdated => 0, + }, + + 'help slideshow body' => { + message => '', + lastUpdated => 0, + }, + + 'help thumbnails title' => { + message => '', + lastUpdated => 0, + }, + + 'help thumbnails body' => { + message => '', + lastUpdated => 0, + }, + + 'help addArchive title' => { + message => '', + lastUpdated => 0, + }, + + 'help addArchive body' => { + message => '', + lastUpdated => 0, + }, + + 'help delete title' => { + message => '', + lastUpdated => 0, + }, + + 'help delete body' => { + message => '', + lastUpdated => 0, + }, + + 'help edit title' => { + message => '', + lastUpdated => 0, + }, + + 'help viewRss title' => { + message => '', + lastUpdated => 0, + }, + + 'help viewRss body' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar canAddFile' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar canEdit' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar url_listAlbums' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar url_listAlbumsRss' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar url_listFilesForCurrentUser' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar url_search' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar url_addArchive' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar url_addPhoto' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar url_addNoClass' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar url_delete' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar url_edit' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar url_listFilesForOwner' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar url_viewRss' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar url_slideshow' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar url_thumbnails' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar fileCount' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar ownerUsername' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar thumbnailUrl' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar file_loop' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar file_*' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar form_start' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar form_end' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar form_submit' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar form_archive' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar form_keywords' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar form_friendsOnly' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar url_yes' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar form_start' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar form_end' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar form_cancel' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar form_submit' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar form_title' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar form_description' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar file_loop edit' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar isAlbumThumbnail' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar file_loop viewRss' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar rssDate' => { + message => '', + lastUpdated => 0, + }, + }; 1; diff --git a/lib/WebGUI/i18n/English/Asset_Photo.pm b/lib/WebGUI/i18n/English/Asset_Photo.pm new file mode 100644 index 000000000..bca896348 --- /dev/null +++ b/lib/WebGUI/i18n/English/Asset_Photo.pm @@ -0,0 +1,291 @@ +package WebGUI::i18n::English::Asset_Photo; + +our $I18N = { + 'assetName' => { + message => q{Photo}, + lastUpdated => 0, + }, + + 'delete message' => { + message => q{The photo has been deleted. Return to Album}, + lastUpdated => 0, + }, + + 'save message' => { + message => q{Your photo has been submitted for approval and commit. View Photo. Add another photo.}, + lastUpdated => 0, + }, + + 'help commentForm title' => { + message => 'Photo -- Comment Form', + lastUpdated => 0, + }, + + 'help commentForm body' => { + message => 'These template variables make up the form to allow users to post comments on Photos', + lastUpdated => 0, + }, + + 'help common title' => { + message => 'Photo -- Common', + lastUpdated => 0, + }, + + 'help common body' => { + message => 'These template variables are shared by all views of the Photo asset.', + lastUpdated => 0, + }, + + 'help edit title' => { + message => 'Photo -- Edit Form', + lastUpdated => 0, + }, + + 'help edit body' => { + message => 'These template variables make up the form to add / edit Photo assets', + lastUpdated => 0, + }, + + 'help makeShortcut title' => { + message => 'Photo -- Make Shortcut Form', + lastUpdated => 0, + }, + + 'help makeShortcut body' => { + message => 'These template variables make up the form to cross-post Photo assets', + lastUpdated => 0, + }, + + 'help view title' => { + message => 'Photo -- Normal View', + lastUpdated => 0, + }, + + 'help view body' => { + message => 'These template variables make up the normal view of Photo assets', + lastUpdated => 0, + }, + + 'helpvar commentForm_start' => { + message => 'Begin the comment form', + lastUpdated => 0, + }, + + 'helpvar commentForm_end' => { + message => 'End the comment form', + lastUpdated => 0, + }, + + 'helpvar commentForm_bodyText' => { + message => 'The body of the comment. A rich editor as configured by the parent Gallery.', + lastUpdated => 0, + }, + + 'helpvar commentForm_submit' => { + message => 'Submit the comment form', + lastUpdated => 0, + }, + + 'helpvar canComment' => { + message => 'This is true if the current user can comment on this photo', + lastUpdated => 0, + }, + + 'helpvar canEdit' => { + message => 'This is true if the current user can edit this photo', + lastUpdated => 0, + }, + + 'helpvar fileUrl' => { + message => 'The URL to the normal-sized photo', + lastUpdated => 0, + }, + + 'helpvar numberOfComments' => { + message => 'The total number of comments on this photo', + lastUpdated => 0, + }, + + 'helpvar ownerUsername' => { + message => 'The username of the user who posted this photo', + lastUpdated => 0, + }, + + 'helpvar thumbnailUrl' => { + message => 'The URL to the thumbnail of this photo', + lastUpdated => 0, + }, + + 'helpvar url_delete' => { + message => 'The URL to delete this photo.', + lastUpdated => 0, + }, + + 'helpvar url_demote' => { + message => 'The URL to demote this photo in rank. Will return the user directly to the parent GalleryAlbum edit form', + lastUpdated => 0, + }, + + 'helpvar url_edit' => { + message => 'The URL to edit this photo', + lastUpdated => 0, + }, + + 'helpvar url_gallery' => { + message => 'The URL to the Gallery that contains this photo.', + lastUpdated => 0, + }, + + 'helpvar url_makeShortcut' => { + message => 'The URL to make a shortcut to this photo.', + lastUpdated => 0, + }, + + 'helpvar url_listFilesForOwner' => { + message => 'The URL to list files and albums posted by the owner of this photo', + lastUpdated => 0, + }, + + 'helpvar url_promote' => { + message => 'The URL to promote this photo in rank. Will return the user directly to the parent GalleryAlbum edit form', + lastUpdated => 0, + }, + + 'helpvar resolutions_loop' => { + message => 'The available resolutions this photo has for download.', + lastUpdated => 0, + }, + + 'helpvar resolutions_loop url_download' => { + message => 'The URL to the resolution to download.', + lastUpdated => 0, + }, + + 'helpvar exif_*' => { + message => 'Each EXIF tag can be referenced by name.', + lastUpdated => 0, + }, + + 'helpvar exifLoop' => { + message => 'A loop of EXIF tags', + lastUpdated => 0, + }, + + 'helpvar exifLoop tag' => { + message => 'The name of the EXIF tag', + lastUpdated => 0, + }, + + 'helpvar exifLoop value' => { + message => 'The value of the EXIF tag', + lastUpdated => 0, + }, + + 'helpvar url_addArchive' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar form_start' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar form_end' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar form_submit' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar form_title' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar form_synopsis' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar form_photo' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar form_keywords' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar form_location' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar form_friendsOnly' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar form_start' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar form_end' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar form_parentId' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar commentLoop' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar commentLoop userId' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar commentLoop visitorIp' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar commentLoop creationDate' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar commentLoop bodyText' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar commentLoop username' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar commentLoop_pageBar' => { + message => '', + lastUpdated => 0, + }, + + 'helpvar url_yes' => { + message => '', + lastUpdated => 0, + }, + +}; + +1; diff --git a/t/Asset/Wobject/Gallery/00base.t b/t/Asset/Wobject/Gallery/00base.t new file mode 100644 index 000000000..0119dc465 --- /dev/null +++ b/t/Asset/Wobject/Gallery/00base.t @@ -0,0 +1,78 @@ +#------------------------------------------------------------------- +# WebGUI is Copyright 2001-2007 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 FindBin; +use strict; +use lib "$FindBin::Bin/../../../../lib"; + +## The goal of this test is to test the creation and deletion of album assets + +use Scalar::Util qw( blessed ); +use WebGUI::Test; +use WebGUI::Session; +use Test::More; + +#---------------------------------------------------------------------------- +# Init +my $session = WebGUI::Test->session; +my $node = WebGUI::Asset->getImportNode($session); +my $versionTag = WebGUI::VersionTag->getWorking($session); +$versionTag->set({name=>"Album Test"}); +my $gallery + = $node->addChild({ + className => "WebGUI::Asset::Wobject::Gallery", + }); + +#---------------------------------------------------------------------------- +# Cleanup +END { + $versionTag->rollback(); +} + +#---------------------------------------------------------------------------- +# Tests +plan tests => 5; + +#---------------------------------------------------------------------------- +# Test module compiles okay +# plan tests => 1 +use_ok("WebGUI::Asset::Wobject::GalleryAlbum"); + +#---------------------------------------------------------------------------- +# Test creating an album +my $album + = $gallery->addChild({ + className => "WebGUI::Asset::Wobject::GalleryAlbum", + }); + +is( + blessed $album, "WebGUI::Asset::Wobject::GalleryAlbum", + "Album is a WebGUI::Asset::Wobject::GalleryAlbum object", +); + +isa_ok( + $album, "WebGUI::Asset::Wobject", +); + +#---------------------------------------------------------------------------- +# Test deleting a album +my $properties = $album->get; +$album->purge; + +is( + $album, undef, + "Album is undefined", +); + +is( + WebGUI::Asset->newByDynamicClass($session, $properties->{assetId}), undef, + "Album no longer able to be instanciated", +); + diff --git a/t/Asset/Wobject/Gallery/delete.t b/t/Asset/Wobject/Gallery/delete.t new file mode 100644 index 000000000..f49603f93 --- /dev/null +++ b/t/Asset/Wobject/Gallery/delete.t @@ -0,0 +1,96 @@ +# $vim: syntax=perl +#------------------------------------------------------------------- +# WebGUI is Copyright 2001-2007 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 FindBin; +use strict; +use lib "$FindBin::Bin/../../../../lib"; + +## The goal of this test is to test the deleting of GalleryAlbums + +use Scalar::Util qw( blessed ); +use WebGUI::Test; +use WebGUI::Session; +use Test::More; + +#---------------------------------------------------------------------------- +# Init +my $maker = WebGUI::Test::Maker::Html->new; +my $session = WebGUI::Test->session; +my $node = WebGUI::Asset->getImportNode($session); +my $versionTag = WebGUI::VersionTag->getWorking($session); +$versionTag->set({name=>"Album Test"}); +my $gallery + = $node->addChild({ + className => "WebGUI::Asset::Wobject::Gallery", + groupIdAddComment => 2, # Registered Users + groupIdAddFile => 2, # Registered Users + groupIdView => 7, # Everyone + groupIdEdit => 3, # Admins + ownerUserId => 3, # Admin + }); +my $album + = $gallery->addChild({ + className => "WebGUI::Asset::Wobject::GalleryAlbum", + ownerUserId => "3", # Admin + }); + +#---------------------------------------------------------------------------- +# Cleanup +END { + $versionTag->rollback(); +} + +#---------------------------------------------------------------------------- +# Tests +plan no_plan => 1; + +#---------------------------------------------------------------------------- +# Delete page gives error for those who can't edit the GalleryAlbum +$maker->prepare({ + object => $album, + method => "www_delete", + test_privilege => "insufficient", + userId => 1, +}, { + object => $album, + method => "www_deleteConfirm", + test_privilege => "insufficient", + userId => 1, +}); +$maker->run; + +#---------------------------------------------------------------------------- +# Delete confirm page appears for those allowed to edit the GalleryAlbum +$maker->prepare({ + object => $album, + method => "www_delete", + test_regex => [ qr/func=deleteConfirm/, ], + userId => 3, +}); +$maker->run; + +#---------------------------------------------------------------------------- +# www_deleteConfirm deletes the asset +my $assetId = $album->getId; +$maker->prepare({ + object => $album, + method => "www_deleteConfirm", + test_regex => [ qr/has been deleted/, ], + userId => 3, +}); +$maker->run; + +is( + WebGUI::Asset->newByDynamicClass( $session, $assetId ), + undef, + "GalleryAlbum cannot be instanciated after www_deleteConfirm", +); + diff --git a/t/Asset/Wobject/Gallery/listFilesForUser.t b/t/Asset/Wobject/Gallery/listFilesForUser.t new file mode 100644 index 000000000..0119dc465 --- /dev/null +++ b/t/Asset/Wobject/Gallery/listFilesForUser.t @@ -0,0 +1,78 @@ +#------------------------------------------------------------------- +# WebGUI is Copyright 2001-2007 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 FindBin; +use strict; +use lib "$FindBin::Bin/../../../../lib"; + +## The goal of this test is to test the creation and deletion of album assets + +use Scalar::Util qw( blessed ); +use WebGUI::Test; +use WebGUI::Session; +use Test::More; + +#---------------------------------------------------------------------------- +# Init +my $session = WebGUI::Test->session; +my $node = WebGUI::Asset->getImportNode($session); +my $versionTag = WebGUI::VersionTag->getWorking($session); +$versionTag->set({name=>"Album Test"}); +my $gallery + = $node->addChild({ + className => "WebGUI::Asset::Wobject::Gallery", + }); + +#---------------------------------------------------------------------------- +# Cleanup +END { + $versionTag->rollback(); +} + +#---------------------------------------------------------------------------- +# Tests +plan tests => 5; + +#---------------------------------------------------------------------------- +# Test module compiles okay +# plan tests => 1 +use_ok("WebGUI::Asset::Wobject::GalleryAlbum"); + +#---------------------------------------------------------------------------- +# Test creating an album +my $album + = $gallery->addChild({ + className => "WebGUI::Asset::Wobject::GalleryAlbum", + }); + +is( + blessed $album, "WebGUI::Asset::Wobject::GalleryAlbum", + "Album is a WebGUI::Asset::Wobject::GalleryAlbum object", +); + +isa_ok( + $album, "WebGUI::Asset::Wobject", +); + +#---------------------------------------------------------------------------- +# Test deleting a album +my $properties = $album->get; +$album->purge; + +is( + $album, undef, + "Album is undefined", +); + +is( + WebGUI::Asset->newByDynamicClass($session, $properties->{assetId}), undef, + "Album no longer able to be instanciated", +); + diff --git a/t/Asset/Wobject/Gallery/permission.t b/t/Asset/Wobject/Gallery/permission.t new file mode 100644 index 000000000..2d91342ed --- /dev/null +++ b/t/Asset/Wobject/Gallery/permission.t @@ -0,0 +1,107 @@ +#------------------------------------------------------------------- +# WebGUI is Copyright 2001-2007 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 FindBin; +use strict; +use lib "$FindBin::Bin/../../../../lib"; + +## The goal of this test is to test the permissions of GalleryAlbum assets + +use Scalar::Util qw( blessed ); +use WebGUI::Test; +use WebGUI::Session; +use Test::More; +use WebGUI::Test::Maker::Permission; + +#---------------------------------------------------------------------------- +# Init +my $maker = WebGUI::Test::Maker::Permission->new; +my $session = WebGUI::Test->session; +my $node = WebGUI::Asset->getImportNode($session); + +my %user; +$user{"2"} = WebGUI::User->new( $session, "new" ); +$user{"2"}->addToGroups( ['2'] ); # Registered user + +my $versionTag = WebGUI::VersionTag->getWorking($session); +$versionTag->set({name=>"Album Test"}); +my $gallery + = $node->addChild({ + className => "WebGUI::Asset::Wobject::Gallery", + groupIdAddComment => 2, # Registered Users + groupIdAddFile => 2, # Registered Users + groupIdView => 7, # Everyone + groupIdEdit => 3, # Admins + ownerUserId => 3, # Admin + }); +my $album + = $gallery->addChild({ + className => "WebGUI::Asset::Wobject::GalleryAlbum", + ownerUserId => "3", # Admin + }); + +#---------------------------------------------------------------------------- +# Cleanup +END { + $versionTag->rollback(); + $user{"2"}->delete; +} + +#---------------------------------------------------------------------------- +# Tests +plan no_plan => 1; + +#---------------------------------------------------------------------------- +# By default, GalleryAlbum inherits its permissions from the Gallery, but +# only the owner of the GalleryAlbum is allowed to add files +$maker->prepare({ + object => $album, + method => "canView", + pass => [ 1, 3, $user{"2"}, ], +}, { + object => $album, + method => "canEdit", + pass => [ 3, ], + fail => [ 1, $user{"2"}, ], +}, { + object => $album, + method => "canAddFile", + pass => [ 3, ], + fail => [ 1, $user{"2"}, ], +}, { + object => $album, + method => "canAddComment", + pass => [ 3, $user{"2"}, ], + fail => [ 1, ], +}); +$maker->run; + +#---------------------------------------------------------------------------- +# GalleryAlbums with "allowComments" false do not allow anyone to comment +$album->update({ allowComments => 0 }); +$maker->prepare({ + object => $album, + method => "canComment", + fail => [ 1, 3, $user{"2"}, ], +}); +$maker->run; + +#---------------------------------------------------------------------------- +# GalleryAlbum with "othersCanAdd" true allows anyone who can add files to +# the Gallery to add files to this GalleryAlbum +$album->update({ othersCanAdd => 1 }); +$maker->prepare({ + object => $album, + method => "canAddFile", + pass => [ 3, $user{"2"}, ], + fail => [ 1, ], +}); +$maker->run; + diff --git a/t/Asset/Wobject/Gallery/rss.t b/t/Asset/Wobject/Gallery/rss.t new file mode 100644 index 000000000..1f96b786c --- /dev/null +++ b/t/Asset/Wobject/Gallery/rss.t @@ -0,0 +1,66 @@ +# $vim: syntax=perl +#------------------------------------------------------------------- +# WebGUI is Copyright 2001-2007 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 FindBin; +use strict; +use lib "$FindBin::Bin/../../../../lib"; + +## The goal of this test is to test the rss view of GalleryAlbums + +use Scalar::Util qw( blessed ); +use WebGUI::Test; +use WebGUI::Session; +use Test::More; +use WebGUI::Test::Maker::HTML; + +#---------------------------------------------------------------------------- +# Init +my $maker = WebGUI::Test::Maker::HTML->new; +my $session = WebGUI::Test->session; +my $node = WebGUI::Asset->getImportNode($session); +my $versionTag = WebGUI::VersionTag->getWorking($session); +$versionTag->set({name=>"Album Test"}); +my $gallery + = $node->addChild({ + className => "WebGUI::Asset::Wobject::Gallery", + groupIdAddComment => 2, # Registered Users + groupIdAddFile => 2, # Registered Users + groupIdView => 7, # Everyone + groupIdEdit => 3, # Admins + ownerUserId => 3, # Admin + }); +my $album + = $gallery->addChild({ + className => "WebGUI::Asset::Wobject::GalleryAlbum", + ownerUserId => "3", # Admin + }); +my @photos; +for my $i ( 0 .. 5 ) { + $photos[ $i ] + = $album->addChild({ + className => "WebGUI::Asset::File::Image::Photo", + filename => "$i.jpg", + }); +} + +#---------------------------------------------------------------------------- +# Cleanup +END { + $versionTag->rollback(); +} + +#---------------------------------------------------------------------------- +# Tests +plan no_plan => 1; + +#---------------------------------------------------------------------------- +# Test www_viewRss + diff --git a/t/Asset/Wobject/Gallery/search.t b/t/Asset/Wobject/Gallery/search.t new file mode 100644 index 000000000..0119dc465 --- /dev/null +++ b/t/Asset/Wobject/Gallery/search.t @@ -0,0 +1,78 @@ +#------------------------------------------------------------------- +# WebGUI is Copyright 2001-2007 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 FindBin; +use strict; +use lib "$FindBin::Bin/../../../../lib"; + +## The goal of this test is to test the creation and deletion of album assets + +use Scalar::Util qw( blessed ); +use WebGUI::Test; +use WebGUI::Session; +use Test::More; + +#---------------------------------------------------------------------------- +# Init +my $session = WebGUI::Test->session; +my $node = WebGUI::Asset->getImportNode($session); +my $versionTag = WebGUI::VersionTag->getWorking($session); +$versionTag->set({name=>"Album Test"}); +my $gallery + = $node->addChild({ + className => "WebGUI::Asset::Wobject::Gallery", + }); + +#---------------------------------------------------------------------------- +# Cleanup +END { + $versionTag->rollback(); +} + +#---------------------------------------------------------------------------- +# Tests +plan tests => 5; + +#---------------------------------------------------------------------------- +# Test module compiles okay +# plan tests => 1 +use_ok("WebGUI::Asset::Wobject::GalleryAlbum"); + +#---------------------------------------------------------------------------- +# Test creating an album +my $album + = $gallery->addChild({ + className => "WebGUI::Asset::Wobject::GalleryAlbum", + }); + +is( + blessed $album, "WebGUI::Asset::Wobject::GalleryAlbum", + "Album is a WebGUI::Asset::Wobject::GalleryAlbum object", +); + +isa_ok( + $album, "WebGUI::Asset::Wobject", +); + +#---------------------------------------------------------------------------- +# Test deleting a album +my $properties = $album->get; +$album->purge; + +is( + $album, undef, + "Album is undefined", +); + +is( + WebGUI::Asset->newByDynamicClass($session, $properties->{assetId}), undef, + "Album no longer able to be instanciated", +); + diff --git a/t/Asset/Wobject/Gallery/view.t b/t/Asset/Wobject/Gallery/view.t new file mode 100644 index 000000000..dedd4f74a --- /dev/null +++ b/t/Asset/Wobject/Gallery/view.t @@ -0,0 +1,130 @@ +# $vim: syntax=perl +#------------------------------------------------------------------- +# WebGUI is Copyright 2001-2007 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 FindBin; +use strict; +use lib "$FindBin::Bin/../../../lib"; + +## The goal of this test is to test the default view and associated subs + +use Scalar::Util qw( blessed ); +use WebGUI::Test; +use WebGUI::Session; +use Test::More; +use Test::Deep; +use WebGUI::Test::Maker::HTML; + +#---------------------------------------------------------------------------- +# Init +my $maker = WebGUI::Test::Maker::HTML->new; +my $session = WebGUI::Test->session; +my $node = WebGUI::Asset->getImportNode($session); +my $versionTag = WebGUI::VersionTag->getWorking($session); +$versionTag->set({name=>"Album Test"}); +my $gallery + = $node->addChild({ + className => "WebGUI::Asset::Wobject::Gallery", + groupIdAddComment => 2, # Registered Users + groupIdAddFile => 2, # Registered Users + groupIdView => 2, # Registered Users + groupIdEdit => 3, # Admins + ownerUserId => 3, # Admin + }); +my $album + = $gallery->addChild({ + className => "WebGUI::Asset::Wobject::GalleryAlbum", + ownerUserId => "3", # Admin + }); +my @photos; +for my $i ( 0 .. 5 ) { + $photos[ $i ] + = $album->addChild({ + className => "WebGUI::Asset::File::Image::Photo", + filename => "$i.jpg", + }); +} + +#---------------------------------------------------------------------------- +# Cleanup +END { + $versionTag->rollback(); +} + +#---------------------------------------------------------------------------- +# Tests +plan no_plan => 1; + +#---------------------------------------------------------------------------- +# Test getFileIds and getFilePaginator +cmp_bag( $album->getFileIds, [ map { $_->getId } @photos ] ); + +my $p = $album->getFilePaginator; +isa_ok( $p, "WebGUI::Paginator" ); +cmp_deeply( $p->getPageData, subbagof( map { $_->getId } @photos ) ); + +#---------------------------------------------------------------------------- +# Test getTemplateVars + +# Is a superset of Asset->get +# NOTE: url is Asset->getUrl +cmp_deeply( $album->getTemplateVars, superhashof( { %{$album->get}, url => $album->getUrl, } ) ); + +# Contains specific keys/values +my $expected = { + "url_addPhoto" + => all( + re( qr/className=WebGUI::Asset::File::Image::Photo/ ), + re( qr/func=add/ ), + re( $album->getUrl ), + ), + "url_addNoClass" + => all( + re( $album->getUrl ), + re( qr/func=add$/ ), + ), + "url_slideshow" + => all( + re( $album->getUrl ), + re( qr/func=slideshow/ ), + ), + "url_thumbnails" + => all( + re( $album->getUrl ), + re( qr/func=thumbnails/ ), + ), + "url_viewRss" + => all( + re( $album->getUrl ), + re( qr/func=viewRss/ ), + ), +}; + +cmp_deeply( $album->getTemplateVars, superhashof( $expected ) ); + +#---------------------------------------------------------------------------- +# Test appendTemplateVarsFileLoop +$expected = { + "file_loop" => bag( map { $_->getTemplateVars } @photos ), +}; +cmp_deeply( + $album->appendTemplateVarsFileLoop({},$self->getFilePaginator->getPageData), + $expected +); + +#---------------------------------------------------------------------------- +# Test www_view() for those without permission to view +$maker->prepare({ + object => $album, + method => "www_view", + test_privilege => "insufficient", +}); +$maker->run; + diff --git a/t/Asset/Wobject/GalleryAlbum/addArchive.t b/t/Asset/Wobject/GalleryAlbum/addArchive.t new file mode 100644 index 000000000..29d9844b3 --- /dev/null +++ b/t/Asset/Wobject/GalleryAlbum/addArchive.t @@ -0,0 +1,69 @@ +# $vim: syntax=perl +#------------------------------------------------------------------- +# WebGUI is Copyright 2001-2007 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 FindBin; +use strict; +use lib "$FindBin::Bin/../../../../lib"; + +## The goal of this test is to test the permissions of GalleryAlbum assets + +use Scalar::Util qw( blessed ); +use WebGUI::Test; +use WebGUI::Session; +use Test::More; +use WebGUI::Test::Maker::Permission; + +#---------------------------------------------------------------------------- +# Init +my $maker = WebGUI::Test::Maker::Permission->new; +my $session = WebGUI::Test->session; +my $node = WebGUI::Asset->getImportNode($session); +my $versionTag = WebGUI::VersionTag->getWorking($session); +$versionTag->set({name=>"Album Test"}); +my $gallery + = $node->addChild({ + className => "WebGUI::Asset::Wobject::Gallery", + groupIdAddComment => 2, # Registered Users + groupIdAddFile => 2, # Registered Users + groupIdView => 7, # Everyone + groupIdEdit => 3, # Admins + ownerUserId => 3, # Admin + }); +my $album + = $gallery->addChild({ + className => "WebGUI::Asset::Wobject::GalleryAlbum", + ownerUserId => "3", # Admin + }); + +#---------------------------------------------------------------------------- +# Cleanup +END { + $versionTag->rollback(); +} + +#---------------------------------------------------------------------------- +# Tests +plan tests => 2; + +#---------------------------------------------------------------------------- +# Test the addArchive sub +# elephant_images.zip contains three jpgs: Aana1.jpg, Aana2.jpg, Aana3.jpg +$album->addArchive( WebGUI::Test->getTestCollateralPath('elephant_images.zip') ); +my $images = $album->getLineage(['descendants'], { returnObjects => 1 }); + +is( scalar @$images, 3, "addArchive() adds one asset per image" ); +cmp_deeply( + [ map { $_->get("filename") } @$images ], + bag( "Aana1.jpg", "Aana2.jpg", "Aana3.jpg" ), +); + +#---------------------------------------------------------------------------- +# Test the www_addArchive page diff --git a/t/Asset/Wobject/GalleryAlbum/delete.t b/t/Asset/Wobject/GalleryAlbum/delete.t new file mode 100644 index 000000000..f49603f93 --- /dev/null +++ b/t/Asset/Wobject/GalleryAlbum/delete.t @@ -0,0 +1,96 @@ +# $vim: syntax=perl +#------------------------------------------------------------------- +# WebGUI is Copyright 2001-2007 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 FindBin; +use strict; +use lib "$FindBin::Bin/../../../../lib"; + +## The goal of this test is to test the deleting of GalleryAlbums + +use Scalar::Util qw( blessed ); +use WebGUI::Test; +use WebGUI::Session; +use Test::More; + +#---------------------------------------------------------------------------- +# Init +my $maker = WebGUI::Test::Maker::Html->new; +my $session = WebGUI::Test->session; +my $node = WebGUI::Asset->getImportNode($session); +my $versionTag = WebGUI::VersionTag->getWorking($session); +$versionTag->set({name=>"Album Test"}); +my $gallery + = $node->addChild({ + className => "WebGUI::Asset::Wobject::Gallery", + groupIdAddComment => 2, # Registered Users + groupIdAddFile => 2, # Registered Users + groupIdView => 7, # Everyone + groupIdEdit => 3, # Admins + ownerUserId => 3, # Admin + }); +my $album + = $gallery->addChild({ + className => "WebGUI::Asset::Wobject::GalleryAlbum", + ownerUserId => "3", # Admin + }); + +#---------------------------------------------------------------------------- +# Cleanup +END { + $versionTag->rollback(); +} + +#---------------------------------------------------------------------------- +# Tests +plan no_plan => 1; + +#---------------------------------------------------------------------------- +# Delete page gives error for those who can't edit the GalleryAlbum +$maker->prepare({ + object => $album, + method => "www_delete", + test_privilege => "insufficient", + userId => 1, +}, { + object => $album, + method => "www_deleteConfirm", + test_privilege => "insufficient", + userId => 1, +}); +$maker->run; + +#---------------------------------------------------------------------------- +# Delete confirm page appears for those allowed to edit the GalleryAlbum +$maker->prepare({ + object => $album, + method => "www_delete", + test_regex => [ qr/func=deleteConfirm/, ], + userId => 3, +}); +$maker->run; + +#---------------------------------------------------------------------------- +# www_deleteConfirm deletes the asset +my $assetId = $album->getId; +$maker->prepare({ + object => $album, + method => "www_deleteConfirm", + test_regex => [ qr/has been deleted/, ], + userId => 3, +}); +$maker->run; + +is( + WebGUI::Asset->newByDynamicClass( $session, $assetId ), + undef, + "GalleryAlbum cannot be instanciated after www_deleteConfirm", +); + diff --git a/t/Asset/Wobject/GalleryAlbum/permission.t b/t/Asset/Wobject/GalleryAlbum/permission.t new file mode 100644 index 000000000..2d91342ed --- /dev/null +++ b/t/Asset/Wobject/GalleryAlbum/permission.t @@ -0,0 +1,107 @@ +#------------------------------------------------------------------- +# WebGUI is Copyright 2001-2007 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 FindBin; +use strict; +use lib "$FindBin::Bin/../../../../lib"; + +## The goal of this test is to test the permissions of GalleryAlbum assets + +use Scalar::Util qw( blessed ); +use WebGUI::Test; +use WebGUI::Session; +use Test::More; +use WebGUI::Test::Maker::Permission; + +#---------------------------------------------------------------------------- +# Init +my $maker = WebGUI::Test::Maker::Permission->new; +my $session = WebGUI::Test->session; +my $node = WebGUI::Asset->getImportNode($session); + +my %user; +$user{"2"} = WebGUI::User->new( $session, "new" ); +$user{"2"}->addToGroups( ['2'] ); # Registered user + +my $versionTag = WebGUI::VersionTag->getWorking($session); +$versionTag->set({name=>"Album Test"}); +my $gallery + = $node->addChild({ + className => "WebGUI::Asset::Wobject::Gallery", + groupIdAddComment => 2, # Registered Users + groupIdAddFile => 2, # Registered Users + groupIdView => 7, # Everyone + groupIdEdit => 3, # Admins + ownerUserId => 3, # Admin + }); +my $album + = $gallery->addChild({ + className => "WebGUI::Asset::Wobject::GalleryAlbum", + ownerUserId => "3", # Admin + }); + +#---------------------------------------------------------------------------- +# Cleanup +END { + $versionTag->rollback(); + $user{"2"}->delete; +} + +#---------------------------------------------------------------------------- +# Tests +plan no_plan => 1; + +#---------------------------------------------------------------------------- +# By default, GalleryAlbum inherits its permissions from the Gallery, but +# only the owner of the GalleryAlbum is allowed to add files +$maker->prepare({ + object => $album, + method => "canView", + pass => [ 1, 3, $user{"2"}, ], +}, { + object => $album, + method => "canEdit", + pass => [ 3, ], + fail => [ 1, $user{"2"}, ], +}, { + object => $album, + method => "canAddFile", + pass => [ 3, ], + fail => [ 1, $user{"2"}, ], +}, { + object => $album, + method => "canAddComment", + pass => [ 3, $user{"2"}, ], + fail => [ 1, ], +}); +$maker->run; + +#---------------------------------------------------------------------------- +# GalleryAlbums with "allowComments" false do not allow anyone to comment +$album->update({ allowComments => 0 }); +$maker->prepare({ + object => $album, + method => "canComment", + fail => [ 1, 3, $user{"2"}, ], +}); +$maker->run; + +#---------------------------------------------------------------------------- +# GalleryAlbum with "othersCanAdd" true allows anyone who can add files to +# the Gallery to add files to this GalleryAlbum +$album->update({ othersCanAdd => 1 }); +$maker->prepare({ + object => $album, + method => "canAddFile", + pass => [ 3, $user{"2"}, ], + fail => [ 1, ], +}); +$maker->run; + diff --git a/t/Asset/Wobject/GalleryAlbum/rss.t b/t/Asset/Wobject/GalleryAlbum/rss.t new file mode 100644 index 000000000..1f96b786c --- /dev/null +++ b/t/Asset/Wobject/GalleryAlbum/rss.t @@ -0,0 +1,66 @@ +# $vim: syntax=perl +#------------------------------------------------------------------- +# WebGUI is Copyright 2001-2007 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 FindBin; +use strict; +use lib "$FindBin::Bin/../../../../lib"; + +## The goal of this test is to test the rss view of GalleryAlbums + +use Scalar::Util qw( blessed ); +use WebGUI::Test; +use WebGUI::Session; +use Test::More; +use WebGUI::Test::Maker::HTML; + +#---------------------------------------------------------------------------- +# Init +my $maker = WebGUI::Test::Maker::HTML->new; +my $session = WebGUI::Test->session; +my $node = WebGUI::Asset->getImportNode($session); +my $versionTag = WebGUI::VersionTag->getWorking($session); +$versionTag->set({name=>"Album Test"}); +my $gallery + = $node->addChild({ + className => "WebGUI::Asset::Wobject::Gallery", + groupIdAddComment => 2, # Registered Users + groupIdAddFile => 2, # Registered Users + groupIdView => 7, # Everyone + groupIdEdit => 3, # Admins + ownerUserId => 3, # Admin + }); +my $album + = $gallery->addChild({ + className => "WebGUI::Asset::Wobject::GalleryAlbum", + ownerUserId => "3", # Admin + }); +my @photos; +for my $i ( 0 .. 5 ) { + $photos[ $i ] + = $album->addChild({ + className => "WebGUI::Asset::File::Image::Photo", + filename => "$i.jpg", + }); +} + +#---------------------------------------------------------------------------- +# Cleanup +END { + $versionTag->rollback(); +} + +#---------------------------------------------------------------------------- +# Tests +plan no_plan => 1; + +#---------------------------------------------------------------------------- +# Test www_viewRss + diff --git a/t/Asset/Wobject/GalleryAlbum/slideshow.t b/t/Asset/Wobject/GalleryAlbum/slideshow.t new file mode 100644 index 000000000..36513b46e --- /dev/null +++ b/t/Asset/Wobject/GalleryAlbum/slideshow.t @@ -0,0 +1,69 @@ +# $vim: syntax=perl +#------------------------------------------------------------------- +# WebGUI is Copyright 2001-2007 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 FindBin; +use strict; +use lib "$FindBin::Bin/../../../../lib"; + +## The goal of this test is to test the slideshow view of GalleryAlbums + +use Scalar::Util qw( blessed ); +use WebGUI::Test; +use WebGUI::Session; +use Test::More; +use WebGUI::Test::Maker::HTML; + +#---------------------------------------------------------------------------- +# Init +my $maker = WebGUI::Test::Maker::HTML->new; +my $session = WebGUI::Test->session; +my $node = WebGUI::Asset->getImportNode($session); +my $versionTag = WebGUI::VersionTag->getWorking($session); +$versionTag->set({name=>"Album Test"}); +my $gallery + = $node->addChild({ + className => "WebGUI::Asset::Wobject::Gallery", + groupIdAddComment => 2, # Registered Users + groupIdAddFile => 2, # Registered Users + groupIdView => 7, # Everyone + groupIdEdit => 3, # Admins + ownerUserId => 3, # Admin + }); +my $album + = $gallery->addChild({ + className => "WebGUI::Asset::Wobject::GalleryAlbum", + ownerUserId => "3", # Admin + }); +my @photos; +for my $i ( 0 .. 5 ) { + $photos[ $i ] + = $album->addChild({ + className => "WebGUI::Asset::File::Image::Photo", + filename => "$i.jpg", + }); +} + +#---------------------------------------------------------------------------- +# Cleanup +END { + $versionTag->rollback(); +} + +#---------------------------------------------------------------------------- +# Tests +plan no_plan => 1; + +#---------------------------------------------------------------------------- +# Test view_slideshow + +#---------------------------------------------------------------------------- +# Test www_slideshow + diff --git a/t/Asset/Wobject/GalleryAlbum/thumbnails.t b/t/Asset/Wobject/GalleryAlbum/thumbnails.t new file mode 100644 index 000000000..578dcd34c --- /dev/null +++ b/t/Asset/Wobject/GalleryAlbum/thumbnails.t @@ -0,0 +1,69 @@ +# $vim: syntax=perl +#------------------------------------------------------------------- +# WebGUI is Copyright 2001-2007 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 FindBin; +use strict; +use lib "$FindBin::Bin/../../../../lib"; + +## The goal of this test is to test the thumbnails view of GalleryAlbums + +use Scalar::Util qw( blessed ); +use WebGUI::Test; +use WebGUI::Session; +use Test::More; +use WebGUI::Test::Maker::HTML; + +#---------------------------------------------------------------------------- +# Init +my $maker = WebGUI::Test::Maker::HTML->new; +my $session = WebGUI::Test->session; +my $node = WebGUI::Asset->getImportNode($session); +my $versionTag = WebGUI::VersionTag->getWorking($session); +$versionTag->set({name=>"Album Test"}); +my $gallery + = $node->addChild({ + className => "WebGUI::Asset::Wobject::Gallery", + groupIdAddComment => 2, # Registered Users + groupIdAddFile => 2, # Registered Users + groupIdView => 7, # Everyone + groupIdEdit => 3, # Admins + ownerUserId => 3, # Admin + }); +my $album + = $gallery->addChild({ + className => "WebGUI::Asset::Wobject::GalleryAlbum", + ownerUserId => "3", # Admin + }); +my @photos; +for my $i ( 0 .. 5 ) { + $photos[ $i ] + = $album->addChild({ + className => "WebGUI::Asset::File::Image::Photo", + filename => "$i.jpg", + }); +} + +#---------------------------------------------------------------------------- +# Cleanup +END { + $versionTag->rollback(); +} + +#---------------------------------------------------------------------------- +# Tests +plan no_plan => 1; + +#---------------------------------------------------------------------------- +# Test view_thumbnails + +#---------------------------------------------------------------------------- +# Test www_thumbnails + diff --git a/t/Asset/Wobject/GalleryAlbum/view.t b/t/Asset/Wobject/GalleryAlbum/view.t new file mode 100644 index 000000000..b12a5f56e --- /dev/null +++ b/t/Asset/Wobject/GalleryAlbum/view.t @@ -0,0 +1,132 @@ +# $vim: syntax=perl +#------------------------------------------------------------------- +# WebGUI is Copyright 2001-2007 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 FindBin; +use strict; +use lib "$FindBin::Bin/../../../lib"; + +## The goal of this test is to test the default view and associated subs + +use Scalar::Util qw( blessed ); +use WebGUI::Test; +use WebGUI::Session; +use Test::More; +use Test::Deep; +use WebGUI::Test::Maker::HTML; + +#---------------------------------------------------------------------------- +# Init +my $maker = WebGUI::Test::Maker::HTML->new; +my $session = WebGUI::Test->session; +my $node = WebGUI::Asset->getImportNode($session); +my $versionTag = WebGUI::VersionTag->getWorking($session); +$versionTag->set({name=>"Album Test"}); +my $gallery + = $node->addChild({ + className => "WebGUI::Asset::Wobject::Gallery", + groupIdAddComment => 2, # Registered Users + groupIdAddFile => 2, # Registered Users + groupIdView => 2, # Registered Users + groupIdEdit => 3, # Admins + ownerUserId => 3, # Admin + }); +my $album + = $gallery->addChild({ + className => "WebGUI::Asset::Wobject::GalleryAlbum", + ownerUserId => "3", # Admin + }); +my @photos; +for my $i ( 0 .. 5 ) { + $photos[ $i ] + = $album->addChild({ + className => "WebGUI::Asset::File::Image::Photo", + filename => "$i.jpg", + }); +} + +#---------------------------------------------------------------------------- +# Cleanup +END { + $versionTag->rollback(); +} + +#---------------------------------------------------------------------------- +# Tests +plan no_plan => 1; + +#---------------------------------------------------------------------------- +# Test getFileIds and getFilePaginator +cmp_bag( $album->getFileIds, [ map { $_->getId } @photos ] ); + +my $p = $album->getFilePaginator; +isa_ok( $p, "WebGUI::Paginator" ); +cmp_deeply( $p->getPageData, subbagof( map { $_->getId } @photos ) ); + +#---------------------------------------------------------------------------- +# Test getTemplateVars + +# Is a superset of Asset->get +# NOTE: url is Asset->getUrl +cmp_deeply( $album->getTemplateVars, superhashof( { %{$album->get}, url => $album->getUrl, } ) ); + +# Contains specific keys/values +my $expected = { + "url_addPhoto" + => all( + re( qr/className=WebGUI::Asset::File::Image::Photo/ ), + re( qr/func=add/ ), + re( $album->getUrl ), + ), + "url_addNoClass" + => all( + re( $album->getUrl ), + re( qr/func=add$/ ), + ), + "url_slideshow" + => all( + re( $album->getUrl ), + re( qr/func=slideshow/ ), + ), + "url_thumbnails" + => all( + re( $album->getUrl ), + re( qr/func=thumbnails/ ), + ), + "url_viewRss" + => all( + re( $album->getUrl ), + re( qr/func=viewRss/ ), + ), + "ownerUsername" + => WebGUI::User->new($session, 3)->username, +}; + +cmp_deeply( $album->getTemplateVars, superhashof( $expected ) ); + +#---------------------------------------------------------------------------- +# Test appendTemplateVarsFileLoop +$expected = { + "file_loop" => bag( map { $_->getTemplateVars } @photos ), +}; +cmp_deeply( + $album->appendTemplateVarsFileLoop({},$self->getFilePaginator->getPageData), + $expected +); + +#---------------------------------------------------------------------------- +# Test www_view() for those without permission to view +$maker->prepare({ + object => $album, + method => "www_view", + test_privilege => "insufficient", +}); +$maker->run; + diff --git a/t/Form.t b/t/Form.t new file mode 100644 index 000000000..01838ddd1 --- /dev/null +++ b/t/Form.t @@ -0,0 +1,104 @@ +# vim:syntax=perl +#------------------------------------------------------------------- +# WebGUI is Copyright 2001-2007 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 FindBin; +use strict; +use lib "$FindBin::Bin/lib"; +use Test::More; +use Test::Deep; +use WebGUI::Test; + +#---------------------------------------------------------------------------- +# Init +my $session = WebGUI::Test->session; + +#---------------------------------------------------------------------------- +# Cleanup +END { + +} + +#---------------------------------------------------------------------------- +# Tests + +plan tests => 5; # Increment this number for each test you create + +#---------------------------------------------------------------------------- +# Test the formHeader method + +ok( + !eval{ WebGUI::Form::formHeader( "" ); 1 }, + "formHeader() dies if first parameter is not WebGUI Session", +); + +ok( + !eval{ WebGUI::Form::formHeader( $session, ['foo'] ); 1 }, + "formHeader() dies if second parameter is not hash reference", +); + +# Test the defaults for formHeader() +my $testDefaults = all( + re( q{]*>} ), + re( q{action=} ), + re( q{enctype="multipart/form-data"} ), + re( q{method="post"} ), +); + +cmp_deeply( + WebGUI::Form::formHeader( $session ), + $testDefaults, + "formHeader called without an options hashref", +); + +# Test options passed into formHeader() +my $testWithOptions = all( + re( q{]*>} ), + re( q{action="action"} ), + re( q{enctype="enctype"} ), + re( q{method="method"} ), +); + +cmp_deeply( + WebGUI::Form::formHeader( $session, { + action => "action", + enctype => "enctype", + method => "method", + } ), + $testWithOptions, + "formHeader called with an options hashref", +); + +# Test "action" option containing query parameters +my $testHiddenElements = all( + re( q{ "action?func=edit;a=1&b=2", + }), + $testHiddenElements, + "formHeader 'action' option containing query parameters", +); + +#---------------------------------------------------------------------------- + +TODO: { + local $TODO = "Some things on the TODO list"; + # Test the formFooter method + # Test that the autohandler works properly +} diff --git a/t/Form/SelectRichEditor.t b/t/Form/SelectRichEditor.t new file mode 100644 index 000000000..60c04e88a --- /dev/null +++ b/t/Form/SelectRichEditor.t @@ -0,0 +1,59 @@ +# $vim: syntax=perl +#------------------------------------------------------------------- +# WebGUI is Copyright 2001-2007 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 FindBin; +use strict; +use lib "$FindBin::Bin/../lib"; + +## The goal of this test is to test the SelectRichEditor form control + +use Scalar::Util qw( blessed ); +use WebGUI::Test; +use WebGUI::Session; +use Test::More; +use Test::Deep; + +use WebGUI::Form::SelectRichEditor; + +#---------------------------------------------------------------------------- +# Init +my $session = WebGUI::Test->session; +my $root = WebGUI::Asset->getRoot( $session ); + +#---------------------------------------------------------------------------- +# Cleanup +END { + +} + +#---------------------------------------------------------------------------- +# Tests +plan tests => 1; + +#---------------------------------------------------------------------------- +# Test that SelectRichEditor control contains all RichEdit assets. +my $richEditAssets + = $root->getLineage( ['descendants'], { + returnObjects => 1, + includeOnlyClasses => ['WebGUI::Asset::RichEdit'], + }); +my $richEditOptions + = { + map { $_->getId => $_->get("title") } @$richEditAssets + }; + +my $control + = WebGUI::Form::SelectRichEditor->new( $session, { name => "richEditId" } ); +cmp_deeply( + $control->get("options"), + $richEditOptions, + "SelectRichEditor control has options for all Rich Editors in this site", +); diff --git a/t/Storage.t b/t/Storage.t index 42e47b354..34fa1917c 100644 --- a/t/Storage.t +++ b/t/Storage.t @@ -227,6 +227,16 @@ ok (-e $storage1->getPath("testfile-hash.file"), 'addFileFromHashRef creates fil my $thawedHash = $storage1->getFileContentsAsHashref('testfile-hash.file'); cmp_deeply($storageHash, $thawedHash, 'getFileContentsAsHashref: thawed hash correctly'); +#################################################### +# +# copyFile +# +#################################################### + +$storage1->copyFile("testfile-hash.file", "testfile-hash-copied.file"); +ok (-e $storage1->getPath("testfile-hash-copied.file"),'copyFile created file with new name'); +ok (-e $storage1->getPath("testfile-hash.file"), "copyFile original file still exists"); + #################################################### # # renameFile diff --git a/t/_test.skeleton b/t/_test.skeleton index 55ab13a23..bf4795eab 100644 --- a/t/_test.skeleton +++ b/t/_test.skeleton @@ -1,24 +1,40 @@ +# vim:syntax=perl #------------------------------------------------------------------- -# WebGUI is Copyright 2001-2006 Plain Black Corporation. +# WebGUI is Copyright 2001-2007 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 -#------------------------------------------------------------------- +#------------------------------------------------------------------ + +# Write a little about what this script tests. +# +# use FindBin; use strict; use lib "$FindBin::Bin/lib"; -use WebGUI::Test; +use Test::More; use WebGUI::Session; +use WebGUI::Test; -# load your modules here +#---------------------------------------------------------------------------- +# Init +my $session = WebGUI::Test->session; -use Test::More tests => 1; # increment this value for each test you create +#---------------------------------------------------------------------------- +# Cleanup +END { -my $session = WebGUI::Test->session; +} +#---------------------------------------------------------------------------- +# Tests + +plan tests => 1; # Increment this number for each test you create + +#---------------------------------------------------------------------------- # put your tests here diff --git a/t/lib/WebGUI/Test/Maker/HTML.pm b/t/lib/WebGUI/Test/Maker/HTML.pm index 123aa8871..404be27d0 100644 --- a/t/lib/WebGUI/Test/Maker/HTML.pm +++ b/t/lib/WebGUI/Test/Maker/HTML.pm @@ -73,6 +73,8 @@ Create a new WebGUI::Test::Maker::HTML object. Get a setting. Set L for a list of settings. +=cut + #---------------------------------------------------------------------------- =head2 plan diff --git a/t/lib/WebGUI/Test/Maker/Permission.pm b/t/lib/WebGUI/Test/Maker/Permission.pm index 926b82d24..f57a23423 100644 --- a/t/lib/WebGUI/Test/Maker/Permission.pm +++ b/t/lib/WebGUI/Test/Maker/Permission.pm @@ -55,9 +55,13 @@ Test::More Create a new WebGUI::Test::Maker::Permission object. +=cut + =head2 get -Get a setting. Set L for a list of settings. +Get a setting. See C for a list of settings. + +=cut #---------------------------------------------------------------------------- @@ -116,11 +120,13 @@ The permissions method to test =item pass -An array reference of userIds that should pass the permissions test. +An array reference of userIds or WebGUI::User objects that should pass the +permissions test. =item fail -An array reference of userIds that should fail the permissions test. +An array reference of userIds or WebGUI::User objects that should fail the +permissions test. =back @@ -146,6 +152,16 @@ sub prepare { croak("Couldn't prepare: Test $test_num, fail is not an array reference") if $test->{fail} && ref $test->{fail} ne "ARRAY"; + # Make sure pass and fail arrayrefs are userIds + for my $array ( $test->{pass, fail} ) { + for ( my $i = 0; $i < @$array; $i++ ) { + # If is a User object, replace with userId + if ( blessed $array->[$i] && $array->[$i]->isa("WebGUI::User") ) { + $array->[$i] = $array->[$i]->userId; + } + } + } + push @{$self->{_tests}}, $test; } diff --git a/t/supporting_collateral/elephant_images.zip b/t/supporting_collateral/elephant_images.zip new file mode 100644 index 000000000..a04bc6e69 Binary files /dev/null and b/t/supporting_collateral/elephant_images.zip differ