1 package SL::Template::Plugin::HTMLFixes;
 
   3 use Template::Plugin::HTML;
 
   8 package Template::Plugin::HTML;
 
  14 # Replacement for Template::Plugin::HTML::url.
 
  16 # Strings in kivitendo are stored in Perl's internal encoding but have
 
  17 # to be output as UTF-8. A normal regex replace doesn't do that
 
  18 # creating invalid UTF-8 characters upon URL-unescaping.
 
  20 # The only addition is the "Encode::encode()" line.
 
  21 no warnings 'redefine';
 
  23     my ($self, $text) = @_;
 
  24     return undef unless defined $text;
 
  25     $text =  Encode::encode('utf-8-strict', $text);
 
  26     $text =~ s/([^a-zA-Z0-9_.-])/uc sprintf("%%%02x",ord($1))/eg;
 
  32 package Template::Stash;
 
  34 # A method for forcing list context. If a method uses 'wantarray' then
 
  35 # calling that method from Template will do strange stuff like chosing
 
  36 # scalar context. The most obvious offender are RDBO relationships.
 
  38 # Example of how NOT to test whether or not a customer has contacts:
 
  39 #   [% IF customer.contacts.size %] ...
 
  40 # Instead force list context and then test the size:
 
  41 #   [% IF customer.contacts.as_list.size %] ...
 
  42 $Template::Stash::LIST_OPS->{ as_list } = sub {
 
  43   return ref( $_[0] ) eq 'ARRAY' ? shift : [shift];