1 |
225 |
ahitrov |
<%once> |
2 |
|
|
|
3 |
|
|
use IO::File; |
4 |
|
|
|
5 |
|
|
</%once> |
6 |
8 |
ahitrov@rambler.ru |
<%args> |
7 |
|
|
|
8 |
225 |
ahitrov |
$SETS => undef |
9 |
|
|
$field => undef |
10 |
|
|
$default=> undef |
11 |
|
|
$object => undef |
12 |
|
|
$prop => undef |
13 |
8 |
ahitrov@rambler.ru |
|
14 |
|
|
</%args> |
15 |
|
|
<%init> |
16 |
|
|
|
17 |
|
|
return undef unless defined $SETS and defined $field; |
18 |
|
|
|
19 |
|
|
# -------------------------------------------------------------------------------------- |
20 |
|
|
# Добавление одной картинки |
21 |
|
|
|
22 |
|
|
my $IMAGE = $default; |
23 |
|
|
|
24 |
117 |
ahitrov |
if ($SETS->{$field} || $SETS->{"$field.ext_url"}) { |
25 |
8 |
ahitrov@rambler.ru |
|
26 |
117 |
ahitrov |
my $upload; |
27 |
|
|
if ( $SETS->{$field} ) { |
28 |
|
|
$upload = $r->upload($field); |
29 |
|
|
} elsif ( $SETS->{"$field.ext_url"} && $SETS->{"$field.ext_url"} =~ /^(http|https|ftp):\/\/.*/ ) { |
30 |
|
|
$upload = $SETS->{"$field.ext_url"}; |
31 |
|
|
} |
32 |
8 |
ahitrov@rambler.ru |
if ($upload) { |
33 |
47 |
ahitrov@rambler.ru |
|
34 |
169 |
ahitrov |
my $IMG = $object->_store_image( $upload, attr => $prop->{attr}, prop => $prop ); |
35 |
47 |
ahitrov@rambler.ru |
|
36 |
113 |
ahitrov |
if ( ref $IMG eq 'HASH' && exists $IMG->{filename} ) { |
37 |
|
|
$object->_delete_image( $default ); |
38 |
|
|
%$IMAGE = %$IMG; |
39 |
|
|
} |
40 |
47 |
ahitrov@rambler.ru |
|
41 |
8 |
ahitrov@rambler.ru |
} else { |
42 |
113 |
ahitrov |
warn 'ERROR in incoming POST form: "'.$field.' is not file upload (value: "'.$SETS->{$field}.'")'; |
43 |
8 |
ahitrov@rambler.ru |
} |
44 |
|
|
} |
45 |
|
|
|
46 |
|
|
# Дополнительные поля - берем все, что найдем... |
47 |
|
|
|
48 |
|
|
my $pattern = "^".$field.q|\.(.*)$|; |
49 |
|
|
|
50 |
|
|
foreach my $localfield (keys(%{ $SETS })) { |
51 |
|
|
if ($localfield =~ /$pattern/) { |
52 |
113 |
ahitrov |
my $imagefield = $1; |
53 |
|
|
$IMAGE->{$imagefield} = $m->comp("/contenido/components/filter.msn", str => $SETS->{$localfield}); |
54 |
8 |
ahitrov@rambler.ru |
} |
55 |
|
|
} |
56 |
|
|
|
57 |
|
|
return $IMAGE; |
58 |
113 |
ahitrov |
|
59 |
8 |
ahitrov@rambler.ru |
</%init> |