b3669baa7c3c327a09d35c585e5624f945b36924
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Controller / File / CreateFolderController.php
1 <?php
2 namespace TYPO3\CMS\Backend\Controller\File;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 1999-2013 Kasper Skårhøj (kasperYYYY@typo3.com)
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 use TYPO3\CMS\Backend\Utility\BackendUtility;
31 use TYPO3\CMS\Core\Utility\GeneralUtility;
32
33 /**
34 * Script Class for the create-new script; Displays a form for creating up to 10 folders or one new text file
35 *
36 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
37 */
38 class CreateFolderController {
39
40 // External, static:
41 /**
42 * @todo Define visibility
43 */
44 public $folderNumber = 10;
45
46 // Internal, static:
47 /**
48 * document template object
49 *
50 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
51 * @todo Define visibility
52 */
53 public $doc;
54
55 // Name of the filemount
56 /**
57 * @todo Define visibility
58 */
59 public $title;
60
61 // Internal, static (GPVar):
62 /**
63 * @todo Define visibility
64 */
65 public $number;
66
67 // Set with the target path inputted in &target
68 /**
69 * @todo Define visibility
70 */
71 public $target;
72
73 /**
74 * The folder object which is the target directory
75 *
76 * @var \TYPO3\CMS\Core\Resource\Folder $folderObject
77 */
78 protected $folderObject;
79
80 // Return URL of list module.
81 /**
82 * @todo Define visibility
83 */
84 public $returnUrl;
85
86 // Internal, dynamic:
87 // Accumulating content
88 /**
89 * @todo Define visibility
90 */
91 public $content;
92
93 /**
94 * Constructor function for class
95 *
96 * @return void
97 * @todo Define visibility
98 */
99 public function init() {
100 // Initialize GPvars:
101 $this->number = GeneralUtility::_GP('number');
102 $this->target = ($combinedIdentifier = GeneralUtility::_GP('target'));
103 $this->returnUrl = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'));
104 // create the folder object
105 if ($combinedIdentifier) {
106 $this->folderObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getFolderObjectFromCombinedIdentifier($combinedIdentifier);
107 }
108 // Cleaning and checking target directory
109 if (!$this->folderObject) {
110 $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:paramError', TRUE);
111 $message = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:targetNoDir', TRUE);
112 throw new \RuntimeException($title . ': ' . $message, 1294586843);
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(' . $GLOBALS['LANG']->JScharCode($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 * @todo Define visibility
143 */
144 public function main() {
145 // Start content compilation
146 $this->content .= $this->doc->startPage($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.pagetitle'));
147 // Make page header:
148 $pageContent = '';
149 $pageContent .= $this->doc->header($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.pagetitle'));
150 $pageContent .= $this->doc->spacer(5);
151 $pageContent .= $this->doc->divider(5);
152 $code = '<form action="tce_file.php" method="post" name="editform">';
153 // Making the selector box for the number of concurrent folder-creations
154 $this->number = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($this->number, 1, 10);
155 $code .= '
156 <div id="c-select">
157 <label for="number-of-new-folders">' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.number_of_folders') . '</label>
158 <select 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>';
161 }
162 $code .= '
163 </select>
164 </div>
165 ';
166 // Making the number of new-folder boxes needed:
167 $code .= '
168 <div id="c-createFolders">
169 ';
170 for ($a = 0; $a < $this->number; $a++) {
171 $code .= '
172 <input' . $this->doc->formWidth(20) . ' type="text" name="file[newfolder][' . $a . '][data]" onchange="changed=true;" />
173 <input type="hidden" name="file[newfolder][' . $a . '][target]" value="' . htmlspecialchars($this->target) . '" /><br />
174 ';
175 }
176 $code .= '
177 </div>
178 ';
179 // Making submit button for folder creation:
180 $code .= '
181 <div id="c-submitFolders">
182 <input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.submit', 1) . '" />
183 <input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.cancel', 1) . '" onclick="backToList(); return false;" />
184 <input type="hidden" name="redirect" value="' . htmlspecialchars($this->returnUrl) . '" />
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();
194 $pageContent .= '</form><form action="tce_file.php" method="post" name="editform2">';
195 // Create a list of allowed file extensions with the nice format "*.jpg, *.gif" etc.
196 $fileExtList = array();
197 $textfileExt = GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'], TRUE);
198 foreach ($textfileExt as $fileExt) {
199 if (!preg_match(('/' . $GLOBALS['TYPO3_CONF_VARS']['BE']['fileDenyPattern'] . '/i'), ('.' . $fileExt))) {
200 $fileExtList[] = '*.' . $fileExt;
201 }
202 }
203 // Add form fields for creation of a new, blank text file:
204 $code = '
205 <div id="c-newFile">
206 <p>[' . htmlspecialchars(implode(', ', $fileExtList)) . ']</p>
207 <input' . $this->doc->formWidth(20) . ' type="text" name="file[newfile][0][data]" onchange="changed=true;" />
208 <input type="hidden" name="file[newfile][0][target]" value="' . htmlspecialchars($this->target) . '" />
209 </div>
210 ';
211 // Submit button for creation of a new file:
212 $code .= '
213 <div id="c-submitFiles">
214 <input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.newfile_submit', 1) . '" />
215 <input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.cancel', 1) . '" onclick="backToList(); return false;" />
216 <input type="hidden" name="redirect" value="' . htmlspecialchars($this->returnUrl) . '" />
217 </div>
218 ';
219 // CSH:
220 $code .= BackendUtility::cshItem('xMOD_csh_corebe', 'file_newfile', $GLOBALS['BACK_PATH'], '<br />');
221 $pageContent .= $this->doc->section($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.newfile'), $code);
222 $pageContent .= $this->doc->sectionEnd();
223 $pageContent .= '</form>';
224 $docHeaderButtons = array(
225 'back' => ''
226 );
227 // Back
228 if ($this->returnUrl) {
229 $docHeaderButtons['back'] = '<a href="' . htmlspecialchars(\TYPO3\CMS\Core\Utility\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>';
230 }
231 // Add the HTML as a section:
232 $markerArray = array(
233 'CSH' => $docHeaderButtons['csh'],
234 'FUNC_MENU' => BackendUtility::getFuncMenu($this->id, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']),
235 'CONTENT' => $pageContent,
236 'PATH' => $this->title
237 );
238 $this->content .= $this->doc->moduleBody(array(), $docHeaderButtons, $markerArray);
239 $this->content .= $this->doc->endPage();
240 $this->content = $this->doc->insertStylesAndJS($this->content);
241 }
242
243 /**
244 * Outputting the accumulated content to screen
245 *
246 * @return void
247 * @todo Define visibility
248 */
249 public function printContent() {
250 echo $this->content;
251 }
252
253 }
254
255 ?>