X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FTemplate%2FOpenDocument.pm;h=a90a9aeea89ff164f263ea038c693a9e360f0664;hb=fb0e4cdd31e9d04adfd5cad1193a92782eadda7c;hp=2ed3c60fa89db36100ff2bf0c1c47050a2ac8ba2;hpb=4c19594dc3035082cf79a81b285000f419429624;p=kivitendo-erp.git diff --git a/SL/Template/OpenDocument.pm b/SL/Template/OpenDocument.pm index 2ed3c60fa..a90a9aeea 100644 --- a/SL/Template/OpenDocument.pm +++ b/SL/Template/OpenDocument.pm @@ -22,7 +22,6 @@ sub new { my $self = $type->SUPER::new(@_); $self->{"rnd"} = int(rand(1000000)); - $self->{"iconv"} = SL::Iconv->new($main::dbcharset, "UTF-8"); $self->set_tag_style('<%', '%>'); $self->{quot_re} = '"'; @@ -37,7 +36,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; @@ -260,7 +259,14 @@ sub parse { $contents =~ s||${new_styles}|; $contents =~ s|[\n\r]||gm; - my $new_contents = $self->parse_block($contents); + my $new_contents; + if ($self->{use_template_toolkit}) { + my $additional_params = $::form; + + $::form->init_template->process(\$contents, $additional_params, \$new_contents) || die $::form->template->error; + } else { + $new_contents = $self->parse_block($contents); + } if (!defined($new_contents)) { $main::lxdebug->leave_sub(); return 0; @@ -270,14 +276,14 @@ sub parse { $zip->contents("content.xml", Encode::encode('utf-8-strict', $new_contents)); - my $styles = $zip->contents("styles.xml"); + my $styles = Encode::decode('utf-8-strict', $zip->contents("styles.xml")); if ($contents) { my $new_styles = $self->parse_block($styles); if (!defined($new_contents)) { $main::lxdebug->leave_sub(); return 0; } - $zip->contents("styles.xml", $new_styles); + $zip->contents("styles.xml", Encode::encode('utf-8-strict', $new_styles)); } $zip->writeToFileNamed($form->{"tmpfile"}, 1); @@ -382,14 +388,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); @@ -416,10 +422,21 @@ sub spawn_xvfb { return $display; } +sub _run_python_uno { + my ($self, @args) = @_; + + local $ENV{PYTHONPATH}; + $ENV{PYTHONPATH} = $::lx_office_conf{environment}->{python_uno_path} . ':' . $ENV{PYTHONPATH} if $::lx_office_conf{environment}->{python_uno_path}; + my $cmd = $::lx_office_conf{applications}->{python_uno} . ' ' . join(' ', @args); + return `$cmd`; +} + sub is_openoffice_running { + my ($self) = @_; + $main::lxdebug->enter_sub(); - my $output = `./scripts/oo-uno-test-conn.py $main::openofficeorg_daemon_port 2> /dev/null`; + my $output = $self->_run_python_uno('./scripts/oo-uno-test-conn.py', $::lx_office_conf{print_templates}->{openofficeorg_daemon_port}, ' 2> /dev/null'); chomp $output; my $res = ($? == 0) || $output; @@ -446,10 +463,19 @@ sub spawn_openoffice { last; } + if ($::dispatcher->interface_type eq 'FastCGI') { + $::dispatcher->{request}->Detach; + } + if (!$spawned_oo) { my $pid = fork(); if (0 == $pid) { $main::lxdebug->message(LXDebug->DEBUG2(), " Child daemonizing\n"); + + if ($::dispatcher->interface_type eq 'FastCGI') { + $::dispatcher->{request}->Finish; + $::dispatcher->{request}->LastCall; + } chdir('/'); open(STDIN, '/dev/null'); open(STDOUT, '>/dev/null'); @@ -457,12 +483,17 @@ 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); + } else { + # parent + if ($::dispatcher->interface_type eq 'FastCGI') { + $::dispatcher->{request}->Attach; + } } $main::lxdebug->message(LXDebug->DEBUG2(), " Parent after fork\n"); @@ -507,27 +538,20 @@ sub convert_to_pdf { return 0; } - my @cmdline; - if (!$main::openofficeorg_daemon) { - @cmdline = ($main::openofficeorg_writer_bin, - "-minimized", "-norestore", "-nologo", "-nolockcheck", - "-headless", - "file:${filename}.odt", - "macro://" . (split('/', $filename))[-1] . - "/Standard.Conversion.ConvertSelfToPDF()"); + if (!$::lx_office_conf{print_templates}->{openofficeorg_daemon}) { + system($::lx_office_conf{applications}->{openofficeorg_writer}, + "-minimized", "-norestore", "-nologo", "-nolockcheck", "-headless", + "file:${filename}.odt", + "macro://" . (split('/', $filename))[-1] . "/Standard.Conversion.ConvertSelfToPDF()"); } else { if (!$self->spawn_openoffice()) { $main::lxdebug->leave_sub(); return 0; } - @cmdline = ("./scripts/oo-uno-convert-pdf.py", - $main::openofficeorg_daemon_port, - "${filename}.odt"); + $self->_run_python_uno('./scripts/oo-uno-convert-pdf.py', $::lx_office_conf{print_templates}->{openofficeorg_daemon_port}, "${filename}.odt"); } - system(@cmdline); - my $res = $?; if ((0 == $?) || (-f "${filename}.pdf" && -s "${filename}.pdf")) { $form->{"tmpfile"} =~ s/odt$/pdf/; @@ -550,7 +574,6 @@ sub convert_to_pdf { sub format_string { my ($self, $variable) = @_; my $form = $self->{"form"}; - my $iconv = $self->{"iconv"}; $variable = $main::locale->quote_special_chars('Template/OpenDocument', $variable); @@ -566,7 +589,7 @@ sub format_string { $variable =~ s|\</${key}\>||gi; } - return $iconv->convert($variable); + return $variable; } sub get_mime_type() {