Updated copyright notices to show "2004"
[Packages/TYPO3.CMS.git] / typo3 / file_edit.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 * Web>File: Editing documents
29 *
30 * $Id$
31 * Revised for TYPO3 3.6 2/2003 by Kasper Skaarhoj
32 * XHTML compliant (except textarea field)
33 *
34 * @author Kasper Skaarhoj <kasper@typo3.com>
35 */
36 /**
37 * [CLASS/FUNCTION INDEX of SCRIPT]
38 *
39 *
40 *
41 * 74: class SC_file_edit
42 * 92: function init()
43 * 141: function main()
44 * 201: function printContent()
45 *
46 * TOTAL FUNCTIONS: 3
47 * (This index is automatically created/updated by the extension "extdeveval")
48 *
49 */
50
51 $BACK_PATH='';
52 require ('init.php');
53 require ('template.php');
54 require_once (PATH_t3lib.'class.t3lib_basicfilefunc.php');
55
56
57
58
59
60
61
62
63
64
65
66
67 /**
68 * Script Class for rendering the file editing screen
69 *
70 * @author Kasper Skaarhoj <kasper@typo3.com>
71 * @package TYPO3
72 * @subpackage core
73 */
74 class SC_file_edit {
75 var $content; // Module content accumulated.
76 var $basicff; // File processing object loaded here.
77 var $shortPath;
78 var $title;
79 var $icon;
80 var $doc; // Document template object
81
82 // Internal, static: GPvar
83 var $origTarget; // Original input target
84 var $target; // The original target, but validated.
85
86
87 /**
88 * Initialize script class
89 *
90 * @return void
91 */
92 function init() {
93 global $BACK_PATH,$TYPO3_CONF_VARS;
94
95 // Setting target, which must be a file reference to a file within the mounts.
96 $this->target = $this->origTarget = t3lib_div::GPvar('target');
97
98 // Creating file management object:
99 $this->basicff = t3lib_div::makeInstance('t3lib_basicFileFunctions');
100 $this->basicff->init($GLOBALS['FILEMOUNTS'],$TYPO3_CONF_VARS['BE']['fileExtensions']);
101
102
103 if (@file_exists($this->target)) {
104 $this->target=$this->basicff->cleanDirectoryName($this->target); // Cleaning and checking target (file or dir)
105 } else {
106 $this->target='';
107 }
108 $key=$this->basicff->checkPathAgainstMounts($this->target.'/');
109 if (!$this->target || !$key) {
110 t3lib_BEfunc::typo3PrintError ('Parameter Error','Target was not a directory!','');
111 exit;
112 }
113 // Finding the icon
114 switch($GLOBALS['FILEMOUNTS'][$key]['type']) {
115 case 'user': $this->icon = 'gfx/i/_icon_ftp_user.gif'; break;
116 case 'group': $this->icon = 'gfx/i/_icon_ftp_group.gif'; break;
117 default: $this->icon = 'gfx/i/_icon_ftp.gif'; break;
118 }
119 $this->shortPath = substr($this->target,strlen($GLOBALS['FILEMOUNTS'][$key]['path']));
120 $this->title = $GLOBALS['FILEMOUNTS'][$key]['name'].': '.$this->shortPath;
121
122 // ***************************
123 // Setting template object
124 // ***************************
125 $this->doc = t3lib_div::makeInstance('template');
126 $this->doc->docType = 'xhtml_trans';
127 $this->doc->backPath = $BACK_PATH;
128 $this->doc->JScode=$this->doc->wrapScriptTags('
129 function backToList() { //
130 top.goToModule("file_list");
131 }
132 ');
133 $this->doc->form='<form action="tce_file.php" method="post" name="editform">';
134 }
135
136 /**
137 * Main function, redering the actual content of the editing page
138 *
139 * @return void
140 */
141 function main() {
142 global $BE_USER, $LANG, $TYPO3_CONF_VARS;
143
144 $this->content='';
145 $this->content.=$this->doc->startPage($LANG->sL('LLL:EXT:lang/locallang_core.php:file_edit.php.pagetitle'));
146 $this->content.=$this->doc->header($LANG->sL('LLL:EXT:lang/locallang_core.php:file_edit.php.pagetitle'));
147 $this->content.=$this->doc->spacer(5);
148 $this->content.=$this->doc->section('',$this->doc->getFileheader($this->title,$this->shortPath,$this->icon));
149 $this->content.=$this->doc->divider(5);
150
151 $fI = pathinfo($this->target);
152 $extList=$TYPO3_CONF_VARS['SYS']['textfile_ext'];
153
154 if ($extList && t3lib_div::inList($extList,strtolower($fI['extension']))) {
155 // Read file content to edit:
156 $fileContent = t3lib_div::getUrl($this->target);
157
158 // making the formfields
159 $hValue = 'file_edit.php?target='.rawurlencode($this->origTarget);
160 $code='';
161 $code.='
162 <div id="c-submit">
163 <input type="hidden" name="redirect" value="'.htmlspecialchars($hValue).'" />
164 <input type="submit" value="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:file_edit.php.submit',1).'" />
165 <input type="submit" value="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:file_edit.php.saveAndClose',1).'" onclick="document.editform.redirect.value=\'\';" />
166 <input type="submit" value="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:labels.cancel',1).'" onclick="backToList(); return false;" />
167 </div>
168 ';
169
170 // Edit textarea:
171 $code.='
172 <div id="c-edit">
173 <textarea rows="30" name="file[editfile][0][data]" wrap="off"'.$this->doc->formWidthText(48,'width:98%;height:80%','off').'>'.
174 t3lib_div::formatForTextarea($fileContent).
175 '</textarea>
176 <input type="hidden" name="file[editfile][0][target]" value="'.$this->target.'" />
177 </div>
178 <br />';
179
180 // Make shortcut:
181 if ($BE_USER->mayMakeShortcut()) {
182 $this->MCONF['name']='xMOD_file_edit.php';
183 $code.= '<br />'.$this->doc->makeShortcutIcon('target','',$this->MCONF['name'],1);
184 }
185 } else {
186 $code.=sprintf($LANG->sL('LLL:EXT:lang/locallang_core.php:file_edit.php.coundNot'), $extList);
187 }
188
189 // Ending of section and outputting editing form:
190 $this->content.= $this->doc->sectionEnd();
191 $this->content.=$code;
192
193 $this->content.=$this->doc->endPage();
194 }
195
196 /**
197 * Outputting the accumulated content to screen
198 *
199 * @return void
200 */
201 function printContent() {
202 echo $this->content;
203 }
204 }
205
206 // Include extension?
207 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/file_edit.php']) {
208 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/file_edit.php']);
209 }
210
211
212
213
214
215
216
217
218
219
220
221
222 // Make instance:
223 $SOBE = t3lib_div::makeInstance('SC_file_edit');
224 $SOBE->init();
225 $SOBE->main();
226 $SOBE->printContent();
227 ?>