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