‪TYPO3CMS  ‪main
ResourcePublicationSlot.php
Go to the documentation of this file.
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 
30 
37 {
41  protected ‪$fileIdentifiers = [];
42 
43  #[AsEventListener('form-framework/resource-getPublicUrl')]
44  public function ‪getPublicUrl(‪GeneratePublicUrlForResourceEvent $event): void
45  {
46  $resource = $event->‪getResource();
47  if (!$resource instanceof ‪FileInterface
48  || !$this->‪has($resource)
49  || $event->‪getStorage()->getDriverType() !== 'Local'
50  ) {
51  return;
52  }
53  $event->‪setPublicUrl($this->‪getStreamUrl($event->‪getResource()));
54  }
55 
56  public function ‪add(‪FileInterface $resource): void
57  {
58  if ($this->‪has($resource)) {
59  return;
60  }
61  $this->fileIdentifiers[] = $resource->‪getIdentifier();
62  }
63 
64  public function ‪has(‪FileInterface $resource): bool
65  {
66  return in_array($resource->‪getIdentifier(), $this->fileIdentifiers, true);
67  }
68 
69  protected function ‪getStreamUrl(‪ResourceInterface $resource): string
70  {
71  $queryParameterArray = ['eID' => 'dumpFile', 't' => ''];
72  if ($resource instanceof ‪File) {
73  $queryParameterArray['f'] = $resource->getUid();
74  $queryParameterArray['t'] = 'f';
75  } elseif ($resource instanceof ‪ProcessedFile) {
76  $queryParameterArray['p'] = $resource->getUid();
77  $queryParameterArray['t'] = 'p';
78  }
79 
80  $queryParameterArray['token'] = ‪GeneralUtility::hmac(implode('|', $queryParameterArray), 'resourceStorageDumpFile');
81  ‪$publicUrl = GeneralUtility::locationHeaderUrl(‪PathUtility::getAbsoluteWebPath(‪Environment::getPublicPath() . '/index.php'));
82  ‪$publicUrl .= '?' . http_build_query($queryParameterArray, '', '&', PHP_QUERY_RFC3986);
83  return ‪$publicUrl;
84  }
85 }
‪TYPO3\CMS\Core\Resource\ResourceInterface\getIdentifier
‪getIdentifier()
‪TYPO3\CMS\Core\Utility\PathUtility
Definition: PathUtility.php:27
‪TYPO3\CMS\Core\Resource\FileInterface
Definition: FileInterface.php:26
‪TYPO3\CMS\Core\Resource\Event\GeneratePublicUrlForResourceEvent\setPublicUrl
‪setPublicUrl(?string $publicUrl)
Definition: GeneratePublicUrlForResourceEvent.php:60
‪TYPO3\CMS\Core\Attribute\AsEventListener
Definition: AsEventListener.php:25
‪TYPO3\CMS\Core\Core\Environment\getPublicPath
‪static getPublicPath()
Definition: Environment.php:187
‪TYPO3\CMS\Form\Slot\ResourcePublicationSlot
Definition: ResourcePublicationSlot.php:37
‪TYPO3\CMS\Form\Slot\ResourcePublicationSlot\getStreamUrl
‪getStreamUrl(ResourceInterface $resource)
Definition: ResourcePublicationSlot.php:68
‪TYPO3\CMS\Core\Resource\Event\GeneratePublicUrlForResourceEvent
Definition: GeneratePublicUrlForResourceEvent.php:31
‪TYPO3\CMS\Core\Utility\PathUtility\getAbsoluteWebPath
‪static string getAbsoluteWebPath(string $targetPath, bool $prefixWithSitePath=true)
Definition: PathUtility.php:52
‪TYPO3\CMS\Form\Slot
Definition: FilePersistenceSlot.php:18
‪TYPO3\CMS\Webhooks\Message\$publicUrl
‪identifier readonly string readonly string $publicUrl
Definition: FileUpdatedMessage.php:36
‪TYPO3\CMS\Core\Resource\Event\GeneratePublicUrlForResourceEvent\getStorage
‪getStorage()
Definition: GeneratePublicUrlForResourceEvent.php:45
‪TYPO3\CMS\Core\Resource\File
Definition: File.php:26
‪TYPO3\CMS\Core\Utility\GeneralUtility\hmac
‪static string hmac($input, $additionalSecret='')
Definition: GeneralUtility.php:474
‪TYPO3\CMS\Form\Slot\ResourcePublicationSlot\$fileIdentifiers
‪list< string > $fileIdentifiers
Definition: ResourcePublicationSlot.php:40
‪TYPO3\CMS\Core\Resource\ProcessedFile
Definition: ProcessedFile.php:47
‪TYPO3\CMS\Form\Slot\ResourcePublicationSlot\has
‪has(FileInterface $resource)
Definition: ResourcePublicationSlot.php:63
‪TYPO3\CMS\Core\Resource\Event\GeneratePublicUrlForResourceEvent\getResource
‪getResource()
Definition: GeneratePublicUrlForResourceEvent.php:40
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:22
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:41
‪TYPO3\CMS\Form\Slot\ResourcePublicationSlot\add
‪add(FileInterface $resource)
Definition: ResourcePublicationSlot.php:55
‪TYPO3\CMS\Core\Resource\ResourceInterface
Definition: ResourceInterface.php:21
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Form\Slot\ResourcePublicationSlot\getPublicUrl
‪getPublicUrl(GeneratePublicUrlForResourceEvent $event)
Definition: ResourcePublicationSlot.php:43