[TASK] Remove require statements for classes
[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
106 // Setting template object
107 $this->doc = t3lib_div::makeInstance('template');
108 $this->doc->setModuleTemplate('templates/file_upload.html');
109 $this->doc->backPath = $GLOBALS['BACK_PATH'];
110 $this->doc->form = '<form action="tce_file.php" method="post" name="editform" enctype="' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'] . '">';
111 }
112
113 /**
114 * Main function, rendering the upload file form fields
115 *
116 * @return void
117 */
118 function main() {
119 // Make page header:
120 $this->content = $this->doc->startPage($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_upload.php.pagetitle'));
121
122 $form = $this->renderUploadForm();
123
124 $pageContent =
125 $this->doc->header($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_upload.php.pagetitle')) .
126 $this->doc->section('', $form);
127
128 // Header Buttons
129 $docHeaderButtons = array(
130 'csh' => t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'file_upload', $GLOBALS['BACK_PATH'])
131 );
132
133 $markerArray = array(
134 'CSH' => $docHeaderButtons['csh'],
135 'FUNC_MENU' => t3lib_BEfunc::getFuncMenu($this->id, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']),
136 'CONTENT' => $pageContent,
137 'PATH' => $this->title,
138 );
139
140 $this->content .= $this->doc->moduleBody(array(), $docHeaderButtons, $markerArray);
141 $this->content .= $this->doc->endPage();
142 $this->content = $this->doc->insertStylesAndJS($this->content);
143 }
144
145 /**
146 * This function renders the upload form
147 *
148 * @return string the HTML form as a string, ready for outputting
149 */
150 function renderUploadForm() {
151
152 // Make checkbox for "overwrite"
153 $content = '
154 <div id="c-override">
155 <p><label for="overwriteExistingFiles"><input type="checkbox" class="checkbox" name="overwriteExistingFiles" id="overwriteExistingFiles" value="1" /> ' . $GLOBALS['LANG']->getLL('overwriteExistingFiles', 1) . '</label></p>
156 <p>&nbsp;</p>
157 <p>' . $GLOBALS['LANG']->getLL('uploadMultipleFilesInfo', TRUE) . '</p>
158 </div>
159 ';
160
161
162 // Produce the number of upload-fields needed:
163 $content .= '
164 <div id="c-upload">
165 ';
166 // Adding 'size="50" ' for the sake of Mozilla!
167 $content .= '
168 <input type="file" multiple="true" name="upload_1[]" />
169 <input type="hidden" name="file[upload][1][target]" value="' . htmlspecialchars($this->folderObject->getCombinedIdentifier()) . '" />
170 <input type="hidden" name="file[upload][1][data]" value="1" /><br />
171 ';
172
173 $content .= '
174 </div>
175 ';
176
177 // Submit button:
178 $content .= '
179 <div id="c-submit">
180 <input type="hidden" name="redirect" value="' . $this->returnUrl . '" /><br />
181 <input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_upload.php.submit', 1) . '" />
182 </div>
183 ';
184
185 return $content;
186 }
187
188 /**
189 * Outputting the accumulated content to screen
190 *
191 * @return void
192 */
193 function printContent() {
194 echo $this->content;
195 }
196 }
197
198 // Make instance:
199 $SOBE = t3lib_div::makeInstance('SC_file_upload');
200 $SOBE->init();
201 $SOBE->main();
202 $SOBE->printContent();
203
204 ?>