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