Revision 171 (by ahitrov, 2012/01/18 19:14:14) The more comprehensive method for image upload
<%args>

$SETS => undef
$field => undef
$default => undef
$object => undef
$prop => undef

</%args>

<%init>
use IO::File;
use Data::Dumper;

return undef unless defined $SETS and defined $field;

# --------------------------------------------------------------------------------------
# ���������� ����� ��������

my $IMAGE = $default;

if ($SETS->{$field} || $SETS->{"$field.ext_url"}) {

    my $upload;
    if ( $SETS->{$field} ) {
	$upload = $r->upload($field);
    } elsif ( $SETS->{"$field.ext_url"} && $SETS->{"$field.ext_url"} =~ /^(http|https|ftp):\/\/.*/ ) {
	$upload = $SETS->{"$field.ext_url"};
    }
    if ($upload) {

	my $IMG = $object->_store_image( $upload, attr => $prop->{attr}, prop => $prop );

	if ( ref $IMG eq 'HASH' && exists $IMG->{filename} ) {
		$object->_delete_image( $default );
		%$IMAGE = %$IMG;
	}

    } else {
	warn 'ERROR in incoming POST form: "'.$field.' is not file upload (value: "'.$SETS->{$field}.'")';
    }
}

# �������������� ���� - ����� ���, ��� ������...

my $pattern = "^".$field.q|\.(.*)$|;

foreach my $localfield (keys(%{ $SETS })) {
    if ($localfield =~ /$pattern/) {
	my $imagefield = $1;
	$IMAGE->{$imagefield} = $m->comp("/contenido/components/filter.msn", str => $SETS->{$localfield});
    }
}

return $IMAGE;

</%init>