summaryrefslogtreecommitdiff
path: root/LedgerSMB/Template
diff options
context:
space:
mode:
authortetragon <tetragon@4979c152-3d1c-0410-bac9-87ea11338e46>2007-10-18 23:00:16 +0000
committertetragon <tetragon@4979c152-3d1c-0410-bac9-87ea11338e46>2007-10-18 23:00:16 +0000
commit152171006218a1ecfbaf567c8e20ce854d09c613 (patch)
tree9bc582016d826ed17f57ba24504493059f3e8d15 /LedgerSMB/Template
parent9bfd772f2b58e5e236e6b81912f2a683b5d8207d (diff)
Some template handling tweaking to allow for escaping scalar references
git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@1788 4979c152-3d1c-0410-bac9-87ea11338e46
Diffstat (limited to 'LedgerSMB/Template')
-rwxr-xr-xLedgerSMB/Template/CSV.pm12
-rwxr-xr-xLedgerSMB/Template/HTML.pm6
-rwxr-xr-xLedgerSMB/Template/LaTeX.pm16
-rw-r--r--LedgerSMB/Template/ODS.pm3
-rwxr-xr-xLedgerSMB/Template/TXT.pm3
-rw-r--r--LedgerSMB/Template/XLS.pm8
6 files changed, 41 insertions, 7 deletions
diff --git a/LedgerSMB/Template/CSV.pm b/LedgerSMB/Template/CSV.pm
index 9700a18a..50edef15 100755
--- a/LedgerSMB/Template/CSV.pm
+++ b/LedgerSMB/Template/CSV.pm
@@ -38,6 +38,9 @@ holders, see the CONTRIBUTORS file.
package LedgerSMB::Template::CSV;
+use warnings;
+use strict;
+
use Error qw(:try);
use Template;
use LedgerSMB::Template::TTI18N;
@@ -54,12 +57,17 @@ sub preprocess {
#XXX fix escaping function
return $rawvars if $type =~ /^LedgerSMB::Locale/;
+ return unless defined $rawvars;
if ( $type eq 'ARRAY' ) {
for (@{$rawvars}) {
push @{$vars}, preprocess( $_ );
}
- } elsif ( !$type ) { # Scalar
- $vars = $rawvars;
+ } elsif ( !$type or $type eq 'SCALAR' ) { # Scalar
+ if ($type eq 'SCALAR' ) {
+ $vars = $$rawvars;
+ } else {
+ $vars = $rawvars;
+ }
$vars =~ s/(^ +| +$)//g;
$vars =~ s/"/""/g;
$vars = qq|"$vars"| if $vars !~ /^\w*$/;
diff --git a/LedgerSMB/Template/HTML.pm b/LedgerSMB/Template/HTML.pm
index 340b6c94..9159098e 100755
--- a/LedgerSMB/Template/HTML.pm
+++ b/LedgerSMB/Template/HTML.pm
@@ -39,6 +39,9 @@ holders, see the CONTRIBUTORS file.
package LedgerSMB::Template::HTML;
+use warnings;
+use strict;
+
use Error qw(:try);
use CGI::Simple::Standard qw(:html);
use Template;
@@ -56,12 +59,15 @@ sub preprocess {
#XXX fix escaping function
return $rawvars if $type =~ /^LedgerSMB::Locale/;
+ return unless defined $rawvars;
if ( $type eq 'ARRAY' ) {
for (@{$rawvars}) {
push @{$vars}, preprocess( $_ );
}
} elsif (!$type) {
return escapeHTML($rawvars);
+ } elsif ($type eq 'SCALAR') {
+ return escapeHTML($$rawvars);
} else { # Hashes and objects
for ( keys %{$rawvars} ) {
$vars->{preprocess($_)} = preprocess( $rawvars->{$_} );
diff --git a/LedgerSMB/Template/LaTeX.pm b/LedgerSMB/Template/LaTeX.pm
index 06c4b8c4..973cb724 100755
--- a/LedgerSMB/Template/LaTeX.pm
+++ b/LedgerSMB/Template/LaTeX.pm
@@ -47,6 +47,9 @@ holders, see the CONTRIBUTORS file.
package LedgerSMB::Template::LaTeX;
+use warnings;
+use strict;
+
use Error qw(:try);
use Template::Latex;
use LedgerSMB::Template::TTI18N;
@@ -62,15 +65,20 @@ sub preprocess {
my $type = ref $rawvars;
return $rawvars if $type =~ /^LedgerSMB::Locale/;
+ return unless defined $type;
if ($type eq 'ARRAY') {
for (@{$rawvars}) {
push @{$vars}, preprocess($_);
}
- } elsif (!$type) {
+ } elsif (!$type or $type eq 'SCALAR') {
+ if ($type eq 'SCALAR') {
+ $vars = $$rawvars;
+ } else {
+ $vars = $rawvars;
+ }
#XXX Fix escaping
- $rawvars =~ s/([&\$\\_<>~^#\%\{\}])/\\$1/g;
- $rawvars =~ s/"(.*)"/``$1''/gs;
- return $rawvars;
+ $vars =~ s/([&\$\\_<>~^#\%\{\}])/\\$1/g;
+ $vars =~ s/"(.*)"/``$1''/gs;
} else {
for ( keys %{$rawvars} ) {
$vars->{$_} = preprocess($rawvars->{$_});
diff --git a/LedgerSMB/Template/ODS.pm b/LedgerSMB/Template/ODS.pm
index 08df87a7..f3a37583 100644
--- a/LedgerSMB/Template/ODS.pm
+++ b/LedgerSMB/Template/ODS.pm
@@ -800,12 +800,15 @@ sub preprocess {
#XXX fix escaping function
return $rawvars if $type =~ /^LedgerSMB::Locale/;
+ return unless defined $rawvars;
if ( $type eq 'ARRAY' ) {
for (@{$rawvars}) {
push @{$vars}, preprocess( $_ );
}
} elsif (!$type) {
return escapeHTML($rawvars);
+ } elsif ($type eq 'SCALAR') {
+ return escapeHTML($$rawvars);
} else { # Hashes and objects
for ( keys %{$rawvars} ) {
$vars->{preprocess($_)} = preprocess( $rawvars->{$_} );
diff --git a/LedgerSMB/Template/TXT.pm b/LedgerSMB/Template/TXT.pm
index d6fa3e4b..66169613 100755
--- a/LedgerSMB/Template/TXT.pm
+++ b/LedgerSMB/Template/TXT.pm
@@ -38,6 +38,9 @@ holders, see the CONTRIBUTORS file.
package LedgerSMB::Template::TXT;
+use warnings;
+use strict;
+
use Error qw(:try);
use Template;
use LedgerSMB::Template::TTI18N;
diff --git a/LedgerSMB/Template/XLS.pm b/LedgerSMB/Template/XLS.pm
index 5e03c7c9..acb8196e 100644
--- a/LedgerSMB/Template/XLS.pm
+++ b/LedgerSMB/Template/XLS.pm
@@ -48,6 +48,9 @@ holders, see the CONTRIBUTORS file.
package LedgerSMB::Template::XLS;
+use warnings;
+use strict;
+
use Error qw(:try);
use CGI::Simple::Standard qw(:html);
use Excel::Template::Plus;
@@ -65,12 +68,15 @@ sub preprocess {
#XXX fix escaping function
return $rawvars if $type =~ /^LedgerSMB::Locale/;
+ return $rawvars unless defined $rawvars;
if ( $type eq 'ARRAY' ) {
for (@{$rawvars}) {
push @{$vars}, preprocess( $_ );
}
} elsif (!$type) {
return escapeHTML($rawvars);
+ } elsif ($type eq 'SCALAR') {
+ return escapeHTML($$rawvars);
} else { # Hashes and objects
for ( keys %{$rawvars} ) {
$vars->{preprocess($_)} = preprocess( $rawvars->{$_} );
@@ -110,7 +116,7 @@ sub process {
);
$template->write_file("$parent->{outputfile}.xls");
- parent->{mimetype} = 'application/vnd.ms-excel';
+ $parent->{mimetype} = 'application/vnd.ms-excel';
}
sub postprocess {