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