|
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\Plugin; |
|
14
|
|
|
|
|
15
|
|
|
use Kitodo\Dlf\Common\DocumentList; |
|
16
|
|
|
use Kitodo\Dlf\Common\Helper; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Plugin 'Navigation' for the 'dlf' extension |
|
20
|
|
|
* |
|
21
|
|
|
* @author Sebastian Meyer <[email protected]> |
|
22
|
|
|
* @package TYPO3 |
|
23
|
|
|
* @subpackage dlf |
|
24
|
|
|
* @access public |
|
25
|
|
|
*/ |
|
26
|
|
|
class Navigation extends \Kitodo\Dlf\Common\AbstractPlugin |
|
27
|
|
|
{ |
|
28
|
|
|
public $scriptRelPath = 'Classes/Plugin/Navigation.php'; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Display a link to the list view |
|
32
|
|
|
* |
|
33
|
|
|
* @access protected |
|
34
|
|
|
* |
|
35
|
|
|
* @return string Link to the list view ready to output |
|
36
|
|
|
*/ |
|
37
|
|
|
protected function getLinkToListview() |
|
38
|
|
|
{ |
|
39
|
|
|
if (!empty($this->conf['targetPid'])) { |
|
40
|
|
|
// Load the list. |
|
41
|
|
|
$list = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(DocumentList::class); |
|
42
|
|
|
if (count($list) > 0) { |
|
43
|
|
|
// Build typolink configuration array. |
|
44
|
|
|
$conf = [ |
|
45
|
|
|
'useCacheHash' => 1, |
|
46
|
|
|
'parameter' => $this->conf['targetPid'], |
|
47
|
|
|
'forceAbsoluteUrl' => !empty($this->conf['forceAbsoluteUrl']) ? 1 : 0, |
|
48
|
|
|
'forceAbsoluteUrl.' => ['scheme' => !empty($this->conf['forceAbsoluteUrl']) && !empty($this->conf['forceAbsoluteUrlHttps']) ? 'https' : 'http'], |
|
49
|
|
|
'title' => $this->pi_getLL('linkToList', '', true) |
|
50
|
|
|
]; |
|
51
|
|
|
return $this->cObj->typoLink($this->pi_getLL('linkToList', '', true), $conf); |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
return ''; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Display the page selector for the page view |
|
59
|
|
|
* |
|
60
|
|
|
* @access protected |
|
61
|
|
|
* |
|
62
|
|
|
* @return string Page selector ready to output |
|
63
|
|
|
*/ |
|
64
|
|
|
protected function getPageSelector() |
|
65
|
|
|
{ |
|
66
|
|
|
// Configure @action URL for form. |
|
67
|
|
|
$linkConf = [ |
|
68
|
|
|
'parameter' => $GLOBALS['TSFE']->id, |
|
69
|
|
|
'forceAbsoluteUrl' => !empty($this->conf['forceAbsoluteUrl']) ? 1 : 0, |
|
70
|
|
|
'forceAbsoluteUrl.' => ['scheme' => !empty($this->conf['forceAbsoluteUrl']) && !empty($this->conf['forceAbsoluteUrlHttps']) ? 'https' : 'http'] |
|
71
|
|
|
]; |
|
72
|
|
|
$output = '<form action="' . $this->cObj->typoLink_URL($linkConf) . '" method="get"><div><input type="hidden" name="id" value="' . $GLOBALS['TSFE']->id . '" />'; |
|
73
|
|
|
// Add plugin variables. |
|
74
|
|
|
foreach ($this->piVars as $piVar => $value) { |
|
75
|
|
|
if ($piVar != 'page' && $piVar != 'DATA' && !empty($value)) { |
|
76
|
|
|
$output .= '<input type="hidden" name="' . $this->prefixId . '[' . $piVar . ']" value="' . $value . '" />'; |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
// Add page selector. |
|
80
|
|
|
$uniqId = uniqid(Helper::getUnqualifiedClassName(get_class($this)) . '-'); |
|
81
|
|
|
$output .= '<label for="' . $uniqId . '">' . $this->pi_getLL('selectPage', '', true) . '</label><select id="' . $uniqId . '" name="' . $this->prefixId . '[page]" onchange="javascript:this.form.submit();"' . ($this->doc->numPages < 1 ? ' disabled="disabled"' : '') . '>'; |
|
82
|
|
|
for ($i = 1; $i <= $this->doc->numPages; $i++) { |
|
83
|
|
|
$output .= '<option value="' . $i . '"' . ($this->piVars['page'] == $i ? ' selected="selected"' : '') . '>[' . $i . ']' . ($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$i]]['orderlabel'] ? ' - ' . htmlspecialchars($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$i]]['orderlabel']) : '') . '</option>'; |
|
84
|
|
|
} |
|
85
|
|
|
$output .= '</select></div></form>'; |
|
86
|
|
|
return $output; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* The main method of the PlugIn |
|
91
|
|
|
* |
|
92
|
|
|
* @access public |
|
93
|
|
|
* |
|
94
|
|
|
* @param string $content: The PlugIn content |
|
95
|
|
|
* @param array $conf: The PlugIn configuration |
|
96
|
|
|
* |
|
97
|
|
|
* @return string The content that is displayed on the website |
|
98
|
|
|
*/ |
|
99
|
|
|
public function main($content, $conf) |
|
100
|
|
|
{ |
|
101
|
|
|
$this->init($conf); |
|
102
|
|
|
// Turn cache on. |
|
103
|
|
|
$this->setCache(true); |
|
104
|
|
|
// Load current document. |
|
105
|
|
|
$this->loadDocument(); |
|
106
|
|
|
if ($this->doc === null) { |
|
107
|
|
|
// Quit without doing anything if required variables are not set. |
|
108
|
|
|
return $content; |
|
109
|
|
|
} else { |
|
110
|
|
|
// Set default values if not set. |
|
111
|
|
|
if ($this->doc->numPages > 0) { |
|
112
|
|
|
if (!empty($this->piVars['logicalPage'])) { |
|
113
|
|
|
$this->piVars['page'] = $this->doc->getPhysicalPage($this->piVars['logicalPage']); |
|
|
|
|
|
|
114
|
|
|
// The logical page parameter should not appear |
|
115
|
|
|
unset($this->piVars['logicalPage']); |
|
116
|
|
|
} |
|
117
|
|
|
// Set default values if not set. |
|
118
|
|
|
// $this->piVars['page'] may be integer or string (physical structure @ID) |
|
119
|
|
|
if ( |
|
120
|
|
|
(int) $this->piVars['page'] > 0 |
|
121
|
|
|
|| empty($this->piVars['page']) |
|
122
|
|
|
) { |
|
123
|
|
|
$this->piVars['page'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange((int) $this->piVars['page'], 1, $this->doc->numPages, 1); |
|
124
|
|
|
} else { |
|
125
|
|
|
$this->piVars['page'] = array_search($this->piVars['page'], $this->doc->physicalStructure); |
|
126
|
|
|
} |
|
127
|
|
|
$this->piVars['double'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($this->piVars['double'], 0, 1, 0); |
|
128
|
|
|
} else { |
|
129
|
|
|
$this->piVars['page'] = 0; |
|
130
|
|
|
$this->piVars['double'] = 0; |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
// Load template file. |
|
134
|
|
|
$this->getTemplate(); |
|
135
|
|
|
// Steps for X pages backward / forward. Double page view uses double steps. |
|
136
|
|
|
$pageSteps = $this->conf['pageStep'] * ($this->piVars['double'] + 1); |
|
137
|
|
|
// Link to first page. |
|
138
|
|
|
if ($this->piVars['page'] > 1) { |
|
139
|
|
|
$markerArray['###FIRST###'] = $this->makeLink($this->pi_getLL('firstPage', '', true), ['page' => 1]); |
|
140
|
|
|
} else { |
|
141
|
|
|
$markerArray['###FIRST###'] = '<span title="' . $this->pi_getLL('firstPage', '', true) . '">' . $this->pi_getLL('firstPage', '', true) . '</span>'; |
|
142
|
|
|
} |
|
143
|
|
|
// Link back X pages. |
|
144
|
|
|
if ($this->piVars['page'] > $pageSteps) { |
|
145
|
|
|
$markerArray['###BACK###'] = $this->makeLink(sprintf($this->pi_getLL('backXPages', '', true), $pageSteps), ['page' => $this->piVars['page'] - $pageSteps]); |
|
146
|
|
|
} else { |
|
147
|
|
|
$markerArray['###BACK###'] = '<span title="' . sprintf($this->pi_getLL('backXPages', '', true), $pageSteps) . '">' . sprintf($this->pi_getLL('backXPages', '', true), $pageSteps) . '</span>'; |
|
148
|
|
|
} |
|
149
|
|
|
// Link to previous page. |
|
150
|
|
|
if ($this->piVars['page'] > (1 + $this->piVars['double'])) { |
|
151
|
|
|
$markerArray['###PREVIOUS###'] = $this->makeLink($this->pi_getLL('prevPage', '', true), ['page' => $this->piVars['page'] - (1 + $this->piVars['double'])]); |
|
152
|
|
|
} else { |
|
153
|
|
|
$markerArray['###PREVIOUS###'] = '<span title="' . $this->pi_getLL('prevPage', '', true) . '">' . $this->pi_getLL('prevPage', '', true) . '</span>'; |
|
154
|
|
|
} |
|
155
|
|
|
// Link to next page. |
|
156
|
|
|
if ($this->piVars['page'] < ($this->doc->numPages - $this->piVars['double'])) { |
|
157
|
|
|
$markerArray['###NEXT###'] = $this->makeLink($this->pi_getLL('nextPage', '', true), ['page' => $this->piVars['page'] + (1 + $this->piVars['double'])]); |
|
158
|
|
|
} else { |
|
159
|
|
|
$markerArray['###NEXT###'] = '<span title="' . $this->pi_getLL('nextPage', '', true) . '">' . $this->pi_getLL('nextPage', '', true) . '</span>'; |
|
160
|
|
|
} |
|
161
|
|
|
// Link forward X pages. |
|
162
|
|
|
if ($this->piVars['page'] <= ($this->doc->numPages - $pageSteps)) { |
|
163
|
|
|
$markerArray['###FORWARD###'] = $this->makeLink(sprintf($this->pi_getLL('forwardXPages', '', true), $pageSteps), ['page' => $this->piVars['page'] + $pageSteps]); |
|
164
|
|
|
} else { |
|
165
|
|
|
$markerArray['###FORWARD###'] = '<span title="' . sprintf($this->pi_getLL('forwardXPages', '', true), $pageSteps) . '">' . sprintf($this->pi_getLL('forwardXPages', '', true), $pageSteps) . '</span>'; |
|
166
|
|
|
} |
|
167
|
|
|
// Link to last page. |
|
168
|
|
|
if ($this->piVars['page'] < $this->doc->numPages) { |
|
169
|
|
|
$markerArray['###LAST###'] = $this->makeLink($this->pi_getLL('lastPage', '', true), ['page' => $this->doc->numPages]); |
|
170
|
|
|
} else { |
|
171
|
|
|
$markerArray['###LAST###'] = '<span title="' . $this->pi_getLL('lastPage', '', true) . '">' . $this->pi_getLL('lastPage', '', true) . '</span>'; |
|
172
|
|
|
} |
|
173
|
|
|
// Add double page switcher. |
|
174
|
|
|
if ($this->doc->numPages > 0) { |
|
175
|
|
|
if (!$this->piVars['double']) { |
|
176
|
|
|
$markerArray['###DOUBLEPAGE###'] = $this->makeLink($this->pi_getLL('doublePageOn', '', true), ['double' => 1], 'class="tx-dlf-navigation-doubleOn" title="' . $this->pi_getLL('doublePageOn', '', true) . '"'); |
|
177
|
|
|
} else { |
|
178
|
|
|
$markerArray['###DOUBLEPAGE###'] = $this->makeLink($this->pi_getLL('doublePageOff', '', true), ['double' => 0], 'class="tx-dlf-navigation-doubleOff" title="' . $this->pi_getLL('doublePageOff', '', true) . '"'); |
|
179
|
|
|
} |
|
180
|
|
|
if ($this->piVars['double'] && $this->piVars['page'] < $this->doc->numPages) { |
|
181
|
|
|
$markerArray['###DOUBLEPAGE+1###'] = $this->makeLink($this->pi_getLL('doublePage+1', '', true), ['page' => $this->piVars['page'] + 1], 'title="' . $this->pi_getLL('doublePage+1', '', true) . '"'); |
|
182
|
|
|
} else { |
|
183
|
|
|
$markerArray['###DOUBLEPAGE+1###'] = '<span title="' . $this->pi_getLL('doublePage+1', '', true) . '">' . $this->pi_getLL('doublePage+1', '', true) . '</span>'; |
|
184
|
|
|
} |
|
185
|
|
|
} else { |
|
186
|
|
|
$markerArray['###DOUBLEPAGE###'] = '<span title="' . $this->pi_getLL('doublePageOn', '', true) . '">' . $this->pi_getLL('doublePageOn', '', true) . '</span>'; |
|
187
|
|
|
$markerArray['###DOUBLEPAGE+1###'] = '<span title="' . $this->pi_getLL('doublePage+1', '', true) . '">' . $this->pi_getLL('doublePage+1', '', true) . '</span>'; |
|
188
|
|
|
} |
|
189
|
|
|
// Add page selector. |
|
190
|
|
|
$markerArray['###PAGESELECT###'] = $this->getPageSelector(); |
|
191
|
|
|
// Add link to listview if applicable. |
|
192
|
|
|
$markerArray['###LINKLISTVIEW###'] = $this->getLinkToListview(); |
|
193
|
|
|
// Fill some language labels if available. |
|
194
|
|
|
$markerArray['###ZOOM_IN###'] = $this->pi_getLL('zoom-in', '', true); |
|
195
|
|
|
$markerArray['###ZOOM_OUT###'] = $this->pi_getLL('zoom-out', '', true); |
|
196
|
|
|
$markerArray['###ZOOM_FULLSCREEN###'] = $this->pi_getLL('zoom-fullscreen', '', true); |
|
197
|
|
|
$markerArray['###ROTATE_LEFT###'] = $this->pi_getLL('rotate-left', '', true); |
|
198
|
|
|
$markerArray['###ROTATE_RIGHT###'] = $this->pi_getLL('rotate-right', '', true); |
|
199
|
|
|
$markerArray['###ROTATE_RESET###'] = $this->pi_getLL('rotate-reset', '', true); |
|
200
|
|
|
$content .= $this->templateService->substituteMarkerArray($this->template, $markerArray); |
|
201
|
|
|
return $this->pi_wrapInBaseClass($content); |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
/** |
|
205
|
|
|
* Generates a navigation link |
|
206
|
|
|
* |
|
207
|
|
|
* @access protected |
|
208
|
|
|
* |
|
209
|
|
|
* @param string $label: The link's text |
|
210
|
|
|
* @param array $overrulePIvars: The new set of plugin variables |
|
211
|
|
|
* @paramstring $aTagParams: Additional HTML attributes for link tag |
|
212
|
|
|
* |
|
213
|
|
|
* @return string Typolink ready to output |
|
214
|
|
|
*/ |
|
215
|
|
|
protected function makeLink($label, array $overrulePIvars = [], $aTagParams = '') |
|
216
|
|
|
{ |
|
217
|
|
|
// Merge plugin variables with new set of values. |
|
218
|
|
|
if (is_array($this->piVars)) { |
|
219
|
|
|
$piVars = $this->piVars; |
|
220
|
|
|
unset($piVars['DATA']); |
|
221
|
|
|
$overrulePIvars = Helper::mergeRecursiveWithOverrule($piVars, $overrulePIvars); |
|
222
|
|
|
} |
|
223
|
|
|
// Build typolink configuration array. |
|
224
|
|
|
$conf = [ |
|
225
|
|
|
'useCacheHash' => 1, |
|
226
|
|
|
'parameter' => $GLOBALS['TSFE']->id, |
|
227
|
|
|
'forceAbsoluteUrl' => !empty($this->conf['forceAbsoluteUrl']) ? 1 : 0, |
|
228
|
|
|
'forceAbsoluteUrl.' => ['scheme' => !empty($this->conf['forceAbsoluteUrl']) && !empty($this->conf['forceAbsoluteUrlHttps']) ? 'https' : 'http'], |
|
229
|
|
|
'ATagParams' => $aTagParams, |
|
230
|
|
|
'additionalParams' => \TYPO3\CMS\Core\Utility\GeneralUtility::implodeArrayForUrl($this->prefixId, $overrulePIvars, '', true, false), |
|
231
|
|
|
'title' => $label |
|
232
|
|
|
]; |
|
233
|
|
|
return $this->cObj->typoLink($label, $conf); |
|
234
|
|
|
} |
|
235
|
|
|
} |
|
236
|
|
|
|