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