‪TYPO3CMS  9.5
FolderUtilityRenderer.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
25 
31 {
35  protected ‪$parameterProvider;
36 
41  {
42  $this->parameterProvider = ‪$parameterProvider;
43  }
44 
53  public function ‪createFolder(‪Folder $folderObject)
54  {
55  $backendUser = $this->‪getBackendUser();
56  $userTsConfig = $backendUser->getTSConfig();
57  $lang = $this->‪getLanguageService();
58 
59  if (!$folderObject->‪checkActionPermission('write')
60  || !$backendUser->isAdmin() && !($userTsConfig['options.']['createFoldersInEB'] ?? false)
61  || $userTsConfig['options.']['folderTree.']['hideCreateFolder'] ?? false
62  ) {
63  // Do not show create folder form if it is denied
64  return '';
65  }
66 
67  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
68  $formAction = (string)$uriBuilder->buildUriFromRoute('tce_file');
69  $markup = [];
70  $markup[] = '<form action="' . htmlspecialchars($formAction)
71  . '" method="post" name="editform" enctype="multipart/form-data">';
72  $markup[] = '<h3>' . htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:create_folder.title')) . ':</h3>';
73  $markup[] = '<p><strong>' . htmlspecialchars($lang->getLL('path')) . ':</strong>'
74  . htmlspecialchars($folderObject->‪getIdentifier()) . '</p>';
75 
76  $a = 1;
77  $markup[] = '<div class="form-group">';
78  $markup[] = '<div class="input-group">';
79  $markup[] = '<input class="form-control" type="text" name="data[newfolder][' . $a . '][data]" />';
80  $markup[] = '<span class="input-group-btn">';
81  $markup[] = '<input class="btn btn-default" type="submit" name="submit" value="'
82  . htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:create_folder.submit')) . '" />';
83  $markup[] = '</span>';
84  $markup[] = '</div>';
85  $markup[] = '<input type="hidden" name="data[newfolder][' . $a . '][target]" value="'
86  . htmlspecialchars($folderObject->‪getCombinedIdentifier()) . '" />';
87 
88  // Make footer of upload form, including the submit button:
89  $redirectValue = $this->parameterProvider->getScriptUrl() . ‪HttpUtility::buildQueryString(
90  $this->parameterProvider->getUrlParameters(
91  ['identifier' => $folderObject->‪getCombinedIdentifier()]
92  ),
93  '&'
94  );
95  $markup[] = '<input type="hidden" name="data[newfolder][' . $a . '][redirect]" value="' . htmlspecialchars($redirectValue) . '" />';
96 
97  $markup[] = '</div></form>';
98 
99  return implode(LF, $markup);
100  }
101 
111  public function ‪uploadForm(‪Folder $folderObject, array $allowedExtensions)
112  {
113  if (!$folderObject->‪checkActionPermission('write')) {
114  return '';
115  }
116  // Read configuration of upload field count
117  $count = (int)($this->‪getBackendUser()->‪getTSConfig()['options.']['folderTree.']['uploadFieldsInLinkBrowser'] ?? 1);
118  if ($count === 0) {
119  return '';
120  }
121 
122  // Create header, showing upload path:
123  $header = $folderObject->‪getIdentifier();
124  $lang = $this->‪getLanguageService();
125  // Create a list of allowed file extensions with the readable format "youtube, vimeo" etc.
126  $fileExtList = [];
127  foreach ($allowedExtensions as $fileExt) {
128  if (GeneralUtility::verifyFilenameAgainstDenyPattern('.' . $fileExt)) {
129  $fileExtList[] = '<span class="label label-success">'
130  . strtoupper(htmlspecialchars($fileExt)) . '</span>';
131  }
132  }
134  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
135  $formAction = (string)$uriBuilder->buildUriFromRoute('tce_file');
136  $combinedIdentifier = $folderObject->‪getCombinedIdentifier();
137  $markup = [];
138  $markup[] = '<form action="' . htmlspecialchars($formAction)
139  . '" method="post" name="editform" enctype="multipart/form-data">';
140  $markup[] = ' <h3>' . htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:file_upload.php.pagetitle')) . ':</h3>';
141  $markup[] = ' <p><strong>' . htmlspecialchars($lang->getLL('path')) . ':</strong>' . htmlspecialchars($header) . '</p>';
142  // Traverse the number of upload fields:
143  for ($a = 1; $a <= $count; $a++) {
144  $markup[] = '<div class="form-group">';
145  $markup[] = '<span class="btn btn-default btn-file">';
146  $markup[] = '<input type="file" multiple="multiple" name="upload_' . $a . '[]" size="50" />';
147  $markup[] = '</span>';
148  $markup[] = '</div>';
149  $markup[] = '<input type="hidden" name="data[upload][' . $a . '][target]" value="'
150  . htmlspecialchars($combinedIdentifier) . '" />';
151  $markup[] = '<input type="hidden" name="data[upload][' . $a . '][data]" value="' . $a . '" />';
152  }
153  $redirectValue = $this->parameterProvider->getScriptUrl() . ‪HttpUtility::buildQueryString(
154  $this->parameterProvider->getUrlParameters(['identifier' => $combinedIdentifier]),
155  '&'
156  );
157  $markup[] = '<input type="hidden" name="data[upload][1][redirect]" value="' . htmlspecialchars($redirectValue) . '" />';
158 
159  if (!empty($fileExtList)) {
160  $markup[] = '<div class="form-group">';
161  $markup[] = ' <label>';
162  $markup[] = htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:cm.allowedFileExtensions')) . '<br/>';
163  $markup[] = ' </label>';
164  $markup[] = ' <div>';
165  $markup[] = implode(' ', $fileExtList);
166  $markup[] = ' </div>';
167  $markup[] = '</div>';
168  }
169 
170  $markup[] = '<div class="checkbox">';
171  $markup[] = ' <label>';
172  $markup[] = ' <input type="checkbox" name="overwriteExistingFiles" id="overwriteExistingFiles" value="replace" />';
173  $markup[] = htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_misc.xlf:overwriteExistingFiles'));
174  $markup[] = ' </label>';
175  $markup[] = '</div>';
176  $markup[] = '<input class="btn btn-default" type="submit" name="submit" value="'
177  . htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:file_upload.php.submit')) . '" />';
178 
179  $markup[] = '</form>';
180 
181  $code = implode(LF, $markup);
182 
183  // Add online media
184  // Create a list of allowed file extensions in a readable format "youtube, vimeo" etc.
185  $fileExtList = [];
187  foreach ($onlineMediaFileExt as $fileExt) {
188  if (GeneralUtility::verifyFilenameAgainstDenyPattern('.' . $fileExt)
189  && (empty($allowedExtensions) || in_array($fileExt, $allowedExtensions, true))
190  ) {
191  $fileExtList[] = '<span class="label label-success">'
192  . strtoupper(htmlspecialchars($fileExt)) . '</span>';
193  }
194  }
195  if (!empty($fileExtList)) {
196  $formAction = (string)$uriBuilder->buildUriFromRoute('online_media');
197 
198  $markup = [];
199  $markup[] = '<form action="' . htmlspecialchars($formAction)
200  . '" method="post" name="editform1" id="typo3-addMediaForm" enctype="multipart/form-data">';
201  $markup[] = '<h3>' . htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:online_media.new_media')) . ':</h3>';
202  $markup[] = '<p><strong>' . htmlspecialchars($lang->getLL('path')) . ':</strong>' . htmlspecialchars($header) . '</p>';
203  $markup[] = '<div class="form-group">';
204  $markup[] = '<input type="hidden" name="data[newMedia][0][target]" value="'
205  . htmlspecialchars($folderObject->‪getCombinedIdentifier()) . '" />';
206  $markup[] = '<input type="hidden" name="data[newMedia][0][allowed]" value="'
207  . htmlspecialchars(implode(',', $allowedExtensions)) . '" />';
208  $markup[] = '<div class="input-group">';
209  $markup[] = '<input type="text" name="data[newMedia][0][url]" class="form-control" placeholder="'
210  . htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:online_media.new_media.placeholder')) . '" />';
211  $markup[] = '<div class="input-group-btn">';
212  $markup[] = '<button class="btn btn-default">'
213  . htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:online_media.new_media.submit')) . '</button>';
214  $markup[] = '</div>';
215  $markup[] = '</div>';
216  $markup[] = '<div class="form-group">';
217  $markup[] = '<label>';
218  $markup[] = $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:online_media.new_media.allowedProviders') . '<br/>';
219  $markup[] = '</label>';
220  $markup[] = '<div>';
221  $markup[] = implode(' ', $fileExtList);
222  $markup[] = '</div>';
223  $markup[] = '</div>';
224  $markup[] = '<input type="hidden" name="redirect" value="' . htmlspecialchars($redirectValue) . '" />';
225  $markup[] = '</form>';
226 
227  $code .= implode(LF, $markup);
228  }
229 
230  return $code;
231  }
232 
239  public function ‪getFileSearchField($searchWord)
240  {
241  $action = $this->parameterProvider->getScriptUrl()
242  . ‪HttpUtility::buildQueryString($this->parameterProvider->getUrlParameters([]), '&');
243 
244  $markup = [];
245  $markup[] = '<form method="post" action="' . htmlspecialchars($action) . '" style="padding-bottom: 15px;">';
246  $markup[] = ' <div class="input-group">';
247  $markup[] = ' <input class="form-control" type="text" name="searchWord" value="'
248  . htmlspecialchars($searchWord) . '">';
249  $markup[] = ' <span class="input-group-btn">';
250  $markup[] = ' <button class="btn btn-default" type="submit">'
251  . htmlspecialchars(
252  $this->‪getLanguageService()->sL('LLL:EXT:filelist/Resources/Private/Language/locallang.xlf:search')
253  )
254  . '</button>';
255  $markup[] = ' </span>';
256  $markup[] = ' </div>';
257  $markup[] = '</form>';
258  return implode(LF, $markup);
259  }
260 
264  protected function ‪getLanguageService()
265  {
266  return ‪$GLOBALS['LANG'];
267  }
268 
272  protected function ‪getBackendUser()
273  {
274  return ‪$GLOBALS['BE_USER'];
275  }
276 }
‪TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\OnlineMediaHelperRegistry
Definition: OnlineMediaHelperRegistry.php:25
‪TYPO3\CMS\Recordlist\View
Definition: FolderUtilityRenderer.php:2
‪TYPO3\CMS\Recordlist\View\FolderUtilityRenderer\getFileSearchField
‪string getFileSearchField($searchWord)
Definition: FolderUtilityRenderer.php:238
‪TYPO3\CMS\Recordlist\View\FolderUtilityRenderer\$parameterProvider
‪LinkParameterProviderInterface $parameterProvider
Definition: FolderUtilityRenderer.php:34
‪TYPO3\CMS\Recordlist\View\FolderUtilityRenderer\createFolder
‪string createFolder(Folder $folderObject)
Definition: FolderUtilityRenderer.php:52
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\getTSConfig
‪array getTSConfig($objectString=null, $config=null)
Definition: BackendUserAuthentication.php:1232
‪TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\OnlineMediaHelperRegistry\getSupportedFileExtensions
‪string[] getSupportedFileExtensions()
Definition: OnlineMediaHelperRegistry.php:81
‪TYPO3\CMS\Recordlist\View\FolderUtilityRenderer\uploadForm
‪string uploadForm(Folder $folderObject, array $allowedExtensions)
Definition: FolderUtilityRenderer.php:110
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:35
‪TYPO3\CMS\Core\Resource\Folder
Definition: Folder.php:34
‪TYPO3\CMS\Core\Utility\HttpUtility\buildQueryString
‪static string buildQueryString(array $parameters, string $prependCharacter='', bool $skipEmptyParameters=false)
Definition: HttpUtility.php:160
‪TYPO3\CMS\Core\Resource\Folder\checkActionPermission
‪bool checkActionPermission($action)
Definition: Folder.php:420
‪TYPO3\CMS\Recordlist\View\FolderUtilityRenderer\getBackendUser
‪BackendUserAuthentication getBackendUser()
Definition: FolderUtilityRenderer.php:271
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:45
‪TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\OnlineMediaHelperRegistry\getInstance
‪static OnlineMediaHelperRegistry getInstance()
Definition: OnlineMediaHelperRegistry.php:31
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Resource\Folder\getIdentifier
‪string getIdentifier()
Definition: Folder.php:157
‪TYPO3\CMS\Recordlist\View\FolderUtilityRenderer
Definition: FolderUtilityRenderer.php:31
‪TYPO3\CMS\Core\Utility\HttpUtility
Definition: HttpUtility.php:21
‪TYPO3\CMS\Core\Resource\Folder\getCombinedIdentifier
‪string getCombinedIdentifier()
Definition: Folder.php:178
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:29
‪TYPO3\CMS\Recordlist\View\FolderUtilityRenderer\getLanguageService
‪LanguageService getLanguageService()
Definition: FolderUtilityRenderer.php:263
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Recordlist\View\FolderUtilityRenderer\__construct
‪__construct(LinkParameterProviderInterface $parameterProvider)
Definition: FolderUtilityRenderer.php:39