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\Helper; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Plugin 'Page Grid' for the 'dlf' extension |
19
|
|
|
* |
20
|
|
|
* @author Henrik Lochmann <[email protected]> |
21
|
|
|
* @author Sebastian Meyer <[email protected]> |
22
|
|
|
* @package TYPO3 |
23
|
|
|
* @subpackage dlf |
24
|
|
|
* @access public |
25
|
|
|
*/ |
26
|
|
|
class PageGrid extends \Kitodo\Dlf\Common\AbstractPlugin |
27
|
|
|
{ |
28
|
|
|
public $scriptRelPath = 'Classes/Plugin/PageGrid.php'; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Renders entry for one page of the current document. |
32
|
|
|
* |
33
|
|
|
* @access protected |
34
|
|
|
* |
35
|
|
|
* @param int $number: The page to render |
36
|
|
|
* @param string $template: Parsed template subpart |
37
|
|
|
* |
38
|
|
|
* @return string The rendered entry ready for output |
39
|
|
|
*/ |
40
|
|
|
protected function getEntry($number, $template) |
41
|
|
|
{ |
42
|
|
|
// Set current page if applicable. |
43
|
|
|
if (!empty($this->piVars['page']) && $this->piVars['page'] == $number) { |
44
|
|
|
$markerArray['###STATE###'] = 'cur'; |
45
|
|
|
} else { |
46
|
|
|
$markerArray['###STATE###'] = 'no'; |
47
|
|
|
} |
48
|
|
|
// Set page number. |
49
|
|
|
$markerArray['###NUMBER###'] = $number; |
50
|
|
|
// Set pagination. |
51
|
|
|
$markerArray['###PAGINATION###'] = htmlspecialchars($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$number]]['orderlabel']); |
52
|
|
|
// Get thumbnail or placeholder. |
53
|
|
|
if (!empty($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$number]]['files'][$this->conf['fileGrpThumbs']])) { |
54
|
|
|
$thumbnailFile = $this->doc->getFileLocation($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$number]]['files'][$this->conf['fileGrpThumbs']]); |
55
|
|
|
} elseif (!empty($this->conf['placeholder'])) { |
56
|
|
|
$thumbnailFile = $GLOBALS['TSFE']->tmpl->getFileName($this->conf['placeholder']); |
57
|
|
|
} else { |
58
|
|
|
$thumbnailFile = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey) . 'Resources/Public/Images/PageGridPlaceholder.jpg'; |
|
|
|
|
59
|
|
|
} |
60
|
|
|
$thumbnail = '<img alt="' . $markerArray['###PAGINATION###'] . '" src="' . $thumbnailFile . '" />'; |
61
|
|
|
// Get new plugin variables for typolink. |
62
|
|
|
$piVars = $this->piVars; |
63
|
|
|
// Unset no longer needed plugin variables. |
64
|
|
|
// unset($piVars['pagegrid']) is for DFG Viewer compatibility! |
65
|
|
|
unset($piVars['pointer'], $piVars['DATA'], $piVars['pagegrid']); |
66
|
|
|
$piVars['page'] = $number; |
67
|
|
|
$linkConf = [ |
68
|
|
|
'useCacheHash' => 1, |
69
|
|
|
'parameter' => $this->conf['targetPid'], |
70
|
|
|
'forceAbsoluteUrl' => !empty($this->conf['forceAbsoluteUrl']) ? 1 : 0, |
71
|
|
|
'forceAbsoluteUrl.' => ['scheme' => !empty($this->conf['forceAbsoluteUrl']) && !empty($this->conf['forceAbsoluteUrlHttps']) ? 'https' : 'http'], |
72
|
|
|
'additionalParams' => \TYPO3\CMS\Core\Utility\GeneralUtility::implodeArrayForUrl($this->prefixId, $piVars, '', true, false), |
73
|
|
|
'title' => $markerArray['###PAGINATION###'] |
74
|
|
|
]; |
75
|
|
|
$markerArray['###THUMBNAIL###'] = $this->cObj->typoLink($thumbnail, $linkConf); |
76
|
|
|
return $this->templateService->substituteMarkerArray($template, $markerArray); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Renders the page browser |
81
|
|
|
* |
82
|
|
|
* @access protected |
83
|
|
|
* |
84
|
|
|
* @return string The rendered page browser ready for output |
85
|
|
|
*/ |
86
|
|
|
protected function getPageBrowser() |
87
|
|
|
{ |
88
|
|
|
// Get overall number of pages. |
89
|
|
|
$maxPages = intval(ceil($this->doc->numPages / $this->conf['limit'])); |
90
|
|
|
// Return empty pagebrowser if there is just one page. |
91
|
|
|
if ($maxPages < 2) { |
92
|
|
|
return ''; |
93
|
|
|
} |
94
|
|
|
// Get separator. |
95
|
|
|
$separator = $this->pi_getLL('separator', ' - ', true); |
96
|
|
|
// Add link to previous page. |
97
|
|
|
if ($this->piVars['pointer'] > 0) { |
98
|
|
|
$output = $this->pi_linkTP_keepPIvars($this->pi_getLL('prevPage', '<', true), ['pointer' => $this->piVars['pointer'] - 1, 'page' => (($this->piVars['pointer'] - 1) * $this->conf['limit']) + 1], true) . $separator; |
99
|
|
|
} else { |
100
|
|
|
$output = '<span class="prev-page not-active">' . $this->pi_getLL('prevPage', '<', true) . '</span>' . $separator; |
101
|
|
|
} |
102
|
|
|
$i = 0; |
103
|
|
|
// Add links to pages. |
104
|
|
|
while ($i < $maxPages) { |
105
|
|
|
if ($i < 3 || ($i > $this->piVars['pointer'] - 3 && $i < $this->piVars['pointer'] + 3) || $i > $maxPages - 4) { |
106
|
|
|
if ($this->piVars['pointer'] != $i) { |
107
|
|
|
$output .= $this->pi_linkTP_keepPIvars(sprintf($this->pi_getLL('page', '%d', true), $i + 1), ['pointer' => $i, 'page' => ($i * $this->conf['limit']) + 1], true) . $separator; |
108
|
|
|
} else { |
109
|
|
|
$output .= '<span class="active">' . sprintf($this->pi_getLL('page', '%d', true), $i + 1) . '</span>' . $separator; |
110
|
|
|
} |
111
|
|
|
$skip = true; |
112
|
|
|
} elseif ($skip == true) { |
|
|
|
|
113
|
|
|
$output .= '<span class="skipped">' . $this->pi_getLL('skip', '...', true) . '</span>' . $separator; |
114
|
|
|
$skip = false; |
115
|
|
|
} |
116
|
|
|
$i++; |
117
|
|
|
} |
118
|
|
|
// Add link to next page. |
119
|
|
|
if ($this->piVars['pointer'] < $maxPages - 1) { |
120
|
|
|
$output .= $this->pi_linkTP_keepPIvars($this->pi_getLL('nextPage', '>', true), ['pointer' => $this->piVars['pointer'] + 1, 'page' => ($this->piVars['pointer'] + 1) * $this->conf['limit'] + 1], true); |
121
|
|
|
} else { |
122
|
|
|
$output .= '<span class="next-page not-active">' . $this->pi_getLL('nextPage', '>', true) . '</span>'; |
123
|
|
|
} |
124
|
|
|
return $output; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* The main method of the PlugIn |
129
|
|
|
* |
130
|
|
|
* @access public |
131
|
|
|
* |
132
|
|
|
* @param string $content: The PlugIn content |
133
|
|
|
* @param array $conf: The PlugIn configuration |
134
|
|
|
* |
135
|
|
|
* @return string The content that is displayed on the website |
136
|
|
|
*/ |
137
|
|
|
public function main($content, $conf) |
138
|
|
|
{ |
139
|
|
|
$this->init($conf); |
140
|
|
|
$this->loadDocument(); |
141
|
|
|
if ( |
142
|
|
|
$this->doc === null |
143
|
|
|
|| $this->doc->numPages < 1 |
144
|
|
|
|| empty($this->conf['fileGrpThumbs']) |
145
|
|
|
) { |
146
|
|
|
// Quit without doing anything if required variables are not set. |
147
|
|
|
return $content; |
148
|
|
|
} else { |
149
|
|
|
// Set default values for page if not set. |
150
|
|
|
$this->piVars['pointer'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($this->piVars['pointer'], 0, $this->doc->numPages, 0); |
|
|
|
|
151
|
|
|
} |
152
|
|
|
// Load template file. |
153
|
|
|
$this->getTemplate(); |
154
|
|
|
$entryTemplate = $this->templateService->getSubpart($this->template, '###ENTRY###'); |
155
|
|
|
if (empty($entryTemplate)) { |
156
|
|
|
Helper::devLog('No template subpart for list entry found', DEVLOG_SEVERITY_WARNING); |
157
|
|
|
// Quit without doing anything if required variables are not set. |
158
|
|
|
return $content; |
159
|
|
|
} |
160
|
|
|
if (!empty($this->piVars['logicalPage'])) { |
161
|
|
|
$this->piVars['page'] = $this->doc->getPhysicalPage($this->piVars['logicalPage']); |
162
|
|
|
// The logical page parameter should not appear |
163
|
|
|
unset($this->piVars['logicalPage']); |
164
|
|
|
} |
165
|
|
|
// Set some variable defaults. |
166
|
|
|
// $this->piVars['page'] may be integer or string (physical structure @ID) |
167
|
|
|
if ( |
168
|
|
|
(int) $this->piVars['page'] > 0 |
169
|
|
|
|| empty($this->piVars['page']) |
170
|
|
|
) { |
171
|
|
|
$this->piVars['page'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange((int) $this->piVars['page'], 1, $this->doc->numPages, 1); |
172
|
|
|
} else { |
173
|
|
|
$this->piVars['page'] = array_search($this->piVars['page'], $this->doc->physicalStructure); |
174
|
|
|
} |
175
|
|
|
if (!empty($this->piVars['page'])) { |
176
|
|
|
$this->piVars['pointer'] = intval(floor(($this->piVars['page'] - 1) / $this->conf['limit'])); |
177
|
|
|
} |
178
|
|
|
if ( |
179
|
|
|
!empty($this->piVars['pointer']) |
180
|
|
|
&& (($this->piVars['pointer'] * $this->conf['limit']) + 1) <= $this->doc->numPages |
181
|
|
|
) { |
182
|
|
|
$this->piVars['pointer'] = max(intval($this->piVars['pointer']), 0); |
183
|
|
|
} else { |
184
|
|
|
$this->piVars['pointer'] = 0; |
185
|
|
|
} |
186
|
|
|
// Iterate through visible page set and display thumbnails. |
187
|
|
|
for ($i = $this->piVars['pointer'] * $this->conf['limit'], $j = ($this->piVars['pointer'] + 1) * $this->conf['limit']; $i < $j; $i++) { |
188
|
|
|
// +1 because page counting starts at 1. |
189
|
|
|
$number = $i + 1; |
190
|
|
|
if ($number > $this->doc->numPages) { |
191
|
|
|
break; |
192
|
|
|
} else { |
193
|
|
|
$content .= $this->getEntry($number, $entryTemplate); |
194
|
|
|
} |
195
|
|
|
} |
196
|
|
|
// Render page browser. |
197
|
|
|
$markerArray['###PAGEBROWSER###'] = $this->getPageBrowser(); |
198
|
|
|
// Merge everything with template. |
199
|
|
|
$content = $this->templateService->substituteMarkerArray($this->templateService->substituteSubpart($this->template, '###ENTRY###', $content, true), $markerArray); |
200
|
|
|
return $this->pi_wrapInBaseClass($content); |
201
|
|
|
} |
202
|
|
|
} |
203
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.