[BUGFIX] Functional Test: force storage record to be caseSensitive "1"
[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 TYPO3\CMS\Backend\Utility\BackendUtility;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19
20 /**
21 * Script Class for the create-new script; Displays a form for creating up to 10 folders or one new text file
22 *
23 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
24 */
25 class CreateFolderController {
26
27 // External, static:
28 /**
29 * @todo Define visibility
30 */
31 public $folderNumber = 10;
32
33 // Internal, static:
34 /**
35 * document template object
36 *
37 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
38 * @todo Define visibility
39 */
40 public $doc;
41
42 // Name of the filemount
43 /**
44 * @todo Define visibility
45 */
46 public $title;
47
48 // Internal, static (GPVar):
49 /**
50 * @todo Define visibility
51 */
52 public $number;
53
54 // Set with the target path inputted in &target
55 /**
56 * @todo Define visibility
57 */
58 public $target;
59
60 /**
61 * The folder object which is the target directory
62 *
63 * @var \TYPO3\CMS\Core\Resource\Folder $folderObject
64 */
65 protected $folderObject;
66
67 // Return URL of list module.
68 /**
69 * @todo Define visibility
70 */
71 public $returnUrl;
72
73 // Internal, dynamic:
74 // Accumulating content
75 /**
76 * @todo Define visibility
77 */
78 public $content;
79
80 /**
81 * Constructor
82 */
83 public function __construct() {
84 $GLOBALS['SOBE'] = $this;
85 $GLOBALS['BACK_PATH'] = '';
86
87 $this->init();
88 }
89
90 /**
91 * Initialize
92 *
93 * @return void
94 */
95 protected function init() {
96 // Initialize GPvars:
97 $this->number = GeneralUtility::_GP('number');
98 $this->target = ($combinedIdentifier = GeneralUtility::_GP('target'));
99 $this->returnUrl = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'));
100 // create the folder object
101 if ($combinedIdentifier) {
102 $this->folderObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getFolderObjectFromCombinedIdentifier($combinedIdentifier);
103 }
104 // Cleaning and checking target directory
105 if (!$this->folderObject) {
106 $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:paramError', TRUE);
107 $message = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:targetNoDir', TRUE);
108 throw new \RuntimeException($title . ': ' . $message, 1294586845);
109 }
110 if ($this->folderObject->getStorage()->getUid() === 0) {
111 throw new \TYPO3\CMS\Core\Resource\Exception\InsufficientFolderAccessPermissionsException('You are not allowed to access folders outside your storages', 1375889838);
112 }
113
114 // Setting the title and the icon
115 $icon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('apps-filetree-root');
116 $this->title = $icon . htmlspecialchars($this->folderObject->getStorage()->getName()) . ': ' . htmlspecialchars($this->folderObject->getIdentifier());
117 // Setting template object
118 $this->doc = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
119 $this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/file_newfolder.html');
120 $this->doc->backPath = $GLOBALS['BACK_PATH'];
121 $this->doc->JScode = $this->doc->wrapScriptTags('
122 var path = "' . $this->target . '";
123
124 function reload(a) { //
125 if (!changed || (changed && confirm(' . GeneralUtility::quoteJSvalue($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.redraw')) . '))) {
126 var params = "&target="+encodeURIComponent(path)+"&number="+a+"&returnUrl=' . rawurlencode($this->returnUrl) . '";
127 window.location.href = "file_newfolder.php?"+params;
128 }
129 }
130 function backToList() { //
131 top.goToModule("file_list");
132 }
133
134 var changed = 0;
135 ');
136 }
137
138 /**
139 * Main function, rendering the main module content
140 *
141 * @return void
142 */
143 public function main() {
144 // Start content compilation
145 $this->content .= $this->doc->startPage($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.pagetitle'));
146 // Make page header:
147 $pageContent = $this->doc->header($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.pagetitle'));
148 $pageContent .= $this->doc->spacer(5);
149 $pageContent .= $this->doc->divider(5);
150 if ($this->folderObject->checkActionPermission('add')) {
151 $code = '<form action="tce_file.php" method="post" name="editform">';
152 // Making the selector box for the number of concurrent folder-creations
153 $this->number = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($this->number, 1, 10);
154 $code .= '
155 <div id="c-select">
156 <label for="number-of-new-folders">' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.number_of_folders') . '</label>
157 <select name="number" id="number-of-new-folders" onchange="reload(this.options[this.selectedIndex].value);">';
158 for ($a = 1; $a <= $this->folderNumber; $a++) {
159 $code .= '<option value="' . $a . '"' . ($this->number == $a ? ' selected="selected"' : '') . '>' . $a . '</option>';
160 }
161 $code .= '
162 </select>
163 </div>
164 ';
165 // Making the number of new-folder boxes needed:
166 $code .= '
167 <div id="c-createFolders">
168 ';
169 for ($a = 0; $a < $this->number; $a++) {
170 $code .= '
171 <input' . $this->doc->formWidth(20) . ' type="text" name="file[newfolder][' . $a . '][data]" onchange="changed=true;" />
172 <input type="hidden" name="file[newfolder][' . $a . '][target]" value="' . htmlspecialchars($this->target) . '" /><br />
173 ';
174 }
175 $code .= '
176 </div>
177 ';
178 // Making submit button for folder creation:
179 $code .= '
180 <div id="c-submitFolders">
181 <input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.submit', TRUE) . '" />
182 <input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.cancel', TRUE) . '" onclick="backToList(); return false;" />
183 <input type="hidden" name="redirect" value="' . htmlspecialchars($this->returnUrl) . '" />
184 ' . \TYPO3\CMS\Backend\Form\FormEngine::getHiddenTokenField('tceAction') . '
185 </div>
186 ';
187 // CSH:
188 $code .= BackendUtility::cshItem('xMOD_csh_corebe', 'file_newfolder', $GLOBALS['BACK_PATH'], '<br />');
189 $pageContent .= $code;
190 // Add spacer:
191 $pageContent .= $this->doc->spacer(10);
192 // Switching form tags:
193 $pageContent .= $this->doc->sectionEnd() . '</form>';
194 }
195
196 if ($this->folderObject->getStorage()->checkUserActionPermission('add', 'File')) {
197 $pageContent .= '<form action="tce_file.php" method="post" name="editform2">';
198 // Create a list of allowed file extensions with the nice format "*.jpg, *.gif" etc.
199 $fileExtList = array();
200 $textfileExt = GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'], TRUE);
201 foreach ($textfileExt as $fileExt) {
202 if (!preg_match(('/' . $GLOBALS['TYPO3_CONF_VARS']['BE']['fileDenyPattern'] . '/i'), ('.' . $fileExt))) {
203 $fileExtList[] = '*.' . $fileExt;
204 }
205 }
206 // Add form fields for creation of a new, blank text file:
207 $code = '
208 <div id="c-newFile">
209 <p>[' . htmlspecialchars(implode(', ', $fileExtList)) . ']</p>
210 <input' . $this->doc->formWidth(20) . ' type="text" name="file[newfile][0][data]" onchange="changed=true;" />
211 <input type="hidden" name="file[newfile][0][target]" value="' . htmlspecialchars($this->target) . '" />
212 </div>
213 ';
214 // Submit button for creation of a new file:
215 $code .= '
216 <div id="c-submitFiles">
217 <input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.newfile_submit', TRUE) . '" />
218 <input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.cancel', TRUE) . '" onclick="backToList(); return false;" />
219 <input type="hidden" name="redirect" value="' . htmlspecialchars($this->returnUrl) . '" />
220 ' . \TYPO3\CMS\Backend\Form\FormEngine::getHiddenTokenField('tceAction') . '
221 </div>
222 ';
223 // CSH:
224 $code .= BackendUtility::cshItem('xMOD_csh_corebe', 'file_newfile', $GLOBALS['BACK_PATH'], '<br />');
225 $pageContent .= $this->doc->section($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.newfile'), $code);
226 $pageContent .= $this->doc->sectionEnd();
227 $pageContent .= '</form>';
228 }
229
230 $docHeaderButtons = array(
231 'back' => ''
232 );
233 // Back
234 if ($this->returnUrl) {
235 $docHeaderButtons['back'] = '<a href="' . htmlspecialchars(GeneralUtility::linkThisUrl($this->returnUrl)) . '" class="typo3-goBack" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.goBack', TRUE) . '">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-view-go-back') . '</a>';
236 }
237 // Add the HTML as a section:
238 $markerArray = array(
239 'CSH' => $docHeaderButtons['csh'],
240 'FUNC_MENU' => BackendUtility::getFuncMenu($this->id, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']),
241 'CONTENT' => $pageContent,
242 'PATH' => $this->title
243 );
244 $this->content .= $this->doc->moduleBody(array(), $docHeaderButtons, $markerArray);
245 $this->content .= $this->doc->endPage();
246 $this->content = $this->doc->insertStylesAndJS($this->content);
247 }
248
249 /**
250 * Outputting the accumulated content to screen
251 *
252 * @return void
253 */
254 public function printContent() {
255 echo $this->content;
256 }
257
258 }