2 namespace TYPO3\CMS\Backend\Controller\File
;
5 * This file is part of the TYPO3 CMS project.
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.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
17 use TYPO3\CMS\Backend\Utility\BackendUtility
;
18 use TYPO3\CMS\Core\Utility\GeneralUtility
;
21 * Script Class for the create-new script; Displays a form for creating up to 10 folders or one new text file
23 class CreateFolderController
{
28 public $folderNumber = 10;
31 * document template object
33 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
38 * Name of the filemount
50 * Set with the target path inputted in &target
57 * The folder object which is the target directory
59 * @var \TYPO3\CMS\Core\Resource\Folder $folderObject
61 protected $folderObject;
64 * Return URL of list module.
71 * Accumulating content
80 public function __construct() {
81 $GLOBALS['SOBE'] = $this;
82 $GLOBALS['BACK_PATH'] = '';
92 protected function init() {
94 $this->number
= GeneralUtility
::_GP('number');
95 $this->target
= ($combinedIdentifier = GeneralUtility
::_GP('target'));
96 $this->returnUrl
= GeneralUtility
::sanitizeLocalUrl(GeneralUtility
::_GP('returnUrl'));
97 // create the folder object
98 if ($combinedIdentifier) {
99 $this->folderObject
= \TYPO3\CMS\Core\Resource\ResourceFactory
::getInstance()->getFolderObjectFromCombinedIdentifier($combinedIdentifier);
101 // Cleaning and checking target directory
102 if (!$this->folderObject
) {
103 $title = $this->getLanguageService()->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:paramError', TRUE
);
104 $message = $this->getLanguageService()->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:targetNoDir', TRUE
);
105 throw new \
RuntimeException($title . ': ' . $message, 1294586845);
107 if ($this->folderObject
->getStorage()->getUid() === 0) {
108 throw new \TYPO3\CMS\Core\Resource\Exception\
InsufficientFolderAccessPermissionsException('You are not allowed to access folders outside your storages', 1375889838);
111 // Setting the title and the icon
112 $icon = \TYPO3\CMS\Backend\Utility\IconUtility
::getSpriteIcon('apps-filetree-root');
113 $this->title
= $icon . htmlspecialchars($this->folderObject
->getStorage()->getName()) . ': ' . htmlspecialchars($this->folderObject
->getIdentifier());
114 // Setting template object
115 $this->doc
= GeneralUtility
::makeInstance(\TYPO3\CMS\Backend\Template\DocumentTemplate
::class);
116 $this->doc
->setModuleTemplate('EXT:backend/Resources/Private/Templates/file_newfolder.html');
117 $this->doc
->backPath
= $GLOBALS['BACK_PATH'];
118 $this->doc
->JScode
= $this->doc
->wrapScriptTags('
119 var path = "' . $this->target
. '";
121 function reload(a) { //
122 if (!changed || (changed && confirm(' . GeneralUtility
::quoteJSvalue($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:mess.redraw')) . '))) {
123 var params = "&target="+encodeURIComponent(path)+"&number="+a+"&returnUrl=' . rawurlencode($this->returnUrl
) . '";
124 window.location.href = ' . GeneralUtility
::quoteJSvalue(BackendUtility
::getModuleUrl('file_newfolder')) . '+params;
127 function backToList() { //
128 top.goToModule("file_list");
136 * Main function, rendering the main module content
140 public function main() {
141 $lang = $this->getLanguageService();
142 // Start content compilation
143 $this->content
.= $this->doc
->startPage($lang->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.pagetitle'));
145 $pageContent = $this->doc
->header($lang->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.pagetitle'));
147 if ($this->folderObject
->checkActionPermission('add')) {
148 $code = '<form role="form" action="' . htmlspecialchars(BackendUtility
::getModuleUrl('tce_file')) . '" method="post" name="editform">';
149 // Making the selector box for the number of concurrent folder-creations
150 $this->number
= \TYPO3\CMS\Core\Utility\MathUtility
::forceIntegerInRange($this->number
, 1, 10);
152 <div class="form-group">
153 <div class="form-section">
154 <div class="form-group">
155 <label for="number-of-new-folders">' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.number_of_folders') . ' ' . BackendUtility
::cshItem('xMOD_csh_corebe', 'file_newfolder') . '</label>
156 <div class="form-control-wrap">
157 <div class="input-group">
158 <select class="form-control form-control-adapt" name="number" id="number-of-new-folders" onchange="reload(this.options[this.selectedIndex].value);">';
159 for ($a = 1; $a <= $this->folderNumber
; $a++
) {
160 $code .= '<option value="' . $a . '"' . ($this->number
== $a ?
' selected="selected"' : '') . '>' . $a . '</option>';
169 // Making the number of new-folder boxes needed:
170 for ($a = 0; $a < $this->number
; $a++
) {
172 <div class="form-section">
173 <div class="form-group">
174 <label for="folder_new_' . $a . '">' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.label_newfolder') . ' ' . ($a +
1) . ':</label>
175 <div class="form-control-wrap">
176 <input type="text" class="form-control" id="folder_new_' . $a . '" name="file[newfolder][' . $a . '][data]" onchange="changed=true;" />
177 <input type="hidden" name="file[newfolder][' . $a . '][target]" value="' . htmlspecialchars($this->target
) . '" />
182 // Making submit button for folder creation:
184 </div><div class="form-group">
185 <input class="btn btn-default" type="submit" value="' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.submit', TRUE
) . '" />
186 <input type="hidden" name="redirect" value="' . htmlspecialchars($this->returnUrl
) . '" />
187 ' . \TYPO3\CMS\Backend\Form\FormEngine
::getHiddenTokenField('tceAction') . '
190 // Switching form tags:
191 $pageContent .= $this->doc
->section($lang->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.newfolders'), $code);
192 $pageContent .= $this->doc
->sectionEnd() . '</form>';
195 if ($this->folderObject
->getStorage()->checkUserActionPermission('add', 'File')) {
196 $pageContent .= '<form action="' . BackendUtility
::getModuleUrl('tce_file') . '" method="post" name="editform2">';
197 // Create a list of allowed file extensions with the nice format "*.jpg, *.gif" etc.
198 $fileExtList = array();
199 $textFileExt = GeneralUtility
::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'], TRUE
);
200 foreach ($textFileExt as $fileExt) {
201 if (!preg_match(('/' . $GLOBALS['TYPO3_CONF_VARS']['BE']['fileDenyPattern'] . '/i'), ('.' . $fileExt))) {
202 $fileExtList[] = '<span class="label label-success">' . strtoupper(htmlspecialchars($fileExt)) . '</span>';
205 // Add form fields for creation of a new, blank text file:
207 <div class="form-group">
208 <div class="form-section">
209 <div class="form-group">
210 <label for="newfile">' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.label_newfile') . ' ' . BackendUtility
::cshItem('xMOD_csh_corebe', 'file_newfile') . '</label>
211 <div class="form-control-wrap">
212 <input class="form-control" type="text" id="newfile" name="file[newfile][0][data]" onchange="changed=true;" />
213 <input type="hidden" name="file[newfile][0][target]" value="' . htmlspecialchars($this->target
) . '" />
215 <div class="help-block">
216 ' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:cm.allowedFileExtensions') . '<br>
217 ' . implode(' ', $fileExtList) . '
223 // Submit button for creation of a new file:
225 <div class="form-group">
226 <input class="btn btn-default" type="submit" value="' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.newfile_submit', TRUE
) . '" />
227 <input type="hidden" name="redirect" value="' . htmlspecialchars($this->returnUrl
) . '" />
228 ' . \TYPO3\CMS\Backend\Form\FormEngine
::getHiddenTokenField('tceAction') . '
231 $pageContent .= $this->doc
->section($lang->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.newfile'), $code);
232 $pageContent .= $this->doc
->sectionEnd();
233 $pageContent .= '</form>';
236 $docHeaderButtons = array(
240 if ($this->returnUrl
) {
241 $docHeaderButtons['back'] = '<a href="' . htmlspecialchars(GeneralUtility
::linkThisUrl($this->returnUrl
)) . '" class="typo3-goBack" title="' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.goBack', TRUE
) . '">' . \TYPO3\CMS\Backend\Utility\IconUtility
::getSpriteIcon('actions-view-go-back') . '</a>';
243 // Add the HTML as a section:
244 $markerArray = array(
245 'CSH' => $docHeaderButtons['csh'],
247 'CONTENT' => $pageContent,
248 'PATH' => $this->title
250 $this->content
.= $this->doc
->moduleBody(array(), $docHeaderButtons, $markerArray);
251 $this->content
.= $this->doc
->endPage();
252 $this->content
= $this->doc
->insertStylesAndJS($this->content
);
256 * Outputting the accumulated content to screen
260 public function printContent() {
265 * Returns LanguageService
267 * @return \TYPO3\CMS\Lang\LanguageService
269 protected function getLanguageService() {
270 return $GLOBALS['LANG'];