TYPO3 API  SVNRelease
file_edit.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
00006 *  All rights reserved
00007 *
00008 *  This script is part of the TYPO3 project. The TYPO3 project is
00009 *  free software; you can redistribute it and/or modify
00010 *  it under the terms of the GNU General Public License as published by
00011 *  the Free Software Foundation; either version 2 of the License, or
00012 *  (at your option) any later version.
00013 *
00014 *  The GNU General Public License can be found at
00015 *  http://www.gnu.org/copyleft/gpl.html.
00016 *  A copy is found in the textfile GPL.txt and important notices to the license
00017 *  from the author is found in LICENSE.txt distributed with these scripts.
00018 *
00019 *
00020 *  This script is distributed in the hope that it will be useful,
00021 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 *  GNU General Public License for more details.
00024 *
00025 *  This copyright notice MUST APPEAR in all copies of the script!
00026 ***************************************************************/
00027 /**
00028  * Web>File: Editing documents
00029  *
00030  * $Id: file_edit.php 10121 2011-01-18 20:15:30Z ohader $
00031  * Revised for TYPO3 3.6 2/2003 by Kasper Skårhøj
00032  * XHTML compliant (except textarea field)
00033  *
00034  * @author  Kasper Skårhøj <kasperYYYY@typo3.com>
00035  */
00036 /**
00037  * [CLASS/FUNCTION INDEX of SCRIPT]
00038  *
00039  *
00040  *
00041  *   74: class SC_file_edit
00042  *   93:     function init()
00043  *  143:     function main()
00044  *  205:     function printContent()
00045  *
00046  * TOTAL FUNCTIONS: 3
00047  * (This index is automatically created/updated by the extension "extdeveval")
00048  *
00049  */
00050 
00051 $BACK_PATH = '';
00052 require('init.php');
00053 require('template.php');
00054 
00055 
00056 /**
00057  * Script Class for rendering the file editing screen
00058  *
00059  * @author  Kasper Skårhøj <kasperYYYY@typo3.com>
00060  * @package TYPO3
00061  * @subpackage core
00062  */
00063 class SC_file_edit {
00064     var $content;       // Module content accumulated.
00065 
00066     /**
00067      * File processing object
00068      *
00069      * @var t3lib_basicFileFunctions
00070      */
00071     var $basicff;
00072     var $shortPath;
00073     var $title;
00074     var $icon;
00075 
00076     /**
00077      * Document template object
00078      *
00079      * @var template
00080      */
00081     var $doc;
00082 
00083         // Internal, static: GPvar
00084     var $origTarget;        // Original input target
00085     var $target;            // The original target, but validated.
00086     var $returnUrl;     // Return URL of list module.
00087 
00088 
00089     /**
00090      * Initialize script class
00091      *
00092      * @return  void
00093      */
00094     function init() {
00095         //TODO remove global
00096         global $BACK_PATH,$TYPO3_CONF_VARS;
00097 
00098             // Setting target, which must be a file reference to a file within the mounts.
00099         $this->target = $this->origTarget = t3lib_div::_GP('target');
00100         $this->returnUrl = t3lib_div::sanitizeLocalUrl(t3lib_div::_GP('returnUrl'));
00101 
00102             // Creating file management object:
00103         $this->basicff = t3lib_div::makeInstance('t3lib_basicFileFunctions');
00104         $this->basicff->init($GLOBALS['FILEMOUNTS'],$TYPO3_CONF_VARS['BE']['fileExtensions']);
00105 
00106 
00107         if (file_exists($this->target)) {
00108             $this->target=$this->basicff->cleanDirectoryName($this->target);        // Cleaning and checking target (file or dir)
00109         } else {
00110             $this->target='';
00111         }
00112         $key=$this->basicff->checkPathAgainstMounts($this->target.'/');
00113         if (!$this->target || !$key) {
00114             $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:paramError', TRUE);
00115             $message = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:targetNoDir', TRUE);
00116             throw new RuntimeException($title . ': ' . $message);
00117         }
00118             // Finding the icon
00119         switch($GLOBALS['FILEMOUNTS'][$key]['type'])    {
00120             case 'user':    $this->icon = 'gfx/i/_icon_ftp_user.gif';   break;
00121             case 'group':   $this->icon = 'gfx/i/_icon_ftp_group.gif';  break;
00122             default:        $this->icon = 'gfx/i/_icon_ftp.gif';    break;
00123         }
00124 
00125         $this->icon = '<img'.t3lib_iconWorks::skinImg($this->backPath,$this->icon,'width="18" height="16"').' title="" alt="" />';
00126 
00127             // Relative path to filemount, $key:
00128         $this->shortPath = substr($this->target,strlen($GLOBALS['FILEMOUNTS'][$key]['path']));
00129 
00130             // Setting title:
00131         $this->title = $this->icon.$GLOBALS['FILEMOUNTS'][$key]['name'].': '.$this->shortPath;
00132 
00133         // ***************************
00134         // Setting template object
00135         // ***************************
00136         $this->doc = t3lib_div::makeInstance('template');
00137         $this->doc->setModuleTemplate('templates/file_edit.html');
00138         $this->doc->backPath = $BACK_PATH;
00139         $this->doc->JScode=$this->doc->wrapScriptTags('
00140             function backToList()   {   //
00141                 top.goToModule("file_list");
00142             }
00143         ');
00144         $this->doc->form='<form action="tce_file.php" method="post" name="editform">';
00145     }
00146 
00147     /**
00148      * Main function, redering the actual content of the editing page
00149      *
00150      * @return  void
00151      */
00152     function main() {
00153         //TODO remove global, change $LANG into $GLOBALS['LANG'], change locallang*.php to locallang*.xml
00154         global $BE_USER, $LANG, $TYPO3_CONF_VARS;
00155         $docHeaderButtons = $this->getButtons();
00156 
00157         $this->content = $this->doc->startPage($LANG->sL('LLL:EXT:lang/locallang_core.php:file_edit.php.pagetitle'));
00158 
00159             // hook before compiling the output
00160         if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/file_edit.php']['preOutputProcessingHook'])) {
00161             $preOutputProcessingHook =& $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/file_edit.php']['preOutputProcessingHook'];
00162             if (is_array($preOutputProcessingHook)) {
00163                 $hookParameters = array(
00164                     'content' => &$this->content,
00165                     'target' => &$this->target,
00166                 );
00167                 foreach ($preOutputProcessingHook as $hookFunction) {
00168                     t3lib_div::callUserFunction($hookFunction, $hookParameters, $this);
00169                 }
00170             }
00171         }
00172 
00173         $pageContent = $this->doc->header($LANG->sL('LLL:EXT:lang/locallang_core.php:file_edit.php.pagetitle'));
00174         $pageContent .= $this->doc->spacer(2);
00175 
00176         $fI = pathinfo($this->target);
00177         $extList=$TYPO3_CONF_VARS['SYS']['textfile_ext'];
00178 
00179         if ($extList && t3lib_div::inList($extList,strtolower($fI['extension'])))       {
00180                 // Read file content to edit:
00181             $fileContent = t3lib_div::getUrl($this->target);
00182 
00183                 // making the formfields
00184             $hValue = 'file_edit.php?target='.rawurlencode($this->origTarget).'&returnUrl='.rawurlencode($this->returnUrl);
00185 
00186                 // Edit textarea:
00187             $code.='
00188                 <div id="c-edit">
00189                     <textarea rows="30" name="file[editfile][0][data]" wrap="off"'.$this->doc->formWidthText(48,'width:98%;height:80%','off').' class="fixed-font enable-tab">'.
00190                     t3lib_div::formatForTextarea($fileContent).
00191                     '</textarea>
00192                     <input type="hidden" name="file[editfile][0][target]" value="'.$this->target.'" />
00193                     <input type="hidden" name="redirect" value="'.htmlspecialchars($hValue).'" />
00194                 </div>
00195                 <br />';
00196 
00197                 // Make shortcut:
00198             if ($BE_USER->mayMakeShortcut())    {
00199                 $this->MCONF['name']='xMOD_file_edit.php';
00200                 $docHeaderButtons['shortcut'] = $this->doc->makeShortcutIcon('target','',$this->MCONF['name'],1);
00201             }
00202         } else {
00203             $code.=sprintf($LANG->sL('LLL:EXT:lang/locallang_core.php:file_edit.php.coundNot'), $extList);
00204         }
00205 
00206             // Ending of section and outputting editing form:
00207         $pageContent.= $this->doc->sectionEnd();
00208         $pageContent.=$code;
00209 
00210                 // hook after compiling the output
00211         if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/file_edit.php']['postOutputProcessingHook'])) {
00212             $postOutputProcessingHook =& $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/file_edit.php']['postOutputProcessingHook'];
00213             if (is_array($postOutputProcessingHook)) {
00214                 $hookParameters = array(
00215                     'pageContent' => &$pageContent,
00216                     'target' => &$this->target,
00217                 );
00218                 foreach ($postOutputProcessingHook as $hookFunction)    {
00219                     t3lib_div::callUserFunction($hookFunction, $hookParameters, $this);
00220                 }
00221             }
00222         }
00223 
00224             // Add the HTML as a section:
00225         $markerArray = array(
00226             'CSH' => $docHeaderButtons['csh'],
00227             'FUNC_MENU' => t3lib_BEfunc::getFuncMenu($this->id, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']),
00228             'BUTTONS' => $docHeaderButtons,
00229             'PATH' => $this->title,
00230             'CONTENT' => $pageContent,
00231         );
00232 
00233         $this->content.= $this->doc->moduleBody(array(), $docHeaderButtons, $markerArray);
00234         $this->content.= $this->doc->endPage();
00235         $this->content = $this->doc->insertStylesAndJS($this->content);
00236 
00237 
00238     }
00239 
00240     /**
00241      * Outputting the accumulated content to screen
00242      *
00243      * @return  void
00244      */
00245     function printContent() {
00246         echo $this->content;
00247     }
00248 
00249     /**
00250      * Builds the buttons for the docheader and returns them as an array
00251      *
00252      * @return array
00253      **/
00254     function getButtons() {
00255 
00256         $buttons = array();
00257 
00258             // CSH button
00259         $buttons['csh'] = t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'file_edit', $GLOBALS['BACK_PATH'], '', TRUE);
00260 
00261             // Save button
00262         $theIcon = t3lib_iconWorks::getSpriteIcon('actions-document-save');
00263         $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>';
00264 
00265             // Save and Close button
00266         $theIcon = t3lib_iconWorks::getSpriteIcon('actions-document-save-close');
00267         $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>';
00268 
00269             // Cancel button
00270         $theIcon = t3lib_iconWorks::getSpriteIcon('actions-document-close');
00271         $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>';
00272 
00273         return $buttons;
00274     }
00275 }
00276 
00277 
00278 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/file_edit.php'])) {
00279     include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/file_edit.php']);
00280 }
00281 
00282 
00283 
00284 // Make instance:
00285 $SOBE = t3lib_div::makeInstance('SC_file_edit');
00286 $SOBE->init();
00287 $SOBE->main();
00288 $SOBE->printContent();
00289 
00290 ?>