|
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
|
|
|
* Image Download tool for the plugin 'Toolbox' of the 'dlf' extension |
|
19
|
|
|
* |
|
20
|
|
|
* @author Alexander Bigga <[email protected]> |
|
21
|
|
|
* @package TYPO3 |
|
22
|
|
|
* @subpackage dlf |
|
23
|
|
|
* @access public |
|
24
|
|
|
*/ |
|
25
|
|
|
class ImageDownloadTool extends \Kitodo\Dlf\Common\AbstractPlugin |
|
26
|
|
|
{ |
|
27
|
|
|
public $scriptRelPath = 'Classes/Plugin/Tools/ImageDownloadTool.php'; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* The main method of the PlugIn |
|
31
|
|
|
* |
|
32
|
|
|
* @access public |
|
33
|
|
|
* |
|
34
|
|
|
* @param string $content: The PlugIn content |
|
35
|
|
|
* @param array $conf: The PlugIn configuration |
|
36
|
|
|
* |
|
37
|
|
|
* @return string The content that is displayed on the website |
|
38
|
|
|
*/ |
|
39
|
|
|
public function main($content, $conf) |
|
40
|
|
|
{ |
|
41
|
|
|
$this->init($conf); |
|
42
|
|
|
// Merge configuration with conf array of toolbox. |
|
43
|
|
|
if (!empty($this->cObj->data['conf'])) { |
|
44
|
|
|
$this->conf = Helper::mergeRecursiveWithOverrule($this->cObj->data['conf'], $this->conf); |
|
|
|
|
|
|
45
|
|
|
} |
|
46
|
|
|
// Load current document. |
|
47
|
|
|
$this->loadDocument(); |
|
48
|
|
|
if ( |
|
49
|
|
|
$this->doc === null |
|
50
|
|
|
|| $this->doc->numPages < 1 |
|
51
|
|
|
|| empty($this->conf['fileGrpsImageDownload']) |
|
52
|
|
|
) { |
|
53
|
|
|
// Quit without doing anything if required variables are not set. |
|
54
|
|
|
return $content; |
|
55
|
|
|
} else { |
|
56
|
|
|
if (!empty($this->piVars['logicalPage'])) { |
|
57
|
|
|
$this->piVars['page'] = $this->doc->getPhysicalPage($this->piVars['logicalPage']); |
|
|
|
|
|
|
58
|
|
|
// The logical page parameter should not appear again |
|
59
|
|
|
unset($this->piVars['logicalPage']); |
|
60
|
|
|
} |
|
61
|
|
|
// Set default values if not set. |
|
62
|
|
|
// $this->piVars['page'] may be integer or string (physical structure @ID) |
|
63
|
|
|
if ( |
|
64
|
|
|
(int) $this->piVars['page'] > 0 |
|
65
|
|
|
|| empty($this->piVars['page']) |
|
66
|
|
|
) { |
|
67
|
|
|
$this->piVars['page'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange((int) $this->piVars['page'], 1, $this->doc->numPages, 1); |
|
68
|
|
|
} else { |
|
69
|
|
|
$this->piVars['page'] = array_search($this->piVars['page'], $this->doc->physicalStructure); |
|
70
|
|
|
} |
|
71
|
|
|
$this->piVars['double'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($this->piVars['double'], 0, 1, 0); |
|
72
|
|
|
} |
|
73
|
|
|
// Load template file. |
|
74
|
|
|
$this->getTemplate(); |
|
75
|
|
|
// Get left or single page download. |
|
76
|
|
|
$markerArray['###IMAGE_LEFT###'] = $this->piVars['double'] == 1 ? $this->getImage($this->piVars['page'], $this->pi_getLL('leftPage', '')) : $this->getImage($this->piVars['page'], $this->pi_getLL('singlePage', '')); |
|
77
|
|
|
// Get right page download. |
|
78
|
|
|
$markerArray['###IMAGE_RIGHT###'] = $this->piVars['double'] == 1 ? $this->getImage($this->piVars['page'] + 1, $this->pi_getLL('rightPage', '')) : ''; |
|
79
|
|
|
$content .= $this->templateService->substituteMarkerArray($this->template, $markerArray); |
|
80
|
|
|
return $this->pi_wrapInBaseClass($content); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Get image's URL and MIME type |
|
85
|
|
|
* |
|
86
|
|
|
* @access protected |
|
87
|
|
|
* |
|
88
|
|
|
* @param int $page: Page number |
|
89
|
|
|
* @param string $label: Link title and label |
|
90
|
|
|
* |
|
91
|
|
|
* @return string Link to image file with given label |
|
92
|
|
|
*/ |
|
93
|
|
|
protected function getImage($page, $label) |
|
94
|
|
|
{ |
|
95
|
|
|
$image = []; |
|
96
|
|
|
// Get @USE value of METS fileGrp. |
|
97
|
|
|
$fileGrps = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $this->conf['fileGrpsImageDownload']); |
|
98
|
|
|
while ($fileGrp = @array_pop($fileGrps)) { |
|
99
|
|
|
// Get image link. |
|
100
|
|
|
if (!empty($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$page]]['files'][$fileGrp])) { |
|
101
|
|
|
$image['url'] = $this->doc->getDownloadLocation($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$page]]['files'][$fileGrp]); |
|
102
|
|
|
$image['mimetype'] = $this->doc->getFileMimeType($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$page]]['files'][$fileGrp]); |
|
103
|
|
|
switch ($image['mimetype']) { |
|
104
|
|
|
case 'image/jpeg': |
|
105
|
|
|
$mimetypeLabel = '(JPG)'; |
|
106
|
|
|
break; |
|
107
|
|
|
case 'image/tiff': |
|
108
|
|
|
$mimetypeLabel = '(TIFF)'; |
|
109
|
|
|
break; |
|
110
|
|
|
default: |
|
111
|
|
|
$mimetypeLabel = ''; |
|
112
|
|
|
} |
|
113
|
|
|
$linkConf = [ |
|
114
|
|
|
'parameter' => $image['url'], |
|
115
|
|
|
'forceAbsoluteUrl' => !empty($this->conf['forceAbsoluteUrl']) ? 1 : 0, |
|
116
|
|
|
'forceAbsoluteUrl.' => ['scheme' => !empty($this->conf['forceAbsoluteUrl']) && !empty($this->conf['forceAbsoluteUrlHttps']) ? 'https' : 'http'], |
|
117
|
|
|
'title' => $label . ' ' . $mimetypeLabel, |
|
118
|
|
|
'additionalParams' => '', |
|
119
|
|
|
]; |
|
120
|
|
|
$imageLink = $this->cObj->typoLink($label . ' ' . $mimetypeLabel, $linkConf); |
|
121
|
|
|
break; |
|
122
|
|
|
} else { |
|
123
|
|
|
Helper::devLog('File not found in fileGrp "' . $fileGrp . '"', DEVLOG_SEVERITY_WARNING); |
|
124
|
|
|
} |
|
125
|
|
|
} |
|
126
|
|
|
return $imageLink; |
|
|
|
|
|
|
127
|
|
|
} |
|
128
|
|
|
} |
|
129
|
|
|
|