Fixed #8802: Fileadmin: extensions of new files should only show allowed extensions...
[Packages/TYPO3.CMS.git] / typo3 / file_newfolder.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2009 Kasper Skaarhoj (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 * $Id$
31 * Revised for TYPO3 3.6 November/2003 by Kasper Skaarhoj
32 *
33 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
34 */
35 /**
36 * [CLASS/FUNCTION INDEX of SCRIPT]
37 *
38 *
39 *
40 * 74: class SC_file_newfolder
41 * 101: function init()
42 * 161: function main()
43 * 255: function printContent()
44 *
45 * TOTAL FUNCTIONS: 3
46 * (This index is automatically created/updated by the extension "extdeveval")
47 *
48 */
49
50
51
52 $BACK_PATH = '';
53 require('init.php');
54 require('template.php');
55
56
57
58
59
60
61
62
63
64
65 /**
66 * Script Class for the create-new script; Displays a form for creating up to 10 folders or one new text file
67 *
68 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
69 * @package TYPO3
70 * @subpackage core
71 */
72 class SC_file_newfolder {
73
74 // External, static:
75 var $folderNumber=10;
76
77 // Internal, static:
78 /**
79 * document template object
80 *
81 * @var smallDoc
82 */
83 var $doc;
84
85 /**
86 * File processing object
87 *
88 * @var t3lib_basicFileFunctions
89 */
90 var $basicff;
91 var $icon; // Will be set to the proper icon for the $target value.
92 var $shortPath; // Relative path to current found filemount
93 var $title; // Name of the filemount
94
95 /**
96 * Charset processing object
97 *
98 * @var t3lib_cs
99 */
100 protected $charsetConversion;
101
102 // Internal, static (GPVar):
103 var $number;
104 var $target; // Set with the target path inputted in &target
105 var $returnUrl; // Return URL of list module.
106
107 // Internal, dynamic:
108 var $content; // Accumulating content
109
110
111
112 /**
113 * Constructor function for class
114 *
115 * @return void
116 */
117 function init() {
118 global $LANG,$BACK_PATH,$TYPO3_CONF_VARS;
119
120 // Initialize GPvars:
121 $this->number = t3lib_div::_GP('number');
122 $this->target = t3lib_div::_GP('target');
123 $this->returnUrl = t3lib_div::_GP('returnUrl');
124
125 // Init basic-file-functions object:
126 $this->basicff = t3lib_div::makeInstance('t3lib_basicFileFunctions');
127 $this->basicff->init($GLOBALS['FILEMOUNTS'],$TYPO3_CONF_VARS['BE']['fileExtensions']);
128
129 // Init basic-charset-functions object:
130 $this->charsetConversion = t3lib_div::makeInstance('t3lib_cs');
131
132 // Cleaning and checking target
133 $this->target = $this->charsetConversion->conv($this->target, 'utf-8', $GLOBALS['LANG']->charSet);
134 $this->target = $this->basicff->is_directory($this->target);
135 $key=$this->basicff->checkPathAgainstMounts($this->target.'/');
136 if (!$this->target || !$key) {
137 t3lib_BEfunc::typo3PrintError ($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:paramError', true), $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:targetNoDir', true), '');
138 exit;
139 }
140
141 // Finding the icon
142 switch($GLOBALS['FILEMOUNTS'][$key]['type']) {
143 case 'user': $this->icon = 'gfx/i/_icon_ftp_user.gif'; break;
144 case 'group': $this->icon = 'gfx/i/_icon_ftp_group.gif'; break;
145 default: $this->icon = 'gfx/i/_icon_ftp.gif'; break;
146 }
147
148 $this->icon = '<img'.t3lib_iconWorks::skinImg($this->backPath,$this->icon,'width="18" height="16"').' title="" alt="" />';
149
150 // Relative path to filemount, $key:
151 $this->shortPath = substr($this->target,strlen($GLOBALS['FILEMOUNTS'][$key]['path']));
152
153 // Setting title:
154 $this->title = $this->icon.$GLOBALS['FILEMOUNTS'][$key]['name'].': '.$this->shortPath;
155
156 // Setting template object
157 $this->doc = t3lib_div::makeInstance('template');
158 $this->doc->setModuleTemplate('templates/file_newfolder.html');
159 $this->doc->backPath = $BACK_PATH;
160 $this->doc->JScode=$this->doc->wrapScriptTags('
161 var path = "'.$this->target.'";
162
163 function reload(a) { //
164 if (!changed || (changed && confirm('.$LANG->JScharCode($LANG->sL('LLL:EXT:lang/locallang_core.php:mess.redraw')).'))) {
165 var params = "&target="+encodeURIComponent(path)+"&number="+a+"&returnUrl='
166 . urlencode($this->charsetConversion->conv($this->returnUrl, $GLOBALS['LANG']->charSet, 'utf-8'))
167 . '";
168 window.location.href = "file_newfolder.php?"+params;
169 }
170 }
171 function backToList() { //
172 top.goToModule("file_list");
173 }
174
175 var changed = 0;
176 ');
177 }
178
179 /**
180 * Main function, rendering the main module content
181 *
182 * @return void
183 */
184 function main() {
185 global $LANG;
186
187 // start content compilation
188 $this->content.=$this->doc->startPage($LANG->sL('LLL:EXT:lang/locallang_core.php:file_newfolder.php.pagetitle'));
189
190
191 // Make page header:
192 $pageContent='';
193 $pageContent.=$this->doc->header($LANG->sL('LLL:EXT:lang/locallang_core.php:file_newfolder.php.pagetitle'));
194 $pageContent.=$this->doc->spacer(5);
195 $pageContent.=$this->doc->divider(5);
196
197
198 $code = '<form action="tce_file.php" method="post" name="editform">';
199 // Making the selector box for the number of concurrent folder-creations
200 $this->number = t3lib_div::intInRange($this->number,1,10);
201 $code .= '
202 <div id="c-select">
203 <label for="number-of-new-folders">' .
204 $LANG->sL('LLL:EXT:lang/locallang_core.php:file_newfolder.php.number_of_folders') .
205 '</label>
206 <select name="number" id="number-of-new-folders" onchange="reload(this.options[this.selectedIndex].value);">';
207 for ($a=1;$a<=$this->folderNumber;$a++) {
208 $code .= '<option value="' . $a . '"' .
209 ($this->number == $a ? ' selected="selected"' : '') .
210 '>' . $a . '</option>';
211 }
212 $code.='
213 </select>
214 </div>
215 ';
216
217 // Making the number of new-folder boxes needed:
218 $code.='
219 <div id="c-createFolders">
220 ';
221 for ($a=0;$a<$this->number;$a++) {
222 $code.='
223 <input'.$this->doc->formWidth(20).' type="text" name="file[newfolder]['.$a.'][data]" onchange="changed=true;" />
224 <input type="hidden" name="file[newfolder]['.$a.'][target]" value="'.htmlspecialchars($this->target).'" />
225 ';
226 }
227 $code.='
228 </div>
229 ';
230
231 // Making submit button for folder creation:
232 $code.='
233 <div id="c-submitFolders">
234 <input type="submit" value="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:file_newfolder.php.submit',1).'" />
235 <input type="submit" value="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:labels.cancel',1).'" onclick="backToList(); return false;" />
236 <input type="hidden" name="redirect" value="'.htmlspecialchars($this->returnUrl).'" />
237 </div>
238 ';
239
240 // CSH:
241 $code.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'file_newfolder', $GLOBALS['BACK_PATH'], '<br />');
242
243 $pageContent.= $code;
244
245
246
247 // Add spacer:
248 $pageContent.= $this->doc->spacer(10);
249
250 // Switching form tags:
251 $pageContent.= $this->doc->sectionEnd();
252 $pageContent.= '</form><form action="tce_file.php" method="post" name="editform2">';
253
254 // Create a list of allowed file extensions with the nice format "*.jpg, *.gif" etc.
255 $fileExtList = array();
256 $textfileExt = t3lib_div::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'], TRUE);
257 foreach ($textfileExt as $fileExt) {
258 if (!preg_match('/' . $GLOBALS['TYPO3_CONF_VARS']['BE']['fileDenyPattern'] . '/i', '.' . $fileExt)) {
259 $fileExtList[] = '*.' . $fileExt;
260 }
261 }
262 // Add form fields for creation of a new, blank text file:
263 $code='
264 <div id="c-newFile">
265 <p>[' . htmlspecialchars(implode(', ', $fileExtList)) . ']</p>
266 <input'.$this->doc->formWidth(20).' type="text" name="file[newfile][0][data]" onchange="changed=true;" />
267 <input type="hidden" name="file[newfile][0][target]" value="'.htmlspecialchars($this->target).'" />
268 </div>
269 ';
270
271 // Submit button for creation of a new file:
272 $code.='
273 <div id="c-submitFiles">
274 <input type="submit" value="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:file_newfolder.php.newfile_submit',1).'" />
275 <input type="submit" value="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:labels.cancel',1).'" onclick="backToList(); return false;" />
276 <input type="hidden" name="redirect" value="'.htmlspecialchars($this->returnUrl).'" />
277 </div>
278 ';
279
280 // CSH:
281 $code.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'file_newfile', $GLOBALS['BACK_PATH'], '<br />');
282 $pageContent.= $this->doc->section($LANG->sL('LLL:EXT:lang/locallang_core.php:file_newfolder.php.newfile'),$code);
283 $pageContent .= $this->doc->sectionEnd();
284 $pageContent .= '</form>';
285
286 $docHeaderButtons = array();
287
288 // Add the HTML as a section:
289 $markerArray = array(
290 'CSH' => $docHeaderButtons['csh'],
291 'FUNC_MENU' => t3lib_BEfunc::getFuncMenu($this->id, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']),
292 'CONTENT' => $pageContent,
293 'PATH' => $this->title,
294 );
295
296 $this->content.= $this->doc->moduleBody(array(), $docHeaderButtons, $markerArray);
297 $this->content.= $this->doc->endPage();
298
299 $this->content = $this->doc->insertStylesAndJS($this->content);
300 }
301
302 /**
303 * Outputting the accumulated content to screen
304 *
305 * @return void
306 */
307 function printContent() {
308 echo $this->content;
309 }
310 }
311
312
313 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/file_newfolder.php']) {
314 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/file_newfolder.php']);
315 }
316
317
318
319 // Make instance:
320 $SOBE = t3lib_div::makeInstance('SC_file_newfolder');
321 $SOBE->init();
322 $SOBE->main();
323 $SOBE->printContent();
324
325 ?>