Added $Id$ keywords, cleaned up comment tags
[Packages/TYPO3.CMS.git] / typo3 / tce_file.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2003 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 *
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 *
33 * For syntax and API information, see the document 'TYPO3 Core APIs'
34 *
35 * Revised for TYPO3 3.6 July/2003 by Kasper Skaarhoj
36 */
37 require ('init.php');
38 require ('template.php');
39 require_once (PATH_t3lib.'class.t3lib_basicfilefunc.php');
40 require_once (PATH_t3lib.'class.t3lib_extfilefunc.php');
41
42
43
44
45
46
47
48
49
50
51
52 /**
53 * Script Class, handling the calling of methods in the file admin classes.
54 *
55 * @author Kasper Skaarhoj <kasper@typo3.com>
56 * @package TYPO3
57 * @subpackage core
58 */
59 class SC_tce_file {
60 var $include_once=array();
61 var $CB;
62 var $file;
63 var $redirect;
64
65 /**
66 * Registering Incoming data
67 *
68 * @return void
69 */
70 function init() {
71 $this->file = t3lib_div::GPvar('file');
72 $this->redirect = t3lib_div::GPvar('redirect');
73
74 $this->CB = t3lib_div::GPvar('CB');
75 if (is_array($this->CB)) {
76 $this->include_once[]=PATH_t3lib.'class.t3lib_clipboard.php';
77 }
78 }
79
80 /**
81 * Initialize the Clipboard. This will fetch the data about files to paste/delete if such an action has been sent.
82 *
83 * @return void
84 */
85 function initClipboard() {
86 if (is_array($this->CB)) {
87 $clipObj = t3lib_div::makeInstance('t3lib_clipboard');
88 $clipObj->initializeClipboard();
89 if ($this->CB['paste']) {
90 $clipObj->setCurrentPad($this->CB['pad']);
91 $this->file = $clipObj->makePasteCmdArray_file($this->CB['paste'],$this->file);
92 }
93 if ($this->CB['delete']) {
94 $clipObj->setCurrentPad($this->CB['pad']);
95 $this->file = $clipObj->makeDeleteCmdArray_file($this->file);
96 }
97 }
98 }
99
100 /**
101 * Performing the file admin action:
102 * Initializes the objects, setting permissions, sending data to object.
103 *
104 * @return void
105 */
106 function main() {
107 global $FILEMOUNTS,$TYPO3_CONF_VARS,$BE_USER;
108
109 // *********************************
110 // Initializing
111 // *********************************
112 $fileProcessor = t3lib_div::makeInstance('t3lib_extFileFunctions');
113 $fileProcessor->init($FILEMOUNTS, $TYPO3_CONF_VARS['BE']['fileExtensions']);
114 $fileProcessor->init_actionPerms($BE_USER->user['fileoper_perms']);
115 $fileProcessor->dontCheckForUnique = t3lib_div::GPvar('overwriteExistingFiles') ? 1 : 0;
116
117 // ***************************
118 // Checking referer / executing
119 // ***************************
120 $refInfo=parse_url(t3lib_div::getIndpEnv('HTTP_REFERER'));
121 $httpHost = t3lib_div::getIndpEnv('TYPO3_HOST_ONLY');
122 if ($httpHost!=$refInfo['host'] && t3lib_div::GPvar('vC')!=$BE_USER->veriCode() && !$TYPO3_CONF_VARS['SYS']['doNotCheckReferer']) {
123 $fileProcessor->writeLog(0,2,1,'Referer host "%s" and server host "%s" did not match!',array($refInfo['host'],$httpHost));
124 } else {
125 $fileProcessor->start($this->file);
126 $fileProcessor->processData();
127 }
128
129 if (!$this->redirect) {
130 $this->redirect = 'status_file.php';
131 }
132 }
133
134 /**
135 * Redirecting to the status script for files.
136 *
137 * @return void
138 */
139 function finish() {
140 Header('Location: '.t3lib_div::locationHeaderUrl($this->redirect));
141
142 echo '
143 <script type="text/javascript">
144 if (confirm(\'System Error:\n\n Some error happend in tce_file.php. Continue?\')) {
145 document.location = \''.$this->redirect.'\';
146 }
147 </script>
148 ';
149 }
150 }
151
152 // Include extension?
153 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/tce_file.php']) {
154 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/tce_file.php']);
155 }
156
157
158
159
160
161
162
163
164
165
166
167
168 // Make instance:
169 $SOBE = t3lib_div::makeInstance('SC_tce_file');
170 $SOBE->init();
171
172 // Include files?
173 reset($SOBE->include_once);
174 while(list(,$INC_FILE)=each($SOBE->include_once)) {include_once($INC_FILE);}
175
176 $SOBE->initClipboard();
177 $SOBE->main();
178 $SOBE->finish();
179 ?>