-
Notifications
You must be signed in to change notification settings - Fork 638
/
CreateFolderController.php
313 lines (286 loc) · 12.6 KB
/
CreateFolderController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
<?php
declare(strict_types = 1);
namespace TYPO3\CMS\Backend\Controller\File;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Backend\Template\ModuleTemplate;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Compatibility\PublicPropertyDeprecationTrait;
use TYPO3\CMS\Core\Http\HtmlResponse;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Resource\Exception\InsufficientFolderAccessPermissionsException;
use TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\OnlineMediaHelperRegistry;
use TYPO3\CMS\Core\Resource\ResourceFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;
/**
* Script class for the create-new script
*
* Displays forms for creating folders (1 to 10), a media asset or a new file.
*/
class CreateFolderController
{
use PublicPropertyDeprecationTrait;
/**
* @var array
*/
protected $deprecatedPublicProperties = [
'number' => 'Using $number of class CreateFolderController from outside is discouraged, as this variable is only used for internal storage.',
'folderNumber' => 'Using $folderNumber of class CreateFolderController from outside is discouraged, as this variable is only used for internal storage.',
'target' => 'Using $target of class CreateFolderController from outside is discouraged, as this variable is only used for internal storage.',
'content' => 'Using $content of class CreateFolderController from outside is discouraged, as this variable is only used for internal storage.',
'returnUrl' => 'Using $content of class CreateFolderController from outside is discouraged, as this variable is only used for internal storage.',
'title' => 'Using $content of class CreateFolderController from outside is discouraged, as this variable is only used for internal storage.',
];
/**
* @var int
*/
protected $folderNumber = 10;
/**
* Name of the filemount
*
* @var string
* @deprecated since v9, will be removed in v10, unused
*/
protected $title;
/**
* @var int
*/
protected $number;
/**
* Set with the target path inputted in &target
*
* @var string
*/
protected $target;
/**
* The folder object which is the target directory
*
* @var \TYPO3\CMS\Core\Resource\Folder $folderObject
*/
protected $folderObject;
/**
* Return URL of list module.
*
* @var string
*/
protected $returnUrl;
/**
* @var array
*/
protected $pathInfo;
/**
* Accumulating content
*
* @var string
* @deprecated since v9, will be removed in v10, unused
*/
protected $content;
/**
* ModuleTemplate object
*
* @var ModuleTemplate
*/
protected $moduleTemplate;
/**
* Constructor
*/
public function __construct()
{
$this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
$GLOBALS['SOBE'] = $this;
// @deprecated since v9, will be moved out of __construct() in v10
$this->init($GLOBALS['TYPO3_REQUEST']);
}
/**
* Processes the request, currently everything is handled and put together via "main()"
*
* @param ServerRequestInterface $request the current request
* @return ResponseInterface the response with the content
*/
public function mainAction(ServerRequestInterface $request): ResponseInterface
{
$this->main();
return new HtmlResponse($this->moduleTemplate->renderContent());
}
/**
* @param ServerRequestInterface|null $request
*
* @throws InsufficientFolderAccessPermissionsException
* @throws \RuntimeException
*/
protected function init(ServerRequestInterface $request): void
{
$parsedBody = $request->getParsedBody();
$queryParams = $request->getQueryParams();
$this->number = $parsedBody['number'] ?? $queryParams['number'] ?? 0;
$this->target = ($combinedIdentifier = $parsedBody['target'] ?? $queryParams['target'] ?? '');
$this->returnUrl = GeneralUtility::sanitizeLocalUrl($parsedBody['returnUrl'] ?? $queryParams['returnUrl'] ?? '');
// create the folder object
if ($combinedIdentifier) {
$this->folderObject = ResourceFactory::getInstance()
->getFolderObjectFromCombinedIdentifier($combinedIdentifier);
}
// Cleaning and checking target directory
if (!$this->folderObject) {
$title = $this->getLanguageService()->sL('LLL:EXT:filelist/Resources/Private/Language/locallang_mod_file_list.xlf:paramError');
$message = $this->getLanguageService()->sL('LLL:EXT:filelist/Resources/Private/Language/locallang_mod_file_list.xlf:targetNoDir');
throw new \RuntimeException($title . ': ' . $message, 1294586845);
}
if ($this->folderObject->getStorage()->getUid() === 0) {
throw new InsufficientFolderAccessPermissionsException(
'You are not allowed to access folders outside your storages',
1375889838
);
}
$pathInfo = [
'combined_identifier' => $this->folderObject->getCombinedIdentifier(),
];
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
$this->moduleTemplate->getDocHeaderComponent()->setMetaInformation($pathInfo);
$this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ContextMenu');
$this->moduleTemplate->addJavaScriptCode(
'CreateFolderInlineJavaScript',
'var path = "' . $this->target . '";
var confirmTitle = '
. GeneralUtility::quoteJSvalue(
$this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:pleaseConfirm')
)
. ';
var confirmText = '
. GeneralUtility::quoteJSvalue(
$this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:mess.redraw')
)
. ';
function reload(a) {
var params = "&target="+encodeURIComponent(path)+"&number="+a+"&returnUrl=' . rawurlencode($this->returnUrl) . '";
var url = \'' . (string)$uriBuilder->buildUriFromRoute('file_newfolder') . '\';
if (!changed) {
window.location.href = url + params;
} else {
var modal = top.TYPO3.Modal.confirm(confirmTitle, confirmText);
modal.on(\'confirm.button.cancel\', function(e) {
top.TYPO3.Modal.currentModal.trigger(\'modal-dismiss\');
});
modal.on(\'confirm.button.ok\', function(e) {
top.TYPO3.Modal.currentModal.trigger(\'modal-dismiss\');
window.location.href = url + params;
});
}
}
function backToList() {
top.goToModule("file_FilelistList");
}
var changed = 0;'
);
}
/**
* Main function, rendering the main module content
*/
public function main()
{
// Foreign class call? Method will be protected in v10, giving core freedom to move stuff around
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
if (end($backtrace)['class'] !== __CLASS__) {
// @deprecated since TYPO3 v9, this method will be set to protected in v10
trigger_error('Method main() will be set to protected in v10. Do not call from other extension', E_USER_DEPRECATED);
}
$lang = $this->getLanguageService();
$assigns = [];
$assigns['target'] = $this->target;
if ($this->folderObject->checkActionPermission('add')) {
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
$assigns['moduleUrlTceFile'] = (string)$uriBuilder->buildUriFromRoute('tce_file');
$assigns['cshFileNewFolder'] = BackendUtility::cshItem('xMOD_csh_corebe', 'file_newfolder');
// Making the selector box for the number of concurrent folder-creations
$this->number = MathUtility::forceIntegerInRange($this->number, 1, 10);
for ($a = 1; $a <= $this->folderNumber; $a++) {
$options = [];
$options['value'] = $a;
$options['selected'] = ($this->number == $a ? ' selected="selected"' : '');
$assigns['options'][] = $options;
}
// Making the number of new-folder boxes needed:
for ($a = 0; $a < $this->number; $a++) {
$folder = [];
$folder['this'] = $a;
$folder['next'] = $a + 1;
$assigns['folders'][] = $folder;
}
// Making submit button for folder creation:
$assigns['returnUrl'] = $this->returnUrl;
}
if ($this->folderObject->getStorage()->checkUserActionPermission('add', 'File')) {
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
$assigns['moduleUrlOnlineMedia'] = (string)$uriBuilder->buildUriFromRoute('online_media');
$assigns['cshFileNewMedia'] = BackendUtility::cshItem('xMOD_csh_corebe', 'file_newMedia');
// Create a list of allowed file extensions with the readable format "youtube, vimeo" etc.
$fileExtList = [];
$onlineMediaFileExt = OnlineMediaHelperRegistry::getInstance()->getSupportedFileExtensions();
foreach ($onlineMediaFileExt as $fileExt) {
if (GeneralUtility::verifyFilenameAgainstDenyPattern('.' . $fileExt)) {
$fileExtList[] = strtoupper(htmlspecialchars($fileExt));
}
}
$assigns['fileExtList'] = $fileExtList;
$assigns['moduleUrlTceFile'] = (string)$uriBuilder->buildUriFromRoute('tce_file');
$assigns['cshFileNewFile'] = BackendUtility::cshItem('xMOD_csh_corebe', 'file_newfile');
// Create a list of allowed file extensions with a text format "*.txt, *.css" etc.
$fileExtList = [];
$textFileExt = GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'], true);
foreach ($textFileExt as $fileExt) {
if (GeneralUtility::verifyFilenameAgainstDenyPattern('.' . $fileExt)) {
$fileExtList[] = strtoupper(htmlspecialchars($fileExt));
}
}
$assigns['txtFileExtList'] = $fileExtList;
}
$buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
// CSH button
$helpButton = $buttonBar->makeHelpButton()
->setFieldName('file_new')
->setModuleName('xMOD_csh_corebe');
$buttonBar->addButton($helpButton);
// Back
if ($this->returnUrl) {
$backButton = $buttonBar->makeLinkButton()
->setHref($this->returnUrl)
->setTitle($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.goBack'))
->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-view-go-back', Icon::SIZE_SMALL));
$buttonBar->addButton($backButton);
}
// Rendering of the output via fluid
$view = GeneralUtility::makeInstance(StandaloneView::class);
$view->setTemplateRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates')]);
$view->setPartialRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Partials')]);
$view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
'EXT:backend/Resources/Private/Templates/File/CreateFolder.html'
));
$view->assignMultiple($assigns);
$this->moduleTemplate->setContent($view->render());
}
/**
* Returns LanguageService
*
* @return LanguageService
*/
protected function getLanguageService(): LanguageService
{
return $GLOBALS['LANG'];
}
}