Apache2-PageKit
view release on metacpan or search on metacpan
lib/Apache2/PageKit.pm view on Meta::CPAN
$output_param_object->param(pkit_hostname => $host);
# my $pkit_done = Apache2::Util::escape_path($apr->param('pkit_done') || $uri_with_query, $apr->pool);
my $pkit_done = $apr->param('pkit_done') || $uri_with_query;
# $pkit_done =~ s/"/\%22/g;
# $pkit_done =~ s/&/\%26/g;
# $pkit_done =~ s/\?/\%3F/g;
$output_param_object->param("pkit_done",$pkit_done);
# $fillinform_object->param("pkit_done",$pkit_done);
$pk->{page_id} = $uri;
# add the default_page for pageid with trailing slash "/"
# WARNING - this is undocumented and may go away at anytime
$pk->{page_id} =~ s!^(.*?)/+$! "$1/" . $model->pkit_get_default_page !e;
# get rid of leading forward slash
$pk->{page_id} =~ s(^/+)();
# get default page if there is no page specified in url
if($pk->{page_id} eq ''){
$pk->{page_id} = $model->pkit_get_default_page;
}
# store name and page_id for a static file, that require a login
my %static_file;
# redirect "not found" pages
unless ($pk->page_exists($pk->{page_id})){
# first try to see if we can find a static file that we
# can return
my $filename = $pk->static_page_exists($pk->{page_id});
unless($filename) {{
if ($pk->is_directory($pk->{page_id})) {
# redirect to the directory instead of deliver the page.
# otherwise the client gets all links wrong if they are relative.
# http://xyz.abc.de/my_dir
# we deliver silently http://xyz.abc.de/my_dir/some_default_page
# but all relative links on some_default_page get
# http://xyz.abc.de/_the_link_ istead of
# http://xyz.abc.de/my_dir/_the_link_
# so we redirect better ...
$apr->headers_out->{Location} = $pk->{page_id} . '/';
return REDIRECT;
}
$pk->{page_id} = $config->uri_match($pk->{page_id})
|| $config->get_global_attr('not_found_page')
|| $model->pkit_get_default_page;
unless ($pk->page_exists($pk->{page_id})){
# if not_found_page is static, then return DECLINED...
$filename = $pk->static_page_exists($pk->{page_id});
}
}}
if ($filename){
my $require_login = $config->get_page_attr($pk->{page_id},'require_login') || 'no';
my $protect_static = $config->get_global_attr('protect_static') || 'yes';
if ( $require_login eq 'no' || $protect_static ne 'yes' ) {
# return the static page only, if no parameters are attached to the uri
# otherwise we can not login logout and so on when one the default or index
# or whatever page is static.
# if we have some parameters, defer the delivery of the page after the
# auth check
return $pk->_send_static_file($filename) unless ( () = $apr->param );
}
$static_file{name} = $filename;
$static_file{page_id} = $pk->{page_id};
}
}
my ($auth_user, $auth_session_id);
unless($apr->param('pkit_logout')){
($auth_user, $auth_session_id) = $pk->authenticate;
}
# session handling
if($model->can('pkit_session_setup')){
if ( ( $config->get_page_attr( $pk->{page_id}, 'use_sessions' ) || 'yes' ) eq 'yes' ) {
$pk->setup_session($auth_session_id);
}
else {
$pk->{session} = {};
}
}
my $session = $pk->{session};
# get language
# get Locale settings
my ($lang, $accept_lang);
if( $lang = $apr->param('pkit_lang') ){
$session->{'pkit_lang'} = $lang if $session;
} elsif ( $session && !exists $pk->{is_new_session} ){
$lang = $session->{'pkit_lang'} if exists $session->{'pkit_lang'};
}
# if we have no lang setting here look what the browser likes most.
unless ($lang) {
if ( $accept_lang = $apr->headers_in->{'Accept-Language'} ) {
$lang = substr($accept_lang, 0, 2);
}
}
$lang ||= $config->get_global_attr('default_lang') || 'en';
# TEMP only for anidea.com site, until fix problems with localization in content
$output_param_object->param("pkit_lang_$lang" => 1);
$pk->{lang} = $lang;
if($apr->param('pkit_logout')){
$pk->logout;
$apr->param('pkit_check_cookie','');
# goto home page when user logouts (if from page that requires login)
my $require_login = $config->get_page_attr($pk->{page_id},'require_login');
if (defined($require_login) && $require_login =~ m!^(?:yes|recent)$!) {
# $pk->{page_id} = $config->get_global_attr('default_page');
$pk->{page_id} = $model->pkit_get_default_page;
}
( run in 2.005 seconds using v1.01-cache-2.11-cpan-e1769b4cff6 )