f767fdf6ead5b0402806b2fbab04b28c7c673477
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Controller / File / FileUploadController.php
1 <?php
2 namespace TYPO3\CMS\Backend\Controller\File;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 1999-2013 Kasper Skårhøj (kasperYYYY@typo3.com)
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 use TYPO3\CMS\Backend\Utility\BackendUtility;
31 use TYPO3\CMS\Core\Utility\GeneralUtility;
32
33 /**
34 * Script Class for display up to 10 upload fields
35 *
36 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
37 */
38 class FileUploadController {
39
40 // Internal, static:
41 /**
42 * Document template object
43 *
44 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
45 * @todo Define visibility
46 */
47 public $doc;
48
49 // Name of the filemount
50 /**
51 * @todo Define visibility
52 */
53 public $title;
54
55 // Internal, static (GPVar):
56 // Set with the target path inputted in &target
57 /**
58 * @todo Define visibility
59 */
60 public $target;
61
62 // Return URL of list module.
63 /**
64 * @todo Define visibility
65 */
66 public $returnUrl;
67
68 // Internal, dynamic:
69 // Accumulating content
70 /**
71 * @todo Define visibility
72 */
73 public $content;
74
75 /**
76 * The folder object which is the target directory for the upload
77 *
78 * @var \TYPO3\CMS\Core\Resource\Folder $folderObject
79 */
80 protected $folderObject;
81
82 /**
83 * Constructor for initializing the class
84 *
85 * @return void
86 * @todo Define visibility
87 */
88 public function init() {
89 // Initialize GPvars:
90 $this->target = GeneralUtility::_GP('target');
91 $this->returnUrl = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'));
92 if (!$this->returnUrl) {
93 $this->returnUrl = GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir . BackendUtility::getModuleUrl('file_list') . '&id=' . rawurlencode($this->target);
94 }
95 // Create the folder object
96 if ($this->target) {
97 $this->folderObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($this->target);
98 }
99 // Cleaning and checking target directory
100 if (!$this->folderObject) {
101 $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:paramError', TRUE);
102 $message = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:targetNoDir', TRUE);
103 throw new \RuntimeException($title . ': ' . $message, 1294586843);
104 }
105 // Setting the title and the icon
106 $icon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('apps-filetree-root');
107 $this->title = $icon . htmlspecialchars($this->folderObject->getStorage()->getName()) . ': ' . htmlspecialchars($this->folderObject->getIdentifier());
108 // Setting template object
109 $this->doc = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
110 $this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/file_upload.html');
111 $this->doc->backPath = $GLOBALS['BACK_PATH'];
112 $this->doc->form = '<form action="tce_file.php" method="post" name="editform" enctype="' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'] . '">';
113 }
114
115 /**
116 * Main function, rendering the upload file form fields
117 *
118 * @return void
119 * @todo Define visibility
120 */
121 public function main() {
122 // Make page header:
123 $this->content = $this->doc->startPage($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_upload.php.pagetitle'));
124 $form = $this->renderUploadForm();
125 $pageContent = $this->doc->header($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_upload.php.pagetitle')) . $this->doc->section('', $form);
126 // Header Buttons
127 $docHeaderButtons = array(
128 'csh' => BackendUtility::cshItem('xMOD_csh_corebe', 'file_upload', $GLOBALS['BACK_PATH']),
129 'back' => ''
130 );
131 $markerArray = array(
132 'CSH' => $docHeaderButtons['csh'],
133 'FUNC_MENU' => BackendUtility::getFuncMenu($this->id, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']),
134 'CONTENT' => $pageContent,
135 'PATH' => $this->title
136 );
137 // Back
138 if ($this->returnUrl) {
139 $docHeaderButtons['back'] = '<a href="' . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::linkThisUrl($this->returnUrl)) . '" class="typo3-goBack" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.goBack', TRUE) . '">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-view-go-back') . '</a>';
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 * @todo Define visibility
151 */
152 public function renderUploadForm() {
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 // Produce the number of upload-fields needed:
162 $content .= '
163 <div id="c-upload">
164 ';
165 // Adding 'size="50" ' for the sake of Mozilla!
166 $content .= '
167 <input type="file" multiple="true" name="upload_1[]" />
168 <input type="hidden" name="file[upload][1][target]" value="' . htmlspecialchars($this->folderObject->getCombinedIdentifier()) . '" />
169 <input type="hidden" name="file[upload][1][data]" value="1" /><br />
170 ';
171 $content .= '
172 </div>
173 ';
174 // Submit button:
175 $content .= '
176 <div id="c-submit">
177 <input type="hidden" name="redirect" value="' . $this->returnUrl . '" /><br />
178 <input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_upload.php.submit', 1) . '" />
179 </div>
180 ';
181 return $content;
182 }
183
184 /**
185 * Outputting the accumulated content to screen
186 *
187 * @return void
188 * @todo Define visibility
189 */
190 public function printContent() {
191 echo $this->content;
192 }
193
194 }
195
196 ?>