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