TYPO3 CMS  TYPO3_7-6
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[] = '<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>' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:create_folder.title', true) . ':</h3>';
72  $markup[] = '<p><strong>' . $lang->getLL('path', true) . ':</strong>'
73  . htmlspecialchars($folderObject->getIdentifier()) . '</p>';
74 
75  $a = 1;
76  $markup[] = '<input class="form-control" type="text" name="file[newfolder][' . $a . '][data]" />';
77  $markup[] = '<input type="hidden" name="file[newfolder][' . $a . '][target]" value="'
78  . htmlspecialchars($folderObject->getCombinedIdentifier()) . '" />';
79 
80  // Make footer of upload form, including the submit button:
81  $redirectValue = $this->parameterProvider->getScriptUrl() . GeneralUtility::implodeArrayForUrl(
82  '',
83  $this->parameterProvider->getUrlParameters(
84  ['identifier' => $folderObject->getCombinedIdentifier()]
85  )
86  );
87  $markup[] = '<input type="hidden" name="redirect" value="' . htmlspecialchars($redirectValue) . '" />';
88  $markup[] = '<input class="btn btn-default" type="submit" name="submit" value="'
89  . $lang->sL('LLL:EXT:lang/locallang_core.xlf:create_folder.submit', true) . '" />';
90 
91  $markup[] = ' </form>';
92  $markup[] = '</div>';
93 
94  return implode(LF, $markup);
95  }
96 
106  public function uploadForm(Folder $folderObject, array $allowedExtensions)
107  {
108  if (!$folderObject->checkActionPermission('write')) {
109  return '';
110  }
111  // Read configuration of upload field count
112  $userSetting = $this->getBackendUser()->getTSConfigVal('options.folderTree.uploadFieldsInLinkBrowser');
113  $count = isset($userSetting) ? (int)$userSetting : 1;
114  if ($count === 0) {
115  return '';
116  }
117 
118  $count = (int)$count === 0 ? 1 : (int)$count;
119  // Create header, showing upload path:
120  $header = $folderObject->getIdentifier();
121  $lang = $this->getLanguageService();
122  // Create a list of allowed file extensions with the readable format "youtube, vimeo" etc.
123  $fileExtList = [];
124  foreach ($allowedExtensions as $fileExt) {
126  $fileExtList[] = '<span class="label label-success">'
127  . strtoupper(htmlspecialchars($fileExt)) . '</span>';
128  }
129  }
130  $formAction = BackendUtility::getModuleUrl('tce_file');
131  $combinedIdentifier = $folderObject->getCombinedIdentifier();
132  $markup = [];
133  $markup[] = '<div class="element-browser-section element-browser-upload">';
134  $markup[] = ' <form action="' . htmlspecialchars($formAction)
135  . '" method="post" name="editform" enctype="multipart/form-data">';
136  $markup[] = ' <h3>' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:file_upload.php.pagetitle', true) . ':</h3>';
137  $markup[] = ' <p><strong>' . $lang->getLL('path', true) . ':</strong>' . htmlspecialchars($header) . '</p>';
138  // Traverse the number of upload fields:
139  for ($a = 1; $a <= $count; $a++) {
140  $markup[] = '<div class="form-group">';
141  $markup[] = '<span class="btn btn-default btn-file">';
142  $markup[] = '<input type="file" multiple="multiple" name="upload_' . $a . '[]" size="50" />';
143  $markup[] = '</span>';
144  $markup[] = '</div>';
145  $markup[] = '<input type="hidden" name="file[upload][' . $a . '][target]" value="'
146  . htmlspecialchars($combinedIdentifier) . '" />';
147  $markup[] = '<input type="hidden" name="file[upload][' . $a . '][data]" value="' . $a . '" />';
148  }
149  $redirectValue = $this->parameterProvider->getScriptUrl() . GeneralUtility::implodeArrayForUrl(
150  '',
151  $this->parameterProvider->getUrlParameters(['identifier' => $combinedIdentifier])
152  );
153  $markup[] = '<input type="hidden" name="redirect" value="' . htmlspecialchars($redirectValue) . '" />';
154 
155  if (!empty($fileExtList)) {
156  $markup[] = '<div class="form-group">';
157  $markup[] = ' <label>';
158  $markup[] = $lang->sL('LLL:EXT:lang/locallang_core.xlf:cm.allowedFileExtensions', true) . '<br/>';
159  $markup[] = ' </label>';
160  $markup[] = ' <div class="form-control">';
161  $markup[] = implode(' ', $fileExtList);
162  $markup[] = ' </div>';
163  $markup[] = '</div>';
164  }
165 
166  $markup[] = '<div class="checkbox">';
167  $markup[] = ' <label>';
168  $markup[] = ' <input type="checkbox" name="overwriteExistingFiles" id="overwriteExistingFiles" value="1" />';
169  $markup[] = $lang->sL('LLL:EXT:lang/locallang_misc.xlf:overwriteExistingFiles', true);
170  $markup[] = ' </label>';
171  $markup[] = '</div>';
172  $markup[] = '<input class="btn btn-default" type="submit" name="submit" value="'
173  . $lang->sL('LLL:EXT:lang/locallang_core.xlf:file_upload.php.submit', true) . '" />';
174 
175  $markup[] = ' </form>';
176  $markup[] = '</div>';
177 
178  $code = implode(LF, $markup);
179 
180  // Add online media
181  // Create a list of allowed file extensions in a readable format "youtube, vimeo" etc.
182  $fileExtList = [];
183  $onlineMediaFileExt = OnlineMediaHelperRegistry::getInstance()->getSupportedFileExtensions();
184  foreach ($onlineMediaFileExt as $fileExt) {
186  && (empty($allowedExtensions) || in_array($fileExt, $allowedExtensions, true))
187  ) {
188  $fileExtList[] = '<span class="label label-success">'
189  . strtoupper(htmlspecialchars($fileExt)) . '</span>';
190  }
191  }
192  if (!empty($fileExtList)) {
193  $formAction = BackendUtility::getModuleUrl('online_media');
194 
195  $markup = [];
196  $markup[] = '<div class="element-browser-section element-browser-mediaurls">';
197  $markup[] = ' <form action="' . htmlspecialchars($formAction)
198  . '" method="post" name="editform1" id="typo3-addMediaForm" enctype="multipart/form-data">';
199  $markup[] = '<h3>' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:online_media.new_media', true) . ':</h3>';
200  $markup[] = '<p><strong>' . $lang->getLL('path', true) . ':</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[] = '<input type="text" name="file[newMedia][0][url]" class="form-control" placeholder="'
207  . $lang->sL('LLL:EXT:lang/locallang_core.xlf:online_media.new_media.placeholder', true) . '" />';
208  $markup[] = '<button class="btn btn-default">'
209  . $lang->sL('LLL:EXT:lang/locallang_core.xlf:online_media.new_media.submit', true) . '</button>';
210  $markup[] = '</div>';
211  $markup[] = '<div class="form-group">';
212  $markup[] = ' <label>';
213  $markup[] = $lang->sL('LLL:EXT:lang/locallang_core.xlf:online_media.new_media.allowedProviders') . '<br/>';
214  $markup[] = ' </label>';
215  $markup[] = ' <div class="form-control">';
216  $markup[] = implode(' ', $fileExtList);
217  $markup[] = ' </div>';
218  $markup[] = '</div>';
219  $markup[] = '<input type="hidden" name="redirect" value="' . htmlspecialchars($redirectValue) . '" />';
220  $markup[] = '</div>';
221  $markup[] = '</form>';
222  $markup[] = '</div>';
223 
224  $code .= implode(LF, $markup);
225  }
226 
227  return $code;
228  }
229 
236  public function getFileSearchField($searchWord)
237  {
238  $action = $this->parameterProvider->getScriptUrl()
239  . GeneralUtility::implodeArrayForUrl('', $this->parameterProvider->getUrlParameters([]));
240 
241  $markup = [];
242  $markup[] = '<form method="post" action="' . htmlspecialchars($action) . '" style="padding-bottom: 15px;">';
243  $markup[] = ' <div class="input-group">';
244  $markup[] = ' <input class="form-control" type="text" name="searchWord" value="'
245  . htmlspecialchars($searchWord) . '">';
246  $markup[] = ' <span class="input-group-btn">';
247  $markup[] = ' <button class="btn btn-default" type="submit">'
248  . htmlspecialchars(
249  $this->getLanguageService()->sL('LLL:EXT:filelist/Resources/Private/Language/locallang.xlf:search')
250  )
251  . '</button>';
252  $markup[] = ' </span>';
253  $markup[] = ' </div>';
254  $markup[] = '</form>';
255  return implode(LF, $markup);
256  }
257 
261  protected function getLanguageService()
262  {
263  return $GLOBALS['LANG'];
264  }
265 
269  protected function getBackendUser()
270  {
271  return $GLOBALS['BE_USER'];
272  }
273 }
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)