Apache-PageKit

 view release on metacpan or  search on metacpan

lib/Apache/PageKit/View.pm  view on Meta::CPAN

	} ^seig;

    $$html_code_ref =~
      s%<PKIT_SELFURL$key_value_pattern?/?>% &process_selfurl_tag($exclude_params_set, $3 || $4 || $5 || $2 ) %seig;

    $$html_code_ref =~ s%</PKIT_(VIEW|IS_ERROR|NOT_ERROR|MESSAGES|HAVE_MESSAGES|HAVE_NOT_MESSAGES)>%    $replace_end_tags{uc($1)}   %seig;
    $$html_code_ref =~ s%<PKIT_(MESSAGES|IS_ERROR|NOT_ERROR|HAVE_MESSAGES|HAVE_NOT_MESSAGES)>%          $replace_start_tags{uc($1)}%seig;
    $$html_code_ref =~ s%<PKIT_(HOSTNAME|MESSAGE|ERRORSTR|REALURL)/?>%$replace_start_tags{uc($1)}%seig;

    $$html_code_ref =~
      s^<PKIT_VIEW$key_value_pattern/?>^ sprintf '<TMPL_IF NAME="PKIT_VIEW:%s">', $3 || $4 || $5 || $2; ^sieg; #"
  }

  my @a = keys %$exclude_params_set;
  return \@a;

  sub process_selfurl_tag {
    my ( $exclude_params_set, $exclude_params ) = @_;
    $exclude_params = defined($exclude_params) ? join ( " ", sort split ( /\s+/, $exclude_params ) ) : "";
    $exclude_params_set->{$exclude_params} = 1;
    return qq{<TMPL_VAR NAME="pkit_selfurl$exclude_params">};
  }
}

1;

package Apache::PageKit::View::TT2;

use strict;
#use vars qw /@ISA $key_value_pattern %replace_start_tags %replace_end_tags/;
our (@ISA, $key_value_pattern, %replace_start_tags, %replace_end_tags);
@ISA = 'Apache::PageKit::View';

*key_value_pattern = \$Apache::PageKit::View::key_value_pattern;

%replace_start_tags = (
                            MESSAGES          => '[% FOREACH pkit_messages %]',
                            IS_ERROR          => '[% IF pkit_is_error %]',
                            NOT_ERROR         => '[% UNLESS pkit_is_error %]',
                            HAVE_MESSAGES     => '[% IF pkit_messages %]',
                            HAVE_NOT_MESSAGES => '[% UNLESS pkit_messages %]',
                            HOSTNAME          => '[% pkit_hostname %]',
                            MESSAGE           => '[% pkit_message %]',
                            ERRORSTR          => '[% pkit_errorstr %]',
                            REALURL           => '[% pkit_realurl %]',
);
%replace_end_tags = (
                          VIEW              => '[% END %]',
                          IS_ERROR          => '[% END %]',
                          NOT_ERROR         => '[% END %]',
                          HAVE_MESSAGES     => '[% END %]',
                          HAVE_NOT_MESSAGES => '[% END %]',
                          MESSAGES          => '[% END %]'
);


sub new {
  require Template;
  require Template::Parser;
  require Template::Context;
  return shift->SUPER::new(@_);
}

sub fill_in_view {
  my ($view) = @_;

  # load record containing Template Toolkit object
  my $record = $view->{record};

  my %tt_params;

  # Fill in (compiled) <PKIT_SELFURL> tags
  my $exclude_params_set = $record->{exclude_params_set};
  if ( $exclude_params_set && @$exclude_params_set ) {
    my $input_param_object = $view->{input_param_object};
    my $orig_uri           = $input_param_object->notes->get('orig_uri');
    foreach my $exclude_params (@$exclude_params_set) {
      my @exclude_params = split ( " ", $exclude_params );
      my $query_string = Apache::PageKit::params_as_string( $input_param_object, \@exclude_params );

      #remove empty parameters as arised from http://ka.zyx.de/galerie?show=abc& or <PKIT_SELFURL>
      $query_string =~ s![?&]$!!;
      if ($query_string) {
        $tt_params{"pkit_selfurl$exclude_params"} = ( $orig_uri . '?' . $query_string ) . '&';
      }
      else {
        $tt_params{"pkit_selfurl$exclude_params"} = $orig_uri . '?';
      }
    }
  }

  # fill in data from associated objects (for example from the Apache request
  # object if $apr is set
  foreach my $object ( @{ $view->{associated_objects} } ) {
    foreach my $key ( $object->param ) {  
      $view->{pkit_pk}->{browser_cache} = 'no';
      # we need a separate variable for value to force scalar context
      # for multivalued params http://www.xx.yy/a?foo=12&foo=13
      my $value = $object->param($key);
      $tt_params{$key} = $value;
    }
  }

  # finally, we use the $output_param_object object to fill in template
  # get params from $view object
  # note that in this case we allow for MODEL_LOOPs as well as MODEL_VARs
  my $output_param_object = $view->{output_param_object};
  foreach my $key ( $output_param_object->param ) {
    my $value = $output_param_object->param($key);
    $view->{pkit_pk}->{browser_cache} = 'no';
    $tt_params{$key} = $value;
  }

  my $output = Template::Context->new->process(Template::Document->new( $record->{filtered_html} ), \%tt_params );

  if ( $record->{has_form} ) {

    # if fillinform_objects is set, then we use that to fill in any HTML
    # forms in the template.
    my $fif;
    if ( @{ $view->{fillinform_objects} } ) {



( run in 0.843 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )