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 .= '
+ filename+ + + linkTitle
+ 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. + +