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} = '"';
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;
$contents =~ s|</office:automatic-styles>|${new_styles}</office:automatic-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;
$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);
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);
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;
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');
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");
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/;
sub format_string {
my ($self, $variable) = @_;
my $form = $self->{"form"};
- my $iconv = $self->{"iconv"};
$variable = $main::locale->quote_special_chars('Template/OpenDocument', $variable);
$variable =~ s|\</${key}\>|</text:span>|gi;
}
- return $iconv->convert($variable);
+ return $variable;
}
sub get_mime_type() {