TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
FolderUtilityRenderer.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Recordlist\View;
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[] = '<div class="element-browser-section element-browser-createfolder">';
69  $markup[] = '<form action="' . htmlspecialchars($formAction)
70  . '" method="post" name="editform" enctype="multipart/form-data">';
71  $markup[] = '<h3>' . htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:create_folder.title')) . ':</h3>';
72  $markup[] = '<p><strong>' . htmlspecialchars($lang->getLL('path')) . ':</strong>'
73  . htmlspecialchars($folderObject->getIdentifier()) . '</p>';
74 
75  $a = 1;
76  $markup[] = '<div class="row form-group"><div class="col-xs-8">';
77  $markup[] = '<input class="form-control" type="text" name="file[newfolder][' . $a . '][data]" />';
78  $markup[] = '<input type="hidden" name="file[newfolder][' . $a . '][target]" value="'
79  . htmlspecialchars($folderObject->getCombinedIdentifier()) . '" />';
80 
81  // Make footer of upload form, including the submit button:
82  $redirectValue = $this->parameterProvider->getScriptUrl() . GeneralUtility::implodeArrayForUrl(
83  '',
84  $this->parameterProvider->getUrlParameters(
85  ['identifier' => $folderObject->getCombinedIdentifier()]
86  )
87  );
88  $markup[] = '<input type="hidden" name="redirect" value="' . htmlspecialchars($redirectValue) . '" />';
89  $markup[] = '</div><div class="col-xs-4">';
90  $markup[] = '<input class="btn btn-default" type="submit" name="submit" value="'
91  . htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:create_folder.submit')) . '" />';
92 
93  $markup[] = '</div></div></form>';
94  $markup[] = '</div>';
95 
96  return implode(LF, $markup);
97  }
98 
108  public function uploadForm(Folder $folderObject, array $allowedExtensions)
109  {
110  if (!$folderObject->checkActionPermission('write')) {
111  return '';
112  }
113  // Read configuration of upload field count
114  $userSetting = $this->getBackendUser()->getTSConfigVal('options.folderTree.uploadFieldsInLinkBrowser');
115  $count = isset($userSetting) ? (int)$userSetting : 1;
116  if ($count === 0) {
117  return '';
118  }
119 
120  $count = (int)$count === 0 ? 1 : (int)$count;
121  // Create header, showing upload path:
122  $header = $folderObject->getIdentifier();
123  $lang = $this->getLanguageService();
124  // Create a list of allowed file extensions with the readable format "youtube, vimeo" etc.
125  $fileExtList = [];
126  foreach ($allowedExtensions as $fileExt) {
128  $fileExtList[] = '<span class="label label-success">'
129  . strtoupper(htmlspecialchars($fileExt)) . '</span>';
130  }
131  }
132  $formAction = BackendUtility::getModuleUrl('tce_file');
133  $combinedIdentifier = $folderObject->getCombinedIdentifier();
134  $markup = [];
135  $markup[] = '<div class="element-browser-section element-browser-upload">';
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 class="form-control">';
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  $markup[] = '</div>';
179 
180  $code = implode(LF, $markup);
181 
182  // Add online media
183  // Create a list of allowed file extensions in a readable format "youtube, vimeo" etc.
184  $fileExtList = [];
185  $onlineMediaFileExt = OnlineMediaHelperRegistry::getInstance()->getSupportedFileExtensions();
186  foreach ($onlineMediaFileExt as $fileExt) {
188  && (empty($allowedExtensions) || in_array($fileExt, $allowedExtensions, true))
189  ) {
190  $fileExtList[] = '<span class="label label-success">'
191  . strtoupper(htmlspecialchars($fileExt)) . '</span>';
192  }
193  }
194  if (!empty($fileExtList)) {
195  $formAction = BackendUtility::getModuleUrl('online_media');
196 
197  $markup = [];
198  $markup[] = '<div class="element-browser-section element-browser-mediaurls">';
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:lang/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="row form-group"><div class="col-xs-8">';
204  $markup[] = '<input type="hidden" name="file[newMedia][0][target]" value="'
205  . htmlspecialchars($folderObject->getCombinedIdentifier()) . '" />';
206  $markup[] = '<input type="hidden" name="file[newMedia][0][allowed]" value="'
207  . htmlspecialchars(implode(',', $allowedExtensions)) . '" />';
208  $markup[] = '<input type="text" name="file[newMedia][0][url]" class="form-control" placeholder="'
209  . htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:online_media.new_media.placeholder')) . '" />';
210  $markup[] = '</div><div class="col-xs-4">';
211  $markup[] = '<button class="btn btn-default">'
212  . htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:online_media.new_media.submit')) . '</button>';
213 
214  $markup[] = '</div></div>';
215  $markup[] = '<div class="form-group">';
216  $markup[] = ' <label>';
217  $markup[] = $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:online_media.new_media.allowedProviders') . '<br/>';
218  $markup[] = ' </label>';
219  $markup[] = ' <div class="form-control">';
220  $markup[] = implode(' ', $fileExtList);
221  $markup[] = ' </div>';
222  $markup[] = '</div>';
223  $markup[] = '<input type="hidden" name="redirect" value="' . htmlspecialchars($redirectValue) . '" />';
224  $markup[] = '</form>';
225  $markup[] = '</div>';
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  . GeneralUtility::implodeArrayForUrl('', $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 }
uploadForm(Folder $folderObject, array $allowedExtensions)
static implodeArrayForUrl($name, array $theArray, $str= '', $skipBlank=false, $rawurlencodeParamName=false)
static verifyFilenameAgainstDenyPattern($filename)
__construct(LinkParameterProviderInterface $parameterProvider)
if(TYPO3_MODE=== 'BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']