file_edit.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2010 Kasper Skaarhoj (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 7905 2010-06-13 14:42:33Z ohader $
00031  * Revised for TYPO3 3.6 2/2003 by Kasper Skaarhoj
00032  * XHTML compliant (except textarea field)
00033  *
00034  * @author  Kasper Skaarhoj <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 Skaarhoj <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::_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             t3lib_BEfunc::typo3PrintError($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:paramError', true), $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:targetNoDir', true), '');
00115             exit;
00116         }
00117             // Finding the icon
00118         switch($GLOBALS['FILEMOUNTS'][$key]['type'])    {
00119             case 'user':    $this->icon = 'gfx/i/_icon_ftp_user.gif';   break;
00120             case 'group':   $this->icon = 'gfx/i/_icon_ftp_group.gif';  break;
00121             default:        $this->icon = 'gfx/i/_icon_ftp.gif';    break;
00122         }
00123 
00124         $this->icon = '<img'.t3lib_iconWorks::skinImg($this->backPath,$this->icon,'width="18" height="16"').' title="" alt="" />';
00125 
00126             // Relative path to filemount, $key:
00127         $this->shortPath = substr($this->target,strlen($GLOBALS['FILEMOUNTS'][$key]['path']));
00128 
00129             // Setting title:
00130         $this->title = $this->icon.$GLOBALS['FILEMOUNTS'][$key]['name'].': '.$this->shortPath;
00131 
00132         // ***************************
00133         // Setting template object
00134         // ***************************
00135         $this->doc = t3lib_div::makeInstance('template');
00136         $this->doc->setModuleTemplate('templates/file_edit.html');
00137         $this->doc->backPath = $BACK_PATH;
00138         $this->doc->JScode=$this->doc->wrapScriptTags('
00139             function backToList()   {   //
00140                 top.goToModule("file_list");
00141             }
00142         ');
00143         $this->doc->form='<form action="tce_file.php" method="post" name="editform">';
00144     }
00145 
00146     /**
00147      * Main function, redering the actual content of the editing page
00148      *
00149      * @return  void
00150      */
00151     function main() {
00152         //TODO remove global, change $LANG into $GLOBALS['LANG'], change locallang*.php to locallang*.xml
00153         global $BE_USER, $LANG, $TYPO3_CONF_VARS;
00154         $docHeaderButtons = $this->getButtons();
00155 
00156         $this->content = $this->doc->startPage($LANG->sL('LLL:EXT:lang/locallang_core.php:file_edit.php.pagetitle'));
00157 
00158         $pageContent = $this->doc->header($LANG->sL('LLL:EXT:lang/locallang_core.php:file_edit.php.pagetitle'));
00159         $pageContent .= $this->doc->spacer(2);
00160 
00161         $fI = pathinfo($this->target);
00162         $extList=$TYPO3_CONF_VARS['SYS']['textfile_ext'];
00163 
00164         if ($extList && t3lib_div::inList($extList,strtolower($fI['extension'])))       {
00165                 // Read file content to edit:
00166             $fileContent = t3lib_div::getUrl($this->target);
00167 
00168                 // making the formfields
00169             $hValue = 'file_edit.php?target='.rawurlencode($this->origTarget).'&returnUrl='.rawurlencode($this->returnUrl);
00170 
00171                 // Edit textarea:
00172             $code.='
00173                 <div id="c-edit">
00174                     <textarea rows="30" name="file[editfile][0][data]" wrap="off"'.$this->doc->formWidthText(48,'width:98%;height:80%','off').' class="fixed-font enable-tab">'.
00175                     t3lib_div::formatForTextarea($fileContent).
00176                     '</textarea>
00177                     <input type="hidden" name="file[editfile][0][target]" value="'.$this->target.'" />
00178                     <input type="hidden" name="redirect" value="'.htmlspecialchars($hValue).'" />
00179                 </div>
00180                 <br />';
00181 
00182                 // Make shortcut:
00183             if ($BE_USER->mayMakeShortcut())    {
00184                 $this->MCONF['name']='xMOD_file_edit.php';
00185                 $docHeaderButtons['shortcut'] = $this->doc->makeShortcutIcon('target','',$this->MCONF['name'],1);
00186             }
00187         } else {
00188             $code.=sprintf($LANG->sL('LLL:EXT:lang/locallang_core.php:file_edit.php.coundNot'), $extList);
00189         }
00190 
00191             // Ending of section and outputting editing form:
00192         $pageContent.= $this->doc->sectionEnd();
00193         $pageContent.=$code;
00194 
00195             // Add the HTML as a section:
00196         $markerArray = array(
00197             'CSH' => $docHeaderButtons['csh'],
00198             'FUNC_MENU' => t3lib_BEfunc::getFuncMenu($this->id, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']),
00199             'BUTTONS' => $docHeaderButtons,
00200             'PATH' => $this->title,
00201             'CONTENT' => $pageContent,
00202         );
00203 
00204         $this->content.= $this->doc->moduleBody(array(), $docHeaderButtons, $markerArray);
00205         $this->content.= $this->doc->endPage();
00206         $this->content = $this->doc->insertStylesAndJS($this->content);
00207 
00208 
00209     }
00210 
00211     /**
00212      * Outputting the accumulated content to screen
00213      *
00214      * @return  void
00215      */
00216     function printContent() {
00217         echo $this->content;
00218     }
00219 
00220     /**
00221      * Builds the buttons for the docheader and returns them as an array
00222      *
00223      * @return array
00224      **/
00225     function getButtons() {
00226 
00227         $buttons = array();
00228 
00229             // CSH button
00230         $buttons['csh'] = t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'file_edit', $GLOBALS['BACK_PATH'], '', TRUE);
00231 
00232             // Save button
00233         $theIcon = t3lib_iconWorks::getSpriteIcon('actions-document-save');
00234         $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>';
00235 
00236             // Save and Close button
00237         $theIcon = t3lib_iconWorks::getSpriteIcon('actions-document-save-close');
00238         $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>';
00239 
00240             // Cancel button
00241         $theIcon = t3lib_iconWorks::getSpriteIcon('actions-document-close');
00242         $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>';
00243 
00244         return $buttons;
00245     }
00246 }
00247 
00248 
00249 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/file_edit.php']) {
00250     include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/file_edit.php']);
00251 }
00252 
00253 
00254 
00255 // Make instance:
00256 $SOBE = t3lib_div::makeInstance('SC_file_edit');
00257 $SOBE->init();
00258 $SOBE->main();
00259 $SOBE->printContent();
00260 
00261 ?>

Generated on Sat Jul 24 04:17:29 2010 for TYPO3 API by  doxygen 1.4.7