Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision f3d322cf

Von Moritz Bunkus vor mehr als 17 Jahren hinzugefügt

  • ID f3d322cfd7776bebb922f3cd390bd62e4f5baf09
  • Vorgänger b5157f97
  • Nachfolger ba863fd6

Filehandles als lokal deklarieren; Kosmetik; Argumente für open() bereinigen.

Unterschiede anzeigen:

SL/DN.pm
500 500

  
501 501
  my ($myconfig, $form, $userspath, $string) = @_;
502 502

  
503
  local (*IN, *OUT);
504

  
503 505
  my $format = $form->{format};
504 506
  $form->{format} = "html";
505 507

  
506 508
  $tmpstring = "parse_string.html";
507 509
  $tmpfile = "$myconfig->{templates}/$tmpstring";
508
  open(OUT, ">$tmpfile") or $form->error("$tmpfile : $!");
510
  open(OUT, ">", $tmpfile) or $form->error("$tmpfile : $!");
511

  
509 512
  print(OUT $string);
510 513
  close(OUT);
511 514

  
......
515 518

  
516 519
  my $fileid = time;
517 520
  $form->{tmpfile} = "$userspath/${fileid}.$tmpstring";
518
  $out = $form->{OUT};
519
  $form->{OUT} = ">$form->{tmpfile}";
520 521

  
521
  if ($form->{OUT}) {
522
    open(OUT, "$form->{OUT}") or $form->error("$form->{OUT} : $!");
523
  }
522
  open(OUT, ">", $form->{tmpfile}) or $form->error("$form->{OUT} : $!");
524 523
  if (!$template->parse(*OUT)) {
525 524
    $form->cleanup();
526 525
    $form->error("$form->{IN} : " . $template->get_error());
......
528 527

  
529 528
  close(OUT);
530 529
  my $result = "";
531
  open(IN, $form->{tmpfile}) or $form->error($form->cleanup . "$form->{tmpfile} : $!");
530
  open(IN, "<", $form->{tmpfile}) or $form->error($form->cleanup . "$form->{tmpfile} : $!");
532 531

  
533 532
  while (<IN>) {
534 533
    $result .= $_;
......
550 549

  
551 550
  my ($self, $myconfig, $form, $userspath) = @_;
552 551

  
553
  foreach my $file (@{ $form->{DUNNING_PDFS} }) {
554
    $inputfiles .= " $userspath/$file ";
555
  }
552
  local (*IN, *OUT);
553

  
554
  # Don't allow access outside of $userspath.
555
  map { $_ =~ s|.*/||; } @{ $form->{DUNNING_PDFS} };
556 556

  
557
  my $inputfiles = join " ", map { "$userspath/$_" } @{ $form->{DUNNING_PDFS} };
557 558
  my $outputfile = "$userspath/dunning.pdf";
559

  
558 560
  system("gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=$outputfile $inputfiles");
559
  foreach my $file (@{ $form->{DUNNING_PDFS} }) {
560
    unlink("$userspath/$file");
561
  }
562
  $out = "";
563 561

  
564
  $form->{OUT} = $out;
562
  map { unlink("$userspath/$_") } @{ $form->{DUNNING_PDFS} };
565 563

  
566 564
  my $numbytes = (-s $outputfile);
567
  open(IN, $outputfile)
568
    or $form->error($self->cleanup . "$outputfile : $!");
565
  open(IN, $outputfile) || $form->error($self->cleanup() . "$outputfile : $!");
569 566

  
570 567
  $form->{copies} = 1 unless $form->{media} eq 'printer';
571 568

  
572
  chdir("$self->{cwd}");
569
  chdir($self->{cwd});
573 570

  
574 571
  for my $i (1 .. $form->{copies}) {
575
    if ($form->{OUT}) {
576
      open(OUT, $form->{OUT})
577
        or $form->error($form->cleanup . "$form->{OUT} : $!");
578
    } else {
579

  
580
      # launch application
581
      print qq|Content-Type: Application/PDF
572
    # launch application
573
    print qq|Content-Type: Application/PDF
582 574
Content-Disposition: attachment; filename="$outputfile"
583 575
Content-Length: $numbytes
584 576

  
585 577
|;
586 578

  
587
      open(OUT, ">-") or $form->error($form->cleanup . "$!: STDOUT");
588

  
589
    }
579
    open(OUT, ">-") or $form->error($form->cleanup . "$!: STDOUT");
590 580

  
591 581
    while (<IN>) {
592 582
      print OUT $_;
......
598 588
  }
599 589

  
600 590
  close(IN);
601
  unlink("$userspath/$outputfile");
591
  unlink($outputfile);
602 592

  
603 593
  $main::lxdebug->leave_sub();
604 594
}

Auch abrufbar als: Unified diff