added file asset uploads
This commit is contained in:
parent
95bac10986
commit
f72368fd8d
4 changed files with 36 additions and 47 deletions
|
|
@ -4,10 +4,12 @@ package WebGUI::Asset;
|
|||
|
||||
use strict;
|
||||
use Tie::IxHash;
|
||||
use WebGUI::AdminConsole;
|
||||
use WebGUI::Clipboard;
|
||||
use WebGUI::DateTime;
|
||||
use WebGUI::ErrorHandler;
|
||||
use WebGUI::Form;
|
||||
use WebGUI::FormProcessor;
|
||||
use WebGUI::Grouping;
|
||||
use WebGUI::HTTP;
|
||||
use WebGUI::Icon;
|
||||
|
|
@ -15,6 +17,7 @@ use WebGUI::Id;
|
|||
use WebGUI::Privilege;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::SQL;
|
||||
use WebGUI::TabForm;
|
||||
use WebGUI::Utility;
|
||||
|
||||
|
||||
|
|
@ -90,7 +93,7 @@ sub definition {
|
|||
properties=>{
|
||||
title=>{
|
||||
fieldType=>'text',
|
||||
defaultValue=>$definition->[0]->{className}
|
||||
defaultValue=>$class->getName
|
||||
},
|
||||
menuTitle=>{
|
||||
fieldType=>'text',
|
||||
|
|
@ -841,7 +844,8 @@ sub www_editSave {
|
|||
}
|
||||
}
|
||||
$object->update(\%data);
|
||||
return $self->www_manageAssets if ($session{form}{afterEdit} eq "assetManager");
|
||||
return $self->www_manageAssets if ($session{form}{afterEdit} eq "assetManager" && $session{form}{assetId} eq "new");
|
||||
return $object->getParent->www_manageAssets if ($session{form}{afterEdit} eq "assetManager");
|
||||
return $object->www_view;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -99,11 +99,15 @@ sub getEditForm {
|
|||
my $tabform = $self->SUPER::getEditForm();
|
||||
if ($self->get("filename") ne "") {
|
||||
my $storage = WebGUI::Storage->get($self->get("storageId"));
|
||||
$tabform->getTab("properties")->readOnly(
|
||||
-label=>"Current File",
|
||||
-value=>'<a href="'.$storage->getUrl($self->get("filename")).'"><img src="'.$storage->getFileIconUrl($self->get("filename")).'" alt="'.$self->get("filename").'" border="0" align="middle" /> '.$self->get("filename").'</a>'
|
||||
);
|
||||
|
||||
}
|
||||
$tabform->getTab("properties")->file(
|
||||
-name=>"file",
|
||||
-label=>"File To Upload"
|
||||
-label=>"New File To Upload"
|
||||
);
|
||||
return $tabform;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,10 +13,11 @@ package WebGUI::Macro::Navigation;
|
|||
use strict;
|
||||
use WebGUI::Macro;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::Navigation;
|
||||
#use WebGUI::Navigation;
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub process {
|
||||
return "Nav disabled.";
|
||||
my @param = WebGUI::Macro::getParams($_[0]);
|
||||
|
||||
my $identifier = $param[0];
|
||||
|
|
|
|||
|
|
@ -20,9 +20,11 @@ use FileHandle;
|
|||
use File::Path;
|
||||
use POSIX;
|
||||
use strict;
|
||||
use warnings;
|
||||
use WebGUI::ErrorHandler;
|
||||
use WebGUI::Id;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::Utility;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
@ -93,23 +95,6 @@ sub _addError {
|
|||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 _getStorageParts
|
||||
|
||||
Returns an array reference containing the hashed values for the storage location directory.
|
||||
|
||||
NOTE: This is a private method and should never be called except internally to this package.
|
||||
|
||||
=cut
|
||||
|
||||
sub _getStorageParts {
|
||||
my $self = shift;
|
||||
my $id = shift;
|
||||
$id =~ m/^(.{2})(.{2})/;
|
||||
return [$1,$2]
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 addFileFromFilesystem( pathToFile )
|
||||
|
|
@ -177,16 +162,17 @@ Provide the form variable name to which the file being uploaded is assigned.
|
|||
|
||||
=cut
|
||||
|
||||
sub addFileFromFormPost{
|
||||
sub addFileFromFormPost {
|
||||
my $self = shift;
|
||||
my $formVariableName = shift;
|
||||
return "" if (WebGUI::HTTP::getStatus() =~ /^413/);
|
||||
my $filename = $session{cgi}->upload($formVariableName);
|
||||
if (defined $filename) {
|
||||
if ($filename =~ /([^\/\\]+)$/) {
|
||||
my $tempPath = $session{cgi}->upload($formVariableName);
|
||||
if (defined $tempPath) {
|
||||
my $filename;
|
||||
if ($tempPath =~ /([^\/\\]+)$/) {
|
||||
$filename = $1;
|
||||
} else {
|
||||
$filename = $filename;
|
||||
$filename = $tempPath;
|
||||
}
|
||||
my $type = $self->getFileExtension($filename);
|
||||
if (isIn($type, qw(pl perl sh cgi php asp))) { # make us safe from malicious uploads
|
||||
|
|
@ -194,11 +180,12 @@ sub addFileFromFormPost{
|
|||
$filename .= ".txt";
|
||||
}
|
||||
$filename = WebGUI::URL::makeCompliant($filename);
|
||||
my $bytesread;
|
||||
my $file = FileHandle->new(">".$self->getPath($filename));
|
||||
if (defined $file) {
|
||||
my $buffer;
|
||||
binmode $file;
|
||||
while (my $bytesread=read($filename,$buffer,1024)) {
|
||||
while ($bytesread=read($tempPath,$buffer,1024)) {
|
||||
print $file $buffer;
|
||||
}
|
||||
close($file);
|
||||
|
|
@ -206,7 +193,6 @@ sub addFileFromFormPost{
|
|||
$self->_addError("Couldn't open file ".$self->getPath($filename)." for writing due to error: ".$!);
|
||||
return undef;
|
||||
}
|
||||
close $filename;
|
||||
return $filename;
|
||||
}
|
||||
return undef;
|
||||
|
|
@ -307,22 +293,15 @@ sub create {
|
|||
my $class = shift;
|
||||
my $id = WebGUI::Id::generate();
|
||||
my $self = $class->get($id);
|
||||
my $parts = $self->_getStorageParts($id);
|
||||
my $node = $session{config}{uploadsPath}.$session{os}{slash}.$parts->[0];
|
||||
mkdir($node);
|
||||
unless ($! eq "File exists" || $! eq "") {
|
||||
$self->_addError("Couldn't create storage location: $node : $!");
|
||||
my $node = $session{config}{uploadsPath};
|
||||
foreach my $folder ($self->{_part1}, $self->{_part2}, $id) {
|
||||
$node .= $session{os}{slash}.$folder;
|
||||
unless (-e $node) { # check to see if it already exists
|
||||
unless (mkdir($node)) { # check to see if there was an error during creation
|
||||
$self->_addError("Couldn't create storage location: $node : $!");
|
||||
}
|
||||
}
|
||||
}
|
||||
$node .= $session{os}{slash}.$parts->[1];
|
||||
mkdir($node);
|
||||
unless ($! eq "File exists" || $! eq "") {
|
||||
$self->_addError("Couldn't create storage location: $node : $!");
|
||||
}
|
||||
$node .= $session{os}{slash}.$id;
|
||||
mkdir($node);
|
||||
unless ($! eq "") {
|
||||
$self->_addError("Couldn't create storage location: $node : $!");
|
||||
}
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
|
@ -374,8 +353,8 @@ The unique identifier for this file system storage location.
|
|||
sub get {
|
||||
my $class = shift;
|
||||
my $id = shift;
|
||||
my $parts = _getStorageParts($id);
|
||||
bless {_id => $id, _part1 => $parts->[0], _part2 => $parts->[1]}, $class;
|
||||
$id =~ m/^(.{2})(.{2})/;
|
||||
bless {_id => $id, _part1 => $1, _part2 => $2}, $class;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -431,6 +410,7 @@ The filename of the file you wish to find out the type for.
|
|||
=cut
|
||||
|
||||
sub getFileExtension {
|
||||
my $self = shift;
|
||||
my $filename = shift;
|
||||
my $extension = lc($filename);
|
||||
$extension =~ s/.*\.(.*?)$/$1/;
|
||||
|
|
@ -453,9 +433,9 @@ The name of the file to get the icon for.
|
|||
sub getFileIconUrl {
|
||||
my $self = shift;
|
||||
my $filename = shift;
|
||||
my $extension = $self->getFileExtension($filename);
|
||||
my $extension = $self->getFileExtension($filename);
|
||||
my $path = $session{config}{extrasPath}.$session{os}{slash}."fileIcons".$session{os}{slash}.$extension.".gif";
|
||||
if (-f $path) {
|
||||
if (-e $path) {
|
||||
return $session{config}{extrasURL}."/fileIcons/".$extension.".gif";
|
||||
}
|
||||
return $session{config}{extrasURL}."/fileIcons/unknown.gif";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue