Added some web services to the Gallery asset to support the use of remote
apps to post photos and create albums.
This commit is contained in:
parent
810c8247cc
commit
e89d1527fa
4 changed files with 334 additions and 12 deletions
|
|
@ -29,6 +29,8 @@
|
||||||
- fixed: testEnvironment.pl can't find WebGUI modules after installing a prerequisite
|
- fixed: testEnvironment.pl can't find WebGUI modules after installing a prerequisite
|
||||||
- fixed: Combo box does not show possible values in Thingy (SDH Consulting
|
- fixed: Combo box does not show possible values in Thingy (SDH Consulting
|
||||||
Group)
|
Group)
|
||||||
|
- Added some web services to the Gallery asset to support the use of remote
|
||||||
|
apps to post photos and create albums.
|
||||||
- fixed: Cross site scripting issue on operation pages
|
- fixed: Cross site scripting issue on operation pages
|
||||||
- fixed: Search asset shows blank page after searching
|
- fixed: Search asset shows blank page after searching
|
||||||
- rfe: Updated Thingy's edit instructions and search description fields to
|
- rfe: Updated Thingy's edit instructions and search description fields to
|
||||||
|
|
|
||||||
|
|
@ -378,24 +378,31 @@ sub purgeRevision {
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 setFile ( filename )
|
=head2 setFile ( [pathtofile] )
|
||||||
|
|
||||||
|
Tells the asset to do all the postprocessing on the file (setting privs, thubnails, or whatever).
|
||||||
|
|
||||||
|
=head3 pathtofile
|
||||||
|
|
||||||
|
If specified will copy a new file into the storage location from this path and delete any existing file.
|
||||||
|
|
||||||
Set the file being handled by this storage location with a file from the
|
|
||||||
system.
|
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub setFile {
|
sub setFile {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $filename = shift;
|
my $filename = shift;
|
||||||
my $storage = $self->getStorageLocation;
|
|
||||||
|
|
||||||
# Clear the old file if any
|
if ($filename) {
|
||||||
$storage->clear;
|
my $storage = $self->getStorageLocation;
|
||||||
|
# Clear the old file if any
|
||||||
$storage->addFileFromFilesystem($filename)
|
$storage->clear;
|
||||||
|| croak "Couldn't setFile: " . join(", ",@{ $storage->getErrors });
|
|
||||||
# NOTE: We should not croak here, the WebGUI::Storage should croak for us.
|
$storage->addFileFromFilesystem($filename)
|
||||||
|
|| croak "Couldn't setFile: " . join(", ",@{ $storage->getErrors });
|
||||||
|
# NOTE: We should not croak here, the WebGUI::Storage should croak for us.
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
$self->updatePropertiesFromStorage;
|
$self->updatePropertiesFromStorage;
|
||||||
$self->applyConstraints;
|
$self->applyConstraints;
|
||||||
|
|
|
||||||
|
|
@ -11,10 +11,12 @@ package WebGUI::Asset::Wobject::Gallery;
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
|
use base 'WebGUI::Asset::Wobject';
|
||||||
|
use JSON;
|
||||||
use Tie::IxHash;
|
use Tie::IxHash;
|
||||||
use WebGUI::International;
|
use WebGUI::International;
|
||||||
use WebGUI::Utility;
|
use WebGUI::Utility;
|
||||||
use base 'WebGUI::Asset::Wobject';
|
use XML::Simple;
|
||||||
|
|
||||||
=head1 NAME
|
=head1 NAME
|
||||||
|
|
||||||
|
|
@ -1043,6 +1045,89 @@ sub www_add {
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 www_addAlbumService ( )
|
||||||
|
|
||||||
|
A web service to create albums. Returns a json string that looks like this:
|
||||||
|
|
||||||
|
{
|
||||||
|
"lastUpdated" : "2008-10-13 17:31:32",
|
||||||
|
"canAddFiles" : 1,
|
||||||
|
"url" : "http://dev.localhost.localdomain/cool-gallery/the-cool-album2",
|
||||||
|
"title" : "The Cool Album",
|
||||||
|
"dateCreated" : "2008-10-13 17:31:32"
|
||||||
|
}
|
||||||
|
|
||||||
|
You can make the request as a post to the gallery url with the following variables:
|
||||||
|
|
||||||
|
=head3 func
|
||||||
|
|
||||||
|
Required. Must have a value of "addAlbumService"
|
||||||
|
|
||||||
|
=head3 as
|
||||||
|
|
||||||
|
Defaults to 'json', but if specified as 'xml' then the return result will be:
|
||||||
|
|
||||||
|
<opt>
|
||||||
|
<canAddFiles>1</canAddFiles>
|
||||||
|
<dateCreated>2008-10-13 17:39:22</dateCreated>
|
||||||
|
<lastUpdated>2008-10-13 17:39:22</lastUpdated>
|
||||||
|
<title>The Cool Album</title>
|
||||||
|
<url>http://dev.localhost.localdomain/cool-gallery/the-cool-album3</url>
|
||||||
|
</opt>
|
||||||
|
|
||||||
|
=head3 title
|
||||||
|
|
||||||
|
The title of the album you wish to create.
|
||||||
|
|
||||||
|
=head3 synopsis
|
||||||
|
|
||||||
|
A brief description of the album you wish to create.
|
||||||
|
|
||||||
|
=head3 othersCanAdd
|
||||||
|
|
||||||
|
A 1 or a 0 depending on whether you want other people to be able to add images to this album.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub www_addAlbumService {
|
||||||
|
my $self = shift;
|
||||||
|
my $session = $self->session;
|
||||||
|
|
||||||
|
return $session->privilege->insufficient unless ($self->canAddFile);
|
||||||
|
my $form = $session->form;
|
||||||
|
|
||||||
|
my $album = $self->addChild({
|
||||||
|
className => "WebGUI::Asset::Wobject::GalleryAlbum",
|
||||||
|
title => $form->get('title','text'),
|
||||||
|
description => $form->get('synopsis','textarea'),
|
||||||
|
synopsis => $form->get('synopsis','textarea'),
|
||||||
|
othersCanAdd => $form->get('othersCanAdd','yesNo'),
|
||||||
|
});
|
||||||
|
|
||||||
|
$album->requestAutoCommit;
|
||||||
|
|
||||||
|
my $siteUrl = $session->url->getSiteURL;
|
||||||
|
my $date = $session->datetime;
|
||||||
|
my $as = $form->get('as') || 'json';
|
||||||
|
|
||||||
|
my $document = {
|
||||||
|
canAddFiles => $album->canAddFile,
|
||||||
|
title => $album->getTitle,
|
||||||
|
url => $siteUrl.$album->getUrl,
|
||||||
|
dateCreated => $date->epochToHuman($album->get('creationDate'), '%y-%m-%d %j:%n:%s'),
|
||||||
|
lastUpdated => $date->epochToHuman($album->get('revisionDate'), '%y-%m-%d %j:%n:%s'),
|
||||||
|
};
|
||||||
|
if ($as eq "xml") {
|
||||||
|
$session->http->setMimeType('text/xml');
|
||||||
|
return XML::Simple::XMLout($document, NoAttr => 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
$session->http->setMimeType('text/json');
|
||||||
|
return JSON->new->pretty->encode($document);
|
||||||
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 www_listAlbums ( )
|
=head2 www_listAlbums ( )
|
||||||
|
|
||||||
Show a paginated list of the albums in this gallery.
|
Show a paginated list of the albums in this gallery.
|
||||||
|
|
@ -1074,7 +1159,7 @@ sub www_listAlbumsRss {
|
||||||
my $var = $self->getTemplateVars;
|
my $var = $self->getTemplateVars;
|
||||||
|
|
||||||
for my $assetId ( @{ $self->getAlbumIds } ) {
|
for my $assetId ( @{ $self->getAlbumIds } ) {
|
||||||
my $asset = WebGUI::Asset->newByDynamicClass( $session, $assetId );
|
my $asset = WebGUI::Asset->new( $session, $assetId, 'WebGUI::Asset::Wobject::GalleryAlbum');
|
||||||
my $assetVar = $asset->getTemplateVars;
|
my $assetVar = $asset->getTemplateVars;
|
||||||
|
|
||||||
# Fix URLs
|
# Fix URLs
|
||||||
|
|
@ -1095,6 +1180,147 @@ sub www_listAlbumsRss {
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 www_listAlbumsService ( )
|
||||||
|
|
||||||
|
A web service to retrieve album information. You may request information from this gallery with a straight GET request:
|
||||||
|
|
||||||
|
http://admin:123qwe@www.example.com/gallery-url?func=listAlbumsService
|
||||||
|
|
||||||
|
The following parameters are optional, but may be passed along the query to change the output of this method.
|
||||||
|
|
||||||
|
=head3 as
|
||||||
|
|
||||||
|
Defaults to 'json', but can be overridden as 'xml'. If specified as 'json' the document returned will look like this:
|
||||||
|
|
||||||
|
{
|
||||||
|
"pageNumber" : 1,
|
||||||
|
"gallery" : {
|
||||||
|
"lastUpdated" : "2008-10-13 14:56:49",
|
||||||
|
"synopsis" : "This is the summary.",
|
||||||
|
"menuTitle" : "My Cool Gallery",
|
||||||
|
"url" : "http://dev.localhost.localdomain/cool-gallery",
|
||||||
|
"title" : "My Cool Gallery",
|
||||||
|
"canAddAlbums" : 1,
|
||||||
|
"dateCreated" : "2008-10-13 14:48:44"
|
||||||
|
},
|
||||||
|
"albums" : [
|
||||||
|
{
|
||||||
|
"thumbnailUrl" : "http://dev.localhost.localdomain",
|
||||||
|
"lastUpdated" : "2008-10-13 14:51:38",
|
||||||
|
"canAddFiles" : 1,
|
||||||
|
"url" : "http://dev.localhost.localdomain/cool-gallery/the-gallery-you-can-post-to",
|
||||||
|
"title" : "The Gallery You Can Post To",
|
||||||
|
"dateCreated" : "2008-10-13 14:50:22"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"thumbnailUrl" : "http://dev.localhost.localdomain",
|
||||||
|
"lastUpdated" : "2008-10-13 14:51:20",
|
||||||
|
"canAddFiles" : 0,
|
||||||
|
"url" : "http://dev.localhost.localdomain/cool-gallery/another-album",
|
||||||
|
"title" : "Another Album",
|
||||||
|
"dateCreated" : "2008-10-13 14:51:20"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
If specified as 'xml' the document returned will look like this:
|
||||||
|
|
||||||
|
<opt>
|
||||||
|
<albums>
|
||||||
|
<canAddFiles>1</canAddFiles>
|
||||||
|
<dateCreated>2008-10-13 14:50:22</dateCreated>
|
||||||
|
<lastUpdated>2008-10-13 14:51:38</lastUpdated>
|
||||||
|
<thumbnailUrl>http://dev.localhost.localdomain</thumbnailUrl>
|
||||||
|
<title>The Gallery You Can Post To</title>
|
||||||
|
<url>http://dev.localhost.localdomain/cool-gallery/the-gallery-you-can-post-to</url>
|
||||||
|
</albums>
|
||||||
|
<albums>
|
||||||
|
<canAddFiles>0</canAddFiles>
|
||||||
|
<dateCreated>2008-10-13 14:51:20</dateCreated>
|
||||||
|
<lastUpdated>2008-10-13 14:51:20</lastUpdated>
|
||||||
|
<thumbnailUrl>http://dev.localhost.localdomain</thumbnailUrl>
|
||||||
|
<title>Another Album</title>
|
||||||
|
<url>http://dev.localhost.localdomain/cool-gallery/another-album</url>
|
||||||
|
</albums>
|
||||||
|
<gallery>
|
||||||
|
<canAddAlbums>1</canAddAlbums>
|
||||||
|
<dateCreated>2008-10-13 14:48:44</dateCreated>
|
||||||
|
<lastUpdated>2008-10-13 14:56:49</lastUpdated>
|
||||||
|
<menuTitle>My Cool Gallery</menuTitle>
|
||||||
|
<synopsis>This is the summary.</synopsis>
|
||||||
|
<title>My Cool Gallery</title>
|
||||||
|
<url>http://dev.localhost.localdomain/cool-gallery</url>
|
||||||
|
</gallery>
|
||||||
|
<pageNumber>1</pageNumber>
|
||||||
|
</opt>
|
||||||
|
|
||||||
|
=head3 pn
|
||||||
|
|
||||||
|
Defaults to 1. This represents the page number. It will return up to 100 albums at a time.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub www_listAlbumsService {
|
||||||
|
my $self = shift;
|
||||||
|
my $session = $self->session;
|
||||||
|
|
||||||
|
return $session->privilege->insufficient unless ($self->canView);
|
||||||
|
|
||||||
|
my $siteUrl = $session->url->getSiteURL;
|
||||||
|
my @assets;
|
||||||
|
my $date = $session->datetime;
|
||||||
|
my $form = $session->form;
|
||||||
|
my $as = $form->get('as') || 'json';
|
||||||
|
my $pageNumber = $form->get('pn') || 1;
|
||||||
|
my $user = $session->user;
|
||||||
|
my $count = 1;
|
||||||
|
|
||||||
|
for my $assetId ( @{ $self->getAlbumIds } ) {
|
||||||
|
if ($count < $pageNumber * 100 - 99) { # skip low page numbers
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
if ($count > $pageNumber * 100) { # skip high page numbers
|
||||||
|
last;
|
||||||
|
}
|
||||||
|
my $asset = WebGUI::Asset->new( $session, $assetId, 'WebGUI::Asset::Wobject::GalleryAlbum' );
|
||||||
|
if (defined $asset) {
|
||||||
|
if ($asset->canView) {
|
||||||
|
push @assets, {
|
||||||
|
title => $asset->getTitle,
|
||||||
|
url => $siteUrl.$asset->getUrl,
|
||||||
|
dateCreated => $date->epochToHuman($asset->get('creationDate'), '%y-%m-%d %j:%n:%s'),
|
||||||
|
lastUpdated => $date->epochToHuman($asset->get('revisionDate'), '%y-%m-%d %j:%n:%s'),
|
||||||
|
thumbnailUrl => $siteUrl.$asset->getThumbnailUrl,
|
||||||
|
canAddFiles => $asset->canAddFile,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
my $document = {
|
||||||
|
pageNumber => $pageNumber,
|
||||||
|
gallery => {
|
||||||
|
canAddAlbums => $self->canAddFile,
|
||||||
|
title => $self->getTitle,
|
||||||
|
menuTitle => $self->get('menuTitle'),
|
||||||
|
synopsis => $self->get('synopsis'),
|
||||||
|
url => $siteUrl.$self->getUrl,
|
||||||
|
dateCreated => $date->epochToHuman($self->get('creationDate'), '%y-%m-%d %j:%n:%s'),
|
||||||
|
lastUpdated => $date->epochToHuman($self->get('revisionDate'), '%y-%m-%d %j:%n:%s'),
|
||||||
|
},
|
||||||
|
albums => \@assets
|
||||||
|
};
|
||||||
|
if ($as eq "xml") {
|
||||||
|
$session->http->setMimeType('text/xml');
|
||||||
|
return XML::Simple::XMLout($document, NoAttr => 1);
|
||||||
|
}
|
||||||
|
$session->http->setMimeType('text/json');
|
||||||
|
return JSON->new->pretty->encode($document);
|
||||||
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 www_search ( )
|
=head2 www_search ( )
|
||||||
|
|
||||||
Search through the GalleryAlbums and files in this gallery. Show the form to
|
Search through the GalleryAlbums and files in this gallery. Show the form to
|
||||||
|
|
|
||||||
|
|
@ -902,6 +902,93 @@ sub www_addArchiveSave {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 www_addFileService ( )
|
||||||
|
|
||||||
|
A web service to create files in albums. Returns a json string that looks like this:
|
||||||
|
|
||||||
|
{
|
||||||
|
"lastUpdated" : "2008-10-13 20:06:13",
|
||||||
|
"thumbnailUrl" : "http://dev.localhost.localdomain/uploads/W1/X9/W1X9A95iagNbq4n1utdXug/thumb-jt_25.jpg",
|
||||||
|
"url" : "http://dev.localhost.localdomain/cool-gallery/the-cool-album3/jt13",
|
||||||
|
"title" : "JT",
|
||||||
|
"dateCreated" : "2008-10-13 20:06:13"
|
||||||
|
}
|
||||||
|
|
||||||
|
You can make the request as a post to the gallery url with the following variables:
|
||||||
|
|
||||||
|
=head3 func
|
||||||
|
|
||||||
|
Required. Must have a value of "addFileService"
|
||||||
|
|
||||||
|
=head3 as
|
||||||
|
|
||||||
|
Defaults to 'json', but if specified as 'xml' then the return result will be:
|
||||||
|
|
||||||
|
<opt>
|
||||||
|
<dateCreated>2008-10-13 20:08:18</dateCreated>
|
||||||
|
<lastUpdated>2008-10-13 20:08:18</lastUpdated>
|
||||||
|
<thumbnailUrl>http://dev.localhost.localdomain/uploads/1k/-B/1k-BTF8m4e6wmXJKRxraIA/thumb-jt_25.jpg</thumbnailUrl>
|
||||||
|
<title>JT</title>
|
||||||
|
<url>http://dev.localhost.localdomain/cool-gallery/the-cool-album3/jt14</url>
|
||||||
|
</opt>
|
||||||
|
|
||||||
|
=head3 title
|
||||||
|
|
||||||
|
The title of the album you wish to create.
|
||||||
|
|
||||||
|
=head3 synopsis
|
||||||
|
|
||||||
|
A brief description of the album you wish to create.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub www_addFileService {
|
||||||
|
my $self = shift;
|
||||||
|
my $session = $self->session;
|
||||||
|
|
||||||
|
return $session->privilege->insufficient unless ($self->canAddFile);
|
||||||
|
my $form = $session->form;
|
||||||
|
|
||||||
|
|
||||||
|
my $file = $self->addChild({
|
||||||
|
className => "WebGUI::Asset::File::GalleryFile::Photo",
|
||||||
|
title => $form->get('title','text'),
|
||||||
|
synopsis => $form->get('description','textarea'),
|
||||||
|
});
|
||||||
|
|
||||||
|
my $storage = $file->getStorageLocation;
|
||||||
|
my $filename = $storage->addFileFromFormPost('file');
|
||||||
|
$file->setFile;
|
||||||
|
# my $storageId = $form->get('file','File');
|
||||||
|
# my $filePath = $storage->getPath( $storage->getFiles->[0] );
|
||||||
|
# $self->setFile( $filePath );
|
||||||
|
# $storage->delete;
|
||||||
|
$session->log->warn('XX:'. $filename);
|
||||||
|
|
||||||
|
$file->requestAutoCommit;
|
||||||
|
|
||||||
|
my $siteUrl = $session->url->getSiteURL;
|
||||||
|
my $date = $session->datetime;
|
||||||
|
my $as = $form->get('as') || 'json';
|
||||||
|
|
||||||
|
my $document = {
|
||||||
|
title => $file->getTitle,
|
||||||
|
url => $siteUrl.$file->getUrl,
|
||||||
|
thumbnailUrl => $siteUrl.$file->getThumbnailUrl,
|
||||||
|
dateCreated => $date->epochToHuman($file->get('creationDate'), '%y-%m-%d %j:%n:%s'),
|
||||||
|
lastUpdated => $date->epochToHuman($file->get('revisionDate'), '%y-%m-%d %j:%n:%s'),
|
||||||
|
};
|
||||||
|
if ($as eq "xml") {
|
||||||
|
$session->http->setMimeType('text/xml');
|
||||||
|
return XML::Simple::XMLout($document, NoAttr => 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
$session->http->setMimeType('text/json');
|
||||||
|
return JSON->new->pretty->encode($document);
|
||||||
|
}
|
||||||
|
|
||||||
#-----------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 www_delete ( )
|
=head2 www_delete ( )
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue