From 76f0c8cecf132dd8b2336e8f9bb66baa945195f6 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Sat, 4 May 2019 11:21:42 -0400 Subject: [PATCH] Bug 22223: Try to not double encoded URIs in items.uri This is just a POC and is not ready for inclusion (Filter.pm and naming need to be discussed). Test plan: Create 2 items, with uri: https://www.google.com/url?q=https://buttercup.pw https://www.google.com/url?q=https%3A%2F%2Fbuttercup.pw Go to the OPAC detail page of the bib record, see that the links are displayed how you entered them. Click on them and confirm that the uri/page is correct --- Koha/Template/Plugin/Filter.pm | 32 +++++++++++++++++++ .../prog/en/modules/catalogue/detail.tt | 9 ++++-- .../bootstrap/en/modules/opac-detail.tt | 7 ++-- 3 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 Koha/Template/Plugin/Filter.pm diff --git a/Koha/Template/Plugin/Filter.pm b/Koha/Template/Plugin/Filter.pm new file mode 100644 index 00000000000..9dbd16022c9 --- /dev/null +++ b/Koha/Template/Plugin/Filter.pm @@ -0,0 +1,32 @@ +package Koha::Template::Plugin::Filter; + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Template::Plugin::Filter; +use base qw( Template::Plugin::Filter ); + +our $DYNAMIC = 1; + +sub no_double_encode { + my ( $self, $value ) = @_; + + $value =~ s/%25([0-9a-f]{2})/%$1/gi; + return $value; +} + +1; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt index 7c2b961d6ca..b71b7d89a03 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt @@ -2,6 +2,7 @@ [% USE Asset %] [% USE Koha %] [% USE KohaDates %] +[% USE Filter %] [% USE KohaPlugins %] [% USE AuthorisedValues %] [% USE Branches %] @@ -517,12 +518,16 @@ Note that permanent location is a code, and location may be an authval. [% IF ( itemdata_uri ) %] [% IF item.uri.split(' \| ').size > 1 %] - [% FOREACH uri IN item.uri.split(' \| ') %][% uri | html %]
[% END %] + [% FOREACH uri IN item.uri.split(' \| ') ~%] + [%~ uri_url_filtered = BLOCK %][% uri | url ~%][% END %] + [% uri | html %]
+ [%~ END %] [% ELSE %] [% IF item.uri %] - [% IF Koha.Preference('URLLinkText') %][% Koha.Preference('URLLinkText') | html %][% ELSE %]Link to resource[% END %] + [%~ uri_url_filtered = BLOCK %][% item.uri | url ~%][% END %] + [% IF Koha.Preference('URLLinkText') %][% Koha.Preference('URLLinkText') | html %][% ELSE %]Link to resource[% END %] [% END %] [% END %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt index 0d417a77713..8609658668f 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt @@ -3,6 +3,7 @@ [% USE Math %] [% USE Koha %] [% USE KohaDates %] +[% USE Filter %] [% USE Branches %] [% USE TablesSettings %] [% USE AuthorisedValues %] @@ -1239,14 +1240,16 @@ [% IF trackclicks == 'track' || trackclicks == 'anonymous' %] [% uri | html %] [% ELSE %] - [% uri | html %] + [% uri_url_filtered = BLOCK %][% uri | url %][% END %] + [% uri | html %] [% END %] [% END %] [% ELSE %] [% IF trackclicks == 'track' || trackclicks == 'anonymous' %] [% ELSE %] - + [% uri_url_filtered = BLOCK %][% ITEM_RESULT.uri | url %][% END %] + [% END %] [% IF Koha.Preference('URLLinkText') %][% Koha.Preference('URLLinkText') | html %][% ELSE %]Link to resource[% END %] -- 2.25.1