[TASK] Fix CGL violations against SuperfluousWhitespace
[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 /**
29 * Web>File: Upload of files
30 *
31 * Revised for TYPO3 3.6 November/2003 by Kasper Skårhøj
32 *
33 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
34 */
35
36 $BACK_PATH = '';
37 require('init.php');
38 $LANG->includeLLFile('EXT:lang/locallang_misc.xml');
39
40 /**
41 * Script Class for display up to 10 upload fields
42 *
43 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
44 * @package TYPO3
45 * @subpackage core
46 */
47 class SC_file_upload {
48
49 // Internal, static:
50 /**
51 * Document template object
52 *
53 * @var smallDoc
54 */
55 var $doc;
56 // Name of the filemount
57 var $title;
58
59 // Internal, static (GPVar):
60 // Set with the target path inputted in &target
61 var $target;
62 // Return URL of list module.
63 var $returnUrl;
64
65 // Internal, dynamic:
66 // Accumulating content
67 var $content;
68
69 /**
70 * The folder object which is the target directory for the upload
71 *
72 * @var t3lib_file_Folder $folderObject
73 */
74 protected $folderObject;
75
76 /**
77 * Constructor for initializing the class
78 *
79 * @return void
80 */
81 function init() {
82 // Initialize GPvars:
83 $this->target = t3lib_div::_GP('target');
84 $this->returnUrl = t3lib_div::sanitizeLocalUrl(t3lib_div::_GP('returnUrl'));
85 if (!$this->returnUrl) {
86 $this->returnUrl = t3lib_div::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir . t3lib_BEfunc::getModuleUrl('file_list') . '&id=' . rawurlencode($this->target);
87 }
88
89 // Create the folder object
90 if ($this->target) {
91 $this->folderObject = t3lib_file_Factory::getInstance()->retrieveFileOrFolderObject($this->target);
92 }
93
94 // Cleaning and checking target directory
95 if (!$this->folderObject) {
96 $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:paramError', TRUE);
97 $message = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:targetNoDir', TRUE);
98 throw new RuntimeException($title . ': ' . $message, 1294586843);
99 }
100
101 // Setting the title and the icon
102 $icon = t3lib_iconWorks::getSpriteIcon('apps-filetree-root');
103 $this->title = $icon . htmlspecialchars($this->folderObject->getStorage()->getName()) . ': ' . htmlspecialchars($this->folderObject->getIdentifier());
104
105 // Setting template object
106 $this->doc = t3lib_div::makeInstance('template');
107 $this->doc->setModuleTemplate('templates/file_upload.html');
108 $this->doc->backPath = $GLOBALS['BACK_PATH'];
109 $this->doc->form = '<form action="tce_file.php" method="post" name="editform" enctype="' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'] . '">';
110 }
111
112 /**
113 * Main function, rendering the upload file form fields
114 *
115 * @return void
116 */
117 function main() {
118 // Make page header:
119 $this->content = $this->doc->startPage($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_upload.php.pagetitle'));
120
121 $form = $this->renderUploadForm();
122
123 $pageContent =
124 $this->doc->header($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_upload.php.pagetitle')) .
125 $this->doc->section('', $form);
126
127 // Header Buttons
128 $docHeaderButtons = array(
129 'csh' => t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'file_upload', $GLOBALS['BACK_PATH'])
130 );
131
132 $markerArray = array(
133 'CSH' => $docHeaderButtons['csh'],
134 'FUNC_MENU' => t3lib_BEfunc::getFuncMenu($this->id, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']),
135 'CONTENT' => $pageContent,
136 'PATH' => $this->title,
137 );
138
139 $this->content .= $this->doc->moduleBody(array(), $docHeaderButtons, $markerArray);
140 $this->content .= $this->doc->endPage();
141 $this->content = $this->doc->insertStylesAndJS($this->content);
142 }
143
144 /**
145 * This function renders the upload form
146 *
147 * @return string the HTML form as a string, ready for outputting
148 */
149 function renderUploadForm() {
150
151 // Make checkbox for "overwrite"
152 $content = '
153 <div id="c-override">
154 <p><label for="overwriteExistingFiles"><input type="checkbox" class="checkbox" name="overwriteExistingFiles" id="overwriteExistingFiles" value="1" /> ' . $GLOBALS['LANG']->getLL('overwriteExistingFiles', 1) . '</label></p>
155 <p>&nbsp;</p>
156 <p>' . $GLOBALS['LANG']->getLL('uploadMultipleFilesInfo', TRUE) . '</p>
157 </div>
158 ';
159
160 // Produce the number of upload-fields needed:
161 $content .= '
162 <div id="c-upload">
163 ';
164 // Adding 'size="50" ' for the sake of Mozilla!
165 $content .= '
166 <input type="file" multiple="true" name="upload_1[]" />
167 <input type="hidden" name="file[upload][1][target]" value="' . htmlspecialchars($this->folderObject->getCombinedIdentifier()) . '" />
168 <input type="hidden" name="file[upload][1][data]" value="1" /><br />
169 ';
170
171 $content .= '
172 </div>
173 ';
174
175 // Submit button:
176 $content .= '
177 <div id="c-submit">
178 <input type="hidden" name="redirect" value="' . $this->returnUrl . '" /><br />
179 <input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_upload.php.submit', 1) . '" />
180 </div>
181 ';
182
183 return $content;
184 }
185
186 /**
187 * Outputting the accumulated content to screen
188 *
189 * @return void
190 */
191 function printContent() {
192 echo $this->content;
193 }
194 }
195
196 // Make instance:
197 $SOBE = t3lib_div::makeInstance('SC_file_upload');
198 $SOBE->init();
199 $SOBE->main();
200 $SOBE->printContent();
201
202 ?>