1 |
8 |
ahitrov@rambler.ru |
<%once> |
2 |
|
|
|
3 |
|
|
my @attypes = ( 'multimedia_new', 'image', 'images', 'audio' ); |
4 |
|
|
|
5 |
|
|
</%once> |
6 |
|
|
<%args> |
7 |
|
|
|
8 |
|
|
$object => undef |
9 |
|
|
$source => undef |
10 |
|
|
|
11 |
|
|
</%args> |
12 |
|
|
<%init> |
13 |
|
|
|
14 |
|
|
return unless ref $object; |
15 |
|
|
return unless ref $source; |
16 |
|
|
|
17 |
|
|
my @properties = $source->structure(); |
18 |
|
|
for (0..$#properties) { |
19 |
|
|
my $prop = $properties[$_]; |
20 |
|
|
my $name = $prop->{attr}; |
21 |
|
|
my $type = $prop->{type}; |
22 |
|
|
next unless grep { $_ eq $type } @attypes; |
23 |
|
|
my $attachment = $source->get_image( $name ); |
24 |
|
|
warn "\nClone: $type | $name\n" if $DEBUG; |
25 |
|
|
if (ref $attachment) { |
26 |
|
|
if ( $prop->{type} eq 'image' ) { |
27 |
|
|
## Отдельная картинка |
28 |
|
|
############################################################## |
29 |
|
|
if ( exists $attachment->{filename} ) { |
30 |
|
|
my $img; |
31 |
|
|
my $source_name; |
32 |
|
|
my $ext; |
33 |
|
|
my $new_name = '/images/'.$object->get_file_name(); |
34 |
|
|
warn "Clone img put from: $source_name to $new_name.$ext\n" if $DEBUG; |
35 |
|
|
my $stored = 0; |
36 |
|
|
foreach my $source ( @{ $state->{files_dir} } ) { |
37 |
|
|
$source_name = $source.$attachment->{filename}; |
38 |
|
|
$ext = $1 if $source_name =~ /\.(\w+)$/; |
39 |
|
|
$stored = Contenido::File::store ($new_name.'.'.$ext, $source_name); |
40 |
|
|
last if $stored; |
41 |
|
|
} |
42 |
|
|
if ( $stored ) { |
43 |
|
|
$img = { |
44 |
|
|
filename => $new_name.'.'.$ext, |
45 |
|
|
width => $attachment->{width}, |
46 |
|
|
height => $attachment->{height}, |
47 |
|
|
alt => $attachment->{alt}, |
48 |
|
|
atext => $attachment->{atext} }; |
49 |
|
|
if ( exists $attachment->{mini} ) { |
50 |
|
|
my $source_mini; |
51 |
|
|
my $main_size = $attachment->{mini}{width}.'x'.$attachment->{mini}{height}; |
52 |
|
|
my $mini_name = $new_name.'.'.$main_size; |
53 |
|
|
my $stored = 0; |
54 |
|
|
foreach my $source ( @{ $state->{files_dir} } ) { |
55 |
|
|
$source_mini = $source.$attachment->{mini}{filename}; |
56 |
|
|
$stored = Contenido::File::store ($mini_name.'.'.$ext, $source_mini); |
57 |
|
|
last if $stored; |
58 |
|
|
} |
59 |
|
|
if ( $stored ) { |
60 |
|
|
$img->{mini} = { |
61 |
|
|
filename => $mini_name.'.'.$ext, |
62 |
|
|
width => $attachment->{mini}{width}, |
63 |
|
|
height => $attachment->{mini}{height}, |
64 |
|
|
}; |
65 |
|
|
$img->{mini}->{$main_size} = { |
66 |
|
|
filename => $mini_name.'.'.$ext, |
67 |
|
|
width => $attachment->{mini}{width}, |
68 |
|
|
height => $attachment->{mini}{height}, |
69 |
|
|
}; |
70 |
|
|
} |
71 |
|
|
foreach my $key ( keys %{ $attachment->{mini} } ) { |
72 |
|
|
next if $key =~ /file|width|height/; |
73 |
|
|
next if $key eq $main_size; |
74 |
|
|
my $source_mini; |
75 |
|
|
my $size = $attachment->{mini}{$key}{width}.'x'.$attachment->{mini}{$key}{height}; |
76 |
|
|
my $mini_name = $new_name.'.'.$size; |
77 |
|
|
my $stored = 0; |
78 |
|
|
foreach my $source ( @{ $state->{files_dir} } ) { |
79 |
|
|
$source_mini = $source.$attachment->{mini}{$key}{filename}; |
80 |
|
|
$stored = Contenido::File::store ($mini_name.'.'.$ext, $source_mini); |
81 |
|
|
last if $stored; |
82 |
|
|
} |
83 |
|
|
if ( $stored ) { |
84 |
|
|
$img->{mini}->{$key} = { |
85 |
|
|
filename => $mini_name.'.'.$ext, |
86 |
|
|
width => $attachment->{mini}{$key}{width}, |
87 |
|
|
height => $attachment->{mini}{$key}{height}, |
88 |
|
|
}; |
89 |
|
|
} |
90 |
|
|
} |
91 |
|
|
} |
92 |
|
|
} |
93 |
640 |
ahitrov |
$object->$name( $img ); |
94 |
8 |
ahitrov@rambler.ru |
warn "\nClone img complete: ".Dumper($img)."\n" if $DEBUG; |
95 |
|
|
} |
96 |
|
|
} elsif ( $prop->{type} eq 'images' ) { |
97 |
|
|
## Куча картинков |
98 |
|
|
############################################################## |
99 |
|
|
my $PICTURE; |
100 |
|
|
for ( 1 .. $attachment->{maxnumber} ) { |
101 |
|
|
my $picture = 'image_'.$_; |
102 |
|
|
if ( exists $attachment->{$picture}{filename} ) { |
103 |
|
|
my $img; |
104 |
|
|
my $source_name = $state->{files_dir}->[0].$attachment->{$picture}{filename}; |
105 |
|
|
my $ext = $1 if $source_name =~ /\.(\w+)$/; |
106 |
|
|
my $new_name = '/images/'.$object->get_file_name(); |
107 |
|
|
warn "Clone pics put from: $source_name to $new_name.$ext\n" if $DEBUG; |
108 |
|
|
if ( Contenido::File::store ($new_name.'.'.$ext, $source_name) ) { |
109 |
|
|
$img = { |
110 |
|
|
filename => $new_name.'.'.$ext, |
111 |
|
|
width => $attachment->{$picture}{width}, |
112 |
|
|
height => $attachment->{$picture}{height}, |
113 |
|
|
alt => $attachment->{$picture}{alt}, |
114 |
|
|
atext => $attachment->{$picture}{atext} }; |
115 |
|
|
if ( exists $attachment->{$picture}{mini} ) { |
116 |
|
|
my $source_mini = $state->{files_dir}->[0].$attachment->{$picture}{mini}{filename}; |
117 |
|
|
my $main_size = $attachment->{$picture}{mini}{width}.'x'.$attachment->{$picture}{mini}{height}; |
118 |
|
|
my $mini_name = $new_name.'.'.$main_size; |
119 |
|
|
if ( Contenido::File::store ($mini_name.'.'.$ext, $source_mini) ) { |
120 |
|
|
$img->{mini} = { |
121 |
|
|
filename => $mini_name.'.'.$ext, |
122 |
|
|
width => $attachment->{$picture}{mini}{width}, |
123 |
|
|
height => $attachment->{$picture}{mini}{height}, |
124 |
|
|
}; |
125 |
|
|
$img->{mini}->{$main_size} = { |
126 |
|
|
filename => $mini_name.'.'.$ext, |
127 |
|
|
width => $attachment->{$picture}{mini}{width}, |
128 |
|
|
height => $attachment->{$picture}{mini}{height}, |
129 |
|
|
}; |
130 |
|
|
} |
131 |
|
|
foreach my $key ( keys %{ $attachment->{$picture}{mini} } ) { |
132 |
|
|
next if $key =~ /file|width|height/; |
133 |
|
|
next if $key eq $main_size; |
134 |
|
|
my $source_mini = $state->{files_dir}->[0].$attachment->{$picture}{mini}{$key}{filename}; |
135 |
|
|
my $size = $attachment->{$picture}{mini}{$key}{width}.'x'.$attachment->{$picture}{mini}{$key}{height}; |
136 |
|
|
my $mini_name = $new_name.'.'.$size; |
137 |
|
|
if ( Contenido::File::store ($mini_name.'.'.$ext, $source_mini) ) { |
138 |
|
|
$img->{mini}->{$key} = { |
139 |
|
|
filename => $mini_name.'.'.$ext, |
140 |
|
|
width => $attachment->{$picture}{mini}{$key}{width}, |
141 |
|
|
height => $attachment->{$picture}{mini}{$key}{height}, |
142 |
|
|
}; |
143 |
|
|
} |
144 |
|
|
} |
145 |
|
|
} |
146 |
|
|
} |
147 |
|
|
$PICTURE->{$picture} = $img; |
148 |
|
|
} |
149 |
|
|
|
150 |
|
|
} |
151 |
|
|
if ( $attachment->{maxnumber} ) { |
152 |
|
|
$PICTURE->{maxnumber} = $attachment->{maxnumber}; |
153 |
640 |
ahitrov |
$object->$name( $PICTURE ); |
154 |
8 |
ahitrov@rambler.ru |
} |
155 |
|
|
warn "\nClone pics complete: ".Dumper($PICTURE)."\n" if $DEBUG; |
156 |
|
|
} elsif ( $prop->{type} eq 'multimedia_new' ) { |
157 |
|
|
## Произвольный бинарник |
158 |
|
|
############################################################## |
159 |
|
|
if ( exists $attachment->{filename} ) { |
160 |
|
|
my $img; |
161 |
|
|
my $source_name = $state->{files_dir}->[0].$attachment->{filename}; |
162 |
|
|
my $ext = $1 if $source_name =~ /\.(\w+)$/; |
163 |
|
|
my $new_name = '/images/'.$object->get_file_name(); |
164 |
|
|
if ( Contenido::File::store ($new_name.'.'.$ext, $source_name) ) { |
165 |
|
|
$img = { |
166 |
|
|
filename => $new_name.'.'.$ext, |
167 |
|
|
atext => $attachment->{atext} |
168 |
|
|
}; |
169 |
|
|
} |
170 |
640 |
ahitrov |
$object->$name( $img ); |
171 |
8 |
ahitrov@rambler.ru |
warn "\nClone binary complete: ".Dumper($img)."\n" if $DEBUG; |
172 |
|
|
} |
173 |
|
|
} |
174 |
|
|
} |
175 |
|
|
} |
176 |
|
|
|
177 |
|
|
|
178 |
|
|
</%init> |