‪TYPO3CMS  10.4
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 
29 
36 {
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 }
‪TYPO3\CMS\Core\Utility\PathUtility
Definition: PathUtility.php:24
‪TYPO3\CMS\Core\Core\Environment\getPublicPath
‪static string getPublicPath()
Definition: Environment.php:180
‪TYPO3\CMS\Core\Resource\FileInterface
Definition: FileInterface.php:22
‪TYPO3\CMS\Core\Resource\Event\GeneratePublicUrlForResourceEvent\setPublicUrl
‪setPublicUrl(?string $publicUrl)
Definition: GeneratePublicUrlForResourceEvent.php:86
‪TYPO3\CMS\Form\Slot\ResourcePublicationSlot
Definition: ResourcePublicationSlot.php:36
‪TYPO3\CMS\Core\Resource\ResourceInterface\getIdentifier
‪string getIdentifier()
‪TYPO3\CMS\Form\Slot\ResourcePublicationSlot\getStreamUrl
‪getStreamUrl(ResourceInterface $resource)
Definition: ResourcePublicationSlot.php:66
‪TYPO3\CMS\Core\Resource\Event\GeneratePublicUrlForResourceEvent
Definition: GeneratePublicUrlForResourceEvent.php:31
‪TYPO3\CMS\Form\Slot
Definition: FilePersistenceSlot.php:18
‪TYPO3\CMS\Core\Resource\Event\GeneratePublicUrlForResourceEvent\getStorage
‪getStorage()
Definition: GeneratePublicUrlForResourceEvent.php:66
‪TYPO3\CMS\Core\Resource\File
Definition: File.php:24
‪TYPO3\CMS\Form\Slot\ResourcePublicationSlot\$fileIdentifiers
‪list< string > $fileIdentifiers
Definition: ResourcePublicationSlot.php:39
‪TYPO3\CMS\Core\Resource\ProcessedFile
Definition: ProcessedFile.php:44
‪TYPO3\CMS\Form\Slot\ResourcePublicationSlot\has
‪has(FileInterface $resource)
Definition: ResourcePublicationSlot.php:61
‪TYPO3\CMS\Core\Resource\Event\GeneratePublicUrlForResourceEvent\getResource
‪getResource()
Definition: GeneratePublicUrlForResourceEvent.php:61
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:23
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:40
‪TYPO3\CMS\Form\Slot\ResourcePublicationSlot\add
‪add(FileInterface $resource)
Definition: ResourcePublicationSlot.php:53
‪TYPO3\CMS\Core\Resource\ResourceInterface
Definition: ResourceInterface.php:22
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Utility\PathUtility\getAbsoluteWebPath
‪static string getAbsoluteWebPath($targetPath)
Definition: PathUtility.php:43
‪TYPO3\CMS\Form\Slot\ResourcePublicationSlot\getPublicUrl
‪getPublicUrl(GeneratePublicUrlForResourceEvent $event)
Definition: ResourcePublicationSlot.php:41