[TASK] Each PHP statement must be on a line by itself
[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':
120 $this->icon = 'gfx/i/_icon_ftp_user.gif';
121 break;
122 case 'group':
123 $this->icon = 'gfx/i/_icon_ftp_group.gif';
124 break;
125 default:
126 $this->icon = 'gfx/i/_icon_ftp.gif';
127 }
128
129 $this->icon = '<img'.t3lib_iconWorks::skinImg($this->backPath,$this->icon,'width="18" height="16"').' title="" alt="" />';
130
131 // Relative path to filemount, $key:
132 $this->shortPath = substr($this->target,strlen($GLOBALS['FILEMOUNTS'][$key]['path']));
133
134 // Setting title:
135 $this->title = $this->icon.$GLOBALS['FILEMOUNTS'][$key]['name'].': '.$this->shortPath;
136
137 // ***************************
138 // Setting template object
139 // ***************************
140 $this->doc = t3lib_div::makeInstance('template');
141 $this->doc->setModuleTemplate('templates/file_edit.html');
142 $this->doc->backPath = $BACK_PATH;
143 $this->doc->JScode=$this->doc->wrapScriptTags('
144 function backToList() { //
145 top.goToModule("file_list");
146 }
147 ');
148 $this->doc->form='<form action="tce_file.php" method="post" name="editform">';
149 }
150
151 /**
152 * Main function, redering the actual content of the editing page
153 *
154 * @return void
155 */
156 function main() {
157 //TODO: change locallang*.php to locallang*.xml
158 $docHeaderButtons = $this->getButtons();
159
160 $this->content = $this->doc->startPage($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_edit.php.pagetitle'));
161
162 // hook before compiling the output
163 if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/file_edit.php']['preOutputProcessingHook'])) {
164 $preOutputProcessingHook =& $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/file_edit.php']['preOutputProcessingHook'];
165 if (is_array($preOutputProcessingHook)) {
166 $hookParameters = array(
167 'content' => &$this->content,
168 'target' => &$this->target,
169 );
170 foreach ($preOutputProcessingHook as $hookFunction) {
171 t3lib_div::callUserFunction($hookFunction, $hookParameters, $this);
172 }
173 }
174 }
175
176 $pageContent = $this->doc->header($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_edit.php.pagetitle'));
177 $pageContent .= $this->doc->spacer(2);
178
179 $fI = pathinfo($this->target);
180 $extList = $GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'];
181
182 if ($extList && t3lib_div::inList($extList,strtolower($fI['extension']))) {
183 // Read file content to edit:
184 $fileContent = t3lib_div::getUrl($this->target);
185
186 // making the formfields
187 $hValue = 'file_edit.php?target='.rawurlencode($this->origTarget).'&returnUrl='.rawurlencode($this->returnUrl);
188
189 // Edit textarea:
190 $code.='
191 <div id="c-edit">
192 <textarea rows="30" name="file[editfile][0][data]" wrap="off"'.$this->doc->formWidthText(48,'width:98%;height:80%','off').' class="fixed-font enable-tab">'.
193 t3lib_div::formatForTextarea($fileContent).
194 '</textarea>
195 <input type="hidden" name="file[editfile][0][target]" value="'.$this->target.'" />
196 <input type="hidden" name="redirect" value="'.htmlspecialchars($hValue).'" />
197 </div>
198 <br />';
199
200 // Make shortcut:
201 if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
202 $this->MCONF['name']='xMOD_file_edit.php';
203 $docHeaderButtons['shortcut'] = $this->doc->makeShortcutIcon('target','',$this->MCONF['name'],1);
204 }
205 } else {
206 $code .= sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_edit.php.coundNot'), $extList);
207 }
208
209 // Ending of section and outputting editing form:
210 $pageContent.= $this->doc->sectionEnd();
211 $pageContent.=$code;
212
213 // hook after compiling the output
214 if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/file_edit.php']['postOutputProcessingHook'])) {
215 $postOutputProcessingHook =& $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/file_edit.php']['postOutputProcessingHook'];
216 if (is_array($postOutputProcessingHook)) {
217 $hookParameters = array(
218 'pageContent' => &$pageContent,
219 'target' => &$this->target,
220 );
221 foreach ($postOutputProcessingHook as $hookFunction) {
222 t3lib_div::callUserFunction($hookFunction, $hookParameters, $this);
223 }
224 }
225 }
226
227 // Add the HTML as a section:
228 $markerArray = array(
229 'CSH' => $docHeaderButtons['csh'],
230 'FUNC_MENU' => t3lib_BEfunc::getFuncMenu($this->id, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']),
231 'BUTTONS' => $docHeaderButtons,
232 'PATH' => $this->title,
233 'CONTENT' => $pageContent,
234 );
235
236 $this->content.= $this->doc->moduleBody(array(), $docHeaderButtons, $markerArray);
237 $this->content.= $this->doc->endPage();
238 $this->content = $this->doc->insertStylesAndJS($this->content);
239
240
241 }
242
243 /**
244 * Outputting the accumulated content to screen
245 *
246 * @return void
247 */
248 function printContent() {
249 echo $this->content;
250 }
251
252 /**
253 * Builds the buttons for the docheader and returns them as an array
254 *
255 * @return array
256 **/
257 function getButtons() {
258
259 $buttons = array();
260
261 // CSH button
262 $buttons['csh'] = t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'file_edit', $GLOBALS['BACK_PATH'], '', TRUE);
263
264 // Save button
265 $theIcon = t3lib_iconWorks::getSpriteIcon('actions-document-save');
266 $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>';
267
268 // Save and Close button
269 $theIcon = t3lib_iconWorks::getSpriteIcon('actions-document-save-close');
270 $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>';
271
272 // Cancel button
273 $theIcon = t3lib_iconWorks::getSpriteIcon('actions-document-close');
274 $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>';
275
276 return $buttons;
277 }
278 }
279
280
281 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/file_edit.php'])) {
282 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/file_edit.php']);
283 }
284
285
286
287 // Make instance:
288 $SOBE = t3lib_div::makeInstance('SC_file_edit');
289 $SOBE->init();
290 $SOBE->main();
291 $SOBE->printContent();
292
293 ?>