|
1
|
|
|
<?php |
|
2
|
|
|
namespace Kitodo\Dlf\Plugin\Tools; |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* (c) Kitodo. Key to digital objects e.V. <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* This file is part of the Kitodo and TYPO3 projects. |
|
8
|
|
|
* |
|
9
|
|
|
* @license GNU General Public License version 3 or later. |
|
10
|
|
|
* For the full copyright and license information, please read the |
|
11
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* PDF Download tool for the plugin 'Toolbox' of the 'dlf' extension |
|
16
|
|
|
* |
|
17
|
|
|
* @author Sebastian Meyer <[email protected]> |
|
18
|
|
|
* @author Alexander Bigga <[email protected]> |
|
19
|
|
|
* @package TYPO3 |
|
20
|
|
|
* @subpackage dlf |
|
21
|
|
|
* @access public |
|
22
|
|
|
*/ |
|
23
|
|
|
class PdfDownloadTool extends \Kitodo\Dlf\Common\AbstractPlugin { |
|
24
|
|
|
public $scriptRelPath = 'Classes/Plugin/Tools/PdfDownloadTool.php'; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* The main method of the PlugIn |
|
28
|
|
|
* |
|
29
|
|
|
* @access public |
|
30
|
|
|
* |
|
31
|
|
|
* @param string $content: The PlugIn content |
|
32
|
|
|
* @param array $conf: The PlugIn configuration |
|
33
|
|
|
* |
|
34
|
|
|
* @return string The content that is displayed on the website |
|
35
|
|
|
*/ |
|
36
|
|
|
public function main($content, $conf) { |
|
37
|
|
|
$this->init($conf); |
|
38
|
|
|
// Merge configuration with conf array of toolbox. |
|
39
|
|
|
$this->conf = \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($this->cObj->data['conf'], $this->conf); |
|
|
|
|
|
|
40
|
|
|
// Load current document. |
|
41
|
|
|
$this->loadDocument(); |
|
42
|
|
|
if ($this->doc === NULL |
|
43
|
|
|
|| $this->doc->numPages < 1 |
|
|
|
|
|
|
44
|
|
|
|| empty($this->conf['fileGrpDownload'])) { |
|
45
|
|
|
// Quit without doing anything if required variables are not set. |
|
46
|
|
|
return $content; |
|
47
|
|
|
} else { |
|
48
|
|
|
if (!empty($this->piVars['logicalPage'])) { |
|
49
|
|
|
$this->piVars['page'] = $this->doc->getPhysicalPage($this->piVars['logicalPage']); |
|
50
|
|
|
// The logical page parameter should not appear again |
|
51
|
|
|
unset($this->piVars['logicalPage']); |
|
52
|
|
|
} |
|
53
|
|
|
// Set default values if not set. |
|
54
|
|
|
// $this->piVars['page'] may be integer or string (physical structure @ID) |
|
55
|
|
|
if ((int) $this->piVars['page'] > 0 |
|
56
|
|
|
|| empty($this->piVars['page'])) { |
|
57
|
|
|
$this->piVars['page'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange((int) $this->piVars['page'], 1, $this->doc->numPages, 1); |
|
58
|
|
|
} else { |
|
59
|
|
|
$this->piVars['page'] = array_search($this->piVars['page'], $this->doc->physicalStructure); |
|
|
|
|
|
|
60
|
|
|
} |
|
61
|
|
|
$this->piVars['double'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($this->piVars['double'], 0, 1, 0); |
|
62
|
|
|
} |
|
63
|
|
|
// Load template file. |
|
64
|
|
|
$this->getTemplate(); |
|
65
|
|
|
// Get single page downloads. |
|
66
|
|
|
$markerArray['###PAGE###'] = $this->getPageLink(); |
|
|
|
|
|
|
67
|
|
|
// Get work download. |
|
68
|
|
|
$markerArray['###WORK###'] = $this->getWorkLink(); |
|
69
|
|
|
$content .= $this->cObj->substituteMarkerArray($this->template, $markerArray); |
|
|
|
|
|
|
70
|
|
|
return $this->pi_wrapInBaseClass($content); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Get page's download link |
|
75
|
|
|
* |
|
76
|
|
|
* @access protected |
|
77
|
|
|
* |
|
78
|
|
|
* @return string Link to downloadable page |
|
79
|
|
|
*/ |
|
80
|
|
|
protected function getPageLink() { |
|
81
|
|
|
$page1Link = ''; |
|
82
|
|
|
$page2Link = ''; |
|
83
|
|
|
$pageNumber = $this->piVars['page']; |
|
84
|
|
|
// Get image link. |
|
85
|
|
|
$details = $this->doc->physicalStructureInfo[$this->doc->physicalStructure[$pageNumber]]; |
|
|
|
|
|
|
86
|
|
|
$file = $details['files'][$this->conf['fileGrpDownload']]; |
|
87
|
|
|
if (!empty($file)) { |
|
88
|
|
|
$page1Link = $this->doc->getFileLocation($file); |
|
89
|
|
|
} |
|
90
|
|
|
// Get second page, too, if double page view is activated. |
|
91
|
|
|
if ($this->piVars['double'] |
|
92
|
|
|
&& $pageNumber < $this->doc->numPages) { |
|
|
|
|
|
|
93
|
|
|
$details = $this->doc->physicalStructureInfo[$this->doc->physicalStructure[$pageNumber + 1]]; |
|
94
|
|
|
$file = $details['files'][$this->conf['fileGrpDownload']]; |
|
95
|
|
|
if (!empty($file)) { |
|
96
|
|
|
$page2Link = $this->doc->getFileLocation($file); |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
if (empty($page1Link) |
|
100
|
|
|
&& empty($page2Link)) { |
|
101
|
|
|
Helper::devLog('File not found in fileGrp "'.$this->conf['fileGrpDownload'].'"', DEVLOG_SEVERITY_WARNING); |
|
|
|
|
|
|
102
|
|
|
} |
|
103
|
|
|
// Wrap URLs with HTML. |
|
104
|
|
|
if (!empty($page1Link)) { |
|
105
|
|
|
if ($this->piVars['double']) { |
|
106
|
|
|
$page1Link = $this->cObj->typoLink($this->pi_getLL('leftPage', ''), ['parameter' => $page1Link, 'title' => $this->pi_getLL('leftPage', '')]); |
|
107
|
|
|
} else { |
|
108
|
|
|
$page1Link = $this->cObj->typoLink($this->pi_getLL('singlePage', ''), ['parameter' => $page1Link, 'title' => $this->pi_getLL('singlePage', '')]); |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
if (!empty($page2Link)) { |
|
112
|
|
|
$page2Link = $this->cObj->typoLink($this->pi_getLL('rightPage', ''), ['parameter' => $page2Link, 'title' => $this->pi_getLL('rightPage', '')]); |
|
113
|
|
|
} |
|
114
|
|
|
return $page1Link.$page2Link; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* Get work's download link |
|
119
|
|
|
* |
|
120
|
|
|
* @access protected |
|
121
|
|
|
* |
|
122
|
|
|
* @return string Link to downloadable work |
|
123
|
|
|
*/ |
|
124
|
|
|
protected function getWorkLink() { |
|
125
|
|
|
$workLink = ''; |
|
126
|
|
|
// Get work link. |
|
127
|
|
|
if (!empty($this->doc->physicalStructureInfo[$this->doc->physicalStructure[0]]['files'][$this->conf['fileGrpDownload']])) { |
|
|
|
|
|
|
128
|
|
|
$workLink = $this->doc->getFileLocation($this->doc->physicalStructureInfo[$this->doc->physicalStructure[0]]['files'][$this->conf['fileGrpDownload']]); |
|
129
|
|
|
} else { |
|
130
|
|
|
$details = $this->doc->getLogicalStructure($this->doc->toplevelId); |
|
|
|
|
|
|
131
|
|
|
if (!empty($details['files'][$this->conf['fileGrpDownload']])) { |
|
132
|
|
|
$workLink = $this->doc->getFileLocation($details['files'][$this->conf['fileGrpDownload']]); |
|
133
|
|
|
} |
|
134
|
|
|
} |
|
135
|
|
|
// Wrap URLs with HTML. |
|
136
|
|
|
if (!empty($workLink)) { |
|
137
|
|
|
$workLink = $this->cObj->typoLink($this->pi_getLL('work', ''), ['parameter' => $workLink, 'title' => $this->pi_getLL('work', '')]); |
|
138
|
|
|
} else { |
|
139
|
|
|
Helper::devLog('File not found in fileGrp "'.$this->conf['fileGrpDownload'].'"', DEVLOG_SEVERITY_WARNING); |
|
140
|
|
|
} |
|
141
|
|
|
return $workLink; |
|
142
|
|
|
} |
|
143
|
|
|
} |
|
144
|
|
|
|