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