Updated Copyright notices
[Packages/TYPO3.CMS.git] / typo3 / tce_file.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2008 Kasper Skaarhoj (kasperYYYY@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 <kasperYYYY@typo3.com>
38 */
39 /**
40 * [CLASS/FUNCTION INDEX of SCRIPT]
41 *
42 *
43 *
44 * 77: class SC_tce_file
45 * 97: function init()
46 * 117: function initClipboard()
47 * 138: function main()
48 * 164: function finish()
49 *
50 * TOTAL FUNCTIONS: 4
51 * (This index is automatically created/updated by the extension "extdeveval")
52 *
53 */
54
55 require ('init.php');
56 require ('template.php');
57 require_once (PATH_t3lib.'class.t3lib_basicfilefunc.php');
58 require_once (PATH_t3lib.'class.t3lib_extfilefunc.php');
59
60
61
62
63
64
65
66
67
68
69
70 /**
71 * Script Class, handling the calling of methods in the file admin classes.
72 *
73 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
74 * @package TYPO3
75 * @subpackage core
76 */
77 class SC_tce_file {
78
79 // Internal, static: GPvar:
80 var $file; // Array of file-operations.
81 var $redirect; // Redirect URL
82 var $CB; // Clipboard operations array
83 var $overwriteExistingFiles; // If existing files should be overridden.
84 var $vC; // VeriCode - a hash of server specific value and other things which identifies if a submission is OK. (see $BE_USER->veriCode())
85
86 // Internal, dynamic:
87 var $include_once=array(); // Used to set the classes to include after the init() function is called.
88 var $fileProcessor; // File processor object
89
90
91
92 /**
93 * Registering Incoming data
94 *
95 * @return void
96 */
97 function init() {
98
99 // GPvars:
100 $this->file = t3lib_div::_GP('file');
101 $this->redirect = t3lib_div::_GP('redirect');
102 $this->CB = t3lib_div::_GP('CB');
103 $this->overwriteExistingFiles = t3lib_div::_GP('overwriteExistingFiles');
104 $this->vC = t3lib_div::_GP('vC');
105
106 // If clipboard is set, then include the clipboard class:
107 if (is_array($this->CB)) {
108 $this->include_once[] = PATH_t3lib.'class.t3lib_clipboard.php';
109 }
110 }
111
112 /**
113 * Initialize the Clipboard. This will fetch the data about files to paste/delete if such an action has been sent.
114 *
115 * @return void
116 */
117 function initClipboard() {
118 if (is_array($this->CB)) {
119 $clipObj = t3lib_div::makeInstance('t3lib_clipboard');
120 $clipObj->initializeClipboard();
121 if ($this->CB['paste']) {
122 $clipObj->setCurrentPad($this->CB['pad']);
123 $this->file = $clipObj->makePasteCmdArray_file($this->CB['paste'],$this->file);
124 }
125 if ($this->CB['delete']) {
126 $clipObj->setCurrentPad($this->CB['pad']);
127 $this->file = $clipObj->makeDeleteCmdArray_file($this->file);
128 }
129 }
130 }
131
132 /**
133 * Performing the file admin action:
134 * Initializes the objects, setting permissions, sending data to object.
135 *
136 * @return void
137 */
138 function main() {
139 global $FILEMOUNTS,$TYPO3_CONF_VARS,$BE_USER;
140
141 // Initializing:
142 $this->fileProcessor = t3lib_div::makeInstance('t3lib_extFileFunctions');
143 $this->fileProcessor->init($FILEMOUNTS, $TYPO3_CONF_VARS['BE']['fileExtensions']);
144 $this->fileProcessor->init_actionPerms($BE_USER->user['fileoper_perms']);
145 $this->fileProcessor->dontCheckForUnique = $this->overwriteExistingFiles ? 1 : 0;
146
147 // Checking referer / executing:
148 $refInfo = parse_url(t3lib_div::getIndpEnv('HTTP_REFERER'));
149 $httpHost = t3lib_div::getIndpEnv('TYPO3_HOST_ONLY');
150 if ($httpHost!=$refInfo['host'] && $this->vC!=$BE_USER->veriCode() && !$TYPO3_CONF_VARS['SYS']['doNotCheckReferer']) {
151 $this->fileProcessor->writeLog(0,2,1,'Referer host "%s" and server host "%s" did not match!',array($refInfo['host'],$httpHost));
152 } else {
153 $this->fileProcessor->start($this->file);
154 $this->fileProcessor->processData();
155 }
156 }
157
158 /**
159 * Redirecting the user after the processing has been done.
160 * Might also display error messages directly, if any.
161 *
162 * @return void
163 */
164 function finish() {
165 // Prints errors, if...
166 $this->fileProcessor->printLogErrorMessages($this->redirect);
167
168 t3lib_BEfunc::getSetUpdateSignal('updateFolderTree');
169 if ($this->redirect) {
170 Header('Location: '.t3lib_div::locationHeaderUrl($this->redirect));
171 }
172 }
173 }
174
175 // Include extension?
176 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/tce_file.php']) {
177 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/tce_file.php']);
178 }
179
180
181
182
183
184
185
186
187
188
189
190
191 // Make instance:
192 $SOBE = t3lib_div::makeInstance('SC_tce_file');
193 $SOBE->init();
194
195 // Include files?
196 foreach($SOBE->include_once as $INC_FILE) include_once($INC_FILE);
197
198 $SOBE->initClipboard();
199 $SOBE->main();
200 $SOBE->finish();
201 ?>