‪TYPO3CMS  10.4
FolderUtilityRenderer.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 
27 
33 {
37  protected ‪$parameterProvider;
38 
43  {
44  $this->parameterProvider = ‪$parameterProvider;
45  }
46 
55  public function ‪createFolder(‪Folder $folderObject)
56  {
57  $backendUser = $this->‪getBackendUser();
58  $userTsConfig = $backendUser->getTSConfig();
59  $lang = $this->‪getLanguageService();
60 
61  if (!$folderObject->‪checkActionPermission('write')
62  || !$backendUser->isAdmin() && !($userTsConfig['options.']['createFoldersInEB'] ?? false)
63  || $userTsConfig['options.']['folderTree.']['hideCreateFolder'] ?? false
64  ) {
65  // Do not show create folder form if it is denied
66  return '';
67  }
68 
69  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
70  $formAction = (string)$uriBuilder->buildUriFromRoute('tce_file');
71  $markup = [];
72  $markup[] = '<form action="' . htmlspecialchars($formAction)
73  . '" method="post" name="editform" enctype="multipart/form-data">';
74  $markup[] = '<h3>' . htmlspecialchars($lang->sL('LLL:EXT:recordlist/Resources/Private/Language/locallang.xlf:create_folder.title')) . ':</h3>';
75  $markup[] = '<p><strong>' . htmlspecialchars($lang->getLL('path')) . ':</strong>'
76  . htmlspecialchars($folderObject->‪getIdentifier()) . '</p>';
77 
78  $a = 1;
79  $markup[] = '<div class="form-group">';
80  $markup[] = '<div class="input-group">';
81  $markup[] = '<input class="form-control" type="text" name="data[newfolder][' . $a . '][data]" />';
82  $markup[] = '<span class="input-group-btn">';
83  $markup[] = '<input class="btn btn-default" type="submit" name="submit" value="'
84  . htmlspecialchars($lang->sL('LLL:EXT:recordlist/Resources/Private/Language/locallang.xlf:create_folder.submit')) . '" />';
85  $markup[] = '</span>';
86  $markup[] = '</div>';
87  $markup[] = '<input type="hidden" name="data[newfolder][' . $a . '][target]" value="'
88  . htmlspecialchars($folderObject->‪getCombinedIdentifier()) . '" />';
89 
90  // Make footer of upload form, including the submit button:
91  $redirectValue = $this->parameterProvider->getScriptUrl() . ‪HttpUtility::buildQueryString(
92  $this->parameterProvider->getUrlParameters(
93  ['identifier' => $folderObject->‪getCombinedIdentifier()]
94  ),
95  '&'
96  );
97  $markup[] = '<input type="hidden" name="data[newfolder][' . $a . '][redirect]" value="' . htmlspecialchars($redirectValue) . '" />';
98 
99  $markup[] = '</div></form>';
100 
101  return implode(LF, $markup);
102  }
103 
113  public function ‪uploadForm(‪Folder $folderObject, array $allowedExtensions)
114  {
115  if (!$folderObject->‪checkActionPermission('write')) {
116  return '';
117  }
118  // Read configuration of upload field count
119  $count = (int)($this->‪getBackendUser()->‪getTSConfig()['options.']['folderTree.']['uploadFieldsInLinkBrowser'] ?? 1);
120  if ($count === 0) {
121  return '';
122  }
123 
124  // Create header, showing upload path:
125  $header = $folderObject->‪getIdentifier();
126  $lang = $this->‪getLanguageService();
127  // Create a list of allowed file extensions with the readable format "youtube, vimeo" etc.
128  $fileExtList = [];
129  $fileNameVerifier = GeneralUtility::makeInstance(FileNameValidator::class);
130  foreach ($allowedExtensions as $fileExt) {
131  if ($fileNameVerifier->isValid('.' . $fileExt)) {
132  $fileExtList[] = '<span class="label label-success">'
133  . strtoupper(htmlspecialchars($fileExt)) . '</span>';
134  }
135  }
137  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
138  $formAction = (string)$uriBuilder->buildUriFromRoute('tce_file');
139  $combinedIdentifier = $folderObject->‪getCombinedIdentifier();
140  $markup = [];
141  $markup[] = '<form action="' . htmlspecialchars($formAction)
142  . '" method="post" name="editform" enctype="multipart/form-data">';
143  $markup[] = ' <h3>' . htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:file_upload.php.pagetitle')) . ':</h3>';
144  $markup[] = ' <p><strong>' . htmlspecialchars($lang->getLL('path')) . ':</strong>' . htmlspecialchars($header) . '</p>';
145  // Traverse the number of upload fields:
146  for ($a = 1; $a <= $count; $a++) {
147  $markup[] = '<div class="form-group">';
148  $markup[] = '<span class="btn btn-default btn-file">';
149  $markup[] = '<input type="file" multiple="multiple" name="upload_' . $a . '[]" size="50" />';
150  $markup[] = '</span>';
151  $markup[] = '</div>';
152  $markup[] = '<input type="hidden" name="data[upload][' . $a . '][target]" value="'
153  . htmlspecialchars($combinedIdentifier) . '" />';
154  $markup[] = '<input type="hidden" name="data[upload][' . $a . '][data]" value="' . $a . '" />';
155  }
156  $redirectValue = $this->parameterProvider->getScriptUrl() . ‪HttpUtility::buildQueryString(
157  $this->parameterProvider->getUrlParameters(['identifier' => $combinedIdentifier]),
158  '&'
159  );
160  $markup[] = '<input type="hidden" name="data[upload][1][redirect]" value="' . htmlspecialchars($redirectValue) . '" />';
161 
162  if (!empty($fileExtList)) {
163  $markup[] = '<div class="form-group">';
164  $markup[] = ' <label>';
165  $markup[] = htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:cm.allowedFileExtensions')) . '<br/>';
166  $markup[] = ' </label>';
167  $markup[] = ' <div>';
168  $markup[] = implode(' ', $fileExtList);
169  $markup[] = ' </div>';
170  $markup[] = '</div>';
171  }
172 
173  $markup[] = '<div class="checkbox">';
174  $markup[] = ' <label>';
175  $markup[] = ' <input type="checkbox" name="overwriteExistingFiles" id="overwriteExistingFiles" value="replace" />';
176  $markup[] = htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_misc.xlf:overwriteExistingFiles'));
177  $markup[] = ' </label>';
178  $markup[] = '</div>';
179  $markup[] = '<input class="btn btn-default" type="submit" name="submit" value="'
180  . htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:file_upload.php.submit')) . '" />';
181 
182  $markup[] = '</form>';
183 
184  $code = implode(LF, $markup);
185 
186  // Add online media
187  // Create a list of allowed file extensions in a readable format "youtube, vimeo" etc.
188  $fileExtList = [];
190  foreach ($onlineMediaFileExt as $fileExt) {
191  if ($fileNameVerifier->isValid('.' . $fileExt)
192  && (empty($allowedExtensions) || in_array($fileExt, $allowedExtensions, true))
193  ) {
194  $fileExtList[] = '<span class="label label-success">'
195  . strtoupper(htmlspecialchars($fileExt)) . '</span>';
196  }
197  }
198  if (!empty($fileExtList)) {
199  $formAction = (string)$uriBuilder->buildUriFromRoute('online_media');
200 
201  $markup = [];
202  $markup[] = '<form action="' . htmlspecialchars($formAction)
203  . '" method="post" name="editform1" id="typo3-addMediaForm" enctype="multipart/form-data">';
204  $markup[] = '<h3>' . htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:online_media.new_media')) . ':</h3>';
205  $markup[] = '<p><strong>' . htmlspecialchars($lang->getLL('path')) . ':</strong>' . htmlspecialchars($header) . '</p>';
206  $markup[] = '<div class="form-group">';
207  $markup[] = '<input type="hidden" name="data[newMedia][0][target]" value="'
208  . htmlspecialchars($folderObject->‪getCombinedIdentifier()) . '" />';
209  $markup[] = '<input type="hidden" name="data[newMedia][0][allowed]" value="'
210  . htmlspecialchars(implode(',', $allowedExtensions)) . '" />';
211  $markup[] = '<div class="input-group">';
212  $markup[] = '<input type="text" name="data[newMedia][0][url]" class="form-control" placeholder="'
213  . htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:online_media.new_media.placeholder')) . '" />';
214  $markup[] = '<div class="input-group-btn">';
215  $markup[] = '<button class="btn btn-default">'
216  . htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:online_media.new_media.submit')) . '</button>';
217  $markup[] = '</div>';
218  $markup[] = '</div>';
219  $markup[] = '<div class="form-group">';
220  $markup[] = '<label>';
221  $markup[] = $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:online_media.new_media.allowedProviders') . '<br/>';
222  $markup[] = '</label>';
223  $markup[] = '<div>';
224  $markup[] = implode(' ', $fileExtList);
225  $markup[] = '</div>';
226  $markup[] = '</div>';
227  $markup[] = '<input type="hidden" name="redirect" value="' . htmlspecialchars($redirectValue) . '" />';
228  $markup[] = '</form>';
229 
230  $code .= implode(LF, $markup);
231  }
232 
233  return $code;
234  }
235 
242  public function ‪getFileSearchField($searchWord)
243  {
244  $action = $this->parameterProvider->getScriptUrl()
245  . ‪HttpUtility::buildQueryString($this->parameterProvider->getUrlParameters([]), '&');
246 
247  $markup = [];
248  $markup[] = '<form method="post" action="' . htmlspecialchars($action) . '" style="padding-bottom: 15px;">';
249  $markup[] = ' <div class="input-group">';
250  $markup[] = ' <input class="form-control" type="text" name="searchWord" value="'
251  . htmlspecialchars($searchWord) . '">';
252  $markup[] = ' <span class="input-group-btn">';
253  $markup[] = ' <button class="btn btn-default" type="submit">'
254  . htmlspecialchars(
255  $this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:search')
256  )
257  . '</button>';
258  $markup[] = ' </span>';
259  $markup[] = ' </div>';
260  $markup[] = '</form>';
261  return implode(LF, $markup);
262  }
263 
267  protected function ‪getLanguageService()
268  {
269  return ‪$GLOBALS['LANG'];
270  }
271 
275  protected function ‪getBackendUser()
276  {
277  return ‪$GLOBALS['BE_USER'];
278  }
279 }
‪TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\OnlineMediaHelperRegistry
Definition: OnlineMediaHelperRegistry.php:27
‪TYPO3\CMS\Core\Resource\Security\FileNameValidator
Definition: FileNameValidator.php:25
‪TYPO3\CMS\Recordlist\View
Definition: FolderUtilityRenderer.php:16
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\getTSConfig
‪array getTSConfig()
Definition: BackendUserAuthentication.php:1217
‪TYPO3\CMS\Recordlist\View\FolderUtilityRenderer\getFileSearchField
‪string getFileSearchField($searchWord)
Definition: FolderUtilityRenderer.php:241
‪TYPO3\CMS\Recordlist\View\FolderUtilityRenderer\$parameterProvider
‪LinkParameterProviderInterface $parameterProvider
Definition: FolderUtilityRenderer.php:36
‪TYPO3\CMS\Recordlist\View\FolderUtilityRenderer\createFolder
‪string createFolder(Folder $folderObject)
Definition: FolderUtilityRenderer.php:54
‪TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\OnlineMediaHelperRegistry\getSupportedFileExtensions
‪string[] getSupportedFileExtensions()
Definition: OnlineMediaHelperRegistry.php:94
‪TYPO3\CMS\Recordlist\View\FolderUtilityRenderer\uploadForm
‪string uploadForm(Folder $folderObject, array $allowedExtensions)
Definition: FolderUtilityRenderer.php:112
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:38
‪TYPO3\CMS\Core\Resource\Folder
Definition: Folder.php:37
‪TYPO3\CMS\Core\Utility\HttpUtility\buildQueryString
‪static string buildQueryString(array $parameters, string $prependCharacter='', bool $skipEmptyParameters=false)
Definition: HttpUtility.php:163
‪TYPO3\CMS\Core\Resource\Folder\checkActionPermission
‪bool checkActionPermission($action)
Definition: Folder.php:423
‪TYPO3\CMS\Recordlist\View\FolderUtilityRenderer\getBackendUser
‪BackendUserAuthentication getBackendUser()
Definition: FolderUtilityRenderer.php:274
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\OnlineMediaHelperRegistry\getInstance
‪static OnlineMediaHelperRegistry getInstance()
Definition: OnlineMediaHelperRegistry.php:33
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Resource\Folder\getIdentifier
‪string getIdentifier()
Definition: Folder.php:160
‪TYPO3\CMS\Recordlist\View\FolderUtilityRenderer
Definition: FolderUtilityRenderer.php:33
‪TYPO3\CMS\Core\Utility\HttpUtility
Definition: HttpUtility.php:24
‪TYPO3\CMS\Core\Resource\Folder\getCombinedIdentifier
‪string getCombinedIdentifier()
Definition: Folder.php:181
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Recordlist\View\FolderUtilityRenderer\getLanguageService
‪LanguageService getLanguageService()
Definition: FolderUtilityRenderer.php:266
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Recordlist\View\FolderUtilityRenderer\__construct
‪__construct(LinkParameterProviderInterface $parameterProvider)
Definition: FolderUtilityRenderer.php:41