X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FTemplate%2FOpenDocument.pm;h=12a7bc8c58d78fcf3e53ae76204099c0c5a55d87;hb=438c47c01070704b143a79c9c0ea7a1512736eff;hp=d0753a5ab46043dae537a5d0ef5b84d27dd5c127;hpb=0fba3edda47fca21bedb14eb88e0f5f8d983bb38;p=kivitendo-erp.git diff --git a/SL/Template/OpenDocument.pm b/SL/Template/OpenDocument.pm index d0753a5ab..12a7bc8c5 100644 --- a/SL/Template/OpenDocument.pm +++ b/SL/Template/OpenDocument.pm @@ -1,10 +1,10 @@ package SL::Template::OpenDocument; -use SL::Template::Simple; +use parent qw(SL::Template::Simple); use Archive::Zip; +use Encode; use POSIX 'setsid'; -use vars qw(@ISA); use SL::Iconv; @@ -14,8 +14,6 @@ use Cwd; # use File::Temp qw(:mktemp); use IO::File; -@ISA = qw(SL::Template::Simple); - use strict; sub new { @@ -24,7 +22,7 @@ sub new { my $self = $type->SUPER::new(@_); $self->{"rnd"} = int(rand(1000000)); - $self->{"iconv"} = SL::Iconv->new($main::dbcharset, "UTF-8"); + $self->{"iconv"} = SL::Iconv->new($::lx_office_conf{system}->{dbcharset}, "UTF-8"); $self->set_tag_style('<%', '%>'); $self->{quot_re} = '"'; @@ -39,7 +37,7 @@ sub parse_foreach { my $ary = $self->_get_loop_variable($var, 1, @indices); - for (my $i = 0; $i < scalar(@{$ary}); $i++) { + for (my $i = 0; $i < scalar(@{$ary || []}); $i++) { $form->{"__first__"} = $i == 0; $form->{"__last__"} = ($i + 1) == scalar(@{$ary}); $form->{"__odd__"} = (($i + 1) % 2) == 1; @@ -112,21 +110,27 @@ sub parse_block { $contents =~ m|^(.*?)(]*>)|; my $table_row = $1; my $end_tag = $2; - substr($contents, 0, length($1) + length($end_tag)) = ""; if ($table_row =~ m|\<\%foreachrow\s+(.*?)\%\>|) { my $var = $1; - substr($table_row, length($`), length($&)) = ""; + $contents =~ m|\<\%foreachrow\s+.*?\%\>|; + substr($contents, length($`), length($&)) = ""; - my ($t1, $t2) = $self->find_end($table_row, length($`)); - if (!$t1) { + ($table_row, $contents) = $self->find_end($contents, length($`)); + if (!$table_row) { $self->{"error"} = "Unclosed <\%foreachrow\%>." unless ($self->{"error"}); $main::lxdebug->leave_sub(); return undef; } - my $new_text = $self->parse_foreach($var, $t1 . $t2, $tag, $end_tag, @indices); + $contents =~ m|^(.*?)(]*>)|; + $table_row .= $1; + $end_tag = $2; + + substr $contents, 0, length($&), ''; + + my $new_text = $self->parse_foreach($var, $table_row, $tag, $end_tag, @indices); if (!defined($new_text)) { $main::lxdebug->leave_sub(); return undef; @@ -134,6 +138,7 @@ sub parse_block { $new_contents .= $new_text; } else { + substr($contents, 0, length($table_row) + length($end_tag)) = ""; my $new_text = $self->parse_block($table_row, @indices); if (!defined($new_text)) { $main::lxdebug->leave_sub(); @@ -224,7 +229,7 @@ sub parse { return 0; } - my $contents = $zip->contents("content.xml"); + my $contents = Encode::decode('utf-8-strict', $zip->contents("content.xml")); if (!$contents) { $self->{"error"} = "File is not a OpenDocument file."; $main::lxdebug->leave_sub(); @@ -263,7 +268,7 @@ sub parse { # $new_contents =~ s|>|>\n|g; - $zip->contents("content.xml", $new_contents); + $zip->contents("content.xml", Encode::encode('utf-8-strict', $new_contents)); my $styles = $zip->contents("styles.xml"); if ($contents) { @@ -377,14 +382,14 @@ sub spawn_xvfb { my $pid = fork(); if (0 == $pid) { $main::lxdebug->message(LXDebug->DEBUG2(), " Child execing\n"); - exec($main::xvfb_bin, $display, "-screen", "0", "640x480x8", "-nolisten", "tcp"); + exec($::lx_office_conf{applications}->{xvfb}, $display, "-screen", "0", "640x480x8", "-nolisten", "tcp"); } sleep(3); $main::lxdebug->message(LXDebug->DEBUG2(), " parent dont sleeping\n"); local *OUT; my $dfname = $self->{"userspath"} . "/xvfb_display"; - if (!open(OUT, ">$dfname")) { + if (!open(OUT, ">", $dfname)) { $self->{"error"} = "Conversion to PDF failed because OpenOffice could not be started ($dfname: $!)"; unlink($xauthority); kill($pid); @@ -414,7 +419,8 @@ sub spawn_xvfb { sub is_openoffice_running { $main::lxdebug->enter_sub(); - my $output = `./scripts/oo-uno-test-conn.py $main::openofficeorg_daemon_port 2> /dev/null`; + my $cmd = "./scripts/oo-uno-test-conn.py " . $::lx_office_conf{print_templates}->{openofficeorg_daemon_port} . " 2> /dev/null"; + my $output = `$cmd`; chomp $output; my $res = ($? == 0) || $output; @@ -452,11 +458,11 @@ sub spawn_openoffice { exit if ($new_pid); my $ssres = setsid(); $main::lxdebug->message(LXDebug->DEBUG2(), " Child execing\n"); - my @cmdline = ($main::openofficeorg_writer_bin, + my @cmdline = ($::lx_office_conf{applications}->{openofficeorg_writer}, "-minimized", "-norestore", "-nologo", "-nolockcheck", "-headless", "-accept=socket,host=localhost,port=" . - $main::openofficeorg_daemon_port . ";urp;"); + $::lx_office_conf{print_templates}->{openofficeorg_daemon_port} . ";urp;"); exec(@cmdline); } @@ -503,8 +509,8 @@ sub convert_to_pdf { } my @cmdline; - if (!$main::openofficeorg_daemon) { - @cmdline = ($main::openofficeorg_writer_bin, + if (!$::lx_office_conf{print_templates}->{openofficeorg_daemon}) { + @cmdline = ($::lx_office_conf{applications}->{openofficeorg_writer}, "-minimized", "-norestore", "-nologo", "-nolockcheck", "-headless", "file:${filename}.odt", @@ -517,7 +523,7 @@ sub convert_to_pdf { } @cmdline = ("./scripts/oo-uno-convert-pdf.py", - $main::openofficeorg_daemon_port, + $::lx_office_conf{print_templates}->{openofficeorg_daemon_port}, "${filename}.odt"); }