[TASK] Fix CGL violations InlineCommentWrongStyle in ext_emconf.php files
[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 // Internal, static:
51 /**
52 * Document template object
53 *
54 * @var smallDoc
55 */
56 var $doc;
57
58 var $title; // Name of the filemount
59
60 // Internal, static (GPVar):
61 var $target; // Set with the target path inputted in &target
62 var $returnUrl; // Return URL of list module.
63
64 // Internal, dynamic:
65 var $content; // Accumulating content
66
67 /**
68 * the folder object which is the target directory for the upload
69 *
70 * @var t3lib_file_Folder $folderObject
71 */
72 protected $folderObject;
73
74 /**
75 * Constructor for initializing the class
76 *
77 * @return void
78 */
79 function init() {
80 // Initialize GPvars:
81 $this->target = t3lib_div::_GP('target');
82 $this->returnUrl = t3lib_div::sanitizeLocalUrl(t3lib_div::_GP('returnUrl'));
83 if (!$this->returnUrl) {
84 $this->returnUrl = t3lib_div::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir . t3lib_extMgm::extRelPath('filelist') . 'mod1/file_list.php?id=' . rawurlencode($this->target);
85 }
86
87 // create the folder object
88 if ($this->target) {
89 $this->folderObject = t3lib_file_Factory::getInstance()->retrieveFileOrFolderObject($this->target);
90 }
91
92 // Cleaning and checking target directory
93 if (!$this->folderObject) {
94 $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:paramError', TRUE);
95 $message = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:targetNoDir', TRUE);
96 throw new RuntimeException($title . ': ' . $message, 1294586843);
97 }
98
99 // Setting the title and the icon
100 $icon = t3lib_iconWorks::getSpriteIcon('apps-filetree-root');
101 $this->title = $icon . htmlspecialchars($this->folderObject->getStorage()->getName()) . ': ' . htmlspecialchars($this->folderObject->getIdentifier());
102
103
104 // Setting template object
105 $this->doc = t3lib_div::makeInstance('template');
106 $this->doc->setModuleTemplate('templates/file_upload.html');
107 $this->doc->backPath = $GLOBALS['BACK_PATH'];
108 $this->doc->form = '<form action="tce_file.php" method="post" name="editform" enctype="' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'] . '">';
109 }
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
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 /**
147 * This function renders the upload form
148 *
149 * @return string the HTML form as a string, ready for outputting
150 */
151 function renderUploadForm() {
152
153 // Make checkbox for "overwrite"
154 $content = '
155 <div id="c-override">
156 <p><label for="overwriteExistingFiles"><input type="checkbox" class="checkbox" name="overwriteExistingFiles" id="overwriteExistingFiles" value="1" /> ' . $GLOBALS['LANG']->getLL('overwriteExistingFiles', 1) . '</label></p>
157 <p>&nbsp;</p>
158 <p>' . $GLOBALS['LANG']->getLL('uploadMultipleFilesInfo', TRUE) . '</p>
159 </div>
160 ';
161
162
163 // Produce the number of upload-fields needed:
164 $content .= '
165 <div id="c-upload">
166 ';
167 // Adding 'size="50" ' for the sake of Mozilla!
168 $content .= '
169 <input type="file" multiple="true" name="upload_1[]" />
170 <input type="hidden" name="file[upload][1][target]" value="' . htmlspecialchars($this->folderObject->getCombinedIdentifier()) . '" />
171 <input type="hidden" name="file[upload][1][data]" value="1" /><br />
172 ';
173
174 $content .= '
175 </div>
176 ';
177
178 // Submit button:
179 $content .= '
180 <div id="c-submit">
181 <input type="hidden" name="redirect" value="' . $this->returnUrl . '" /><br />
182 <input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_upload.php.submit', 1) . '" />
183 </div>
184 ';
185
186 return $content;
187 }
188
189
190 /**
191 * Outputting the accumulated content to screen
192 *
193 * @return void
194 */
195 function printContent() {
196 echo $this->content;
197 }
198 }
199
200 // Make instance:
201 $SOBE = t3lib_div::makeInstance('SC_file_upload');
202 $SOBE->init();
203 $SOBE->main();
204 $SOBE->printContent();
205
206 ?>