diff --git a/docs/upgrades/installPhotoGallery.pl b/docs/upgrades/installPhotoGallery.pl deleted file mode 100644 index 1e03a9a1c..000000000 --- a/docs/upgrades/installPhotoGallery.pl +++ /dev/null @@ -1,237 +0,0 @@ -#------------------------------------------------------------------- -# WebGUI is Copyright 2001-2006 Plain Black Corporation. -#------------------------------------------------------------------- -# Please read the legal notices (docs/legal.txt) and the license -# (docs/license.txt) that came with this distribution before using -# this software. -#------------------------------------------------------------------- -# http://www.plainblack.com info@plainblack.com -#------------------------------------------------------------------- - -use lib "../../lib"; -use strict; -use Getopt::Long; -use WebGUI::Session; - - -my $toVersion = "photogallery"; # make this match what version you're going to -my $quiet; # this line required - - -my $session = start(); # this line required - -# upgrade functions go here -installGalleryAsset($session); -installGalleryAlbumAsset($session); -installPhotoAsset($session); - -finish($session); # this line required - - -##------------------------------------------------- -#sub exampleFunction { -# my $session = shift; -# print "\tWe're doing some stuff here that you should know about.\n" unless ($quiet); -# # and here's our code -#} - -#---------------------------------------------------------------------------- -# Install the Gallery asset -sub installGalleryAsset { - my $session = shift; - print "\tInstalling Gallery asset..." unless $quiet; - - $session->db->write(<<'ENDSQL'); -CREATE TABLE IF NOT EXISTS Gallery ( - assetId VARCHAR(22) BINARY NOT NULL, - revisionDate BIGINT NOT NULL, - groupIdAddComment VARCHAR(22) BINARY, - groupIdAddFile VARCHAR(22) BINARY, - groupIdModerator VARCHAR(22) BINARY, - imageResolutions TEXT, - imageViewSize INT, - imageViewCompression INT, - imageThumbnailSize INT, - maxSpacePerUser VARCHAR(20), - richEditIdFileComment VARCHAR(22) BINARY, - templateIdAddArchive VARCHAR(22) BINARY, - templateIdDeleteAlbum VARCHAR(22) BINARY, - templateIdDeleteFile VARCHAR(22) BINARY, - templateIdEditFile VARCHAR(22) BINARY, - templateIdListAlbums VARCHAR(22) BINARY, - templateIdListAlbumsRss VARCHAR(22) BINARY, - templateIdListUserFiles VARCHAR(22) BINARY, - templateIdListUserFilesRss VARCHAR(22) BINARY, - templateIdMakeShortcut VARCHAR(22) BINARY, - templateIdSearch VARCHAR(22) BINARY, - templateIdSlideshow VARCHAR(22) BINARY, - templateIdThumbnails VARCHAR(22) BINARY, - templateIdViewAlbum VARCHAR(22) BINARY, - templateIdViewAlbumRss VARCHAR(22) BINARY, - templateIdViewFile VARCHAR(22) BINARY, - workflowIdCommit VARCHAR(22) BINARY, - PRIMARY KEY (assetId, revisionDate) -) -ENDSQL - - - - print "DONE!\n" unless $quiet; -} - -#---------------------------------------------------------------------------- -# Install the GalleryAlbum asset -sub installGalleryAlbumAsset { - my $session = shift; - print "\tInstalling GalleryAlbum asset..." unless $quiet; - - $session->db->write(<<'ENDSQL'); -CREATE TABLE IF NOT EXISTS GalleryAlbum ( - assetId VARCHAR(22) BINARY NOT NULL, - revisionDate BIGINT NOT NULL, - othersCanAdd INT, - allowComments INT, - PRIMARY KEY (assetId, revisionDate) -) -ENDSQL - - print "DONE!\n" unless $quiet; -} - -#---------------------------------------------------------------------------- -# Install the photo asset -sub installPhotoAsset { - my $session = shift; - print "\tInstalling Photo asset..." unless $quiet; - - # Photo Asset - $session->db->write(<<'ENDSQL'); -CREATE TABLE IF NOT EXISTS Photo ( - assetId VARCHAR(22) BINARY NOT NULL, - revisionDate BIGINT NOT NULL, - friendsOnly INT, - rating INT, - storageIdPhoto VARCHAR(22) BINARY, - userDefined1 TEXT, - userDefined2 TEXT, - userDefined3 TEXT, - userDefined4 TEXT, - userDefined5 TEXT, - PRIMARY KEY (assetId, revisionDate) -) -ENDSQL - - $session->db->write(<<'ENDSQL'); -CREATE TABLE IF NOT EXISTS Photo_comment ( - assetId VARCHAR(22) BINARY NOT NULL, - commentId VARCHAR(22) BINARY NOT NULL, - userId VARCHAR(22) BINARY, - visitorIp VARCHAR(255), - creationDate DATETIME, - bodyText LONGTEXT, - INDEX (commentId), - PRIMARY KEY (assetId, commentId) -) -ENDSQL - - $session->db->write(<<'ENDSQL'); -CREATE TABLE IF NOT EXISTS Photo_rating ( - assetId VARCHAR(22) BINARY NOT NULL, - userId VARCHAR(22) BINARY, - visitorIp VARCHAR(255), - rating INT, - INDEX (assetId) -) -ENDSQL - - print "DONE!\n" unless $quiet; -} - -# ---- DO NOT EDIT BELOW THIS LINE ---- - -#------------------------------------------------- -sub start { - my $configFile; - $|=1; #disable output buffering - GetOptions( - 'configFile=s'=>\$configFile, - 'quiet'=>\$quiet - ); - my $session = WebGUI::Session->open("../..",$configFile); - $session->user({userId=>3}); - my $versionTag = WebGUI::VersionTag->getWorking($session); - $versionTag->set({name=>"Upgrade to ".$toVersion}); - updateTemplates($session); - return $session; -} - -#------------------------------------------------- -sub finish { - my $session = shift; - my $versionTag = WebGUI::VersionTag->getWorking($session); - $versionTag->commit; - $session->close(); -} - -#------------------------------------------------- -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); - } - } - } -} - -#------------------------------------------------- -sub createNewTemplatesFolder { - my $importNode = shift; - my $newFolder = $importNode->addChild({ - className=>"WebGUI::Asset::Wobject::Folder", - title => $toVersion." New Templates", - menuTitle => $toVersion." New Templates", - url=> $toVersion."_new_templates", - groupIdView=>"12" - }); - return $newFolder; -} - - - 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 2a9ca925b..daa0c5bad 100644 --- a/docs/upgrades/upgrade_7.4.10-7.5.0.pl +++ b/docs/upgrades/upgrade_7.4.10-7.5.0.pl @@ -22,6 +22,9 @@ my $session = start(); # this line required # upgrade functions go here addFriendsNetwork($session); +installGalleryAsset($session); +installGalleryAlbumAsset($session); +installPhotoAsset($session); finish($session); # this line required @@ -99,6 +102,118 @@ EOSQL print "OK\n" unless $quiet; } +#---------------------------------------------------------------------------- +# Install the GalleryAlbum asset +sub installGalleryAlbumAsset { + my $session = shift; + print "\tInstalling GalleryAlbum asset..." unless $quiet; + + $session->db->write(<<'ENDSQL'); +CREATE TABLE IF NOT EXISTS GalleryAlbum ( + assetId VARCHAR(22) BINARY NOT NULL, + revisionDate BIGINT NOT NULL, + othersCanAdd INT, + allowComments INT, + PRIMARY KEY (assetId, revisionDate) +) +ENDSQL + + print "DONE!\n" unless $quiet; +} + +#---------------------------------------------------------------------------- +# Install the Gallery asset +sub installGalleryAsset { + my $session = shift; + print "\tInstalling Gallery asset..." unless $quiet; + + $session->db->write(<<'ENDSQL'); +CREATE TABLE IF NOT EXISTS Gallery ( + assetId VARCHAR(22) BINARY NOT NULL, + revisionDate BIGINT NOT NULL, + groupIdAddComment VARCHAR(22) BINARY, + groupIdAddFile VARCHAR(22) BINARY, + groupIdModerator VARCHAR(22) BINARY, + imageResolutions TEXT, + imageViewSize INT, + imageThumbnailSize INT, + maxSpacePerUser VARCHAR(20), + richEditIdFileComment VARCHAR(22) BINARY, + templateIdAddArchive VARCHAR(22) BINARY, + templateIdDeleteAlbum VARCHAR(22) BINARY, + templateIdDeleteFile VARCHAR(22) BINARY, + templateIdEditFile VARCHAR(22) BINARY, + templateIdListAlbums VARCHAR(22) BINARY, + templateIdListAlbumsRss VARCHAR(22) BINARY, + templateIdListUserFiles VARCHAR(22) BINARY, + templateIdListUserFilesRss VARCHAR(22) BINARY, + templateIdMakeShortcut VARCHAR(22) BINARY, + templateIdSearch VARCHAR(22) BINARY, + templateIdSlideshow VARCHAR(22) BINARY, + templateIdThumbnails VARCHAR(22) BINARY, + templateIdViewAlbum VARCHAR(22) BINARY, + templateIdViewAlbumRss VARCHAR(22) BINARY, + templateIdViewFile VARCHAR(22) BINARY, + workflowIdCommit VARCHAR(22) BINARY, + PRIMARY KEY (assetId, revisionDate) +) +ENDSQL + + + + print "DONE!\n" unless $quiet; +} + +#---------------------------------------------------------------------------- +# Install the photo asset +sub installPhotoAsset { + my $session = shift; + print "\tInstalling Photo asset..." unless $quiet; + + # Photo Asset + $session->db->write(<<'ENDSQL'); +CREATE TABLE IF NOT EXISTS Photo ( + assetId VARCHAR(22) BINARY NOT NULL, + revisionDate BIGINT NOT NULL, + exifData LONGTEXT, + friendsOnly INT, + rating INT, + storageIdPhoto VARCHAR(22) BINARY, + userDefined1 TEXT, + userDefined2 TEXT, + userDefined3 TEXT, + userDefined4 TEXT, + userDefined5 TEXT, + PRIMARY KEY (assetId, revisionDate) +) +ENDSQL + + $session->db->write(<<'ENDSQL'); +CREATE TABLE IF NOT EXISTS Photo_comment ( + assetId VARCHAR(22) BINARY NOT NULL, + commentId VARCHAR(22) BINARY NOT NULL, + userId VARCHAR(22) BINARY, + visitorIp VARCHAR(255), + creationDate DATETIME, + bodyText LONGTEXT, + INDEX (commentId), + PRIMARY KEY (assetId, commentId) +) +ENDSQL + + $session->db->write(<<'ENDSQL'); +CREATE TABLE IF NOT EXISTS Photo_rating ( + assetId VARCHAR(22) BINARY NOT NULL, + userId VARCHAR(22) BINARY, + visitorIp VARCHAR(255), + rating INT, + INDEX (assetId) +) +ENDSQL + + print "DONE!\n" unless $quiet; +} + # ---- DO NOT EDIT BELOW THIS LINE ---- diff --git a/lib/WebGUI/Asset/File.pm b/lib/WebGUI/Asset/File.pm index b47140b25..f58f7472f 100644 --- a/lib/WebGUI/Asset/File.pm +++ b/lib/WebGUI/Asset/File.pm @@ -397,16 +397,25 @@ sub setFile { } #------------------------------------------------------------------- + +=head2 setSize ( fileSize ) + +Set the size of this asset by including all the files in its storage +location. C is an integer of additional bytes to include in +the asset size. + +=cut + sub setSize { - my $self = shift; - my $fileSize = shift || 0; - my $storage = $self->getStorageLocation; - if (defined $storage) { - foreach my $file (@{$storage->getFiles}) { - $fileSize += $storage->getFileSize($file); - } - } - return $self->SUPER::setSize($fileSize); + my $self = shift; + my $fileSize = shift || 0; + my $storage = $self->getStorageLocation; + if (defined $storage) { + foreach my $file (@{$storage->getFiles}) { + $fileSize += $storage->getFileSize($file); + } + } + return $self->SUPER::setSize($fileSize); } #------------------------------------------------------------------- diff --git a/lib/WebGUI/Asset/File/Image/Photo.pm b/lib/WebGUI/Asset/File/Image/Photo.pm index 714757960..82e6727e4 100644 --- a/lib/WebGUI/Asset/File/Image/Photo.pm +++ b/lib/WebGUI/Asset/File/Image/Photo.pm @@ -15,9 +15,14 @@ package WebGUI::Asset::File::Image::Photo; =cut use strict; -use Tie::IxHash; -use Carp qw( croak ); use base 'WebGUI::Asset::File::Image'; + +use Carp qw( croak ); +use Image::ExifTool qw( :Public ); +use JSON; +use Tie::IxHash; + +use WebGUI::Friends; use WebGUI::Utility; @@ -109,18 +114,30 @@ sub appendTemplateVarsForCommentForm { #---------------------------------------------------------------------------- -=head2 applyConstraints ( ) +=head2 applyConstraints ( options ) Apply the constraints to the original file. Called automatically by C and C. +This is a sort of catch-all method for applying things to the file after it's +uploaded. This method simply calls other methods to do its work. + +C is a hash reference of options and is currently not used. + =cut 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"), + }); } #---------------------------------------------------------------------------- @@ -164,9 +181,8 @@ sub canView { return 0 unless $album->canView($userId); if ($self->isFriendsOnly) { - - # ... - + return 0 + unless WebGUI::Friends->new($self->session, $self->get("ownerUserId"))->isFriend($userId); } # Passed all checks @@ -188,7 +204,7 @@ sub deleteComment { croak "Photo->deleteComment: No commentId specified." unless $commentId; - return $self->session->db->do( + return $self->session->db->write( "DELETE FROM Photo_comment WHERE assetId=? AND commentId=?", [$self->getId, $commentId], ); @@ -296,7 +312,8 @@ sub getResolutions { my $self = shift; my $storage = $self->getStorageLocation; - # ... + # Return a list not including the web view image. + return grep { $_ ne $self->get("filename") } @{ $storage->getFiles }; } #---------------------------------------------------------------------------- @@ -310,8 +327,16 @@ Get a hash reference of template variables shared by all views of this asset. sub getTemplateVars { my $self = shift; my $vars = $self->get; + + ### Format exif vars + my $exif = jsonToObj( delete $var->{exifData} ); + for my $tag ( keys %$exif ) { + # Hash of exif_tag => value + $var->{ "exif_" . $tag } = $exif->{$tag}; - # ... + # Loop of tag => "...", value => "..." + push @{ $var->{exifLoop} }, { tag => $tag, value => $exif->{$tag} }; + } return $vars; } @@ -407,9 +432,6 @@ sub makeShortcut { =head2 processPropertiesFromFormPost ( ) -Used to process properties from the form posted. Do custom things with -noFormPost fields here, or do whatever you want. This method is called -when /yourAssetUrl?func=editSave is requested/posted. =cut @@ -444,6 +466,24 @@ sub setComment { #---------------------------------------------------------------------------- +=head2 updateExifDataFromFile ( ) + +Gets the EXIF data from the uploaded image and store it in the database. + +=cut + +sub updateExifDataFromFile { + my $self = shift; + my $storage = $self->getStorageLocation; + + my $info = ImageInfo( $storage->getFilePath( $self->get('filename') ) ); + $self->update({ + exifData => objToJson( $info ), + }); +} + +#---------------------------------------------------------------------------- + =head2 view ( ) method called by the container www_view method. @@ -535,6 +575,9 @@ This page is only available to those who can edit this Photo. sub www_edit { my $self = shift; + my $session = $self->session; + my $form = $self->session->form; + return $self->session->privilege->insufficient unless $self->canEdit; return $self->session->privilege->locked unless $self->canEditIfLocked; @@ -619,7 +662,8 @@ sub www_makeShortcutSave { return $self->session->privilege->insufficient unless $self->canEdit; -#... + #... + } 1; diff --git a/lib/WebGUI/Friends.pm b/lib/WebGUI/Friends.pm index 514f2963e..c852c0910 100644 --- a/lib/WebGUI/Friends.pm +++ b/lib/WebGUI/Friends.pm @@ -311,7 +311,7 @@ sub sendMessage { userId => $userId, sentBy => $myId, status => 'unread', - }); + }); } } diff --git a/lib/WebGUI/i18n/English/Asset_Gallery.pm b/lib/WebGUI/i18n/English/Asset_Gallery.pm new file mode 100644 index 000000000..41bc3d843 --- /dev/null +++ b/lib/WebGUI/i18n/English/Asset_Gallery.pm @@ -0,0 +1,10 @@ +package WebGUI::i18n::English::Asset_Gallery; + +our $I18N = { + 'assetName' => { + message => 'Gallery', + lastUpdated => 1131394072, + }, +}; + +1; diff --git a/lib/WebGUI/i18n/English/Asset_GalleryAlbum.pm b/lib/WebGUI/i18n/English/Asset_GalleryAlbum.pm new file mode 100644 index 000000000..cff839973 --- /dev/null +++ b/lib/WebGUI/i18n/English/Asset_GalleryAlbum.pm @@ -0,0 +1,10 @@ +package WebGUI::i18n::English::Asset_GalleryAlbum; + +our $I18N = { + 'assetName' => { + message => 'Gallery Album', + lastUpdated => 1131394072, + }, +}; + +1; diff --git a/sbin/testEnvironment.pl b/sbin/testEnvironment.pl index 8f60865af..0f571f660 100644 --- a/sbin/testEnvironment.pl +++ b/sbin/testEnvironment.pl @@ -122,6 +122,7 @@ checkModule("Locale::US"); checkModule("Weather::Com::Finder","0.5.1"); checkModule("Class::InsideOut","1.06"); checkModule("HTML::TagCloud","0.34"); +checkModule("Image::ExifTool","7.00"); ################################### @@ -200,8 +201,8 @@ print "\nTesting complete!\n\n"; #---------------------------------------- sub checkModule { my $module = shift; - my $version = shift || 0; - my $skipInstall = shift; + my $version = shift || 0; + my $skipInstall = shift; my $afterinstall = shift; unless (defined $afterinstall) { $afterinstall = 0; } printTest("Checking for module $module"); diff --git a/t/Asset/File/Image/Photo/exif.t b/t/Asset/File/Image/Photo/exif.t new file mode 100644 index 000000000..81297cb96 --- /dev/null +++ b/t/Asset/File/Image/Photo/exif.t @@ -0,0 +1,56 @@ +#------------------------------------------------------------------- +# 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 EXIF functionality of WebGUI's photo +# asset + +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=>"Photo Test"}); +my $gallery + = $node->addChild({ + className => "WebGUI::Asset::Wobject::Gallery", + }); +my $album + = $gallery->addChild({ + className => "WebGUI::Asset::Wobject::GalleryAlbum", + }); +my ( $photo ); + +#---------------------------------------------------------------------------- +# Cleanup +END { + $versionTag->rollback(); +} + +#---------------------------------------------------------------------------- +# Tests +plan no_plan => 1; + +#---------------------------------------------------------------------------- +# Test that exif data gets parsed from the file +$photo + = $album->addChild({ + className => "WebGUI::Asset::File::Image::Photo", + }); +$photo->setFile( WebGUI::Test->getCollateralPath("lamp.jpg") ); +my $exif = $photo->get("exifData"); diff --git a/t/Asset/File/Image/Photo/permissions.t b/t/Asset/File/Image/Photo/permissions.t index f39c8ba79..75598deee 100644 --- a/t/Asset/File/Image/Photo/permissions.t +++ b/t/Asset/File/Image/Photo/permissions.t @@ -17,6 +17,7 @@ use lib "$FindBin::Bin/../../../../lib"; use Scalar::Util qw( blessed ); use WebGUI::Test; use WebGUI::Session; +use WebGUI::Friends; use Test::More; #---------------------------------------------------------------------------- @@ -27,6 +28,10 @@ my $versionTag = WebGUI::VersionTag->getWorking($session); $versionTag->set({name=>"Photo Test"}); my ($photo); $session->user({ userId => 3 }); + +my $friend = WebGUI::User->new($session, "new"); +WebGUI::Friends->new($session)->add( [ $friend->userId ] ); + my $gallery = $node->addChild({ className => "WebGUI::Asset::Wobject::Gallery", @@ -46,7 +51,9 @@ my $album #---------------------------------------------------------------------------- # Cleanup END { - $versionTag->rollback(); + WebGUI::Friends->new($session)->delete( [ $friend->userId ] ); + $friend->delete; + $versionTag->rollback; } #---------------------------------------------------------------------------- @@ -54,8 +61,6 @@ END { plan no_plan => 1; #---------------------------------------------------------------------------- -# Photo assets outside of Gallery assets - # Everyone can view, Admins can edit, Owned by current user $photo = $album->addChild({ @@ -72,6 +77,7 @@ ok( !$photo->canEdit(2), "Registered users cannot edit" ); ok( $photo->canView, "Current user can view" ); ok( $photo->canEdit, "Current user can edit" ); +#---------------------------------------------------------------------------- # Admins can view, Admins can edit, Owned by Admin, current user is Visitor my $oldUser = $session->user; $session->user( { user => WebGUI::User->new($session, "1") } ); @@ -91,6 +97,7 @@ ok( $photo->canView(3), "Admins can view" ); ok( $photo->canEdit(3), "Admins can edit" ); $session->user( { user => $oldUser } ); +#---------------------------------------------------------------------------- # Photo without specific view/edit inherits from gallery properties $photo = $album->addChild({ @@ -109,11 +116,11 @@ ok( $photo->canEdit, "Owner can edit" ); ok( $photo->canView(3), "Admin can view" ); ok( $photo->canEdit(3), "Admin can edit" ); -# Photo with specific view uses that instead (friends lists) +#---------------------------------------------------------------------------- +# Friends are allowed to view friendsOnly photos $photo = $album->addChild({ className => "WebGUI::Asset::File::Image::Photo", - groupIdView => "3", groupIdEdit => "", ownerUserId => $session->user->userId, }); diff --git a/t/supporting_collateral/lamp.jpg b/t/supporting_collateral/lamp.jpg new file mode 100644 index 000000000..3145fa816 Binary files /dev/null and b/t/supporting_collateral/lamp.jpg differ