Revision 114

Date:
2011/08/17 15:54:23
Author:
ahitrov
Revision Log:
Image generation and saving transfered to File.pm and Object.pm
Files:

Legend:

 
Added
 
Removed
 
Modified
  • koi8/core/comps/contenido/components/set_image.msn

     
    21 21
    22 22 if ($SETS->{$field}) {
    23 23
    24 my @preview = exists $prop->{'preview'} && ref $prop->{'preview'} eq 'ARRAY' ? @{$prop->{'preview'}} : exists $prop->{'preview'} && $prop->{'preview'} ? ($prop->{'preview'}) : ();
    25 my @crops = exists $prop->{'crop'} && ref $prop->{'crop'} eq 'ARRAY' ? @{$prop->{'crop'}} : exists $prop->{'crop'} && $prop->{'crop'} ? ($prop->{'crop'}) : ();
    26 my @shrinks = exists $prop->{'shrink'} && ref $prop->{'shrink'} eq 'ARRAY' ? @{$prop->{'shrink'}} : exists $prop->{'shrink'} && $prop->{'shrink'} ? ($prop->{'shrink'}) : ();
    27
    28 if (ref $IMAGE eq 'HASH' && exists $IMAGE->{mini} && ref $IMAGE->{mini} eq 'HASH') {
    29 foreach my $val ( values %{$IMAGE->{mini}} ) {
    30 if ( ref $val && exists $val->{filename} && $val->{filename} ) {
    31 Contenido::File::remove($val->{'filename'});
    32 }
    33 }
    34 }
    35
    36 my $filename = '/images/'.$object->get_file_name() || return;
    37 my $filename_tmp = $state->{'tmp_dir'}.'/'.join('_', split('/', $filename));
    38
    39 24 my $upload = $r->upload($field);
    40 25 if ($upload) {
    41 my $extension = $upload->filename() =~ /(jpe?g|gif|png)$/i ? lc $1 : 'bin';
    42 my $fh = $upload->fh();
    43 my $size = (stat $fh)[7];
    44
    45 my $fh_tmp = IO::File->new('>'.$filename_tmp.'.'.$extension) || die 'Can\'t open temporary file';
    46
    47 my $buffer;
    48
    49 sysread $fh, $buffer, $size;
    50 syswrite $fh_tmp, $buffer, $size;
    51
    52 undef $fh_tmp;
    53
    54 if (Contenido::File::store($filename.'.'.$extension, $filename_tmp.'.'.$extension)) {
    55 if (ref $IMAGE eq 'HASH' and $IMAGE->{'filename'}) {
    56 Contenido::File::remove($IMAGE->{'filename'});
    57 }
    58
    59 # hashref slice assigning - ������
    60 @{$IMAGE}{'filename', 'width', 'height'} = (
    61 $filename.'.'.$extension,
    62 Image::Size::imgsize($filename_tmp.'.'.$extension),
    63 );
    64 foreach my $suffix (@preview) {
    65
    66 my $c_line = $state->{'convert_binary'}.' -geometry \''.$suffix.'\' -quality 80 '.$filename_tmp.'.'.$extension.' '.$filename_tmp.'.'.$suffix.'.'.$extension;
    67 my $result = `$c_line`;
    68
    69 if (length $result > 0) {
    70 warn 'Contenido Error: ��� ������ "'.$c_line.'" ��������� ������ "'.$result.'" ('.$@.")\n";
    71 return undef;
    72 }
    73 @{$IMAGE->{'mini'}{$suffix}}{'filename', 'width', 'height'} = (
    74 $filename.'.'.$suffix.'.'.$extension,
    75 Image::Size::imgsize($filename_tmp.'.'.$suffix.'.'.$extension),
    76 );
    77 %{$IMAGE->{'resize'}{$suffix}} = %{$IMAGE->{'mini'}{$suffix}};
    78 Contenido::File::store($filename.'.'.$suffix.'.'.$extension, $filename_tmp.'.'.$suffix.'.'.$extension);
    79 unlink $filename_tmp.'.'.$suffix.'.'.$extension if -e $filename_tmp.'.'.$suffix.'.'.$extension;
    80 }
    81 if ( @preview ) {
    82 @{$IMAGE->{'mini'}}{'filename', 'width', 'height'} = @{$IMAGE->{'mini'}{$preview[0]}}{'filename', 'width', 'height'};
    83 @{$IMAGE->{'resize'}}{'filename', 'width', 'height'} = @{$IMAGE->{'mini'}{$preview[0]}}{'filename', 'width', 'height'};
    84 }
    85 26
    86 ########## CROPS
    87 foreach my $suffix (@crops) {
    88
    89 my $shave_string;
    90 my ($nwidth, $nheight) = $suffix =~ /(\d+)x(\d+)/i ? ($1, $2) : (0, 0);
    91 if ( ($IMAGE->{width} / $IMAGE->{height}) > ($nwidth / $nheight) ) {
    92 my $shave_pixels = (($IMAGE->{width} / $IMAGE->{height}) - ($nwidth / $nheight)) * $IMAGE->{height};
    93 $shave_string = ' -shave '.int($shave_pixels / 2).'x0';
    94 } elsif ( ($IMAGE->{height} / $IMAGE->{width}) > ($nheight / $nwidth) ) {
    95 my $shave_pixels = (($IMAGE->{height} / $IMAGE->{width}) - ($nheight / $nwidth)) * $IMAGE->{width};
    96 $shave_string = ' -shave 0x'.int($shave_pixels / 2);
    97 }
    98 if ( $shave_string ) {
    99 my $c_line = $state->{"convert_binary"}." $shave_string $filename_tmp.$extension $filename_tmp.shaved.$extension";
    100 my $result = `$c_line`;
    101 if (length $result > 0) {
    102 print "Contenido Error: ��� ������ '$c_line' ��������� ������ '$result' ($@)\n";
    103 }
    104 } else {
    105 my $c_line = "cp $filename_tmp.$extension $filename_tmp.shaved.$extension";
    106 my $result = `$c_line`;
    107 if (length $result > 0) {
    108 print "Contenido Error: ��� ������ '$c_line' ��������� ������ '$result' ($@)\n";
    109 }
    110 }
    27 my $IMG = $object->_store_image( $upload, attr => $prop->{attr} );
    111 28
    112 my $c_line = $state->{'convert_binary'}.' -geometry \''.$suffix.'!\' -quality 80 '.$filename_tmp.'.shaved.'.$extension.' '.$filename_tmp.'.'.$suffix.'.'.$extension;
    113 my $result = `$c_line`;
    114
    115 if (length $result > 0) {
    116 warn 'Contenido Error: ��� ������ "'.$c_line.'" ��������� ������ "'.$result.'" ('.$@.")\n";
    117 return undef;
    118 }
    119 @{$IMAGE->{'mini'}{$suffix}}{'filename', 'width', 'height'} = (
    120 $filename.'.'.$suffix.'.'.$extension,
    121 Image::Size::imgsize($filename_tmp.'.'.$suffix.'.'.$extension),
    122 );
    123 %{$IMAGE->{'crop'}{$suffix}} = %{$IMAGE->{'mini'}{$suffix}};
    124 Contenido::File::store($filename.'.'.$suffix.'.'.$extension, $filename_tmp.'.'.$suffix.'.'.$extension);
    125 unlink $filename_tmp.'.shaved.'.$extension if -e $filename_tmp.'.shaved.'.$extension;
    126 unlink $filename_tmp.'.'.$suffix.'.'.$extension if -e $filename_tmp.'.'.$suffix.'.'.$extension;
    127 }
    128 if ( @crops ) {
    129 if ( !exists $IMAGE->{'mini'}{'filename'} ) {
    130 @{$IMAGE->{'mini'}}{'filename', 'width', 'height'} = @{$IMAGE->{'mini'}{$crops[0]}}{'filename', 'width', 'height'};
    131 }
    132 @{$IMAGE->{'crop'}}{'filename', 'width', 'height'} = @{$IMAGE->{'crop'}{$crops[0]}}{'filename', 'width', 'height'};
    133 }
    29 if ( ref $IMG eq 'HASH' && exists $IMG->{filename} ) {
    30 $object->_delete_image( $default );
    31 %$IMAGE = %$IMG;
    32 }
    134 33
    135 ########## SHRINKS
    136 foreach my $suffix (@shrinks) {
    137
    138 my $c_line = $state->{'convert_binary'}.' -geometry \''.$suffix.'!\' -quality 80 '.$filename_tmp.'.'.$extension.' '.$filename_tmp.'.'.$suffix.'.'.$extension;
    139 my $result = `$c_line`;
    140
    141 if (length $result > 0) {
    142 warn 'Contenido Error: ��� ������ "'.$c_line.'" ��������� ������ "'.$result.'" ('.$@.")\n";
    143 return undef;
    144 }
    145 @{$IMAGE->{'mini'}{$suffix}}{'filename', 'width', 'height'} = (
    146 $filename.'.'.$suffix.'.'.$extension,
    147 Image::Size::imgsize($filename_tmp.'.'.$suffix.'.'.$extension),
    148 );
    149 %{$IMAGE->{'shrink'}{$suffix}} = %{$IMAGE->{'mini'}{$suffix}};
    150 Contenido::File::store($filename.'.'.$suffix.'.'.$extension, $filename_tmp.'.'.$suffix.'.'.$extension);
    151 unlink $filename_tmp.'.'.$suffix.'.'.$extension if -e $filename_tmp.'.'.$suffix.'.'.$extension;
    152 }
    153 if ( @shrinks && !exists $IMAGE->{'mini'}{'filename'} ) {
    154 if ( !exists $IMAGE->{'mini'}{'filename'} ) {
    155 @{$IMAGE->{'mini'}}{'filename', 'width', 'height'} = @{$IMAGE->{'mini'}{$shrinks[0]}}{'filename', 'width', 'height'};
    156 }
    157 @{$IMAGE->{'shrink'}}{'filename', 'width', 'height'} = @{$IMAGE->{'shrink'}{$shrinks[0]}}{'filename', 'width', 'height'};
    158 }
    159
    160
    161 }
    162
    163 unlink $filename_tmp.'.'.$extension if -e $filename_tmp.'.'.$extension;
    164 34 } else {
    165 warn 'ERROR in incoming POST form: "'.$field.' is not file upload (value: "'.$SETS->{$field}.'")';
    35 warn 'ERROR in incoming POST form: "'.$field.' is not file upload (value: "'.$SETS->{$field}.'")';
    166 36 }
    167 37 }
    168 38
     
    172 42
    173 43 foreach my $localfield (keys(%{ $SETS })) {
    174 44 if ($localfield =~ /$pattern/) {
    175 my $imagefield = $1;
    176 $IMAGE->{$imagefield} = $m->comp("/contenido/components/filter.msn", str => $SETS->{$localfield});
    45 my $imagefield = $1;
    46 $IMAGE->{$imagefield} = $m->comp("/contenido/components/filter.msn", str => $SETS->{$localfield});
    177 47 }
    178 48 }
    179 49
    180 50 return $IMAGE;
    51
    181 52 </%init>
  • koi8/core/comps/contenido/components/set_properties.msn

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

     
    112 112 if (not ref $input) {
    113 113 no strict "refs";
    114 114 $fh = &{"Contenido::File::Scheme::".uc(scheme($input))."::get_fh"}($input);
    115 } elsif ((ref $input eq "GLOB") or (ref $input eq 'Apache::Upload') or (ref $input eq 'IO::File')) {
    115 } elsif ( ref $input eq 'Apache::Upload' ) {
    116 $fh = $input->fh;
    117 } elsif ((ref $input eq "GLOB") or (ref $input eq 'IO::File')) {
    116 118 $fh = $input;
    117 119 } elsif (ref $input eq "SCALAR") {
    118 120 $fh = IO::Scalar->new($input);
     
    153 155 # return $dir;
    154 156 # }
    155 157
    158 sub store_image {
    159 my $input = shift;
    160 my (%opts) = @_;
    161 my $object = delete $opts{object} || return;
    162 my $attr = delete $opts{attr} || return;
    163
    164 my ($prop) = grep { $_->{attr} eq $attr } $object->structure;
    165 return unless ref $prop;
    166 my @preview = exists $prop->{'preview'} && ref $prop->{'preview'} eq 'ARRAY' ? @{$prop->{'preview'}} : exists $prop->{'preview'} && $prop->{'preview'} ? ($prop->{'preview'}) : ();
    167 my @crops = exists $prop->{'crop'} && ref $prop->{'crop'} eq 'ARRAY' ? @{$prop->{'crop'}} : exists $prop->{'crop'} && $prop->{'crop'} ? ($prop->{'crop'}) : ();
    168 my @shrinks = exists $prop->{'shrink'} && ref $prop->{'shrink'} eq 'ARRAY' ? @{$prop->{'shrink'}} : exists $prop->{'shrink'} && $prop->{'shrink'} ? ($prop->{'shrink'}) : ();
    169
    170 my $filename = '/images/'.$object->get_file_name() || return;
    171 my $filename_tmp = $state->{'tmp_dir'}.'/'.join('_', split('/', $filename));
    172
    173 my $fh = get_fh($input);
    174 return unless ref $fh;
    175
    176 my $size = (stat $fh)[7];
    177 my $ext;
    178 if ( $opts{filename} ) {
    179 $ext = $opts{filename} =~ /(jpe?g|gif|png)$/i ? lc $1 : 'bin';
    180 } elsif ( not ref $input ) {
    181 $ext = $input =~ /(jpe?g|gif|png)$/i ? lc $1 : 'bin';
    182 } elsif ( ref $input eq 'Apache::Upload' ) {
    183 $ext = $input->filename() =~ /(jpe?g|gif|png)$/i ? lc $1 : 'bin';
    184 }
    185 $ext ||= 'bin';
    186
    187 my $fh_tmp = IO::File->new('>'.$filename_tmp.'.'.$ext) || return;
    188 my $buffer;
    189
    190 sysread $fh, $buffer, $size;
    191 syswrite $fh_tmp, $buffer, $size;
    192
    193 undef $fh_tmp;
    194
    195 my $IMAGE;
    196 if ( store($filename.'.'.$ext, $filename_tmp.'.'.$ext) ) {
    197 $IMAGE = {};
    198 # hashref slice assigning - ������
    199 @{$IMAGE}{'filename', 'width', 'height'} = (
    200 $filename.'.'.$ext,
    201 Image::Size::imgsize($filename_tmp.'.'.$ext),
    202 );
    203
    204 foreach my $suffix (@preview) {
    205 my $c_line = $state->{'convert_binary'}.' -geometry \''.$suffix.'\' -quality 80 '.$filename_tmp.'.'.$ext.' '.$filename_tmp.'.'.$suffix.'.'.$ext;
    206 my $result = `$c_line`;
    207
    208 if (length $result > 0) {
    209 warn 'Contenido Error: ��� ������ "'.$c_line.'" ��������� ������ "'.$result.'" ('.$@.")\n";
    210 return undef;
    211 }
    212 @{$IMAGE->{'mini'}{$suffix}}{'filename', 'width', 'height'} = (
    213 $filename.'.'.$suffix.'.'.$ext,
    214 Image::Size::imgsize($filename_tmp.'.'.$suffix.'.'.$ext),
    215 );
    216 %{$IMAGE->{'resize'}{$suffix}} = %{$IMAGE->{'mini'}{$suffix}};
    217 store($filename.'.'.$suffix.'.'.$ext, $filename_tmp.'.'.$suffix.'.'.$ext);
    218 unlink $filename_tmp.'.'.$suffix.'.'.$ext if -e $filename_tmp.'.'.$suffix.'.'.$ext;
    219 }
    220 if ( @preview ) {
    221 @{$IMAGE->{'mini'}}{'filename', 'width', 'height'} = @{$IMAGE->{'mini'}{$preview[0]}}{'filename', 'width', 'height'};
    222 @{$IMAGE->{'resize'}}{'filename', 'width', 'height'} = @{$IMAGE->{'mini'}{$preview[0]}}{'filename', 'width', 'height'};
    223 }
    224
    225 ########## CROPS
    226 foreach my $suffix (@crops) {
    227
    228 my $shave_string;
    229 my ($nwidth, $nheight) = $suffix =~ /(\d+)x(\d+)/i ? ($1, $2) : (0, 0);
    230 if ( ($IMAGE->{width} / $IMAGE->{height}) > ($nwidth / $nheight) ) {
    231 my $shave_pixels = (($IMAGE->{width} / $IMAGE->{height}) - ($nwidth / $nheight)) * $IMAGE->{height};
    232 $shave_string = ' -shave '.int($shave_pixels / 2).'x0';
    233 } elsif ( ($IMAGE->{height} / $IMAGE->{width}) > ($nheight / $nwidth) ) {
    234 my $shave_pixels = (($IMAGE->{height} / $IMAGE->{width}) - ($nheight / $nwidth)) * $IMAGE->{width};
    235 $shave_string = ' -shave 0x'.int($shave_pixels / 2);
    236 }
    237 if ( $shave_string ) {
    238 my $c_line = $state->{"convert_binary"}." $shave_string $filename_tmp.$ext $filename_tmp.shaved.$ext";
    239 my $result = `$c_line`;
    240 if (length $result > 0) {
    241 print "Contenido Error: ��� ������ '$c_line' ��������� ������ '$result' ($@)\n";
    242 }
    243 } else {
    244 my $c_line = "cp $filename_tmp.$ext $filename_tmp.shaved.$ext";
    245 my $result = `$c_line`;
    246 if (length $result > 0) {
    247 print "Contenido Error: ��� ������ '$c_line' ��������� ������ '$result' ($@)\n";
    248 }
    249 }
    250
    251 my $c_line = $state->{'convert_binary'}.' -geometry \''.$suffix.'!\' -quality 80 '.$filename_tmp.'.shaved.'.$ext.' '.$filename_tmp.'.'.$suffix.'.'.$ext;
    252 my $result = `$c_line`;
    253
    254 if (length $result > 0) {
    255 warn 'Contenido Error: ��� ������ "'.$c_line.'" ��������� ������ "'.$result.'" ('.$@.")\n";
    256 return undef;
    257 }
    258 @{$IMAGE->{'mini'}{$suffix}}{'filename', 'width', 'height'} = (
    259 $filename.'.'.$suffix.'.'.$ext,
    260 Image::Size::imgsize($filename_tmp.'.'.$suffix.'.'.$ext),
    261 );
    262 %{$IMAGE->{'crop'}{$suffix}} = %{$IMAGE->{'mini'}{$suffix}};
    263 store($filename.'.'.$suffix.'.'.$ext, $filename_tmp.'.'.$suffix.'.'.$ext);
    264 unlink $filename_tmp.'.shaved.'.$ext if -e $filename_tmp.'.shaved.'.$ext;
    265 unlink $filename_tmp.'.'.$suffix.'.'.$ext if -e $filename_tmp.'.'.$suffix.'.'.$ext;
    266 }
    267 if ( @crops ) {
    268 if ( !exists $IMAGE->{'mini'}{'filename'} ) {
    269 @{$IMAGE->{'mini'}}{'filename', 'width', 'height'} = @{$IMAGE->{'mini'}{$crops[0]}}{'filename', 'width', 'height'};
    270 }
    271 @{$IMAGE->{'crop'}}{'filename', 'width', 'height'} = @{$IMAGE->{'crop'}{$crops[0]}}{'filename', 'width', 'height'};
    272 }
    273
    274
    275 ########## SHRINKS
    276 foreach my $suffix (@shrinks) {
    277
    278 my $c_line = $state->{'convert_binary'}.' -geometry \''.$suffix.'!\' -quality 80 '.$filename_tmp.'.'.$ext.' '.$filename_tmp.'.'.$suffix.'.'.$ext;
    279 my $result = `$c_line`;
    280
    281 if (length $result > 0) {
    282 warn 'Contenido Error: ��� ������ "'.$c_line.'" ��������� ������ "'.$result.'" ('.$@.")\n";
    283 return undef;
    284 }
    285 @{$IMAGE->{'mini'}{$suffix}}{'filename', 'width', 'height'} = (
    286 $filename.'.'.$suffix.'.'.$ext,
    287 Image::Size::imgsize($filename_tmp.'.'.$suffix.'.'.$ext),
    288 );
    289 %{$IMAGE->{'shrink'}{$suffix}} = %{$IMAGE->{'mini'}{$suffix}};
    290 store($filename.'.'.$suffix.'.'.$ext, $filename_tmp.'.'.$suffix.'.'.$ext);
    291 unlink $filename_tmp.'.'.$suffix.'.'.$ext if -e $filename_tmp.'.'.$suffix.'.'.$ext;
    292 }
    293 if ( @shrinks && !exists $IMAGE->{'mini'}{'filename'} ) {
    294 if ( !exists $IMAGE->{'mini'}{'filename'} ) {
    295 @{$IMAGE->{'mini'}}{'filename', 'width', 'height'} = @{$IMAGE->{'mini'}{$shrinks[0]}}{'filename', 'width', 'height'};
    296 }
    297 @{$IMAGE->{'shrink'}}{'filename', 'width', 'height'} = @{$IMAGE->{'shrink'}{$shrinks[0]}}{'filename', 'width', 'height'};
    298 }
    299
    300 unlink $filename_tmp.'.'.$ext if -e $filename_tmp.'.'.$ext;
    301 }
    302
    303 return $IMAGE;
    304 }
    305
    306 sub remove_image {
    307 my $IMAGE = shift;
    308
    309 if ( ref $IMAGE eq 'HASH' && exists $IMAGE->{filename} ) {
    310 remove($IMAGE->{'filename'}) || return;
    311 }
    312 if ( ref $IMAGE && exists $IMAGE->{mini} && ref $IMAGE->{mini} eq 'HASH' ) {
    313 foreach my $val ( values %{$IMAGE->{mini}} ) {
    314 if ( ref $val && exists $val->{filename} && $val->{filename} ) {
    315 remove($val->{'filename'}) || return;
    316 }
    317 }
    318 }
    319 1;
    320 }
    321
    322
    156 323 1;
  • koi8/core/lib/Contenido/Object.pm

     
    18 18
    19 19 use Utils;
    20 20 use Contenido::Globals;
    21 use Contenido::File;
    21 22 use Data::Dumper;
    22 23
    23 24 use DBD::Pg;
     
    747 748
    748 749 do { $log->warning("����� ������ ->set_link() ��� �������� �������������� ���������-���������"); return undef } unless ($self->id() > 0);
    749 750 do { $log->warning("����� ������ ->set_link() ��� �������� �������������� ���������-����"); return undef } unless ($dest_id >= 0);
    750 do { $log->warning("����� ������ ->set_link() ��� �������� ������ �����"); } unless (defined($lclass) && length($lclass));
    751 do { $log->warning("����� ������ ->set_link() ��� �������� ������ �����"); } unless defined($lclass) && length($lclass);
    751 752
    752 753 # ������� ������ �����...
    753 754 my $link = $lclass->new($self->keeper);
     
    1130 1131 return $_[0]->keeper->state->memcached_object_expire;
    1131 1132 }
    1132 1133
    1134 # ----------------------------------------------------------------------------
    1135 # ����� _image_store() ������� ��������� �������, ����������� � ���� image ��� images
    1136 #
    1137 # ������ �������������:
    1138 # $document->_image_store( INPUT, attr => 'fieldname' )
    1139 # ----------------------------------------------------------------------------
    1140 sub _store_image {
    1141 my $self = shift;
    1142 do { $log->error("����� delete() ����� �������� ������ � ��������, �� �� �������"); die } unless ref($self);
    1143
    1144 my $input = shift;
    1145 my (%opts) = @_;
    1146
    1147 return Contenido::File::store_image( $input, object => $self, attr => $opts{attr} );
    1148 }
    1149
    1150 sub _delete_image {
    1151 my $self = shift;
    1152 my $IMAGE = shift;
    1153
    1154 return Contenido::File::remove_image( $IMAGE );
    1155 }
    1156
    1133 1157 1;
    1134 1158

Небольшая справка по веткам

cnddist – контейнер, в котором хранятся все дистрибутивы всех библиотек и программных пакетов, которые использовались при построении различных версий Contenido. Если какой-то библиотеки в данном хранилище нет, инсталлятор сделает попытку "подтянуть" ее с веба (например, с CPAN). Если библиотека слишком старая, есть очень большая вероятность, что ее там уже нет. Поэтому мы храним весь хлам от всех сборок. Если какой-то дистрибутив вдруг отсутствует в cnddist - напишите нам, мы положим его туда.

koi8 – отмирающая ветка, чей код, выдача и все внутренние библиотеки заточены на кодировку KOI8-R. Вносятся только те дополнения, которые касаются внешнего вида и функционала админки, баги ядра, обязательные обновления портов и мелочи, которые легко скопипастить. В дальнейшем планируется полная остановка поддержки по данной ветке.

utf8 – актуальная ветка, заточенная под UTF-8.

Внутри каждой ветки: core – исходники ядра; install – скрипт установки инсталляции; plugins – плагины; samples – "готовые к употреблению" проекты, которые можно поставить, запустить и посмотреть, как они работают.