- Added tests for GalleryAlbum RSS - More tests for comments - Test International Macro sprintf as third+ arguments - Add Gallery search limiting by user ID - Remaining i18n for Gallery templates - Fix: Search form now visible in Photo assets Moved a lot of stuff from Photo to GalleryFile
212 lines
7.4 KiB
Perl
212 lines
7.4 KiB
Perl
package WebGUI::Utility::Gallery;
|
|
|
|
=head1 LEGAL
|
|
|
|
-------------------------------------------------------------------
|
|
WebGUI is Copyright 2001-2008 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 Carp qw( carp croak );
|
|
use File::Find;
|
|
use Scalar::Util qw( blessed );
|
|
use WebGUI::Asset::Wobject::Collaboration;
|
|
use WebGUI::Asset::Wobject::Gallery;
|
|
use WebGUI::Asset::Post::Thread;
|
|
use WebGUI::Storage::Image;
|
|
|
|
|
|
=head1 NAME
|
|
|
|
WebGUI::Utility::Gallery -- Utility functions for working
|
|
with Gallery assets.
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
This module provides utility functions to work with Gallery assets from
|
|
utility scripts.
|
|
|
|
This module is B<NOT> to be used by the Gallery asset itself!
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
use WebGUI::Utility::Gallery;
|
|
my $utility = "WebGUI::Utility::Gallery" # <- not as cumbersome
|
|
|
|
# Add albums from a collaboration system's threads
|
|
my $gallery = WebGUI::Asset::Wobject::Gallery->new( ... );
|
|
my $collab = WebGUI::Asset::Wobject::Collaboration->new( ... );
|
|
$utility->addAlbumFromCollaboration( $gallery, $collab );
|
|
|
|
# Add a single album from a collaboration system thread
|
|
my $thread = WebGUI::Asset::Post::Thread->new( ... );
|
|
$utility->addAlbumFromThread( $gallery, $thread );
|
|
|
|
# Add a single album from a filesystem branch
|
|
$utility->addAlbumFromFilesystem( $gallery, "/Users/Doug/Photos" );
|
|
|
|
# Add a single album for every folder in a filesystem branch
|
|
$utility->addAlbumFromFilesystem(
|
|
$gallery, "/Users/Doug/Photos",
|
|
{
|
|
multiple => 1,
|
|
}
|
|
);
|
|
|
|
=head1 METHODS
|
|
|
|
These methods are available from this class:
|
|
|
|
=cut
|
|
|
|
#----------------------------------------------------------------------------
|
|
|
|
=head2 addAlbumFromCollaboration ( gallery, collab )
|
|
|
|
Add an album or albums to the gallery from the given Collaboration System.
|
|
C<gallery> is an instanciated Gallery asset. C<collab> is an instanciated
|
|
Collaboration System asset.
|
|
|
|
Will add one album for every thread in the Collaboration System. Will call
|
|
C<addAlbumFromThread> to do its dirty work.
|
|
|
|
=cut
|
|
|
|
sub addAlbumFromCollaboration {
|
|
my $class = shift;
|
|
my $gallery = shift;
|
|
my $collab = shift;
|
|
|
|
croak "First argument must be Gallery asset"
|
|
unless blessed $gallery && $gallery->isa('WebGUI::Asset::Wobject::Gallery');
|
|
croak "Second argument must be Collaboration System asset"
|
|
unless blessed $collab && $collab->isa('WebGUI::Asset::Wobject::Collaboration');
|
|
|
|
my $threads
|
|
= $collab->getLineage(['descendants'], {
|
|
returnObjects => 1,
|
|
includeOnlyClasses => ['WebGUI::Asset::Post::Thread'],
|
|
statesToInclude => ['published'],
|
|
statusToInclude => ['approved', 'archived', 'pending'],
|
|
});
|
|
|
|
for my $thread ( @$threads ) {
|
|
$class->addAlbumFromThread( $gallery, $thread );
|
|
}
|
|
|
|
return undef;
|
|
}
|
|
|
|
#----------------------------------------------------------------------------
|
|
|
|
=head2 addAlbumFromFilesystem ( gallery, root [, options] )
|
|
|
|
Add an album to the gallery from the file system. C<gallery> is an
|
|
instanciated Gallery asset. C<root> is a location on the file system.
|
|
|
|
C<options> is a hash reference of options with the following keys:
|
|
|
|
multiple - Create multiple albums, one for each folder.
|
|
|
|
=cut
|
|
|
|
sub addAlbumFromFilesystem {
|
|
my $class = shift;
|
|
my $gallery = shift;
|
|
my $root = shift;
|
|
my $options = shift;
|
|
|
|
# TODO!!!
|
|
|
|
return undef;
|
|
}
|
|
|
|
#----------------------------------------------------------------------------
|
|
|
|
=head2 addAlbumFromThread ( gallery, thread )
|
|
|
|
Add an album to the gallery from the given Collaboration System thread.
|
|
C<gallery> is an instanciated Gallery asset. C<thread> is an instanciated
|
|
Thread asset.
|
|
|
|
=cut
|
|
|
|
sub addAlbumFromThread {
|
|
my $class = shift;
|
|
my $gallery = shift;
|
|
my $thread = shift;
|
|
|
|
croak "First argument must be Gallery asset"
|
|
unless blessed $gallery && $gallery->isa('WebGUI::Asset::Wobject::Gallery');
|
|
croak "Second argument must be Thread asset"
|
|
unless blessed $thread && $thread->isa('WebGUI::Asset::Post::Thread');
|
|
|
|
my $session = $gallery->session;
|
|
my $addOptions = { skipAutoCommitWorkflows => 1 };
|
|
|
|
# Create the new album
|
|
my $album = $gallery->addChild({
|
|
className => 'WebGUI::Asset::Wobject::GalleryAlbum',
|
|
description => $thread->get('content'),
|
|
menuTitle => $thread->get('menuTitle'),
|
|
createdBy => $thread->get('createdBy'),
|
|
creationDate => $thread->get('creationDate'),
|
|
ownerUserId => $thread->get('ownerUserId'),
|
|
synopsis => $thread->get('synopsis'),
|
|
title => $thread->get('title'),
|
|
url => $session->url->urlize( $gallery->get('url') . "/" . $thread->get('title') ),
|
|
userDefined1 => $thread->get('userDefined1'),
|
|
userDefined2 => $thread->get('userDefined2'),
|
|
userDefined3 => $thread->get('userDefined3'),
|
|
userDefined4 => $thread->get('userDefined4'),
|
|
userDefined5 => $thread->get('userDefined5'),
|
|
}, undef, $thread->get('revisionDate'), $addOptions );
|
|
|
|
for my $post ( @{ $thread->getPosts } ) {
|
|
if ( my $storageId = $post->get('storageId') ) {
|
|
# Use WebGUI::Storage::Image to avoid thumbnails if there
|
|
my $storage = WebGUI::Storage::Image->get( $session, $storageId );
|
|
|
|
for my $filename ( @{$storage->getFiles} ) {
|
|
my $className = $gallery->getAssetClassForFile( $filename );
|
|
if ( !$className ) {
|
|
warn "Skipping $filename because Gallery doesn't handle this file type";
|
|
next;
|
|
}
|
|
|
|
# Get rid of that file extention
|
|
my ($title) = $filename =~ m{(.*)\.[^.]*$};
|
|
|
|
my $file = $album->addChild({
|
|
className => $className,
|
|
createdBy => $post->get('createdBy'),
|
|
creationDate => $post->get('creationDate'),
|
|
menuTitle => $title,
|
|
ownerUserId => $post->get('ownerUserId'),
|
|
synopsis => $post->get('content'),
|
|
title => $title,
|
|
url => $session->url->urlize( $album->get('url') . "/" . $title ),
|
|
userDefined1 => $post->get('userDefined1'),
|
|
userDefined2 => $post->get('userDefined2'),
|
|
userDefined3 => $post->get('userDefined3'),
|
|
userDefined4 => $post->get('userDefined4'),
|
|
userDefined5 => $post->get('userDefined5'),
|
|
}, undef, $post->get('revisionDate'), $addOptions );
|
|
|
|
$file->setFile( $storage->getPath( $filename ) );
|
|
}
|
|
}
|
|
}
|
|
|
|
return undef;
|
|
}
|
|
|
|
1;
|