[TASK] Clean-up several whitespaces and PHPdoc comments
[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->charsetConversion->conv($this->target, 'utf-8', $GLOBALS['LANG']->charSet);
114 $this->target = $this->basicff->is_directory($this->target);
115 $key = $this->basicff->checkPathAgainstMounts($this->target . '/');
116 if (!$this->target || !$key) {
117 $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:paramError', TRUE);
118 $message = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:targetNoDir', TRUE);
119 throw new RuntimeException($title . ': ' . $message, 1294586845);
120 }
121
122 // Finding the icon
123 switch ($GLOBALS['FILEMOUNTS'][$key]['type']) {
124 case 'user':
125 $this->icon = 'gfx/i/_icon_ftp_user.gif';
126 break;
127 case 'group':
128 $this->icon = 'gfx/i/_icon_ftp_group.gif';
129 break;
130 default:
131 $this->icon = 'gfx/i/_icon_ftp.gif';
132 break;
133 }
134
135 $this->icon = '<img' . t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'], $this->icon, 'width="18" height="16"') . ' title="" alt="" />';
136
137 // Relative path to filemount, $key:
138 $this->shortPath = substr($this->target, strlen($GLOBALS['FILEMOUNTS'][$key]['path']));
139
140 // Setting title:
141 $this->title = $this->icon . htmlspecialchars($GLOBALS['FILEMOUNTS'][$key]['name']) . ': ' . $this->shortPath;
142
143 // Setting template object
144 $this->doc = t3lib_div::makeInstance('template');
145 $this->doc->setModuleTemplate('templates/file_upload.html');
146 $this->doc->backPath = $GLOBALS['BACK_PATH'];
147 $this->doc->form = '<form action="tce_file.php" method="post" name="editform" enctype="' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'] . '">';
148
149 if($GLOBALS['BE_USER']->jsConfirmation(1)) {
150 $confirm = ' && confirm(' . $GLOBALS['LANG']->JScharCode($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.redraw')) . ')';
151 } else {
152 $confirm = '';
153 }
154 $this->doc->JScode = $this->doc->wrapScriptTags('
155 var path = "'.$this->target.'";
156
157 function reload(a) { //
158 if (!changed || (changed ' . $confirm . ')) {
159 var params = "&target="+encodeURIComponent(path)+"&number="+a+"&returnUrl='
160 . urlencode($this->charsetConversion->conv($this->returnUrl, $GLOBALS['LANG']->charSet, 'utf-8'))
161 . '";
162 window.location.href = "file_upload.php?"+params;
163 }
164 }
165 function backToList() { //
166 top.goToModule("file_list");
167 }
168 var changed = 0;
169 ');
170 }
171
172
173 /**
174 * Main function, rendering the upload file form fields
175 *
176 * @return void
177 */
178 function main() {
179 // Make page header:
180 $this->content = $this->doc->startPage($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_upload.php.pagetitle'));
181
182 $form = $this->renderUploadForm();
183
184 $pageContent =
185 $this->doc->header($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_upload.php.pagetitle')) .
186 $this->doc->section('', $form);
187
188
189 // Header Buttons
190 $docHeaderButtons = array(
191 'csh' => t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'file_upload', $GLOBALS['BACK_PATH'])
192 );
193
194 $markerArray = array(
195 'CSH' => $docHeaderButtons['csh'],
196 'FUNC_MENU' => t3lib_BEfunc::getFuncMenu($this->id, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']),
197 'CONTENT' => $pageContent,
198 'PATH' => $this->title,
199 );
200
201 $this->content .= $this->doc->moduleBody(array(), $docHeaderButtons, $markerArray);
202 $this->content .= $this->doc->endPage();
203 $this->content = $this->doc->insertStylesAndJS($this->content);
204 }
205
206
207 /**
208 * This function renders the upload form
209 *
210 * @return string the HTML form as a string, ready for outputting
211 */
212 function renderUploadForm() {
213 $content = '
214 <div id="c-select">
215 <label for="number-of-uploads">' .
216 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_upload.php.number_of_files') .
217 '</label>
218 <select name="number" id="number-of-uploads" onchange="reload(this.options[this.selectedIndex].value);">';
219
220 for ($a = 1; $a <= $this->uploadNumber; $a++) {
221 $content .= '<option value="' . $a . '"' .
222 ($this->number == $a ? ' selected="selected"' : '' ) .
223 '>' . $a . '</option>';
224 }
225 $content .= '
226 </select>
227 </div>
228 ';
229
230
231 // Make checkbox for "overwrite"
232 $content .= '
233 <div id="c-override">
234 <input type="checkbox" class="checkbox" name="overwriteExistingFiles" id="overwriteExistingFiles" value="1" /> <label for="overwriteExistingFiles">' . $GLOBALS['LANG']->getLL('overwriteExistingFiles', 1) . '</label>
235 </div>
236 ';
237
238
239 // Produce the number of upload-fields needed:
240 $content .= '
241 <div id="c-upload">
242 ';
243 for ($a = 0; $a < $this->number; $a++) {
244 // Adding 'size="50" ' for the sake of Mozilla!
245 $content .= '
246 <input type="file" name="upload_' . $a . '"' . $this->doc->formWidth(35) . ' size="50" onclick="changed=1;" />
247 <input type="hidden" name="file[upload][' . $a . '][target]" value="' . htmlspecialchars($this->target) . '" />
248 <input type="hidden" name="file[upload][' . $a . '][data]" value="' . $a . '" /><br />
249 ';
250 }
251 $content .= '
252 </div>
253 ';
254
255 // Submit button:
256 $content .= '
257 <div id="c-submit">
258 <input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_upload.php.submit', 1) . '" />
259 <input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.cancel', 1) . '" onclick="backToList(); return false;" />
260 <input type="hidden" name="redirect" value="' . htmlspecialchars($this->returnUrl) . '" />
261 </div>
262 ';
263
264 return $content;
265 }
266
267
268 /**
269 * Outputting the accumulated content to screen
270 *
271 * @return void
272 */
273 function printContent() {
274 echo $this->content;
275 }
276 }
277
278
279 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/file_upload.php'])) {
280 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/file_upload.php']);
281 }
282
283
284 // Make instance:
285 $SOBE = t3lib_div::makeInstance('SC_file_upload');
286 $SOBE->init();
287 $SOBE->main();
288 $SOBE->printContent();
289
290 ?>