Apache-PageKit
view release on metacpan or search on metacpan
lib/Apache/PageKit/View.pm view on Meta::CPAN
sub _include_components {
my ($view, $page_id, $html_code_ref, $pkit_view) = @_;
if ( $view->{relaxed_parser} eq 'yes' ) {
$$html_code_ref =~ s%<(!--)?\s*PKIT_COMPONENT($key_value_pattern+)\s*/?(?(1)--)?>(?:<(!--)?\s*/PKIT_COMPONENT\s*(?(1)--)>)?%get_component($page_id,$2,$view,$pkit_view)%eig;
} else {
$$html_code_ref =~ s%<\s*PKIT_COMPONENT($key_value_pattern+)\s*/?>(<\s*/PKIT_COMPONENT\s*>)?%&get_component($page_id,$1,$view,$pkit_view)%eig;
}
sub get_component {
my ($page_id, $params, $view, $pkit_view) = @_;
my %params = ();
while($params =~ m!$key_value_pattern!ig) {
$params{uc($2)} = $+;
}
my $component_id = delete $params{NAME} or die qq{component item "NAME=..." not found};
unless($component_id =~ s!^/!!){
# relative component, component relative to page_id
(my $page_id_dir = $page_id) =~ s![^/]*$!!;
$component_id = $page_id_dir . $component_id;
while ($component_id =~ s![^/]*/\.\./!!) {};
}
my $cid_key = join '', $component_id, sort %params;
unless ( $view->{component_ids_hash}->{$cid_key}++ ) {
push @{ $view->{component_ids} }, [ $component_id , \%params ];
}
# check for recursive pkit_components
if($view->{component_ids_hash}->{$cid_key} > 100){
die "Likely recursive PKIT_COMPONENTS for component_id $component_id and giving up.";
}
my $template_ref = $view->_load_component($page_id, $component_id, $pkit_view, \%params);
return $$template_ref;
}
}
sub _is_record_uptodate {
my ($view, $record, $pkit_view, $page_id) = @_;
# first check timestamps
my $include_mtimes = $record->{include_mtimes};
while (my ($filename, $cache_mtime) = each %$include_mtimes){
# check if file still exists
unless(-f "$filename"){
return 0;
}
# check if file is up to date
my $file_mtime = (stat($filename))[9];
# print "hi $filename - $cache_mtime - $file_mtime<br>";
if($file_mtime != $cache_mtime){
return 0;
}
if($filename =~ m!^$view->{view_dir}/Default/! && $pkit_view ne 'Default'){
# check to see if any new files have been uploaded to the $pkit_view dir
(my $check_filename = $filename) =~ s!^$view->{view_dir}/Default/!$view->{view_dir}/$pkit_view/!;
if (-f "$check_filename"){
return 0;
}
}
}
# record up to date!
return 1;
}
# here the usage of "component" also includes page
sub _load_component {
my ($view, $page_id, $component_id, $pkit_view, $component_params) = @_;
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 TEMPLATE, "<$template_file" or die "can not read $template_file";
binmode TEMPLATE;
local($/) = undef;
my $template = <TEMPLATE>;
close TEMPLATE;
# expand PKIT_MACRO tags
$template =~ s!<\s*PKIT_MACRO$key_value_pattern\s*/?>!$component_params->{uc($+)} || ''!egi;
$template_ref = \$template;
my $mtime = (stat(_))[9];
$view->{include_mtimes}->{$template_file} = $mtime;
}
if($view->{can_edit} eq 'yes'){
Apache::PageKit::Edit::add_component_edit_stubs($view, $page_id, $template_ref, $pkit_view);
}
$view->_include_components($page_id,$template_ref,$pkit_view);
return $template_ref;
}
sub _load_page {
my ($view, $page_id, $pkit_view) = @_;
$Apache::PageKit::Content::PAGE_ID_XSL_PARAMS->{$page_id} = {};
my $content = $view->{content} ||= Apache::PageKit::Content->new(
content_dir => $view->{content_dir},
view_dir => $view->{view_dir},
default_lang => $view->{default_lang},
relaxed_parser => $view->{relaxed_parser},
template_class => $view->{template_class},
);
( run in 0.936 second using v1.01-cache-2.11-cpan-b16cb0d3907 )