# HG changeset patch # User wizard # Date 1277469956 -14400 # Node ID f6af119ac741ab0155f0342a4bee75b1c73a338b # Parent 5b849974bed8515d82d1301c86fd41304bf4a024 url routines for templates diff -r 5b849974bed8 -r f6af119ac741 Lib/IMPL/Web/QueryHandler/PageFormat.pm --- a/Lib/IMPL/Web/QueryHandler/PageFormat.pm Thu Jun 24 02:39:00 2010 +0400 +++ b/Lib/IMPL/Web/QueryHandler/PageFormat.pm Fri Jun 25 16:45:56 2010 +0400 @@ -1,14 +1,18 @@ package IMPL::Web::QueryHandler::PageFormat; use base qw(IMPL::Web::QueryHandler IMPL::Object::Autofill); +use strict; __PACKAGE__->PassThroughArgs; use IMPL::Class::Property; use IMPL::Web::TT::Document; +use Template::Plugin::URL; use IMPL::Security::Context; use File::Spec; use Error qw(:try); +$Template::Plugin::URL::JOINT = '&'; + BEGIN { public property templatesCharset => prop_all; public property templatesBase => prop_all; @@ -34,12 +38,29 @@ $this->templatesBase($ENV{DOCUMENT_ROOT}) unless $this->templatesBase; - my $pathInfo = $ENV{PATH_INFO}; - my $prefixRoot = ""; + my ($requestUri) = split /\?/, $ENV{REQUEST_URI}; + + my $pathInfo; + + if ( $requestUri eq $ENV{SCRIPT_NAME}.$ENV{PATH_INFO} ) { + # CGI with path info + $pathInfo = $ENV{PATH_INFO}; + } else { + die "REQUEST_URI: $ENV{REQUEST_URI}\nPATH_INFO: $ENV{PATH_INFO}" unless $ENV{REQUEST_URI} eq $ENV{PATH_INFO}; + } + + my @root = (''); + my @base; + if (my $rx = $this->pathinfoPrefix) { - $pathInfo =~ s/($rx)//; - $prefixRoot = $1 if $1; + $requestUri =~ s/^($rx)//; + push @root, grep $_, split /\//, $1 if $1; } + + $pathInfo = $requestUri unless defined $pathInfo; + + @base = grep $_, split /\//, ($pathInfo ? substr $requestUri,0, -length($pathInfo) : $requestUri); + local $ENV{PATH_INFO} = $pathInfo || $this->defaultTarget; my @path = grep $_, split /\//, ($ENV{PATH_INFO} || '') or die new IMPL::Exception("PATH_INFO is empty and no defaultTarget specified" ); @@ -50,8 +71,9 @@ $doc->LoadFile ( File::Spec->catfile($this->templatesBase,@path), $this->templatesCharset, $this->templatesBase ); $doc->AddVar( result => $nextHandler->() ); $doc->AddVar( app => $action->application ); - $doc->AddVar( absoluteUrl => sub { "$prefixRoot/$_[0]" } ); - $doc->AddVar( relativeUrl => sub { join '/', $prefixRoot, @pathContainer,$_[0] } ); + $doc->AddVar( absoluteUrl => sub { join '/', @root, $_[0] } ); + $doc->AddVar( baseUrl => sub { join '/', @root, @base, $_[0] } ); + $doc->AddVar( relativeUrl => sub { join '/', @root, @base, @pathContainer,$_[0] } ); { local $@; $doc->AddVar( user => IMPL::Security::Context->current->principal ); diff -r 5b849974bed8 -r f6af119ac741 Lib/IMPL/Web/TT/Document.pm --- a/Lib/IMPL/Web/TT/Document.pm Thu Jun 24 02:39:00 2010 +0400 +++ b/Lib/IMPL/Web/TT/Document.pm Fri Jun 25 16:45:56 2010 +0400 @@ -5,7 +5,6 @@ use base qw(IMPL::DOM::Document IMPL::Object::Disposable); use Template::Context; use Template::Provider; -use Template::Plugin::URL; use IMPL::Class::Property; use File::Spec; use Scalar::Util qw(blessed); @@ -13,8 +12,6 @@ use IMPL::Web::TT::Control; use Carp; -$Template::Plugin::URL::JOINT = '&'; - BEGIN { private property _provider => prop_all; private property _context => prop_all;