* Fixed various things in file processing, t3lib_extFileFunc et al.
[Packages/TYPO3.CMS.git] / typo3 / tce_file.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2004 Kasper Skaarhoj (kasper@typo3.com)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Gateway for TCE (TYPO3 Core Engine) file-handling through POST forms.
29 * This script serves as the fileadministration part of the TYPO3 Core Engine.
30 * Basically it includes two libraries which are used to manipulate files on the server.
31 *
32 * For syntax and API information, see the document 'TYPO3 Core APIs'
33 *
34 * $Id$
35 * Revised for TYPO3 3.6 July/2003 by Kasper Skaarhoj
36 *
37 * @author Kasper Skaarhoj <kasper@typo3.com>
38 */
39 /**
40 * [CLASS/FUNCTION INDEX of SCRIPT]
41 *
42 *
43 *
44 * 76: class SC_tce_file
45 * 96: function init()
46 * 116: function initClipboard()
47 * 137: function main()
48 *
49 * TOTAL FUNCTIONS: 3
50 * (This index is automatically created/updated by the extension "extdeveval")
51 *
52 */
53
54 require ('init.php');
55 require ('template.php');
56 require_once (PATH_t3lib.'class.t3lib_basicfilefunc.php');
57 require_once (PATH_t3lib.'class.t3lib_extfilefunc.php');
58
59
60
61
62
63
64
65
66
67
68
69 /**
70 * Script Class, handling the calling of methods in the file admin classes.
71 *
72 * @author Kasper Skaarhoj <kasper@typo3.com>
73 * @package TYPO3
74 * @subpackage core
75 */
76 class SC_tce_file {
77
78 // Internal, static: GPvar:
79 var $file; // Array of file-operations.
80 var $redirect; // Redirect URL
81 var $CB; // Clipboard operations array
82 var $overwriteExistingFiles; // If existing files should be overridden.
83 var $vC; // VeriCode - a hash of server specific value and other things which identifies if a submission is OK. (see $BE_USER->veriCode())
84
85 // Internal, dynamic:
86 var $include_once=array(); // Used to set the classes to include after the init() function is called.
87 var $fileProcessor; // File processor object
88
89
90
91 /**
92 * Registering Incoming data
93 *
94 * @return void
95 */
96 function init() {
97
98 // GPvars:
99 $this->file = t3lib_div::_GP('file');
100 $this->redirect = t3lib_div::_GP('redirect');
101 $this->CB = t3lib_div::_GP('CB');
102 $this->overwriteExistingFiles = t3lib_div::_GP('overwriteExistingFiles');
103 $this->vC = t3lib_div::_GP('vC');
104
105 // If clipboard is set, then include the clipboard class:
106 if (is_array($this->CB)) {
107 $this->include_once[] = PATH_t3lib.'class.t3lib_clipboard.php';
108 }
109 }
110
111 /**
112 * Initialize the Clipboard. This will fetch the data about files to paste/delete if such an action has been sent.
113 *
114 * @return void
115 */
116 function initClipboard() {
117 if (is_array($this->CB)) {
118 $clipObj = t3lib_div::makeInstance('t3lib_clipboard');
119 $clipObj->initializeClipboard();
120 if ($this->CB['paste']) {
121 $clipObj->setCurrentPad($this->CB['pad']);
122 $this->file = $clipObj->makePasteCmdArray_file($this->CB['paste'],$this->file);
123 }
124 if ($this->CB['delete']) {
125 $clipObj->setCurrentPad($this->CB['pad']);
126 $this->file = $clipObj->makeDeleteCmdArray_file($this->file);
127 }
128 }
129 }
130
131 /**
132 * Performing the file admin action:
133 * Initializes the objects, setting permissions, sending data to object.
134 *
135 * @return void
136 */
137 function main() {
138 global $FILEMOUNTS,$TYPO3_CONF_VARS,$BE_USER;
139
140 // Initializing:
141 $this->fileProcessor = t3lib_div::makeInstance('t3lib_extFileFunctions');
142 $this->fileProcessor->init($FILEMOUNTS, $TYPO3_CONF_VARS['BE']['fileExtensions']);
143 $this->fileProcessor->init_actionPerms($BE_USER->user['fileoper_perms']);
144 $this->fileProcessor->dontCheckForUnique = $this->overwriteExistingFiles ? 1 : 0;
145
146 // Checking referer / executing:
147 $refInfo = parse_url(t3lib_div::getIndpEnv('HTTP_REFERER'));
148 $httpHost = t3lib_div::getIndpEnv('TYPO3_HOST_ONLY');
149 if ($httpHost!=$refInfo['host'] && $this->vC!=$BE_USER->veriCode() && !$TYPO3_CONF_VARS['SYS']['doNotCheckReferer']) {
150 $this->fileProcessor->writeLog(0,2,1,'Referer host "%s" and server host "%s" did not match!',array($refInfo['host'],$httpHost));
151 } else {
152 $this->fileProcessor->start($this->file);
153 $this->fileProcessor->processData();
154 }
155 }
156
157 /**
158 * Redirecting the user after the processing has been done.
159 * Might also display error messages directly, if any.
160 *
161 * @return void
162 */
163 function finish() {
164 // Prints errors, if...
165 $this->fileProcessor->printLogErrorMessages($this->redirect);
166
167 t3lib_BEfunc::getSetUpdateSignal('updateFolderTree');
168 if ($this->redirect) {
169 Header('Location: '.t3lib_div::locationHeaderUrl($this->redirect));
170 }
171 }
172 }
173
174 // Include extension?
175 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/tce_file.php']) {
176 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/tce_file.php']);
177 }
178
179
180
181
182
183
184
185
186
187
188
189
190 // Make instance:
191 $SOBE = t3lib_div::makeInstance('SC_tce_file');
192 $SOBE->init();
193
194 // Include files?
195 foreach($SOBE->include_once as $INC_FILE) include_once($INC_FILE);
196
197 $SOBE->initClipboard();
198 $SOBE->main();
199 $SOBE->finish();
200 ?>