Apache-PageKit
view release on metacpan or search on metacpan
lib/Apache/PageKit.pm view on Meta::CPAN
$pk->{browser_cache} = 'no';
} else {
# display login page with error message
$pk->{page_id} = $config->get_global_attr('login_page');
$model->pkit_gettext_message('Cookies must be enabled in your browser.', is_error => 1);
}
}
my $require_login = $config->get_page_attr($pk->{page_id},'require_login');
if(defined($require_login) && $require_login =~ /^(yes|recent)$/){
# this page requires that the user has a valid cookie
$pk->{page_id} = $config->get_global_attr('login_page');
# do NOT cache this page other wise we end up on the loginpage instead of the page we want
$pk->{browser_cache} = 'no';
$output_param_object->param("pkit_done",$uri_with_query) unless $apr->param("pkit_done");
$model->pkit_gettext_message('This page requires a login.');
}
}
$model->pkit_common_code if $model->can('pkit_common_code');
if ( $static_file{name} ) {
if ( $pk->{page_id} eq $static_file{page_id} ) {
# page_id is the same as we tested already (this may save some stat calls)
return $pk->_send_static_file($static_file{name});
} elsif ( my $filename = $pk->static_page_exists($pk->{page_id}) ) {
return $pk->_send_static_file($filename);
}
}
# run the page code!
$pk->page_code;
# check for the statuscode that can be set with $model->pkit_status_code
return $pk->{status_code} if ( defined $pk->{status_code} );
# add pkit_message from previous page, if that pagekit did a pkit_redirect
if(my @pkit_messages = $apr->param('pkit_messages')){
for my $message (@pkit_messages){
$model->pkit_message($message);
}
}
if(my @pkit_error_messages = $apr->param('pkit_error_messages')){
for my $message (@pkit_error_messages){
$model->pkit_message($message, is_error => 1);
}
}
# deal with different views
if(my $pkit_view = $apr->param('pkit_view')){
$output_param_object->param('pkit_view:' . $pkit_view => 1);
}
return OK;
}
sub _send_static_file {
my ( $pk, $filename ) = @_;
my $apr = $pk->{apr};
my $file_mtime = (stat($filename))[9];
my $ims = $apr->header_in('If-Modified-Since');
if ( $ims ) {
my $t = Apache::Util::parsedate($ims);
if ( $t && $file_mtime <= $t ) {
return HTTP_NOT_MODIFIED;
}
}
$apr->header_out( 'Last-Modified' => Apache::Util::ht_time($file_mtime) );
require MIME::Types;
my ($media_type) = MIME::Types::by_suffix($filename);
if (defined $media_type) {
$apr->content_type($media_type);
if($media_type eq "text/html" && $pk->{use_gzip} ne 'none') {
my $gzipped = $pk->{view}->get_static_gzip($filename);
if ($gzipped){
$apr->content_encoding("gzip");
$apr->send_http_header;
$apr->print($gzipped) unless $apr->header_only;
return DONE;
}
}
}
return $pk->{model}->pkit_send($filename, $media_type);
# set path_info to '', otherwise Apache tacks it on at the end
## $apr->path_info('');
## $apr->filename($filename);
## return DECLINED;
}
sub _check_gzip {
my $pk = shift;
# check Accent-Encoding or if the user_agent field for Unix/Mac Netscape
# to see if should gzip output
my $gzip_output = $pk->{config}->get_global_attr("gzip_output") || 'none';
$pk->{use_gzip} = 'none';
my $apr = $pk->{apr};
if ($gzip_output =~ m!^(all|static)$!){
if(($apr->header_in("Accept-Encoding") || '') =~ /gzip/){
$pk->{use_gzip} = $gzip_output;
} else {
my $user_agent = $apr->header_in("User-Agent");
# this regular expression borrowed from Apache::AxKit::ConfigReader::DoZip
if ($user_agent && $user_agent =~ m{
^Mozilla/
\d+
\.
\d+
[\s\[\]\w\-]+
(
\(X11 |
Macint.+PPC,\sNav
)
}x
) {
$pk->{use_gzip} = $gzip_output;
}
}
}
( run in 0.520 second using v1.01-cache-2.11-cpan-39bf76dae61 )