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