Revision 129
- Date:
- 2011/08/27 12:01:02
- Files:
Legend:
- Added
- Removed
- Modified
-
koi8/core/comps/contenido/components/set_multimedia_new.msn
1 <%once> 2 3 my %translit = ( 4 '�' => 'a', 5 '�' => 'b', 6 '�' => 'v', 7 '�' => 'g', 8 '�' => 'd', 9 '�' => 'e', 10 '�' => 'e', 11 '�' => 'zh', 12 '�' => 'z', 13 '�' => 'i', 14 '�' => 'y', 15 '�' => 'k', 16 '�' => 'l', 17 '�' => 'm', 18 '�' => 'n', 19 '�' => 'o', 20 '�' => 'p', 21 '�' => 'r', 22 '�' => 's', 23 '�' => 't', 24 '�' => 'u', 25 '�' => 'f', 26 '�' => 'h', 27 '�' => 'ts', 28 '�' => '4', 29 '�' => 'sh', 30 '�' => 'sch', 31 '�' => 'y', 32 '�' => 'i', 33 '�' => 'y', 34 '�' => 'e', 35 '�' => 'u', 36 '�' => 'a', 37 '�' => 'A', 38 '�' => 'B', 39 '�' => 'V', 40 '�' => 'G', 41 '�' => 'D', 42 '�' => 'E', 43 '�' => 'E', 44 '�' => 'ZH', 45 '�' => 'Z', 46 '�' => 'I', 47 '�' => 'Y', 48 '�' => 'K', 49 '�' => 'L', 50 '�' => 'M', 51 '�' => 'N', 52 '�' => 'O', 53 '�' => 'P', 54 '�' => 'R', 55 '�' => 'S', 56 '�' => 'T', 57 '�' => 'U', 58 '�' => 'F', 59 '�' => 'H', 60 '�' => 'TS', 61 '�' => '4', 62 '�' => 'SH', 63 '�' => 'SCH', 64 '�' => 'Y', 65 '�' => 'I', 66 '�' => 'Y', 67 '�' => 'E', 68 '�' => 'U', 69 '�' => 'YA', 70 ); 71 72 </%once> 73 1 <%args> 74 2 75 3 $SETS => undef … … 81 9 </%args> 82 10 <%init> 83 11 84 use IO::File; 85 86 12 return undef unless defined $SETS and defined $field; 87 13 #use vars qw($keeper); 88 14 … … 91 17 92 18 my $BINARY = $default; 93 19 94 if ($SETS->{$field}) { 95 my $filename = "/binary/".$object->get_file_name() || return; 96 my $upload = $r->upload($field); 97 if ( $prop->{softrename} ) { 98 my $oid = $object->id || int(rand(10000)); 99 my $orig_name = $upload->filename(); 100 if ( $orig_name =~ /\\([^\\]+)$/ ) { 101 $orig_name = $1; 102 } elsif ( $orig_name =~ /\/([^\/]+)$/ ) { 103 $orig_name = $1; 104 } 105 $orig_name =~ s/[\ \t]/_/g; 106 $orig_name = $oid.'_'.$orig_name; 107 $filename =~ s/\/([^\/]+)$//; 108 my $fname = $1; 109 unless ( $orig_name =~ /^[a-zA-Z_\d\.\-\,]+$/ ) { 110 $orig_name = $m->comp('.translit', str => $orig_name); 111 } 112 warn "\n\n\n\n\nNew Name: [$orig_name]\n\n\n\n\n"; 113 unless ( $orig_name =~ /^[a-zA-Z_\d\.\-\,]+$/ ) { 114 $orig_name = $fname; 115 } 116 $filename .= '/'.$orig_name; 117 $filename =~ s/\.([^\.]+)$//; 20 if ($SETS->{$field} || $SETS->{"$field.ext_url"}) { 21 22 my $upload; 23 if ( $SETS->{$field} ) { 24 $upload = $r->upload($field); 25 } elsif ( $SETS->{"$field.ext_url"} && $SETS->{"$field.ext_url"} =~ /^(http|https|ftp):\/\/.*/ ) { 26 $upload = $SETS->{"$field.ext_url"}; 118 27 } 119 my $filename_tmp = $state->{"tmp_dir"}."/".join("_", split("/", $filename)); 28 if ($upload) { 120 29 121 my $suffix = $upload->filename() =~ /\.([^\.]+)$/ ? lc($1) : 'bin'; 122 my $fh = $upload->fh(); 123 my $size = (stat $fh)[7]; 30 my $BIN = $object->_store_binary( $upload, attr => $prop->{attr} ); 124 31 125 my $fh_tmp = IO::File->new(">".$filename_tmp.".".$suffix) || die "Can't open temporary file"; 32 if ( ref $BIN eq 'HASH' && exists $BIN->{filename} ) { 33 $object->_delete_binary( $default ); 34 %$BINARY = %$BIN; 35 } 126 36 127 my $buffer; 128 129 $size = sysread $fh, $buffer, $size; 130 syswrite $fh_tmp, $buffer, $size; 131 132 undef $fh_tmp; 133 134 if (Contenido::File::store($filename.".".$suffix, $filename_tmp.".".$suffix)) { 135 if (ref $BINARY eq "HASH" and $BINARY->{"filename"}) { 136 Contenido::File::remove($BINARY->{"filename"}); 137 } 138 139 @{$BINARY}{"filename", "ext", "size"} = ( 140 $filename.".".$suffix, 141 $suffix, 142 $size 143 ); 37 } else { 38 warn 'ERROR in incoming POST form: "'.$field.' is not file upload (value: "'.$SETS->{$field}.'")'; 144 39 } 145 40 146 unlink $filename_tmp.".".$suffix if -e $filename_tmp.".".$suffix; 147 if ( $suffix =~ /(rar|7z|zip|arc|lha|arj|cab)/ ) { 148 $BINARY->{type} = 'archive'; 149 } elsif ( $suffix =~ /(doc|rtf)/ ) { 150 $BINARY->{type} = 'doc'; 151 } elsif ( $suffix eq 'xls' ) { 152 $BINARY->{type} = 'xls'; 153 } elsif ( $suffix =~ /(mdb|ppt)/ ) { 154 $BINARY->{type} = 'msoffice'; 155 } elsif ( $suffix =~ /(pdf)/ ) { 156 $BINARY->{type} = 'ebook'; 157 } elsif ( $suffix eq 'psd' ) { 158 $BINARY->{type} = 'psd'; 159 } elsif ( $suffix =~ /(exe|msi|cab)/ ) { 160 $BINARY->{type} = 'executable'; 161 } else { 162 $BINARY->{type} = 'unknown'; 163 } 164 41 } 165 42 166 43 # �������������� ���� - ����� ���, ��� ������... … … 169 46 170 47 foreach my $localfield (keys(%{ $SETS })) { 171 48 if ($localfield =~ /$pattern/) { 172 my $imagefield = $1; 173 $BINARY->{$imagefield} = $m->comp("/contenido/components/filter.msn", str => $SETS->{$localfield}); 49 my $imagefield = $1; 50 $BINARY->{$imagefield} = $m->comp("/contenido/components/filter.msn", str => $SETS->{$localfield}); 174 51 } 175 52 } 176 53 177 54 return $BINARY; 178 55 179 56 </%init> 180 181 182 <%def .translit> 183 <%args> 184 $str => undef 185 </%args> 186 <%init> 187 188 my @str = split (//, $str); 189 my $res = ''; 190 while ( scalar @str ) { 191 my $alpha = shift @str; 192 if ( exists $translit{$alpha} ) { 193 $res .= $translit{$alpha}; 194 } else { 195 $res .= $alpha; 196 } 197 } 198 return $res; 199 200 </%init> 201 </%def> -
utf8/core/comps/contenido/components/set_multimedia_new.msn
1 <%once> 2 3 my %translit = ( 4 'а' => 'a', 5 'б' => 'b', 6 'в' => 'v', 7 'г' => 'g', 8 'д' => 'd', 9 'е' => 'e', 10 'ё' => 'e', 11 'ж' => 'zh', 12 'з' => 'z', 13 'и' => 'i', 14 'й' => 'y', 15 'к' => 'k', 16 'л' => 'l', 17 'м' => 'm', 18 'н' => 'n', 19 'о' => 'o', 20 'п' => 'p', 21 'р' => 'r', 22 'с' => 's', 23 'т' => 't', 24 'у' => 'u', 25 'ф' => 'f', 26 'х' => 'h', 27 'ц' => 'ts', 28 'ч' => '4', 29 'ш' => 'sh', 30 'щ' => 'sch', 31 'ъ' => 'y', 32 'ы' => 'i', 33 'ь' => 'y', 34 'э' => 'e', 35 'ю' => 'u', 36 'я' => 'a', 37 'А' => 'A', 38 'Б' => 'B', 39 'В' => 'V', 40 'Г' => 'G', 41 'Д' => 'D', 42 'Е' => 'E', 43 'Ё' => 'E', 44 'Ж' => 'ZH', 45 'З' => 'Z', 46 'И' => 'I', 47 'Й' => 'Y', 48 'К' => 'K', 49 'Л' => 'L', 50 'М' => 'M', 51 'Н' => 'N', 52 'О' => 'O', 53 'П' => 'P', 54 'Р' => 'R', 55 'С' => 'S', 56 'Т' => 'T', 57 'У' => 'U', 58 'Ф' => 'F', 59 'Х' => 'H', 60 'Ц' => 'TS', 61 'Ч' => '4', 62 'Ш' => 'SH', 63 'Щ' => 'SCH', 64 'Ъ' => 'Y', 65 'Ы' => 'I', 66 'Ь' => 'Y', 67 'Э' => 'E', 68 'Ю' => 'U', 69 'Я' => 'YA', 70 ); 71 72 </%once> 73 1 <%args> 74 2 75 3 $SETS => undef … … 126 54 return $BINARY; 127 55 128 56 </%init> 129 130 131 <%def .translit> 132 <%args> 133 $str => undef 134 </%args> 135 <%init> 136 137 my @str = split (//, $str); 138 my $res = ''; 139 while ( scalar @str ) { 140 my $alpha = shift @str; 141 if ( exists $translit{$alpha} ) { 142 $res .= $translit{$alpha}; 143 } else { 144 $res .= $alpha; 145 } 146 } 147 return $res; 148 149 </%init> 150 </%def>