added Image::ExifTool to WebGUI. fixed upgrade script properlike

This commit is contained in:
Doug Bell 2007-10-29 22:44:35 +00:00
parent 7e12c6c2f0
commit 673faf9be6
11 changed files with 283 additions and 268 deletions

View file

@ -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,"<templates-".$toVersion."/".$file);
my $first = 1;
my $create = 0;
my $head = 0;
my %properties = (className=>"WebGUI::Asset::Template");
while (my $line = <FILE>) {
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;
}

View file

@ -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 ----

View file

@ -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<fileSize> is an integer of additional bytes to include in
the asset size.
=cut
sub setSize {
my $self = shift;
my $fileSize = shift || 0;
my $storage = $self->getStorageLocation;
if (defined $storage) {
foreach my $file (@{$storage->getFiles}) {
$fileSize += $storage->getFileSize($file);
}
}
return $self->SUPER::setSize($fileSize);
my $self = shift;
my $fileSize = shift || 0;
my $storage = $self->getStorageLocation;
if (defined $storage) {
foreach my $file (@{$storage->getFiles}) {
$fileSize += $storage->getFileSize($file);
}
}
return $self->SUPER::setSize($fileSize);
}
#-------------------------------------------------------------------

View file

@ -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<setFile>
and C<processPropertiesFromFormPost>.
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<options> 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;

View file

@ -311,7 +311,7 @@ sub sendMessage {
userId => $userId,
sentBy => $myId,
status => 'unread',
});
});
}
}

View file

@ -0,0 +1,10 @@
package WebGUI::i18n::English::Asset_Gallery;
our $I18N = {
'assetName' => {
message => 'Gallery',
lastUpdated => 1131394072,
},
};
1;

View file

@ -0,0 +1,10 @@
package WebGUI::i18n::English::Asset_GalleryAlbum;
our $I18N = {
'assetName' => {
message => 'Gallery Album',
lastUpdated => 1131394072,
},
};
1;

View file

@ -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");

View file

@ -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");

View file

@ -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,
});

Binary file not shown.

After

Width:  |  Height:  |  Size: 663 KiB