[BUGFIX] Warning in list module
[Packages/TYPO3.CMS.git] / typo3 / file_edit.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2011 Kasper Skårhøj (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 * Web>File: Editing documents
29 *
30 * $Id$
31 * Revised for TYPO3 3.6 2/2003 by Kasper Skårhøj
32 * XHTML compliant (except textarea field)
33 *
34 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
35 */
36 /**
37 * [CLASS/FUNCTION INDEX of SCRIPT]
38 *
39 *
40 *
41 * 74: class SC_file_edit
42 * 93: function init()
43 * 143: function main()
44 * 205: 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
55
56 /**
57 * Script Class for rendering the file editing screen
58 *
59 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
60 * @package TYPO3
61 * @subpackage core
62 */
63 class SC_file_edit {
64 var $content; // Module content accumulated.
65
66 /**
67 * File processing object
68 *
69 * @var t3lib_basicFileFunctions
70 */
71 var $basicff;
72 var $shortPath;
73 var $title;
74 var $icon;
75
76 /**
77 * Document template object
78 *
79 * @var template
80 */
81 var $doc;
82
83 // Internal, static: GPvar
84 var $origTarget; // Original input target
85 var $target; // The original target, but validated.
86 var $returnUrl; // Return URL of list module.
87
88
89 /**
90 * Initialize script class
91 *
92 * @return void
93 */
94 function init() {
95 //TODO remove global
96 global $BACK_PATH,$TYPO3_CONF_VARS;
97
98 // Setting target, which must be a file reference to a file within the mounts.
99 $this->target = $this->origTarget = t3lib_div::_GP('target');
100 $this->returnUrl = t3lib_div::sanitizeLocalUrl(t3lib_div::_GP('returnUrl'));
101
102 // Creating file management object:
103 $this->basicff = t3lib_div::makeInstance('t3lib_basicFileFunctions');
104 $this->basicff->init($GLOBALS['FILEMOUNTS'],$TYPO3_CONF_VARS['BE']['fileExtensions']);
105
106
107 if (file_exists($this->target)) {
108 $this->target=$this->basicff->cleanDirectoryName($this->target); // Cleaning and checking target (file or dir)
109 } else {
110 $this->target='';
111 }
112 $key=$this->basicff->checkPathAgainstMounts($this->target.'/');
113 if (!$this->target || !$key) {
114 $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:paramError', TRUE);
115 $message = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:targetNoDir', TRUE);
116 throw new RuntimeException($title . ': ' . $message);
117 }
118 // Finding the icon
119 switch($GLOBALS['FILEMOUNTS'][$key]['type']) {
120 case 'user': $this->icon = 'gfx/i/_icon_ftp_user.gif'; break;
121 case 'group': $this->icon = 'gfx/i/_icon_ftp_group.gif'; break;
122 default: $this->icon = 'gfx/i/_icon_ftp.gif'; break;
123 }
124
125 $this->icon = '<img'.t3lib_iconWorks::skinImg($this->backPath,$this->icon,'width="18" height="16"').' title="" alt="" />';
126
127 // Relative path to filemount, $key:
128 $this->shortPath = substr($this->target,strlen($GLOBALS['FILEMOUNTS'][$key]['path']));
129
130 // Setting title:
131 $this->title = $this->icon.$GLOBALS['FILEMOUNTS'][$key]['name'].': '.$this->shortPath;
132
133 // ***************************
134 // Setting template object
135 // ***************************
136 $this->doc = t3lib_div::makeInstance('template');
137 $this->doc->setModuleTemplate('templates/file_edit.html');
138 $this->doc->backPath = $BACK_PATH;
139 $this->doc->JScode=$this->doc->wrapScriptTags('
140 function backToList() { //
141 top.goToModule("file_list");
142 }
143 ');
144 $this->doc->form='<form action="tce_file.php" method="post" name="editform">';
145 }
146
147 /**
148 * Main function, redering the actual content of the editing page
149 *
150 * @return void
151 */
152 function main() {
153 //TODO remove global, change $LANG into $GLOBALS['LANG'], change locallang*.php to locallang*.xml
154 global $BE_USER, $LANG, $TYPO3_CONF_VARS;
155 $docHeaderButtons = $this->getButtons();
156
157 $this->content = $this->doc->startPage($LANG->sL('LLL:EXT:lang/locallang_core.php:file_edit.php.pagetitle'));
158
159 // hook before compiling the output
160 if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/file_edit.php']['preOutputProcessingHook'])) {
161 $preOutputProcessingHook =& $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/file_edit.php']['preOutputProcessingHook'];
162 if (is_array($preOutputProcessingHook)) {
163 $hookParameters = array(
164 'content' => &$this->content,
165 'target' => &$this->target,
166 );
167 foreach ($preOutputProcessingHook as $hookFunction) {
168 t3lib_div::callUserFunction($hookFunction, $hookParameters, $this);
169 }
170 }
171 }
172
173 $pageContent = $this->doc->header($LANG->sL('LLL:EXT:lang/locallang_core.php:file_edit.php.pagetitle'));
174 $pageContent .= $this->doc->spacer(2);
175
176 $fI = pathinfo($this->target);
177 $extList=$TYPO3_CONF_VARS['SYS']['textfile_ext'];
178
179 if ($extList && t3lib_div::inList($extList,strtolower($fI['extension']))) {
180 // Read file content to edit:
181 $fileContent = t3lib_div::getUrl($this->target);
182
183 // making the formfields
184 $hValue = 'file_edit.php?target='.rawurlencode($this->origTarget).'&returnUrl='.rawurlencode($this->returnUrl);
185
186 // Edit textarea:
187 $code.='
188 <div id="c-edit">
189 <textarea rows="30" name="file[editfile][0][data]" wrap="off"'.$this->doc->formWidthText(48,'width:98%;height:80%','off').' class="fixed-font enable-tab">'.
190 t3lib_div::formatForTextarea($fileContent).
191 '</textarea>
192 <input type="hidden" name="file[editfile][0][target]" value="'.$this->target.'" />
193 <input type="hidden" name="redirect" value="'.htmlspecialchars($hValue).'" />
194 </div>
195 <br />';
196
197 // Make shortcut:
198 if ($BE_USER->mayMakeShortcut()) {
199 $this->MCONF['name']='xMOD_file_edit.php';
200 $docHeaderButtons['shortcut'] = $this->doc->makeShortcutIcon('target','',$this->MCONF['name'],1);
201 } else {
202 $docHeaderButtons['shortcut'] = '';
203 }
204 } else {
205 $code.=sprintf($LANG->sL('LLL:EXT:lang/locallang_core.php:file_edit.php.coundNot'), $extList);
206 }
207
208 // Ending of section and outputting editing form:
209 $pageContent.= $this->doc->sectionEnd();
210 $pageContent.=$code;
211
212 // hook after compiling the output
213 if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/file_edit.php']['postOutputProcessingHook'])) {
214 $postOutputProcessingHook =& $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/file_edit.php']['postOutputProcessingHook'];
215 if (is_array($postOutputProcessingHook)) {
216 $hookParameters = array(
217 'pageContent' => &$pageContent,
218 'target' => &$this->target,
219 );
220 foreach ($postOutputProcessingHook as $hookFunction) {
221 t3lib_div::callUserFunction($hookFunction, $hookParameters, $this);
222 }
223 }
224 }
225
226 // Add the HTML as a section:
227 $markerArray = array(
228 'CSH' => $docHeaderButtons['csh'],
229 'FUNC_MENU' => t3lib_BEfunc::getFuncMenu($this->id, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']),
230 'BUTTONS' => $docHeaderButtons,
231 'PATH' => $this->title,
232 'CONTENT' => $pageContent,
233 );
234
235 $this->content.= $this->doc->moduleBody(array(), $docHeaderButtons, $markerArray);
236 $this->content.= $this->doc->endPage();
237 $this->content = $this->doc->insertStylesAndJS($this->content);
238
239
240 }
241
242 /**
243 * Outputting the accumulated content to screen
244 *
245 * @return void
246 */
247 function printContent() {
248 echo $this->content;
249 }
250
251 /**
252 * Builds the buttons for the docheader and returns them as an array
253 *
254 * @return array
255 **/
256 function getButtons() {
257
258 $buttons = array();
259
260 // CSH button
261 $buttons['csh'] = t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'file_edit', $GLOBALS['BACK_PATH'], '', TRUE);
262
263 // Save button
264 $theIcon = t3lib_iconWorks::getSpriteIcon('actions-document-save');
265 $buttons['SAVE'] = '<a href="#" onclick="document.editform.submit();" title="'.$GLOBALS['LANG']->makeEntities($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_edit.php.submit', TRUE)).'">' . $theIcon . '</a>';
266
267 // Save and Close button
268 $theIcon = t3lib_iconWorks::getSpriteIcon('actions-document-save-close');
269 $buttons['SAVE_CLOSE'] = '<a href="#" onclick="document.editform.redirect.value=\''.htmlspecialchars($this->returnUrl).'\'; document.editform.submit();" title="'.$GLOBALS['LANG']->makeEntities($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_edit.php.saveAndClose', TRUE)).'">' . $theIcon . '</a>';
270
271 // Cancel button
272 $theIcon = t3lib_iconWorks::getSpriteIcon('actions-document-close');
273 $buttons['CANCEL'] = '<a href="#" onclick="backToList(); return false;" title="' . $GLOBALS['LANG']->makeEntities($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.cancel', TRUE)) . '">' . $theIcon . '</a>';
274
275 return $buttons;
276 }
277 }
278
279
280 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/file_edit.php'])) {
281 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/file_edit.php']);
282 }
283
284
285
286 // Make instance:
287 $SOBE = t3lib_div::makeInstance('SC_file_edit');
288 $SOBE->init();
289 $SOBE->main();
290 $SOBE->printContent();
291
292 ?>