[TASK] Whitespace CGL
[Packages/TYPO3.CMS.git] / typo3 / file_newfolder.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Web>File: Create new folders in the filemounts
29 *
30 * Revised for TYPO3 3.6 November/2003 by Kasper Skårhøj
31 *
32 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
33 */
34
35
36
37 $BACK_PATH = '';
38 require('init.php');
39 require('template.php');
40
41
42 /**
43 * Script Class for the create-new script; Displays a form for creating up to 10 folders or one new text file
44 *
45 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
46 * @package TYPO3
47 * @subpackage core
48 */
49 class SC_file_newfolder {
50
51 // External, static:
52 var $folderNumber=10;
53
54 // Internal, static:
55 /**
56 * document template object
57 *
58 * @var smallDoc
59 */
60 var $doc;
61
62 var $title; // Name of the filemount
63
64 // Internal, static (GPVar):
65 var $number;
66 var $target; // Set with the target path inputted in &target
67
68 /**
69 * the folder object which is the target directory
70 *
71 * @var t3lib_file_Folder $folderObject
72 */
73 protected $folderObject;
74 var $returnUrl; // Return URL of list module.
75
76 // Internal, dynamic:
77 var $content; // Accumulating content
78
79
80
81 /**
82 * Constructor function for class
83 *
84 * @return void
85 */
86 function init() {
87 // Initialize GPvars:
88 $this->number = t3lib_div::_GP('number');
89 $this->target = $combinedIdentifier = t3lib_div::_GP('target');
90 $this->returnUrl = t3lib_div::sanitizeLocalUrl(t3lib_div::_GP('returnUrl'));
91
92 // create the folder object
93 if ($combinedIdentifier) {
94 $this->folderObject = t3lib_file_Factory::getInstance()->getFolderObjectFromCombinedIdentifier($combinedIdentifier);
95 }
96
97 // Cleaning and checking target directory
98 if (!$this->folderObject) {
99 $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:paramError', TRUE);
100 $message = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:targetNoDir', TRUE);
101 throw new RuntimeException($title . ': ' . $message, 1294586843);
102 }
103
104 // Setting the title and the icon
105 $icon = t3lib_iconWorks::getSpriteIcon('apps-filetree-root');
106 $this->title = $icon . htmlspecialchars($this->folderObject->getStorage()->getName()) . ': ' . htmlspecialchars($this->folderObject->getIdentifier());
107
108 // Setting template object
109 $this->doc = t3lib_div::makeInstance('template');
110 $this->doc->setModuleTemplate('templates/file_newfolder.html');
111 $this->doc->backPath = $GLOBALS['BACK_PATH'];
112 $this->doc->JScode=$this->doc->wrapScriptTags('
113 var path = "' . $this->target . '";
114
115 function reload(a) { //
116 if (!changed || (changed && confirm(' . $GLOBALS['LANG']->JScharCode($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.redraw')) . '))) {
117 var params = "&target="+encodeURIComponent(path)+"&number="+a+"&returnUrl=' . rawurlencode($this->returnUrl) . '";
118 window.location.href = "file_newfolder.php?"+params;
119 }
120 }
121 function backToList() { //
122 top.goToModule("file_list");
123 }
124
125 var changed = 0;
126 ');
127 }
128
129 /**
130 * Main function, rendering the main module content
131 *
132 * @return void
133 */
134 function main() {
135
136 // start content compilation
137 $this->content .= $this->doc->startPage($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_newfolder.php.pagetitle'));
138
139
140 // Make page header:
141 $pageContent='';
142 $pageContent.=$this->doc->header($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_newfolder.php.pagetitle'));
143 $pageContent.=$this->doc->spacer(5);
144 $pageContent.=$this->doc->divider(5);
145
146
147 $code = '<form action="tce_file.php" method="post" name="editform">';
148 // Making the selector box for the number of concurrent folder-creations
149 $this->number = t3lib_utility_Math::forceIntegerInRange($this->number,1,10);
150 $code .= '
151 <div id="c-select">
152 <label for="number-of-new-folders">' .
153 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_newfolder.php.number_of_folders') .
154 '</label>
155 <select name="number" id="number-of-new-folders" onchange="reload(this.options[this.selectedIndex].value);">';
156 for ($a=1;$a<=$this->folderNumber;$a++) {
157 $code .= '<option value="' . $a . '"' .
158 ($this->number == $a ? ' selected="selected"' : '') .
159 '>' . $a . '</option>';
160 }
161 $code.='
162 </select>
163 </div>
164 ';
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
180 // Making submit button for folder creation:
181 $code.='
182 <div id="c-submitFolders">
183 <input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_newfolder.php.submit', 1) . '" />
184 <input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.cancel', 1) . '" onclick="backToList(); return false;" />
185 <input type="hidden" name="redirect" value="'.htmlspecialchars($this->returnUrl).'" />
186 </div>
187 ';
188
189 // CSH:
190 $code.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'file_newfolder', $GLOBALS['BACK_PATH'], '<br />');
191
192 $pageContent.= $code;
193
194
195
196 // Add spacer:
197 $pageContent.= $this->doc->spacer(10);
198
199 // Switching form tags:
200 $pageContent.= $this->doc->sectionEnd();
201 $pageContent.= '</form><form action="tce_file.php" method="post" name="editform2">';
202
203 // Create a list of allowed file extensions with the nice format "*.jpg, *.gif" etc.
204 $fileExtList = array();
205 $textfileExt = t3lib_div::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
220 // Submit button for creation of a new file:
221 $code.='
222 <div id="c-submitFiles">
223 <input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_newfolder.php.newfile_submit', 1) . '" />
224 <input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.cancel', 1) . '" onclick="backToList(); return false;" />
225 <input type="hidden" name="redirect" value="'.htmlspecialchars($this->returnUrl).'" />
226 </div>
227 ';
228
229 // CSH:
230 $code.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'file_newfile', $GLOBALS['BACK_PATH'], '<br />');
231 $pageContent .= $this->doc->section($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_newfolder.php.newfile'), $code);
232 $pageContent .= $this->doc->sectionEnd();
233 $pageContent .= '</form>';
234
235 $docHeaderButtons = array();
236
237 // Add the HTML as a section:
238 $markerArray = array(
239 'CSH' => $docHeaderButtons['csh'],
240 'FUNC_MENU' => t3lib_BEfunc::getFuncMenu($this->id, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']),
241 'CONTENT' => $pageContent,
242 'PATH' => $this->title,
243 );
244
245 $this->content.= $this->doc->moduleBody(array(), $docHeaderButtons, $markerArray);
246 $this->content.= $this->doc->endPage();
247
248 $this->content = $this->doc->insertStylesAndJS($this->content);
249 }
250
251 /**
252 * Outputting the accumulated content to screen
253 *
254 * @return void
255 */
256 function printContent() {
257 echo $this->content;
258 }
259 }
260
261 // Make instance:
262 $SOBE = t3lib_div::makeInstance('SC_file_newfolder');
263 $SOBE->init();
264 $SOBE->main();
265 $SOBE->printContent();
266
267 ?>