reverted FileUrl macro, added new StorageUrl macro
This commit is contained in:
parent
41a688ac23
commit
7349633d63
4 changed files with 97 additions and 47 deletions
|
|
@ -37,6 +37,7 @@ addPosMode($session);
|
|||
fixFriendsGroups( $session );
|
||||
upgradeAccount( $session );
|
||||
removeProcessRecurringPaymentsFromConfig( $session );
|
||||
addStorageUrlMacro( $session );
|
||||
finish($session); # this line required
|
||||
|
||||
|
||||
|
|
@ -59,6 +60,14 @@ sub addPosMode {
|
|||
print qq{Finished\n} if !$quiet;
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
sub addStorageUrlMacro {
|
||||
my $session = shift;
|
||||
print qq{\tAdding StorageUrl Macro... } if !$quiet;
|
||||
$session->config->addToHash( "macros", "StorageUrl" => "StorageUrl" );
|
||||
print qq{Done!\n} if !$quiet;
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
sub removeProcessRecurringPaymentsFromConfig {
|
||||
my $session = shift;
|
||||
|
|
@ -74,6 +83,7 @@ sub removeProcessRecurringPaymentsFromConfig {
|
|||
}
|
||||
$workflowActivities->{'None'} = [ @noObjects ];
|
||||
$config->set('workflowActivities', $workflowActivities);
|
||||
print qq{Done!\n} if !$quiet;
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -751,7 +751,8 @@
|
|||
"User" : "User",
|
||||
"UsersOnline" : "UsersOnline",
|
||||
"u" : "u_companyUrl",
|
||||
"ViewCart" : "ViewCart"
|
||||
"ViewCart" : "ViewCart",
|
||||
"StorageUrl" : "StorageUrl"
|
||||
},
|
||||
|
||||
#Specify any LDAP aliases for synchronizing user profiles to LDAP
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ identified by it's asset URL.
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 process ( url, id, isStorageId, filename )
|
||||
=head2 process ( url )
|
||||
|
||||
returns the file system URL if url is the URL for an Asset in the
|
||||
system that has storageId and filename properties. If no Asset
|
||||
|
|
@ -37,54 +37,13 @@ be returned.
|
|||
|
||||
The URL to the Asset.
|
||||
|
||||
head3 id
|
||||
|
||||
If id is passed in, the macro will attempt to retrive the storageId using the
|
||||
Id of the Asset instead of by the url
|
||||
|
||||
=head3 isStorageId
|
||||
|
||||
If id is passed in and the isStorageId flag is set, the macro will forgo
|
||||
the asset and simply return the url of the first file it finds
|
||||
|
||||
=head3 filename
|
||||
|
||||
If id is passed in and the isStorageId flag is set, you may pass in filename
|
||||
to specify the name of the file you'd like returned.
|
||||
|
||||
head3 isImage
|
||||
|
||||
If id is passed in and the isImage flag is set, the first image will be returned
|
||||
|
||||
=cut
|
||||
|
||||
sub process {
|
||||
my $session = shift;
|
||||
my $url = shift;
|
||||
my $id = shift;
|
||||
my $isStorageId = shift;
|
||||
my $filename = shift;
|
||||
my $isImage = shift;
|
||||
my $i18n = WebGUI::International->new($session, 'Macro_FileUrl');
|
||||
|
||||
#Handle storageId case
|
||||
if($isStorageId && $id) {
|
||||
my $store = undef;
|
||||
if($isImage) {
|
||||
$store = WebGUI::Storage::Image->get($session,$id);
|
||||
}
|
||||
else {
|
||||
$store = WebGUI::Storage->get($session,$id);
|
||||
}
|
||||
$filename = $store->getFiles->[0] unless ($filename);
|
||||
return "" unless ($filename);
|
||||
return $store->getUrl($filename);
|
||||
}
|
||||
|
||||
my $asset = ($id)
|
||||
? WebGUI::Asset->newByDynamicClass($session,$id)
|
||||
: WebGUI::Asset->newByUrl($session,$url);
|
||||
|
||||
my $session = shift;
|
||||
my $url = shift;
|
||||
my $asset = WebGUI::Asset->newByUrl($session,$url);
|
||||
my $i18n = WebGUI::International->new($session, 'Macro_FileUrl');
|
||||
if (not defined $asset) {
|
||||
return $i18n->get('invalid url');
|
||||
}
|
||||
|
|
|
|||
80
lib/WebGUI/Macro/StorageUrl.pm
Normal file
80
lib/WebGUI/Macro/StorageUrl.pm
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
package WebGUI::Macro::StorageUrl; # edit this line to match your own macro name
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
# 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
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
use strict;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Package WebGUI::Macro::StorageUrl
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This macro gets the URL to a storage location, optionally adding a filename.
|
||||
|
||||
=head2 process( session, storageId [, returnType, filename ] )
|
||||
|
||||
=over 4
|
||||
|
||||
=item *
|
||||
|
||||
A session variable
|
||||
|
||||
=item *
|
||||
|
||||
The ID to a storage location
|
||||
|
||||
=item *
|
||||
|
||||
Optional: One of the following strings:
|
||||
|
||||
file - Default: Get the url to the file
|
||||
thumb - Get the url to the thumbnail of an image
|
||||
Only works with images
|
||||
|
||||
=item *
|
||||
|
||||
Optional: A filename to get the URL for. If not supplied, will
|
||||
get the first file asciibetically in the storage location.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub process {
|
||||
my $session = shift;
|
||||
my $storageId = shift;
|
||||
my $wantThumbnail = ( shift eq "thumb" ) ? 1 : 0;
|
||||
my $filename = shift;
|
||||
my $output = "";
|
||||
|
||||
# Use WebGUI::Storage::Image because we might be getting an image
|
||||
my $storage = WebGUI::Storage::Image->new( $session, $storageId );
|
||||
return "" if !$storage;
|
||||
|
||||
if ( !$filename ) {
|
||||
$filename = $storage->getFiles->[0];
|
||||
}
|
||||
return "" if !$filename;
|
||||
|
||||
if ( $wantThumbnail && $storage->isImage( $filename ) ) {
|
||||
return $storage->getThumbnailUrl( $filename );
|
||||
}
|
||||
else {
|
||||
return $storage->getUrl( $filename );
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
#vim:ft=perl
|
||||
Loading…
Add table
Add a link
Reference in a new issue