We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
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 Ubl\Iiif\Presentation\Common\Model\Resources\ManifestInterface; |
||
18 | use Ubl\Iiif\Presentation\Common\Vocabulary\Motivation; |
||
19 | |||
20 | /** |
||
21 | * Controller class for the plugin 'Page View'. |
||
22 | * |
||
23 | * @package TYPO3 |
||
24 | * @subpackage dlf |
||
25 | * |
||
26 | * @access public |
||
27 | */ |
||
28 | class PageViewController extends AbstractController |
||
29 | { |
||
30 | /** |
||
31 | * @access protected |
||
32 | * @var array Holds the controls to add to the map |
||
33 | */ |
||
34 | protected array $controls = []; |
||
35 | |||
36 | /** |
||
37 | * @access protected |
||
38 | * @var array Holds the current images' URLs and MIME types |
||
39 | */ |
||
40 | protected array $images = []; |
||
41 | |||
42 | /** |
||
43 | * @access protected |
||
44 | * @var array Holds the current full texts' URLs |
||
45 | */ |
||
46 | protected array $fulltexts = []; |
||
47 | |||
48 | /** |
||
49 | * Holds the current AnnotationLists / AnnotationPages |
||
50 | * |
||
51 | * @access protected |
||
52 | * @var array Holds the current AnnotationLists / AnnotationPages |
||
53 | */ |
||
54 | protected array $annotationContainers = []; |
||
55 | |||
56 | /** |
||
57 | * The main method of the plugin |
||
58 | * |
||
59 | * @access public |
||
60 | * |
||
61 | * @return void |
||
62 | */ |
||
63 | public function mainAction(): void |
||
64 | { |
||
65 | // Load current document. |
||
66 | $this->loadDocument(); |
||
67 | if ($this->isDocMissingOrEmpty()) { |
||
68 | // Quit without doing anything if required variables are not set. |
||
69 | return; |
||
70 | } |
||
71 | |||
72 | $this->setPage(); |
||
73 | |||
74 | // Get image data. |
||
75 | $this->images[0] = $this->getImage($this->requestData['page']); |
||
76 | $this->fulltexts[0] = $this->getFulltext($this->requestData['page']); |
||
77 | $this->annotationContainers[0] = $this->getAnnotationContainers($this->requestData['page']); |
||
78 | if ($this->requestData['double'] && $this->requestData['page'] < $this->document->getCurrentDocument()->numPages) { |
||
79 | $this->images[1] = $this->getImage($this->requestData['page'] + 1); |
||
80 | $this->fulltexts[1] = $this->getFulltext($this->requestData['page'] + 1); |
||
81 | $this->annotationContainers[1] = $this->getAnnotationContainers($this->requestData['page'] + 1); |
||
82 | } |
||
83 | |||
84 | // Get the controls for the map. |
||
85 | $this->controls = explode(',', $this->settings['features']); |
||
86 | |||
87 | $this->view->assign('forceAbsoluteUrl', $this->settings['general']['forceAbsoluteUrl']); |
||
88 | |||
89 | $this->addViewerJS(); |
||
90 | |||
91 | $this->view->assign('images', $this->images); |
||
92 | $this->view->assign('docId', $this->requestData['id']); |
||
93 | $this->view->assign('page', $this->requestData['page']); |
||
94 | } |
||
95 | |||
96 | /** |
||
97 | * Get fulltext URL and MIME type |
||
98 | * |
||
99 | * @access protected |
||
100 | * |
||
101 | * @param int $page Page number |
||
102 | * |
||
103 | * @return array URL and MIME type of fulltext file |
||
104 | */ |
||
105 | protected function getFulltext(int $page): array |
||
106 | { |
||
107 | $fulltext = []; |
||
108 | // Get fulltext link. |
||
109 | $fileGrpsFulltext = GeneralUtility::trimExplode(',', $this->extConf['files']['fileGrpFulltext']); |
||
110 | while ($fileGrpFulltext = array_shift($fileGrpsFulltext)) { |
||
111 | $physicalStructureInfo = $this->document->getCurrentDocument()->physicalStructureInfo[$this->document->getCurrentDocument()->physicalStructure[$page]]; |
||
0 ignored issues
–
show
|
|||
112 | $fileId = $physicalStructureInfo['files'][$fileGrpFulltext]; |
||
113 | if (!empty($fileId)) { |
||
114 | $file = $this->document->getCurrentDocument()->getFileInfo($fileId); |
||
115 | $fulltext['url'] = $file['location']; |
||
116 | if ($this->settings['useInternalProxy']) { |
||
117 | $this->configureProxyUrl($fulltext['url']); |
||
118 | } |
||
119 | $fulltext['mimetype'] = $file['mimeType']; |
||
120 | break; |
||
121 | } else { |
||
122 | $this->logger->notice('No full-text file found for page "' . $page . '" in fileGrp "' . $fileGrpFulltext . '"'); |
||
123 | } |
||
124 | } |
||
125 | if (empty($fulltext)) { |
||
126 | $this->logger->notice('No full-text file found for page "' . $page . '" in fileGrps "' . $this->extConf['files']['fileGrpFulltext'] . '"'); |
||
127 | } |
||
128 | return $fulltext; |
||
129 | } |
||
130 | |||
131 | /** |
||
132 | * Adds Viewer javascript |
||
133 | * |
||
134 | * @access protected |
||
135 | * |
||
136 | * @return void |
||
137 | */ |
||
138 | protected function addViewerJS(): void |
||
139 | { |
||
140 | // Viewer configuration. |
||
141 | $viewerConfiguration = '$(document).ready(function() { |
||
142 | if (dlfUtils.exists(dlfViewer)) { |
||
143 | tx_dlf_viewer = new dlfViewer({ |
||
144 | controls: ["' . implode('", "', $this->controls) . '"], |
||
145 | div: "' . $this->settings['elementId'] . '", |
||
146 | progressElementId: "' . $this->settings['progressElementId'] . '", |
||
147 | images: ' . json_encode($this->images) . ', |
||
148 | fulltexts: ' . json_encode($this->fulltexts) . ', |
||
149 | annotationContainers: ' . json_encode($this->annotationContainers) . ', |
||
150 | useInternalProxy: ' . ($this->settings['useInternalProxy'] ? 1 : 0) . ' |
||
151 | }); |
||
152 | } |
||
153 | });'; |
||
154 | $this->view->assign('viewerConfiguration', $viewerConfiguration); |
||
155 | } |
||
156 | |||
157 | /** |
||
158 | * Get all AnnotationPages / AnnotationLists that contain text Annotations with motivation "painting" |
||
159 | * |
||
160 | * @access protected |
||
161 | * |
||
162 | * @param int $page Page number |
||
163 | * @return array An array containing the IRIs of the AnnotationLists / AnnotationPages as well as some information about the canvas. |
||
164 | */ |
||
165 | protected function getAnnotationContainers(int $page): array |
||
166 | { |
||
167 | if ($this->document->getCurrentDocument() instanceof IiifManifest) { |
||
168 | $canvasId = $this->document->getCurrentDocument()->physicalStructure[$page]; |
||
169 | $iiif = $this->document->getCurrentDocument()->getIiif(); |
||
170 | if ($iiif instanceof ManifestInterface) { |
||
171 | $canvas = $iiif->getContainedResourceById($canvasId); |
||
172 | /* @var $canvas \Ubl\Iiif\Presentation\Common\Model\Resources\CanvasInterface */ |
||
173 | if ($canvas != null && !empty($canvas->getPossibleTextAnnotationContainers(Motivation::PAINTING))) { |
||
174 | $annotationContainers = []; |
||
175 | /* |
||
176 | * TODO Analyzing the annotations on the server side requires loading the annotation lists / pages |
||
177 | * just to determine whether they contain text annotations for painting. This will take time and lead to a bad user experience. |
||
178 | * It would be better to link every annotation and analyze the data on the client side. |
||
179 | * |
||
180 | * On the other hand, server connections are potentially better than client connections. Downloading annotation lists |
||
181 | */ |
||
182 | foreach ($canvas->getPossibleTextAnnotationContainers(Motivation::PAINTING) as $annotationContainer) { |
||
183 | if (($textAnnotations = $annotationContainer->getTextAnnotations(Motivation::PAINTING)) != null) { |
||
184 | foreach ($textAnnotations as $annotation) { |
||
185 | if ( |
||
186 | $annotation->getBody()->getFormat() == 'text/plain' |
||
187 | && $annotation->getBody()->getChars() != null |
||
188 | ) { |
||
189 | $annotationListData = []; |
||
190 | $annotationListData['uri'] = $annotationContainer->getId(); |
||
191 | $annotationListData['label'] = $annotationContainer->getLabelForDisplay(); |
||
192 | $annotationContainers[] = $annotationListData; |
||
193 | break; |
||
194 | } |
||
195 | } |
||
196 | } |
||
197 | } |
||
198 | $result = [ |
||
199 | 'canvas' => [ |
||
200 | 'id' => $canvas->getId(), |
||
201 | 'width' => $canvas->getWidth(), |
||
202 | 'height' => $canvas->getHeight(), |
||
203 | ], |
||
204 | 'annotationContainers' => $annotationContainers |
||
205 | ]; |
||
206 | return $result; |
||
207 | } |
||
208 | } |
||
209 | } |
||
210 | return []; |
||
211 | } |
||
212 | |||
213 | /** |
||
214 | * Get image's URL and MIME type |
||
215 | * |
||
216 | * @access protected |
||
217 | * |
||
218 | * @param int $page Page number |
||
219 | * |
||
220 | * @return array URL and MIME type of image file |
||
221 | */ |
||
222 | protected function getImage(int $page): array |
||
223 | { |
||
224 | $image = []; |
||
225 | // Get @USE value of METS fileGrp. |
||
226 | $fileGrpsImages = GeneralUtility::trimExplode(',', $this->extConf['files']['fileGrpImages']); |
||
227 | while ($fileGrpImages = array_pop($fileGrpsImages)) { |
||
228 | // Get image link. |
||
229 | $physicalStructureInfo = $this->document->getCurrentDocument()->physicalStructureInfo[$this->document->getCurrentDocument()->physicalStructure[$page]]; |
||
230 | $fileId = $physicalStructureInfo['files'][$fileGrpImages]; |
||
231 | if (!empty($fileId)) { |
||
232 | $file = $this->document->getCurrentDocument()->getFileInfo($fileId); |
||
233 | $image['url'] = $file['location']; |
||
234 | $image['mimetype'] = $file['mimeType']; |
||
235 | |||
236 | // Only deliver static images via the internal PageViewProxy. |
||
237 | // (For IIP and IIIF, the viewer needs to build and access a separate metadata URL, see `getMetadataURL` in `OLSources.js`.) |
||
238 | if ($this->settings['useInternalProxy'] && !str_contains(strtolower($image['mimetype']), 'application')) { |
||
239 | $this->configureProxyUrl($image['url']); |
||
240 | } |
||
241 | break; |
||
242 | } else { |
||
243 | $this->logger->notice('No image file found for page "' . $page . '" in fileGrp "' . $fileGrpImages . '"'); |
||
244 | } |
||
245 | } |
||
246 | if (empty($image)) { |
||
247 | $this->logger->warning('No image file found for page "' . $page . '" in fileGrps "' . $this->extConf['files']['fileGrpImages'] . '"'); |
||
248 | } |
||
249 | return $image; |
||
250 | } |
||
251 | } |
||
252 |
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.