|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 2010-2011 Tobias Liebig <mail_typo3@etobi.de> 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 require_once(t3lib_extMgm::extPath('t3editor', 'classes/class.tx_t3editor.php')); 00029 00030 class tx_t3editor_hooks_fileedit { 00031 00032 /** 00033 * @var tx_t3editor 00034 */ 00035 protected $t3editor = NULL; 00036 00037 /** 00038 * @var string 00039 */ 00040 protected $ajaxSaveType = 'tx_tstemplateinfo'; 00041 00042 /** 00043 * @return tx_t3editor 00044 */ 00045 protected function getT3editor() { 00046 if ($this->t3editor == NULL) { 00047 $this->t3editor = t3lib_div::makeInstance('tx_t3editor') 00048 ->setAjaxSaveType($this->ajaxSaveType); 00049 } 00050 return $this->t3editor; 00051 } 00052 00053 /** 00054 * Hook-function: inject t3editor JavaScript code before the page is compiled 00055 * called in file_edit.php:SC_file_edit->main 00056 * 00057 * @param array $parameters 00058 * @param SC_file_edit $pObj 00059 */ 00060 public function preOutputProcessingHook($parameters, $pObj) { 00061 $t3editor = $this->getT3editor(); 00062 $t3editor->setModeByFile($parameters['target']); 00063 00064 if (!$t3editor->isEnabled() || !$t3editor->getMode()) { 00065 return; 00066 } 00067 00068 $parameters['content'] = str_replace( 00069 '<!--###POSTJSMARKER###-->', 00070 '<!--###POSTJSMARKER###-->' . $t3editor->getModeSpecificJavascriptCode(), 00071 $parameters['content'] 00072 ); 00073 } 00074 00075 /** 00076 * Hook-function: inject t3editor JavaScript code before the page is compiled 00077 * called in typo3/template.php:startPage 00078 * 00079 * @param array $parameters 00080 * @param template $pObj 00081 */ 00082 public function preStartPageHook($parameters, $pObj) { 00083 if (preg_match('/typo3\/file_edit\.php/', $_SERVER['SCRIPT_NAME'])) { 00084 $t3editor = $this->getT3editor(); 00085 if (!$t3editor->isEnabled()) { 00086 return; 00087 } 00088 $pObj->JScode .= $t3editor->getJavascriptCode($pObj); 00089 $pObj->loadJavascriptLib(t3lib_extmgm::extRelPath('t3editor') . 'res/jslib/fileedit.js'); 00090 } 00091 } 00092 00093 /** 00094 * Hook-function: 00095 * called in file_edit.php:SC_file_edit->main 00096 * 00097 * @param array $parameters 00098 * @param SC_file_edit $pObj 00099 */ 00100 public function postOutputProcessingHook($parameters, $pObj) { 00101 $t3editor = $this->getT3editor(); 00102 00103 if (!$t3editor->isEnabled() || !$t3editor->getMode()) { 00104 return; 00105 } 00106 00107 $attributes = 'rows="30" ' . 00108 'wrap="off" ' . 00109 $pObj->doc->formWidthText(48, 'width:98%;height:60%', 'off'); 00110 00111 $title = $GLOBALS['LANG']->getLL('file') . ' ' . 00112 htmlspecialchars($pObj->target); 00113 00114 $outCode = $t3editor->getCodeEditor( 00115 'file[editfile][0][data]', 00116 'fixed-font enable-tab', 00117 '$1', // will be replaced with the actual code later, see preg_replace below 00118 $attributes, 00119 $title, 00120 array( 00121 'target' => intval($pObj->target) 00122 ) 00123 ); 00124 00125 $parameters['pageContent'] = preg_replace( 00126 '/<textarea .*name="file\[editfile\]\[0\]\[data\]".*>([^<]*)<\/textarea>/mi', 00127 $outCode, 00128 $parameters['pageContent'] 00129 ); 00130 00131 } 00132 00133 /** 00134 * @return boolean true if successful 00135 */ 00136 public function save($parameters, $pObj) { 00137 $savingsuccess = false; 00138 if ($parameters['type'] == $this->ajaxSaveType) { 00139 require_once('init.php'); 00140 require_once('classes/class.typo3_tcefile.php'); 00141 00142 $tceFile = t3lib_div::makeInstance('TYPO3_tcefile'); 00143 $tceFile->processAjaxRequest(array(), $parameters['ajaxObj']); 00144 00145 $result = $parameters['ajaxObj']->getContent('result'); 00146 $savingsuccess = is_array($result) && $result['editfile'][0]; 00147 } 00148 return $savingsuccess; 00149 } 00150 } 00151 00152 00153 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/t3editor/classes/class.tx_t3editor_hooks_fileedit.php']) { 00154 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/t3editor/classes/class.tx_t3editor_hooks_fileedit.php']); 00155 } 00156 00157 ?>
1.8.0