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