2 /***************************************************************
5 * (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
6 * (c) 2009-2011 Benjamin Mack (benni.typo3.org)
9 * This script is part of the TYPO3 project. The TYPO3 project is
10 * free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * The GNU General Public License can be found at
16 * http://www.gnu.org/copyleft/gpl.html.
17 * A copy is found in the textfile GPL.txt and important notices to the license
18 * from the author is found in LICENSE.txt distributed with these scripts.
21 * This script is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * This copyright notice MUST APPEAR in all copies of the script!
27 ***************************************************************/
29 * Gateway for TCE (TYPO3 Core Engine) file-handling through POST forms.
30 * This script serves as the fileadministration part of the TYPO3 Core Engine.
31 * Basically it includes two libraries which are used to manipulate files on the server.
32 * Before TYPO3 4.3, it was located in typo3/tce_file.php and redirected back to a
33 * $redirectURL. Since 4.3 this class is also used for accessing via AJAX
36 * For syntax and API information, see the document 'TYPO3 Core APIs'
38 * Revised for TYPO3 3.6 July/2003 by Kasper Skårhøj
39 * Revised for TYPO3 4.3 Mar/2009 by Benjamin Mack
41 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
44 require_once(PATH_typo3
. 'template.php');
47 * Script Class, handling the calling of methods in the file admin classes.
49 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
55 // Internal, static: GPvar:
56 // Array of file-operations.
58 // Clipboard operations array
60 // If existing files should be overridden.
61 protected $overwriteExistingFiles;
62 // VeriCode - a hash of server specific value and other things which
63 // identifies if a submission is OK. (see $GLOBALS['BE_USER']->veriCode())
65 // the page where the user should be redirected after everything is done
69 // File processor object
70 protected $fileProcessor;
71 // the result array from the file processor
77 * Registering incoming data
81 public function init() {
82 // set the GPvars from outside
83 $this->file
= t3lib_div
::_GP('file');
84 $this->CB
= t3lib_div
::_GP('CB');
85 $this->overwriteExistingFiles
= t3lib_div
::_GP('overwriteExistingFiles');
86 $this->vC
= t3lib_div
::_GP('vC');
87 $this->redirect
= t3lib_div
::sanitizeLocalUrl(t3lib_div
::_GP('redirect'));
89 $this->initClipboard();
93 * Initialize the Clipboard. This will fetch the data about files to paste/delete if such an action has been sent.
97 public function initClipboard() {
98 if (is_array($this->CB
)) {
99 $clipObj = t3lib_div
::makeInstance('t3lib_clipboard');
100 $clipObj->initializeClipboard();
101 if ($this->CB
['paste']) {
102 $clipObj->setCurrentPad($this->CB
['pad']);
103 $this->file
= $clipObj->makePasteCmdArray_file($this->CB
['paste'], $this->file
);
105 if ($this->CB
['delete']) {
106 $clipObj->setCurrentPad($this->CB
['pad']);
107 $this->file
= $clipObj->makeDeleteCmdArray_file($this->file
);
113 * Performing the file admin action:
114 * Initializes the objects, setting permissions, sending data to object.
118 public function main() {
120 $this->fileProcessor
= t3lib_div
::makeInstance('t3lib_extFileFunctions');
121 $this->fileProcessor
->init($GLOBALS['FILEMOUNTS'], $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']);
122 $this->fileProcessor
->init_actionPerms($GLOBALS['BE_USER']->getFileoperationPermissions());
123 $this->fileProcessor
->dontCheckForUnique
= ($this->overwriteExistingFiles ?
1 : 0);
125 // Checking referer / executing:
126 $refInfo = parse_url(t3lib_div
::getIndpEnv('HTTP_REFERER'));
127 $httpHost = t3lib_div
::getIndpEnv('TYPO3_HOST_ONLY');
128 if ($httpHost != $refInfo['host']
129 && $this->vC
!= $GLOBALS['BE_USER']->veriCode()
130 && !$GLOBALS['TYPO3_CONF_VARS']['SYS']['doNotCheckReferer']
131 && $GLOBALS['CLIENT']['BROWSER'] != 'flash') {
132 $this->fileProcessor
->writeLog(0, 2, 1, 'Referer host "%s" and server host "%s" did not match!', array($refInfo['host'], $httpHost));
134 $this->fileProcessor
->start($this->file
);
135 $this->fileData
= $this->fileProcessor
->processData();
140 * Redirecting the user after the processing has been done.
141 * Might also display error messages directly, if any.
145 public function finish() {
146 // Prints errors, if there are any
147 $this->fileProcessor
->printLogErrorMessages($this->redirect
);
148 t3lib_BEfunc
::setUpdateSignal('updateFolderTree');
149 if ($this->redirect
) {
150 t3lib_utility_Http
::redirect($this->redirect
);
155 * Handles the actual process from within the ajaxExec function
156 * therefore, it does exactly the same as the real typo3/tce_file.php
157 * but without calling the "finish" method, thus makes it simpler to deal with the
158 * actual return value
161 * @param string $params always empty.
162 * @param string $ajaxObj The Ajax object used to return content and set content types
165 public function processAjaxRequest(array $params, TYPO3AJAX
$ajaxObj) {
168 $errors = $this->fileProcessor
->getErrorMessages();
169 if (count($errors)) {
170 $ajaxObj->setError(implode(',', $errors));
172 $ajaxObj->addContent('result', $this->fileData
);
173 if ($this->redirect
) {
174 $ajaxObj->addContent('redirect', $this->redirect
);
176 $ajaxObj->setContentFormat('json');