|
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\Eid; |
|
14
|
|
|
|
|
15
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
16
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
|
17
|
|
|
use TYPO3\CMS\Core\Http\Response; |
|
18
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
19
|
|
|
/** |
|
20
|
|
|
* eID image proxy for plugin 'Page View' of the 'dlf' extension |
|
21
|
|
|
* |
|
22
|
|
|
* @author Alexander Bigga <[email protected]> |
|
23
|
|
|
* @package TYPO3 |
|
24
|
|
|
* @subpackage dlf |
|
25
|
|
|
* @access public |
|
26
|
|
|
*/ |
|
27
|
|
|
class PageViewProxy |
|
28
|
|
|
{ |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* The main method of the eID script |
|
32
|
|
|
* |
|
33
|
|
|
* @access public |
|
34
|
|
|
* |
|
35
|
|
|
* @param ServerRequestInterface $request |
|
36
|
|
|
* @return ResponseInterface |
|
37
|
|
|
*/ |
|
38
|
|
|
public function main(ServerRequestInterface $request) |
|
39
|
|
|
{ |
|
40
|
|
|
// header parameter for getUrl(); allowed values 0,1,2; default 0 |
|
41
|
|
|
$header = (int)$request->getQueryParams()['header']; |
|
42
|
|
|
$header = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($header, 0, 2, 0); |
|
43
|
|
|
|
|
44
|
|
|
// the URI to fetch data or header from |
|
45
|
|
|
$url = (string)$request->getQueryParams()['url']; |
|
46
|
|
|
if (!GeneralUtility::isValidUrl($url)) { |
|
47
|
|
|
throw new \InvalidArgumentException('No valid url passed!', 1580482805); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
// fetch the requested data or header |
|
51
|
|
|
$fetchedData = GeneralUtility::getUrl($url, $header); |
|
52
|
|
|
|
|
53
|
|
|
// Fetch header data separately to get "Last-Modified" info |
|
54
|
|
|
if ($header === 0) { |
|
55
|
|
|
$fetchedHeaderString = GeneralUtility::getUrl($url, 2); |
|
56
|
|
|
if (!empty($fetchedHeaderString)) { |
|
57
|
|
|
$fetchedHeader = explode("\n", $fetchedHeaderString); |
|
58
|
|
|
foreach ($fetchedHeader as $headerline) { |
|
59
|
|
|
if (stripos($headerline, 'Last-Modified:') !== false) { |
|
60
|
|
|
$lastModified = trim(substr($headerline, strpos($headerline, ':') + 1)); |
|
61
|
|
|
break; |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
// create response object |
|
68
|
|
|
/** @var Response $response */ |
|
69
|
|
|
$response = GeneralUtility::makeInstance(Response::class); |
|
70
|
|
|
if ($fetchedData) { |
|
71
|
|
|
$response->getBody()->write($fetchedData); |
|
72
|
|
|
$response = $response->withHeader('Content-Type', finfo_buffer(finfo_open(FILEINFO_MIME), $fetchedData)); |
|
73
|
|
|
} |
|
74
|
|
|
if ($header === 0 && !empty($lastModified)) { |
|
75
|
|
|
$response = $response->withHeader('Last-Modified', $lastModified); |
|
76
|
|
|
} |
|
77
|
|
|
return $response; |
|
78
|
|
|
} |
|
79
|
|
|
} |