Added Feature #12066: Added constants throughout the core for LF, CR, TAB (Thanks...
[Packages/TYPO3.CMS.git] / typo3 / classes / class.typo3_tcefile.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2009 Kasper Skaarhoj (kasperYYYY@typo3.com)
6 * (c) 2009 Benjamin Mack (benni.typo3.org)
7 * All rights reserved
8 *
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.
14 *
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.
19 *
20 *
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.
25 *
26 * This copyright notice MUST APPEAR in all copies of the script!
27 ***************************************************************/
28 /**
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
34 *
35 *
36 * For syntax and API information, see the document 'TYPO3 Core APIs'
37 *
38 * Revised for TYPO3 3.6 July/2003 by Kasper Skaarhoj
39 * Revised for TYPO3 4.3 Mar/2009 by Benjamin Mack
40 *
41 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
42 */
43
44 require_once(PATH_typo3 . 'template.php');
45
46 /**
47 * Script Class, handling the calling of methods in the file admin classes.
48 *
49 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
50 * @package TYPO3
51 * @subpackage core
52 */
53 class TYPO3_tcefile {
54
55 // Internal, static: GPvar:
56 // Array of file-operations.
57 protected $file;
58 // Clipboard operations array
59 protected $CB;
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 $BE_USER->veriCode())
64 protected $vC;
65 // the page where the user should be redirected after everything is done
66 protected $redirect;
67
68 // Internal, dynamic:
69 // File processor object
70 protected $fileProcessor;
71 // the result array from the file processor
72 protected $fileData;
73
74
75
76 /**
77 * Registering incoming data
78 *
79 * @return void
80 */
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::_GP('redirect');
88
89 $this->initClipboard();
90 }
91
92 /**
93 * Initialize the Clipboard. This will fetch the data about files to paste/delete if such an action has been sent.
94 *
95 * @return void
96 */
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);
104 }
105 if ($this->CB['delete']) {
106 $clipObj->setCurrentPad($this->CB['pad']);
107 $this->file = $clipObj->makeDeleteCmdArray_file($this->file);
108 }
109 }
110 }
111
112 /**
113 * Performing the file admin action:
114 * Initializes the objects, setting permissions, sending data to object.
115 *
116 * @return void
117 */
118 public function main() {
119 // Initializing:
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);
124
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));
133 } else {
134 $this->fileProcessor->start($this->file);
135 $this->fileData = $this->fileProcessor->processData();
136 }
137 }
138
139 /**
140 * Redirecting the user after the processing has been done.
141 * Might also display error messages directly, if any.
142 *
143 * @return void
144 */
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);
151 }
152 }
153
154 /**
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
159 *
160 *
161 * @param string $params always empty.
162 * @param string $ajaxObj The Ajax object used to return content and set content types
163 * @return void
164 */
165 public function processAjaxRequest(array $params, TYPO3AJAX $ajaxObj) {
166 $this->init();
167 $this->main();
168 $errors = $this->fileProcessor->getErrorMessages();
169 if (count($errors)) {
170 $ajaxObj->setError(implode(',', $errors));
171 } else {
172 $ajaxObj->addContent('result', $this->fileData);
173 if ($this->redirect) {
174 $ajaxObj->addContent('redirect', $this->redirect);
175 }
176 $ajaxObj->setContentFormat('json');
177 }
178 }
179 }
180
181 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/classes/class.typo3_tcefile.php']) {
182 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/classes/class.typo3_tcefile.php']);
183 }
184
185 ?>