TYPO3 CMS  TYPO3_8-7
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 
24 
29 {
33  protected $parameterProvider;
34 
39  {
40  $this->parameterProvider = $parameterProvider;
41  }
42 
51  public function createFolder(Folder $folderObject)
52  {
53  if (!$folderObject->checkActionPermission('write')) {
54  return '';
55  }
56  $backendUser = $this->getBackendUser();
57  if (!$backendUser->isAdmin() && !$backendUser->getTSConfigVal('options.createFoldersInEB')) {
58  return '';
59  }
60  // Don't show Folder-create form if it's denied
61  if ($backendUser->getTSConfigVal('options.folderTree.hideCreateFolder')) {
62  return '';
63  }
64  $lang = $this->getLanguageService();
65 
66  $formAction = BackendUtility::getModuleUrl('tce_file');
67  $markup = [];
68  $markup[] = '<form action="' . htmlspecialchars($formAction)
69  . '" method="post" name="editform" enctype="multipart/form-data">';
70  $markup[] = '<h3>' . htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:create_folder.title')) . ':</h3>';
71  $markup[] = '<p><strong>' . htmlspecialchars($lang->getLL('path')) . ':</strong>'
72  . htmlspecialchars($folderObject->getIdentifier()) . '</p>';
73 
74  $a = 1;
75  $markup[] = '<div class="form-group">';
76  $markup[] = '<div class="input-group">';
77  $markup[] = '<input class="form-control" type="text" name="file[newfolder][' . $a . '][data]" />';
78  $markup[] = '<span class="input-group-btn">';
79  $markup[] = '<input class="btn btn-default" type="submit" name="submit" value="'
80  . htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:create_folder.submit')) . '" />';
81  $markup[] = '</span>';
82  $markup[] = '</div>';
83  $markup[] = '<input type="hidden" name="file[newfolder][' . $a . '][target]" value="'
84  . htmlspecialchars($folderObject->getCombinedIdentifier()) . '" />';
85 
86  // Make footer of upload form, including the submit button:
87  $redirectValue = $this->parameterProvider->getScriptUrl() . GeneralUtility::implodeArrayForUrl(
88  '',
89  $this->parameterProvider->getUrlParameters(
90  ['identifier' => $folderObject->getCombinedIdentifier()]
91  )
92  );
93  $markup[] = '<input type="hidden" name="redirect" value="' . htmlspecialchars($redirectValue) . '" />';
94 
95  $markup[] = '</div></form>';
96 
97  return implode(LF, $markup);
98  }
99 
109  public function uploadForm(Folder $folderObject, array $allowedExtensions)
110  {
111  if (!$folderObject->checkActionPermission('write')) {
112  return '';
113  }
114  // Read configuration of upload field count
115  $userSetting = $this->getBackendUser()->getTSConfigVal('options.folderTree.uploadFieldsInLinkBrowser');
116  $count = isset($userSetting) ? (int)$userSetting : 1;
117  if ($count === 0) {
118  return '';
119  }
120 
121  $count = (int)$count === 0 ? 1 : (int)$count;
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) {
129  $fileExtList[] = '<span class="label label-success">'
130  . strtoupper(htmlspecialchars($fileExt)) . '</span>';
131  }
132  }
133  $formAction = BackendUtility::getModuleUrl('tce_file');
134  $combinedIdentifier = $folderObject->getCombinedIdentifier();
135  $markup = [];
136  $markup[] = '<form action="' . htmlspecialchars($formAction)
137  . '" method="post" name="editform" enctype="multipart/form-data">';
138  $markup[] = ' <h3>' . htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:file_upload.php.pagetitle')) . ':</h3>';
139  $markup[] = ' <p><strong>' . htmlspecialchars($lang->getLL('path')) . ':</strong>' . htmlspecialchars($header) . '</p>';
140  // Traverse the number of upload fields:
141  for ($a = 1; $a <= $count; $a++) {
142  $markup[] = '<div class="form-group">';
143  $markup[] = '<span class="btn btn-default btn-file">';
144  $markup[] = '<input type="file" multiple="multiple" name="upload_' . $a . '[]" size="50" />';
145  $markup[] = '</span>';
146  $markup[] = '</div>';
147  $markup[] = '<input type="hidden" name="file[upload][' . $a . '][target]" value="'
148  . htmlspecialchars($combinedIdentifier) . '" />';
149  $markup[] = '<input type="hidden" name="file[upload][' . $a . '][data]" value="' . $a . '" />';
150  }
151  $redirectValue = $this->parameterProvider->getScriptUrl() . GeneralUtility::implodeArrayForUrl(
152  '',
153  $this->parameterProvider->getUrlParameters(['identifier' => $combinedIdentifier])
154  );
155  $markup[] = '<input type="hidden" name="redirect" value="' . htmlspecialchars($redirectValue) . '" />';
156 
157  if (!empty($fileExtList)) {
158  $markup[] = '<div class="form-group">';
159  $markup[] = ' <label>';
160  $markup[] = htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.allowedFileExtensions')) . '<br/>';
161  $markup[] = ' </label>';
162  $markup[] = ' <div>';
163  $markup[] = implode(' ', $fileExtList);
164  $markup[] = ' </div>';
165  $markup[] = '</div>';
166  }
167 
168  $markup[] = '<div class="checkbox">';
169  $markup[] = ' <label>';
170  $markup[] = ' <input type="checkbox" name="overwriteExistingFiles" id="overwriteExistingFiles" value="replace" />';
171  $markup[] = htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_misc.xlf:overwriteExistingFiles'));
172  $markup[] = ' </label>';
173  $markup[] = '</div>';
174  $markup[] = '<input class="btn btn-default" type="submit" name="submit" value="'
175  . htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:file_upload.php.submit')) . '" />';
176 
177  $markup[] = '</form>';
178 
179  $code = implode(LF, $markup);
180 
181  // Add online media
182  // Create a list of allowed file extensions in a readable format "youtube, vimeo" etc.
183  $fileExtList = [];
184  $onlineMediaFileExt = OnlineMediaHelperRegistry::getInstance()->getSupportedFileExtensions();
185  foreach ($onlineMediaFileExt as $fileExt) {
187  && (empty($allowedExtensions) || in_array($fileExt, $allowedExtensions, true))
188  ) {
189  $fileExtList[] = '<span class="label label-success">'
190  . strtoupper(htmlspecialchars($fileExt)) . '</span>';
191  }
192  }
193  if (!empty($fileExtList)) {
194  $formAction = BackendUtility::getModuleUrl('online_media');
195 
196  $markup = [];
197  $markup[] = '<form action="' . htmlspecialchars($formAction)
198  . '" method="post" name="editform1" id="typo3-addMediaForm" enctype="multipart/form-data">';
199  $markup[] = '<h3>' . htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:online_media.new_media')) . ':</h3>';
200  $markup[] = '<p><strong>' . htmlspecialchars($lang->getLL('path')) . ':</strong>' . htmlspecialchars($header) . '</p>';
201  $markup[] = '<div class="form-group">';
202  $markup[] = '<input type="hidden" name="file[newMedia][0][target]" value="'
203  . htmlspecialchars($folderObject->getCombinedIdentifier()) . '" />';
204  $markup[] = '<input type="hidden" name="file[newMedia][0][allowed]" value="'
205  . htmlspecialchars(implode(',', $allowedExtensions)) . '" />';
206  $markup[] = '<div class="input-group">';
207  $markup[] = '<input type="text" name="file[newMedia][0][url]" class="form-control" placeholder="'
208  . htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:online_media.new_media.placeholder')) . '" />';
209  $markup[] = '<div class="input-group-btn">';
210  $markup[] = '<button class="btn btn-default">'
211  . htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:online_media.new_media.submit')) . '</button>';
212  $markup[] = '</div>';
213  $markup[] = '</div>';
214  $markup[] = '<div class="form-group">';
215  $markup[] = '<label>';
216  $markup[] = $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:online_media.new_media.allowedProviders') . '<br/>';
217  $markup[] = '</label>';
218  $markup[] = '<div>';
219  $markup[] = implode(' ', $fileExtList);
220  $markup[] = '</div>';
221  $markup[] = '</div>';
222  $markup[] = '<input type="hidden" name="redirect" value="' . htmlspecialchars($redirectValue) . '" />';
223  $markup[] = '</form>';
224 
225  $code .= implode(LF, $markup);
226  }
227 
228  return $code;
229  }
230 
237  public function getFileSearchField($searchWord)
238  {
239  $action = $this->parameterProvider->getScriptUrl()
240  . GeneralUtility::implodeArrayForUrl('', $this->parameterProvider->getUrlParameters([]));
241 
242  $markup = [];
243  $markup[] = '<form method="post" action="' . htmlspecialchars($action) . '" style="padding-bottom: 15px;">';
244  $markup[] = ' <div class="input-group">';
245  $markup[] = ' <input class="form-control" type="text" name="searchWord" value="'
246  . htmlspecialchars($searchWord) . '">';
247  $markup[] = ' <span class="input-group-btn">';
248  $markup[] = ' <button class="btn btn-default" type="submit">'
249  . htmlspecialchars(
250  $this->getLanguageService()->sL('LLL:EXT:filelist/Resources/Private/Language/locallang.xlf:search')
251  )
252  . '</button>';
253  $markup[] = ' </span>';
254  $markup[] = ' </div>';
255  $markup[] = '</form>';
256  return implode(LF, $markup);
257  }
258 
262  protected function getLanguageService()
263  {
264  return $GLOBALS['LANG'];
265  }
266 
270  protected function getBackendUser()
271  {
272  return $GLOBALS['BE_USER'];
273  }
274 }
static verifyFilenameAgainstDenyPattern($filename)
static implodeArrayForUrl($name, array $theArray, $str='', $skipBlank=false, $rawurlencodeParamName=false)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
__construct(LinkParameterProviderInterface $parameterProvider)
uploadForm(Folder $folderObject, array $allowedExtensions)