From 7349633d6395500b17b0c9bfa1ee47e74ea3e64f Mon Sep 17 00:00:00 2001 From: Doug Bell Date: Wed, 19 Nov 2008 00:17:34 +0000 Subject: [PATCH] reverted FileUrl macro, added new StorageUrl macro --- docs/upgrades/upgrade_7.6.3-7.6.4.pl | 10 ++++ etc/WebGUI.conf.original | 3 +- lib/WebGUI/Macro/FileUrl.pm | 51 ++---------------- lib/WebGUI/Macro/StorageUrl.pm | 80 ++++++++++++++++++++++++++++ 4 files changed, 97 insertions(+), 47 deletions(-) create mode 100644 lib/WebGUI/Macro/StorageUrl.pm diff --git a/docs/upgrades/upgrade_7.6.3-7.6.4.pl b/docs/upgrades/upgrade_7.6.3-7.6.4.pl index b1d85dcfe..ea73e82d2 100644 --- a/docs/upgrades/upgrade_7.6.3-7.6.4.pl +++ b/docs/upgrades/upgrade_7.6.3-7.6.4.pl @@ -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; } #---------------------------------------------------------------------------- diff --git a/etc/WebGUI.conf.original b/etc/WebGUI.conf.original index 315c7b6dd..5723390fe 100644 --- a/etc/WebGUI.conf.original +++ b/etc/WebGUI.conf.original @@ -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 diff --git a/lib/WebGUI/Macro/FileUrl.pm b/lib/WebGUI/Macro/FileUrl.pm index 5c412db7c..d3db012e0 100644 --- a/lib/WebGUI/Macro/FileUrl.pm +++ b/lib/WebGUI/Macro/FileUrl.pm @@ -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'); } diff --git a/lib/WebGUI/Macro/StorageUrl.pm b/lib/WebGUI/Macro/StorageUrl.pm new file mode 100644 index 000000000..058e9faaa --- /dev/null +++ b/lib/WebGUI/Macro/StorageUrl.pm @@ -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