[TASK] Cleanup entry classes in typo3/ part2
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Controller / File / EditFileController.php
1 <?php
2 namespace TYPO3\CMS\Backend\Controller\File;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 1999-2013 Kasper Skårhøj (kasperYYYY@typo3.com)
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 use TYPO3\CMS\Backend\Utility\BackendUtility;
31 use TYPO3\CMS\Backend\Utility\IconUtility;
32 use TYPO3\CMS\Core\Utility\GeneralUtility;
33
34 /**
35 * Script Class for rendering the file editing screen
36 *
37 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
38 */
39 class EditFileController {
40
41 // Module content accumulated.
42 /**
43 * @todo Define visibility
44 */
45 public $content;
46
47 /**
48 * @todo Define visibility
49 */
50 public $title;
51
52 /**
53 * Document template object
54 *
55 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
56 * @todo Define visibility
57 */
58 public $doc;
59
60 // Internal, static: GPvar
61 // Original input target
62 /**
63 * @todo Define visibility
64 */
65 public $origTarget;
66
67 // The original target, but validated.
68 /**
69 * @todo Define visibility
70 */
71 public $target;
72
73 // Return URL of list module.
74 /**
75 * @todo Define visibility
76 */
77 public $returnUrl;
78
79 /**
80 * the file that is being edited on
81 *
82 * @var \TYPO3\CMS\Core\Resource\AbstractFile
83 */
84 protected $fileObject;
85
86 /**
87 * Constructor
88 */
89 public function __construct() {
90 $GLOBALS['SOBE'] = $this;
91 $GLOBALS['BACK_PATH'] = '';
92
93 $this->init();
94 }
95
96 /**
97 * Initialize script class
98 *
99 * @return void
100 */
101 protected function init() {
102 // Setting target, which must be a file reference to a file within the mounts.
103 $this->target = ($this->origTarget = ($fileIdentifier = GeneralUtility::_GP('target')));
104 $this->returnUrl = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'));
105 // create the file object
106 if ($fileIdentifier) {
107 $this->fileObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($fileIdentifier);
108 }
109 // Cleaning and checking target directory
110 if (!$this->fileObject) {
111 $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:paramError', TRUE);
112 $message = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:targetNoDir', TRUE);
113 throw new \RuntimeException($title . ': ' . $message, 1294586841);
114 }
115 // Setting the title and the icon
116 $icon = IconUtility::getSpriteIcon('apps-filetree-root');
117 $this->title = $icon . htmlspecialchars($this->fileObject->getStorage()->getName()) . ': ' . htmlspecialchars($this->fileObject->getIdentifier());
118
119 // Setting template object
120 $this->doc = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
121 $this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/file_edit.html');
122 $this->doc->backPath = $GLOBALS['BACK_PATH'];
123 $this->doc->JScode = $this->doc->wrapScriptTags('
124 function backToList() { //
125 top.goToModule("file_list");
126 }
127 ');
128 $this->doc->form = '<form action="tce_file.php" method="post" name="editform">';
129 }
130
131 /**
132 * Main function, redering the actual content of the editing page
133 *
134 * @return void
135 */
136 public function main() {
137 $docHeaderButtons = $this->getButtons();
138 $this->content = $this->doc->startPage($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_edit.php.pagetitle'));
139 // Hook before compiling the output
140 if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/file_edit.php']['preOutputProcessingHook'])) {
141 $preOutputProcessingHook = &$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/file_edit.php']['preOutputProcessingHook'];
142 if (is_array($preOutputProcessingHook)) {
143 $hookParameters = array(
144 'content' => &$this->content,
145 'target' => &$this->target
146 );
147 foreach ($preOutputProcessingHook as $hookFunction) {
148 GeneralUtility::callUserFunction($hookFunction, $hookParameters, $this);
149 }
150 }
151 }
152 $pageContent = $this->doc->header($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_edit.php.pagetitle') . ' ' . htmlspecialchars($this->fileObject->getName()));
153 $pageContent .= $this->doc->spacer(2);
154 $code = '';
155 $extList = $GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'];
156 if ($extList && GeneralUtility::inList($extList, $this->fileObject->getExtension())) {
157 // Read file content to edit:
158 $fileContent = $this->fileObject->getContents();
159 // Making the formfields
160 $hValue = 'file_edit.php?target=' . rawurlencode($this->origTarget) . '&returnUrl=' . rawurlencode($this->returnUrl);
161 // Edit textarea:
162 $code .= '
163 <div id="c-edit">
164 <textarea rows="30" name="file[editfile][0][data]" wrap="off"' . $this->doc->formWidthText(48, 'width:98%;height:80%', 'off') . ' class="fixed-font enable-tab">' . GeneralUtility::formatForTextarea($fileContent) . '</textarea>
165 <input type="hidden" name="file[editfile][0][target]" value="' . $this->fileObject->getUid() . '" />
166 <input type="hidden" name="redirect" value="' . htmlspecialchars($hValue) . '" />
167 </div>
168 <br />';
169 // Make shortcut:
170 if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
171 $this->MCONF['name'] = 'xMOD_file_edit.php';
172 $docHeaderButtons['shortcut'] = $this->doc->makeShortcutIcon('target', '', $this->MCONF['name'], 1);
173 } else {
174 $docHeaderButtons['shortcut'] = '';
175 }
176 } else {
177 $code .= sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_edit.php.coundNot'), $extList);
178 }
179 // Ending of section and outputting editing form:
180 $pageContent .= $this->doc->sectionEnd();
181 $pageContent .= $code;
182 // Hook after compiling the output
183 if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/file_edit.php']['postOutputProcessingHook'])) {
184 $postOutputProcessingHook = &$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/file_edit.php']['postOutputProcessingHook'];
185 if (is_array($postOutputProcessingHook)) {
186 $hookParameters = array(
187 'pageContent' => &$pageContent,
188 'target' => &$this->target
189 );
190 foreach ($postOutputProcessingHook as $hookFunction) {
191 GeneralUtility::callUserFunction($hookFunction, $hookParameters, $this);
192 }
193 }
194 }
195 // Add the HTML as a section:
196 $markerArray = array(
197 'CSH' => $docHeaderButtons['csh'],
198 'FUNC_MENU' => BackendUtility::getFuncMenu($this->id, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']),
199 'BUTTONS' => $docHeaderButtons,
200 'PATH' => $this->title,
201 'CONTENT' => $pageContent
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 public 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 * @todo Define visibility
222 */
223 public function getButtons() {
224 $buttons = array();
225 // CSH button
226 $buttons['csh'] = BackendUtility::cshItem('xMOD_csh_corebe', 'file_edit', $GLOBALS['BACK_PATH'], '', TRUE);
227 // Save button
228 $theIcon = IconUtility::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.xlf:file_edit.php.submit', TRUE)) . '">' . $theIcon . '</a>';
230 // Save and Close button
231 $theIcon = IconUtility::getSpriteIcon('actions-document-save-close');
232 $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.xlf:file_edit.php.saveAndClose', TRUE)) . '">' . $theIcon . '</a>';
233 // Cancel button
234 $theIcon = IconUtility::getSpriteIcon('actions-document-close');
235 $buttons['CANCEL'] = '<a href="#" onclick="backToList(); return false;" title="' . $GLOBALS['LANG']->makeEntities($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.cancel', TRUE)) . '">' . $theIcon . '</a>';
236 return $buttons;
237 }
238
239 }
240
241 ?>