58 lines
1.6 KiB
Perl
58 lines
1.6 KiB
Perl
# Selima Website Content Management System
|
|
# AbsURI.pm: The converter to turn all URIs to absolute URIs.
|
|
|
|
# Copyright (c) 2003-2018 imacat.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
# Author: imacat <imacat@mail.imacat.idv.tw>
|
|
# First written: 2003-03-26
|
|
|
|
package Selima::AbsURI;
|
|
use 5.008;
|
|
use strict;
|
|
use warnings;
|
|
use base qw(Exporter);
|
|
use vars qw(@EXPORT @EXPORT_OK);
|
|
BEGIN {
|
|
@EXPORT = qw(absuri);
|
|
@EXPORT_OK = @EXPORT;
|
|
# Prototype declaration
|
|
sub absuri($;$$);
|
|
}
|
|
|
|
use URI qw();
|
|
|
|
use Selima::DataVars qw(:requri);
|
|
|
|
# absuri: Convert and colonicalize to an absolute URI
|
|
sub absuri($;$$) {
|
|
local ($_, %_);
|
|
my ($uri, $base, $skip_fragment);
|
|
($uri, $base, $skip_fragment) = @_;
|
|
|
|
# Default base to $REQUEST_FULLURI
|
|
$base = defined $base? new URI($base): $REQUEST_FULLURI;
|
|
# Skip the fragment
|
|
return $uri if $skip_fragment && $uri =~ /^#/;
|
|
# Absolute path -- add the root difference
|
|
$uri = "$ROOT_DIFF$uri" if $uri =~ /^\//;
|
|
$uri = new URI($uri);
|
|
# Obtain the absolute URI
|
|
$uri = $uri->abs($base);
|
|
|
|
return $uri->canonical;
|
|
}
|
|
|
|
return 1;
|