Bug 35105: Fix patron accessor in Illrequest.pm
[koha.git] / Koha / XSLT / HTTPS.pm
1 package Koha::XSLT::HTTPS;
2
3 # Copyright 2022 Rijksmuseum
4 #
5 # This file is part of Koha.
6 #
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.
11 #
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.
16 #
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>.
19
20 =head1 NAME
21
22 Koha::XSLT::HTTPS - Helper module to resolve issues with https stylesheets
23
24 =head1 SYNOPSIS
25
26     Koha::XSLT::HTTPS->load( $filename );
27
28 =head1 DESCRIPTION
29
30 This module collects the contents of https XSLT styleheets where
31 libxml2/libxslt fail to do so. This should be considered as a
32 temporary workaround.
33
34 A similar problem comes up with xslt include files. The module could
35 be extended to resolve these issues too. What holds me back now, is
36 the fact that we need to parse the whole xslt code.
37
38 =cut
39
40 use Modern::Perl;
41 use LWP::UserAgent;
42
43 use Koha::Exceptions::XSLT;
44
45 =head1 METHODS
46
47 =head2 load
48
49      Koha::XSLT::HTTPS->load( $filename );
50
51 =cut
52
53 sub load {
54     my ( $class, $filename ) = @_;
55
56     Koha::Exceptions::XSLT::MissingFilename->throw if !$filename;
57     return { location => $filename } if $filename !~ /^https:\/\//;
58
59     my $ua = LWP::UserAgent->new( ssl_opts => { verify_hostname => 0 } );
60     my $resp = $ua->get( $filename );
61     if( $resp->is_success ) {
62         my $contents = $resp->decoded_content;
63         # $contents = $self->_resolve_includes( $contents );
64         return { string => $contents };
65     }
66     Koha::Exceptions::XSLT::FetchFailed->throw;
67 }
68
69 sub _resolve_includes {
70 # We could parse the code for includes/imports, fetch them and change refs
71     my ( $self, $code ) = @_;
72     # TODO Extend it
73     return $code;
74 }
75
76 1;
77
78 =head1 AUTHOR
79
80     Marcel de Rooy, Rijksmuseum Amsterdam, The Netherlands
81
82 =cut