1 |
8 |
ahitrov@rambler.ru |
<%ARGS> |
2 |
|
|
|
3 |
53 |
ahitrov@rambler.ru |
$object => undef |
4 |
|
|
$SETS => undef |
5 |
8 |
ahitrov@rambler.ru |
|
6 |
|
|
</%ARGS> |
7 |
|
|
<%INIT> |
8 |
53 |
ahitrov@rambler.ru |
|
9 |
|
|
use Contenido::File; |
10 |
8 |
ahitrov@rambler.ru |
use vars qw($keeper $request ); |
11 |
|
|
|
12 |
|
|
$request->{local_codepage} = 'UTF8'; |
13 |
53 |
ahitrov@rambler.ru |
$request->{local_codepage} = 'WIN' if Convert::Cyrillic::cstocs('WIN', 'UTF8', $SETS->{control_charset}) eq 'Контроль'; |
14 |
|
|
$request->{local_codepage} = 'KOI8' if Convert::Cyrillic::cstocs('KOI8', 'UTF8', $SETS->{control_charset}) eq 'Контроль'; |
15 |
8 |
ahitrov@rambler.ru |
|
16 |
|
|
warn "Contenido Debug: Форма для редактирования пришла в кодировке ".$request->{local_codepage}."\n" if ($state->debug()); |
17 |
|
|
|
18 |
|
|
my @properties = $object->structure(); |
19 |
|
|
for (0..$#properties) |
20 |
|
|
{ |
21 |
53 |
ahitrov@rambler.ru |
my $prop = $properties[$_]; |
22 |
|
|
my $name = $prop->{attr}; |
23 |
|
|
my $type = $prop->{type}; |
24 |
8 |
ahitrov@rambler.ru |
|
25 |
53 |
ahitrov@rambler.ru |
next if ($name eq 'sections'); |
26 |
|
|
next if ($name eq 'id'); |
27 |
8 |
ahitrov@rambler.ru |
|
28 |
53 |
ahitrov@rambler.ru |
if ($m->comp_exists("/contenido/components/outputs/$type.msn")) { |
29 |
|
|
$object->{$name} = $m->comp("/contenido/components/outputs/$type.msn", SETS => $SETS, name => $name, object => $object ); |
30 |
|
|
|
31 |
|
|
} elsif ( $prop->{type} eq 'image' ) { |
32 |
8 |
ahitrov@rambler.ru |
# -------------------------------------------------------------------------------------- |
33 |
|
|
# Добавление одной, отдельно стоящей картинки... |
34 |
|
|
|
35 |
|
|
if ($SETS->{'_delete_image.'.$name} == 1) |
36 |
|
|
{ |
37 |
|
|
my $IMAGE = eval ('my '.$object->{ $name }); |
38 |
|
|
Contenido::File::remove($IMAGE->{'filename'}); |
39 |
|
|
Contenido::File::remove($IMAGE->{'mini'}{'filename'}); |
40 |
|
|
foreach my $key (keys %{$IMAGE->{'mini'}}) { |
41 |
|
|
if (ref $IMAGE->{'mini'}{$key} && ref $IMAGE->{'mini'}{$key} eq 'HASH' && $IMAGE->{'mini'}{$key}->{'filename'}) { |
42 |
|
|
Contenido::File::remove($IMAGE->{'mini'}{$key}->{'filename'}) if $IMAGE->{'mini'}{$key}->{'filename'} ne $IMAGE->{'mini'}{'filename'}; |
43 |
|
|
} |
44 |
|
|
} |
45 |
|
|
$object->{$name} = ''; |
46 |
|
|
} else { |
47 |
|
|
my $IMAGE = undef; |
48 |
|
|
if (length($object->{ $name }) > 8) |
49 |
|
|
{ |
50 |
|
|
$IMAGE = eval ('my '.$object->{ $name }); |
51 |
|
|
if (ref($IMAGE) ne 'HASH') { $IMAGE = {} }; |
52 |
|
|
} |
53 |
|
|
$IMAGE = $m->comp('/contenido/components/set_image.msn', default=>$IMAGE, field=>$name, SETS=>$SETS, object=>$object, prop => $prop); |
54 |
|
|
if (exists($IMAGE->{filename})) |
55 |
|
|
{ |
56 |
|
|
local $Data::Dumper::Indent = 0; |
57 |
|
|
$object->{$name} = Data::Dumper::Dumper($IMAGE); |
58 |
|
|
} |
59 |
|
|
} |
60 |
53 |
ahitrov@rambler.ru |
|
61 |
|
|
} elsif ($prop->{type} =~ /^images/) { |
62 |
8 |
ahitrov@rambler.ru |
# -------------------------------------------------------------------------------------- |
63 |
|
|
# А вот это уже сложнее - составление блока из всех картинок... |
64 |
|
|
|
65 |
|
|
my $IMAGES = {}; |
66 |
|
|
if (length($object->{ $name }) > 10) |
67 |
|
|
{ |
68 |
|
|
$IMAGES = eval ('my '.$object->{ $prop->{attr} }); |
69 |
|
|
if (ref($IMAGES) ne 'HASH') |
70 |
|
|
{ |
71 |
|
|
$IMAGES = {}; |
72 |
|
|
$IMAGES->{maxnumber} = 0; |
73 |
|
|
}; |
74 |
|
|
} |
75 |
|
|
|
76 |
|
|
my $maxnumber_ = 0; |
77 |
|
|
|
78 |
|
|
# Теперь надо просмотреть все аргументы - а вдруг это то, что нам нужно... |
79 |
|
|
foreach my $arg (keys(%{ $SETS })) |
80 |
|
|
{ |
81 |
|
|
# Разбиваем все на части, отделяем... |
82 |
|
|
my ($partname,undef) = split(/\./,$arg); |
83 |
|
|
$partname =~ /^(.+)_(\d+)$/; |
84 |
|
|
my ($localname,$number) = ($1, $2); |
85 |
|
|
if ( ($localname eq $prop->{attr}) && ($number > 0) && ( $arg eq $localname.'_'.$number )) |
86 |
|
|
{ |
87 |
|
|
# Ура! Нашли элемент! |
88 |
|
|
|
89 |
|
|
my $partname = $localname.'_'.$number; |
90 |
|
|
|
91 |
|
|
if ($SETS->{'_delete_image.'.$partname} == 1) |
92 |
|
|
{ |
93 |
|
|
Contenido::File::remove($IMAGES->{'image_'.$number}{"filename"}); |
94 |
|
|
Contenido::File::remove($IMAGES->{'image_'.$number}{"mini"}{"filename"}); |
95 |
|
|
foreach my $key (keys %{$IMAGES->{'image_'.$number}{'mini'}}) { |
96 |
|
|
if (ref $IMAGES->{'image_'.$number}{'mini'}{$key} && ref $IMAGES->{'image_'.$number}{'mini'}{$key} eq 'HASH' && $IMAGES->{'image_'.$number}{'mini'}{$key}->{'filename'}) { |
97 |
|
|
Contenido::File::remove($IMAGES->{'image_'.$number}{'mini'}{$key}->{'filename'}) if $IMAGES->{'image_'.$number}{'mini'}{$key}->{'filename'} ne $IMAGES->{'image_'.$number}{'mini'}{'filename'}; |
98 |
|
|
} |
99 |
|
|
} |
100 |
|
|
delete $IMAGES->{'image_'.$number}; |
101 |
|
|
} |
102 |
|
|
else |
103 |
|
|
{ |
104 |
|
|
my $IMAGE = undef; |
105 |
|
|
if (exists($IMAGES->{'image_'.$number})) |
106 |
|
|
{ |
107 |
|
|
$IMAGE = $IMAGES->{'image_'.$number}; |
108 |
|
|
}; |
109 |
|
|
$IMAGE = $m->comp('/contenido/components/set_image.msn', default=>$IMAGE, field=>$partname, SETS=>$SETS, object=>$object, prop => $prop); |
110 |
|
|
if (exists($IMAGE->{filename})) |
111 |
|
|
{ |
112 |
|
|
local $Data::Dumper::Indent = 0; |
113 |
|
|
$IMAGE->{number} = $number; |
114 |
|
|
$IMAGES->{'image_'.$number} = $IMAGE; |
115 |
|
|
$IMAGES->{maxnumber} = $number if ($number > $IMAGES->{maxnumber}); |
116 |
|
|
} |
117 |
|
|
} |
118 |
|
|
} |
119 |
|
|
|
120 |
|
|
} |
121 |
|
|
|
122 |
|
|
if ( scalar(keys(%{ $IMAGES })) > 0) |
123 |
|
|
{ |
124 |
|
|
local $Data::Dumper::Indent = 0; |
125 |
|
|
$object->{$name} = Data::Dumper::Dumper($IMAGES); |
126 |
|
|
} |
127 |
|
|
|
128 |
53 |
ahitrov@rambler.ru |
} elsif ( $prop->{type} eq 'multimedia' ) { |
129 |
8 |
ahitrov@rambler.ru |
# -------------------------------------------------------------------------------------- |
130 |
|
|
# Добавление одного объект Мультимедиа |
131 |
|
|
|
132 |
|
|
if ($SETS->{'_delete_multi.'.$name} == 1) |
133 |
|
|
{ |
134 |
|
|
my $BINARY = eval ('my '.$object->{ $name }); |
135 |
|
|
Contenido::File::remove($BINARY->{"filename"}); |
136 |
|
|
$object->{$name} = ''; |
137 |
|
|
} else { |
138 |
|
|
my $MULTI = undef; |
139 |
|
|
if (length($object->{ $name }) > 8) |
140 |
|
|
{ |
141 |
|
|
$MULTI = eval ('my '.$object->{ $name }); |
142 |
|
|
if (ref($MULTI) ne 'HASH') { $MULTI = {} }; |
143 |
|
|
} |
144 |
|
|
$MULTI = $m->comp('/contenido/components/set_multi.msn', default=>$MULTI, field=>$name, SETS=>$SETS, object=>$object); |
145 |
|
|
if (exists($MULTI->{filename})) |
146 |
|
|
{ |
147 |
|
|
local $Data::Dumper::Indent = 0; |
148 |
|
|
$object->{$name} = Data::Dumper::Dumper($MULTI); |
149 |
|
|
} |
150 |
|
|
} |
151 |
|
|
|
152 |
53 |
ahitrov@rambler.ru |
} elsif ( $prop->{type} eq 'multimedia_new' ) { |
153 |
8 |
ahitrov@rambler.ru |
# -------------------------------------------------------------------------------------- |
154 |
|
|
# Добавление одного объект Мультимедиа |
155 |
|
|
|
156 |
|
|
if ($SETS->{'_delete_multi.'.$name} == 1) |
157 |
|
|
{ |
158 |
|
|
my $BINARY = eval ('my '.$object->{ $name }); |
159 |
|
|
Contenido::File::remove($BINARY->{"filename"}); |
160 |
|
|
$object->{$name} = ''; |
161 |
|
|
} else { |
162 |
|
|
my $MULTI = undef; |
163 |
|
|
if (length($object->{ $name }) > 8) |
164 |
|
|
{ |
165 |
|
|
$MULTI = eval ('my '.$object->{ $name }); |
166 |
|
|
if (ref($MULTI) ne 'HASH') { $MULTI = {} }; |
167 |
|
|
} |
168 |
|
|
$MULTI = $m->comp('/contenido/components/set_multimedia_new.msn', default=>$MULTI, field=>$name, SETS=>$SETS, object=>$object, prop => $prop); |
169 |
|
|
if (exists($MULTI->{filename})) |
170 |
|
|
{ |
171 |
|
|
local $Data::Dumper::Indent = 0; |
172 |
|
|
$object->{$name} = Data::Dumper::Dumper($MULTI); |
173 |
|
|
} |
174 |
|
|
} |
175 |
|
|
|
176 |
53 |
ahitrov@rambler.ru |
} elsif ( $prop->{type} eq 'audio' ) { |
177 |
8 |
ahitrov@rambler.ru |
# -------------------------------------------------------------------------------------- |
178 |
|
|
# Добавление одного объект Мультимедиа |
179 |
|
|
|
180 |
|
|
if ($SETS->{'_delete_multi.'.$name} == 1) |
181 |
|
|
{ |
182 |
|
|
my $VAR1 = undef; |
183 |
|
|
eval "\$object->{$name}"; |
184 |
|
|
my $BINARY = $VAR1; |
185 |
|
|
if (ref $BINARY) {$BINARY->remove} |
186 |
|
|
$object->{$name} = ''; |
187 |
|
|
} else { |
188 |
|
|
my $MULTI = undef; |
189 |
|
|
if (length($object->$name) > 8) |
190 |
|
|
{ |
191 |
|
|
my $VAR1 = undef; |
192 |
|
|
eval "\$object->{$name}"; |
193 |
|
|
$MULTI = $VAR1; |
194 |
|
|
unless (ref $MULTI) {$MULTI = undef}; |
195 |
|
|
} |
196 |
|
|
$MULTI = $m->comp('/contenido/components/set_audio.msn', default=>$MULTI, field=>$name, SETS=>$SETS, object=>$object, prop => $prop); |
197 |
|
|
if (exists($MULTI->{filename})) |
198 |
|
|
{ |
199 |
|
|
local $Data::Dumper::Indent = 0; |
200 |
|
|
$object->{$name} = Data::Dumper::Dumper($MULTI); |
201 |
|
|
} |
202 |
|
|
} |
203 |
|
|
|
204 |
53 |
ahitrov@rambler.ru |
} else { |
205 |
|
|
$object->{$name} = $m->comp('/contenido/components/filter.msn', str => $SETS->{$name} ); |
206 |
8 |
ahitrov@rambler.ru |
} |
207 |
|
|
|
208 |
|
|
} |
209 |
|
|
|
210 |
|
|
# По идее - мы работаем с ссылкой, так что ничего не надо возвращать! |
211 |
|
|
# O-ле! О-ле! О-ле! |
212 |
|
|
return 1; |
213 |
|
|
|
214 |
|
|
</%INIT> |