Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 14 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
AbstractCover | |
0.00% |
0 / 14 |
|
0.00% |
0 / 5 |
462 | |
0.00% |
0 / 1 |
isCacheAllowed | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
useDirectUrls | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
supports | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
272 | |||
getUrl | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
getMetadata | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
getMandatoryBacklinkLocations | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | /** |
4 | * Abstract base for cover loader plug-ins. |
5 | * |
6 | * PHP version 8 |
7 | * |
8 | * Copyright (C) Villanova University 2010. |
9 | * |
10 | * This program is free software; you can redistribute it and/or modify |
11 | * it under the terms of the GNU General Public License version 2, |
12 | * as published by the Free Software Foundation. |
13 | * |
14 | * This program is distributed in the hope that it will be useful, |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | * GNU General Public License for more details. |
18 | * |
19 | * You should have received a copy of the GNU General Public License |
20 | * along with this program; if not, write to the Free Software |
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
22 | * |
23 | * @category VuFind |
24 | * @package Content |
25 | * @author Demian Katz <demian.katz@villanova.edu> |
26 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
27 | * @link https://vufind.org/wiki/development Wiki |
28 | */ |
29 | |
30 | namespace VuFind\Content; |
31 | |
32 | /** |
33 | * Abstract base for cover loader plug-ins. |
34 | * |
35 | * @category VuFind |
36 | * @package Content |
37 | * @author Demian Katz <demian.katz@villanova.edu> |
38 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
39 | * @link https://vufind.org/wiki/development Wiki |
40 | */ |
41 | abstract class AbstractCover |
42 | { |
43 | /** |
44 | * Does this plugin support ISBNs? |
45 | * |
46 | * @var bool |
47 | */ |
48 | protected $supportsIsbn = false; |
49 | |
50 | /** |
51 | * Does this plugin support ISSNs? |
52 | * |
53 | * @var bool |
54 | */ |
55 | protected $supportsIssn = false; |
56 | |
57 | /** |
58 | * Does this plugin support ISMNs? |
59 | * |
60 | * @var bool |
61 | */ |
62 | protected $supportsIsmn = false; |
63 | |
64 | /** |
65 | * Does this plugin support OCLC numbers? |
66 | * |
67 | * @var bool |
68 | */ |
69 | protected $supportsOclc = false; |
70 | |
71 | /** |
72 | * Does this plugin support UPC numbers? |
73 | * |
74 | * @var bool |
75 | */ |
76 | protected $supportsUpc = false; |
77 | |
78 | /** |
79 | * Does this plugin support national bibliographies number? |
80 | * |
81 | * @var bool |
82 | */ |
83 | protected $supportsNbn = false; |
84 | |
85 | /** |
86 | * Does this plugin support getting cover by local id? |
87 | * |
88 | * @var bool |
89 | */ |
90 | protected $supportsRecordid = false; |
91 | |
92 | /** |
93 | * Does this plugin support getting cover by UUID (Universally unique |
94 | * identifier)? |
95 | * |
96 | * @var bool |
97 | */ |
98 | protected $supportsUuid = false; |
99 | |
100 | /** |
101 | * Are we allowed to cache images from this source? |
102 | * |
103 | * @var bool |
104 | */ |
105 | protected $cacheAllowed = false; |
106 | |
107 | /** |
108 | * Use direct urls as image urls. When set to true, direct urls to content cover |
109 | * provider will be used in interface instead internal Cover/Show urls. |
110 | * |
111 | * @var bool |
112 | */ |
113 | protected $directUrls = false; |
114 | |
115 | /** |
116 | * Are backlinks to source of cover mandatory? |
117 | * |
118 | * @var array |
119 | */ |
120 | protected $mandatoryBacklinkLocations = []; |
121 | |
122 | /** |
123 | * Are we allowed to cache images from this source? |
124 | * |
125 | * @return bool |
126 | */ |
127 | public function isCacheAllowed() |
128 | { |
129 | return $this->cacheAllowed; |
130 | } |
131 | |
132 | /** |
133 | * Use direct urls? (Or proxied urls) |
134 | * |
135 | * @return bool |
136 | */ |
137 | public function useDirectUrls() |
138 | { |
139 | return $this->directUrls; |
140 | } |
141 | |
142 | /** |
143 | * Does this plugin support the provided ID array? |
144 | * |
145 | * @param array $ids IDs that will later be sent to load() -- see below. |
146 | * |
147 | * @return bool |
148 | */ |
149 | public function supports($ids) |
150 | { |
151 | return |
152 | ($this->supportsIsbn && isset($ids['isbn'])) |
153 | || ($this->supportsIssn && isset($ids['issn'])) |
154 | || ($this->supportsIsmn && isset($ids['ismn'])) |
155 | || ($this->supportsOclc && isset($ids['oclc'])) |
156 | || ($this->supportsUpc && isset($ids['upc'])) |
157 | || ($this->supportsNbn && isset($ids['nbn'])) |
158 | || ($this->supportsRecordid && isset($ids['recordid'])) |
159 | || ($this->supportsUuid && isset($ids['uuid'])); |
160 | } |
161 | |
162 | /** |
163 | * Get image URL for a particular API key and set of IDs (or false if invalid). |
164 | * |
165 | * @param string $key API key |
166 | * @param string $size Size of image to load (small/medium/large) |
167 | * @param array $ids Associative array of identifiers (keys may include 'isbn' |
168 | * pointing to an ISBN object, 'issn' pointing to a string and 'oclc' pointing |
169 | * to an OCLC number string) |
170 | * |
171 | * @return string|bool |
172 | */ |
173 | abstract public function getUrl($key, $size, $ids); |
174 | |
175 | /** |
176 | * Get cover metadata for a particular API key and set of IDs (or empty array). |
177 | * |
178 | * @param string $key API key |
179 | * @param string $size Size of image to load (small/medium/large) |
180 | * @param array $ids Associative array of identifiers (keys may include 'isbn' |
181 | * pointing to an ISBN object, 'issn' pointing to a string and 'oclc' pointing |
182 | * to an OCLC number string) |
183 | * |
184 | * @return array Array with keys: url, backlink_url, backlink_text |
185 | */ |
186 | public function getMetadata(?string $key, string $size, array $ids) |
187 | { |
188 | $url = $this->getUrl($key, $size, $ids); |
189 | return $url ? ['url' => $url] : []; |
190 | } |
191 | |
192 | /** |
193 | * Which location are mandatory for backlinks, available locations are the same |
194 | * as used for cover size determination, see coversize setting in [Content] |
195 | * section of config.ini |
196 | * |
197 | * @return array |
198 | */ |
199 | public function getMandatoryBacklinkLocations(): array |
200 | { |
201 | return $this->mandatoryBacklinkLocations; |
202 | } |
203 | } |