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