Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 63 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
Threesixtylink | |
0.00% |
0 / 63 |
|
0.00% |
0 / 3 |
182 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
fetchLinks | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
parseLinks | |
0.00% |
0 / 57 |
|
0.00% |
0 / 1 |
110 |
1 | <?php |
2 | |
3 | /** |
4 | * 360Link Link Resolver Driver |
5 | * |
6 | * PHP version 8 |
7 | * |
8 | * Copyright (C) Royal Holloway, University of London |
9 | * |
10 | * last update: 2010-11-17 |
11 | * |
12 | * This program is free software; you can redistribute it and/or modify |
13 | * it under the terms of the GNU General Public License version 2, |
14 | * as published by the Free Software Foundation. |
15 | * |
16 | * This program is distributed in the hope that it will be useful, |
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19 | * GNU General Public License for more details. |
20 | * |
21 | * You should have received a copy of the GNU General Public License |
22 | * along with this program; if not, write to the Free Software |
23 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
24 | * |
25 | * @category VuFind |
26 | * @package Resolver_Drivers |
27 | * @author Graham Seaman <Graham.Seaman@rhul.ac.uk> |
28 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
29 | * @link https://vufind.org/wiki/development:plugins:link_resolver_drivers Wiki |
30 | */ |
31 | |
32 | namespace VuFind\Resolver\Driver; |
33 | |
34 | use DOMDocument; |
35 | use DOMXpath; |
36 | |
37 | /** |
38 | * 360Link Link Resolver Driver |
39 | * |
40 | * @category VuFind |
41 | * @package Resolver_Drivers |
42 | * @author Graham Seaman <Graham.Seaman@rhul.ac.uk> |
43 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
44 | * @link https://vufind.org/wiki/development:plugins:link_resolver_drivers Wiki |
45 | */ |
46 | class Threesixtylink extends AbstractBase |
47 | { |
48 | /** |
49 | * HTTP client |
50 | * |
51 | * @var \Laminas\Http\Client |
52 | */ |
53 | protected $httpClient; |
54 | |
55 | /** |
56 | * Constructor |
57 | * |
58 | * @param string $baseUrl Base URL for link resolver |
59 | * @param \Laminas\Http\Client $httpClient HTTP client |
60 | */ |
61 | public function __construct($baseUrl, \Laminas\Http\Client $httpClient) |
62 | { |
63 | parent::__construct($baseUrl); |
64 | $this->httpClient = $httpClient; |
65 | } |
66 | |
67 | /** |
68 | * Fetch Links |
69 | * |
70 | * Fetches a set of links corresponding to an OpenURL |
71 | * |
72 | * @param string $openURL openURL (url-encoded) |
73 | * |
74 | * @return string raw XML returned by resolver |
75 | */ |
76 | public function fetchLinks($openURL) |
77 | { |
78 | // Make the call to SerialsSolutions and load results |
79 | $url = $this->baseUrl . (str_ends_with($this->baseUrl, '/') ? '' : '/') . |
80 | 'openurlxml?version=1.0&' . $openURL; |
81 | $feed = $this->httpClient->setUri($url)->send()->getBody(); |
82 | return $feed; |
83 | } |
84 | |
85 | /** |
86 | * Parse Links |
87 | * |
88 | * Parses an XML file returned by a link resolver |
89 | * and converts it to a standardised format for display |
90 | * |
91 | * @param string $xmlstr Raw XML returned by resolver |
92 | * |
93 | * @return array Array of values |
94 | */ |
95 | public function parseLinks($xmlstr) |
96 | { |
97 | $records = []; // array to return |
98 | |
99 | $xml = new DOMDocument(); |
100 | if (!@$xml->loadXML($xmlstr)) { |
101 | return $records; |
102 | } |
103 | |
104 | $xpath = new DOMXpath($xml); |
105 | $linkGroups = $xpath->query("//ssopenurl:linkGroup[@type='holding']"); |
106 | if (null !== $linkGroups) { |
107 | foreach ($linkGroups as $linkGroup) { |
108 | $record = []; |
109 | // select the deepest link returned |
110 | $elems = $xpath->query( |
111 | ".//ssopenurl:url[@type='article']", |
112 | $linkGroup |
113 | ); |
114 | if ($elems->length > 0) { |
115 | $record['linktype'] = 'article'; |
116 | } else { |
117 | $elems = $xpath->query( |
118 | ".//ssopenurl:url[@type='journal']", |
119 | $linkGroup |
120 | ); |
121 | if ($elems->length > 0) { |
122 | $record['linktype'] = 'journal'; |
123 | } else { |
124 | $elems = $xpath->query( |
125 | ".//ssopenurl:url[@type='source']", |
126 | $linkGroup |
127 | ); |
128 | if ($elems->length > 0) { |
129 | $record['linktype'] = 'source'; |
130 | } |
131 | } |
132 | } |
133 | if ($elems->length > 0) { |
134 | $href = $elems->item(0)->nodeValue; |
135 | $record['href'] = $href; |
136 | $record['service_type'] = 'getFullTxt'; |
137 | } else { |
138 | $record['service_type'] = 'getHolding'; |
139 | } |
140 | $elems = $xpath->query( |
141 | './/ssopenurl:holdingData/ssopenurl:providerName', |
142 | $linkGroup |
143 | ); |
144 | $title = $elems->item(0)->textContent; |
145 | $elems = $xpath->query( |
146 | './/ssopenurl:holdingData/ssopenurl:databaseName', |
147 | $linkGroup |
148 | ); |
149 | $title .= ' - ' . $elems->item(0)->textContent; |
150 | $record['title'] = $title; |
151 | $elems = $xpath->query( |
152 | './/ssopenurl:holdingData/ssopenurl:startDate', |
153 | $linkGroup |
154 | ); |
155 | if ($elems->length > 0) { |
156 | $record['coverage'] = $elems->item(0)->textContent . ' - '; |
157 | } |
158 | $elems = $xpath->query( |
159 | './/ssopenurl:holdingData/ssopenurl:endDate', |
160 | $linkGroup |
161 | ); |
162 | if ($elems->length > 0) { |
163 | $record['coverage'] .= $elems->item(0)->textContent; |
164 | } |
165 | |
166 | array_push($records, $record); |
167 | } |
168 | } |
169 | return $records; |
170 | } |
171 | } |