[BUGFIX] sysext recycler: Typo in language label
[Packages/TYPO3.CMS.git] / typo3 / file_upload.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: Upload of files
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 * 77: class SC_file_upload
40 * 103: function init()
41 * 171: function main()
42 * 241: function printContent()
43 *
44 * TOTAL FUNCTIONS: 3
45 * (This index is automatically created/updated by the extension "extdeveval")
46 *
47 */
48
49 $BACK_PATH = '';
50 require('init.php');
51 require('template.php');
52 $LANG->includeLLFile('EXT:lang/locallang_misc.xml');
53
54
55
56
57
58
59 /**
60 * Script Class for display up to 10 upload fields
61 *
62 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
63 * @package TYPO3
64 * @subpackage core
65 */
66 class SC_file_upload {
67
68 // External, static:
69 var $uploadNumber = 10;
70
71 // Internal, static:
72 /**
73 * Document template object
74 *
75 * @var smallDoc
76 */
77 var $doc;
78
79 /**
80 * File processing object
81 *
82 * @var t3lib_basicFileFunctions
83 */
84 var $basicff;
85 var $icon; // Will be set to the proper icon for the $target value.
86 var $shortPath; // Relative path to current found filemount
87 var $title; // Name of the filemount
88
89 /**
90 * Charset processing object
91 *
92 * @var t3lib_cs
93 */
94 protected $charsetConversion;
95
96 // Internal, static (GPVar):
97 var $number;
98 var $target; // Set with the target path inputted in &target
99 var $returnUrl; // Return URL of list module.
100
101 // Internal, dynamic:
102 var $content; // Accumulating content
103
104
105 /**
106 * Constructor for initializing the class
107 *
108 * @return void
109 */
110 function init() {
111 // Initialize GPvars:
112 $this->number = t3lib_div::_GP('number');
113 $this->target = t3lib_div::_GP('target');
114 $this->returnUrl = t3lib_div::sanitizeLocalUrl(t3lib_div::_GP('returnUrl'));
115 $this->returnUrl = $this->returnUrl ? $this->returnUrl : t3lib_div::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir . t3lib_extMgm::extRelPath('filelist') . 'mod1/file_list.php?id=' . rawurlencode($this->target);
116
117 // set the number of input fields
118 if (empty($this->number)) {
119 $this->number = $GLOBALS['BE_USER']->getTSConfigVal('options.defaultFileUploads');
120 }
121 $this->number = t3lib_div::intInRange($this->number, 1, $this->uploadNumber);
122
123 // Init basic-file-functions object:
124 $this->basicff = t3lib_div::makeInstance('t3lib_basicFileFunctions');
125 $this->basicff->init($GLOBALS['FILEMOUNTS'], $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']);
126
127 // Init basic-charset-functions object:
128 $this->charsetConversion = t3lib_div::makeInstance('t3lib_cs');
129
130 // Cleaning and checking target
131 $this->target = $this->charsetConversion->conv($this->target, 'utf-8', $GLOBALS['LANG']->charSet);
132 $this->target = $this->basicff->is_directory($this->target);
133 $key = $this->basicff->checkPathAgainstMounts($this->target . '/');
134 if (!$this->target || !$key) {
135 $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:paramError', TRUE);
136 $message = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:targetNoDir', TRUE);
137 throw new RuntimeException($title . ': ' . $message, 1294586845);
138 }
139
140 // Finding the icon
141 switch ($GLOBALS['FILEMOUNTS'][$key]['type']) {
142 case 'user':
143 $this->icon = 'gfx/i/_icon_ftp_user.gif';
144 break;
145 case 'group':
146 $this->icon = 'gfx/i/_icon_ftp_group.gif';
147 break;
148 default:
149 $this->icon = 'gfx/i/_icon_ftp.gif';
150 break;
151 }
152
153 $this->icon = '<img' . t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'], $this->icon, 'width="18" height="16"') . ' title="" alt="" />';
154
155 // Relative path to filemount, $key:
156 $this->shortPath = substr($this->target, strlen($GLOBALS['FILEMOUNTS'][$key]['path']));
157
158 // Setting title:
159 $this->title = $this->icon . htmlspecialchars($GLOBALS['FILEMOUNTS'][$key]['name']) . ': ' . $this->shortPath;
160
161 // Setting template object
162 $this->doc = t3lib_div::makeInstance('template');
163 $this->doc->setModuleTemplate('templates/file_upload.html');
164 $this->doc->backPath = $GLOBALS['BACK_PATH'];
165 $this->doc->form = '<form action="tce_file.php" method="post" name="editform" enctype="' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'] . '">';
166
167 if($GLOBALS['BE_USER']->jsConfirmation(1)) {
168 $confirm = ' && confirm(' . $GLOBALS['LANG']->JScharCode($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.redraw')) . ')';
169 } else {
170 $confirm = '';
171 }
172 $this->doc->JScode = $this->doc->wrapScriptTags('
173 var path = "'.$this->target.'";
174
175 function reload(a) { //
176 if (!changed || (changed ' . $confirm . ')) {
177 var params = "&target="+encodeURIComponent(path)+"&number="+a+"&returnUrl='
178 . urlencode($this->charsetConversion->conv($this->returnUrl, $GLOBALS['LANG']->charSet, 'utf-8'))
179 . '";
180 window.location.href = "file_upload.php?"+params;
181 }
182 }
183 function backToList() { //
184 top.goToModule("file_list");
185 }
186 var changed = 0;
187 ');
188 }
189
190
191 /**
192 * Main function, rendering the upload file form fields
193 *
194 * @return void
195 */
196 function main() {
197 // Make page header:
198 $this->content = $this->doc->startPage($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_upload.php.pagetitle'));
199
200 $form = $this->renderUploadForm();
201
202 $pageContent =
203 $this->doc->header($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_upload.php.pagetitle')) .
204 $this->doc->section('', $form);
205
206
207 // Header Buttons
208 $docHeaderButtons = array(
209 'csh' => t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'file_upload', $GLOBALS['BACK_PATH'])
210 );
211
212 $markerArray = array(
213 'CSH' => $docHeaderButtons['csh'],
214 'FUNC_MENU' => t3lib_BEfunc::getFuncMenu($this->id, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']),
215 'CONTENT' => $pageContent,
216 'PATH' => $this->title,
217 );
218
219 $this->content .= $this->doc->moduleBody(array(), $docHeaderButtons, $markerArray);
220 $this->content .= $this->doc->endPage();
221 $this->content = $this->doc->insertStylesAndJS($this->content);
222 }
223
224
225 /**
226 * This function renders the upload form
227 *
228 * @return string the HTML form as a string, ready for outputting
229 */
230 function renderUploadForm() {
231 $content = '
232 <div id="c-select">
233 <label for="number-of-uploads">' .
234 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_upload.php.number_of_files') .
235 '</label>
236 <select name="number" id="number-of-uploads" onchange="reload(this.options[this.selectedIndex].value);">';
237
238 for ($a = 1; $a <= $this->uploadNumber; $a++) {
239 $content .= '<option value="' . $a . '"' .
240 ($this->number == $a ? ' selected="selected"' : '' ) .
241 '>' . $a . '</option>';
242 }
243 $content .= '
244 </select>
245 </div>
246 ';
247
248
249 // Make checkbox for "overwrite"
250 $content .= '
251 <div id="c-override">
252 <input type="checkbox" class="checkbox" name="overwriteExistingFiles" id="overwriteExistingFiles" value="1" /> <label for="overwriteExistingFiles">' . $GLOBALS['LANG']->getLL('overwriteExistingFiles', 1) . '</label>
253 </div>
254 ';
255
256
257 // Produce the number of upload-fields needed:
258 $content .= '
259 <div id="c-upload">
260 ';
261 for ($a = 0; $a < $this->number; $a++) {
262 // Adding 'size="50" ' for the sake of Mozilla!
263 $content .= '
264 <input type="file" name="upload_' . $a . '"' . $this->doc->formWidth(35) . ' size="50" onclick="changed=1;" />
265 <input type="hidden" name="file[upload][' . $a . '][target]" value="' . htmlspecialchars($this->target) . '" />
266 <input type="hidden" name="file[upload][' . $a . '][data]" value="' . $a . '" /><br />
267 ';
268 }
269 $content .= '
270 </div>
271 ';
272
273 // Submit button:
274 $content .= '
275 <div id="c-submit">
276 <input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_upload.php.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 return $content;
283 }
284
285
286 /**
287 * Outputting the accumulated content to screen
288 *
289 * @return void
290 */
291 function printContent() {
292 echo $this->content;
293 }
294 }
295
296
297 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/file_upload.php'])) {
298 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/file_upload.php']);
299 }
300
301
302 // Make instance:
303 $SOBE = t3lib_div::makeInstance('SC_file_upload');
304 $SOBE->init();
305 $SOBE->main();
306 $SOBE->printContent();
307
308 ?>