‪TYPO3CMS  9.5
ResourcePublicationSlot.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 namespace ‪TYPO3\CMS\Form\Slot;
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 
28 
35 {
39  protected ‪$fileIdentifiers = [];
40 
48  public function ‪onPreGeneratePublicUrl(
49  ‪ResourceStorage $storage,
50  ‪DriverInterface $driver,
51  ‪ResourceInterface $resource,
52  bool $relativeToCurrentScript,
53  array $urlData
54  ): void {
55  if (!$resource instanceof ‪FileInterface
56  || !$this->‪has($resource)
57  || $storage->‪getDriverType() !== 'Local'
58  ) {
59  return;
60  }
61  $urlData['publicUrl'] = $this->‪getStreamUrl($resource);
62  }
63 
64  public function ‪add(‪FileInterface $resource): void
65  {
66  if ($this->‪has($resource)) {
67  return;
68  }
69  $this->fileIdentifiers[] = $resource->‪getIdentifier();
70  }
71 
72  public function ‪has(‪FileInterface $resource): bool
73  {
74  return in_array($resource->‪getIdentifier(), $this->fileIdentifiers, true);
75  }
76 
77  protected function ‪getStreamUrl(‪ResourceInterface $resource): string
78  {
79  $queryParameterArray = ['eID' => 'dumpFile', 't' => ''];
80  if ($resource instanceof ‪File) {
81  $queryParameterArray['f'] = $resource->getUid();
82  $queryParameterArray['t'] = 'f';
83  } elseif ($resource instanceof ‪ProcessedFile) {
84  $queryParameterArray['p'] = $resource->getUid();
85  $queryParameterArray['t'] = 'p';
86  }
87 
88  $queryParameterArray['token'] = GeneralUtility::hmac(implode('|', $queryParameterArray), 'resourceStorageDumpFile');
89  $publicUrl = GeneralUtility::locationHeaderUrl(‪PathUtility::getAbsoluteWebPath(‪Environment::getPublicPath() . '/index.php'));
90  $publicUrl .= '?' . http_build_query($queryParameterArray, '', '&', PHP_QUERY_RFC3986);
91  return $publicUrl;
92  }
93 }
‪TYPO3\CMS\Form\Slot\ResourcePublicationSlot\onPreGeneratePublicUrl
‪onPreGeneratePublicUrl(ResourceStorage $storage, DriverInterface $driver, ResourceInterface $resource, bool $relativeToCurrentScript, array $urlData)
Definition: ResourcePublicationSlot.php:47
‪TYPO3\CMS\Core\Utility\PathUtility
Definition: PathUtility.php:23
‪TYPO3\CMS\Core\Core\Environment\getPublicPath
‪static string getPublicPath()
Definition: Environment.php:153
‪TYPO3\CMS\Core\Resource\FileInterface
Definition: FileInterface.php:21
‪TYPO3\CMS\Core\Resource\ResourceStorage\getDriverType
‪string getDriverType()
Definition: ResourceStorage.php:3133
‪TYPO3\CMS\Core\Resource\Driver\DriverInterface
Definition: DriverInterface.php:22
‪TYPO3\CMS\Form\Slot\ResourcePublicationSlot
Definition: ResourcePublicationSlot.php:35
‪TYPO3\CMS\Core\Resource\ResourceInterface\getIdentifier
‪string getIdentifier()
‪TYPO3\CMS\Form\Slot\ResourcePublicationSlot\getStreamUrl
‪getStreamUrl(ResourceInterface $resource)
Definition: ResourcePublicationSlot.php:76
‪TYPO3\CMS\Form\Slot
Definition: FilePersistenceSlot.php:3
‪TYPO3\CMS\Core\Resource\File
Definition: File.php:23
‪TYPO3\CMS\Form\Slot\ResourcePublicationSlot\$fileIdentifiers
‪list< string > $fileIdentifiers
Definition: ResourcePublicationSlot.php:38
‪TYPO3\CMS\Core\Resource\ProcessedFile
Definition: ProcessedFile.php:42
‪TYPO3\CMS\Form\Slot\ResourcePublicationSlot\has
‪has(FileInterface $resource)
Definition: ResourcePublicationSlot.php:71
‪TYPO3\CMS\Core\Resource\ResourceStorage
Definition: ResourceStorage.php:74
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:22
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:39
‪TYPO3\CMS\Form\Slot\ResourcePublicationSlot\add
‪add(FileInterface $resource)
Definition: ResourcePublicationSlot.php:63
‪TYPO3\CMS\Core\Resource\ResourceInterface
Definition: ResourceInterface.php:21
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Utility\PathUtility\getAbsoluteWebPath
‪static string getAbsoluteWebPath($targetPath)
Definition: PathUtility.php:42