Line # Revision Author
1 3 ahitrov@rambler.ru package Contenido::File;
2
3 use strict;
4 use warnings;
5
6 use Contenido::Globals;
7 use URI;
8 use Data::Dumper;
9 use IO::File;
10 use IO::Scalar;
11 use Contenido::File::Scheme::HTTP;
12 use Contenido::File::Scheme::FILE;
13 use Contenido::DateTime;
14 143 ahitrov use Image::Info qw(image_info dim);
15 3 ahitrov@rambler.ru
16 our $IgnoreErrors = 1;
17
18 132 ahitrov my %translit = (
19 '�' => 'a', '�' => 'b', '�' => 'v', '�' => 'g', '�' => 'd', '�' => 'e', '�' => 'e', '�' => 'zh', '�' => 'z', '�' => 'i', '�' => 'y',
20 '�' => 'k', '�' => 'l', '�' => 'm', '�' => 'n', '�' => 'o', '�' => 'p', '�' => 'r', '�' => 's', '�' => 't', '�' => 'u', '�' => 'f', '�' => 'h',
21 '�' => 'ts', '�' => '4', '�' => 'sh', '�' => 'sch', '�' => 'y', '�' => 'i', '�' => 'y', '�' => 'e', '�' => 'u', '�' => 'a', '�' => 'A',
22 '�' => 'B', '�' => 'V', '�' => 'G', '�' => 'D', '�' => 'E', '�' => 'E', '�' => 'ZH', '�' => 'Z', '�' => 'I', '�' => 'Y', '�' => 'K', '�' => 'L',
23 '�' => 'M', '�' => 'N', '�' => 'O', '�' => 'P', '�' => 'R', '�' => 'S', '�' => 'T', '�' => 'U', '�' => 'F', '�' => 'H', '�' => 'TS', '�' => '4',
24 '�' => 'SH', '�' => 'SCH', '�' => 'Y', '�' => 'I', '�' => 'Y', '�' => 'E', '�' => 'U', '�' => 'YA',
25 );
26
27
28 3 ahitrov@rambler.ru sub fetch {
29 my $filename = shift || return;
30 my $fh;
31
32 foreach my $dir (@{$state->{"files_dir"}}) {
33 my $path = $dir . '/' . $filename;
34
35 no strict "refs";
36 $fh = &{"Contenido::File::Scheme::".uc(scheme($path))."::fetch"}($path);
37 return $fh if $fh;
38 }
39 }
40
41 sub store {
42 my $filename = shift || return;
43 my $fh = get_fh(shift) || return;
44
45 my $dt = Contenido::DateTime->new()->set_locale('en')->set_time_zone("UTC");
46
47 my @successful;
48
49 #������� ��������� � ����� /
50 $filename =~ s#/+#/#g;
51 #������� ��������� /
52 $filename =~ s#^/##;
53
54 foreach my $dir (@{$state->{"files_dir"}}) {
55 seek $fh, 0, 0;
56 my $path = $dir . '/' . $filename;
57
58 no strict "refs";
59 my $return = &{"Contenido::File::Scheme::".uc(scheme($path))."::store"}($path, $fh, $dt);
60 push @successful, $path if $return;
61 }
62
63 if (
64 !@successful or
65 (
66 (scalar @successful != scalar @{$state->{"files_dir"}}) and
67 !$IgnoreErrors
68 )
69 ) {
70 foreach my $path (@successful) {
71 no strict "refs";
72 &{"Contenido::File::Scheme::".uc(scheme($path))."::remove"}($path);
73 }
74 return;
75 }
76 1;
77 }
78
79 sub size {
80 my $filename = shift;
81 my %args = @_;
82
83 my $size;
84
85 #������� ��������� � ����� /
86 $filename =~ s#/+#/#g;
87 #������� ��������� /
88 $filename =~ s#^/##;
89
90 foreach my $dir (@{$state->{"files_dir"}}) {
91 no strict "refs";
92 my $response = &{"Contenido::File::Scheme::".uc(scheme($dir))."::size"}($dir."/".$filename, %args);
93 return unless defined $response;
94 return if defined $size and $size != $response;
95
96 $size = $response;
97 #TODO
98 last;
99 }
100 return $size;
101 }
102
103 sub remove {
104 my $filename = shift || return;
105
106 #������� ��������� � ����� /
107 $filename =~ s#/+#/#g;
108 #������� ��������� /
109 $filename =~ s#^/##;
110
111 foreach my $dir (@{$state->{"files_dir"}}) {
112 no strict "refs";
113 &{"Contenido::File::Scheme::".uc(scheme($dir))."::remove"}($dir."/".$filename);
114 }
115
116 1;
117 }
118
119 sub get_fh {
120 my $input = shift;
121 my $fh;
122
123 if (not ref $input) {
124 no strict "refs";
125 $fh = &{"Contenido::File::Scheme::".uc(scheme($input))."::get_fh"}($input);
126 114 ahitrov } elsif ( ref $input eq 'Apache::Upload' ) {
127 $fh = $input->fh;
128 } elsif ((ref $input eq "GLOB") or (ref $input eq 'IO::File')) {
129 3 ahitrov@rambler.ru $fh = $input;
130 } elsif (ref $input eq "SCALAR") {
131 $fh = IO::Scalar->new($input);
132 } else {
133 $log->warning("Path, scalar ref or fh needed");
134 return;
135 }
136
137 return $fh
138 }
139
140 sub scheme {
141 my $uri = shift;
142 my $scheme;
143
144 $scheme = URI->new($uri)->scheme() || "file";
145 170 ahitrov $scheme = 'http' if lc($scheme) eq 'https';
146 3 ahitrov@rambler.ru
147 return $scheme;
148 }
149
150 # sub files_dir {
151 # return unless $_[0];
152 # my $dir;
153
154 # for (scheme($_[0])) {
155 # /http/ && do {
156 # $dir = URI->new($_[0])->canonical();
157 # $dir =~ s|/*$|/|;
158 # last;
159 # };
160 # /file/ && do {
161 # $dir = URI->new($_[0])->path();
162 # $dir =~ s|/*$|/|;
163 # last;
164 # };
165 # }
166
167 # return $dir;
168 # }
169
170 114 ahitrov sub store_image {
171 my $input = shift;
172 my (%opts) = @_;
173 my $object = delete $opts{object} || return;
174 171 ahitrov my $attr = delete $opts{attr};
175 114 ahitrov
176 171 ahitrov my ($prop) = exists $opts{prop} && ref $opts{prop} ? ($opts{prop}) : $attr ? grep { $_->{attr} eq $attr } $object->structure : (undef);
177 114 ahitrov return unless ref $prop;
178 my @preview = exists $prop->{'preview'} && ref $prop->{'preview'} eq 'ARRAY' ? @{$prop->{'preview'}} : exists $prop->{'preview'} && $prop->{'preview'} ? ($prop->{'preview'}) : ();
179 my @crops = exists $prop->{'crop'} && ref $prop->{'crop'} eq 'ARRAY' ? @{$prop->{'crop'}} : exists $prop->{'crop'} && $prop->{'crop'} ? ($prop->{'crop'}) : ();
180 my @shrinks = exists $prop->{'shrink'} && ref $prop->{'shrink'} eq 'ARRAY' ? @{$prop->{'shrink'}} : exists $prop->{'shrink'} && $prop->{'shrink'} ? ($prop->{'shrink'}) : ();
181
182 my $filename = '/images/'.$object->get_file_name() || return;
183 my $filename_tmp = $state->{'tmp_dir'}.'/'.join('_', split('/', $filename));
184
185 my $fh = get_fh($input);
186 return unless ref $fh;
187
188 my $ext;
189 121 ahitrov my $size = 1073741824;
190 if ( not ref $input ) {
191 114 ahitrov $ext = $input =~ /(jpe?g|gif|png)$/i ? lc $1 : 'bin';
192 121 ahitrov if ( scheme($input) eq 'file' ) {
193 $size = (stat $fh)[7];
194 }
195 114 ahitrov } elsif ( ref $input eq 'Apache::Upload' ) {
196 $ext = $input->filename() =~ /(jpe?g|gif|png)$/i ? lc $1 : 'bin';
197 121 ahitrov $size = (stat $fh)[7];
198 } elsif ( $opts{filename} ) {
199 $ext = $opts{filename} =~ /(jpe?g|gif|png)$/i ? lc $1 : 'bin';
200 114 ahitrov }
201 127 ahitrov if ( ref $fh eq 'IO::Scalar' ) {
202 $size = length("$fh");
203 }
204 114 ahitrov $ext ||= 'bin';
205
206 my $fh_tmp = IO::File->new('>'.$filename_tmp.'.'.$ext) || return;
207 my $buffer;
208
209 121 ahitrov $size = sysread $fh, $buffer, $size;
210 114 ahitrov syswrite $fh_tmp, $buffer, $size;
211
212 undef $fh_tmp;
213
214 143 ahitrov my $image_info = image_info($filename_tmp.'.'.$ext);
215 183 ahitrov if ( !(ref $image_info && $image_info->{width} && $image_info->{height}) || (ref $image_info && $image_info->{error}) ) {
216 148 ahitrov unlink $filename_tmp.'.'.$ext;
217 return undef;
218 143 ahitrov }
219 183 ahitrov if ( $image_info->{file_ext} ne $ext ) {
220 rename $filename_tmp.'.'.$ext, $filename_tmp.'.'.$image_info->{file_ext};
221 $ext = $image_info->{file_ext};
222 }
223 148 ahitrov my $transformed;
224 if ( exists $prop->{transform} && ref $prop->{transform} eq 'ARRAY' && scalar @{$prop->{transform}} == 2 && $prop->{transform}[0] =~ /(crop|resize|shrink)/ ) {
225 my $c_line;
226 if ( $prop->{transform}[0] eq 'resize' ) {
227 $c_line = $state->{'convert_binary'}.' -resize \''.$prop->{transform}[1].'\' -quality 80 '.$filename_tmp.'.'.$ext.' '.$filename_tmp.'.transformed.'.$ext;
228 } elsif ( $prop->{transform}[0] eq 'crop' ) {
229 my $shave_string;
230 my ($nwidth, $nheight) = $prop->{transform}[1] =~ /(\d+)x(\d+)/i ? ($1, $2) : (0, 0);
231 if ( ($image_info->{width} / $image_info->{height}) > ($nwidth / $nheight) ) {
232 my $shave_pixels = (($image_info->{width} / $image_info->{height}) - ($nwidth / $nheight)) * $image_info->{height};
233 $shave_string = ' -shave '.int($shave_pixels / 2).'x0';
234 } elsif ( ($image_info->{height} / $image_info->{width}) > ($nheight / $nwidth) ) {
235 my $shave_pixels = (($image_info->{height} / $image_info->{width}) - ($nheight / $nwidth)) * $image_info->{width};
236 $shave_string = ' -shave 0x'.int($shave_pixels / 2);
237 }
238 if ( $shave_string ) {
239 my $c_line = $state->{"convert_binary"}." $shave_string $filename_tmp.$ext $filename_tmp.shaved.$ext";
240 my $result = `$c_line`;
241 if (length $result > 0) {
242 print "Contenido Error: ��� ������ '$c_line' ��������� ������ '$result' ($@)\n";
243 return undef;
244 }
245 } else {
246 my $c_line = "cp $filename_tmp.$ext $filename_tmp.shaved.$ext";
247 my $result = `$c_line`;
248 if (length $result > 0) {
249 print "Contenido Error: ��� ������ '$c_line' ��������� ������ '$result' ($@)\n";
250 return undef;
251 }
252 }
253 $c_line = $state->{'convert_binary'}.' -geometry \''.$prop->{transform}[1].'!\' -quality 80 '.$filename_tmp.'.shaved.'.$ext.' '.$filename_tmp.'.transformed.'.$ext;
254 } elsif ( $prop->{transform}[0] eq 'shrink' ) {
255 $c_line = $state->{'convert_binary'}.' -geometry \''.$prop->{transform}[1].'!\' -quality 80 '.$filename_tmp.'.'.$ext.' '.$filename_tmp.'.transformed.'.$ext;
256 }
257 my $result = `$c_line`;
258 $transformed = 1;
259 unlink $filename_tmp.'.shaved.'.$ext if -e $filename_tmp.'.shaved.'.$ext;
260 }
261 143 ahitrov
262 114 ahitrov my $IMAGE;
263 148 ahitrov my $stored = $transformed ? store($filename.'.'.$ext, $filename_tmp.'.transformed.'.$ext) : store($filename.'.'.$ext, $filename_tmp.'.'.$ext);
264 if ( $stored ) {
265 114 ahitrov $IMAGE = {};
266 150 ahitrov # hashref slice assigning - ������
267 148 ahitrov if ( $transformed && -e $filename_tmp.'.transformed.'.$ext ) {
268 161 ahitrov my ($tw, $th) = Image::Size::imgsize($filename_tmp.'.transformed.'.$ext);
269 my ($w, $h) = Image::Size::imgsize($filename_tmp.'.'.$ext);
270 @{$IMAGE}{'filename', 't_width', 't_height', 'width', 'height'} = (
271 $filename.'.'.$ext, $tw, $th, $w, $h
272 148 ahitrov );
273 unlink $filename_tmp.'.transformed.'.$ext;
274 } else {
275 @{$IMAGE}{'filename', 'width', 'height'} = (
276 $filename.'.'.$ext,
277 Image::Size::imgsize($filename_tmp.'.'.$ext),
278 );
279 }
280 114 ahitrov
281 foreach my $suffix (@preview) {
282 my $c_line = $state->{'convert_binary'}.' -geometry \''.$suffix.'\' -quality 80 '.$filename_tmp.'.'.$ext.' '.$filename_tmp.'.'.$suffix.'.'.$ext;
283 my $result = `$c_line`;
284
285 if (length $result > 0) {
286 warn 'Contenido Error: ��� ������ "'.$c_line.'" ��������� ������ "'.$result.'" ('.$@.")\n";
287 return undef;
288 }
289 @{$IMAGE->{'mini'}{$suffix}}{'filename', 'width', 'height'} = (
290 $filename.'.'.$suffix.'.'.$ext,
291 Image::Size::imgsize($filename_tmp.'.'.$suffix.'.'.$ext),
292 );
293 %{$IMAGE->{'resize'}{$suffix}} = %{$IMAGE->{'mini'}{$suffix}};
294 store($filename.'.'.$suffix.'.'.$ext, $filename_tmp.'.'.$suffix.'.'.$ext);
295 unlink $filename_tmp.'.'.$suffix.'.'.$ext if -e $filename_tmp.'.'.$suffix.'.'.$ext;
296 }
297 if ( @preview ) {
298 @{$IMAGE->{'mini'}}{'filename', 'width', 'height'} = @{$IMAGE->{'mini'}{$preview[0]}}{'filename', 'width', 'height'};
299 @{$IMAGE->{'resize'}}{'filename', 'width', 'height'} = @{$IMAGE->{'mini'}{$preview[0]}}{'filename', 'width', 'height'};
300 }
301
302 ########## CROPS
303 foreach my $suffix (@crops) {
304
305 my $shave_string;
306 my ($nwidth, $nheight) = $suffix =~ /(\d+)x(\d+)/i ? ($1, $2) : (0, 0);
307 if ( ($IMAGE->{width} / $IMAGE->{height}) > ($nwidth / $nheight) ) {
308 my $shave_pixels = (($IMAGE->{width} / $IMAGE->{height}) - ($nwidth / $nheight)) * $IMAGE->{height};
309 $shave_string = ' -shave '.int($shave_pixels / 2).'x0';
310 } elsif ( ($IMAGE->{height} / $IMAGE->{width}) > ($nheight / $nwidth) ) {
311 my $shave_pixels = (($IMAGE->{height} / $IMAGE->{width}) - ($nheight / $nwidth)) * $IMAGE->{width};
312 $shave_string = ' -shave 0x'.int($shave_pixels / 2);
313 }
314 if ( $shave_string ) {
315 my $c_line = $state->{"convert_binary"}." $shave_string $filename_tmp.$ext $filename_tmp.shaved.$ext";
316 my $result = `$c_line`;
317 if (length $result > 0) {
318 print "Contenido Error: ��� ������ '$c_line' ��������� ������ '$result' ($@)\n";
319 }
320 } else {
321 my $c_line = "cp $filename_tmp.$ext $filename_tmp.shaved.$ext";
322 my $result = `$c_line`;
323 if (length $result > 0) {
324 print "Contenido Error: ��� ������ '$c_line' ��������� ������ '$result' ($@)\n";
325 }
326 }
327
328 my $c_line = $state->{'convert_binary'}.' -geometry \''.$suffix.'!\' -quality 80 '.$filename_tmp.'.shaved.'.$ext.' '.$filename_tmp.'.'.$suffix.'.'.$ext;
329 my $result = `$c_line`;
330
331 if (length $result > 0) {
332 warn 'Contenido Error: ��� ������ "'.$c_line.'" ��������� ������ "'.$result.'" ('.$@.")\n";
333 return undef;
334 }
335 @{$IMAGE->{'mini'}{$suffix}}{'filename', 'width', 'height'} = (
336 $filename.'.'.$suffix.'.'.$ext,
337 Image::Size::imgsize($filename_tmp.'.'.$suffix.'.'.$ext),
338 );
339 %{$IMAGE->{'crop'}{$suffix}} = %{$IMAGE->{'mini'}{$suffix}};
340 store($filename.'.'.$suffix.'.'.$ext, $filename_tmp.'.'.$suffix.'.'.$ext);
341 unlink $filename_tmp.'.shaved.'.$ext if -e $filename_tmp.'.shaved.'.$ext;
342 unlink $filename_tmp.'.'.$suffix.'.'.$ext if -e $filename_tmp.'.'.$suffix.'.'.$ext;
343 }
344 if ( @crops ) {
345 if ( !exists $IMAGE->{'mini'}{'filename'} ) {
346 @{$IMAGE->{'mini'}}{'filename', 'width', 'height'} = @{$IMAGE->{'mini'}{$crops[0]}}{'filename', 'width', 'height'};
347 }
348 @{$IMAGE->{'crop'}}{'filename', 'width', 'height'} = @{$IMAGE->{'crop'}{$crops[0]}}{'filename', 'width', 'height'};
349 }
350
351
352 ########## SHRINKS
353 foreach my $suffix (@shrinks) {
354
355 my $c_line = $state->{'convert_binary'}.' -geometry \''.$suffix.'!\' -quality 80 '.$filename_tmp.'.'.$ext.' '.$filename_tmp.'.'.$suffix.'.'.$ext;
356 my $result = `$c_line`;
357
358 if (length $result > 0) {
359 warn 'Contenido Error: ��� ������ "'.$c_line.'" ��������� ������ "'.$result.'" ('.$@.")\n";
360 return undef;
361 }
362 @{$IMAGE->{'mini'}{$suffix}}{'filename', 'width', 'height'} = (
363 $filename.'.'.$suffix.'.'.$ext,
364 Image::Size::imgsize($filename_tmp.'.'.$suffix.'.'.$ext),
365 );
366 %{$IMAGE->{'shrink'}{$suffix}} = %{$IMAGE->{'mini'}{$suffix}};
367 store($filename.'.'.$suffix.'.'.$ext, $filename_tmp.'.'.$suffix.'.'.$ext);
368 unlink $filename_tmp.'.'.$suffix.'.'.$ext if -e $filename_tmp.'.'.$suffix.'.'.$ext;
369 }
370 if ( @shrinks && !exists $IMAGE->{'mini'}{'filename'} ) {
371 if ( !exists $IMAGE->{'mini'}{'filename'} ) {
372 @{$IMAGE->{'mini'}}{'filename', 'width', 'height'} = @{$IMAGE->{'mini'}{$shrinks[0]}}{'filename', 'width', 'height'};
373 }
374 @{$IMAGE->{'shrink'}}{'filename', 'width', 'height'} = @{$IMAGE->{'shrink'}{$shrinks[0]}}{'filename', 'width', 'height'};
375 }
376
377 unlink $filename_tmp.'.'.$ext if -e $filename_tmp.'.'.$ext;
378 161 ahitrov $IMAGE->{width} = delete $IMAGE->{t_width} if exists $IMAGE->{t_width};
379 $IMAGE->{height} = delete $IMAGE->{t_height} if exists $IMAGE->{t_height};
380 114 ahitrov }
381
382 return $IMAGE;
383 }
384
385 sub remove_image {
386 my $IMAGE = shift;
387
388 if ( ref $IMAGE eq 'HASH' && exists $IMAGE->{filename} ) {
389 remove($IMAGE->{'filename'}) || return;
390 }
391 if ( ref $IMAGE && exists $IMAGE->{mini} && ref $IMAGE->{mini} eq 'HASH' ) {
392 foreach my $val ( values %{$IMAGE->{mini}} ) {
393 if ( ref $val && exists $val->{filename} && $val->{filename} ) {
394 remove($val->{'filename'}) || return;
395 }
396 }
397 }
398 1;
399 }
400
401
402 127 ahitrov sub store_binary {
403 my $input = shift;
404 my (%opts) = @_;
405 my $object = delete $opts{object} || return;
406 my $attr = delete $opts{attr} || return;
407
408 my ($prop) = grep { $_->{attr} eq $attr } $object->structure;
409 return unless ref $prop;
410
411 my $filename = '/binary/'.$object->get_file_name() || return;
412 132 ahitrov if ( $prop->{softrename} ) {
413 my $oid = $object->id || int(rand(10000));
414 my $orig_name = '';
415 if ( ref $input eq 'Apache::Upload' ) {
416 $orig_name = $input->filename();
417 } elsif ( !ref $input ) {
418 $orig_name = $input;
419 }
420 if ( $orig_name ) {
421 if ( $orig_name =~ /\\([^\\]+)$/ ) {
422 $orig_name = $1;
423 } elsif ( $orig_name =~ /\/([^\/]+)$/ ) {
424 $orig_name = $1;
425 }
426 $orig_name =~ s/[\ \t]/_/g;
427 $orig_name = $oid.'_'.$orig_name;
428 $filename =~ s/\/([^\/]+)$//;
429 my $fname = $1;
430 unless ( $orig_name =~ /^[a-zA-Z_\d\.\-\,]+$/ ) {
431 $orig_name = translit( $orig_name );
432 }
433 warn "\n\n\n\n\nNew Name: [$orig_name]\n\n\n\n\n" if $DEBUG;
434 unless ( $orig_name =~ /^[a-zA-Z_\d\.\-\,]+$/ ) {
435 $orig_name = $fname;
436 }
437 $filename .= '/'.$orig_name;
438 $filename =~ s/\.([^\.]+)$//;
439 }
440 }
441
442 127 ahitrov my $filename_tmp = $state->{'tmp_dir'}.'/'.join('_', split('/', $filename));
443
444 my $fh = get_fh($input);
445 return unless ref $fh;
446
447 my $ext;
448 my $size = 1073741824;
449 if ( not ref $input ) {
450 132 ahitrov $ext = $input =~ /\.([^\.]+)$/ ? lc($1) : 'bin';
451 127 ahitrov if ( scheme($input) eq 'file' ) {
452 $size = (stat $fh)[7];
453 }
454 } elsif ( ref $input eq 'Apache::Upload' ) {
455 132 ahitrov $ext = $input->filename() =~ /\.([^\.]+)$/ ? lc($1) : 'bin';
456 127 ahitrov $size = (stat $fh)[7];
457 } elsif ( $opts{filename} ) {
458 132 ahitrov $ext = $opts{filename} =~ /\.([^\.]+)$/ ? lc($1) : 'bin';
459 127 ahitrov }
460 if ( ref $fh eq 'IO::Scalar' ) {
461 $size = length("$fh");
462 }
463 $ext ||= 'bin';
464
465 my $fh_tmp = IO::File->new('>'.$filename_tmp.'.'.$ext) || return;
466 my $buffer;
467
468 $size = sysread $fh, $buffer, $size;
469 syswrite $fh_tmp, $buffer, $size;
470
471 undef $fh_tmp;
472
473 my $BINARY;
474 if ( store($filename.'.'.$ext, $filename_tmp.'.'.$ext) ) {
475 132 ahitrov @{$BINARY}{"filename", "ext", "size"} = (
476 $filename.".".$ext, $ext, $size
477 );
478
479 127 ahitrov unlink $filename_tmp.'.'.$ext if -e $filename_tmp.'.'.$ext;
480 132 ahitrov
481 if ( $ext =~ /(rar|7z|zip|arc|lha|arj|cab)/ ) {
482 $BINARY->{type} = 'archive';
483 } elsif ( $ext =~ /(doc|rtf)/ ) {
484 $BINARY->{type} = 'doc';
485 } elsif ( $ext eq 'xls' ) {
486 $BINARY->{type} = 'xls';
487 } elsif ( $ext =~ /(mdb|ppt)/ ) {
488 $BINARY->{type} = 'msoffice';
489 } elsif ( $ext =~ /(pdf)/ ) {
490 $BINARY->{type} = 'ebook';
491 } elsif ( $ext eq 'psd' ) {
492 $BINARY->{type} = 'psd';
493 } elsif ( $ext =~ /(exe|msi|cab)/ ) {
494 $BINARY->{type} = 'executable';
495 } else {
496 $BINARY->{type} = 'unknown';
497 }
498
499 127 ahitrov }
500
501 return $BINARY;
502 }
503
504 sub remove_binary {
505 my $BINARY = shift;
506
507 if ( ref $BINARY eq 'HASH' && exists $BINARY->{filename} ) {
508 remove($BINARY->{'filename'}) || return;
509 }
510
511 1;
512 }
513
514
515 132 ahitrov sub translit {
516 my $str = shift;
517 my @str = split (//, $str);
518 my $res = '';
519 while ( scalar @str ) {
520 my $alpha = shift @str;
521 if ( exists $translit{$alpha} ) {
522 $res .= $translit{$alpha};
523 } else {
524 $res .= $alpha;
525 }
526 }
527 return $res;
528 }
529
530
531 3 ahitrov@rambler.ru 1;