Revision 347
- Date:
- 2013/05/17 20:16:39
- Files:
-
- /utf8/core/comps/contenido/components/inputs/multimedia_new.msn (Diff) (Checkout)
- /utf8/core/comps/contenido/components/object_form.msn (Diff) (Checkout)
- /utf8/core/comps/contenido/components/set_multimedia_new.msn (Diff) (Checkout)
- /utf8/core/comps/contenido/components/set_properties.msn (Diff) (Checkout)
- /utf8/core/lib/Contenido/File.pm (Diff) (Checkout)
- /utf8/core/lib/Contenido/Object.pm (Diff) (Checkout)
Legend:
- Added
- Removed
- Modified
-
utf8/core/comps/contenido/components/inputs/multimedia_new.msn
10 10 <div id="<% $attr %>_url_loader" style="display:none; background:#d0d0d0; padding:2px;"> URL: <input 11 11 id="<% $attr %>_ext_url" type="text" name="<% $attr %>.ext_url" style="width:81%;font-family:arial;font-size:9pt;"></div> 12 12 </td></tr> 13 % if ( exists($MULTI->{filename}) ) 14 % { 13 % if ( exists($MULTI->{filename}) ) { 15 14 % my $TYPE = 'unknown'; 16 % if (length($MULTI->{ext}) > 0) 17 % { 18 % if (-e $keeper->{state}->{mason_comp}.'/contenido/i/icons/'.$MULTI->{ext}.'.gif') 19 % { 15 % if (length($MULTI->{ext}) > 0) { 16 % if (-e $keeper->{state}->{mason_comp}.'/contenido/i/icons/'.$MULTI->{ext}.'.gif') { 20 17 % $TYPE = $MULTI->{ext}; 21 18 % } 22 19 % } 23 <tr><td style="font-size:95%;"><% $MULTI->{filename} %></td></tr> 20 <tr><td style="font-size:90%;"><a href="<% $MULTI->{filename} %>" target="_blank"><% $MULTI->{sourcename} || $MULTI->{filename} %></a></td></tr> 24 21 <tr><td> 25 22 26 23 <table border="0" width="100%"><tr> 27 24 <td align="right"><a href="<% $MULTI->{filename} %>"><img src="/contenido/i/icons/<% $TYPE %>.gif" width="36" height=36" hspace="5" border="0"></a></td> 28 25 <td> 29 <font size="-1" color="#888888">Тип: <% uc($MULTI->{ext}) %><br> 26 <font style="font-size:90%" color="#888888">Тип: <% uc($MULTI->{ext}) %><br> 30 27 Размер: <% int($MULTI->{size}/1024) %> Кб 31 28 </font> 32 29 </td> … … 35 32 </td></tr> 36 33 % } 37 34 % 38 % foreach my $iattr (sort (@{ $iattrs })) 39 % { 35 % foreach my $iattr (sort (@{ $iattrs })) { 40 36 % next if ( ($iattr eq 'filename') || ($iattr eq 'mini') || ($iattr eq 'width') || ($iattr eq 'height') ); 41 37 <tr><td><font size="-1" color="#888888"><% $ATTRNAMES->{$iattr} %> (<% $iattr %>):</font></td></tr> 42 38 <tr><td><input type="text" name="<% $attr %>.<% $iattr %>" size="60" value="<% html_escape($MULTI->{$iattr}) %>" style="width:95%;font-family:arial;font-size:9pt;"></td></tr> … … 60 56 <%INIT> 61 57 62 58 my $iattrs = $prop->{iattrs}; 63 $iattrs ||= []; 59 $iattrs ||= ['alt']; 64 60 65 61 my $ATTRNAMES = { 66 'alt' => 'Подпись', 62 'alt' => 'Название', 67 63 'btext' => 'Текст до картинки', 68 64 'atext' => 'Текст после картинки', 69 65 'url' => 'Ссылка с картинки', -
utf8/core/comps/contenido/components/object_form.msn
40 40 41 41 my $prop = $properties[$_]; 42 42 my $name = $prop->{attr}; 43 next if ($prop->{hidden} == 1) || ($prop->{type} eq 'image') || ($prop->{type} eq 'external') || ($prop->{type} =~ /^array/i) || ($prop->{type} =~ /^image/) || ($prop->{type} eq 'multimedia') || ($prop->{type} eq 'multimedia_new') || ($prop->{type} eq 'audio'); 43 next if ($prop->{hidden} == 1) || ($prop->{type} eq 'image') || ($prop->{type} eq 'external') || ($prop->{type} =~ /^array/i) || ($prop->{type} =~ /^image/) || ($prop->{type} eq 'multimedia') || ($prop->{type} eq 'multimedia_new') || ($prop->{type} eq 'multimedia_multi') || ($prop->{type} eq 'audio'); 44 44 45 45 </%perl> 46 46 <tr><td height="8"></td></tr> … … 162 162 MULTI => $MULTI, 163 163 options => $options, 164 164 &> 165 % } elsif ($prop->{type} eq 'multimedia_new') 166 % { 165 % } elsif ($prop->{type} eq 'multimedia_new') { 167 166 % my $MULTI = $object->get_image( $prop->{attr} ); 168 167 169 168 <& "/contenido/components/inputs/multimedia_new.msn", … … 172 171 attr => $prop->{attr}, 173 172 MULTI => $MULTI, 174 173 options => $options, 175 &> 176 % } elsif ($prop->{type} eq 'audio') 177 % { 174 &> 175 176 % } elsif ($prop->{type} eq 'multimedia_multi') { 177 % my $FILES = $object->get_image( $prop->{attr} ); 178 % if (ref($FILES) ne 'HASH') { next }; 179 % my $MN = $FILES->{maxnumber}+0; 180 % for my $mn (1..$MN) { 181 % my $MULTI = $FILES->{'file_'.$mn}; 182 <& "/contenido/components/inputs/multimedia_new.msn", 183 rusname => $prop->{rusname}, 184 prop => $prop, object=>$object, 185 attr => $prop->{attr}.'_'.$mn, 186 MULTI => $MULTI, 187 options => $options, 188 &> 189 190 % } 191 % my $ME = exists $prop->{empty_slots} ? $prop->{empty_slots} : 3; 192 % $ME = ($ME + $FILES->{maxnumber}) >= 100 ? 0 : (100 - $FILES->{maxnumber} < $ME ? 100 - $FILES->{maxnumber} : $ME ); 193 % for my $mn (1..$ME) { 194 195 <& "/contenido/components/inputs/multimedia_new.msn", 196 rusname => $prop->{rusname}, 197 prop => $prop, object=>$object, 198 attr => $prop->{attr}.'_'.($MN+$mn), 199 MULTI => {}, 200 options => $options, 201 &> 202 203 % } 204 % } elsif ($prop->{type} eq 'audio') { 178 205 % my $MULTI = $object->get_image( $prop->{attr} ); 179 206 180 207 <& "/contenido/components/inputs/audio.msn", -
utf8/core/comps/contenido/components/set_multimedia_new.msn
27 27 } 28 28 if ($upload) { 29 29 30 my $BIN = $object->_store_binary( $upload, attr => $prop->{attr} ); 30 my $BIN = $object->_store_binary( $upload, attr => $prop->{attr}, prop => $prop ); 31 31 32 32 if ( ref $BIN eq 'HASH' && exists $BIN->{filename} ) { 33 33 $object->_delete_binary( $default ); -
utf8/core/comps/contenido/components/set_properties.msn
101 101 102 102 if ($SETS->{'_delete_multi.'.$name} == 1) 103 103 { 104 my $BINARY = eval ('my '.$object->{ $name }); 105 Contenido::File::remove($BINARY->{"filename"}); 106 $object->{$name} = ''; 104 my $BINARY = $object->get_image( $name ); 105 $object->_delete_binary( $BINARY ); 106 $object->$name(''); 107 107 } else { 108 108 my $MULTI = undef; 109 109 if (length($object->{ $name }) > 8) … … 124 124 125 125 if ($SETS->{'_delete_multi.'.$name} == 1) 126 126 { 127 my $BINARY = eval ('my '.$object->{ $name }); 128 Contenido::File::remove($BINARY->{"filename"}); 129 $object->{$name} = ''; 127 my $BINARY = $object->get_image( $name ); 128 $object->_delete_binary( $BINARY ); 129 $object->$name(''); 130 130 } else { 131 131 my $MULTI = undef; 132 132 if (length($object->{ $name }) > 8) … … 141 141 } 142 142 } 143 143 144 } elsif ($prop->{type} eq 'multimedia_multi') { 145 # -------------------------------------------------------------------------------------- 146 # А вот это уже сложнее - составление блока из всех файлов... 147 148 my $FILES = $object->get_image( $name ); 149 if ( ref($FILES) ne 'HASH' ) { 150 $FILES = {}; 151 $FILES->{maxnumber} = 0; 152 }; 153 154 # Теперь надо просмотреть все аргументы - а вдруг это то, что нам нужно... 155 foreach my $arg (keys(%{ $SETS })) 156 { 157 # Разбиваем все на части, отделяем... 158 my ($partname,undef) = split(/\./,$arg); 159 $partname =~ /^(.+)_(\d+)$/; 160 my ($localname,$number) = ($1, $2); 161 if ( ($localname eq $prop->{attr}) && ($number > 0) && ( $arg eq $localname.'_'.$number )) { 162 # Ура! Нашли элемент! 163 164 my $partname = $localname.'_'.$number; 165 166 if ($SETS->{'_delete_multi.'.$partname} == 1) { 167 $object->_delete_binary( $FILES->{'file_'.$number} ); 168 delete $FILES->{'file_'.$number}; 169 } else { 170 my $MULTI = undef; 171 if (exists($FILES->{'file_'.$number})) { 172 $MULTI = $FILES->{'file_'.$number}; 173 }; 174 $MULTI = $m->comp('/contenido/components/set_multimedia_new.msn', default=>$MULTI, field=>$partname, SETS=>$SETS, object=>$object, prop => $prop); 175 if (exists($MULTI->{filename})) { 176 $MULTI->{number} = $number; 177 $FILES->{'file_'.$number} = $MULTI; 178 $FILES->{maxnumber} = $number if ($number > $FILES->{maxnumber}); 179 } 180 } 181 } 182 } 183 184 if ( scalar(keys(%{ $FILES })) > 0) { 185 my $maxnumber = 0; 186 for ( 1..100 ) { 187 $maxnumber = $_ if exists $FILES->{"file_$_"} && $_ > $maxnumber; 188 } 189 $FILES->{maxnumber} = $maxnumber; 190 $object->$name( $object->_serialize($FILES) ); 191 } 192 144 193 } elsif ( $prop->{type} eq 'audio' ) { 145 194 # -------------------------------------------------------------------------------------- 146 195 # Добавление одного объект Мультимедиа -
utf8/core/lib/Contenido/File.pm
428 428 return unless ref $prop; 429 429 430 430 my $filename = '/binary/'.$object->get_file_name() || return; 431 my $orig_name = ''; 432 if ( ref $input eq 'Apache::Upload' ) { 433 $orig_name = $input->filename(); 434 } elsif ( !ref $input ) { 435 $orig_name = $input; 436 } 437 if ( $orig_name ) { 438 if ( $orig_name =~ /\\([^\\]+)$/ ) { 439 $orig_name = $1; 440 } elsif ( $orig_name =~ /\/([^\/]+)$/ ) { 441 $orig_name = $1; 442 } 443 } 431 444 if ( $prop->{softrename} ) { 432 445 my $oid = $object->id || int(rand(10000)); 433 my $orig_name = ''; 434 if ( ref $input eq 'Apache::Upload' ) { 435 $orig_name = $input->filename(); 436 } elsif ( !ref $input ) { 437 $orig_name = $input; 438 } 439 446 if ( $orig_name ) { 440 if ( $orig_name =~ /\\([^\\]+)$/ ) { 441 $orig_name = $1; 442 } elsif ( $orig_name =~ /\/([^\/]+)$/ ) { 443 $orig_name = $1; 444 } 445 $orig_name =~ s/[\ \t]/_/g; 446 $orig_name = $oid.'_'.$orig_name; 447 my $set_name = $orig_name; 448 $set_name =~ s/[\ \t]/_/g; 449 $set_name = $oid.'_'.$set_name; 447 450 $filename =~ s/\/([^\/]+)$//; 448 451 my $fname = $1; 449 unless ( $orig_name =~ /^[a-zA-Z_\d\.\-\,]+$/ ) { 450 $orig_name = translit( $orig_name ); 452 unless ( $set_name =~ /^[a-zA-Z_\d\.\-\,]+$/ ) { 453 $set_name = translit( $set_name ); 451 454 } 452 warn "\n\n\n\n\nNew Name: [$orig_name]\n\n\n\n\n" if $DEBUG; 453 unless ( $orig_name =~ /^[a-zA-Z_\d\.\-\,]+$/ ) { 454 $orig_name = $fname; 455 warn "\n\n\n\n\nNew Name: [$set_name]\n\n\n\n\n" if $DEBUG; 456 unless ( $set_name =~ /^[a-zA-Z_\d\.\-\,]+$/ ) { 457 $set_name = $fname; 455 458 } 456 $filename .= '/'.$orig_name; 459 $filename .= '/'.$set_name; 457 460 $filename =~ s/\.([^\.]+)$//; 458 461 } 459 462 } … … 491 494 492 495 my $BINARY; 493 496 if ( store($filename.'.'.$ext, $filename_tmp.'.'.$ext) ) { 494 @{$BINARY}{"filename", "ext", "size"} = ( 495 $filename.".".$ext, $ext, $size 497 @{$BINARY}{"filename", "ext", "size", "sourcename"} = ( 498 $filename.".".$ext, $ext, $size, $orig_name 496 499 ); 497 500 498 501 unlink $filename_tmp.'.'.$ext if -e $filename_tmp.'.'.$ext; 499 502 500 503 if ( $ext =~ /(rar|7z|zip|arc|lha|arj|cab)/ ) { 501 504 $BINARY->{type} = 'archive'; 502 } elsif ( $ext =~ /(doc|rtf)/ ) { 505 } elsif ( $ext =~ /(doc|docx|rtf)/ ) { 503 506 $BINARY->{type} = 'doc'; 504 } elsif ( $ext eq 'xls' ) { 507 } elsif ( $ext =~ /(xls|xlsx)/ ) { 505 508 $BINARY->{type} = 'xls'; 506 509 } elsif ( $ext =~ /(mdb|ppt)/ ) { 507 510 $BINARY->{type} = 'msoffice'; 508 } elsif ( $ext =~ /(pdf)/ ) { 511 } elsif ( $ext =~ /(pdf|fb2|djvu)/ ) { 509 512 $BINARY->{type} = 'ebook'; 510 } elsif ( $ext eq 'psd' ) { 511 $BINARY->{type} = 'psd'; 513 } elsif ( $ext =~ /(psd|cdr)/ ) { 514 $BINARY->{type} = 'graphics'; 515 } elsif ( $ext eq 'ico' ) { 516 $BINARY->{type} = 'icon'; 512 517 } elsif ( $ext =~ /(exe|msi|cab)/ ) { 513 518 $BINARY->{type} = 'executable'; 514 519 } else { -
utf8/core/lib/Contenido/Object.pm
641 641 if ( exists $opts{attachments} && $opts{attachments} ) { 642 642 my @props = $self->structure(); 643 643 if ( @props ) { 644 @props = grep { $_->{type} =~ /^(image|images|multimedia_new)$/ } @props; 644 @props = grep { $_->{type} =~ /^(image|images|multimedia_new|multimedia_multi)$/ } @props; 645 645 foreach my $prop ( @props ) { 646 646 my $att = $self->get_image($prop->{attr}); 647 647 if ( $prop->{type} eq 'image' ) { … … 677 677 if ( ref $att && exists $att->{filename} && $att->{filename} ) { 678 678 Contenido::File::remove( $att->{filename} ); 679 679 } 680 } elsif ( $prop->{type} eq 'multimedia_multi' ) { 681 for ( 1..100 ) { 682 next unless exists $att->{"file_$_"}; 683 my $file = $att->{"file_$_"}; 684 if ( ref $file && exists $file->{filename} && $file->{filename} ) { 685 Contenido::File::remove( $file->{filename} ); 686 } 687 } 680 688 } 681 689 } 682 690 } … … 1200 1208 # Вычищает все мини-копии 1201 1209 # 1202 1210 # Формат использования: 1203 # $document->_store_image( $image_attr_structure ) 1211 # $document->_delete_image( $image_attr_structure ) 1204 1212 # ---------------------------------------------------------------------------- 1205 1213 sub _delete_image { 1206 1214 my $self = shift; … … 1210 1218 } 1211 1219 1212 1220 # ---------------------------------------------------------------------------- 1213 # Метод _store_binary() сохраняет произвольный бинарный файл, привязанную к полю multimedia или multimedia_new 1221 # Метод _store_binary() сохраняет произвольный бинарный файл, привязанную к полю multimedia_multi или multimedia_new 1214 1222 # 1215 1223 # Формат использования: 1216 1224 # $document->_store_binary( INPUT, attr => 'fieldname' )