1 package Koha
::Util
::Navigation
;
3 # Copyright Rijksmuseum 2018
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
29 use Koha::Util::Navigation;
31 my $referer = Koha::Util::Navigation::local_referer($cgi);
41 my $referer = Koha::Util::Navigation::local_referer( $cgi, { fallback => '/', remove_language => 1, staff => 1 });
43 If the referer is a local URI, return local path.
44 Otherwise return fallback.
45 Optional parameters fallback, remove_language and staff. If you do not
46 pass staff, opac is assumed.
51 my ( $cgi, $params ) = @_;
52 my $referer = $cgi->referer;
53 my $fallback = $params->{fallback
} // '/';
54 my $staff = $params->{staff
}; # no staff means OPAC
55 return $fallback if !$referer;
57 my $base = C4
::Context
->preference($staff ?
'staffClientBaseURL' : 'OPACBaseURL');
60 # Try ..BaseURL first, otherwise use CGI::url
62 if( $referer =~ m
|^\Q
$base\E
|i
&&
63 $referer =~ /\/cgi-bin\
/koha\// )
65 $rv = substr( $referer, length($base) );
70 my $cgibase = $cgi->url( -base
=> 1 );
71 $cgibase =~ s/^https?://;
72 if( $referer =~ /$cgibase(\/cgi-bin\
/koha\/.*)$/ ) {
76 $rv =~ s/(?<=[?&])language=[\w-]+(&|$)// if $rv and $params->{remove_language
};
77 return $rv // $fallback;
84 Marcel de Rooy, Rijksmuseum Amsterdam, The Netherlands