2 /***************************************************************
5 * (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
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.
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.
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.
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
28 * Web>File: Editing documents
30 * Revised for TYPO3 3.6 2/2003 by Kasper Skårhøj
31 * XHTML compliant (except textarea field)
33 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
36 $GLOBALS['BACK_PATH'] = '';
38 require('template.php');
42 * Script Class for rendering the file editing screen
44 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
49 var $content; // Module content accumulated.
54 * Document template object
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.
66 * the file that is being edited on
68 * @var t3lib_file_AbstractFile
70 protected $fileObject;
73 * Initialize script class
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'));
82 // create the file object
83 if ($fileIdentifier) {
84 $this->fileObject
= t3lib_file_Factory
::getInstance()->retrieveFileOrFolderObject($fileIdentifier);
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);
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());
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");
109 $this->doc
->form
='<form action="tce_file.php" method="post" name="editform">';
113 * Main function, redering the actual content of the editing page
118 //TODO: change locallang*.php to locallang*.xml
119 $docHeaderButtons = $this->getButtons();
121 $this->content
= $this->doc
->startPage($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_edit.php.pagetitle'));
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
,
131 foreach ($preOutputProcessingHook as $hookFunction) {
132 t3lib_div
::callUserFunction($hookFunction, $hookParameters, $this);
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);
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();
147 // making the formfields
148 $hValue = 'file_edit.php?target='.rawurlencode($this->origTarget
).'&returnUrl='.rawurlencode($this->returnUrl
);
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).
156 <input type="hidden" name="file[editfile][0][target]" value="' . $this->fileObject
->getUid() . '" />
157 <input type="hidden" name="redirect" value="'.htmlspecialchars($hValue).'" />
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);
166 $docHeaderButtons['shortcut'] = '';
169 $code .= sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_edit.php.coundNot'), $extList);
172 // Ending of section and outputting editing form:
173 $pageContent.= $this->doc
->sectionEnd();
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
,
184 foreach ($postOutputProcessingHook as $hookFunction) {
185 t3lib_div
::callUserFunction($hookFunction, $hookParameters, $this);
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,
199 $this->content
.= $this->doc
->moduleBody(array(), $docHeaderButtons, $markerArray);
200 $this->content
.= $this->doc
->endPage();
201 $this->content
= $this->doc
->insertStylesAndJS($this->content
);
207 * Outputting the accumulated content to screen
211 function printContent() {
216 * Builds the buttons for the docheader and returns them as an array
220 function getButtons() {
225 $buttons['csh'] = t3lib_BEfunc
::cshItem('xMOD_csh_corebe', 'file_edit', $GLOBALS['BACK_PATH'], '', TRUE);
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>';
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>';
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>';
244 $SOBE = t3lib_div
::makeInstance('SC_file_edit');
247 $SOBE->printContent();