[TASK] Cleanup entry classes in typo3/ part2
[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
84 */
85 public function __construct() {
86 $GLOBALS['SOBE'] = $this;
87 $GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_misc.xlf');
88 $GLOBALS['BACK_PATH'] = '';
89
90 $this->init();
91 }
92
93 /**
94 * Initialize
95 *
96 * @return void
97 */
98 protected function init() {
99 // Initialize GPvars:
100 $this->target = GeneralUtility::_GP('target');
101 $this->returnUrl = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'));
102 if (!$this->returnUrl) {
103 $this->returnUrl = GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir . BackendUtility::getModuleUrl('file_list') . '&id=' . rawurlencode($this->target);
104 }
105 // Create the folder object
106 if ($this->target) {
107 $this->folderObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($this->target);
108 }
109 // Cleaning and checking target directory
110 if (!$this->folderObject) {
111 $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:paramError', TRUE);
112 $message = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:targetNoDir', TRUE);
113 throw new \RuntimeException($title . ': ' . $message, 1294586843);
114 }
115 // Setting the title and the icon
116 $icon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('apps-filetree-root');
117 $this->title = $icon . htmlspecialchars($this->folderObject->getStorage()->getName()) . ': ' . htmlspecialchars($this->folderObject->getIdentifier());
118 // Setting template object
119 $this->doc = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
120 $this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/file_upload.html');
121 $this->doc->backPath = $GLOBALS['BACK_PATH'];
122 $this->doc->form = '<form action="tce_file.php" method="post" name="editform" enctype="' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'] . '">';
123 }
124
125 /**
126 * Main function, rendering the upload file form fields
127 *
128 * @return void
129 */
130 public function main() {
131 // Make page header:
132 $this->content = $this->doc->startPage($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_upload.php.pagetitle'));
133 $form = $this->renderUploadForm();
134 $pageContent = $this->doc->header($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_upload.php.pagetitle')) . $this->doc->section('', $form);
135 // Header Buttons
136 $docHeaderButtons = array(
137 'csh' => BackendUtility::cshItem('xMOD_csh_corebe', 'file_upload', $GLOBALS['BACK_PATH']),
138 'back' => ''
139 );
140 $markerArray = array(
141 'CSH' => $docHeaderButtons['csh'],
142 'FUNC_MENU' => BackendUtility::getFuncMenu($this->id, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']),
143 'CONTENT' => $pageContent,
144 'PATH' => $this->title
145 );
146 // Back
147 if ($this->returnUrl) {
148 $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>';
149 }
150 $this->content .= $this->doc->moduleBody(array(), $docHeaderButtons, $markerArray);
151 $this->content .= $this->doc->endPage();
152 $this->content = $this->doc->insertStylesAndJS($this->content);
153 }
154
155 /**
156 * This function renders the upload form
157 *
158 * @return string the HTML form as a string, ready for outputting
159 * @todo Define visibility
160 */
161 public function renderUploadForm() {
162 // Make checkbox for "overwrite"
163 $content = '
164 <div id="c-override">
165 <p><label for="overwriteExistingFiles"><input type="checkbox" class="checkbox" name="overwriteExistingFiles" id="overwriteExistingFiles" value="1" /> ' . $GLOBALS['LANG']->getLL('overwriteExistingFiles', 1) . '</label></p>
166 <p>&nbsp;</p>
167 <p>' . $GLOBALS['LANG']->getLL('uploadMultipleFilesInfo', TRUE) . '</p>
168 </div>
169 ';
170 // Produce the number of upload-fields needed:
171 $content .= '
172 <div id="c-upload">
173 ';
174 // Adding 'size="50" ' for the sake of Mozilla!
175 $content .= '
176 <input type="file" multiple="true" name="upload_1[]" />
177 <input type="hidden" name="file[upload][1][target]" value="' . htmlspecialchars($this->folderObject->getCombinedIdentifier()) . '" />
178 <input type="hidden" name="file[upload][1][data]" value="1" /><br />
179 ';
180 $content .= '
181 </div>
182 ';
183 // Submit button:
184 $content .= '
185 <div id="c-submit">
186 <input type="hidden" name="redirect" value="' . $this->returnUrl . '" /><br />
187 <input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_upload.php.submit', 1) . '" />
188 </div>
189 ';
190 return $content;
191 }
192
193 /**
194 * Outputting the accumulated content to screen
195 *
196 * @return void
197 */
198 public function printContent() {
199 echo $this->content;
200 }
201
202 }
203
204 ?>