TYPO3 CMS  TYPO3_6-2
FileController.php
Go to the documentation of this file.
1 <?php
3 
19 
30 
31  // Internal, static: GPvar:
32  // Array of file-operations.
33  protected $file;
34 
35  // Clipboard operations array
36  protected $CB;
37 
38  // If existing files should be overridden.
40 
41  // VeriCode - a hash of server specific value and other things which
42  // identifies if a submission is OK. (see $GLOBALS['BE_USER']->veriCode())
43  protected $vC;
44 
45  // the page where the user should be redirected after everything is done
46  protected $redirect;
47 
54  protected $fileProcessor;
55 
56  // the result array from the file processor
57  protected $fileData;
58 
62  public function __construct() {
63  $GLOBALS['SOBE'] = $this;
64  $this->init();
65  }
66 
72  protected function init() {
73  // Set the GPvars from outside
74  $this->file = GeneralUtility::_GP('file');
75  $this->CB = GeneralUtility::_GP('CB');
76  $this->overwriteExistingFiles = GeneralUtility::_GP('overwriteExistingFiles');
77  $this->vC = GeneralUtility::_GP('vC');
78  $this->redirect = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('redirect'));
79  $this->initClipboard();
80  $this->fileProcessor = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Utility\\File\\ExtendedFileUtility');
81  }
82 
88  public function initClipboard() {
89  if (is_array($this->CB)) {
90  $clipObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Clipboard\\Clipboard');
91  $clipObj->initializeClipboard();
92  if ($this->CB['paste']) {
93  $clipObj->setCurrentPad($this->CB['pad']);
94  $this->file = $clipObj->makePasteCmdArray_file($this->CB['paste'], $this->file);
95  }
96  if ($this->CB['delete']) {
97  $clipObj->setCurrentPad($this->CB['pad']);
98  $this->file = $clipObj->makeDeleteCmdArray_file($this->file);
99  }
100  }
101  }
102 
109  public function main() {
110  // Initializing:
111  $this->fileProcessor->init(array(), $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']);
112  $this->fileProcessor->setActionPermissions();
113  $this->fileProcessor->dontCheckForUnique = $this->overwriteExistingFiles ? 1 : 0;
114  // Checking referrer / executing:
115  $refInfo = parse_url(GeneralUtility::getIndpEnv('HTTP_REFERER'));
116  $httpHost = GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY');
117  if ($httpHost != $refInfo['host'] && $this->vC != $GLOBALS['BE_USER']->veriCode() && !$GLOBALS['TYPO3_CONF_VARS']['SYS']['doNotCheckReferer'] && $GLOBALS['CLIENT']['BROWSER'] != 'flash') {
118  $this->fileProcessor->writeLog(0, 2, 1, 'Referrer host "%s" and server host "%s" did not match!', array($refInfo['host'], $httpHost));
119  } else {
120  $this->fileProcessor->start($this->file);
121  $this->fileData = $this->fileProcessor->processData();
122  }
123  }
124 
131  public function finish() {
132  // Push errors to flash message queue, if there are any
133  $this->fileProcessor->pushErrorMessagesToFlashMessageQueue();
134  BackendUtility::setUpdateSignal('updateFolderTree');
135  if ($this->redirect) {
137  }
138  }
139 
150  public function processAjaxRequest(array $params, \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj) {
151  $this->init();
152  $this->main();
153  $errors = $this->fileProcessor->getErrorMessages();
154  if (count($errors)) {
155  $ajaxObj->setError(implode(',', $errors));
156  } else {
157  $flatResult = array();
158  foreach ($this->fileData as $action => $results) {
159  foreach ($results as $result) {
160  if (is_array($result)) {
161  foreach ($result as $subResult) {
162  $flatResult[$action][] = $this->flattenResultDataValue($subResult);
163  }
164  } else {
165  $flatResult[$action][] = $this->flattenResultDataValue($result);
166  }
167  }
168  }
169  $ajaxObj->addContent('result', $flatResult);
170  if ($this->redirect) {
171  $ajaxObj->addContent('redirect', $this->redirect);
172  }
173  $ajaxObj->setContentFormat('json');
174  }
175  }
176 
185  protected function flattenResultDataValue($result) {
186 
187  if ($result instanceof \TYPO3\CMS\Core\Resource\File) {
188  $result = array_merge(
189  $result->toArray(),
190  array (
191  'date' => BackendUtility::date($result->getModificationTime()),
192  'iconClasses' => \TYPO3\CMS\Backend\Utility\IconUtility::mapFileExtensionToSpriteIconClass($result->getExtension()),
193  )
194  );
195  } elseif ($result instanceof \TYPO3\CMS\Core\Resource\Folder) {
196  $result = $result->getIdentifier();
197  }
198 
199  return $result;
200  }
201 }
processAjaxRequest(array $params, \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj)
static mapFileExtensionToSpriteIconClass($fileExtension)
if($list_of_literals) if(!empty($literals)) if(!empty($literals)) $result
Analyse literals to prepend the N char to them if their contents aren&#39;t numeric.
static setUpdateSignal($set='', $params='')
static redirect($url, $httpStatus=self::HTTP_STATUS_303)
Definition: HttpUtility.php:76
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
if($ajaxRegistryEntry !==NULL) $ajaxObj
Definition: ajax.php:63