TYPO3 CMS  TYPO3_7-6
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/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/locallang_mod_file_list.xlf:paramError', true);
107  $message = $this->getLanguageService()->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:targetNoDir', true);
108  throw new \RuntimeException($title . ': ' . $message, 1294586843);
109  }
110 
111  // Setting up the context sensitive menu
112  $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ClickMenu');
113 
114  // building pathInfo for metaInformation
115  $pathInfo = [
116  'combined_identifier' => $this->folderObject->getCombinedIdentifier(),
117  ];
118  $this->moduleTemplate->getDocHeaderComponent()->setMetaInformation($pathInfo);
119  }
120 
126  public function main()
127  {
128  $lang = $this->getLanguageService();
129 
130  // set page title
131  $this->moduleTemplate->setTitle($lang->sL('LLL:EXT:lang/locallang_core.xlf:file_upload.php.pagetitle'));
132 
133  $pageContent = '<form action="'
134  . htmlspecialchars(BackendUtility::getModuleUrl('tce_file'))
135  . '" method="post" id="FileUploadController" name="editform" enctype="multipart/form-data">';
136  // Make page header:
137  $pageContent .= '<h1>' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:file_upload.php.pagetitle') . '</h1>';
138  $pageContent .= $this->renderUploadForm();
139 
140  // Header Buttons
141  $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
142 
143  // csh button
144  $cshButton = $buttonBar->makeHelpButton()
145  ->setModuleName('xMOD_csh_corebe')
146  ->setFieldName('file_upload');
147  $buttonBar->addButton($cshButton);
148 
149  // back button
150  if ($this->returnUrl) {
151  $backButton = $buttonBar->makeLinkButton()
152  ->setHref(GeneralUtility::linkThisUrl($this->returnUrl))
153  ->setTitle($lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.goBack'))
154  ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-view-go-back', Icon::SIZE_SMALL));
155  $buttonBar->addButton($backButton);
156  }
157 
158  $pageContent .= '</form>';
159  $this->content .= '<div>' . $pageContent . '</div>';
160  $this->moduleTemplate->setContent($this->content);
161  }
162 
168  public function renderUploadForm()
169  {
170  // Make checkbox for "overwrite"
171  $content = '
172  <div id="c-override">
173  <p><label for="overwriteExistingFiles"><input type="checkbox" class="checkbox" name="overwriteExistingFiles" id="overwriteExistingFiles" value="replace" /> ' . $this->getLanguageService()->getLL('overwriteExistingFiles', 1) . '</label></p>
174  <p>&nbsp;</p>
175  <p>' . $this->getLanguageService()->getLL('uploadMultipleFilesInfo', true) . '</p>
176  </div>
177  ';
178  // Produce the number of upload-fields needed:
179  $content .= '
180  <div id="c-upload">
181  ';
182  // Adding 'size="50" ' for the sake of Mozilla!
183  $content .= '
184  <input type="file" multiple="multiple" name="upload_1[]" />
185  <input type="hidden" name="file[upload][1][target]" value="' . htmlspecialchars($this->folderObject->getCombinedIdentifier()) . '" />
186  <input type="hidden" name="file[upload][1][data]" value="1" /><br />
187  ';
188  $content .= '
189  </div>
190  ';
191  // Submit button:
192  $content .= '
193  <div id="c-submit">
194  <input type="hidden" name="redirect" value="' . $this->returnUrl . '" /><br />
195  <input class="btn btn-default" type="submit" value="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:file_upload.php.submit', true) . '" />
196  </div>
197  ';
198  return $content;
199  }
200 
208  public function mainAction(ServerRequestInterface $request, ResponseInterface $response)
209  {
210  $this->main();
211  $response->getBody()->write($this->moduleTemplate->renderContent());
212 
213  return $response;
214  }
215 
221  protected function getLanguageService()
222  {
223  return $GLOBALS['LANG'];
224  }
225 }
static linkThisUrl($url, array $getParams=[])
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
mainAction(ServerRequestInterface $request, ResponseInterface $response)