Revision 225 (by ahitrov, 2012/06/27 17:59:40) Serialize

<%once>

    use IO::File;

</%once>
<%args>

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

</%args>
<%init>

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>