|
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\Tools; |
|
14
|
|
|
|
|
15
|
|
|
use Kitodo\Dlf\Common\Helper; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* PDF Download tool for the plugin 'Toolbox' of the 'dlf' extension |
|
19
|
|
|
* |
|
20
|
|
|
* @author Sebastian Meyer <[email protected]> |
|
21
|
|
|
* @author Alexander Bigga <[email protected]> |
|
22
|
|
|
* @package TYPO3 |
|
23
|
|
|
* @subpackage dlf |
|
24
|
|
|
* @access public |
|
25
|
|
|
*/ |
|
26
|
|
|
class PdfDownloadTool extends \Kitodo\Dlf\Common\AbstractPlugin |
|
27
|
|
|
{ |
|
28
|
|
|
public $scriptRelPath = 'Classes/Plugin/Tools/PdfDownloadTool.php'; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* The main method of the PlugIn |
|
32
|
|
|
* |
|
33
|
|
|
* @access public |
|
34
|
|
|
* |
|
35
|
|
|
* @param string $content: The PlugIn content |
|
36
|
|
|
* @param array $conf: The PlugIn configuration |
|
37
|
|
|
* |
|
38
|
|
|
* @return string The content that is displayed on the website |
|
39
|
|
|
*/ |
|
40
|
|
|
public function main($content, $conf) |
|
41
|
|
|
{ |
|
42
|
|
|
$this->init($conf); |
|
43
|
|
|
// Merge configuration with conf array of toolbox. |
|
44
|
|
|
if (!empty($this->cObj->data['conf'])) { |
|
45
|
|
|
$this->conf = Helper::mergeRecursiveWithOverrule($this->cObj->data['conf'], $this->conf); |
|
|
|
|
|
|
46
|
|
|
} |
|
47
|
|
|
// Load current document. |
|
48
|
|
|
$this->loadDocument(); |
|
49
|
|
|
if ( |
|
50
|
|
|
$this->doc === null |
|
51
|
|
|
|| $this->doc->numPages < 1 |
|
52
|
|
|
|| empty($this->conf['fileGrpDownload']) |
|
53
|
|
|
) { |
|
54
|
|
|
// Quit without doing anything if required variables are not set. |
|
55
|
|
|
return $content; |
|
56
|
|
|
} else { |
|
57
|
|
|
if (!empty($this->piVars['logicalPage'])) { |
|
58
|
|
|
$this->piVars['page'] = $this->doc->getPhysicalPage($this->piVars['logicalPage']); |
|
|
|
|
|
|
59
|
|
|
// The logical page parameter should not appear again |
|
60
|
|
|
unset($this->piVars['logicalPage']); |
|
61
|
|
|
} |
|
62
|
|
|
// Set default values if not set. |
|
63
|
|
|
// $this->piVars['page'] may be integer or string (physical structure @ID) |
|
64
|
|
|
if ( |
|
65
|
|
|
(int) $this->piVars['page'] > 0 |
|
66
|
|
|
|| empty($this->piVars['page']) |
|
67
|
|
|
) { |
|
68
|
|
|
$this->piVars['page'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange((int) $this->piVars['page'], 1, $this->doc->numPages, 1); |
|
69
|
|
|
} else { |
|
70
|
|
|
$this->piVars['page'] = array_search($this->piVars['page'], $this->doc->physicalStructure); |
|
71
|
|
|
} |
|
72
|
|
|
$this->piVars['double'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($this->piVars['double'], 0, 1, 0); |
|
73
|
|
|
} |
|
74
|
|
|
// Load template file. |
|
75
|
|
|
$this->getTemplate(); |
|
76
|
|
|
// Get single page downloads. |
|
77
|
|
|
$markerArray['###PAGE###'] = $this->getPageLink(); |
|
78
|
|
|
// Get work download. |
|
79
|
|
|
$markerArray['###WORK###'] = $this->getWorkLink(); |
|
80
|
|
|
$content .= $this->templateService->substituteMarkerArray($this->template, $markerArray); |
|
81
|
|
|
return $this->pi_wrapInBaseClass($content); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Get page's download link |
|
86
|
|
|
* |
|
87
|
|
|
* @access protected |
|
88
|
|
|
* |
|
89
|
|
|
* @return string Link to downloadable page |
|
90
|
|
|
*/ |
|
91
|
|
|
protected function getPageLink() |
|
92
|
|
|
{ |
|
93
|
|
|
$page1Link = ''; |
|
94
|
|
|
$page2Link = ''; |
|
95
|
|
|
$pageNumber = $this->piVars['page']; |
|
96
|
|
|
// Get image link. |
|
97
|
|
|
$details = $this->doc->physicalStructureInfo[$this->doc->physicalStructure[$pageNumber]]; |
|
98
|
|
|
$file = $details['files'][$this->conf['fileGrpDownload']]; |
|
99
|
|
|
if (!empty($file)) { |
|
100
|
|
|
$page1Link = $this->doc->getFileLocation($file); |
|
101
|
|
|
} |
|
102
|
|
|
// Get second page, too, if double page view is activated. |
|
103
|
|
|
if ( |
|
104
|
|
|
$this->piVars['double'] |
|
105
|
|
|
&& $pageNumber < $this->doc->numPages |
|
106
|
|
|
) { |
|
107
|
|
|
$details = $this->doc->physicalStructureInfo[$this->doc->physicalStructure[$pageNumber + 1]]; |
|
108
|
|
|
$file = $details['files'][$this->conf['fileGrpDownload']]; |
|
109
|
|
|
if (!empty($file)) { |
|
110
|
|
|
$page2Link = $this->doc->getFileLocation($file); |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
if ( |
|
114
|
|
|
empty($page1Link) |
|
115
|
|
|
&& empty($page2Link) |
|
116
|
|
|
) { |
|
117
|
|
|
Helper::devLog('File not found in fileGrp "' . $this->conf['fileGrpDownload'] . '"', DEVLOG_SEVERITY_WARNING); |
|
118
|
|
|
} |
|
119
|
|
|
// Wrap URLs with HTML. |
|
120
|
|
|
$linkConf = [ |
|
121
|
|
|
'forceAbsoluteUrl' => !empty($this->conf['forceAbsoluteUrl']) ? 1 : 0, |
|
122
|
|
|
'forceAbsoluteUrl.' => ['scheme' => !empty($this->conf['forceAbsoluteUrl']) && !empty($this->conf['forceAbsoluteUrlHttps']) ? 'https' : 'http'] |
|
123
|
|
|
]; |
|
124
|
|
|
if (!empty($page1Link)) { |
|
125
|
|
|
$linkConf['parameter'] = $page1Link; |
|
126
|
|
|
if ($this->piVars['double']) { |
|
127
|
|
|
$linkConf['title'] = $this->pi_getLL('leftPage', ''); |
|
128
|
|
|
$page1Link = $this->cObj->typoLink($this->pi_getLL('leftPage', ''), $linkConf); |
|
129
|
|
|
} else { |
|
130
|
|
|
$linkConf['title'] = $this->pi_getLL('singlePage', ''); |
|
131
|
|
|
$page1Link = $this->cObj->typoLink($this->pi_getLL('singlePage', ''), $linkConf); |
|
132
|
|
|
} |
|
133
|
|
|
} |
|
134
|
|
|
if (!empty($page2Link)) { |
|
135
|
|
|
$linkConf['parameter'] = $page2Link; |
|
136
|
|
|
$linkConf['title'] = $this->pi_getLL('rightPage', ''); |
|
137
|
|
|
$page2Link = $this->cObj->typoLink($this->pi_getLL('rightPage', ''), $linkConf); |
|
138
|
|
|
} |
|
139
|
|
|
return $page1Link . $page2Link; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* Get work's download link |
|
144
|
|
|
* |
|
145
|
|
|
* @access protected |
|
146
|
|
|
* |
|
147
|
|
|
* @return string Link to downloadable work |
|
148
|
|
|
*/ |
|
149
|
|
|
protected function getWorkLink() |
|
150
|
|
|
{ |
|
151
|
|
|
$workLink = ''; |
|
152
|
|
|
// Get work link. |
|
153
|
|
|
if (!empty($this->doc->physicalStructureInfo[$this->doc->physicalStructure[0]]['files'][$this->conf['fileGrpDownload']])) { |
|
154
|
|
|
$workLink = $this->doc->getFileLocation($this->doc->physicalStructureInfo[$this->doc->physicalStructure[0]]['files'][$this->conf['fileGrpDownload']]); |
|
155
|
|
|
} else { |
|
156
|
|
|
$details = $this->doc->getLogicalStructure($this->doc->toplevelId); |
|
157
|
|
|
if (!empty($details['files'][$this->conf['fileGrpDownload']])) { |
|
158
|
|
|
$workLink = $this->doc->getFileLocation($details['files'][$this->conf['fileGrpDownload']]); |
|
159
|
|
|
} |
|
160
|
|
|
} |
|
161
|
|
|
// Wrap URLs with HTML. |
|
162
|
|
|
if (!empty($workLink)) { |
|
163
|
|
|
$linkConf = [ |
|
164
|
|
|
'parameter' => $workLink, |
|
165
|
|
|
'forceAbsoluteUrl' => !empty($this->conf['forceAbsoluteUrl']) ? 1 : 0, |
|
166
|
|
|
'forceAbsoluteUrl.' => ['scheme' => !empty($this->conf['forceAbsoluteUrl']) && !empty($this->conf['forceAbsoluteUrlHttps']) ? 'https' : 'http'], |
|
167
|
|
|
'title' => $this->pi_getLL('work', '') |
|
168
|
|
|
]; |
|
169
|
|
|
$workLink = $this->cObj->typoLink($this->pi_getLL('work', ''), $linkConf); |
|
170
|
|
|
} else { |
|
171
|
|
|
Helper::devLog('File not found in fileGrp "' . $this->conf['fileGrpDownload'] . '"', DEVLOG_SEVERITY_WARNING); |
|
172
|
|
|
} |
|
173
|
|
|
return $workLink; |
|
174
|
|
|
} |
|
175
|
|
|
} |
|
176
|
|
|
|