Revision 132
- Date:
- 2011/09/01 11:46:10
- Files:
Legend:
- Added
- Removed
- Modified
-
koi8/core/comps/contenido/components/section_browse.msn
174 174 <td nowrap align="right"><% $document->{$col->{attr}} || ' ' %>\ 175 175 % } elsif ($col->{type} eq 'integer') { 176 176 <td align="right"><% $document->{$col->{attr}} %> \ 177 % } elsif ($col->{type} eq 'lookup') { 177 % } elsif ($col->{type} eq 'lookup' || $col->{type} eq 'pickup') { 178 178 <td align="left">\ 179 179 % my $id = $document->{$col->{attr}}; 180 180 % if ($id) { -
koi8/core/comps/contenido/sections.html
293 293 } 294 294 295 295 my %filter=(); 296 my $nothing_found = 0; 296 297 my %order = (not $class and $owner->order_by) ? (order_by => $owner->order_by) : (order => ['date','direct']); 297 298 if (defined $alpha and $alpha ne '') { 298 299 $filter{ilike}=1; … … 313 314 if ( $doc_class ) { 314 315 my @props = $doc_class->new( $keeper )->structure(); 315 316 my ($prop) = grep { $_->{attr} eq $search_by } @props if @props; 316 if ( ref $prop && ($prop->{type} eq 'integer' || $prop->{type} eq 'checkbox') ) { 317 if ( ref $prop && ($prop->{type} eq 'integer' || $prop->{type} eq 'checkbox' || 318 (($prop->{type} eq 'pickup' || $prop->{type} eq 'lookup') && $search =~ /^\d+$/) ) ) { 317 319 $filter{$search_by} = int($search); 320 } elsif ( ref $prop && ($prop->{type} eq 'pickup' || $prop->{type} eq 'lookup') && $search =~ /\D/ ) { 321 my $lookup_opts = $prop->{lookup_opts}; 322 if ( ref $lookup_opts && exists $lookup_opts->{class} ) { 323 my $search_field = exists $lookup_opts->{search_by} ? $lookup_opts->{search_by} : 'name'; 324 my @ids = $keeper->get_documents ( 325 ids => 1, 326 class => $lookup_opts->{class}, 327 ilike => 1, 328 $search_field => '%'.$search.'%', 329 ); 330 if ( @ids ) { 331 $filter{$search_by} = \@ids; 332 } else { 333 $nothing_found = 1; 334 } 335 } 318 336 } else { 319 337 $filter{$search_by}='%'.$search.'%'; 320 338 $filter{ilike} = 1; … … 325 343 } 326 344 } 327 345 328 # �������������� ������� ������� 329 if ($owner->filters) { 330 no strict 'vars'; 331 my $filters = eval($owner->filters); 332 if ($@) { 333 warn "Bad filter: " . $owner->filters . " in section " . $owner->id; 334 } elsif (ref $filters eq 'HASH') { 335 map { $filter{$_} = $filters->{$_} } keys %$filters; 336 } 337 } 346 # �������������� ������� ������� 347 if ($owner->filters) { 348 no strict 'vars'; 349 my $filters = eval($owner->filters); 350 if ($@) { 351 warn "Bad filter: " . $owner->filters . " in section " . $owner->id; 352 } elsif (ref $filters eq 'HASH') { 353 while ( my ($key, $val) = each %$filters ) { 354 $filter{$key} = $val; 355 } 356 } 357 } 338 358 339 359 $total = $keeper->get_documents(%filter, count=>1) unless $owner->no_count; 340 360 … … 342 362 my $first = $n * ($p - 1); 343 363 ($first,$p)=(0,0) if (!$owner->no_count && $first>$total); 344 364 345 if ($class && !$use_section) { 346 @documents = $keeper->get_documents(%filter, %order, limit=>$n, offset=>$first); 347 } elsif ($sorted) { 348 @documents = $keeper->get_sorted_documents(%filter, limit=>$n, offset=>$first); 349 } else { 350 @documents = $keeper->get_documents(%filter, %order, limit=>$n, offset=>$first); 365 unless ( $nothing_found ) { 366 if ($class && !$use_section) { 367 @documents = $keeper->get_documents(%filter, %order, limit=>$n, offset=>$first); 368 } elsif ($sorted) { 369 @documents = $keeper->get_sorted_documents(%filter, limit=>$n, offset=>$first); 370 } else { 371 @documents = $keeper->get_documents(%filter, %order, limit=>$n, offset=>$first); 372 } 351 373 } 352 374 353 375 # ����� ������� ������� ����������... 354 my @columns = $sorted ? ({attr => '_sort_', name => 'N'}) : (); 376 my @columns = $sorted ? ({attr => '_sort_', name => 'N'}) : (); 355 377 356 # �������� ����� �������, ������� �������� ��� ������� �������� (required_properties -> column)... 357 if ($filter{class} or @documents and $documents[0]) { 358 push @columns, 359 sort {$a->{column} <=> $b->{column}} 360 grep {$_->{column}} ($filter{class} ? $filter{class}->new($keeper)->structure : $documents[0]->structure); 361 } 378 # �������� ����� �������, ������� �������� ��� ������� �������� (required_properties -> column)... 379 if ($filter{class} or @documents and $documents[0]) { 380 push @columns, 381 sort {$a->{column} <=> $b->{column}} 382 grep {$_->{column}} ($filter{class} ? $filter{class}->new($keeper)->structure : $documents[0]->structure); 383 } 362 384 363 # ����������� ����� �������... 364 @columns = (@columns, 365 {attr => '_act_', rusname => '��������'}, 366 ); 385 # ����������� ����� �������... 386 @columns = (@columns, 387 {attr => '_act_', rusname => '��������'}, 388 ); 389 367 390 </%init> -
koi8/core/lib/Contenido/File.pm
14 14 15 15 our $IgnoreErrors = 1; 16 16 17 my %translit = ( 18 '�' => 'a', '�' => 'b', '�' => 'v', '�' => 'g', '�' => 'd', '�' => 'e', '�' => 'e', '�' => 'zh', '�' => 'z', '�' => 'i', '�' => 'y', 19 '�' => 'k', '�' => 'l', '�' => 'm', '�' => 'n', '�' => 'o', '�' => 'p', '�' => 'r', '�' => 's', '�' => 't', '�' => 'u', '�' => 'f', '�' => 'h', 20 '�' => 'ts', '�' => '4', '�' => 'sh', '�' => 'sch', '�' => 'y', '�' => 'i', '�' => 'y', '�' => 'e', '�' => 'u', '�' => 'a', '�' => 'A', 21 '�' => 'B', '�' => 'V', '�' => 'G', '�' => 'D', '�' => 'E', '�' => 'E', '�' => 'ZH', '�' => 'Z', '�' => 'I', '�' => 'Y', '�' => 'K', '�' => 'L', 22 '�' => 'M', '�' => 'N', '�' => 'O', '�' => 'P', '�' => 'R', '�' => 'S', '�' => 'T', '�' => 'U', '�' => 'F', '�' => 'H', '�' => 'TS', '�' => '4', 23 '�' => 'SH', '�' => 'SCH', '�' => 'Y', '�' => 'I', '�' => 'Y', '�' => 'E', '�' => 'U', '�' => 'YA', 24 ); 25 26 17 27 sub fetch { 18 28 my $filename = shift || return; 19 29 my $fh; … … 337 347 return unless ref $prop; 338 348 339 349 my $filename = '/binary/'.$object->get_file_name() || return; 350 if ( $prop->{softrename} ) { 351 my $oid = $object->id || int(rand(10000)); 352 my $orig_name = ''; 353 if ( ref $input eq 'Apache::Upload' ) { 354 $orig_name = $input->filename(); 355 } elsif ( !ref $input ) { 356 $orig_name = $input; 357 } 358 if ( $orig_name ) { 359 if ( $orig_name =~ /\\([^\\]+)$/ ) { 360 $orig_name = $1; 361 } elsif ( $orig_name =~ /\/([^\/]+)$/ ) { 362 $orig_name = $1; 363 } 364 $orig_name =~ s/[\ \t]/_/g; 365 $orig_name = $oid.'_'.$orig_name; 366 $filename =~ s/\/([^\/]+)$//; 367 my $fname = $1; 368 unless ( $orig_name =~ /^[a-zA-Z_\d\.\-\,]+$/ ) { 369 $orig_name = translit( $orig_name ); 370 } 371 warn "\n\n\n\n\nNew Name: [$orig_name]\n\n\n\n\n" if $DEBUG; 372 unless ( $orig_name =~ /^[a-zA-Z_\d\.\-\,]+$/ ) { 373 $orig_name = $fname; 374 } 375 $filename .= '/'.$orig_name; 376 $filename =~ s/\.([^\.]+)$//; 377 } 378 } 379 340 380 my $filename_tmp = $state->{'tmp_dir'}.'/'.join('_', split('/', $filename)); 341 381 342 382 my $fh = get_fh($input); … … 345 385 my $ext; 346 386 my $size = 1073741824; 347 387 if ( not ref $input ) { 348 $ext = $input =~ /(jpe?g|gif|png)$/i ? lc $1 : 'bin'; 388 $ext = $input =~ /\.([^\.]+)$/ ? lc($1) : 'bin'; 349 389 if ( scheme($input) eq 'file' ) { 350 390 $size = (stat $fh)[7]; 351 391 } 352 392 } elsif ( ref $input eq 'Apache::Upload' ) { 353 $ext = $input->filename() =~ /(jpe?g|gif|png)$/i ? lc $1 : 'bin'; 393 $ext = $input->filename() =~ /\.([^\.]+)$/ ? lc($1) : 'bin'; 354 394 $size = (stat $fh)[7]; 355 395 } elsif ( $opts{filename} ) { 356 $ext = $opts{filename} =~ /(jpe?g|gif|png)$/i ? lc $1 : 'bin'; 396 $ext = $opts{filename} =~ /\.([^\.]+)$/ ? lc($1) : 'bin'; 357 397 } 358 398 if ( ref $fh eq 'IO::Scalar' ) { 359 399 $size = length("$fh"); … … 370 410 371 411 my $BINARY; 372 412 if ( store($filename.'.'.$ext, $filename_tmp.'.'.$ext) ) { 373 $BINARY = { filename => $filename.'.'.$ext }; 413 @{$BINARY}{"filename", "ext", "size"} = ( 414 $filename.".".$ext, $ext, $size 415 ); 416 374 417 unlink $filename_tmp.'.'.$ext if -e $filename_tmp.'.'.$ext; 418 419 if ( $ext =~ /(rar|7z|zip|arc|lha|arj|cab)/ ) { 420 $BINARY->{type} = 'archive'; 421 } elsif ( $ext =~ /(doc|rtf)/ ) { 422 $BINARY->{type} = 'doc'; 423 } elsif ( $ext eq 'xls' ) { 424 $BINARY->{type} = 'xls'; 425 } elsif ( $ext =~ /(mdb|ppt)/ ) { 426 $BINARY->{type} = 'msoffice'; 427 } elsif ( $ext =~ /(pdf)/ ) { 428 $BINARY->{type} = 'ebook'; 429 } elsif ( $ext eq 'psd' ) { 430 $BINARY->{type} = 'psd'; 431 } elsif ( $ext =~ /(exe|msi|cab)/ ) { 432 $BINARY->{type} = 'executable'; 433 } else { 434 $BINARY->{type} = 'unknown'; 435 } 436 375 437 } 376 438 377 439 return $BINARY; … … 388 450 } 389 451 390 452 453 sub translit { 454 my $str = shift; 455 my @str = split (//, $str); 456 my $res = ''; 457 while ( scalar @str ) { 458 my $alpha = shift @str; 459 if ( exists $translit{$alpha} ) { 460 $res .= $translit{$alpha}; 461 } else { 462 $res .= $alpha; 463 } 464 } 465 return $res; 466 } 467 468 391 469 1;