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