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