1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* (c) Kitodo. Key to digital objects e.V. <[email protected]> |
4
|
|
|
* |
5
|
|
|
* This file is part of the Kitodo and TYPO3 projects. |
6
|
|
|
* |
7
|
|
|
* @license GNU General Public License version 3 or later. |
8
|
|
|
* For the full copyright and license information, please read the |
9
|
|
|
* LICENSE.txt file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Kitodo\Dlf\Controller; |
13
|
|
|
|
14
|
|
|
use Kitodo\Dlf\Common\IiifManifest; |
15
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
16
|
|
|
use TYPO3\CMS\Core\Utility\MathUtility; |
17
|
|
|
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration; |
18
|
|
|
use TYPO3\CMS\Core\Database\Connection; |
19
|
|
|
use Ubl\Iiif\Presentation\Common\Model\Resources\ManifestInterface; |
20
|
|
|
use Ubl\Iiif\Presentation\Common\Vocabulary\Motivation; |
21
|
|
|
|
22
|
|
|
class PageViewController extends AbstractController |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var |
26
|
|
|
*/ |
27
|
|
|
protected $extConf; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Holds the controls to add to the map |
31
|
|
|
* |
32
|
|
|
* @var array |
33
|
|
|
* @access protected |
34
|
|
|
*/ |
35
|
|
|
protected $controls = []; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Holds the current images' URLs and MIME types |
39
|
|
|
* |
40
|
|
|
* @var array |
41
|
|
|
* @access protected |
42
|
|
|
*/ |
43
|
|
|
protected $images = []; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Holds the current fulltexts' URLs |
47
|
|
|
* |
48
|
|
|
* @var array |
49
|
|
|
* @access protected |
50
|
|
|
*/ |
51
|
|
|
protected $fulltexts = []; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Holds the current AnnotationLists / AnnotationPages |
55
|
|
|
* |
56
|
|
|
* @var array |
57
|
|
|
* @access protected |
58
|
|
|
*/ |
59
|
|
|
protected $annotationContainers = []; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* The main method of the plugin |
63
|
|
|
* |
64
|
|
|
* @return void |
65
|
|
|
*/ |
66
|
|
|
public function mainAction() |
67
|
|
|
{ |
68
|
|
|
$requestData = GeneralUtility::_GPmerged('tx_dlf'); |
69
|
|
|
unset($requestData['__referrer'], $requestData['__trustedProperties']); |
70
|
|
|
|
71
|
|
|
$this->extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('dlf'); |
72
|
|
|
|
73
|
|
|
// Load current document. |
74
|
|
|
$this->loadDocument($requestData); |
75
|
|
|
if ( |
76
|
|
|
$this->doc === null |
77
|
|
|
|| $this->doc->numPages < 1 |
78
|
|
|
) { |
79
|
|
|
// Quit without doing anything if required variables are not set. |
80
|
|
|
return; |
81
|
|
|
} else { |
82
|
|
|
if (!empty($requestData['logicalPage'])) { |
83
|
|
|
$requestData['page'] = $this->doc->getPhysicalPage($requestData['logicalPage']); |
84
|
|
|
// The logical page parameter should not appear again |
85
|
|
|
unset($requestData['logicalPage']); |
86
|
|
|
} |
87
|
|
|
// Set default values if not set. |
88
|
|
|
// $requestData['page'] may be integer or string (physical structure @ID) |
89
|
|
|
if ((int) $requestData['page'] > 0 || empty($requestData['page'])) { |
90
|
|
|
$requestData['page'] = MathUtility::forceIntegerInRange((int) $requestData['page'], 1, $this->doc->numPages, 1); |
91
|
|
|
} else { |
92
|
|
|
$requestData['page'] = array_search($requestData['page'], $this->doc->physicalStructure); |
93
|
|
|
} |
94
|
|
|
$requestData['double'] = MathUtility::forceIntegerInRange($requestData['double'], 0, 1, 0); |
95
|
|
|
} |
96
|
|
|
// Get image data. |
97
|
|
|
$this->images[0] = $this->getImage($requestData['page']); |
98
|
|
|
$this->fulltexts[0] = $this->getFulltext($requestData['page']); |
99
|
|
|
$this->annotationContainers[0] = $this->getAnnotationContainers($requestData['page']); |
100
|
|
|
if ($requestData['double'] && $requestData['page'] < $this->doc->numPages) { |
101
|
|
|
$this->images[1] = $this->getImage($requestData['page'] + 1); |
102
|
|
|
$this->fulltexts[1] = $this->getFulltext($requestData['page'] + 1); |
103
|
|
|
$this->annotationContainers[1] = $this->getAnnotationContainers($requestData['page'] + 1); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
// Get the controls for the map. |
107
|
|
|
$this->controls = explode(',', $this->settings['features']); |
108
|
|
|
|
109
|
|
|
$this->view->assign('forceAbsoluteUrl', $this->settings['forceAbsoluteUrl']); |
110
|
|
|
|
111
|
|
|
$this->addViewerJS(); |
112
|
|
|
|
113
|
|
|
$this->view->assign('images', $this->images); |
114
|
|
|
$this->view->assign('docId', $requestData['id']); |
115
|
|
|
$this->view->assign('page', $requestData['page']); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Get fulltext URL and MIME type |
120
|
|
|
* |
121
|
|
|
* @access protected |
122
|
|
|
* |
123
|
|
|
* @param int $page: Page number |
124
|
|
|
* |
125
|
|
|
* @return array URL and MIME type of fulltext file |
126
|
|
|
*/ |
127
|
|
|
protected function getFulltext($page) |
128
|
|
|
{ |
129
|
|
|
$fulltext = []; |
130
|
|
|
// Get fulltext link. |
131
|
|
|
$fileGrpsFulltext = GeneralUtility::trimExplode(',', $this->extConf['fileGrpFulltext']); |
132
|
|
|
while ($fileGrpFulltext = array_shift($fileGrpsFulltext)) { |
133
|
|
|
if (!empty($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$page]]['files'][$fileGrpFulltext])) { |
134
|
|
|
$fulltext['url'] = $this->doc->getFileLocation($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$page]]['files'][$fileGrpFulltext]); |
135
|
|
|
if ($this->settings['useInternalProxy']) { |
136
|
|
|
// Configure @action URL for form. |
137
|
|
|
$uri = $this->uriBuilder->reset() |
138
|
|
|
->setTargetPageUid($GLOBALS['TSFE']->id) |
139
|
|
|
->setCreateAbsoluteUri(!empty($this->settings['forceAbsoluteUrl']) ? 1 : 0) |
140
|
|
|
->setArguments(['eID' => 'tx_dlf_pageview_proxy', 'url' => urlencode($fulltext['url'])]) |
141
|
|
|
->build(); |
142
|
|
|
|
143
|
|
|
$fulltext['url'] = $uri; |
144
|
|
|
} |
145
|
|
|
$fulltext['mimetype'] = $this->doc->getFileMimeType($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$page]]['files'][$fileGrpFulltext]); |
146
|
|
|
break; |
147
|
|
|
} else { |
148
|
|
|
$this->logger->notice('No full-text file found for page "' . $page . '" in fileGrp "' . $fileGrpFulltext . '"'); |
|
|
|
|
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
if (empty($fulltext)) { |
152
|
|
|
$this->logger->notice('No full-text file found for page "' . $page . '" in fileGrps "' . $this->conf['settings.fileGrpFulltext'] . '"'); |
153
|
|
|
} |
154
|
|
|
return $fulltext; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Adds Viewer javascript |
159
|
|
|
* |
160
|
|
|
* @access protected |
161
|
|
|
* |
162
|
|
|
* @return void |
163
|
|
|
*/ |
164
|
|
|
protected function addViewerJS() |
165
|
|
|
{ |
166
|
|
|
// Viewer configuration. |
167
|
|
|
$viewerConfiguration = '<script> |
168
|
|
|
$(document).ready(function() { |
169
|
|
|
if (dlfUtils.exists(dlfViewer)) { |
170
|
|
|
tx_dlf_viewer = new dlfViewer({ |
171
|
|
|
controls: ["' . implode('", "', $this->controls) . '"], |
172
|
|
|
div: "' . $this->settings['elementId'] . '", |
173
|
|
|
images: ' . json_encode($this->images) . ', |
174
|
|
|
fulltexts: ' . json_encode($this->fulltexts) . ', |
175
|
|
|
annotationContainers: ' . json_encode($this->annotationContainers) . ', |
176
|
|
|
useInternalProxy: ' . ($this->settings['useInternalProxy'] ? 1 : 0) . ' |
177
|
|
|
}); |
178
|
|
|
} |
179
|
|
|
}); |
180
|
|
|
</script>'; |
181
|
|
|
$this->view->assign('viewerConfiguration', $viewerConfiguration); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* Get all AnnotationPages / AnnotationLists that contain text Annotations with motivation "painting" |
186
|
|
|
* |
187
|
|
|
* @access protected |
188
|
|
|
* |
189
|
|
|
* @param int $page: Page number |
190
|
|
|
* @return array An array containing the IRIs of the AnnotationLists / AnnotationPages as well as |
191
|
|
|
* some information about the canvas. |
192
|
|
|
*/ |
193
|
|
|
protected function getAnnotationContainers($page) |
194
|
|
|
{ |
195
|
|
|
if ($this->doc instanceof IiifManifest) { |
196
|
|
|
$canvasId = $this->doc->physicalStructure[$page]; |
197
|
|
|
$iiif = $this->doc->getIiif(); |
198
|
|
|
if ($iiif instanceof ManifestInterface) { |
|
|
|
|
199
|
|
|
$canvas = $iiif->getContainedResourceById($canvasId); |
200
|
|
|
/* @var $canvas \Ubl\Iiif\Presentation\Common\Model\Resources\CanvasInterface */ |
201
|
|
|
if ($canvas != null && !empty($canvas->getPossibleTextAnnotationContainers(Motivation::PAINTING))) { |
202
|
|
|
$annotationContainers = []; |
203
|
|
|
/* |
204
|
|
|
* TODO Analyzing the annotations on the server side requires loading the annotation lists / pages |
205
|
|
|
* just to determine wether they contain text annotations for painting. This will take time and lead to a bad user experience. |
206
|
|
|
* It would be better to link every annotation and analyze the data on the client side. |
207
|
|
|
* |
208
|
|
|
* On the other hand, server connections are potentially better than client connections. Downloading annotation lists |
209
|
|
|
*/ |
210
|
|
|
foreach ($canvas->getPossibleTextAnnotationContainers(Motivation::PAINTING) as $annotationContainer) { |
211
|
|
|
if (($textAnnotations = $annotationContainer->getTextAnnotations(Motivation::PAINTING)) != null) { |
212
|
|
|
foreach ($textAnnotations as $annotation) { |
213
|
|
|
if ( |
214
|
|
|
$annotation->getBody()->getFormat() == 'text/plain' |
215
|
|
|
&& $annotation->getBody()->getChars() != null |
216
|
|
|
) { |
217
|
|
|
$annotationListData = []; |
218
|
|
|
$annotationListData['uri'] = $annotationContainer->getId(); |
219
|
|
|
$annotationListData['label'] = $annotationContainer->getLabelForDisplay(); |
220
|
|
|
$annotationContainers[] = $annotationListData; |
221
|
|
|
break; |
222
|
|
|
} |
223
|
|
|
} |
224
|
|
|
} |
225
|
|
|
} |
226
|
|
|
$result = [ |
227
|
|
|
'canvas' => [ |
228
|
|
|
'id' => $canvas->getId(), |
229
|
|
|
'width' => $canvas->getWidth(), |
230
|
|
|
'height' => $canvas->getHeight(), |
231
|
|
|
], |
232
|
|
|
'annotationContainers' => $annotationContainers |
233
|
|
|
]; |
234
|
|
|
return $result; |
235
|
|
|
} |
236
|
|
|
} |
237
|
|
|
} |
238
|
|
|
return []; |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
/** |
242
|
|
|
* Get image's URL and MIME type |
243
|
|
|
* |
244
|
|
|
* @access protected |
245
|
|
|
* |
246
|
|
|
* @param int $page: Page number |
247
|
|
|
* |
248
|
|
|
* @return array URL and MIME type of image file |
249
|
|
|
*/ |
250
|
|
|
protected function getImage($page) |
251
|
|
|
{ |
252
|
|
|
$image = []; |
253
|
|
|
// Get @USE value of METS fileGrp. |
254
|
|
|
$fileGrpsImages = GeneralUtility::trimExplode(',', $this->extConf['fileGrpImages']); |
255
|
|
|
while ($fileGrpImages = array_pop($fileGrpsImages)) { |
256
|
|
|
// Get image link. |
257
|
|
|
if (!empty($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$page]]['files'][$fileGrpImages])) { |
258
|
|
|
$image['url'] = $this->doc->getFileLocation($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$page]]['files'][$fileGrpImages]); |
259
|
|
|
if ($this->settings['useInternalProxy']) { |
260
|
|
|
// Configure @action URL for form. |
261
|
|
|
$uri = $this->uriBuilder->reset() |
262
|
|
|
->setTargetPageUid($GLOBALS['TSFE']->id) |
263
|
|
|
->setCreateAbsoluteUri(!empty($this->settings['forceAbsoluteUrl']) ? 1 : 0) |
264
|
|
|
->setArguments(['eID' => 'tx_dlf_pageview_proxy', 'url' => urlencode($image['url'])]) |
265
|
|
|
->build(); |
266
|
|
|
$image['url'] = $uri; |
267
|
|
|
} |
268
|
|
|
$image['mimetype'] = $this->doc->getFileMimeType($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$page]]['files'][$fileGrpImages]); |
269
|
|
|
break; |
270
|
|
|
} else { |
271
|
|
|
$this->logger->notice('No image file found for page "' . $page . '" in fileGrp "' . $fileGrpImages . '"'); |
272
|
|
|
} |
273
|
|
|
} |
274
|
|
|
if (empty($image)) { |
275
|
|
|
$this->logger->warning('No image file found for page "' . $page . '" in fileGrps "' . $this->settings['fileGrpImages'] . '"'); |
276
|
|
|
} |
277
|
|
|
return $image; |
278
|
|
|
} |
279
|
|
|
} |
280
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.