|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the TYPO3 CMS project. |
|
7
|
|
|
* |
|
8
|
|
|
* It is free software; you can redistribute it and/or modify it under |
|
9
|
|
|
* the terms of the GNU General Public License, either version 2 |
|
10
|
|
|
* of the License, or any later version. |
|
11
|
|
|
* |
|
12
|
|
|
* For the full copyright and license information, please read the |
|
13
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
14
|
|
|
* |
|
15
|
|
|
* The TYPO3 project - inspiring people to share! |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
namespace TYPO3\CMS\Form\Slot; |
|
19
|
|
|
|
|
20
|
|
|
use TYPO3\CMS\Core\Core\Environment; |
|
21
|
|
|
use TYPO3\CMS\Core\Resource\Event\GeneratePublicUrlForResourceEvent; |
|
22
|
|
|
use TYPO3\CMS\Core\Resource\File; |
|
23
|
|
|
use TYPO3\CMS\Core\Resource\FileInterface; |
|
24
|
|
|
use TYPO3\CMS\Core\Resource\ProcessedFile; |
|
25
|
|
|
use TYPO3\CMS\Core\Resource\ResourceInterface; |
|
26
|
|
|
use TYPO3\CMS\Core\SingletonInterface; |
|
27
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
28
|
|
|
use TYPO3\CMS\Core\Utility\PathUtility; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* A PSR-14 event listener for using FAL resources in public (frontend) |
|
32
|
|
|
* |
|
33
|
|
|
* @internal will be renamed at some point. |
|
34
|
|
|
*/ |
|
35
|
|
|
class ResourcePublicationSlot implements SingletonInterface |
|
36
|
|
|
{ |
|
37
|
|
|
/** |
|
38
|
|
|
* @var list<string> |
|
|
|
|
|
|
39
|
|
|
*/ |
|
40
|
|
|
protected $fileIdentifiers = []; |
|
41
|
|
|
|
|
42
|
|
|
public function getPublicUrl(GeneratePublicUrlForResourceEvent $event): void |
|
43
|
|
|
{ |
|
44
|
|
|
$resource = $event->getResource(); |
|
45
|
|
|
if (!$resource instanceof FileInterface |
|
46
|
|
|
|| !$this->has($resource) |
|
47
|
|
|
|| $event->getStorage()->getDriverType() !== 'Local' |
|
48
|
|
|
) { |
|
49
|
|
|
return; |
|
50
|
|
|
} |
|
51
|
|
|
$event->setPublicUrl($this->getStreamUrl($event->getResource())); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function add(FileInterface $resource): void |
|
55
|
|
|
{ |
|
56
|
|
|
if ($this->has($resource)) { |
|
57
|
|
|
return; |
|
58
|
|
|
} |
|
59
|
|
|
$this->fileIdentifiers[] = $resource->getIdentifier(); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function has(FileInterface $resource): bool |
|
63
|
|
|
{ |
|
64
|
|
|
return in_array($resource->getIdentifier(), $this->fileIdentifiers, true); |
|
|
|
|
|
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
protected function getStreamUrl(ResourceInterface $resource): string |
|
68
|
|
|
{ |
|
69
|
|
|
$queryParameterArray = ['eID' => 'dumpFile', 't' => '']; |
|
70
|
|
|
if ($resource instanceof File) { |
|
71
|
|
|
$queryParameterArray['f'] = $resource->getUid(); |
|
72
|
|
|
$queryParameterArray['t'] = 'f'; |
|
73
|
|
|
} elseif ($resource instanceof ProcessedFile) { |
|
74
|
|
|
$queryParameterArray['p'] = $resource->getUid(); |
|
75
|
|
|
$queryParameterArray['t'] = 'p'; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
$queryParameterArray['token'] = GeneralUtility::hmac(implode('|', $queryParameterArray), 'resourceStorageDumpFile'); |
|
79
|
|
|
$publicUrl = GeneralUtility::locationHeaderUrl(PathUtility::getAbsoluteWebPath(Environment::getPublicPath() . '/index.php')); |
|
80
|
|
|
$publicUrl .= '?' . http_build_query($queryParameterArray, '', '&', PHP_QUERY_RFC3986); |
|
81
|
|
|
return $publicUrl; |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths