Cleanup: Fixed formatting issues in typo3 and test PHP files
[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 require_once(PATH_t3lib . 'class.t3lib_basicfilefunc.php');
46 require_once(PATH_t3lib . 'class.t3lib_extfilefunc.php');
47 require_once(PATH_t3lib . 'class.t3lib_clipboard.php');
48
49 /**
50 * Script Class, handling the calling of methods in the file admin classes.
51 *
52 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
53 * @package TYPO3
54 * @subpackage core
55 */
56 class TYPO3_tcefile {
57
58 // Internal, static: GPvar:
59 // Array of file-operations.
60 protected $file;
61 // Clipboard operations array
62 protected $CB;
63 // If existing files should be overridden.
64 protected $overwriteExistingFiles;
65 // VeriCode - a hash of server specific value and other things which
66 // identifies if a submission is OK. (see $BE_USER->veriCode())
67 protected $vC;
68 // the page where the user should be redirected after everything is done
69 protected $redirect;
70
71 // Internal, dynamic:
72 // File processor object
73 protected $fileProcessor;
74 // the result array from the file processor
75 protected $fileData;
76
77
78
79 /**
80 * Registering incoming data
81 *
82 * @return void
83 */
84 public function init() {
85 // set the GPvars from outside
86 $this->file = t3lib_div::_GP('file');
87 $this->CB = t3lib_div::_GP('CB');
88 $this->overwriteExistingFiles = t3lib_div::_GP('overwriteExistingFiles');
89 $this->vC = t3lib_div::_GP('vC');
90 $this->redirect = t3lib_div::_GP('redirect');
91
92 $this->initClipboard();
93 }
94
95 /**
96 * Initialize the Clipboard. This will fetch the data about files to paste/delete if such an action has been sent.
97 *
98 * @return void
99 */
100 public function initClipboard() {
101 if (is_array($this->CB)) {
102 $clipObj = t3lib_div::makeInstance('t3lib_clipboard');
103 $clipObj->initializeClipboard();
104 if ($this->CB['paste']) {
105 $clipObj->setCurrentPad($this->CB['pad']);
106 $this->file = $clipObj->makePasteCmdArray_file($this->CB['paste'], $this->file);
107 }
108 if ($this->CB['delete']) {
109 $clipObj->setCurrentPad($this->CB['pad']);
110 $this->file = $clipObj->makeDeleteCmdArray_file($this->file);
111 }
112 }
113 }
114
115 /**
116 * Performing the file admin action:
117 * Initializes the objects, setting permissions, sending data to object.
118 *
119 * @return void
120 */
121 public function main() {
122 // Initializing:
123 $this->fileProcessor = t3lib_div::makeInstance('t3lib_extFileFunctions');
124 $this->fileProcessor->init($GLOBALS['FILEMOUNTS'], $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']);
125 $this->fileProcessor->init_actionPerms($GLOBALS['BE_USER']->getFileoperationPermissions());
126 $this->fileProcessor->dontCheckForUnique = ($this->overwriteExistingFiles ? 1 : 0);
127
128 // Checking referer / executing:
129 $refInfo = parse_url(t3lib_div::getIndpEnv('HTTP_REFERER'));
130 $httpHost = t3lib_div::getIndpEnv('TYPO3_HOST_ONLY');
131 if ($httpHost != $refInfo['host']
132 && $this->vC != $GLOBALS['BE_USER']->veriCode()
133 && !$GLOBALS['TYPO3_CONF_VARS']['SYS']['doNotCheckReferer']
134 && $GLOBALS['CLIENT']['BROWSER'] != 'flash') {
135 $this->fileProcessor->writeLog(0, 2, 1, 'Referer host "%s" and server host "%s" did not match!', array($refInfo['host'], $httpHost));
136 } else {
137 $this->fileProcessor->start($this->file);
138 $this->fileData = $this->fileProcessor->processData();
139 }
140 }
141
142 /**
143 * Redirecting the user after the processing has been done.
144 * Might also display error messages directly, if any.
145 *
146 * @return void
147 */
148 public function finish() {
149 // Prints errors, if there are any
150 $this->fileProcessor->printLogErrorMessages($this->redirect);
151 t3lib_BEfunc::getSetUpdateSignal('updateFolderTree');
152 if ($this->redirect) {
153 header('Location: ' . t3lib_div::locationHeaderUrl($this->redirect));
154 }
155 }
156
157 /**
158 * Handles the actual process from within the ajaxExec function
159 * therefore, it does exactly the same as the real typo3/tce_file.php
160 * but without calling the "finish" method, thus makes it simpler to deal with the
161 * actual return value
162 *
163 *
164 * @param string $params always empty.
165 * @param string $ajaxObj The Ajax object used to return content and set content types
166 * @return void
167 */
168 public function processAjaxRequest(array $params, TYPO3AJAX $ajaxObj) {
169 $this->init();
170 $this->main();
171 $errors = $this->fileProcessor->getErrorMessages();
172 if (count($errors)) {
173 $ajaxObj->setError(implode(',', $errors));
174 } else {
175 $ajaxObj->addContent('result', $this->fileData);
176 if ($this->redirect) {
177 $ajaxObj->addContent('redirect', $this->redirect);
178 }
179 $ajaxObj->setContentFormat('json');
180 }
181 }
182 }
183
184 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/classes/class.typo3_tcefile.php']) {
185 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/classes/class.typo3_tcefile.php']);
186 }
187
188 ?>