[TASK] Cleanup entry classes in typo3/ part2
[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
95 */
96 public function __construct() {
97 $GLOBALS['SOBE'] = $this;
98 $GLOBALS['BACK_PATH'] = '';
99
100 $this->init();
101 }
102
103 /**
104 * Initialize
105 *
106 * @return void
107 */
108 protected function init() {
109 // Initialize GPvars:
110 $this->number = GeneralUtility::_GP('number');
111 $this->target = ($combinedIdentifier = GeneralUtility::_GP('target'));
112 $this->returnUrl = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'));
113 // create the folder object
114 if ($combinedIdentifier) {
115 $this->folderObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getFolderObjectFromCombinedIdentifier($combinedIdentifier);
116 }
117 // Cleaning and checking target directory
118 if (!$this->folderObject) {
119 $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:paramError', TRUE);
120 $message = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:targetNoDir', TRUE);
121 throw new \RuntimeException($title . ': ' . $message, 1294586843);
122 }
123 // Setting the title and the icon
124 $icon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('apps-filetree-root');
125 $this->title = $icon . htmlspecialchars($this->folderObject->getStorage()->getName()) . ': ' . htmlspecialchars($this->folderObject->getIdentifier());
126 // Setting template object
127 $this->doc = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
128 $this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/file_newfolder.html');
129 $this->doc->backPath = $GLOBALS['BACK_PATH'];
130 $this->doc->JScode = $this->doc->wrapScriptTags('
131 var path = "' . $this->target . '";
132
133 function reload(a) { //
134 if (!changed || (changed && confirm(' . $GLOBALS['LANG']->JScharCode($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.redraw')) . '))) {
135 var params = "&target="+encodeURIComponent(path)+"&number="+a+"&returnUrl=' . rawurlencode($this->returnUrl) . '";
136 window.location.href = "file_newfolder.php?"+params;
137 }
138 }
139 function backToList() { //
140 top.goToModule("file_list");
141 }
142
143 var changed = 0;
144 ');
145 }
146
147 /**
148 * Main function, rendering the main module content
149 *
150 * @return void
151 */
152 public function main() {
153 // Start content compilation
154 $this->content .= $this->doc->startPage($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.pagetitle'));
155 // Make page header:
156 $pageContent = '';
157 $pageContent .= $this->doc->header($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.pagetitle'));
158 $pageContent .= $this->doc->spacer(5);
159 $pageContent .= $this->doc->divider(5);
160 $code = '<form action="tce_file.php" method="post" name="editform">';
161 // Making the selector box for the number of concurrent folder-creations
162 $this->number = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($this->number, 1, 10);
163 $code .= '
164 <div id="c-select">
165 <label for="number-of-new-folders">' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.number_of_folders') . '</label>
166 <select name="number" id="number-of-new-folders" onchange="reload(this.options[this.selectedIndex].value);">';
167 for ($a = 1; $a <= $this->folderNumber; $a++) {
168 $code .= '<option value="' . $a . '"' . ($this->number == $a ? ' selected="selected"' : '') . '>' . $a . '</option>';
169 }
170 $code .= '
171 </select>
172 </div>
173 ';
174 // Making the number of new-folder boxes needed:
175 $code .= '
176 <div id="c-createFolders">
177 ';
178 for ($a = 0; $a < $this->number; $a++) {
179 $code .= '
180 <input' . $this->doc->formWidth(20) . ' type="text" name="file[newfolder][' . $a . '][data]" onchange="changed=true;" />
181 <input type="hidden" name="file[newfolder][' . $a . '][target]" value="' . htmlspecialchars($this->target) . '" /><br />
182 ';
183 }
184 $code .= '
185 </div>
186 ';
187 // Making submit button for folder creation:
188 $code .= '
189 <div id="c-submitFolders">
190 <input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.submit', 1) . '" />
191 <input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.cancel', 1) . '" onclick="backToList(); return false;" />
192 <input type="hidden" name="redirect" value="' . htmlspecialchars($this->returnUrl) . '" />
193 </div>
194 ';
195 // CSH:
196 $code .= BackendUtility::cshItem('xMOD_csh_corebe', 'file_newfolder', $GLOBALS['BACK_PATH'], '<br />');
197 $pageContent .= $code;
198 // Add spacer:
199 $pageContent .= $this->doc->spacer(10);
200 // Switching form tags:
201 $pageContent .= $this->doc->sectionEnd();
202 $pageContent .= '</form><form action="tce_file.php" method="post" name="editform2">';
203 // Create a list of allowed file extensions with the nice format "*.jpg, *.gif" etc.
204 $fileExtList = array();
205 $textfileExt = GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'], TRUE);
206 foreach ($textfileExt as $fileExt) {
207 if (!preg_match(('/' . $GLOBALS['TYPO3_CONF_VARS']['BE']['fileDenyPattern'] . '/i'), ('.' . $fileExt))) {
208 $fileExtList[] = '*.' . $fileExt;
209 }
210 }
211 // Add form fields for creation of a new, blank text file:
212 $code = '
213 <div id="c-newFile">
214 <p>[' . htmlspecialchars(implode(', ', $fileExtList)) . ']</p>
215 <input' . $this->doc->formWidth(20) . ' type="text" name="file[newfile][0][data]" onchange="changed=true;" />
216 <input type="hidden" name="file[newfile][0][target]" value="' . htmlspecialchars($this->target) . '" />
217 </div>
218 ';
219 // Submit button for creation of a new file:
220 $code .= '
221 <div id="c-submitFiles">
222 <input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.newfile_submit', 1) . '" />
223 <input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.cancel', 1) . '" onclick="backToList(); return false;" />
224 <input type="hidden" name="redirect" value="' . htmlspecialchars($this->returnUrl) . '" />
225 </div>
226 ';
227 // CSH:
228 $code .= BackendUtility::cshItem('xMOD_csh_corebe', 'file_newfile', $GLOBALS['BACK_PATH'], '<br />');
229 $pageContent .= $this->doc->section($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.newfile'), $code);
230 $pageContent .= $this->doc->sectionEnd();
231 $pageContent .= '</form>';
232 $docHeaderButtons = array(
233 'back' => ''
234 );
235 // Back
236 if ($this->returnUrl) {
237 $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>';
238 }
239 // Add the HTML as a section:
240 $markerArray = array(
241 'CSH' => $docHeaderButtons['csh'],
242 'FUNC_MENU' => BackendUtility::getFuncMenu($this->id, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']),
243 'CONTENT' => $pageContent,
244 'PATH' => $this->title
245 );
246 $this->content .= $this->doc->moduleBody(array(), $docHeaderButtons, $markerArray);
247 $this->content .= $this->doc->endPage();
248 $this->content = $this->doc->insertStylesAndJS($this->content);
249 }
250
251 /**
252 * Outputting the accumulated content to screen
253 *
254 * @return void
255 */
256 public function printContent() {
257 echo $this->content;
258 }
259
260 }
261
262 ?>