[TASK] Each PHP statement must be on a line by itself
[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':
142 $this->icon = 'gfx/i/_icon_ftp_user.gif';
143 break;
144 case 'group':
145 $this->icon = 'gfx/i/_icon_ftp_group.gif';
146 break;
147 default:
148 $this->icon = 'gfx/i/_icon_ftp.gif';
149 }
150
151 $this->icon = '<img'.t3lib_iconWorks::skinImg($this->backPath,$this->icon,'width="18" height="16"').' title="" alt="" />';
152
153 // Relative path to filemount, $key:
154 $this->shortPath = substr($this->target,strlen($GLOBALS['FILEMOUNTS'][$key]['path']));
155
156 // Setting title:
157 $this->title = $this->icon . htmlspecialchars($GLOBALS['FILEMOUNTS'][$key]['name']) . ': ' . $this->shortPath;
158
159 // Setting template object
160 $this->doc = t3lib_div::makeInstance('template');
161 $this->doc->setModuleTemplate('templates/file_newfolder.html');
162 $this->doc->backPath = $GLOBALS['BACK_PATH'];
163 $this->doc->JScode=$this->doc->wrapScriptTags('
164 var path = "'.$this->target.'";
165
166 function reload(a) { //
167 if (!changed || (changed && confirm(' . $GLOBALS['LANG']->JScharCode($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.redraw')) . '))) {
168 var params = "&target="+encodeURIComponent(path)+"&number="+a+"&returnUrl='
169 . urlencode($this->charsetConversion->conv($this->returnUrl, $GLOBALS['LANG']->charSet, 'utf-8'))
170 . '";
171 window.location.href = "file_newfolder.php?"+params;
172 }
173 }
174 function backToList() { //
175 top.goToModule("file_list");
176 }
177
178 var changed = 0;
179 ');
180 }
181
182 /**
183 * Main function, rendering the main module content
184 *
185 * @return void
186 */
187 function main() {
188
189 // start content compilation
190 $this->content .= $this->doc->startPage($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_newfolder.php.pagetitle'));
191
192
193 // Make page header:
194 $pageContent='';
195 $pageContent.=$this->doc->header($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_newfolder.php.pagetitle'));
196 $pageContent.=$this->doc->spacer(5);
197 $pageContent.=$this->doc->divider(5);
198
199
200 $code = '<form action="tce_file.php" method="post" name="editform">';
201 // Making the selector box for the number of concurrent folder-creations
202 $this->number = t3lib_div::intInRange($this->number,1,10);
203 $code .= '
204 <div id="c-select">
205 <label for="number-of-new-folders">' .
206 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_newfolder.php.number_of_folders') .
207 '</label>
208 <select name="number" id="number-of-new-folders" onchange="reload(this.options[this.selectedIndex].value);">';
209 for ($a=1;$a<=$this->folderNumber;$a++) {
210 $code .= '<option value="' . $a . '"' .
211 ($this->number == $a ? ' selected="selected"' : '') .
212 '>' . $a . '</option>';
213 }
214 $code.='
215 </select>
216 </div>
217 ';
218
219 // Making the number of new-folder boxes needed:
220 $code.='
221 <div id="c-createFolders">
222 ';
223 for ($a=0;$a<$this->number;$a++) {
224 $code.='
225 <input'.$this->doc->formWidth(20).' type="text" name="file[newfolder]['.$a.'][data]" onchange="changed=true;" />
226 <input type="hidden" name="file[newfolder][' . $a . '][target]" value="' . htmlspecialchars($this->target) . '" /><br />
227 ';
228 }
229 $code.='
230 </div>
231 ';
232
233 // Making submit button for folder creation:
234 $code.='
235 <div id="c-submitFolders">
236 <input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_newfolder.php.submit', 1) . '" />
237 <input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.cancel', 1) . '" onclick="backToList(); return false;" />
238 <input type="hidden" name="redirect" value="'.htmlspecialchars($this->returnUrl).'" />
239 </div>
240 ';
241
242 // CSH:
243 $code.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'file_newfolder', $GLOBALS['BACK_PATH'], '<br />');
244
245 $pageContent.= $code;
246
247
248
249 // Add spacer:
250 $pageContent.= $this->doc->spacer(10);
251
252 // Switching form tags:
253 $pageContent.= $this->doc->sectionEnd();
254 $pageContent.= '</form><form action="tce_file.php" method="post" name="editform2">';
255
256 // Create a list of allowed file extensions with the nice format "*.jpg, *.gif" etc.
257 $fileExtList = array();
258 $textfileExt = t3lib_div::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'], TRUE);
259 foreach ($textfileExt as $fileExt) {
260 if (!preg_match('/' . $GLOBALS['TYPO3_CONF_VARS']['BE']['fileDenyPattern'] . '/i', '.' . $fileExt)) {
261 $fileExtList[] = '*.' . $fileExt;
262 }
263 }
264 // Add form fields for creation of a new, blank text file:
265 $code='
266 <div id="c-newFile">
267 <p>[' . htmlspecialchars(implode(', ', $fileExtList)) . ']</p>
268 <input'.$this->doc->formWidth(20).' type="text" name="file[newfile][0][data]" onchange="changed=true;" />
269 <input type="hidden" name="file[newfile][0][target]" value="'.htmlspecialchars($this->target).'" />
270 </div>
271 ';
272
273 // Submit button for creation of a new file:
274 $code.='
275 <div id="c-submitFiles">
276 <input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_newfolder.php.newfile_submit', 1) . '" />
277 <input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.cancel', 1) . '" onclick="backToList(); return false;" />
278 <input type="hidden" name="redirect" value="'.htmlspecialchars($this->returnUrl).'" />
279 </div>
280 ';
281
282 // CSH:
283 $code.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'file_newfile', $GLOBALS['BACK_PATH'], '<br />');
284 $pageContent .= $this->doc->section($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_newfolder.php.newfile'), $code);
285 $pageContent .= $this->doc->sectionEnd();
286 $pageContent .= '</form>';
287
288 $docHeaderButtons = array();
289
290 // Add the HTML as a section:
291 $markerArray = array(
292 'CSH' => $docHeaderButtons['csh'],
293 'FUNC_MENU' => t3lib_BEfunc::getFuncMenu($this->id, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']),
294 'CONTENT' => $pageContent,
295 'PATH' => $this->title,
296 );
297
298 $this->content.= $this->doc->moduleBody(array(), $docHeaderButtons, $markerArray);
299 $this->content.= $this->doc->endPage();
300
301 $this->content = $this->doc->insertStylesAndJS($this->content);
302 }
303
304 /**
305 * Outputting the accumulated content to screen
306 *
307 * @return void
308 */
309 function printContent() {
310 echo $this->content;
311 }
312 }
313
314
315 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/file_newfolder.php'])) {
316 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/file_newfolder.php']);
317 }
318
319
320
321 // Make instance:
322 $SOBE = t3lib_div::makeInstance('SC_file_newfolder');
323 $SOBE->init();
324 $SOBE->main();
325 $SOBE->printContent();
326
327 ?>