X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=inline;f=SL%2FTemplate%2FOpenDocument.pm;h=e57032189d597125c6f0c91f427848b9468c7026;hb=661febc70d58eb13923455512e8d76f1ef29ae60;hp=85184c01986ff6b0f9971258967af27830081f1b;hpb=a4c6c83d27a9613e0fec95159988d16cdbe2782d;p=kivitendo-erp.git
diff --git a/SL/Template/OpenDocument.pm b/SL/Template/OpenDocument.pm
index 85184c019..e57032189 100644
--- a/SL/Template/OpenDocument.pm
+++ b/SL/Template/OpenDocument.pm
@@ -70,30 +70,50 @@ my %html_replace = (
sub _format_html {
my ($self, $content, %params) = @_;
- $content =~ s{ ^
|
$ }{}gx;
- $content =~ s{ \r+ }{}gx;
- $content =~ s{ \n+ }{ }gx;
- $content =~ s{ (?:\ |\s)+ }{ }gx;
-
- my $in_p = 1;
- my $p_start_tag = qq||;
- my $ul_start_tag = qq||;
- my $ol_start_tag = qq||;
- my $ul_li_start_tag = qq||;
- my $ol_li_start_tag = qq||;
+ my $in_p = 0;
+ my $p_start_tag = qq||;
+ my $prefix = '';
+ my $suffix = '';
+
+ my (@tags_to_open, @tags_to_close);
+ for (my $idx = scalar(@{ $self->{tag_stack} }) - 1; $idx >= 0; --$idx) {
+ my $tag = $self->{tag_stack}->[$idx];
+
+ next if $tag =~ m{/>$};
+ last if $tag =~ m{^}{>};
+ $prefix .= '' . substr($tag, 1);
+ }
+ }
+
+ $content =~ s{ ^ |
$ }{}gx if $in_p;
+ $content =~ s{ \r+ }{}gx;
+ $content =~ s{ \n+ }{ }gx;
+ $content =~ s{ (?:\ |\s)+ }{ }gx;
+
+ my $ul_start_tag = qq||;
+ my $ol_start_tag = qq||;
+ my $ul_li_start_tag = qq||;
+ my $ol_li_start_tag = qq||;
my @parts = map {
if (substr($_, 0, 1) eq '<') {
s{ +}{}g;
if ($_ eq '') {
$in_p--;
- '';
+ $in_p == 0 ? '' : '';
} elsif ($_ eq '') {
- if (!$in_p) {
- $in_p = 1;
- $p_start_tag;
- }
+ $in_p++;
+ $in_p == 1 ? $p_start_tag : '';
} elsif ($_ eq '
') {
$self->{used_list_styles}->{itemize}->{$self->{current_text_style}} = 1;
@@ -114,10 +134,9 @@ sub _format_html {
}
} split(m{(<.*?>)}x, $content);
- my $out = join('', @parts);
- $out .= $p_start_tag if !$in_p;
+ my $out = join('', $prefix, @parts, $suffix);
- # $::lxdebug->message(0, "out $out");
+ # $::lxdebug->dump(0, "prefix parts suffix", [ $prefix, join('', @parts), $suffix ]);
return $out;
}
@@ -210,12 +229,14 @@ sub parse_block {
while ($contents ne "") {
if (substr($contents, 0, 1) eq "<") {
- $contents =~ m|^<[^>]+>|;
- my $tag = $&;
- substr($contents, 0, length($&)) = "";
+ $contents =~ m|^(<[^>]+>)|;
+ my $tag = $1;
+ substr($contents, 0, length($1)) = "";
$self->{current_text_style} = $1 if $tag =~ m|text:style-name\s*=\s*"([^"]+)"|;
+ push @{ $self->{tag_stack} }, $tag;
+
if ($tag =~ m|]*>)|;
my $table_row = $1;
@@ -224,10 +245,10 @@ sub parse_block {
if ($table_row =~ m|\<\%foreachrow\s+(.*?)\%\>|) {
my $var = $1;
- $contents =~ m|\<\%foreachrow\s+.*?\%\>|;
- substr($contents, length($`), length($&)) = "";
+ $contents =~ m|^(.*?)(\<\%foreachrow\s+.*?\%\>)|;
+ substr($contents, length($1), length($2)) = "";
- ($table_row, $contents) = $self->find_end($contents, length($`));
+ ($table_row, $contents) = $self->find_end($contents, length($1));
if (!$table_row) {
$self->{"error"} = "Unclosed <\%foreachrow\%>." unless ($self->{"error"});
$main::lxdebug->leave_sub();
@@ -238,7 +259,7 @@ sub parse_block {
$table_row .= $1;
$end_tag = $2;
- substr $contents, 0, length($&), '';
+ substr $contents, 0, length($1) + length($2), '';
my $new_text = $self->parse_foreach($var, $table_row, $tag, $end_tag, @indices);
if (!defined($new_text)) {
@@ -261,9 +282,14 @@ sub parse_block {
$new_contents .= $tag;
}
+ if ($tag =~ m{^ | />$}x) {
+ # $::lxdebug->message(0, "popping top tag is $tag top " . $self->{tag_stack}->[-1]);
+ pop @{ $self->{tag_stack} };
+ }
+
} else {
- $contents =~ /^[^<]+/;
- my $text = $&;
+ $contents =~ /^([^<]+)/;
+ my $text = $1;
my $pos_if = index($text, '<%if');
my $pos_foreach = index($text, '<%foreach');
@@ -278,15 +304,15 @@ sub parse_block {
$new_contents .= $self->substitute_vars(substr($contents, 0, $pos_foreach), @indices);
substr($contents, 0, $pos_foreach) = "";
- if ($contents !~ m|^\<\%foreach (.*?)\%\>|) {
+ if ($contents !~ m|^(\<\%foreach (.*?)\%\>)|) {
$self->{"error"} = "Malformed <\%foreach\%>.";
$main::lxdebug->leave_sub();
return undef;
}
- my $var = $1;
+ my $var = $2;
- substr($contents, 0, length($&)) = "";
+ substr($contents, 0, length($1)) = "";
my $block;
($block, $contents) = $self->find_end($contents);
@@ -356,8 +382,9 @@ sub parse {
if ($self->{use_template_toolkit}) {
my $additional_params = $::form;
- $::form->init_template->process(\$contents, $additional_params, \$new_contents) || die $::form->template->error;
+ $::form->template->process(\$contents, $additional_params, \$new_contents) || die $::form->template->error;
} else {
+ $self->{tag_stack} = [];
$new_contents = $self->parse_block($contents);
}
if (!defined($new_contents)) {
@@ -483,7 +510,9 @@ sub spawn_xvfb {
$main::lxdebug->message(LXDebug->DEBUG2(), " xauthority $xauthority\n");
- system("xauth add \"${display}\" . \"${mcookie}\"");
+ if (system("xauth add \"${display}\" . \"${mcookie}\"") == -1) {
+ die "system call to xauth failed: $!";
+ }
if ($? != 0) {
$self->{"error"} = "Conversion to PDF failed because OpenOffice could not be started (xauth: $!)";
$main::lxdebug->leave_sub();
@@ -646,10 +675,12 @@ sub convert_to_pdf {
}
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()");
+ if (system($::lx_office_conf{applications}->{openofficeorg_writer},
+ "-minimized", "-norestore", "-nologo", "-nolockcheck", "-headless",
+ "file:${filename}.odt",
+ "macro://" . (split('/', $filename))[-1] . "/Standard.Conversion.ConvertSelfToPDF()") == -1) {
+ die "system call to $::lx_office_conf{applications}->{openofficeorg_writer} failed: $!";
+ }
} else {
if (!$self->spawn_openoffice()) {
$main::lxdebug->leave_sub();