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