TYPO3 CMS  TYPO3_8-7
FileUploadController.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
25 
30 {
36  public $title;
37 
43  public $target;
44 
50  public $returnUrl;
51 
57  public $content;
58 
64  protected $folderObject;
65 
69  public function __construct()
70  {
71  parent::__construct();
72  $GLOBALS['SOBE'] = $this;
73  $this->getLanguageService()->includeLLFile('EXT:lang/Resources/Private/Language/locallang_misc.xlf');
74  $this->init();
75  }
76 
82  protected function init()
83  {
84  // Initialize GPvars:
85  $this->target = GeneralUtility::_GP('target');
86  $this->returnUrl = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'));
87  if (!$this->returnUrl) {
88  $this->returnUrl = BackendUtility::getModuleUrl('file_list', [
89  'id' => rawurlencode($this->target)
90  ]);
91  }
92  // Create the folder object
93  if ($this->target) {
94  $this->folderObject = ResourceFactory::getInstance()
95  ->retrieveFileOrFolderObject($this->target);
96  }
97  if ($this->folderObject->getStorage()->getUid() === 0) {
99  'You are not allowed to access folders outside your storages',
100  1375889834
101  );
102  }
103 
104  // Cleaning and checking target directory
105  if (!$this->folderObject) {
106  $title = $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_mod_file_list.xlf:paramError');
107  $message = $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_mod_file_list.xlf:targetNoDir');
108  throw new \RuntimeException($title . ': ' . $message, 1294586843);
109  }
110 
111  // Setting up the context sensitive menu
112  $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ContextMenu');
113 
114  // building pathInfo for metaInformation
115  $pathInfo = [
116  'combined_identifier' => $this->folderObject->getCombinedIdentifier(),
117  ];
118  $this->moduleTemplate->getDocHeaderComponent()->setMetaInformation($pathInfo);
119  }
120 
124  public function main()
125  {
126  $lang = $this->getLanguageService();
127 
128  // set page title
129  $this->moduleTemplate->setTitle($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:file_upload.php.pagetitle'));
130 
131  $pageContent = '<form action="'
132  . htmlspecialchars(BackendUtility::getModuleUrl('tce_file'))
133  . '" method="post" id="FileUploadController" name="editform" enctype="multipart/form-data">';
134  // Make page header:
135  $pageContent .= '<h1>' . $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:file_upload.php.pagetitle') . '</h1>';
136  $pageContent .= $this->renderUploadForm();
137 
138  // Header Buttons
139  $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
140 
141  // csh button
142  $cshButton = $buttonBar->makeHelpButton()
143  ->setModuleName('xMOD_csh_corebe')
144  ->setFieldName('file_upload');
145  $buttonBar->addButton($cshButton);
146 
147  // back button
148  if ($this->returnUrl) {
149  $backButton = $buttonBar->makeLinkButton()
150  ->setHref($this->returnUrl)
151  ->setTitle($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.goBack'))
152  ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-view-go-back', Icon::SIZE_SMALL));
153  $buttonBar->addButton($backButton);
154  }
155 
156  $pageContent .= '</form>';
157  $this->content .= '<div>' . $pageContent . '</div>';
158  $this->moduleTemplate->setContent($this->content);
159  }
160 
166  public function renderUploadForm()
167  {
168  // Make checkbox for "overwrite"
169  $content = '
170  <div id="c-override">
171  <p><label for="overwriteExistingFiles"><input type="checkbox" class="checkbox" name="overwriteExistingFiles" id="overwriteExistingFiles" value="replace" /> ' . htmlspecialchars($this->getLanguageService()->getLL('overwriteExistingFiles')) . '</label></p>
172  <p>&nbsp;</p>
173  <p>' . htmlspecialchars($this->getLanguageService()->getLL('uploadMultipleFilesInfo')) . '</p>
174  </div>
175  ';
176  // Produce the number of upload-fields needed:
177  $content .= '
178  <div id="c-upload">
179  ';
180  // Adding 'size="50" ' for the sake of Mozilla!
181  $content .= '
182  <input type="file" multiple="multiple" name="upload_1[]" />
183  <input type="hidden" name="file[upload][1][target]" value="' . htmlspecialchars($this->folderObject->getCombinedIdentifier()) . '" />
184  <input type="hidden" name="file[upload][1][data]" value="1" /><br />
185  ';
186  $content .= '
187  </div>
188  ';
189  // Submit button:
190  $content .= '
191  <div id="c-submit">
192  <input type="hidden" name="redirect" value="' . $this->returnUrl . '" /><br />
193  <input class="btn btn-default" type="submit" value="' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:file_upload.php.submit')) . '" />
194  </div>
195  ';
196  return $content;
197  }
198 
206  public function mainAction(ServerRequestInterface $request, ResponseInterface $response)
207  {
208  $this->main();
209  $response->getBody()->write($this->moduleTemplate->renderContent());
210 
211  return $response;
212  }
213 
219  protected function getLanguageService()
220  {
221  return $GLOBALS['LANG'];
222  }
223 }
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
mainAction(ServerRequestInterface $request, ResponseInterface $response)