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