1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* (c) Kitodo. Key to digital objects e.V. <[email protected]> |
5
|
|
|
* |
6
|
|
|
* This file is part of the Kitodo and TYPO3 projects. |
7
|
|
|
* |
8
|
|
|
* @license GNU General Public License version 3 or later. |
9
|
|
|
* For the full copyright and license information, please read the |
10
|
|
|
* LICENSE.txt file that was distributed with this source code. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace Kitodo\Dlf\Controller; |
14
|
|
|
|
15
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
16
|
|
|
use TYPO3\CMS\Core\Utility\MathUtility; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Provide document JSON for client side access |
20
|
|
|
* |
21
|
|
|
* @package TYPO3 |
22
|
|
|
* @subpackage dlf |
23
|
|
|
* @access public |
24
|
|
|
*/ |
25
|
|
|
class DocumentController extends AbstractController |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* The main method of the PlugIn |
29
|
|
|
* |
30
|
|
|
* @access public |
31
|
|
|
* |
32
|
|
|
* @param string $content: The PlugIn content |
33
|
|
|
* @param array $conf: The PlugIn configuration |
34
|
|
|
* |
35
|
|
|
* @return string The content that is displayed on the website |
36
|
|
|
*/ |
37
|
|
|
public function mainAction() |
38
|
|
|
{ |
39
|
|
|
// Load current document. |
40
|
|
|
$this->loadDocument($this->requestData); |
41
|
|
|
if ($this->isDocMissingOrEmpty()) { |
42
|
|
|
// Quit without doing anything if required variables are not set. |
43
|
|
|
return; |
44
|
|
|
} else { |
45
|
|
|
if (!empty($this->requestData['logicalPage'])) { |
46
|
|
|
$this->requestData['page'] = $this->document->getDoc()->getPhysicalPage($this->requestData['logicalPage']); |
47
|
|
|
// The logical page parameter should not appear again |
48
|
|
|
unset($this->requestData['logicalPage']); |
49
|
|
|
} |
50
|
|
|
// Set default values if not set. |
51
|
|
|
// $this->requestData['page'] may be integer or string (physical structure @ID) |
52
|
|
|
if ((int) $this->requestData['page'] > 0 || empty($this->requestData['page'])) { |
53
|
|
|
$this->requestData['page'] = MathUtility::forceIntegerInRange((int) $this->requestData['page'], 1, $this->document->getDoc()->numPages, 1); |
54
|
|
|
} else { |
55
|
|
|
$this->requestData['page'] = array_search($this->requestData['page'], $this->document->getDoc()->physicalStructure); |
56
|
|
|
} |
57
|
|
|
$this->requestData['double'] = MathUtility::forceIntegerInRange($this->requestData['double'], 0, 1, 0); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
$doc = $this->document->getDoc(); |
|
|
|
|
61
|
|
|
|
62
|
|
|
if (!empty($this->settings['targetPidMetadata'])) { |
63
|
|
|
$metadataUrl = $this->uriBuilder |
64
|
|
|
->reset() |
65
|
|
|
->setTargetPageUid((int) $this->settings['targetPidMetadata']) |
66
|
|
|
->setCreateAbsoluteUri(true) |
67
|
|
|
->setArguments([ |
68
|
|
|
'tx_dlf' => [ |
69
|
|
|
'id' => $this->requestData['id'], |
70
|
|
|
], |
71
|
|
|
]) |
72
|
|
|
->build(); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
$imageFileGroups = array_reverse(GeneralUtility::trimExplode(',', $this->extConf['fileGrpImages'])); |
76
|
|
|
$fulltextFileGroups = GeneralUtility::trimExplode(',', $this->extConf['fileGrpFulltext']); |
77
|
|
|
$config = [ |
78
|
|
|
'forceAbsoluteUrl' => !empty($this->settings['forceAbsoluteUrl']), |
79
|
|
|
'proxyFileGroups' => !empty($this->settings['useInternalProxy']) |
80
|
|
|
? array_merge($imageFileGroups, $fulltextFileGroups) |
81
|
|
|
: [], |
82
|
|
|
]; |
83
|
|
|
$tx_dlf_loaded = [ |
84
|
|
|
'state' => [ |
85
|
|
|
'documentId' => $this->requestData['id'], |
86
|
|
|
'page' => $this->requestData['page'], |
87
|
|
|
'simultaneousPages' => (int) $this->requestData['double'] + 1, |
88
|
|
|
], |
89
|
|
|
'urlTemplate' => $this->getUrlTemplate(), |
90
|
|
|
'metadataUrl' => $metadataUrl, |
|
|
|
|
91
|
|
|
'fileGroups' => [ |
92
|
|
|
'images' => $imageFileGroups, |
93
|
|
|
'fulltext' => $fulltextFileGroups, |
94
|
|
|
'download' => GeneralUtility::trimExplode(',', $this->extConf['fileGrpDownload']), |
95
|
|
|
], |
96
|
|
|
'document' => $this->document->getDoc()->toArray($this->uriBuilder, $config), |
97
|
|
|
]; |
98
|
|
|
|
99
|
|
|
$docConfiguration = ' |
100
|
|
|
window.addEventListener("DOMContentLoaded", function() { |
101
|
|
|
const tx_dlf_loaded = ' . json_encode($tx_dlf_loaded) . '; |
102
|
|
|
window.dispatchEvent(new CustomEvent("tx-dlf-documentLoaded", { |
103
|
|
|
detail: { |
104
|
|
|
docController: new dlfController(tx_dlf_loaded) |
105
|
|
|
} |
106
|
|
|
})); |
107
|
|
|
});'; |
108
|
|
|
|
109
|
|
|
$this->view->assign('docConfiguration', $docConfiguration); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Get URL template with the following placeholders: |
114
|
|
|
* |
115
|
|
|
* * `PAGE_NO` (for value of `tx_dlf[page]`) |
116
|
|
|
* * `DOUBLE_PAGE` (for value of `tx_dlf[double]`) |
117
|
|
|
* * `PAGE_GRID` (for value of `tx_dlf[pagegrid]`) |
118
|
|
|
* |
119
|
|
|
* @return string |
120
|
|
|
*/ |
121
|
|
|
protected function getUrlTemplate() |
122
|
|
|
{ |
123
|
|
|
// Should work for route enhancers like this: |
124
|
|
|
// |
125
|
|
|
// routeEnhancers: |
126
|
|
|
// KitodoWorkview: |
127
|
|
|
// type: Plugin |
128
|
|
|
// namespace: tx_dlf |
129
|
|
|
// routePath: '/{page}/{double}' |
130
|
|
|
// requirements: |
131
|
|
|
// page: \d+ |
132
|
|
|
// double: 0|1 |
133
|
|
|
|
134
|
|
|
$make = function ($page, $double, $pagegrid) { |
135
|
|
|
$result = $this->uriBuilder->reset() |
136
|
|
|
->setTargetPageUid($GLOBALS['TSFE']->id) |
137
|
|
|
->setCreateAbsoluteUri(!empty($this->settings['forceAbsoluteUrl']) ? true : false) |
138
|
|
|
->setArguments([ |
139
|
|
|
'tx_dlf' => array_merge($this->requestData, [ |
140
|
|
|
'page' => $page, |
141
|
|
|
'double' => $double, |
142
|
|
|
'pagegrid' => $pagegrid |
143
|
|
|
]), |
144
|
|
|
]) |
145
|
|
|
->build(); |
146
|
|
|
|
147
|
|
|
$cHashIdx = strpos($result, '&cHash='); |
148
|
|
|
if ($cHashIdx !== false) { |
149
|
|
|
$result = substr($result, 0, $cHashIdx); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
return $result; |
153
|
|
|
}; |
154
|
|
|
|
155
|
|
|
// Generate two URLs that differ in tx_dlf[page], tx_dlf[double] and tx_dlf[highlight]. |
156
|
|
|
// We don't know the order of these parameters, so use the values for matching. |
157
|
|
|
$first = $make(2, 1, 0); |
158
|
|
|
$second = $make(3, 0, 1); |
159
|
|
|
|
160
|
|
|
$lastIdx = 0; |
161
|
|
|
$result = ''; |
162
|
|
|
for ($i = 0, $len = strlen($first); $i < $len; $i++) { |
163
|
|
|
if ($first[$i] === $second[$i]) { |
164
|
|
|
continue; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
$result .= substr($first, $lastIdx, $i - $lastIdx); |
168
|
|
|
$lastIdx = $i + 1; |
169
|
|
|
|
170
|
|
|
if ($first[$i] === '2') { |
171
|
|
|
$placeholder = 'PAGE_NO'; |
172
|
|
|
} else if ($first[$i] === '1') { |
173
|
|
|
$placeholder = 'DOUBLE_PAGE'; |
174
|
|
|
} else { |
175
|
|
|
$placeholder = 'PAGE_GRID'; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
$result .= $placeholder; |
179
|
|
|
} |
180
|
|
|
$result .= substr($first, $lastIdx); |
181
|
|
|
|
182
|
|
|
return $result; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
} |
186
|
|
|
|