diff --git a/docs/upgrades/upgrade_6.8.8-6.99.0.pl b/docs/upgrades/upgrade_6.8.8-6.99.0.pl index 7625b364e..6c1102417 100644 --- a/docs/upgrades/upgrade_6.8.8-6.99.0.pl +++ b/docs/upgrades/upgrade_6.8.8-6.99.0.pl @@ -46,9 +46,16 @@ addAdManager(); updateMatrix(); updateFolder(); addRichEditUpload(); +updateArticle(); finish($session); # this line required +#------------------------------------------------- +sub updateArticle { + print "\tAllowing articles to have direct attachments.\n"; + $session->db->write("alter table Article add column storageId varchar(22) binary"); +} + #------------------------------------------------- sub addRichEditUpload { print "\tAdding the ability to upload from the rich editor.\n"; diff --git a/lib/WebGUI/Asset/Post.pm b/lib/WebGUI/Asset/Post.pm index 5d2eeb8b7..8e0c23bd0 100644 --- a/lib/WebGUI/Asset/Post.pm +++ b/lib/WebGUI/Asset/Post.pm @@ -147,8 +147,7 @@ sub definition { className=>'WebGUI::Asset::Post', properties=>{ storageId => { - noFormPost=>1, - fieldType=>"hidden", + fieldType=>"file", defaultValue=>undef }, threadId => { @@ -504,30 +503,6 @@ sub getThumbnailUrl { } -#------------------------------------------------------------------- -sub getUploadControl { - my $self = shift; - my $maxAttachments = $self->getThread->getParent->getValue("attachmentsPerPost"); - my $uploadControl; - return undef unless ($maxAttachments); - my $i18n = WebGUI::International->new($self->session); - if ($self->get("storageId")) { - my $i; - foreach my $filename (@{$self->getStorageLocation->getFiles}) { - $uploadControl .= $self->session->icon->delete("func=deleteFile;filename=".$filename,$self->get("url"),$i18n->get("delete file warning","Asset_Collaboration")) - .' '.$filename.'' - .'
'; - $i++; - } - return $uploadControl unless ($i < $maxAttachments); - } - $uploadControl .= WebGUI::Form::file($self->session, - maxAttachments=>$maxAttachments - ); - return $uploadControl; -} - - #------------------------------------------------------------------- =head2 hasRated ( ) @@ -1065,7 +1040,11 @@ sub www_edit { $var{'form.preview'} = WebGUI::Form::submit($self->session, { value=>$i18n->get("preview","Asset_Collaboration") }); - $var{'attachment.form'} = $self->getUploadControl; + $var{'attachment.form'} = WebGUI::Form::file($self->session, { + value=>$self->get("storageId"), + maxAttachments=>$self->getThread->getParent->getValue("attachmentsPerPost"), + deleteFileUrl=>$self->getUrl("func=deleteFile;filename=") + }); $var{'contentType.form'} = WebGUI::Form::contentType($self->session, { name=>'contentType', value=>$self->getValue("contentType") || "mixed" diff --git a/lib/WebGUI/Asset/Wobject/Article.pm b/lib/WebGUI/Asset/Wobject/Article.pm index 44e5b3ee4..33a0880e2 100644 --- a/lib/WebGUI/Asset/Wobject/Article.pm +++ b/lib/WebGUI/Asset/Wobject/Article.pm @@ -16,6 +16,7 @@ use WebGUI::International; use WebGUI::Cache; use WebGUI::Paginator; use WebGUI::Asset::Wobject; +use WebGUI::Storage::Image; our @ISA = qw(WebGUI::Asset::Wobject); @@ -114,6 +115,15 @@ sub definition { subtext=>'   '.$i18n->get(11).'', hoverHelp=>$i18n->get('carriage return description'), uiLevel=>5 + }, + storageId=>{ + tab=>"properties", + fieldType=>"image", + deleteFileUrl=>$session->url->page("func=deleteFile;filename="), + maxAttachments=>25, + defaultValue=>undef, + label=>$i18n->get("attachments"), + hoverHelp=>$i18n->get("attachments help") } ); push(@{$definition}, { @@ -127,6 +137,32 @@ sub definition { return $class->SUPER::definition($session, $definition); } +#------------------------------------------------------------------- + +sub duplicate { + my $self = shift; + my $newAsset = $self->SUPER::duplicate(shift); + my $newStorage = $self->getStorageLocation->copy; + $newAsset->update({storageId=>$newStorage->getId}); + return $newAsset; +} + +#------------------------------------------------------------------- + +=head2 exportAssetData() ( ) + +See WebGUI::AssetPackage::exportAssetData() for details. + +=cut + +sub exportAssetData { + my $self = shift; + my $data = $self->SUPER::exportAssetData; + push(@{$data->{storage}}, $self->get("storageId")) if ($self->get("storageId") ne ""); + return $data; +} + + #------------------------------------------------------------------- =head2 prepareView ( ) @@ -178,15 +214,24 @@ sub view { return $out if $out; } my %var; - my $children = $self->getLineage(["children"],{returnObjects=>1,includeOnlyClasses=>["WebGUI::Asset::File","WebGUI::Asset::File::Image"]}); - foreach my $child (@{$children}) { - if (ref $child eq "WebGUI::Asset::File") { - $var{"attachment.icon"} = $child->getFileIconUrl; - $var{"attachment.url"} = $child->getFileUrl; - $var{"attachment.name"} = $child->get("filename"); - } elsif (ref $child eq "WebGUI::Asset::File::Image") { - $var{"image.url"} = $child->getFileUrl; - $var{"image.thumbnail"} = $child->getThumbnailUrl; + if ($self->get("storageId")) { + my $storage = WebGUI::Storage::Image->get($self->session, $self->get("storageId")); + foreach my $file (@{$storage->getFiles}) { + if ($storage->isImage($file)) { + $var{'image.url'} = $storage->getUrl($file); + $var{'image.thumbnail'} = $storage->getThumbnailUrl($file); + } else { + $var{'attachment.icon'} = $storage->getFileIconUrl($file); + $var{'attachment.url'} = $storage->getUrl($file); + $var{'attachment.name'} = $file; + } + push(@{$var{attachment_loop}}, { + filename => $file, + isImage => $storage->isImage($file), + url=> $storage->getUrl($file), + thumbnailUrl => $storage->getUrl($file), + iconUrl => $storage->getFileIconUrl($file) + }); } } $var{description} = $self->get("description"); @@ -235,5 +280,25 @@ sub view { return $out; } +#------------------------------------------------------------------- + +=head2 www_deleteFile ( ) + +Deletes and attached file. + +=cut + +sub www_deleteFile { + my $self = shift; + return $self->session->privilege->insufficient unless $self->canEdit; + if ($self->get("storageId") ne "") { + my $storage = WebGUI::Storage::Image->get($self->session, $self->get("storageId")); + $storage->deleteFile($self->session->form->param("filename")); + } + return $self->www_edit; +} + + + 1; diff --git a/lib/WebGUI/Form/File.pm b/lib/WebGUI/Form/File.pm index e9bedd99a..eb273f0c2 100644 --- a/lib/WebGUI/Form/File.pm +++ b/lib/WebGUI/Form/File.pm @@ -60,6 +60,10 @@ only supports displaying/deleting 1 attachment. Flag that tells the User Profile system that this is a valid form element in a User Profile +=head4 deleteFileUrl + +A url that will get a filename appended to it and then links to delete the files will be generated automatically. + =cut sub definition { @@ -80,6 +84,9 @@ sub definition { profileEnabled=>{ defaultValue=>1 }, + deleteFileUrl=>{ + defaultValue=>undef + } }); return $class->SUPER::definition($session, $definition); } @@ -125,7 +132,7 @@ sub displayValue { return '' unless $self->get("value"); my $location = WebGUI::Storage->get($self->session,$self->get("value")); my $file = shift @{ $location->getFiles }; - my $fileValue = sprintf qq! %s!, $location->getFileIconUrl($file), $file; + my $fileValue = sprintf qq| %s|, $location->getFileIconUrl($file), $file; return $fileValue; } @@ -146,14 +153,11 @@ sub getValueFromPost { my $storage = WebGUI::Storage->get($self->session,$value); $storage->delete; return ''; - } - elsif ($self->session->form->param($self->privateName('action')) eq 'keep') { + } elsif ($self->session->form->param($self->privateName('action')) eq 'keep') { return $value; - } - elsif ($self->session->form->param($self->privateName('action')) eq 'upload') { - my $storage; - $storage = WebGUI::Storage::Image->create($self->session); - $storage->addFileFromFormPost($self->get("name"), 1); + } elsif ($self->session->form->param($self->privateName('action')) eq 'upload') { + my $storage = WebGUI::Storage::Image->create($self->session); + $storage->addFileFromFormPost($self->get("name"),1000); my @files = @{ $storage->getFiles }; if (scalar(@files) < 1) { $storage->delete; @@ -175,25 +179,42 @@ Renders a file upload control. sub toHtml { my $self = shift; - $self->session->style->setScript($self->session->config->get("extrasURL").'/FileUploadControl.js',{type=>"text/javascript"}); - my $uploadControl = '!, $self->get("name"), $i18n->get("removeLabel"), $self->get('maxAttachments'); - $uploadControl .= WebGUI::Form::Hidden->new($self->session, {-name => $self->privateName('action'), -value => 'upload'})->toHtml(); + my $uploadControl = undef; + my $storage = WebGUI::Storage->get($self->session, $self->get("value")) if ($self->get("value")); + my @files = $storage->getFiles if (defined $storage); + my $maxFiles = $self->get('maxAttachments') - scalar(@files); + if ($maxFiles > 0) { + $self->session->style->setScript($self->session->config->get("extrasURL").'/FileUploadControl.js',{type=>"text/javascript"}); + $uploadControl = '!, $self->get("name"), $i18n->get("removeLabel"), $maxFiles; + $uploadControl .= WebGUI::Form::Hidden->new($self->session, {-name => $self->privateName('action'), -value => 'upload'})->toHtml()."
"; + } + if (scalar(@files)) { + foreach my $file (@{$storage->getFiles}) { + if ($self->get("deleteFileUrl")) { + $uploadControl .= '

' + .'x

'; + } + $uploadControl .= '

' + .''
+				.$file.' '.$file.'


'; + } + } return $uploadControl; } diff --git a/lib/WebGUI/Form/Image.pm b/lib/WebGUI/Form/Image.pm index e5234c584..df6d292d2 100644 --- a/lib/WebGUI/Form/Image.pm +++ b/lib/WebGUI/Form/Image.pm @@ -17,7 +17,7 @@ package WebGUI::Form::Image; use strict; use base 'WebGUI::Form::File'; use WebGUI::International; -use WebGUI::Storage; +use WebGUI::Storage::Image; use WebGUI::Form::YesNo; =head1 NAME @@ -92,7 +92,7 @@ sub displayForm { return $self->toHtml unless $self->get('value'); ##There are files inside here, for each one, display the image ##and another form control for deleting it. - my $location = WebGUI::Storage->get($self->session, $self->get('value')); + my $location = WebGUI::Storage::Image->get($self->session, $self->get('value')); my $i18n = WebGUI::International->new($self->session); my $fileForm = ''; my $file = shift @{ $location->getFiles }; @@ -118,10 +118,83 @@ profile field. sub displayValue { my ($self) = @_; return '' unless $self->get("value"); - my $location = WebGUI::Storage->get($self->session,$self->get("value")); + my $location = WebGUI::Storage::Image->get($self->session,$self->get("value")); my $file = shift @{ $location->getFiles }; - my $fileValue = sprintf qq! %s!, $location->getUrl($file), $file; + my $fileValue = sprintf qq| %s|, $location->getUrl($file), $file; return $fileValue; +} + +#------------------------------------------------------------------- + +=head2 getValueFromFormPost ( ) + +See WebGUI::Form::File::getValueFromFormPost() for details. Generates a thumbnail. + +=cut + +sub getValueFromFormPost { + my $self = shift; + my $id = $self->SUPER::getValueFromFormPost(@_); + if (defined $id) { + my $storage = WebGUI::Storage::Image->get($self->session, $id); + if (defined $storage) { + foreach my $file (@{$storage->getFiles}) { + $storage->generateThumbnail($file) if ($storage->isImage($file)); + } + } } + return $id; +} + + +#------------------------------------------------------------------- + +=head2 toHtml ( ) + +Renders a file upload control. + +=cut + +sub toHtml { + my $self = shift; + my $i18n = WebGUI::International->new($self->session); + my $uploadControl = undef; + my $storage = WebGUI::Storage::Image->get($self->session, $self->get("value")) if ($self->get("value")); + my @files = $storage->getFiles if (defined $storage); + my $maxFiles = $self->get('maxAttachments') - scalar(@files); + if ($maxFiles > 0) { + $self->session->style->setScript($self->session->config->get("extrasURL").'/FileUploadControl.js',{type=>"text/javascript"}); + $uploadControl = '!, $self->get("name"), $i18n->get("removeLabel"), $maxFiles; + $uploadControl .= WebGUI::Form::Hidden->new($self->session, {-name => $self->privateName('action'), -value => 'upload'})->toHtml()."
"; + } + if (scalar(@files)) { + foreach my $file (@{$storage->getFiles}) { + if ($self->get("deleteFileUrl")) { + $uploadControl .= '

' + .'x

'; + } + my $image = $storage->isImage($file) ? $storage->getThumbnailUrl($file) : $storage->getFileIconUrl($file); + $uploadControl .= '

' + .''
+				.$file.' '.$file.'


'; + } + } + return $uploadControl; +} 1; diff --git a/lib/WebGUI/Operation/Profile.pm b/lib/WebGUI/Operation/Profile.pm index 6370ab8c1..eebad9a45 100644 --- a/lib/WebGUI/Operation/Profile.pm +++ b/lib/WebGUI/Operation/Profile.pm @@ -225,7 +225,7 @@ sub www_editProfileSave { return WebGUI::Operation::Auth::www_auth($session, "init") if ($session->user->userId eq '1'); ($profile, $error, $warning) = validateProfileData($session); $error .= $warning; - return www_editProfile('') if($error ne ""); + return www_editProfile($session, '') if($error ne ""); foreach $fieldName (keys %{$profile}) { $session->user->profileField($fieldName,$profile->{$fieldName}); } diff --git a/lib/WebGUI/Session/Url.pm b/lib/WebGUI/Session/Url.pm index 9760dd826..8519be403 100644 --- a/lib/WebGUI/Session/Url.pm +++ b/lib/WebGUI/Session/Url.pm @@ -147,7 +147,7 @@ sub gateway { my $url = $self->session->config->get("gateway").'/'.$pageUrl; $url =~ s/\/+/\//g; if ($self->session->setting->get("preventProxyCache") == 1) { - $url = $self->append($url,"noCache=".randint(0,1000).';'.$self->session->datetime->time()); + $url = $self->append($url,"noCache=".randint(0,1000).','.$self->session->datetime->time()); } if ($pairs) { $url = $self->append($url,$pairs); @@ -319,7 +319,7 @@ sub page { } $url .= $self->gateway($self->session->asset ? $self->session->asset->get("url") : $self->getRequestedUrl); if ($self->session->setting->get("preventProxyCache") == 1 && !$skipPreventProxyCache) { - $url = $self->append($url,"noCache=".randint(0,1000).';'.$self->session->datetime->time()); + $url = $self->append($url,"noCache=".randint(0,1000).','.$self->session->datetime->time()); } if ($pairs) { $url = $self->append($url,$pairs); diff --git a/lib/WebGUI/Storage/Image.pm b/lib/WebGUI/Storage/Image.pm index 3102605f2..ae8cb5f37 100644 --- a/lib/WebGUI/Storage/Image.pm +++ b/lib/WebGUI/Storage/Image.pm @@ -40,8 +40,8 @@ use WebGUI::Storage::Image; These methods are available from this class: my $boolean = $self->generateThumbnail($filename); -my $url = $self->getThumbnailUrl; -my $boolean = $self->isImage; +my $url = $self->getThumbnailUrl($filename); +my $boolean = $self->isImage($filename); my ($captchaFile, $challenge) = $self->addFileFromCaptcha; $self->resize($imageFile, $width, $height); diff --git a/lib/WebGUI/i18n/English/Asset_Article.pm b/lib/WebGUI/i18n/English/Asset_Article.pm index 524dac56c..68cee3845 100644 --- a/lib/WebGUI/i18n/English/Asset_Article.pm +++ b/lib/WebGUI/i18n/English/Asset_Article.pm @@ -1,6 +1,16 @@ package WebGUI::i18n::English::Asset_Article; our $I18N = { + 'attachments' => { + message => q|Attachments|, + lastUpdated => 0 + }, + + 'attachments help' => { + message => q|Attach files and images directly to this Article. Please note that these files will not be accessible through the asset manager to other assets.|, + lastUpdated => 0 + }, + 'cache timeout' => { message => q|Cache Timeout|, lastUpdated => 0 @@ -166,6 +176,28 @@ The URL to the thumbnail for the attached image. The URL to the attached image.

+attachment_loop
+A loop containing all the attachments. +

+ filename
+ The name of the file. +

+ url
+ The url to download the file. +

+ thumbnailUrl
+ The url of the thumbnail of this file. +

+ iconUrl
+ The url to the file type icon of this file. +

+ isImage
+ A boolean indicating whether this is an image or not. +

+

+

+ + linkTitle
The title of the link added to the article.

diff --git a/lib/WebGUI/i18n/English/Asset_Collaboration.pm b/lib/WebGUI/i18n/English/Asset_Collaboration.pm index caf94916b..f65716065 100644 --- a/lib/WebGUI/i18n/English/Asset_Collaboration.pm +++ b/lib/WebGUI/i18n/English/Asset_Collaboration.pm @@ -177,11 +177,6 @@ our $I18N = { lastUpdated => 1141142205, }, - 'delete file warning' => { - message => q|Are you sure you wish to delete this file?|, - lastUpdated => 1109618544, - }, - 'display last reply' => { message => q|Display last reply?|, lastUpdated => 1109618544,