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