[TASK] Clean up phpDoc comments in typo3/
[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 require('template.php');
39 $LANG->includeLLFile('EXT:lang/locallang_misc.xml');
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 // Name of the filemount
58 var $title;
59
60 // Internal, static (GPVar):
61 // Set with the target path inputted in &target
62 var $target;
63 // Return URL of list module.
64 var $returnUrl;
65
66 // Internal, dynamic:
67 // Accumulating content
68 var $content;
69
70 /**
71 * The folder object which is the target directory for the upload
72 *
73 * @var t3lib_file_Folder $folderObject
74 */
75 protected $folderObject;
76
77 /**
78 * Constructor for initializing the class
79 *
80 * @return void
81 */
82 function init() {
83 // Initialize GPvars:
84 $this->target = t3lib_div::_GP('target');
85 $this->returnUrl = t3lib_div::sanitizeLocalUrl(t3lib_div::_GP('returnUrl'));
86 if (!$this->returnUrl) {
87 $this->returnUrl = t3lib_div::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir . t3lib_extMgm::extRelPath('filelist') . 'mod1/file_list.php?id=' . rawurlencode($this->target);
88 }
89
90 // Create the folder object
91 if ($this->target) {
92 $this->folderObject = t3lib_file_Factory::getInstance()->retrieveFileOrFolderObject($this->target);
93 }
94
95 // Cleaning and checking target directory
96 if (!$this->folderObject) {
97 $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:paramError', TRUE);
98 $message = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:targetNoDir', TRUE);
99 throw new RuntimeException($title . ': ' . $message, 1294586843);
100 }
101
102 // Setting the title and the icon
103 $icon = t3lib_iconWorks::getSpriteIcon('apps-filetree-root');
104 $this->title = $icon . htmlspecialchars($this->folderObject->getStorage()->getName()) . ': ' . htmlspecialchars($this->folderObject->getIdentifier());
105
106
107 // Setting template object
108 $this->doc = t3lib_div::makeInstance('template');
109 $this->doc->setModuleTemplate('templates/file_upload.html');
110 $this->doc->backPath = $GLOBALS['BACK_PATH'];
111 $this->doc->form = '<form action="tce_file.php" method="post" name="editform" enctype="' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'] . '">';
112 }
113
114 /**
115 * Main function, rendering the upload file form fields
116 *
117 * @return void
118 */
119 function main() {
120 // Make page header:
121 $this->content = $this->doc->startPage($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_upload.php.pagetitle'));
122
123 $form = $this->renderUploadForm();
124
125 $pageContent =
126 $this->doc->header($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_upload.php.pagetitle')) .
127 $this->doc->section('', $form);
128
129 // Header Buttons
130 $docHeaderButtons = array(
131 'csh' => t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'file_upload', $GLOBALS['BACK_PATH'])
132 );
133
134 $markerArray = array(
135 'CSH' => $docHeaderButtons['csh'],
136 'FUNC_MENU' => t3lib_BEfunc::getFuncMenu($this->id, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']),
137 'CONTENT' => $pageContent,
138 'PATH' => $this->title,
139 );
140
141 $this->content .= $this->doc->moduleBody(array(), $docHeaderButtons, $markerArray);
142 $this->content .= $this->doc->endPage();
143 $this->content = $this->doc->insertStylesAndJS($this->content);
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 * Outputting the accumulated content to screen
191 *
192 * @return void
193 */
194 function printContent() {
195 echo $this->content;
196 }
197 }
198
199 // Make instance:
200 $SOBE = t3lib_div::makeInstance('SC_file_upload');
201 $SOBE->init();
202 $SOBE->main();
203 $SOBE->printContent();
204
205 ?>