Apache2-PageKit

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

		section of Config.xml. Defaults to yes.
		( Boris Zentner, Shimon Rura )
	- Adjust Makefile.PL to support ExtUtils::MakeMaker > 6.21
		( Boris Zentner, Mike Castle )
1.16
	- Fix: Use Apache::ServerRec and Apache::ServerUtil in 
		Apache::ErrorReport ( Boris Zentner )
	! The param method returns a empty list in list context if 
		the param was not defined. Older PageKits returned undef
		( Boris Zentner )
	- Fix: add missing : in binmode $fh, ":encoding(...)";
		( Boris Zentner )
	- Fix: typo in scripts/pkit_rename_app.pl ( Boris Zentner )
1.15
	- Add: request_class parameter just for the case, that you like 
		another class or subclass do what Apache::Request do for
		you. Defaults to Apache::Request::PageKit
		( Boris Zentner )
	- Fix: conversion error if the tmpl file's encoding is != utf8 
		and no content_var's are used. affects only perl < 5.8.0
		( Boris Zentner )

lib/Apache2/PageKit.pm  view on Meta::CPAN


  $model_base_class->pkit_startup($pkit_root, $server, $config)
    if $model_base_class->can('pkit_startup');
}

# object oriented method call, see Eagle p.65
sub handler : method {
  my ( $class, $requestrec ) =  @_ ;
  my ($pk, $model, $status_code);

  binmode STDOUT;
  $| = 1;

  eval {
    $pk = $class->new( $requestrec );
    $model = $pk->{model};
    my $apr = $pk->{apr};
    my $view = $pk->{view};
    my $config = $pk->{config};
    $status_code = $pk->prepare_page;
    my $use_template = $config->get_page_attr($pk->{page_id},'use_template') || 'yes' if ($status_code eq OK);

lib/Apache2/PageKit.pm  view on Meta::CPAN

    
    my $fop_command = $config->get_server_attr('fop_command') 
      || $config->get_global_attr('fop_command');

    if ( $fop_command ) {
      # write output_media to file, using process number of Apache child process
      my $view_cache_dir = $view->{cache_dir};
      my $fo_file = "$view_cache_dir/$$.fo";
      my $pdf_file = "$view_cache_dir/$$.pdf";
      open FO_TEMPLATE, ">$fo_file" or die "can't open file: $fo_file ($!)";
      binmode FO_TEMPLATE;
      print FO_TEMPLATE $$output_ref;
      close FO_TEMPLATE;
      
      #   my $error_message = `$fop_command $fo_file $pdf_file 2>&1 1>/dev/null`;
      my $error_message = `$fop_command $fo_file $pdf_file 2>&1`;

      ## the recommended fop converter has no usefull error messages.
      ## the errormoessages go also to STDOUT
      ## and the returncode is always 0
      unless ($error_message =~ /^\[ERROR\]:/m){
        local $/;
        open PDF_OUTPUT, "<$pdf_file" or die "can't open file: $pdf_file ($!)";
        binmode PDF_OUTPUT;
        $$output_ref = <PDF_OUTPUT>;
        close PDF_OUTPUT;
      } 
      else {
        die "Error processing template with Apache XML FOP: $error_message";
      }
    }
  } else {
    # just set content_type but it is already $output_media
    ;

lib/Apache2/PageKit/Config.pm  view on Meta::CPAN

  $page_attr->{$config_dir}    = {};
  $user_attr->{$config_dir}    = {};
  $view_attr->{$config_dir}    = {};
  $uri_match->{$config_dir}    = {};

  my $parser = XML::LibXML->new;

  # this open close hack is needed. oherwise XML::LibXML sometimes likes to open with the
  # handlers we set in Content.pm! So we use parse_fh instead of parse_file.
  open CFH, "<$config_dir/Config.xml" or die $!;
  binmode CFH;
  my $dom  = $parser->parse_fh(\*CFH);
  close CFH;

  my $root = $dom->getDocumentElement;

  #search for the following nodes ...
  my %subs = (
    GLOBAL             => \&GLOBAL,
    USER               => \&USER,
    'SERVERS/SERVER'   => \&SERVER,

lib/Apache2/PageKit/Content.pm  view on Meta::CPAN


sub match_uri {
  my $uri = shift;
  return $uri !~ /(^\w+:)|(catalog$)/;
}

sub open_uri {
  my $uri = shift;
  my $abs_uri = _rel2abs($uri);
  open my $xml, "$abs_uri" or die "XML file $abs_uri doesn't exist";
  binmode $xml;
  local($/) = undef;
  my $xml_str = <$xml>;
  close $xml;
  my $mtime = (stat(_))[9];
  $INCLUDE_MTIMES->{$abs_uri} = $mtime;

  # we avoid to use any XML::LibXML parser inside the callbackroutines.

  return $xml_str;
}

lib/Apache2/PageKit/Edit.pm  view on Meta::CPAN

  my $file = $model->input('file') || die "No input filename!";

  $model->output(file => $file);

  $file = _build_path( $model->pkit_root, $file ) || die "Illegal input chars ($file)" ;

  $model->output( read_only => 1 ) if ( ! -w $file );

  my $default_input_charset = $model->{pkit_pk}->{view}->{default_input_charset};
  open my $fh, $file or die $!;
  binmode $fh, ":encoding($default_input_charset)";
  local $/;

# we need to escape HTML tags to avoid </textarea>
# my $content = Apache2::Util::escape_html(<PAGE> || "");
  my $content = <$fh>;
  close $fh;

  # we need to escape all & chars so that for example &nbsp; is
  # &nbsp; and not ' ' 
  #<textarea> holds #PCDATA

lib/Apache2/PageKit/Edit.pm  view on Meta::CPAN

  }

  my $file = $model->input('file') || die "No input filename!";
  $file = _build_path( $model->pkit_root, $file ) || die "Illegal input chars ($file)" ;

  my $pkit_done = $model->input('pkit_done');
  my $content = $model->input('content');

  my $default_input_charset = $model->{pkit_pk}->{view}->{default_input_charset};
  open my $fh, ">$file" or die $!;
  binmode $fh, ":encoding($default_input_charset)";
  print $fh $content;
  close $fh;

  if($pkit_done){
    $model->pkit_redirect($pkit_done);
  }
}

sub add_edit_links {
  my ($view, $record, $output_ref) = @_;

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

sub get_static_gzip {
  my ($view, $filename) = @_;
  my ($gzip_mtime, $gzipped_content);

  (my $relative_filename = $filename) =~ s!^$view->{view_dir}/!!;
  my $gzipped_filename = "$view->{cache_dir}/$relative_filename.gz";

  # is the cache entry valid or changed on disc?
  if(-f "$gzipped_filename"){
    open my $fh, "<$gzipped_filename" or return undef;
    binmode $fh;
    # read mtime from first line
    chomp($gzip_mtime = <$fh>);

    # read rest of gzipped content
    local $/;
    $gzipped_content = <$fh>;
    close $fh;
    if($view->{reload} ne 'no'){
      # is the cache entry valid or changed on disc?
      my $mtime = ( stat($filename) )[9];

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

  return 1 if $view->_find_template($pkit_view,$page_id);
}

# private methods

# creates gzipped file
sub _create_static_zip {
  my ($view, $filename, $gzipped_filename) = @_;
  local $/;
  open my $fh, "<$filename" or return undef;
  binmode $fh;
  my $content = <$fh>;
  close $fh;

  $view->_html_clean(\$content);

  my $gzipped_content = Compress::Zlib::memGzip($content);

  (my $gzipped_dir = $gzipped_filename) =~ s!(/)?[^/]*?$!!;

  File::Path::mkpath("$gzipped_dir");

  if ($gzipped_content) {
    my $mtime = (stat($filename))[9];
    if ( open my $gzip_fh, ">$gzipped_filename" ) {
      binmode $gzip_fh;
      print $gzip_fh "$mtime\n";
      print $gzip_fh $gzipped_content;
      close $gzip_fh;
    } else {
      warn "can not create gzip cache file $view->{cache_dir}/$gzipped_filename: $!";
    }
    return $gzipped_content;
  }
  return undef;
}

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

  my $template_file = $view->_find_template($pkit_view, $component_id);
  my $template_ref;

  unless($template_file){
    # no template file exists, attempt to generate from XML and XSL files
    # currently only XML::LibXSLT is supported
    $template_ref = $view->{content}->generate_template($page_id, $component_id, $pkit_view, $view->{input_param_object}, $component_params);
  } else {
      open my $template_fh, "<$template_file" or die "can not read $template_file";
      my $default_input_charset = $view->{default_input_charset};
      binmode $template_fh, ":encoding($default_input_charset)";
      local $/;
      my $template = <$template_fh>;
      close $template_fh;

    # expand PKIT_MACRO tags
    $template =~ s!<\s*PKIT_MACRO$key_value_pattern\s*/?>!$component_params->{uc($+)} || ''!egi;

    $template_ref = \$template;

    my $mtime = (stat(_))[9];



( run in 0.400 second using v1.01-cache-2.11-cpan-8d75d55dd25 )