‪TYPO3CMS  ‪main
FileLinkHandler.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
18 use Psr\Http\Message\ServerRequestInterface;
30 
35 {
36  protected ‪LinkType ‪$type = LinkType::FILE;
37 
38  public function ‪initializeVariables(ServerRequestInterface $request): void
39  {
40  parent::initializeVariables($request);
41  $this->pageRenderer->loadJavaScriptModule('@typo3/filelist/linkbrowser-file-handler.js');
42 
43  $this->resourceDisplayMatcher = GeneralUtility::makeInstance(Matcher::class);
44  $this->resourceDisplayMatcher->addMatcher(GeneralUtility::makeInstance(ResourceFolderTypeMatcher::class));
45 
46  // @todo Deprecate "allowedExtensions", see LinkPopup for further information
47  $allowedExtensions = ‪GeneralUtility::trimExplode(',', (string)($this->linkBrowser->getParameters()['params']['allowedExtensions'] ?? ''), true);
48  $allowedFileExtensions = ‪GeneralUtility::trimExplode(',', (string)($this->linkBrowser->getParameters()['params']['allowedFileExtensions'] ?? ''), true);
49  $allowedFileExtensions = array_unique(array_merge($allowedExtensions, $allowedFileExtensions));
50  if (count($allowedFileExtensions) >= 1) {
51  $fileExtensionMatcher = GeneralUtility::makeInstance(ResourceFileExtensionMatcher::class);
52  $fileExtensionMatcher->setExtensions($allowedFileExtensions);
53  } else {
54  $fileExtensionMatcher = GeneralUtility::makeInstance(ResourceFileTypeMatcher::class);
55  }
56  $this->resourceDisplayMatcher->addMatcher($fileExtensionMatcher);
57  }
58 
59  public function ‪render(ServerRequestInterface $request): string
60  {
61  $contentHtml = '';
62  if ($this->selectedFolder !== null) {
63  $markup = [];
64 
65  // Create the filelist header bar
66  $markup[] = '<div class="row justify-content-between mb-2">';
67  $markup[] = ' <div class="col-auto"></div>';
68  $markup[] = ' <div class="col-auto">';
69  $markup[] = ' ' . $this->‪getViewModeButton($request);
70  $markup[] = ' </div>';
71  $markup[] = '</div>';
72 
73  // Create the filelist
74  $this->filelist->start(
75  $this->selectedFolder,
76  ‪MathUtility::forceIntegerInRange($this->currentPage, 1, 100000),
77  $request->getQueryParams()['sort'] ?? '',
78  ($request->getQueryParams()['reverse'] ?? '') === '1',
79  Mode::BROWSE
80  );
81  $this->filelist->setResourceDisplayMatcher($this->resourceDisplayMatcher);
82  $this->filelist->setResourceSelectableMatcher($this->resourceSelectableMatcher);
83 
84  $resource = $this->linkParts['url']['file'] ?? null;
85  if ($resource instanceof ‪ResourceInterface) {
86  $resourceSelectedMatcher = GeneralUtility::makeInstance(Matcher::class);
87  $resourceMatcher = GeneralUtility::makeInstance(ResourceMatcher::class);
88  $resourceMatcher->addResource($resource);
89  $resourceSelectedMatcher->addMatcher($resourceMatcher);
90  $this->filelist->setResourceSelectedMatcher($resourceSelectedMatcher);
91  }
92 
93  $markup[] = $this->filelist->render(null, $this->view);
94 
95  // Build the file upload and folder creation form
96  $folderUtilityRenderer = GeneralUtility::makeInstance(FolderUtilityRenderer::class, $this);
97  $markup[] = $folderUtilityRenderer->uploadForm($request, $this->selectedFolder);
98  $markup[] = $folderUtilityRenderer->createFolder($request, $this->selectedFolder);
99 
100  $contentHtml = implode(PHP_EOL, $markup);
101  }
102 
103  $this->view->assign('selectedFolder', $this->selectedFolder);
104  $this->view->assign('content', $contentHtml);
105  $this->view->assign('contentOnly', (bool)($request->getQueryParams()['contentOnly'] ?? false));
106  $this->view->assign('treeActions', ($this->type === LinkType::FOLDER) ? ['link'] : []);
107  $this->view->assign('currentIdentifier', !empty($this->linkParts) ? $this->linkParts['url']['file']->getUid() : '');
108 
109  return $this->view->render('LinkHandler/File');
110  }
111 }
‪TYPO3\CMS\Filelist\Matcher\ResourceMatcher
Definition: ResourceMatcher.php:26
‪TYPO3\CMS\Filelist\Matcher\ResourceFolderTypeMatcher
Definition: ResourceFolderTypeMatcher.php:27
‪TYPO3\CMS\Filelist\Matcher\ResourceFileExtensionMatcher
Definition: ResourceFileExtensionMatcher.php:26
‪TYPO3\CMS\Filelist\Matcher\Matcher
Definition: Matcher.php:24
‪TYPO3\CMS\Filelist\Type\LinkType
‪LinkType
Definition: LinkType.php:28
‪TYPO3\CMS\Filelist\Type\Mode
‪Mode
Definition: Mode.php:24
‪TYPO3\CMS\Backend\View\FolderUtilityRenderer
Definition: FolderUtilityRenderer.php:36
‪TYPO3\CMS\Core\Utility\MathUtility
Definition: MathUtility.php:24
‪TYPO3\CMS\Core\Resource\ResourceInterface
Definition: ResourceInterface.php:21
‪TYPO3\CMS\Core\Utility\MathUtility\forceIntegerInRange
‪static int forceIntegerInRange(mixed $theInt, int $min, int $max=2000000000, int $defaultValue=0)
Definition: MathUtility.php:34
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Filelist\Matcher\ResourceFileTypeMatcher
Definition: ResourceFileTypeMatcher.php:27
‪TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode
‪static list< string > trimExplode(string $delim, string $string, bool $removeEmptyValues=false, int $limit=0)
Definition: GeneralUtility.php:817