[TASK] Whitespace CGL
[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 $GLOBALS['BACK_PATH'] = '';
37 require('init.php');
38 require('template.php');
39
40
41 /**
42 * Script Class for rendering the file editing screen
43 *
44 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
45 * @package TYPO3
46 * @subpackage core
47 */
48 class SC_file_edit {
49 var $content; // Module content accumulated.
50
51 var $title;
52
53 /**
54 * Document template object
55 *
56 * @var template
57 */
58 var $doc;
59
60 // Internal, static: GPvar
61 var $origTarget; // Original input target
62 var $target; // The original target, but validated.
63 var $returnUrl; // Return URL of list module.
64
65 /**
66 * the file that is being edited on
67 *
68 * @var t3lib_file_AbstractFile
69 */
70 protected $fileObject;
71
72 /**
73 * Initialize script class
74 *
75 * @return void
76 */
77 function init() {
78 // Setting target, which must be a file reference to a file within the mounts.
79 $this->target = $this->origTarget = $fileIdentifier = t3lib_div::_GP('target');
80 $this->returnUrl = t3lib_div::sanitizeLocalUrl(t3lib_div::_GP('returnUrl'));
81
82 // create the file object
83 if ($fileIdentifier) {
84 $this->fileObject = t3lib_file_Factory::getInstance()->retrieveFileOrFolderObject($fileIdentifier);
85 }
86
87 // Cleaning and checking target directory
88 if (!$this->fileObject) {
89 $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:paramError', TRUE);
90 $message = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:targetNoDir', TRUE);
91 throw new RuntimeException($title . ': ' . $message, 1294586841);
92 }
93
94 // Setting the title and the icon
95 $icon = t3lib_iconWorks::getSpriteIcon('apps-filetree-root');
96 $this->title = $icon . htmlspecialchars($this->fileObject->getStorage()->getName()) . ': ' . htmlspecialchars($this->fileObject->getIdentifier());
97
98 // ***************************
99 // Setting template object
100 // ***************************
101 $this->doc = t3lib_div::makeInstance('template');
102 $this->doc->setModuleTemplate('templates/file_edit.html');
103 $this->doc->backPath = $GLOBALS['BACK_PATH'];
104 $this->doc->JScode=$this->doc->wrapScriptTags('
105 function backToList() { //
106 top.goToModule("file_list");
107 }
108 ');
109 $this->doc->form='<form action="tce_file.php" method="post" name="editform">';
110 }
111
112 /**
113 * Main function, redering the actual content of the editing page
114 *
115 * @return void
116 */
117 function main() {
118 //TODO: change locallang*.php to locallang*.xml
119 $docHeaderButtons = $this->getButtons();
120
121 $this->content = $this->doc->startPage($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_edit.php.pagetitle'));
122
123 // hook before compiling the output
124 if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/file_edit.php']['preOutputProcessingHook'])) {
125 $preOutputProcessingHook =& $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/file_edit.php']['preOutputProcessingHook'];
126 if (is_array($preOutputProcessingHook)) {
127 $hookParameters = array(
128 'content' => &$this->content,
129 'target' => &$this->target,
130 );
131 foreach ($preOutputProcessingHook as $hookFunction) {
132 t3lib_div::callUserFunction($hookFunction, $hookParameters, $this);
133 }
134 }
135 }
136
137 $pageContent = $this->doc->header($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_edit.php.pagetitle') . ' ' . htmlspecialchars($this->fileObject->getName()));
138 $pageContent .= $this->doc->spacer(2);
139
140 $code = '';
141
142 $extList = $GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'];
143 if ($extList && t3lib_div::inList($extList, $this->fileObject->getExtension())) {
144 // Read file content to edit:
145 $fileContent = $this->fileObject->getContents();
146
147 // making the formfields
148 $hValue = 'file_edit.php?target='.rawurlencode($this->origTarget).'&returnUrl='.rawurlencode($this->returnUrl);
149
150 // Edit textarea:
151 $code.='
152 <div id="c-edit">
153 <textarea rows="30" name="file[editfile][0][data]" wrap="off"'.$this->doc->formWidthText(48,'width:98%;height:80%','off').' class="fixed-font enable-tab">'.
154 t3lib_div::formatForTextarea($fileContent).
155 '</textarea>
156 <input type="hidden" name="file[editfile][0][target]" value="' . $this->fileObject->getUid() . '" />
157 <input type="hidden" name="redirect" value="'.htmlspecialchars($hValue).'" />
158 </div>
159 <br />';
160
161 // Make shortcut:
162 if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
163 $this->MCONF['name']='xMOD_file_edit.php';
164 $docHeaderButtons['shortcut'] = $this->doc->makeShortcutIcon('target','',$this->MCONF['name'],1);
165 } else {
166 $docHeaderButtons['shortcut'] = '';
167 }
168 } else {
169 $code .= sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_edit.php.coundNot'), $extList);
170 }
171
172 // Ending of section and outputting editing form:
173 $pageContent.= $this->doc->sectionEnd();
174 $pageContent.=$code;
175
176 // hook after compiling the output
177 if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/file_edit.php']['postOutputProcessingHook'])) {
178 $postOutputProcessingHook =& $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/file_edit.php']['postOutputProcessingHook'];
179 if (is_array($postOutputProcessingHook)) {
180 $hookParameters = array(
181 'pageContent' => &$pageContent,
182 'target' => &$this->target,
183 );
184 foreach ($postOutputProcessingHook as $hookFunction) {
185 t3lib_div::callUserFunction($hookFunction, $hookParameters, $this);
186 }
187 }
188 }
189
190 // Add the HTML as a section:
191 $markerArray = array(
192 'CSH' => $docHeaderButtons['csh'],
193 'FUNC_MENU' => t3lib_BEfunc::getFuncMenu($this->id, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']),
194 'BUTTONS' => $docHeaderButtons,
195 'PATH' => $this->title,
196 'CONTENT' => $pageContent,
197 );
198
199 $this->content.= $this->doc->moduleBody(array(), $docHeaderButtons, $markerArray);
200 $this->content.= $this->doc->endPage();
201 $this->content = $this->doc->insertStylesAndJS($this->content);
202
203
204 }
205
206 /**
207 * Outputting the accumulated content to screen
208 *
209 * @return void
210 */
211 function printContent() {
212 echo $this->content;
213 }
214
215 /**
216 * Builds the buttons for the docheader and returns them as an array
217 *
218 * @return array
219 **/
220 function getButtons() {
221
222 $buttons = array();
223
224 // CSH button
225 $buttons['csh'] = t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'file_edit', $GLOBALS['BACK_PATH'], '', TRUE);
226
227 // Save button
228 $theIcon = t3lib_iconWorks::getSpriteIcon('actions-document-save');
229 $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>';
230
231 // Save and Close button
232 $theIcon = t3lib_iconWorks::getSpriteIcon('actions-document-save-close');
233 $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>';
234
235 // Cancel button
236 $theIcon = t3lib_iconWorks::getSpriteIcon('actions-document-close');
237 $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>';
238
239 return $buttons;
240 }
241 }
242
243 // Make instance:
244 $SOBE = t3lib_div::makeInstance('SC_file_edit');
245 $SOBE->init();
246 $SOBE->main();
247 $SOBE->printContent();
248
249 ?>