diff options
author | tetragon <tetragon@4979c152-3d1c-0410-bac9-87ea11338e46> | 2007-10-18 23:00:16 +0000 |
---|---|---|
committer | tetragon <tetragon@4979c152-3d1c-0410-bac9-87ea11338e46> | 2007-10-18 23:00:16 +0000 |
commit | 152171006218a1ecfbaf567c8e20ce854d09c613 (patch) | |
tree | 9bc582016d826ed17f57ba24504493059f3e8d15 | |
parent | 9bfd772f2b58e5e236e6b81912f2a683b5d8207d (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
-rwxr-xr-x | LedgerSMB/Template.pm | 9 | ||||
-rwxr-xr-x | LedgerSMB/Template/CSV.pm | 12 | ||||
-rwxr-xr-x | LedgerSMB/Template/HTML.pm | 6 | ||||
-rwxr-xr-x | LedgerSMB/Template/LaTeX.pm | 16 | ||||
-rw-r--r-- | LedgerSMB/Template/ODS.pm | 3 | ||||
-rwxr-xr-x | LedgerSMB/Template/TXT.pm | 3 | ||||
-rw-r--r-- | LedgerSMB/Template/XLS.pm | 8 |
7 files changed, 47 insertions, 10 deletions
diff --git a/LedgerSMB/Template.pm b/LedgerSMB/Template.pm index 8c302e91..5248ab78 100755 --- a/LedgerSMB/Template.pm +++ b/LedgerSMB/Template.pm @@ -120,6 +120,9 @@ your software. package LedgerSMB::Template; +use warnings; +use strict; + use Error qw(:try); use LedgerSMB::Sysconfig; use LedgerSMB::Mailer; @@ -164,9 +167,9 @@ sub new { throw Error::Simple "Invalid format"; } if (!$self->{include_path}){ -## SC: hardcoding due to config migration -## $self->{include_path} = $self->{'myconfig'}->{'templates'}; - $self->{include_path} = 'templates/demo'; +## SC: XXX hardcoding due to config migration, will need adjustment + $self->{include_path} = $self->{'myconfig'}->{'templates'}; + $self->{include_path} ||= 'templates/demo'; if (defined $self->{language}){ if (!$self->_valid_language){ throw Error::Simple 'Invalid language'; 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 { |