[TASK] Remove undefined property iconFactory from EditFileController
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Controller / File / CreateFolderController.php
1 <?php
2 namespace TYPO3\CMS\Backend\Controller\File;
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
17 use Psr\Http\Message\ResponseInterface;
18 use Psr\Http\Message\ServerRequestInterface;
19 use TYPO3\CMS\Backend\Module\AbstractModule;
20 use TYPO3\CMS\Backend\Utility\BackendUtility;
21 use TYPO3\CMS\Core\Imaging\Icon;
22 use TYPO3\CMS\Core\Resource\Exception\InsufficientFolderAccessPermissionsException;
23 use TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\OnlineMediaHelperRegistry;
24 use TYPO3\CMS\Core\Resource\ResourceFactory;
25 use TYPO3\CMS\Core\Utility\GeneralUtility;
26 use TYPO3\CMS\Core\Utility\MathUtility;
27
28 /**
29 * Script Class for the create-new script; Displays a form for creating up to 10 folders or one new text file
30 */
31 class CreateFolderController extends AbstractModule
32 {
33 /**
34 * @var int
35 */
36 public $folderNumber = 10;
37
38 /**
39 * Name of the filemount
40 *
41 * @var string
42 */
43 public $title;
44
45 /**
46 * @var int
47 */
48 public $number;
49
50 /**
51 * Set with the target path inputted in &target
52 *
53 * @var string
54 */
55 public $target;
56
57 /**
58 * The folder object which is the target directory
59 *
60 * @var \TYPO3\CMS\Core\Resource\Folder $folderObject
61 */
62 protected $folderObject;
63
64 /**
65 * Return URL of list module.
66 *
67 * @var string
68 */
69 public $returnUrl;
70
71 /**
72 * @var array
73 */
74 protected $pathInfo;
75
76 /**
77 * Accumulating content
78 *
79 * @var string
80 */
81 public $content;
82
83 /**
84 * Constructor
85 */
86 public function __construct()
87 {
88 parent::__construct();
89 $GLOBALS['SOBE'] = $this;
90 $this->init();
91 }
92
93 /**
94 * @throws InsufficientFolderAccessPermissionsException
95 * @throws \RuntimeException
96 */
97 protected function init()
98 {
99 // Initialize GPvars:
100 $this->number = GeneralUtility::_GP('number');
101 $this->target = ($combinedIdentifier = GeneralUtility::_GP('target'));
102 $this->returnUrl = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'));
103 // create the folder object
104 if ($combinedIdentifier) {
105 $this->folderObject = ResourceFactory::getInstance()
106 ->getFolderObjectFromCombinedIdentifier($combinedIdentifier);
107 }
108 // Cleaning and checking target directory
109 if (!$this->folderObject) {
110 $title = htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:paramError'));
111 $message = htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:targetNoDir'));
112 throw new \RuntimeException($title . ': ' . $message, 1294586845);
113 }
114 if ($this->folderObject->getStorage()->getUid() === 0) {
115 throw new InsufficientFolderAccessPermissionsException(
116 'You are not allowed to access folders outside your storages',
117 1375889838
118 );
119 }
120
121 $pathInfo = [
122 'combined_identifier' => $this->folderObject->getCombinedIdentifier(),
123 ];
124 $this->moduleTemplate->getDocHeaderComponent()->setMetaInformation($pathInfo);
125 $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ClickMenu');
126 $this->moduleTemplate->addJavaScriptCode(
127 'CreateFolderInlineJavaScript',
128 'var path = "' . $this->target . '";
129 var confirmTitle = '
130 . GeneralUtility::quoteJSvalue(
131 $this->getLanguageService()->sL('LLL:EXT:lang/locallang_common.xlf:pleaseConfirm')
132 )
133 . ';
134 var confirmText = '
135 . GeneralUtility::quoteJSvalue(
136 $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:mess.redraw')
137 )
138 . ';
139 function reload(a) {
140 var params = "&target="+encodeURIComponent(path)+"&number="+a+"&returnUrl=' . rawurlencode($this->returnUrl) . '";
141 var url = \'' . BackendUtility::getModuleUrl('file_newfolder') . '\';
142 if (!changed) {
143 window.location.href = url + params;
144 } else {
145 var modal = top.TYPO3.Modal.confirm(confirmTitle, confirmText);
146 modal.on(\'confirm.button.cancel\', function(e) {
147 top.TYPO3.Modal.currentModal.trigger(\'modal-dismiss\');
148 });
149 modal.on(\'confirm.button.ok\', function(e) {
150 top.TYPO3.Modal.currentModal.trigger(\'modal-dismiss\');
151 window.location.href = url + params;
152 });
153 }
154 }
155 function backToList() {
156 top.goToModule("file_FilelistList");
157 }
158 var changed = 0;'
159 );
160 }
161
162 /**
163 * Main function, rendering the main module content
164 *
165 * @return void
166 */
167 public function main()
168 {
169 $lang = $this->getLanguageService();
170 $pageContent = '<h1>' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.pagetitle') . '</h1>';
171
172 if ($this->folderObject->checkActionPermission('add')) {
173 $code = '<form role="form" action="' . htmlspecialchars(BackendUtility::getModuleUrl('tce_file')) . '" method="post" name="editform">';
174 // Making the selector box for the number of concurrent folder-creations
175 $this->number = MathUtility::forceIntegerInRange($this->number, 1, 10);
176 $code .= '
177 <div class="form-group">
178 <div class="form-section">
179 <div class="form-group">
180 <label for="number-of-new-folders">' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.number_of_folders') . '</label> ' . BackendUtility::cshItem('xMOD_csh_corebe', 'file_newfolder') . '
181 <div class="form-control-wrap">
182 <div class="input-group">
183 <select class="form-control form-control-adapt" name="number" id="number-of-new-folders" onchange="reload(this.options[this.selectedIndex].value);">';
184 for ($a = 1; $a <= $this->folderNumber; $a++) {
185 $code .= '<option value="' . $a . '"' . ($this->number == $a ? ' selected="selected"' : '') . '>' . $a . '</option>';
186 }
187 $code .= '
188 </select>
189 </div>
190 </div>
191 </div>
192 </div>
193 ';
194 // Making the number of new-folder boxes needed:
195 for ($a = 0; $a < $this->number; $a++) {
196 $code .= '
197 <div class="form-section">
198 <div class="form-group">
199 <label for="folder_new_' . $a . '">' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.label_newfolder') . ' ' . ($a + 1) . ':</label>
200 <div class="form-control-wrap">
201 <input type="text" class="form-control" id="folder_new_' . $a . '" name="file[newfolder][' . $a . '][data]" onchange="changed=true;" />
202 <input type="hidden" name="file[newfolder][' . $a . '][target]" value="' . htmlspecialchars($this->target) . '" />
203 </div>
204 </div>
205 </div>';
206 }
207 // Making submit button for folder creation:
208 $code .= '
209 </div><div class="form-group">
210 <input class="btn btn-default" type="submit" value="' . htmlspecialchars($lang->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.submit')) . '" />
211 <input type="hidden" name="redirect" value="' . htmlspecialchars($this->returnUrl) . '" />
212 </div>
213 ';
214
215 // Switching form tags:
216 $pageContent .= '<h3>' . htmlspecialchars($lang->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.newfolders')) . '</h3>';
217 $pageContent .= '<div>' . $code . '</form></div>';
218 }
219
220 if ($this->folderObject->getStorage()->checkUserActionPermission('add', 'File')) {
221 $pageContent .= '<form action="' . htmlspecialchars(BackendUtility::getModuleUrl('online_media')) . '" method="post" name="editform2">';
222 // Create a list of allowed file extensions with the readable format "youtube, vimeo" etc.
223 $fileExtList = [];
224 $onlineMediaFileExt = OnlineMediaHelperRegistry::getInstance()->getSupportedFileExtensions();
225 foreach ($onlineMediaFileExt as $fileExt) {
226 if (GeneralUtility::verifyFilenameAgainstDenyPattern('.' . $fileExt)) {
227 $fileExtList[] = '<span class="label label-success">' . strtoupper(htmlspecialchars($fileExt)) . '</span>';
228 }
229 }
230 // Add form fields for adding media files:
231 $code = '
232 <div class="form-group">
233 <div class="form-section">
234 <div class="form-group">
235 <label for="newMedia">' . htmlspecialchars($lang->sL('LLL:EXT:lang/locallang_core.xlf:online_media.new_media.label')) . '</label> ' . BackendUtility::cshItem('xMOD_csh_corebe', 'file_newMedia') . '
236 <div class="form-control-wrap">
237 <input class="form-control" type="text" id="newMedia" name="file[newMedia][0][url]"
238 placeholder="' . htmlspecialchars($lang->sL('LLL:EXT:lang/locallang_core.xlf:online_media.new_media.placeholder')) . '" />
239 <input type="hidden" name="file[newMedia][0][target]" value="' . htmlspecialchars($this->target) . '" />
240 </div>
241 <div class="help-block">
242 ' . htmlspecialchars($lang->sL('LLL:EXT:lang/locallang_core.xlf:online_media.new_media.allowedProviders')) . '<br>
243 ' . implode(' ', $fileExtList) . '
244 </div>
245 </div>
246 </div>
247 </div>
248 ';
249 // Submit button for creation of a new media:
250 $code .= '
251 <div class="form-group">
252 <input class="btn btn-default" type="submit" value="' . htmlspecialchars($lang->sL('LLL:EXT:lang/locallang_core.xlf:online_media.new_media.submit')) . '" />
253 <input type="hidden" name="redirect" value="' . htmlspecialchars($this->returnUrl) . '" />
254 </div>
255 ';
256 $pageContent .= '<h3>' . htmlspecialchars($lang->sL('LLL:EXT:lang/locallang_core.xlf:online_media.new_media')) . '</h3>';
257 $pageContent .= '<div>' . $code . '</div>';
258 $pageContent .= '</form>';
259
260 $pageContent .= '<form action="' . BackendUtility::getModuleUrl('tce_file') . '" method="post" name="editform3">';
261 // Create a list of allowed file extensions with the nice format "*.jpg, *.gif" etc.
262 $fileExtList = [];
263 $textFileExt = GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'], true);
264 foreach ($textFileExt as $fileExt) {
265 if (GeneralUtility::verifyFilenameAgainstDenyPattern('.' . $fileExt)) {
266 $fileExtList[] = '<span class="label label-success">' . strtoupper(htmlspecialchars($fileExt)) . '</span>';
267 }
268 }
269 // Add form fields for creation of a new, blank text file:
270 $code = '
271 <div class="form-group">
272 <div class="form-section">
273 <div class="form-group">
274 <label for="newfile">' . htmlspecialchars($lang->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.label_newfile')) . '</label> ' . BackendUtility::cshItem('xMOD_csh_corebe', 'file_newfile') . '
275 <div class="form-control-wrap">
276 <input class="form-control" type="text" id="newfile" name="file[newfile][0][data]" onchange="changed=true;" />
277 <input type="hidden" name="file[newfile][0][target]" value="' . htmlspecialchars($this->target) . '" />
278 </div>
279 <div class="help-block">
280 ' . htmlspecialchars($lang->sL('LLL:EXT:lang/locallang_core.xlf:cm.allowedFileExtensions')) . '<br>
281 ' . implode(' ', $fileExtList) . '
282 </div>
283 </div>
284 </div>
285 </div>
286 ';
287 // Submit button for "creation of a new file":
288 $code .= '
289 <div class="form-group">
290 <button class="btn btn-default" name="edit" type="submit" value="1">' . htmlspecialchars($lang->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.newfile_submit')) . '</button>
291 <input type="hidden" name="redirect" value="' . htmlspecialchars($this->returnUrl) . '" />
292 </div>
293 ';
294 $pageContent .= '<h3>' . htmlspecialchars($lang->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.newfile')) . '</h3>';
295 $pageContent .= '<div>' . $code . '</div>';
296 $pageContent .= '</form>';
297 }
298
299 $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
300 // Back
301 if ($this->returnUrl) {
302 $backButton = $buttonBar->makeLinkButton()
303 ->setHref($this->returnUrl)
304 ->setTitle($lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.goBack'))
305 ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-view-go-back', Icon::SIZE_SMALL));
306 $buttonBar->addButton($backButton);
307 }
308
309 $this->content .= '<div>' . $pageContent . '</div>';
310 $this->moduleTemplate->setContent($this->content);
311 }
312
313 /**
314 * Processes the request, currently everything is handled and put together via "main()"
315 *
316 * @param ServerRequestInterface $request the current request
317 * @param ResponseInterface $response
318 * @return ResponseInterface the response with the content
319 */
320 public function mainAction(ServerRequestInterface $request, ResponseInterface $response)
321 {
322 $this->main();
323 $response->getBody()->write($this->moduleTemplate->renderContent());
324 return $response;
325 }
326
327 /**
328 * Returns LanguageService
329 *
330 * @return \TYPO3\CMS\Lang\LanguageService
331 */
332 protected function getLanguageService()
333 {
334 return $GLOBALS['LANG'];
335 }
336 }